-
Notifications
You must be signed in to change notification settings - Fork 423
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
gpu*Reduce
functions on AMD GPUs (#23950)
Resolves Cray/chapel-private#5609 Continuation from where I left off in #23689. In that PR, I struggled with segfaults with AMD GPUs, so I had to back out of AMD support. Turns out AMD GPUs tend to segfault at execution time if you don't use the right `--offload-arch`, and that the default on the system that I tested this was not right. This PR adds that while compiling the reduction support code in the runtime to remove the blockage. ### Details - The runtime now has `chpl_gpu_can_reduce`/`chpl_gpu_impl_can_reduce` interface that returns true/false depending on whether we can use this cub-based reduction support - Today, it returns false for cpu-as-device mode or ROCm 4.x which doesn't have hipcub - For cases where there's no cub-based reduction, we fallback to regular CPU-based reductions. On ROCm 4.x this means we copy the array to the host and reduce on host. Clearly, this is less than ideal and just a portability stopgap. I hope to drop ROCm 4 support as soon as we can - Adds a new `rocm-utils` header to be able to use `ROCM_VERSION_MAJOR` portably, and to be able to use `ROCM_CALL` in multiple files - Moves `test/gpu/native/noAmd/reduction` directory to `test/gpu/native` and removes `noAmd.skipif` [Reviewed by @stonea] ### Test - [x] nvidia - [x] amd with ROCm 4.2 - [x] amd with ROCm 4.4 - [x] amd with ROCm 5.2 `gpu/native/reduction` only - [x] amd with ROCm 5.4 `gpu/native/reduction` only - [x] cpu `gpu/native/reduction` only
- Loading branch information
Showing
31 changed files
with
181 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2020-2023 Hewlett Packard Enterprise Development LP | ||
* Copyright 2004-2019 Cray Inc. | ||
* Other additional copyright holders may be indicated within. * | ||
* The entirety of this work is licensed under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __HIP_PLATFORM_AMD__ | ||
#define __HIP_PLATFORM_AMD__ | ||
#endif | ||
#include <hip/hip_common.h> | ||
#include <hip/hip_runtime.h> | ||
|
||
#if __has_include(<rocm-core/rocm_version.h>) // 5.x wants this | ||
#include <rocm-core/rocm_version.h> | ||
#elif __has_include(<rocm/rocm_version.h>) // 4.x wants this | ||
#include <rocm/rocm_version.h> | ||
#elif __has_include(<rocm_version.h>) // Deprecated. 5.x used to want this | ||
#include <rocm_version.h> | ||
#elif !defined(ROCM_VERSION_MAJOR) | ||
#define ROCM_VERSION_MAJOR 4 // this is the safe bet | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
extern void chpl_internal_error(const char*); | ||
|
||
|
||
static void chpl_gpu_rocm_check(int err, const char* file, int line) { | ||
if(err == hipErrorContextAlreadyInUse) { return; } | ||
if(err != hipSuccess) { | ||
const int msg_len = 256; | ||
char msg[msg_len]; | ||
|
||
snprintf(msg, msg_len, | ||
"%s:%d: Error calling HIP function: %s (Code: %d)", | ||
file, line, hipGetErrorString((hipError_t)err), err); | ||
|
||
chpl_internal_error(msg); | ||
} | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#define ROCM_CALL(call) do {\ | ||
chpl_gpu_rocm_check((int)call, __FILE__, __LINE__);\ | ||
} while(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion
10
...u/native/noAmd/reduction/largeArrays.chpl → test/gpu/native/reduction/largeArrays.chpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--n=2_000_000_000 | ||
--n=2_000_000_001 | ||
--n=2_147_483_647 | ||
--n=4_000_000_000 | ||
--n=4_000_000_001 | ||
|
||
# Engin: I want to test the following too, but hit unrelated issues on AMD | ||
# https://github.com/chapel-lang/chapel/issues/23934 | ||
# -n=4_294_967_293 | ||
# -n=4_294_967_294 | ||
# -n=4_294_967_295 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.