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

Merged
merged 3 commits into from
Oct 1, 2024
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
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;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an unfortunate consequence of adding this here: they are not documented. I believe the locale documentation is in https://chapel-lang.org/docs/main/language/spec/locales.html#locale-methods, and it comes from the record _locale rather than this base implementation class, which is a forwarding field in the record. I believe Jade has recently mentioned that isGpu is also not documented. I believe the same applies for proc gpus.

This is not specific to this PR, and I think we can merge this as is, but could you open an issue about these methods that I think should be documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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