Reputation: 17
I want to delete an array allocated by cudaMalloc
inside a kernel using delete[]
; but memory checker shows access violation, array is kept in memory and kernel continues to execute.
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
__global__ void kernel(int *a)
{
int *b = new int[10];
delete[] b; // no violation
delete[] a; // Memory Checker detects access violation.
}
int main()
{
int *d_a;
cudaMalloc(&d_a, 10 * sizeof(int));
kernel<<<1, 1>>>(d_a);
return 0;
}
cudaMalloc
and new
in device code? cudaMalloc
in device code?Thanks
Upvotes: 1
Views: 668
Reputation: 151879
cudaMalloc
in host code and new
(or malloc
) in device code allocate out of logically separate areas. The two areas are not generally interoperable from an API standpoint.
no
You may wish to read the documentation. The description given there for in-kernel malloc
and free
generally applies to in-kernel new
and delete
as well.
Upvotes: 5