CudaMemCpy returns cudaErrorInvalidValue
1.CUDA Buffer 没有分配cudaMalloc,而是分配 Malloc,导致错误
由于使用 DeviceAllocatorSingleton,之前已经定义了一个 CPUDeviceAllocator,
-> 所以直接返回instance
定义不同类型两个实例
class DeviceAllocatorSingleton {public:// 创建实例,使用懒加载模式,确保只有一个实例被创建static std::shared_ptr<DeviceAllocator> getInstance(DeviceType device_type_) {if (device_type_ == DeviceType::kDeviceCPU) {if (!cpu_instance) {cpu_instance = std::make_shared<CPUAllocator>();}return cpu_instance;} else if (device_type_ == DeviceType::kDeviceCUDA) {if (!cuda_instance) {cuda_instance = std::make_shared<CUDADeviceAllocator>();}return cuda_instance;}return nullptr; // 返回 nullptr 如果设备类型未知}private:static std::shared_ptr<DeviceAllocator> cpu_instance;static std::shared_ptr<DeviceAllocator> cuda_instance;
};
2.cudaMalloc((void**)&dev_input, size)
的 size
参数可能是错误的。