Textures, cudaArrays and C++ classes

Hi,

I wanted to ask for some advice regarding textures and cudaArrays. Currently I have a class “Crowd” defined in a C++ file “Crowd.cpp” with all of its methods and variables etc. I have a separate “CrowdSim.cu” file containing wrappers for methods such as cudaMalloc so that I can call them from methods in my “Crowd” class. I have also planned on using this “CrowdSim.cu” file to allow me to call kernels in “crowd_kernels.cu” from each crowd object e.g. as part of a crowd update method.

I want to be able to have the positions of several crowds stored in their own cudaArrays so that I can bind these one at a time to a texture in order to take advantage of cudaFilterModeLinear for linear interpolation when reading from the texture. These textures would be read from during execution of a “posUpdate” kernel.

I can’t add a cudaArray variable to each crowd object in “Crowd.cpp”. As such I am trying to find some way to create cudaArrays in my “CrowdSim.cu” or “crowd_kernels.cu” file so that an array gets made every time I create a new crowd object. These arrays could then can be subsequently accessed in order to update data in the array and to bind each array to the texture and do “updatePos” in turn. I could create a new array every time I run the update on each crowd but this seems wasteful.

Any help would be greatly appreciated.

If you #include <cuda_rumtime.h> in Crowd.h and/or Crowd.cpp you can declare cudaArrays and call nearly all cuda runtime functions like cudaMalloc in Crowd.cpp within the C++ class. The only things that have to go in the .cu file are the kernel call, texture bind call, and a few other misc calls like cudaMemcpyToSymbol (if you use it).

I presume you meant cuda_runtime.h :lol: . Anyway it appears to be working now thank you very much!