Skip to content

Commit

Permalink
Add missing GC.@preserves. (#2487)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Sep 10, 2024
1 parent d72cdaa commit 123977e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/cudadrv/devices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function name(dev::CuDevice)
buf = Vector{Cchar}(undef, buflen)
cuDeviceGetName(pointer(buf), buflen, dev)
buf[end] = 0
return unsafe_string(pointer(buf))
return GC.@preserve buf unsafe_string(pointer(buf))
end

"""
Expand Down
2 changes: 1 addition & 1 deletion lib/cudadrv/module.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mutable struct CuModule
ERROR_INVALID_IMAGE,
ERROR_INVALID_PTX)
options = decode(optionKeys, optionVals)
error(unsafe_string(pointer(options[JIT_ERROR_LOG_BUFFER])))
error(GC.@preserve options unsafe_string(pointer(options[JIT_ERROR_LOG_BUFFER])))
else
rethrow()
end
Expand Down
6 changes: 3 additions & 3 deletions lib/nvml/device.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Base.IteratorSize(::DeviceIterator) = Base.HasLength()
function name(dev::Device)
buf = Vector{Cchar}(undef, NVML_DEVICE_NAME_V2_BUFFER_SIZE)
nvmlDeviceGetName(dev, pointer(buf), length(buf))
return unsafe_string(pointer(buf))
return GC.@preserve buf unsafe_string(pointer(buf))
end

function brand(dev::Device)
Expand All @@ -67,15 +67,15 @@ end
function uuid(dev::Device)
buf = Vector{Cchar}(undef, NVML_DEVICE_UUID_V2_BUFFER_SIZE)
nvmlDeviceGetUUID(dev, pointer(buf), length(buf))
uuid_str = unsafe_string(pointer(buf))
uuid_str = GC.@preserve buf unsafe_string(pointer(buf))
@assert startswith(uuid_str, "GPU-") || startswith(uuid_str, "MIG-")
return Base.UUID(uuid_str[5:end])
end

function serial(dev::Device)
buf = Vector{Cchar}(undef, NVML_DEVICE_SERIAL_BUFFER_SIZE)
nvmlDeviceGetSerial(dev, pointer(buf), length(buf))
return unsafe_string(pointer(buf))
return GC.@preserve buf unsafe_string(pointer(buf))
end

function index(dev::Device)
Expand Down
4 changes: 2 additions & 2 deletions lib/nvml/system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ function version()

# the version string is too long for Julia to handle, e.g. 11.450.36.06,
# so split off the driver part into the build suffix
ver = unsafe_string(pointer(buf))
ver = GC.@preserve buf unsafe_string(pointer(buf))
parts = parse.(Int, split(ver, '.'))
return VersionNumber(parts[1], 0, 0, (), Tuple(parts[2:end]))
end

function driver_version()
buf = Vector{Cchar}(undef, NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE)
nvmlSystemGetDriverVersion(pointer(buf), length(buf))
return VersionNumber(unsafe_string(pointer(buf)))
return GC.@preserve buf VersionNumber(unsafe_string(pointer(buf)))
end

function cuda_driver_version()
Expand Down

0 comments on commit 123977e

Please sign in to comment.