Created
July 26, 2013 01:03
-
-
Save allanmac/6085213 to your computer and use it in GitHub Desktop.
Namespaces and shared structs.
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
#define KERNEL_QUALIFIERS __global__ | |
#define VOLATILE volatile | |
#define DEVICE_INTRINSIC_QUALIFIERS __device__ __forceinline__ | |
#define DEVICE_STATIC_FUNCTION_QUALIFIERS static DEVICE_FUNCTION_QUALIFIERS | |
#define DEVICE_STATIC_INTRINSIC_QUALIFIERS static DEVICE_INTRINSIC_QUALIFIERS | |
// | |
// | |
// | |
DEVICE_STATIC_INTRINSIC_QUALIFIERS | |
unsigned int laneId() | |
{ | |
unsigned int id; | |
asm("mov.u32 %0, %%laneid;" : "=r"(id)); | |
return id; | |
} | |
// | |
// | |
// | |
namespace foo | |
{ | |
VOLATILE __shared__ struct | |
{ | |
float v[32]; | |
} shared; | |
KERNEL_QUALIFIERS | |
void | |
baz(const float* const vin, float* const vout) | |
{ | |
shared.v[laneId()] = vin[threadIdx.x]; | |
__syncthreads(); | |
vout[threadIdx.x] = shared.v[laneId()^31]; | |
} | |
} | |
// | |
// | |
// | |
namespace bar | |
{ | |
VOLATILE __shared__ struct | |
{ | |
double v[32]; | |
} shared; | |
KERNEL_QUALIFIERS | |
void | |
baz(const double* const vin, double* const vout) | |
{ | |
shared.v[laneId()] = vin[threadIdx.x]; | |
__syncthreads(); | |
vout[threadIdx.x] = shared.v[laneId()^31]; | |
} | |
} | |
// | |
// | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiled with:
nvcc -m 32 -arch sm_35 -Xptxas=-v,-abi=no -cubin namespace.cu