Skip to content

Commit 11a075f

Browse files
authored
[SYCLomatic #595] Add test case for migration of atomicDec (#235)
Signed-off-by: chenwei.sun <[email protected]>
1 parent 61f9482 commit 11a075f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

samples/src/atomic_test/cuda/atomic_test.cu

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
#include <stdio.h>
1111
#include <cuda.h>
1212
typedef unsigned int dataType;
13-
#define ArraySize 10
13+
#define ArraySize 11
1414
#define numThreads 256
1515
#define numBlocks 64
1616

17+
const dataType Limit = 139;
18+
19+
1720
__global__ void atomic_test_kernel(dataType *ddata) {
1821

1922
unsigned int tid = blockDim.x * blockIdx.x + threadIdx.x;
@@ -38,7 +41,8 @@ __global__ void atomic_test_kernel(dataType *ddata) {
3841
atomicXor(&ddata[8], tid);
3942
// Inc test
4043
atomicInc(&ddata[9], 0);
41-
44+
// Dec test
45+
atomicDec(&ddata[10], Limit);
4246
}
4347

4448
int main(int argc, char **argv) {
@@ -60,7 +64,7 @@ int main(int argc, char **argv) {
6064
Hdata[7] = 0; // or
6165
Hdata[8] = 0xff; // xor
6266
Hdata[9] = 10; // inc
63-
67+
Hdata[10] = 0; // dec
6468

6569
// allocate device memory for result
6670
dataType *Ddata;
@@ -116,12 +120,21 @@ int main(int argc, char **argv) {
116120
err = -1;
117121
printf("atomicXor test failed , %d \n", Hdata2[8]);
118122
}
119-
// check Xor Hdata2[9]
123+
// check Inc Hdata2[9]
120124
if (Hdata2[9] != 0) {
121125
err = -1;
122-
printf("atomicInc test failed , %d \n", Hdata2[8]);
126+
printf("atomicInc test failed , %d \n", Hdata2[9]);
123127
}
124128

129+
dataType val = 0;
130+
for (int i = 0; i < 256 * 64; ++i) {
131+
val = ((val == 0) || (val > Limit)) ? Limit : val - 1;
132+
}
133+
// check dec Hdata2[10]
134+
if (Hdata2[10] != val) {
135+
err = -1;
136+
printf("atomicDec test failed , %d \n", Hdata2[10]);
137+
}
125138

126139
cudaFree(Ddata);
127140
printf("atomic test completed, returned %s\n", err == 0 ? "OK" : "ERROR");

0 commit comments

Comments
 (0)