-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][HIP] Add basic HIP atomics #8003
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
75abcef
First commit adding some HIP atomics
8953f41
Adding initial support for HIP atomics
41af655
Removing cmpxchg
263c7a7
Adding compare exchange as well as generic AS
7289005
Update sycl/include/sycl/atomic_ref.hpp
hdelan ad575d4
Add AtomicAdd for FP64
89fb7e6
Updating preprocessor tests
4dfac50
Add comments to test and remove empty line in CMakeLists
85e96b9
Making test cl-std=2.0
33ba670
Add remaining atomic ops
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,9 @@ | ||
// This test checks for the presence of target specific macros for openCL | ||
// | ||
// RUN: %clang_cc1 %s -E -dM -triple amdgcn-amdhsa-amdhsa \ | ||
// RUN: | FileCheck --check-prefix=CHECK-AMDGPU %s | ||
hdelan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-AMDGPU: #define __HIP_MEMORY_SCOPE_AGENT | ||
// CHECK-AMDGPU: #define __HIP_MEMORY_SCOPE_SINGLETHREAD | ||
// CHECK-AMDGPU: #define __HIP_MEMORY_SCOPE_SYSTEM | ||
// CHECK-AMDGPU: #define __HIP_MEMORY_SCOPE_WAVEFRONT | ||
// CHECK-AMDGPU: #define __HIP_MEMORY_SCOPE_WORKGROUP |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,57 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "atomic_helpers.h" | ||
#include <spirv/spirv.h> | ||
#include <spirv/spirv_types.h> | ||
|
||
AMDGPU_ATOMIC(_Z18__spirv_AtomicIAdd, int, i, __hip_atomic_fetch_add) | ||
AMDGPU_ATOMIC(_Z18__spirv_AtomicIAdd, unsigned int, j, __hip_atomic_fetch_add) | ||
AMDGPU_ATOMIC(_Z18__spirv_AtomicIAdd, long, l, __hip_atomic_fetch_add) | ||
AMDGPU_ATOMIC(_Z18__spirv_AtomicIAdd, unsigned long, m, __hip_atomic_fetch_add) | ||
AMDGPU_ATOMIC(_Z21__spirv_AtomicFAddEXT, float, f, __hip_atomic_fetch_add) | ||
|
||
#define AMDGPU_ATOMIC_FP64_ADD_IMPL(AS, AS_MANGLED, SUB1, SUB2) \ | ||
_CLC_DEF long \ | ||
_Z29__spirv_AtomicCompareExchangeP##AS_MANGLED##lN5__spv5Scope4FlagENS##SUB1##_19MemorySemanticsMask4FlagES##SUB2##_ll( \ | ||
volatile AS long *, enum Scope, enum MemorySemanticsMask, \ | ||
enum MemorySemanticsMask, long desired, long expected); \ | ||
_CLC_DEF long \ | ||
_Z18__spirv_AtomicLoadP##AS_MANGLED##KlN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagE( \ | ||
const volatile AS long *, enum Scope, enum MemorySemanticsMask); \ | ||
_CLC_DEF double \ | ||
_Z21__spirv_AtomicFAddEXTP##AS_MANGLED##dN5__spv5Scope4FlagENS##SUB1##_19MemorySemanticsMask4FlagEd( \ | ||
volatile AS double *p, enum Scope scope, \ | ||
enum MemorySemanticsMask semantics, double val) { \ | ||
int atomic_scope = 0, memory_order = 0; \ | ||
volatile AS long *int_pointer = (volatile AS long *)p; \ | ||
long old_int_val = 0, new_int_val = 0; \ | ||
do { \ | ||
old_int_val = \ | ||
_Z18__spirv_AtomicLoadP##AS_MANGLED##KlN5__spv5Scope4FlagENS1_19MemorySemanticsMask4FlagE( \ | ||
int_pointer, scope, semantics); \ | ||
double new_double_val = *(double *)&old_int_val + val; \ | ||
new_int_val = *(long *)&new_double_val; \ | ||
} while ( \ | ||
_Z29__spirv_AtomicCompareExchangeP##AS_MANGLED##lN5__spv5Scope4FlagENS##SUB1##_19MemorySemanticsMask4FlagES##SUB2##_ll( \ | ||
int_pointer, scope, semantics, semantics, new_int_val, \ | ||
old_int_val) != old_int_val); \ | ||
\ | ||
return *(double *)&old_int_val; \ | ||
} | ||
|
||
#ifdef cl_khr_int64_base_atomics | ||
AMDGPU_ATOMIC_FP64_ADD_IMPL(global, U3AS1, 1, 5) | ||
AMDGPU_ATOMIC_FP64_ADD_IMPL(local, U3AS3, 1, 5) | ||
AMDGPU_ATOMIC_FP64_ADD_IMPL(, , 0, 4) | ||
#endif | ||
|
||
#undef AMDGPU_ATOMIC | ||
hdelan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#undef AMDGPU_ATOMIC_IMPL | ||
#undef AMDGPU_ATOMIC_FP64_ADD_IMPL | ||
#undef GET_ATOMIC_SCOPE_AND_ORDER |
This file contains hidden or 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,20 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "atomic_helpers.h" | ||
#include <spirv/spirv.h> | ||
#include <spirv/spirv_types.h> | ||
|
||
AMDGPU_ATOMIC(_Z17__spirv_AtomicAnd, int, i, __hip_atomic_fetch_and) | ||
AMDGPU_ATOMIC(_Z17__spirv_AtomicAnd, unsigned int, j, __hip_atomic_fetch_and) | ||
AMDGPU_ATOMIC(_Z17__spirv_AtomicAnd, long, l, __hip_atomic_fetch_and) | ||
AMDGPU_ATOMIC(_Z17__spirv_AtomicAnd, unsigned long, m, __hip_atomic_fetch_and) | ||
|
||
#undef AMDGPU_ATOMIC | ||
#undef AMDGPU_ATOMIC_IMPL | ||
#undef GET_ATOMIC_SCOPE_AND_ORDER |
This file contains hidden or 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,51 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "atomic_helpers.h" | ||
#include <spirv/spirv.h> | ||
#include <spirv/spirv_types.h> | ||
|
||
#define AMDGPU_ATOMIC_CMPXCHG_IMPL(TYPE, TYPE_MANGLED, AS, AS_MANGLED, SUB1, \ | ||
SUB2) \ | ||
_CLC_DEF TYPE \ | ||
_Z29__spirv_AtomicCompareExchangeP##AS_MANGLED##TYPE_MANGLED##N5__spv5Scope4FlagENS##SUB1##_19MemorySemanticsMask4FlagES##SUB2##_##TYPE_MANGLED##TYPE_MANGLED( \ | ||
volatile AS TYPE *p, enum Scope scope, \ | ||
enum MemorySemanticsMask success_semantics, \ | ||
enum MemorySemanticsMask failure_semantics, TYPE desired, \ | ||
TYPE expected) { \ | ||
int atomic_scope = 0, memory_order_success = 0, memory_order_failure = 0; \ | ||
GET_ATOMIC_SCOPE_AND_ORDER(scope, atomic_scope, success_semantics, \ | ||
memory_order_success) \ | ||
GET_ATOMIC_SCOPE_AND_ORDER(scope, atomic_scope, failure_semantics, \ | ||
memory_order_failure) \ | ||
TYPE original_val = *p; \ | ||
bool success = __hip_atomic_compare_exchange_strong( \ | ||
p, &expected, desired, memory_order_success, memory_order_failure, \ | ||
atomic_scope); \ | ||
\ | ||
return success ? original_val : *p; \ | ||
} | ||
|
||
#define AMDGPU_ATOMIC_CMPXCHG(TYPE, TYPE_MANGLED) \ | ||
AMDGPU_ATOMIC_CMPXCHG_IMPL(TYPE, TYPE_MANGLED, global, U3AS1, 1, 5) \ | ||
AMDGPU_ATOMIC_CMPXCHG_IMPL(TYPE, TYPE_MANGLED, local, U3AS3, 1, 5) \ | ||
AMDGPU_ATOMIC_CMPXCHG_IMPL(TYPE, TYPE_MANGLED, , , 0, 4) | ||
|
||
AMDGPU_ATOMIC_CMPXCHG(int, i) | ||
AMDGPU_ATOMIC_CMPXCHG(unsigned int, j) | ||
AMDGPU_ATOMIC_CMPXCHG(long, l) | ||
AMDGPU_ATOMIC_CMPXCHG(unsigned long, m) | ||
AMDGPU_ATOMIC_CMPXCHG(float, f) | ||
|
||
// TODO implement for fp64 | ||
|
||
#undef AMDGPU_ATOMIC | ||
#undef AMDGPU_ATOMIC_IMPL | ||
#undef AMDGPU_ATOMIC_CPMXCHG | ||
#undef AMDGPU_ATOMIC_CPMXCHG_IMPL | ||
#undef GET_ATOMIC_SCOPE_AND_ORDER |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.