Hello,
I looked at the example simpleDevLibCUBLAS: This calls the CublasAPIs from a kernel, and this kernel is called from another normal “C”-like function. This “C”-like function is then called from the simpleDevLibCUBLAS.cpp by including it’s reference as doing a forward declaration.
Similarly, How can I simply call this “C”-like function from Python like it’s done in .cpp file ?
I tried using PyCuda in Python file as below code snippet but I got following errors :
pycuda.driver.CompileError: nvcc compilation of /tmp/tmpONE9yY/kernel.cu failed
[command: nvcc --cubin -I/usr/local/cuda-8.0/samples/common/inc/ -arch sm_61 -I/usr/lib64/python2.7/site-packages/pycuda-2017.1.1-py2.7-linux-x86_64.egg/pycuda/cuda kernel.cu]
[stderr:
/usr/include/c++/4.8/bits/memoryfwd.h(63): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/memoryfwd.h(66): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/memoryfwd.h(70): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stringfwd.h(52): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stringfwd.h(55): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stringfwd.h(59): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stringfwd.h(65): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/postypes.h(111): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/postypes.h(214): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/postypes.h(219): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(76): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(79): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(82): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(85): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(88): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(91): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(95): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(99): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(103): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(107): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(110): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(113): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(116): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(119): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/iosfwd(122): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(54): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(67): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(70): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(73): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(76): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(99): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(111): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(114): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(117): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(120): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/ext/numeric_traits.h(123): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/move.h(45): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/move.h(164): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/move.h(183): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(95): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(212): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(218): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(225): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(231): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(237): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(243): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_pair.h(284): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(116): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(162): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(174): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(185): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(199): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(208): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_types.h(216): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(71): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(88): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(112): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(121): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(132): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(148): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h(171): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator.h(95): error: this declaration may not have extern “C” linkage
/usr/include/c++/4.8/bits/stl_iterator.h(289): error: this declaration may not have extern “C” linkage
File Python.py:
mod = SourceModule(open(“kernels.cu”).read())
cublasGemm = mod.get_function(“gemm”)
cublasGemm(A, B, C[0], np.intc(m), np.intc(n), np.intc(k))
File kernals.cu:
global void cublas_gemm(float* A, float* B, float* C, int m, int n, int k){
cublasHandle_t handle;
//cublasCreate(&handle);
cublasStatus_t status = cublasCreate(&handle);
float alpha = 1.0, beta = 0.0;
// cublas use column-major
cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, m, n, k, &alpha, B, m, A, n, &beta, C, m);
}
#endif
//}
extern “C” void gemm(float* A, float* B, float* C, int m, int n, int k) {
cublas_gemm<<<1,1>>>(A,B,C, m, n, k);
}