cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

jeromedne
Journeyman III

Crash in clCreateKernel

Hello!

I have integrated some OpenCL in Unreal Engine for our game production via AMD APP 2.8.1 and I am trying to avoid compiling the OpenCL code every time as this takes a very long time.

So I have a working path that uses clCreateProgramWithSource and then I save it on the HDD with:

size_t number_of_binaries;

uint8** binary;

size_t* binary_sizes;

result = clGetProgramInfo(*program, CL_PROGRAM_NUM_DEVICES, sizeof(number_of_binaries), &number_of_binaries, NULL);

binary_sizes = new size_t[number_of_binaries];

binary = new uint8*[number_of_binaries];

result = clGetProgramInfo(*program, CL_PROGRAM_BINARY_SIZES, number_of_binaries*sizeof(size_t), binary_sizes, NULL);

check(number_of_binaries==1); // We ask for only one GPU device, so we should get one binary

for (int i = 0; i < number_of_binaries; ++i) binary[i] = new uint8[binary_sizes[i]];

result = clGetProgramInfo(*program, CL_PROGRAM_BINARIES, number_of_binaries*sizeof(uint8*), binary, NULL);

const FString BC7CompressorFilename = FPaths::Combine(*FPaths::EngineDir(), TEXT("Source\\Developer\\TextureFormatBC67"),

TEXT("Private\\Compressor"),

codename);

FArchive* Ar = GFileManager->CreateFileWriter( *BC7CompressorFilename, 0, binary_sizes[0] );

if( !Ar )

{

GWarn->Logf(ELogVerbosity::Error, TEXT("Cannot create file for saving OpenCL binary."));

return false;

}

Ar->Serialize( const_cast<uint8*>(binary[0]), binary_sizes[0] );

And then, on a separate later session, I load the program:

if (FFileHelper::LoadFileToArray( program_binary, *BC7CompressorFilename, FILEREAD_Silent ))

{

const uint8* binary = (uint8*)program_binary.GetData();

size_t binary_size = (size_t) program_binary.Num();

GWarn->Logf(ELogVerbosity::Log, *(FString(TEXT("Loading ")) + BC7CompressorFilename + FString(TEXT(" (")) + FString::FromInt(binary_size) + FString(TEXT(" bytes)"))));

cl_program returned_program = clCreateProgramWithBinary(_context, 1, &_device,

&binary_size, &binary, &binary_status,

&result);

if (result != CL_SUCCESS)

{

GWarn->Logf(ELogVerbosity::Error, TEXT("Failed to create BC7 program!"));

return false;

}

return returned_program;

I get no error through all these.

Then  I will call

kernel = clCreateKernel(_compress_32bits, "bc7_kernel", &result);

And it crashes there, with the end of the callstack being

amdocl64.dll!000007feb969a389()   
[Frames below may be incorrect and/or missing, no symbols loaded for amdocl64.dll]  
amdocl64.dll!000007feb969aa3f()   
amdocl64.dll!000007feb9684f3e()   

I suppose something is wrong in cl_program, but as the type is opaque, I can't get information from it.

This is running on the same computer, but on separate sessions (so intializations -platform, device, context- are done twice). But as long as device and drivers are the same, that should not make a difference right?

Thanks for reading!

Jerome

0 Likes
1 Solution

Should you not be doing "clCreateKernel" with "returned_program".

I am not sure why you are saying "_compress_32bits" instead? What is that?

You may also want to do a "clBuildProgram" after creating the program from "clCreateProgramWithBinary".

I am not too sure.. but the spec has references to such a call under "clBuildProgram"

- Bruhaspati

View solution in original post

0 Likes
6 Replies
himanshu_gautam
Grandmaster

Have you called "clBuildProgram" after calling "clCreateProgramWithSource"?

- Bruhaspati

0 Likes

Sure did, yes. The pipe via clCreateProgramWithSource works perfectly fine; I can call clCreateKernel through that path and executes my kernel successfully. This perfectly working binary is then wrote to the disk (after calling clBuildProgram).

It is read at next launch and passed to clCreateProgramWithBinary with success until it I try clCreateKernel on this one.

Jerome

0 Likes

Should you not be doing "clCreateKernel" with "returned_program".

I am not sure why you are saying "_compress_32bits" instead? What is that?

You may also want to do a "clBuildProgram" after creating the program from "clCreateProgramWithBinary".

I am not too sure.. but the spec has references to such a call under "clBuildProgram"

- Bruhaspati

0 Likes

These are several snippets; it's not one continuous chunck of code. The code is too long to copy paste everything 😉

Returned_value is the return value of a function, and this value is assigned to _compress_32bits (which is a cl_program member of one of my class).

Good point on your second note! I will try that now!

Thank you

Jerome

0 Likes

It worked, good catch mate!

Many thanks,

Jerome

0 Likes

Thanks for reporting back! Glad it worked!

I was always not sure about that statement in the spec... Now I know..Thanks!

Cheers,

Bruhaspati

0 Likes