Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create test_cuda_compile.py #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions test/test_cuda_compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ctypes
import os
from subprocess import run

def compile_cuda_kernel():
kernel_code = """
extern "C"
__global__ void testKernel() {
printf("Hello from CUDA kernel!\\n");
}
"""
kernel_file = 'test_kernel.cu'
binary_file = 'test_kernel'

with open(kernel_file, 'w') as f:
f.write(kernel_code)

result = run(['nvcc', kernel_file, '-o', binary_file])
if result.returncode != 0:
raise RuntimeError("CUDA kernel compilation failed")

return binary_file

def run_cuda_kernel(binary_file):
result = run(['./' + binary_file])
if result.returncode != 0:
raise RuntimeError("CUDA kernel execution failed")

def test_cuda_compile_run():
binary_file = compile_cuda_kernel()
try:
run_cuda_kernel(binary_file)
finally:
os.remove(binary_file)
os.remove('test_kernel.cu')

if __name__ == "__main__":
test_cuda_compile_run()
Loading