mexcuda Compile CUDA code with child kernels
古いコメントを表示
Dear,
I cannot manage to get a cuda mex code compiled and running if I need to run a Child Kernel from the Parent kernel (both cuda threads).
Let me outline the code:
#include "mex.h"
#include<stdlib.h>
#include<stdio.h>
#include <cuda_runtime.h>
#define GRIDx 32
#define BLOCKx 32
/*g_scal scales y = alpha*y */
__global__ void g_scal(double *y, double alpha, int n){
int tid = blockIdx.x * blockDim.x + threadIdx.x;
for(int i = tid; i < n; i+=blockDim.x*gridDim.x){
y[i] = alpha*y[i];
}
}
__global__ void mainKernel(double *x, double a, int n){
//this kernel call is always invoked as <<<1,1,0,streamId>>>, so threadIdx.x = 0
g_scal<<<GRIDx, BLOCKx>>>(x, a, n);
cudaDeviceSynchronize();
//yes for the full example, I need device synchronize mid kernel call. I am aware of the deprecated issue
}
extern "C" void launchKernel(double *x, double a, int n){
//allocate gpu memory, memcpy
//invoke, lets leave the streams alone for now
mainKernel<<<1,1>>>(g_x, a, n);
cudaDeviceSynchronize();
//free memory
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
//Get pointers and cast, call launchKernel and define outputs
}
OK, so the point is, everything manages to compile in my own windows terminal just fine (omitting the mexFunction, since I cannot link mex.h correctly). However, no matter what I seem to do, in the end I always get the
error LNK2019: unresolved external symbol
__fatbinwrap_e05b72bc_22_cuda_device_runtime_cu_66a51b0c_63316 referenced in function
__cudaRegisterLinkedBinary_e05b72bc_22_cuda_device_runtime_cu_66a51b0c_63316
cuADMMsolver.mexw64 : fatal error LNK1120: 1 unresolved externals
Error. Here is the mex line (in MATLAB):
mexcuda -v -dynamic -DCUDA_FORCE_CDP1_IF_SUPPORTED cuADMMsolver.cu '-LC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.2\lib\x64' -lcudadevrt -lcudart_static -lcuda NVCC_FLAGS=-rdc=true NVCC_FLAGS=-arch=compute_50
Now, online I found that much of these problems related to not linking -lcudadevrt, which I am doing very explicitly. Does anyone know what is going wrong?
Thanks in advance
-Peter
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で MATLAB Compiler についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!