Skip to content

Commit

Permalink
Create test_cuda_compile.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Esmail-ibraheem authored Jun 29, 2024
1 parent c4c4394 commit 85e007f
Showing 1 changed file with 38 additions and 0 deletions.
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()

0 comments on commit 85e007f

Please sign in to comment.