-
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 #729 from CHIP-SPV/rtdevlib-ballot
Link __ballot() implementation at runtime
- Loading branch information
Showing
16 changed files
with
159 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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. | ||
*/ | ||
// __ballot implementation with sub_group_ballot(). | ||
|
||
// SPIR-V requirements: 1.3+ unless environment supports | ||
// cl_khr_subgroup_ballot or ZE_extension_subgroups. | ||
// OpenCL requirements: cl_khr_subgroup_ballot. | ||
// Level0 requirements: ZE_extension_subgroups. | ||
|
||
#define OVERLOADED __attribute__((overloadable)) | ||
|
||
OVERLOADED ulong __chip_ballot(int predicate) { | ||
#if DEFAULT_WARP_SIZE <= 32 | ||
return sub_group_ballot(predicate).x; | ||
#else | ||
return sub_group_ballot(predicate).x | (sub_group_ballot(predicate).y << 32); | ||
#endif | ||
} |
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
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,42 @@ | ||
#include "CHIPDriver.hh" | ||
#include <hip/hip_runtime.h> | ||
#include <cstdint> | ||
#include <cstdlib> | ||
|
||
__global__ void k(uint64_t *Out, uint64_t In) { | ||
auto Votes = __ballot((In >> threadIdx.x) & 1u); | ||
if (threadIdx.x == 0) | ||
*Out = Votes; | ||
} | ||
|
||
void checkBallot(unsigned BlockSize, uint64_t In) { | ||
uint64_t *OutD, OutH = ~In; | ||
(void)hipMalloc(&OutD, sizeof(uint64_t)); | ||
k<<<1, BlockSize>>>(OutD, In); | ||
(void)hipMemcpy(&OutH, OutD, sizeof(uint64_t), hipMemcpyHostToDevice); | ||
|
||
hipDeviceProp_t Props{}; | ||
(void)hipGetDeviceProperties(&Props, 0); | ||
|
||
if (Props.warpSize < 64 && OutH >> Props.warpSize) { | ||
printf("Error: Garbage bits in the __ballot result!\n"); | ||
exit(1); | ||
} | ||
|
||
if (OutH != In) { | ||
printf("BlockSize=%u:\nError: Expected '%lu'. Got '%lu'\n", BlockSize, In, | ||
OutH); | ||
exit(1); | ||
} | ||
(void)hipFree(OutD); | ||
} | ||
|
||
int main() { | ||
if (!Backend->getActiveDevice()->hasBallot()) { | ||
printf("SKIP: device does not support __ballot()\n"); | ||
return 2; | ||
} | ||
|
||
checkBallot(32, 0xBADF00D1); | ||
return 0; | ||
} |