Unable to compile kernel with comments

Hi everybody.

first of all my working environment:

OpenCL on arch linux with latest nvidia sdk, nvidia drivers for linux version 190.29.

i can compile and execute kernels with no comments in it such as

__kernel void update(__global float *data)

{

}

but if i try to run the same code with this kernel:

__kernel void update(__global float *data)

{

//this is a comment

}

i get a build error as if i have an error on the source code (error 1 on clBuildProgram).

ideas?

please ask if you need more info

I’m not sure if it can be that. But I guess depending on how you give the program source to the compiler, if it gives the whole code in a unique line then the end your code is still considered as commented…

Maybe you can try this :

__kernel void update(__global float *data)

{

/*this is a comment*/

}

Thanks for the answer.

your suggestions has been very useful.

in fact, there was an error in the function i used to load a *.cl file.

now i corrected it, and now it loads the file correctly (at least i think so).

anyway, the problem is not solved :(

let me show you what it happens:

if i try to run my code with this kernel, everything goes fine:

$ ./OpenCLcpp

__kernel void increment(

				__global float *data

){

		const uint index = get_global_id(0);

		// comment

		data[index] = data[index]+1;

}

Size is 136

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

input 0 output 10

Execution finished correctly

If i try to execute the same code with this kernel, an error occours!!!

$ ./OpenCLcpp

__kernel void increment(

				__global float *data

){

		const uint index = get_global_id(0);

		// comment long

		data[index] = data[index]+1;

}

Size is 141

ERROR: clCreateKernel(-46)

-46 is CL_INVALID_KERNEL_NAME but the name of the kernel and the cpp code is the same!!!

this is the function i use to load the *.cl sources:

#include <fstream>

std::pair<const char*, unsigned int> ReadClFromFile(const char* path)

{

	std::string str,KernelSource;

	std::ifstream in;

	if(! in)

	{

		std::cerr << "File not found??" << std::endl;

	}

	in.open(path);

	std::getline(in,str);

	while ( in ) {

		KernelSource += str + "\n";

		std::getline(in,str);

	}

	in.close();

	std::cout << KernelSource << std::endl;

	std::cout << "Size is " << KernelSource.length() << std::endl;

	return std::make_pair(KernelSource.c_str(), KernelSource.length());

}

Are you aware that your ReadClFromFile() function is returning pointer from a string object (KernelSource) that is destructed at the end of the function? Change the first pair element to std::string, and see if that helps.

it worked, thanks a lot. very noob problem :)