作者:木棉 | 来源:互联网 | 2022-12-07 04:53
vscode-cpptools是否有任何方法可以抑制“ <<<>>>”错误。
我在中将“ * .cu”与“ cpp”相关联setting.json
。
// use normal c++ syntax highlighting for CUDA files
"files.associations": {"*.cu": "cpp"},
并且工作正常,除了一个问题, kernel execution configuration parameters surrounded by <<>>
被误认为是错误expected an expression
dim3 dimGrid(2, 2, 1);
dim3 dimBlock(width / 2, width / 2, 1);
MatrixMulKernel<<>>(d_M, d_N, d_P, width);
任何建议
1> BugKiller..:
搜寻了几个小时,找不到完美的解决方案,但找到了一些解决方法。
我在这里总结:
通过编辑对CUDA文件使用普通的c ++语法突出显示setting.json
在程序中包含必要的CUDA标头
包括虚拟头以解决方法INTELLISENSE
波纹管是一个具体的例子
setting.json
"files.associations": {
"*.cu": "cpp",
"*.cuh": "cpp"
}
cudaDmy.cuh
#pragma once
#ifdef __INTELLISENSE__
void __syncthreads(); // workaround __syncthreads warning
#define KERNEL_ARG2(grid, block)
#define KERNEL_ARG3(grid, block, sh_mem)
#define KERNEL_ARG4(grid, block, sh_mem, stream)
#else
#define KERNEL_ARG2(grid, block) <<>>
#define KERNEL_ARG3(grid, block, sh_mem) <<>>
#define KERNEL_ARG4(grid, block, sh_mem, stream) <<>>
#endif
矩阵文库
#include
#include
#include
#include
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include
#include
#include "cudaDmy.cuh"
__global__ void MatrixMulKernel(float *M, float *N, float *P, int width)
{
int Row = blockIdx.y * blockDim.y + threadIdx.y;
int Col = blockIdx.x * blockDim.x + threadIdx.x;
if (Row >> will replace macro KERNEL_ARG2 when compiling
MatrixMulKernel KERNEL_ARG2(dimGrid,dimBlock) (d_M, d_M, d_P, width);
cudaMemcpy(P, d_P, size, cudaMemcpyDeviceToHost);
cudaFree(d_M);
cudaFree(d_N);
cudaFree(d_P);
}
int main()
{
int elem = 100;
float *M = new float[elem];
float *N = new float[elem];
float *P = new float[elem];
for (int i = 0; i
让我们用NVCC编译它
nvcc matrixMul.cu -Xcudafe "--diag_suppress=unrecognized_pragma" -o runcuda
有用的链接:
https://devtalk.nvidia.com/default/topic/513485/cuda-programming-and-performance/__syncthreads-is-undefined-need-a-help/post/5189004/#5189004
/sf/ask/17360801/
/sf/ask/17360801/
https://gist.github.com/ruofeidu/df95ba27dfc6b77121b27fd4a6483426