CUDA fails when freeing memory after kernel execution error
I have found weird behavior of CUDA. After I got segfault in my kernel, I was trying to free prior allocated memory and it fails. Does CUDA do it automatically? I mean, does CUDA free memory after segfault during kernel executions?
Here is code to reproduce my situation. I have tested that on CUDA 4.0, 4.0rc2 and 3.2
#include <cassert>
__global__ void segfault(){
int* null = NULL;
*null = 0;
}
int main() {
int* i;
assert (cudaSuccess == cudaHostAlloc(&i, sizeof(int)*100, cudaHostAllocMapped));
segfault&l开发者_开发知识库t;<<1,100>>>();
assert (cudaErrorLaunchFailure == cudaThreadSynchronize());
assert (cudaErrorLaunchFailure == cudaGetLastError());
assert (cudaSuccess == cudaGetLastError());
assert (cudaSuccess == cudaFreeHost(i));
return 0;
}
In my experience, once you hit that kind of error in CUDA execution, all subsequent operations will fail until you reset the device. The documentation indicates that the memory is scoped to the CUDA context, so when you destroy the context (by resetting the device), the memory will be freed.
精彩评论