Thank you rbischof,
I have been trying to use Legacy but even with it I seem to be getting the same error.
Here is what I am trying to do.
#include
#include <cuda_runtime.h>
#include <cuda.h>
#include “device_launch_parameters.h”
#include “Header.h”
#include <math.h>
//#define CUDA_CALL(x) {cudaError_t cuda_error__ = (x); if (cuda_error__) printf(“CUDA error: " #x " returned "%s"\n”, cudaGetErrorString(cuda_error__));}
#define GRIDVAL 20.0
global void sobelfilter_kernel(int iw, int ih, unsigned char source, unsigned char dest)
{
int x = (blockIdx.x + blockDim.x) + threadIdx.x;
int y = (blockIdx.y + blockDim.y) + threadIdx.y;
int gx, gy;
if (x > 0 && x < iw - 1 && y > 0 && y < ih - 1)
{
gx = -source[iw(y - 1)(x - 1)] + source[iw*(y - 1)(x + 1)] +
-2 * source[iwy*(x - 1)] + 2 * source[iwy(x + 1)] +
-source[iw*(y + 1)(x - 1)] + source[iw(y + 1)(x + 1)];
gy = -source[ih(y - 1)(x - 1)] - 2 * source[ih(y - 1)x] + -source[ih(y - 1)(x + 1)] +
source[ih(y + 1)(x - 1)] + source[ih(y + 1)(x)] + source[ih(y + 1)(x + 1)];
dest[iwyx] = (int)sqrt((float)(gx)(float)(gx)+(float)(gy)*(float)(gy));
}
}
void sobelfilter(int iw, int ih, unsigned char *source, unsigned char *dest)
{
unsigned char *dev_source, *dev_dest;
cudaHostGetDevicePointer(&dev_source, source, 0);
cudaHostGetDevicePointer(&dev_dest, dest, 0);
dim3 threadsPerBlock(GRIDVAL, GRIDVAL, 1);
dim3 numBlocks(ceil(iw / GRIDVAL), ceil(ih / GRIDVAL), 1);
sobelfilter_kernel <<<numBlocks, threadsPerBlock>>> (iw, ih, dev_source, dev_dest);
cudaThreadSynchronize();
}
unsigned char* createImageBuffer(unsigned int bytes)
{
unsigned char *ptr = NULL;
cudaSetDeviceFlags(cudaDeviceMapHost);
cudaHostAlloc(&ptr, bytes, cudaHostAllocMapped);
return ptr;
}
void destroyImageBuffer(unsigned char* bytes)
{
cudaFreeHost(bytes);
}