1

I'm a begginer in using pycuda, so far, I've learned some basic stuff how to write the kernels from book "Cuda by example", and my next task is to use a class, that is already written in C++, inside of kernels. How can I import this .h file to pycuda? Do I have to use boost python for transfering this .h so it can be imported like any other module in python? The thing is that I only need this special variables inside of a kernel. This class is used for computing the derivatives and I will write you a couple of lines so you can see how it's constructed:

adoublecuda.h:

namespace adtl {
class adouble {
public:
    // ctors
    __device__ __host__ inline adouble();
    __device__ __host__ inline adouble(const double v);
    __device__ __host__ inline adouble(const adouble& a);

    __device__ __host__ inline adouble operator - () const;
    __device__ __host__ inline adouble operator + () const;

...etc.

I use this class inside of C-CUDA just typing the #include "adoublecuda.h" and now I want to include the same thing in PyCUDA. I'm only using this class inside of kernels (I don't need adouble variables inside of main). So will I have to use boost python in order to include this header file to PyCuda?

Any advice would be appreciated, thank you for helping me!

Banana
  • 1,276
  • 2
  • 16
  • 19
  • Since you're a beginner, I thought I'd mention that for Python coding, I find that a mix of PyCuda and ArrayFire for Python have been awesome for me. I've been doing a lot of my prototyping in Python instead of MATLAB lately and have found that combo to be the quickest way to get good performance. Maybe try that out as you get started. – Ben Stewart Jun 29 '12 at 14:05

1 Answers1

1

If it is only used inside device code, and you are not intending to do any metaprogramming, then you actually don't need to do anything with Python or PyCUDA to make it work. Just compile your device code to a CUBIN object (so use nvcc -cubin) and then load that CUBIN file using driver.module_from_file().

You can see a complete example of this in this older answer of mine.

Community
  • 1
  • 1
talonmies
  • 70,661
  • 34
  • 192
  • 269
  • Ok, I read your example, so every time I want to use some function, I'll need to lookup in this binary file, for the function code, so at the end my code will not be so readable. :) But thank you anyway for this advice, I think that I'll use boostpython and transfer my C++ clas using it. – Banana Jun 29 '12 at 12:06