我正在使用 nvprof 来获取以下 CUDA 代码的全局内存访问次数。内核中加载次数为 36(访问 d_In 数组),内核中存储次数为 36+36(访问 d_Out 数组和 d_rows 数组)。因此,全局内存加载的总数为 36,全局内存存储的数量为 72。但是,当我使用 nvprof CUDA 分析器分析代码时,它会报告以下内容:(基本上我想计算全局内存访问的计算(CGMA) 比率)
1 gld_transactions Global Load Transactions 6 6 6
1 gst_transactions Global Store Transactions 11 11 11
1 l2_read_transactions L2 Read Transactions 133 133 133
1 l2_write_transactions L2 Write Transactions 24 24 24
#include <stdio.h>
#include "cuda_profiler_api.h"
__constant__ int crows;
__global__ void kernel(double *d_In, double *d_Out, int *d_rows){
int tx=threadIdx.x;
int bx=blockIdx.x;
int n=bx*blockDim.x+tx;
if(n < 36){
d_Out[n]=d_In[n]+1;
d_rows[n]=crows;
}
return;
}
int main(int argc,char **argv){
double I[36]={1,5,9,2,6,10,3,7,11,4,8,12,13,17,21,14,18,22,15,19,23,16,20,24,25,29,33,26,30,34,27,31,35,28,32,36};
double *d_In;
double *d_Out;
int *d_rows;
double Iout[36];
int rows=5;
int h_rows[36];
cudaMemcpyToSymbol(crows,&rows,sizeof(int));
cudaMalloc(&d_In,sizeof(double)*36);
cudaMalloc(&d_Out,sizeof(double)*36);
cudaMalloc(&d_rows,sizeof(int)*36);
cudaMemcpy(d_In,I,sizeof(double)*36,cudaMemcpyHostToDevice);
dim3 dimGrid(4,1,1);
dim3 dimBlock(10,1,1);
cudaProfilerStart();
kernel<<<dimGrid,dimBlock>>>(d_In,d_Out,d_rows);
cudaProfilerStop();
cudaMemcpy(Iout,d_Out,sizeof(double)*36,cudaMemcpyDeviceToHost);
cudaMemcpy(h_rows,d_rows,sizeof(int)*36,cudaMemcpyDeviceToHost);
int i;
for(i=0;i<36;i++)
printf("%f %d\n",Iout[i],h_rows[i]);
}
有人能帮我吗?谢谢