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

Add gpuId proc on locale #25943

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions modules/internal/ChapelLocale.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ module ChapelLocale {
@chpldoc.nodoc
proc isGpu() : bool { return false; }

// if using a gpu locale return its position in the parent locale's
// `here.gpus` array
proc gpuId : int do return gpuIdImpl();

@chpldoc.nodoc
proc gpuIdImpl() : int {
halt("Can not use 'gpuId' field on a non gpu locale");
return -1;
}

// Part of the required locale interface.
// Commented out because presently iterators are statically bound.
// iter getChildren() : locale {
Expand Down
4 changes: 4 additions & 0 deletions modules/internal/localeModels/gpu/LocaleModel.chpl
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ module LocaleModel {
}

override proc isGpu() : bool { return true; }

override proc gpuIdImpl() : int {
return sid;
}
}

const chpl_emptyLocaleSpace: domain(1) = {1..0};
Expand Down
5 changes: 5 additions & 0 deletions test/gpu/native/multiGPU/gpuId.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var n = 0;
for gpu in here.gpus do on gpu {
assert(gpu.gpuId == n);
n += 1;
}
Empty file.
7 changes: 7 additions & 0 deletions test/gpu/native/multiLocale/gpuId.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coforall loc in Locales do on loc {
var n = 0;
for gpu in here.gpus do on gpu {
assert(gpu.gpuId == n);
n += 1;
}
}
Empty file.
1 change: 1 addition & 0 deletions test/gpu/nongpu/gpuId.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
writeln(here.gpuId);
1 change: 1 addition & 0 deletions test/gpu/nongpu/gpuId.good
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gpuId.chpl:1: error: halt reached - Can not use 'gpuId' field on a non gpu locale