How can I compile CUDA C-code with Cython on Windows?

Viewed 394

I would like to include several CUDA accelearated functions into Python. Therefore, I was looking into Cython. However, how can I tell Cython to use the nvcc Compiler? I have the following C code in the file hello.c:

#include <stdio.h>
#include <cuda.h>
#include <cublas_v2.h>
#include <cuda_runtime.h>


cuComplex test_datatype() {
    return make_cuComplex(1, 2);;
}

void f() {
    printf("%s", "Hello world!\n");
    cuComplex test;
    test = test_datatype();
    printf("(%5.3f,%5.3fi) \n", test.x, test.y);
}


int main(int argc, const char* argv[]) {
    f();
    return 0;
}

This compliles using nvcc -o hello.exe hello.c.

For Cython, I have set up a file hello_caller.pyx

cdef extern from "hello.c":
    void f()

cpdef myf():
    f()

and the setup.py

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

sourcefiles = ['hello_caller.pyx']
ext_modules = [Extension("hello_caller", 
                          sourcefiles
                          )]

setup(
  name = 'Hello World app',
  cmdclass = {'build_ext': build_ext},
  ext_modules = ext_modules
)

I tried to build the module using

python setup.py build_ext --inplace --compiler=nvcc

with no success. The output states

error: don't know how to compile C/C++ code on platform 'nt' with 'nvcc' compiler

How can I advise distutils to use the nvcc compiler? I am aimimg for getting in the next step the function test_datatype exposed to Python. Here, my goal is to get a numpy array as a return from the function. Comments on how to achieve this are also very welcome!

0 Answers
Related