2 * Copyright 1993-2013 NVIDIA Corporation. All rights reserved.
4 * Please refer to the NVIDIA end user license agreement (EULA) associated
5 * with this source code for terms and conditions that govern your use of
6 * this software. Any use, reproduction, disclosure, or distribution of
7 * this software and related documentation outside the terms of the EULA
8 * is strictly prohibited.
12 /* Simple kernel demonstrating atomic functions in device code. */
14 #ifndef _SIMPLEATOMICS_KERNEL_H_
15 #define _SIMPLEATOMICS_KERNEL_H_
17 ////////////////////////////////////////////////////////////////////////////////
18 //! Simple test kernel for atomic instructions
19 //! @param g_idata input data in global memory
20 //! @param g_odata output data in global memory
21 ////////////////////////////////////////////////////////////////////////////////
23 testKernel(int *g_odata)
26 const unsigned int tid = blockDim.x * blockIdx.x + threadIdx.x;
28 // Test various atomic instructions
30 // Arithmetic atomic instructions
33 atomicAdd(&g_odata[0], 10);
35 // Atomic subtraction (final should be 0)
36 atomicSub(&g_odata[1], 10);
39 atomicExch(&g_odata[2], tid);
42 atomicMax(&g_odata[3], tid);
45 atomicMin(&g_odata[4], tid);
47 // Atomic increment (modulo 17+1)
48 atomicInc((unsigned int *)&g_odata[5], 17);
51 atomicDec((unsigned int *)&g_odata[6], 137);
53 // Atomic compare-and-swap
54 atomicCAS(&g_odata[7], tid-1, tid);
56 // Bitwise atomic instructions
59 atomicAnd(&g_odata[8], 2*tid+7);
62 atomicOr(&g_odata[9], 1 << tid);
65 atomicXor(&g_odata[10], tid);
68 #endif // #ifndef _SIMPLEATOMICS_KERNEL_H_