How to call cuda function from c++ file?

Changing the code to

main.cpp

#include "Test.cuh"

int main(int argc, char *argv[])
{
	Wrapper::wrapper();
}

Test.cuh

#pragma once
#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>

namespace Wrapper {
	void wrapper(void);
}

Test.cu

#include "Test.cuh"

__global__ void test_kernel(void) {
}

namespace Wrapper {
	void wrapper(void)
	{
		test_kernel <<<1, 1>>> ();
		printf("Hello, world!");
	}
}

Allows me to compile and run the code. Thanks for your help. I also had to add “$(CudaToolkitLibDir)” to Project “Properties > Linker > General > Additional Library Directories” and add “cudart.lib” to Project “Properties > Linker > Input > Additional dependencies” before it would start working.

Edit: One thing I was wondering about though, the “Hello, World!” doesn’t seem to get printed and no terminal opens.

4 Likes