Мой тестовый код: < /p>
Код: Выделить всё
#define SIZE 1024
__global__ void test_shfl_sync(int* x, int N){
int tid = threadIdx.x;
int val = tid ;
x[tid] = __shfl_sync(0xffffffff, val, 1);
__syncwarp();
}
int main(){
int* x = (int *)malloc(sizeof(int) * SIZE);
int* y = (int *)malloc(sizeof(int) * SIZE);
for(int i = 0; i < SIZE; i++){
x[i] = i;
y[i] = 0;
}
int *d_x1;
cudaMalloc(&d_x1, sizeof(int) * SIZE);
cudaMemcpy(d_x1, x, sizeof(int) * SIZE, cudaMemcpyHostToDevice);
int THREAD_NUM_PER_BLOCK = 64;
int block_num = (SIZE + THREAD_NUM_PER_BLOCK - 1) / THREAD_NUM_PER_BLOCK;
test_shfl_sync(d_x1, SIZE);
cudaDeviceSynchronize();
cudaMemcpy(y, d_x1, sizeof(int) * SIZE, cudaMemcpyDeviceToHost);
for(int i = 0; i < 64; i++){
printf("%d ", y[i]);
}
printf("\n");
}
< /code>
А печать: 1 1 ... 1 33 33 ... 33 < /code> (есть тридцать два 1 и тридцать два 33).
Затем я изменяю ядро: < /p>
__global__ void test_shfl_sync(int* x, int N){
int tid = threadIdx.x;
int val = tid ;
x[tid] = __shfl_sync(0xfffffffe, val, 1);
__syncwarp();
}
< /code>
lane 0 замаскирована, поэтому ожидаемая печать:0 1 1 ... 1 32 33 33 ... 33Почему это произошло?
Подробнее здесь: https://stackoverflow.com/questions/797 ... -functions