I got two projects, one renders 3d textures, the other manipulates 3d textures, both build static libs. Is there a way include both projects and pass information (e.g. a cuda texture handle) between them, without copying to the CPU first?
I would like to do something like this:
#include "manipulator.h"
#include "renderer.h"
foo() {
Manipulator myM();
Renderer myR();
//alloc cuda memory x on device
myM.manipulate(x);
myR.render(x);
}
CUDA texture handles are implicit static variables, so they only exist within the .cu file that contains the kernel.
You can pass the cudaArray* between the libraries and just have the 2nd library bind it to its own texture handle (binding is very cheap). This is assuming that both all code you are executing shares the same cuda context (i.e. it is in the same host thread).
Of course you can do that. The cudaArray* is just a pointer after all. #include <cuda_runtime.h> in your standard compiler c++ files, so cudaArray is defined of course. If you aren’t aware, you can call cudaMalloc, cudaMemcpy, etc… from functions compiled by the standard compiler too: there is nothing magical about them :) The only things that must be done in nvcc compiled files are kernel defintions, kernel<<<…>>> calls, and texture binds.