Hi all - i’m having an issue with a case where a typedef is used to create a type, and this is then used inside a struct. It seems that in this case the visual studio next gen cuda debugger is not able to show the typedef’d variables correctly.
Note that it only seems to be a problem if the typedef is used inside a struct. If it’s used as a standalone variable it seems to work ok.
Here is a minimal example:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
void checkCudaError(cudaError_t result)
{
if (result != cudaSuccess)
{
std::cout << "ERROR: " << result << std::endl;
}
}
typedef unsigned int uint;
struct SPairToAdd
{
uint a;
unsigned int b;
};
__global__ void addPairsKernel(uint *sumsOut, const SPairToAdd *pairsIn, unsigned int numPairs)
{
unsigned int index = threadIdx.x;
if (index >= numPairs)
{
return;
}
SPairToAdd myPair = pairsIn[index];
//put debugger breakpoint on next line.
//the 'a' member of the pair is not displayed
//correctly but the 'b' member is.
sumsOut[index] = myPair.a + myPair.b;
}
int main()
{
checkCudaError(cudaSetDevice(0));
SPairToAdd hostPair;
hostPair.a = 1;
hostPair.b = 2;
SPairToAdd* devicePair = nullptr;
checkCudaError(cudaMalloc(&devicePair, sizeof(SPairToAdd)));
checkCudaError(cudaMemcpy(devicePair, &hostPair, sizeof(SPairToAdd), cudaMemcpyHostToDevice));
unsigned int* deviceSum = nullptr;
checkCudaError(cudaMalloc(&deviceSum, 1 * sizeof(unsigned int)));
addPairsKernel << <1, 1>>> (deviceSum, devicePair, 1);
checkCudaError(cudaDeviceSynchronize());
unsigned int hostSum;
checkCudaError(cudaMemcpy(&hostSum, deviceSum, 1 * sizeof(unsigned int), cudaMemcpyDeviceToHost));
std::cout << hostSum << std::endl;
checkCudaError(cudaFree(devicePair));
checkCudaError(cudaFree(deviceSum));
return 0;
}
In the above example, the ‘SPairToAdd’ struct has a member ‘a’ which is a typedef and a member ‘b’ which is a straightforward type. When putting a breakpoint in the code at the commented position, the ‘a’ member is not visible in the debugger correctly but the ‘b’ member is.
I have tested this using nsight visual studio version 2020.2.1 and earlier versions. My gpu is RTX2070 and i’m using visual studio 2019 and windows 10 and cuda toolkit 11.1 .
Any suggestions or workarounds would be appreciated.