-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #693 from CHIP-SPV/rtdevlib
Add capability based HIP device library link
- Loading branch information
Showing
31 changed files
with
7,119 additions
and
3,624 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2023 chipStar developers | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
// Implementations for emulated 64-bit floating point atomic add operations. | ||
|
||
#ifndef __opencl_c_generic_address_space | ||
#error __opencl_c_generic_address_space needed! | ||
#endif | ||
|
||
#define OVERLOADED __attribute__((overloadable)) | ||
|
||
/* This code is adapted from AMD's HIP sources */ | ||
static OVERLOADED double __chip_atomic_add_f64(volatile local double *address, | ||
double val) { | ||
volatile local ulong *uaddr = (volatile local ulong *)address; | ||
ulong old = *uaddr; | ||
ulong r; | ||
|
||
do { | ||
r = old; | ||
old = atom_cmpxchg(uaddr, r, as_ulong(val + as_double(r))); | ||
} while (r != old); | ||
|
||
return as_double(r); | ||
} | ||
|
||
static OVERLOADED double __chip_atomic_add_f64(volatile global double *address, | ||
double val) { | ||
volatile global ulong *uaddr = (volatile global ulong *)address; | ||
ulong old = *uaddr; | ||
ulong r; | ||
|
||
do { | ||
r = old; | ||
old = atom_cmpxchg(uaddr, r, as_ulong(val + as_double(r))); | ||
} while (r != old); | ||
|
||
return as_double(r); | ||
} | ||
|
||
double __chip_atomic_add_f64(generic double *address, double val) { | ||
volatile global double *gi = to_global(address); | ||
if (gi) | ||
return __chip_atomic_add_f64(gi, val); | ||
volatile local double *li = to_local(address); | ||
if (li) | ||
return __chip_atomic_add_f64(li, val); | ||
return 0; | ||
} | ||
|
||
double __chip_atomic_add_system_f64(generic double *address, double val) { | ||
return __chip_atomic_add_f64(address, val); | ||
} |
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,50 @@ | ||
/* | ||
* Copyright (c) 2023 chipStar developers | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
// Implementations for 64-bit floating point atomic operations using | ||
// OpenCL built-in extension. | ||
|
||
#ifndef __opencl_c_generic_address_space | ||
#error __opencl_c_generic_address_space needed! | ||
#endif | ||
|
||
#if !defined(__opencl_c_ext_fp64_global_atomic_add) || \ | ||
!defined(__opencl_c_ext_fp64_local_atomic_add) | ||
#error cl_ext_float_atomics needed! | ||
#endif | ||
|
||
#define OVERLOADED __attribute__((overloadable)) | ||
|
||
/* https://registry.khronos.org/OpenCL/extensions/ext/cl_ext_float_atomics.html | ||
*/ | ||
#define DEF_CHIP_ATOMIC2F_ORDER_SCOPE(NAME, OP, ORDER, SCOPE) \ | ||
double __chip_atomic_##NAME##_f64(double *address, double i) { \ | ||
return atomic_##OP##_explicit((volatile __generic double *)address, i, \ | ||
memory_order_##ORDER, memory_scope_##SCOPE); \ | ||
} | ||
|
||
#define DEF_CHIP_ATOMIC2F(NAME, OP) \ | ||
DEF_CHIP_ATOMIC2F_ORDER_SCOPE(NAME, OP, relaxed, device) \ | ||
DEF_CHIP_ATOMIC2F_ORDER_SCOPE(NAME##_system, OP, relaxed, all_svm_devices) \ | ||
DEF_CHIP_ATOMIC2F_ORDER_SCOPE(NAME##_block, OP, relaxed, work_group) | ||
|
||
DEF_CHIP_ATOMIC2F(add, fetch_add); |
Oops, something went wrong.