Using helper functions for clCreateKernel (#1064)

* Using helper functions for clCreateKernel

Uses of clCreateKernel following create program helper
functions, have been incorporated into
create_single_kernel_helper when suitable.

Contributes #31

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* Skip tests using clCompileProgram in offline mode

Contributes #31

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* Using type wrappers when using kernel helper functions

Also includes fix for windows build

Fixes #31

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>

* Remove clReleaseKernel for wrapped kernel

Fixes #31

Signed-off-by: Ellen Norris-Thompson <ellen.norris-thompson@arm.com>
This commit is contained in:
ellnor01
2021-01-07 11:34:42 +00:00
committed by GitHub
parent 85bae70f81
commit 25d9ff5d6e
13 changed files with 111 additions and 231 deletions

View File

@@ -25,6 +25,7 @@
#include "harness/errorHelpers.h"
#include "harness/kernelHelpers.h"
#include "harness/parseParameters.h"
#include "harness/typeWrappers.h"
#if defined( __APPLE__ )
#include <sys/sysctl.h>
@@ -1384,36 +1385,36 @@ void _LogBuildError( cl_program p, int line, const char *file )
int InitILogbConstants( void )
{
int error;
const char *kernel =
"__kernel void GetILogBConstants( __global int *out )\n"
"{\n"
" out[0] = FP_ILOGB0;\n"
" out[1] = FP_ILOGBNAN;\n"
"}\n";
const char *kernelSource =
R"(__kernel void GetILogBConstants( __global int *out )
{
out[0] = FP_ILOGB0;
out[1] = FP_ILOGBNAN;
})";
cl_program query;
error = create_single_kernel_helper(gContext, &query, NULL, 1, &kernel, NULL);
if (NULL == query || error)
clProgramWrapper query;
clKernelWrapper kernel;
error = create_single_kernel_helper(gContext, &query, &kernel, 1,
&kernelSource, "GetILogBConstants");
if (error != CL_SUCCESS)
{
vlog_error( "Error: Unable to create program to get FP_ILOGB0 and FP_ILOGBNAN for the device. (%d)", error );
vlog_error("Error: Unable to create kernel to get FP_ILOGB0 and "
"FP_ILOGBNAN for the device. (%d)",
error);
return error;
}
cl_kernel k = clCreateKernel( query, "GetILogBConstants", &error );
if( NULL == k || error)
{
vlog_error( "Error: Unable to create kernel to get FP_ILOGB0 and FP_ILOGBNAN for the device. Err = %d", error );
return error;
}
if((error = clSetKernelArg(k, 0, sizeof( gOutBuffer[gMinVectorSizeIndex]), &gOutBuffer[gMinVectorSizeIndex])))
if ((error =
clSetKernelArg(kernel, 0, sizeof(gOutBuffer[gMinVectorSizeIndex]),
&gOutBuffer[gMinVectorSizeIndex])))
{
vlog_error( "Error: Unable to set kernel arg to get FP_ILOGB0 and FP_ILOGBNAN for the device. Err = %d", error );
return error;
}
size_t dim = 1;
if((error = clEnqueueNDRangeKernel(gQueue, k, 1, NULL, &dim, NULL, 0, NULL, NULL) ))
if ((error = clEnqueueNDRangeKernel(gQueue, kernel, 1, NULL, &dim, NULL, 0,
NULL, NULL)))
{
vlog_error( "Error: Unable to execute kernel to get FP_ILOGB0 and FP_ILOGBNAN for the device. Err = %d", error );
return error;
@@ -1429,45 +1430,43 @@ int InitILogbConstants( void )
gDeviceILogb0 = data.ilogb0;
gDeviceILogbNaN = data.ilogbnan;
clReleaseKernel(k);
clReleaseProgram(query);
return 0;
}
int IsTininessDetectedBeforeRounding( void )
{
int error;
const char *kernel =
"__kernel void IsTininessDetectedBeforeRounding( __global float *out )\n"
"{\n"
" volatile float a = 0x1.000002p-126f;\n"
" volatile float b = 0x1.fffffcp-1f;\n" // product is 0x1.fffffffffff8p-127
" out[0] = a * b;\n"
"}\n";
const char *kernelSource =
R"(__kernel void IsTininessDetectedBeforeRounding( __global float *out )
{
volatile float a = 0x1.000002p-126f;
volatile float b = 0x1.fffffcp-1f;
out[0] = a * b; // product is 0x1.fffffffffff8p-127
})";
cl_program query;
error = create_single_kernel_helper(gContext, &query, NULL, 1, &kernel, NULL);
clProgramWrapper query;
clKernelWrapper kernel;
error =
create_single_kernel_helper(gContext, &query, &kernel, 1, &kernelSource,
"IsTininessDetectedBeforeRounding");
if (error != CL_SUCCESS) {
vlog_error( "Error: Unable to create program to detect how tininess is detected for the device. (%d)", error );
vlog_error("Error: Unable to create kernel to detect how tininess is "
"detected for the device. (%d)",
error);
return error;
}
cl_kernel k = clCreateKernel( query, "IsTininessDetectedBeforeRounding", &error );
if( NULL == k || error)
{
vlog_error( "Error: Unable to create kernel to detect how tininess is detected for the device. Err = %d", error );
return error;
}
if((error = clSetKernelArg(k, 0, sizeof( gOutBuffer[gMinVectorSizeIndex]), &gOutBuffer[gMinVectorSizeIndex])))
if ((error =
clSetKernelArg(kernel, 0, sizeof(gOutBuffer[gMinVectorSizeIndex]),
&gOutBuffer[gMinVectorSizeIndex])))
{
vlog_error( "Error: Unable to set kernel arg to detect how tininess is detected for the device. Err = %d", error );
return error;
}
size_t dim = 1;
if((error = clEnqueueNDRangeKernel(gQueue, k, 1, NULL, &dim, NULL, 0, NULL, NULL) ))
if ((error = clEnqueueNDRangeKernel(gQueue, kernel, 1, NULL, &dim, NULL, 0,
NULL, NULL)))
{
vlog_error( "Error: Unable to execute kernel to detect how tininess is detected for the device. Err = %d", error );
return error;
@@ -1482,9 +1481,6 @@ int IsTininessDetectedBeforeRounding( void )
gCheckTininessBeforeRounding = 0 == (data.f & 0x7fffffff);
clReleaseKernel(k);
clReleaseProgram(query);
return 0;
}
@@ -1505,22 +1501,11 @@ int MakeKernel(const char **c, cl_uint count, const char *name, cl_kernel *k,
strcat(options, " -cl-fast-relaxed-math");
}
error = create_single_kernel_helper(gContext, p, NULL, count, c, NULL, options);
error =
create_single_kernel_helper(gContext, p, k, count, c, name, options);
if (error != CL_SUCCESS)
{
vlog_error("\t\tFAILED -- Failed to create program. (%d)\n", error);
return error;
}
*k = clCreateKernel( *p, name, &error );
if( NULL == *k || error )
{
char buffer[2048] = "";
vlog_error("\t\tFAILED -- clCreateKernel() failed: (%d)\n", error);
clGetProgramBuildInfo(*p, gDevice, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, NULL);
vlog_error("Log: %s\n", buffer);
clReleaseProgram( *p );
vlog_error("\t\tFAILED -- Failed to create kernel. (%d)\n", error);
return error;
}
@@ -1581,36 +1566,36 @@ int MakeKernels(const char **c, cl_uint count, const char *name,
static int IsInRTZMode( void )
{
int error;
const char *kernel =
"__kernel void GetRoundingMode( __global int *out )\n"
"{\n"
" volatile float a = 0x1.0p23f;\n"
" volatile float b = -0x1.0p23f;\n"
" out[0] = (a + 0x1.fffffep-1f == a) && (b - 0x1.fffffep-1f == b);\n"
"}\n";
const char *kernelSource =
R"(__kernel void GetRoundingMode( __global int *out )
{
volatile float a = 0x1.0p23f;
volatile float b = -0x1.0p23f;
out[0] = (a + 0x1.fffffep-1f == a) && (b - 0x1.fffffep-1f == b);
"})";
cl_program query;
error = create_single_kernel_helper(gContext, &query, NULL, 1, &kernel, NULL);
clProgramWrapper query;
clKernelWrapper kernel;
error = create_single_kernel_helper(gContext, &query, &kernel, 1,
&kernelSource, "GetRoundingMode");
if (error != CL_SUCCESS) {
vlog_error( "Error: Unable to create program to detect RTZ mode for the device. (%d)", error );
vlog_error("Error: Unable to create kernel to detect RTZ mode for the "
"device. (%d)",
error);
return error;
}
cl_kernel k = clCreateKernel( query, "GetRoundingMode", &error );
if( NULL == k || error)
{
vlog_error( "Error: Unable to create kernel to gdetect RTZ mode for the device. Err = %d", error );
return error;
}
if((error = clSetKernelArg(k, 0, sizeof( gOutBuffer[gMinVectorSizeIndex]), &gOutBuffer[gMinVectorSizeIndex])))
if ((error =
clSetKernelArg(kernel, 0, sizeof(gOutBuffer[gMinVectorSizeIndex]),
&gOutBuffer[gMinVectorSizeIndex])))
{
vlog_error( "Error: Unable to set kernel arg to detect RTZ mode for the device. Err = %d", error );
return error;
}
size_t dim = 1;
if((error = clEnqueueNDRangeKernel(gQueue, k, 1, NULL, &dim, NULL, 0, NULL, NULL) ))
if ((error = clEnqueueNDRangeKernel(gQueue, kernel, 1, NULL, &dim, NULL, 0,
NULL, NULL)))
{
vlog_error( "Error: Unable to execute kernel to detect RTZ mode for the device. Err = %d", error );
return error;
@@ -1623,9 +1608,6 @@ static int IsInRTZMode( void )
return error;
}
clReleaseKernel(k);
clReleaseProgram(query);
return data.isRTZ;
}