Hello,
So I’m brand new to coding, and I’ve sort of been thrown into the deep end here in that I’ve been tasked to write a simulation using Cuda. I’m currently trying to allocate a 3-D array on the GPU memory, and I’ve copied the source code giving in the programming guide more or less as is. However, when I try to compile it, it throws me an error on line 11 (the “char* devPtr = devPitchedPtr.ptr;” line) as follows.
“error : a value of type “void *” cannot be used to initialize an entity of type “char *””
I have no idea what to do about this. Does anyone have any ideas?
Code in its entirety is below. Thanks for your time.
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
cudaError_t addWithCuda(int *c, const int *a, const int *b, unsigned int size);
__global__ void ThreeDimensional(cudaPitchedPtr devPitchedPtr,
int width, int height, int depth)
{
char* devPtr = devPitchedPtr.ptr;
size_t pitch = devPitchedPtr.pitch;
size_t slicePitch = pitch * height;
for (int z = 0; z < depth; ++z) {
char* slice = devPtr + z * slicePitch;
for (int y = 0; y < height; ++y) {
float* row = (float*)(slice + y*pitch);
for (int x=0; x < width; ++x) {
float element = row[x];
}
}
}
}
int main()
{
int width = 3, height = 3, depth = 3;
cudaExtent extent = make_cudaExtent(width * sizeof(float), height, depth);
cudaPitchedPtr devPitchedPtr;
cudaMalloc3D(&devPitchedPtr, extent);
ThreeDimensional<<<1, 1>>>(devPitchedPtr, width, height, depth);
return(0);
}