在docker环境下 设备为orin
运行cuda程序时,可以获取设备信息,cuda版本等内容,但是在调用内存相关函数时,出现未知错误
例如cudaMalloc会直接返回999
请问各位大佬,有没有遇到过类似问题
可以再描述一下你的硬件设备,软件环境吗?如果有输出,错误日志,你可以用```代码格式化粘贴进来。也可以粘贴截图。
您好
感谢您的回复
使用设备是orin
cuda及驱动版本为:
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_Oct_11_21:52:10_PDT_2021
Cuda compilation tools, release 11.4, V11.4.152
Build cuda_11.4.r11.4/compiler.30521435_0
Device 0:“Orin”
CUDA Driver Version / Runtime Version 12.0 / 11.4
代码为:
int deviceCount = 0;
cudaError_t error_id = cudaGetDeviceCount(&deviceCount); //获取设备数量device count
if(error_id!=cudaSuccess)
{
printf("cudaGetDeviceCount returned %d\n ->%s\n",
(int)error_id,cudaGetErrorString(error_id));
printf("Result = FAIL\n");
exit(EXIT_FAILURE);
}
if(deviceCount==0)
{
printf("There are no available device(s) that support CUDA\n");
}
else
{
printf("Detected %d CUDA Capable device(s)\n",deviceCount);
}
int dev=0,driverVersion=0,runtimeVersion=0;
cudaSetDevice(dev);
cudaDeviceProp deviceProp;
cudaGetDeviceProperties(&deviceProp,dev); // __host__ cudaError_t cudaGetDeviceProperties ( cudaDeviceProp* prop, int device )
//Returns information about the compute-device.
printf("Device %d:\"%s\"\n",dev,deviceProp.name);
cudaDriverGetVersion(&driverVersion);
cudaRuntimeGetVersion(&runtimeVersion);
printf(" CUDA Driver Version / Runtime Version %d.%d / %d.%d\n",
driverVersion/1000,(driverVersion%100)/10,
runtimeVersion/1000,(runtimeVersion%100)/10);
//cudaError_t e = cudaGetLastError();
//if (e != cudaSuccess)
//{
// printf("Cuda failure %s:%d: '%s'\n", cudaGetErrorString(e));
//}
size_t free_byte, total_byte;
cudaMemGetInfo(&free_byte, &total_byte);
// 输出设备上的总内存大小和可用内存大小
printf("Device memory: total %ld, free %ld\n", total_byte, free_byte);
float *device_data=NULL;
size_t size = 1024*sizeof(float);
printf("使用malloc 申请内存 \n");
cudaError_t malloc_error_id = cudaMalloc((void**)&device_data, size);
if(malloc_error_id != cudaSuccess)
{
printf("申请内存失败 returned %d\n ->%s\n", (int)malloc_error_id,cudaGetErrorString(malloc_error_id));
}
//test end
错误信息为:
Device memory: total 1, free 281474076453604
使用malloc 申请内存
申请内存失败 returned 999
->unknown error
terminate called after throwing an instance of ‘thrust::system::detail::bad_alloc’
what(): std::bad_alloc: cudaErrorUnknown: unknown error
Aborted
将cu函数编译为动态库形式
因此CMake为:
set(CUDA_NVCC_FLAGS "--expt-relaxed-constexpr")
add_definitions(-DUSE_VGICP_CUDA)
cuda_add_library(fast_vgicp_cuda SHARED
src/fast_gicp/cuda/fast_vgicp_cuda.cu
src/fast_gicp/cuda/brute_force_knn.cu
src/fast_gicp/cuda/covariance_estimation.cu
src/fast_gicp/cuda/covariance_estimation_rbf.cu
src/fast_gicp/cuda/covariance_regularization.cu
src/fast_gicp/cuda/gaussian_voxelmap.cu
src/fast_gicp/cuda/find_voxel_correspondences.cu
src/fast_gicp/cuda/compute_derivatives.cu
src/fast_gicp/cuda/compute_mahalanobis.cu
src/fast_gicp/cuda/ndt_cuda.cu
src/fast_gicp/cuda/ndt_compute_derivatives.cu
)
target_include_directories(fast_vgicp_cuda PRIVATE
include
thirdparty/Eigen
thirdparty/nvbio
)
target_link_directories(fast_vgicp_cuda PRIVATE
${CUDA_LIBRARY_DIRS}
)
target_link_libraries(fast_vgicp_cuda
cudart
)
set_target_properties(fast_vgicp_cuda PROPERTIES
COMPILE_FLAGS "--generate-code arch=compute_${CUDA_ARCH},code=sm_${CUDA_ARCH}"
)
cuda_add_cublas_to_target(fast_vgicp_cuda)
以上内容经编译后,生成的可执行文件在docker未开启情况下,可以运行,开启docker后,程序打印的信息不变,但是会出现错误。
关于在docker中使用cuda的情况,可以继续采用什么调试方法或者还应关注哪些信息
另外,我在运行cuda sample中的示例时,会报该错误
**
code=221(cudaErrorJitCompilerNotFound) “cudaGetLastError()”
**
错误代码999表示一个未定义的CUDA错误,通常与以下几个方面有关:
- CUDA驱动程序与运行时版本不匹配 - 您的系统显示驱动版本12.0,而运行时版本是11.4
- Docker容器中GPU访问权限不足3.
- NVIDIA Container Toolkit配置问题
可以尝试如下调试。
-
在 docker 容器中运行 nvidia-smi 命令
docker exec <container_id> nvidia-smi
如果无法看到GPU,说明容器没有正确访问NVIDIA驱动。 -
确保使用正确的参数启动Docker容器
docker run --gpus all --runtime=nvidia -it <your_image>
-
正确安装和配置NVIDIA Container Toolkit
sudo nvidia-ctk runtime configure --runtime=docker
重启Docker服务
sudo systemctl restart docker
-
设备挂载。对于Orin,可以尝试显式挂载NVIDIA设备
docker run --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm -it <your_image>
这个错误是 PTX JIT编译器库未找到。当应用程序不包含适用于当前设备的预编译二进制文件时,CUDA运行时会尝试使用JIT编译器将PTX代码编译为设备可执行代码。
- 检查CUDA安装是否完整。
- 确保您的CUDA驱动程序版本与CUDA工具包版本兼容。
- 确保
LD_LIBRARY_PATH
和PATH
环境变量正确设置,指向CUDA库和二进制文件的位置 - 检查是否存在
/usr/local/cuda/nvvm/libdevice
目录 - 确保您的代码编译时指定了与您的GPU兼容的计算能力
- JIT编译可能被禁用。您可以尝试启用它或提供预编译的二进制文件
你是如何安装的 CUDA?