I am very new to cuda programming and im trying to invert colors of an image with c++ cuda and overcv but i have done everything possible solving error after error until ive reached a dead end please help. Environment is set to release x64, i have included the lib paths and the includes of both cuda and open cv plus all the libraries needed in the linker input.
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "C:\Users\USER\source\repos\cudatry2\cudatry2\Inversion_CUDA.h"
using namespace std;
using namespace cv;
int main() {
Mat Input_Image = imread("C:\\Users\\USER\\source\\repos\\cudatry2\\cudatry2\\Test_Image.png");
cout << "Height: " << Input_Image.rows << ", Width: " << Input_Image.rows << ", Channels: " << Input_Image.channels() << endl;
Image_Inversion_CUDA(Input_Image.data, Input_Image.rows, Input_Image.rows, Input_Image.channels());
imwrite("Inverted_Image.png", Input_Image);
system("pause");
return 0;
}
this is my cpp file
#include "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include\cuda_runtime.h"
#include "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include\device_launch_parameters.h"
#include "C:\Users\USER\source\repos\cudatry2\cudatry2\Inversion_CUDA.h"
__global__ void Inversion_CUDA(unsigned char* Image, int Channels);
void Image_Inversion_CUDA(unsigned char* Input_Image, int Height, int Width, int Channels){
unsigned char* Dev_Input_Image = NULL;
//allocate the memory in gpu
cudaMalloc((void**)&Dev_Input_Image, Height * Width * Channels);
//copy data from CPU to GPU
cudaMemcpy(Dev_Input_Image, Input_Image, Height * Width * Channels, cudaMemcpyHostToDevice);
dim3 Grid_Image(Width, Height);
Inversion_CUDA << <Grid_Image, 1 >> >(Dev_Input_Image, Channels);
//copy processed data back to cpu from gpu
cudaMemcpy(Input_Image, Dev_Input_Image, Height * Width * Channels, cudaMemcpyDeviceToHost);
//free gpu mempry
cudaFree(Dev_Input_Image);
}
__global__ void Inversion_CUDA(unsigned char* Image, int Channels){
int x = blockIdx.x;
int y = blockIdx.y;
int idx = (x + y * gridDim.x) * Channels;
for (int i = 0; i < Channels; i++){
Image[idx + i] = 255 - Image[idx + i];
}
}
this is my cuda file
#ifndef _Inversion_CUDA_
#define _Inversion_CUDA_
void Image_Inversion_CUDA(unsigned char* Input_Image, int Height, int Width, int Channels);
#endif
this is the headers file Please help i'm desperate
Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "void __cdecl Image_Inversion_CUDA(unsigned char *,int,int,int)" (?Image_Inversion_CUDA@@YAXPEAEHHH@Z) cudatry2 C:\Users\USER\source\repos\cudatry2\cudatry2\Image_Inversion_CUDA.obj 1
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals cudatry2 C:\Users\USER\source\repos\cudatry2\x64\Release\cudatry2.exe 1
this is the error i'm getting and i don't know what's happening