is it valid to free device allocated memory from a host function? I'm writing some C++ class that should be used on host and device. My constructor and destructor are something like this:
class myClass {
public:
__host__ __device__ myClass() {
#if defined(__CUDA_ARCH__)
data = (char*)malloc(DATA_SIZE);
#else
cudaMalloc(&data,DATA_SIZE);
#endif
}
__host__ __device__ ~myClass() {
#if defined(__CUDA_ARCH__)
free(data);
#else
cudaFree(data);
#endif
}
private:
char* data;
}
The above code compiles and i didn't get an error if i construct a class on the device and free it on the host. But this case is not documented in the CUDA developer papers.