using namespace std;
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
const int threadsPerBlock = 256;
const int blocksPerGrid = 1024;
const int N = 64;
__global__ void reverse(int *data, int count){
__shared__ int cache[threadsPerBlock];
int tid = threadIdx.x + blockIdx.x * blockDim.x;
int cacheIndex = threadIdx.x;
int tr = count-cacheIndex-1;
if(tid< count/2)
cache[cacheIndex] = data[cacheIndex];
__syncthreads();
data[cacheIndex] = cache[tr];
}
int main(void){
int a[N];
int *devA;
generate(a,N);
cudaMalloc((void**)&devA, N * sizeof(int));
cudaMemcpy(devA, a, N * sizeof(int), cudaMemcpyHostToDevice);
reverse<<<blocksPerGrid,threadsPerBlock>>>(devA,N);
cudaMemcpy(a,devA, N * sizeof(int), cudaMemcpyDeviceToHost);
cout << a[63];
cudaFree(devA);
}
上面的代码并没有颠倒我的相反。这个程序有什么问题?我怎么了?我认为一切都很好。我需要编辑什么才能正常工作?怎么了?