Dynamic allocations cannot be freed
- Dominant language
- Julia
- Stars
- 1.4k
- Forks
- 281
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 30
Description
Hi,
I am getting a dynamic memory crash when using Ref and custom structs.
This is occuring across multiple calls to the same kernel, which looks like the memory being allocated is not being deallocated when the kernel returns. Even when using garbage collection.
I am running a mobile NVidia 2060 6GB, if that helps.
I have put together a minimal example here:
```
# Running once is fine. Running multiple times causes crash
# It seems dynamic memory allocation is consistent across
# runs.
struct Point
x::Float32
y::Float32
z::Float32
Point() = new(0.0f0, 0.0f0, 0.0f0)
Point(a,b,c) = new(a,b,c)
end
function GetThreePoint(mem, offset, sz)
a = GetValue(mem, offset, sz)
b = GetValue(mem, offset, sz) ## Comment this line out to not crash.
return Point(a,b,a)
end
function GetValue(mem, offset, sz)
offset[] = offset[]+1
r = mem[][1+(offset[] % sz-2)]
return r
end
function AllocatingKernel(memIn, memOut, size)
i = 1 #(blockIdx().x - 1) * blockDim().x + threadIdx().x
memRef = Ref(memIn)
a = Ref(1)
memOut[i] = GetThreePoint(memRef, a, size).x
return
end
# Running
memInGpu = CuArray(ones(Float32, 256))
memOutGpu = CuArray(ones(Float32, 256))
sz = length(memInGpu)
for i in 1:1000
@cuda blocks = (16,1) threads=(64,1) AllocatingKernel(memInGpu, memOutGpu, sz)
end
```
which results many pages of
```
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: Out of dynamic GPU memory (trying to allocate 16 bytes)
ERROR: a exception was thrown during kernel execution.
Run Julia on debug level 2 for device stack traces.
```
From my limited testing, this crash only happens with my Point type, if we dont use the reference object with it, it is fine?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.