How can I run my own CUDA code?
2 次查看(过去 30 天)
显示 更早的评论
I have a ptx, and a cu files and I want to implement into my code but I dont know how.
I have read this section but I dont understand how can I call my code
I have created a kernel:
like this:
k = parallel.gpu.CUDAKernel('kernel.ptx','kernel.cu');
and that's all
here is the inputs what use the cuda code:
limit = 50;
m = 4;
and here is how can I call
kernel<<<grid, block>>>(surfacePoints, d_surface_x, d_surface_y, d_surface_z,
d_electrodes_x, d_electrodes_y, d_electrodes_z,
d_potential, d_laplacian, d_mX, limit, m)
So my problem is, how can I implement a cuda code into the matlab script use that values (the d_ values are known)
0 个评论
采纳的回答
Edric Ellis
2021-6-7
To call the kernel, you must first set up the ThreadBlockSize and GridSize properties of k. See this page for more https://www.mathworks.com/help/parallel-computing/cudakernel.html . Then, you call the feval method, supplying either standard MATLAB arrays or gpuArray data for each input. something a little bit like this:
k.ThreadBlockSize = <>;
k.GridSize = <>;
feval(k, d_surface_x, ... % d_surface_x is a standard array or a gpuArray
... % more inputs
limit, m);
There is another option instead of using CUDAKernel that might be more appropriate: use cudamex instead.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!