I have isolated a problem, namely that I can't seem to be able to retrieve memory from my CUDA device. I have created a simple script to demonstrate my problem:
#include <iostream>
#define CUDA_WARN(XXX)
do { if (XXX != cudaSuccess) std::cerr << "CUDA Error: " <<
cudaGetErrorString(XXX) << ", at line " << __LINE__
<< std::endl; cudaDeviceSynchronize(); } while (0)
struct Car {
int id;
float max_vel;
float max_acc;
float max_steer;
bool alive;
};
int main() {
Car* dCar;
Car* hCar = new Car;
Car* hCar2;
hCar->id = 1;
CUDA_WARN(cudaMalloc((void**) &dCar, sizeof(Car)));
CUDA_WARN(cudaMemcpy( dCar, hCar, sizeof(Car), cudaMemcpyHostToDevice));
CUDA_WARN(cudaMemcpy( hCar2, dCar, sizeof(Car), cudaMemcpyDeviceToHost));
std::cout << "hCar2 id:" << hCar2->id << std::endl;
}
I would fully expect hCar2 now to have been set to point to a value as it came from the device, but for some reason this does not work.
question from:
https://stackoverflow.com/questions/65907048/cant-retrieve-cuda-memory-from-device 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…