IntelLabs / RiverTrail

An API for data parallelism in JavaScript
Other
748 stars 71 forks source link

Incorrect memory allocation for the build log #33

Closed hujiajie closed 11 years ago

hujiajie commented 11 years ago

In dpoCContext.cpp, clGetProgramBuildInfo is used to get the actual size of the build log. However, according to the OpenCL specs, it only works when buildLogSize is equal to or larger than the actual size of the build log. If buildLogSize is smaller than the log size and buildLog is not NULL, the error code CL_INVALID_VALUE will be returned. The following code could result in the above situation :

var pa1 = new ParallelArray(4, function f(x) { return 0; });
var pa2 = new ParallelArray(4, function func(x) { return 0; }); // elemental function with a longer name

In this example, buildLogSize and buildLog are initialized during the compilation of the first statement. But the build log of the second kernel function is slightly larger because of the longer function name. Thus, CL_INVALID_VALUE is return, and the value of actual is not defined by the OpenCL specs. According to my debugging, actual could be weird in this situation and might be extremely large (e.g. 10931776), so the program just continues and the bug is unnoticed.

Please correct me if there's any misunderstanding.

Thanks Jiajie

sherhut commented 11 years ago

Great catch and thanks for the detailed analysis. I have read the OpenCL specification and came to the same conclusion. The update I have just pushed no longer uses actual to predict the size of the required buffer. Instead, we now enlarge the buffer until the message finally fits.

Stephan