调用fork()后,出现“初始化错误”。如果我在不使用fork的情况下运行同一程序,则一切正常。
if (fork() == 0) {
...
cudaMalloc(....);
...
}
Run Code Online (Sandbox Code Playgroud)
是什么原因造成的?
下面是一个完整的示例。如果我注释掉cudaGetDeviceCount调用,它将正常工作。
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <cuda_runtime.h>
#define PERR(call) \
if (call) {\
fprintf(stderr, "%s:%d Error [%s] on "#call"\n", __FILE__, __LINE__,\
cudaGetErrorString(cudaGetLastError()));\
exit(1);\
}
int
main(int argc, char **argv)
{
float *v_d;
int gpucount;
cudaGetDeviceCount(&gpucount);
if (fork() == 0) {
cudaSetDevice(0);
PERR(cudaMalloc(&v_d, 1000*sizeof(float)));
}
wait(NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
简单的Makefile:
PROGS = fork
CUDA_PATH = /usr/local/cuda
CXXFLAGS = -g -O0 -Wall
CXXINCLUDES = -I$(CUDA_PATH)/include …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从设备运行矩阵求逆。如果从主机调用,此逻辑可以正常工作。
编译行如下(Linux):
nvcc -ccbin g++ -arch=sm_35 -rdc=true simple-inv.cu -o simple-inv -lcublas_device -lcudadevrt
Run Code Online (Sandbox Code Playgroud)
我收到以下警告,但我似乎无法解决。(我的 GPU 是 Kepler。我不知道为什么它试图链接到 Maxwell 例程。我有 Cuda 6.5-14):
nvlink warning : SM Arch ('sm_35') not found in '/usr/local/cuda/bin/../targets/x86_64-linux/lib/libcublas_device.a:maxwell_sm50_sgemm.o'
Run Code Online (Sandbox Code Playgroud)
该程序运行时:
handle 0 n = 3
simple-inv.cu:63 Error [an illegal memory access was encountered]
Run Code Online (Sandbox Code Playgroud)
测试程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cuda_runtime.h>
#include <cublas_v2.h>
#define PERR(call) \
if (call) {\
fprintf(stderr, "%s:%d Error [%s] on "#call"\n", __FILE__, __LINE__,\
cudaGetErrorString(cudaGetLastError()));\
exit(1);\
}
#define ERRCHECK \
if (cudaPeekAtLastError()) { \
fprintf(stderr, …
Run Code Online (Sandbox Code Playgroud)