Skip to content

Commit 5b470c4

Browse files
authored
Protect against occupancy calculations with very large numbers. (#2666)
1 parent 6ec9913 commit 5b470c4

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

lib/cudadrv/occupancy.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function launch_configuration(fun::CuFunction; shmem::Union{Integer,Base.Callabl
5757
max_threads::Integer=0)
5858
blocks_ref = Ref{Cint}()
5959
threads_ref = Ref{Cint}()
60+
max_threads = clamp(max_threads, Cint)
6061
if isa(shmem, Integer)
6162
cuOccupancyMaxPotentialBlockSize(blocks_ref, threads_ref, fun, C_NULL, shmem, max_threads)
6263
elseif Sys.ARCH == :x86 || Sys.ARCH == :x86_64

test/core/cudadrv.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ let md = CuModuleFile(joinpath(@__DIR__, "ptx/dummy.ptx"))
819819
launch_configuration(dummy)
820820
launch_configuration(dummy; shmem=64)
821821
launch_configuration(dummy; shmem=64, max_threads=64)
822+
launch_configuration(dummy; shmem=64, max_threads=typemax(Cint)+1)
822823

823824
let cb_calls = 0
824825
launch_configuration(dummy; shmem=threads->(cb_calls += 1; 0))

0 commit comments

Comments
 (0)