Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect compute-exclusive mode and adjust testing. #2166

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions test/core/cudadrv.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,34 @@

ctx = current_context()
dev = current_device()
exclusive = attribute(dev, CUDA.DEVICE_ATTRIBUTE_COMPUTE_MODE) == CUDA.CU_COMPUTEMODE_EXCLUSIVE_PROCESS

synchronize(ctx)

let ctx2 = CuContext(dev)
@test ctx2 == current_context() # ctor implicitly pushes
activate(ctx)
@test ctx == current_context()
if !exclusive
let ctx2 = CuContext(dev)
@test ctx2 == current_context() # ctor implicitly pushes
activate(ctx)
@test ctx == current_context()

@test device(ctx2) == dev
@test device(ctx2) == dev

CUDA.unsafe_destroy!(ctx2)
end

let global_ctx2 = nothing
CuContext(dev) do ctx2
@test ctx2 == current_context()
@test ctx != ctx2
global_ctx2 = ctx2
CUDA.unsafe_destroy!(ctx2)
end
@test !CUDA.isvalid(global_ctx2)
@test ctx == current_context()

@test device(ctx) == dev
@test current_device() == dev
device_synchronize()
let global_ctx2 = nothing
CuContext(dev) do ctx2
@test ctx2 == current_context()
@test ctx != ctx2
global_ctx2 = ctx2
end
@test !CUDA.isvalid(global_ctx2)
@test ctx == current_context()

@test device(ctx) == dev
@test current_device() == dev
device_synchronize()
end
end

end
Expand Down
14 changes: 10 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ function gpu_entry(dev)
id = deviceid(dev)
name = CUDA.name(dev)
uuid = CUDA.uuid(dev)
cap = CUDA.capability(dev)
mig = uuid != CUDA.parent_uuid(dev)
(; id, name, cap, uuid="$(mig ? "MIG" : "GPU")-$uuid")
cap = capability(dev)
mig = uuid != parent_uuid(dev)
compute_mode = attribute(dev, CUDA.DEVICE_ATTRIBUTE_COMPUTE_MODE)
(; id, name, cap, uuid="$(mig ? "MIG" : "GPU")-$uuid", compute_mode)
end
gpus = if do_gpu_list
# parse the list of GPUs
Expand All @@ -135,8 +136,9 @@ gpus = if do_gpu_list
end
else
# find all GPUs
map(gpu_entry, CUDA.devices())
map(gpu_entry, devices())
end
filter!(gpu->gpu.compute_mode != CUDA.CU_COMPUTEMODE_PROHIBITED, gpus)
@info("Testing using device " * join(map(gpu->"$(gpu.id) ($(gpu.name))", gpus), ", ", " and ") *
". To change this, specify the `--gpus` argument to the tests, or set the `CUDA_VISIBLE_DEVICES` environment variable.")
ENV["CUDA_VISIBLE_DEVICES"] = join(map(gpu->gpu.uuid, gpus), ",")
Expand All @@ -148,6 +150,10 @@ if !set_jobs
jobs = min(cpu_jobs, memory_jobs)
end
@info "Running $jobs tests in parallel. If this is too many, specify the `--jobs` argument to the tests, or set the `JULIA_CPU_THREADS` environment variable."
if first(gpus).compute_mode == CUDA.CU_COMPUTEMODE_EXCLUSIVE_PROCESS
@warn "Running tests on a GPU in exclusive mode; reducing parallelism to 1."
jobs = 1
end

# add workers
const test_exeflags = Base.julia_cmd()
Expand Down