Created
October 28, 2019 11:08
-
-
Save hayunjong83/8cceee458b8345e355e59e379e629dfe to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
#include <stdint.h> | |
static __device__ __inline__ uint32_t __mysmid(){ | |
uint32_t smid; | |
asm volatile("mov.u32 %0, %%smid;" : "=r"(smid)); | |
return smid; | |
} | |
static __device__ __inline__ uint32_t __mywarpid(){ | |
uint32_t warpid; | |
asm volatile("mov.u32 %0, %%warpid;" : "=r"(warpid)); | |
return warpid; | |
} | |
static __device__ __inline__ uint32_t __mylaneid(){ | |
uint32_t laneid; | |
asm volatile("mov.u32 %0, %%laneid;" : "=r"(laneid)); | |
return laneid; | |
} | |
__global__ void mykernel(){ | |
int idx = threadIdx.x + blockDim.x*blockIdx.x; | |
printf("I am thread %d, my SM ID is %d, my warp ID is %d, and my warp lane is %d\n", | |
idx, __mysmid(), __mywarpid(), __mylaneid()); | |
} | |
int main() | |
{ | |
mykernel<<<4,4>>>(); | |
cudaDeviceSynchronize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment