How can I run my own CUDA code?

조회 수: 2 (최근 30일)
Question Mr
Question Mr 2021년 6월 6일
댓글: Question Mr 2021년 6월 7일
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)

채택된 답변

Edric Ellis
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 CenterFile 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!

Translated by