From 85e007fde666b793781873dde836aef72c1bd9af Mon Sep 17 00:00:00 2001 From: Esmail <113830751+Esmail-ibraheem@users.noreply.github.com> Date: Sat, 29 Jun 2024 16:18:20 +0300 Subject: [PATCH] Create test_cuda_compile.py --- test/test_cuda_compile.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/test_cuda_compile.py diff --git a/test/test_cuda_compile.py b/test/test_cuda_compile.py new file mode 100644 index 0000000..864e536 --- /dev/null +++ b/test/test_cuda_compile.py @@ -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()