cublas地址超出特定矩阵大小的范围

当我运行以下代码来计算矩阵乘法y = X * B时:

#include <iostream>
#include <Eigen/Dense>
#include <cuda_runtime.h>
#include "cublas_v2.h"


using namespace Eigen;

int main(){
  int N = 240000;
  int K = 3;
  int p = 9700;

  MatrixXf X_host = MatrixXf::Zero(N, p);
  MatrixXf B_host = MatrixXf::Zero(p, K);
  MatrixXf y_host(N, K);

  float *X_dev;
  float *B_dev;
  float *y_dev;

  cudaMalloc((void**)&X_dev, sizeof(float) * p * N);
  cudaMalloc((void**)&B_dev, sizeof(float) * p * K);
  cudaMalloc((void**)&y_dev, sizeof(float) * N * K);

  cudaMemcpy(X_dev, X_host.data(), sizeof(float)*p*N, cudaMemcpyHostToDevice);
  cudaMemcpy(B_dev, B_host.data(), sizeof(float)*p*K, cudaMemcpyHostToDevice);

  cublasHandle_t handle;
  cublasCreate(&handle);

  cudaError_t error = cudaGetLastError();
  if(error != cudaSuccess)
  {
    std::cout << "CUDA error: " << cudaGetErrorString(error) << std::endl;
  } else {
    std::cout << "No problem before cublas call\n";
  }

  float alpha = 1.0;
  float beta = 0.0;
  cublasSgemm(handle, CUBLAS_OP_N, CUBLAS_OP_N, 
              N, K, p, &alpha, 
              X_dev, N, B_dev, p, &beta, y_dev, N);

  cudaDeviceSynchronize();
  error = cudaGetLastError();
  if(error != cudaSuccess)
  {
      std::cout << "CUDA error: " << cudaGetErrorString(error) << std::endl;
  }

  cublasDestroy(handle);
  cudaFree(X_dev);
  cudaFree(B_dev);
  cudaFree(y_dev);
  return 0;
}

I got this error from cuda-memcheck:

========= Invalid __global__ read of size 4
=========     at 0x00000a88 in void gemmSN_NN_kernel<float, int=256, int=4, int=2, int=8, int=4, int=4, cublasGemvTensorStridedBatched<float const >, cublasGemvTensorStridedBatched<float>>(cublasGemmSmallNParams<float const , cublasGemvTensorStridedBatched<float const >, float>)
=========     by thread (223,0,0) in block (190,0,0)
=========     Address 0x2b660269807c is out of bounds

大约有100个这样的地址超出范围错误,并且它们的数量在运行之间有所不同。当我将K设置为更大的数字(例如10)时,问题消失了。任何人都知道会发生什么事吗?我在CentOS 7上使用CUDA 10.1,P100。谢谢!

评论