【问题标题】:How to have a matrix as paramater when working with CUDA and Matlab使用 CUDA 和 Matlab 时如何将矩阵作为参数
【发布时间】:2014-03-16 15:04:21
【问题描述】:

我试图弄清楚如何将矩阵从 Matlab 传递到 C++ CUDA 文件 (*.ptx)。 我想在每个线程中以不同的方式处理矩阵!我绝对不想将矩阵拆分为不同的线程!我希望每个线程都有相同的矩阵!

Matlab and CUDA (C++)

我尝试过类似的方法:

_global_ void radialAverage(int* image[][]) {
  ...
}

但它没有用。我收到以下错误:

kernel.cu(8): error: an array may not have elements of this type
1 error detected in the compilation of "C:/Users/ADMINI~1/AppData/Loca/Temp/tmpxft_00000c44_00000000-8_kernel.cpp1.ii".

你能想出什么办法吗?或者有可能吗?

顺便说一句:我没有使用任何 C++ 库,只有 CUDA-Api。

【问题讨论】:

  • 你能发布你收到的错误吗?
  • kernel.cu(8): error: an array may not have elements of this type 1 error detected in the compilation of "C:/Users/ADMINI~1/AppData/Local/Temp/tmpxft_00000c44_00000000 -8_kernel.cpp1.ii"。

标签: c++ windows matlab matrix cuda


【解决方案1】:

定义内核以从 Matlab 传递矩阵的正确方法在您在问题中链接到的页面上清楚地显示(多次)。

总而言之,像这样定义内核(Matlab gpuArray 自动作为设备指针传递给内核):

__global__ void radialAverage(int* image) {
  ...
}

使用工具箱中的CUDAKernel 检索内核后,从您的Matlab 矩阵创建一个整数gpuArray,并将其传递给内核函数。

【讨论】:

  • 当我尝试你的解决方案时,我得到了错误:“kernel.cu(55): error: expression must have pointer-to-object type” 我认为这是因为他不接受指针作为一个多维数组!
  • 您不能在 CUDA 内核中对指针传递的数组使用 [][] 样式索引。这个错误实际上是一个不同的问题——“如何在内核中索引 Matlab 数组”。请用一些真实的代码更新您的问题.....
  • 好的,这就是我想要访问数据的方式!谢谢您的帮助!我想我会为此打开一个新问题:D
猜你喜欢
  • 2016-06-04
  • 2013-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 2019-04-08
相关资源
最近更新 更多