Skip to content

Commit

Permalink
Merge branch 'main' into printf_long_type
Browse files Browse the repository at this point in the history
  • Loading branch information
shajder committed Sep 4, 2024
2 parents e45f742 + 9116bb7 commit 3bce0cc
Show file tree
Hide file tree
Showing 81 changed files with 3,739 additions and 4,768 deletions.
34 changes: 18 additions & 16 deletions test_common/harness/conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ static Long sLowerLimits[kNumExplicitTypes] = {
} \
break;

#define TO_HALF_CASE(inType) \
#define TO_HALF_CASE(inType, halfRoundingMode) \
case kHalf: \
halfPtr = (cl_half *)outRaw; \
*halfPtr = cl_half_from_float((float)(*inType##Ptr), CL_HALF_RTE); \
*halfPtr = \
cl_half_from_float((float)(*inType##Ptr), halfRoundingMode); \
break;
#define TO_FLOAT_CASE(inType) \
case kFloat: \
Expand Down Expand Up @@ -453,6 +454,7 @@ typedef unsigned long ulong;

void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
bool saturate, RoundingType roundType,
cl_half_rounding_mode halfRoundingMode,
ExplicitType outType)
{
bool *boolPtr;
Expand Down Expand Up @@ -537,7 +539,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(schar, kULong, ULong)
SIMPLE_CAST_CASE(schar, kUnsignedLong, ULong)

TO_HALF_CASE(schar)
TO_HALF_CASE(schar, halfRoundingMode)
TO_FLOAT_CASE(schar)
TO_DOUBLE_CASE(schar)

Expand Down Expand Up @@ -570,7 +572,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(uchar, kULong, ULong)
SIMPLE_CAST_CASE(uchar, kUnsignedLong, ULong)

TO_HALF_CASE(uchar)
TO_HALF_CASE(uchar, halfRoundingMode)
TO_FLOAT_CASE(uchar)
TO_DOUBLE_CASE(uchar)

Expand Down Expand Up @@ -603,7 +605,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(uchar, kULong, ULong)
SIMPLE_CAST_CASE(uchar, kUnsignedLong, ULong)

TO_HALF_CASE(uchar)
TO_HALF_CASE(uchar, halfRoundingMode)
TO_FLOAT_CASE(uchar)
TO_DOUBLE_CASE(uchar)

Expand Down Expand Up @@ -636,7 +638,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(short, kULong, ULong)
SIMPLE_CAST_CASE(short, kUnsignedLong, ULong)

TO_HALF_CASE(short)
TO_HALF_CASE(short, halfRoundingMode)
TO_FLOAT_CASE(short)
TO_DOUBLE_CASE(short)

Expand Down Expand Up @@ -669,7 +671,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(ushort, kULong, ULong)
SIMPLE_CAST_CASE(ushort, kUnsignedLong, ULong)

TO_HALF_CASE(ushort)
TO_HALF_CASE(ushort, halfRoundingMode)
TO_FLOAT_CASE(ushort)
TO_DOUBLE_CASE(ushort)

Expand Down Expand Up @@ -702,7 +704,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(ushort, kULong, ULong)
SIMPLE_CAST_CASE(ushort, kUnsignedLong, ULong)

TO_HALF_CASE(ushort)
TO_HALF_CASE(ushort, halfRoundingMode)
TO_FLOAT_CASE(ushort)
TO_DOUBLE_CASE(ushort)

Expand Down Expand Up @@ -735,7 +737,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(int, kULong, ULong)
SIMPLE_CAST_CASE(int, kUnsignedLong, ULong)

TO_HALF_CASE(int)
TO_HALF_CASE(int, halfRoundingMode)
TO_FLOAT_CASE(int)
TO_DOUBLE_CASE(int)

Expand Down Expand Up @@ -768,7 +770,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(uint, kULong, ULong)
SIMPLE_CAST_CASE(uint, kUnsignedLong, ULong)

TO_HALF_CASE(uint)
TO_HALF_CASE(uint, halfRoundingMode)
TO_FLOAT_CASE(uint)
TO_DOUBLE_CASE(uint)

Expand Down Expand Up @@ -801,7 +803,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
SIMPLE_CAST_CASE(uint, kULong, ULong)
SIMPLE_CAST_CASE(uint, kUnsignedLong, ULong)

TO_HALF_CASE(uint)
TO_HALF_CASE(uint, halfRoundingMode)
TO_FLOAT_CASE(uint)
TO_DOUBLE_CASE(uint)

Expand Down Expand Up @@ -834,7 +836,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
DOWN_CAST_CASE(Long, kULong, ULong, saturate)
DOWN_CAST_CASE(Long, kUnsignedLong, ULong, saturate)

TO_HALF_CASE(Long)
TO_HALF_CASE(Long, halfRoundingMode)
TO_FLOAT_CASE(Long)
TO_DOUBLE_CASE(Long)

Expand Down Expand Up @@ -867,7 +869,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
U_DOWN_CAST_CASE(ULong, kUnsignedInt, uint, saturate)
U_DOWN_CAST_CASE(ULong, kLong, Long, saturate)

TO_HALF_CASE(ULong)
TO_HALF_CASE(ULong, halfRoundingMode)
TO_FLOAT_CASE(ULong)
TO_DOUBLE_CASE(ULong)

Expand Down Expand Up @@ -900,7 +902,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
U_DOWN_CAST_CASE(ULong, kUnsignedInt, uint, saturate)
U_DOWN_CAST_CASE(ULong, kLong, Long, saturate)

TO_HALF_CASE(ULong)
TO_HALF_CASE(ULong, halfRoundingMode)
TO_FLOAT_CASE(ULong)
TO_DOUBLE_CASE(ULong)

Expand Down Expand Up @@ -969,7 +971,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
FLOAT_ROUND_CASE(kULong, ULong, roundType, saturate)
FLOAT_ROUND_CASE(kUnsignedLong, ULong, roundType, saturate)

TO_HALF_CASE(float)
TO_HALF_CASE(float, halfRoundingMode)

case kFloat:
memcpy(outRaw, inRaw, get_explicit_type_size(inType));
Expand Down Expand Up @@ -1003,7 +1005,7 @@ void convert_explicit_value(void *inRaw, void *outRaw, ExplicitType inType,
DOUBLE_ROUND_CASE(kULong, ULong, roundType, saturate)
DOUBLE_ROUND_CASE(kUnsignedLong, ULong, roundType, saturate)

TO_HALF_CASE(double)
TO_HALF_CASE(double, halfRoundingMode)

TO_FLOAT_CASE(double);

Expand Down
3 changes: 3 additions & 0 deletions test_common/harness/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <string.h>
#include <sys/types.h>

#include <CL/cl_half.h>

/* Note: the next three all have to match in size and order!! */

enum ExplicitTypes
Expand Down Expand Up @@ -71,6 +73,7 @@ extern const char *get_explicit_type_name(ExplicitType type);
extern void convert_explicit_value(void *inRaw, void *outRaw,
ExplicitType inType, bool saturate,
RoundingType roundType,
cl_half_rounding_mode halfRoundingMode,
ExplicitType outType);

extern void generate_random_data(ExplicitType type, size_t count, MTdata d,
Expand Down
39 changes: 39 additions & 0 deletions test_common/harness/deviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,42 @@ size_t get_max_param_size(cl_device_id device)
}
return ret;
}

static cl_ulong get_device_info_max_size(cl_device_id device,
cl_device_info info,
unsigned int divisor)
{
cl_ulong max_size;

if (divisor == 0)
{
throw std::runtime_error("Allocation divisor should not be 0\n");
}

if (clGetDeviceInfo(device, info, sizeof(max_size), &max_size, NULL)
!= CL_SUCCESS)
{
throw std::runtime_error("clGetDeviceInfo failed\n");
}
return max_size / divisor;
}

cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device,
unsigned int divisor)
{
return get_device_info_max_size(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
divisor);
}

cl_ulong get_device_info_global_mem_size(cl_device_id device,
unsigned int divisor)
{
return get_device_info_max_size(device, CL_DEVICE_GLOBAL_MEM_SIZE, divisor);
}

cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device,
unsigned int divisor)
{
return get_device_info_max_size(device, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE,
divisor);
}
12 changes: 12 additions & 0 deletions test_common/harness/deviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ std::string get_device_name(cl_device_id device);
// Returns the maximum size in bytes for Kernel Parameters
size_t get_max_param_size(cl_device_id device);

/* We need to use a portion of available alloc size,
* divide it to leave some memory for the platform. */
#define MAX_DEVICE_MEMORY_SIZE_DIVISOR (2)

/* Get max allocation size. */
cl_ulong get_device_info_max_mem_alloc_size(cl_device_id device,
unsigned int divisor = 1);
cl_ulong get_device_info_global_mem_size(cl_device_id device,
unsigned int divisor = 1);
cl_ulong get_device_info_max_constant_buffer_size(cl_device_id device,
unsigned int divisor = 1);

#endif // _deviceInfo_h
29 changes: 13 additions & 16 deletions test_common/harness/kernelHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,30 +1511,27 @@ size_t get_min_alignment(cl_context context)
return align_size;
}

cl_device_fp_config get_default_rounding_mode(cl_device_id device,
const cl_uint &param)
cl_device_fp_config get_default_rounding_mode(const cl_device_id device,
const cl_uint param)
{
if (param == CL_DEVICE_DOUBLE_FP_CONFIG)
test_error_ret(
-1,
"FAILURE: CL_DEVICE_DOUBLE_FP_CONFIG not supported by this routine",
0);

char profileStr[128] = "";
cl_device_fp_config single = 0;
int error = clGetDeviceInfo(device, param, sizeof(single), &single, NULL);
cl_device_fp_config config = 0;
int error = clGetDeviceInfo(device, param, sizeof(config), &config, NULL);
if (error)
{
std::string message = std::string("Unable to get device ")
+ std::string(param == CL_DEVICE_HALF_FP_CONFIG
? "CL_DEVICE_HALF_FP_CONFIG"
: "CL_DEVICE_SINGLE_FP_CONFIG");
std::string config_name = "CL_DEVICE_SINGLE_FP_CONFIG";
if (param == CL_DEVICE_HALF_FP_CONFIG)
config_name = "CL_DEVICE_HALF_FP_CONFIG";
else if (param == CL_DEVICE_DOUBLE_FP_CONFIG)
config_name = "CL_DEVICE_DOUBLE_FP_CONFIG";
std::string message =
std::string("Unable to get device ") + config_name;
test_error_ret(error, message.c_str(), 0);
}

if (single & CL_FP_ROUND_TO_NEAREST) return CL_FP_ROUND_TO_NEAREST;
if (config & CL_FP_ROUND_TO_NEAREST) return CL_FP_ROUND_TO_NEAREST;

if (0 == (single & CL_FP_ROUND_TO_ZERO))
if (0 == (config & CL_FP_ROUND_TO_ZERO))
test_error_ret(-1,
"FAILURE: device must support either "
"CL_FP_ROUND_TO_ZERO or CL_FP_ROUND_TO_NEAREST",
Expand Down
4 changes: 2 additions & 2 deletions test_common/harness/kernelHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ size_t get_min_alignment(cl_context context);
/* Helper to obtain the default rounding mode for single precision computation.
* (Double is always CL_FP_ROUND_TO_NEAREST.) Returns 0 on error. */
cl_device_fp_config
get_default_rounding_mode(cl_device_id device,
const cl_uint &param = CL_DEVICE_SINGLE_FP_CONFIG);
get_default_rounding_mode(const cl_device_id device,
const cl_uint param = CL_DEVICE_SINGLE_FP_CONFIG);

#define PASSIVE_REQUIRE_IMAGE_SUPPORT(device) \
if (checkForImageSupport(device)) \
Expand Down
4 changes: 2 additions & 2 deletions test_conformance/SVM/test_allocate_shared_buffer_negative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int test_svm_allocate_shared_buffer_negative(cl_device_id deviceID,
// under construction...
err = create_cl_objects(deviceID, NULL, &context, &program, &queues[0],
&num_devices, CL_DEVICE_SVM_COARSE_GRAIN_BUFFER);
if (err) return -1;
if (err) return err;

size_t size = 1024;

Expand Down Expand Up @@ -98,5 +98,5 @@ int test_svm_allocate_shared_buffer_negative(cl_device_id deviceID,
clSVMFree(context, pBufData1);
}

return 0;
return TEST_PASS;
}
18 changes: 3 additions & 15 deletions test_conformance/allocations/allocation_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,27 +188,15 @@ int allocate_size(cl_context context, cl_command_queue *queue,
// one we don't end up returning a garbage value
*number_of_mems = 0;

error = clGetDeviceInfo(device_id, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
sizeof(max_individual_allocation_size),
&max_individual_allocation_size, NULL);
test_error_abort(error,
"clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE");
error = clGetDeviceInfo(device_id, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(global_mem_size), &global_mem_size, NULL);
test_error_abort(error,
"clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE");
max_individual_allocation_size =
get_device_info_max_mem_alloc_size(device_id);
global_mem_size = get_device_info_global_mem_size(device_id);

if (global_mem_size > (cl_ulong)SIZE_MAX)
{
global_mem_size = (cl_ulong)SIZE_MAX;
}

// log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB),
// CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n",
// max_individual_allocation_size,
// toMB(max_individual_allocation_size), global_mem_size,
// toMB(global_mem_size));

if (size_to_allocate > global_mem_size)
{
log_error("Can not allocate more than the global memory size.\n");
Expand Down
25 changes: 6 additions & 19 deletions test_conformance/allocations/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

typedef long long unsigned llu;

#define REDUCTION_PERCENTAGE_DEFAULT 50

int g_repetition_count = 1;
int g_reduction_percentage = 100;
int g_reduction_percentage = REDUCTION_PERCENTAGE_DEFAULT;
int g_write_allocations = 1;
int g_multiple_allocations = 0;
int g_execute_kernel = 1;
Expand All @@ -44,24 +46,9 @@ test_status init_cl(cl_device_id device)
{
int error;

error = clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
sizeof(g_max_individual_allocation_size),
&g_max_individual_allocation_size, NULL);
if (error)
{
print_error(error,
"clGetDeviceInfo failed for CL_DEVICE_MAX_MEM_ALLOC_SIZE");
return TEST_FAIL;
}
error =
clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE,
sizeof(g_global_mem_size), &g_global_mem_size, NULL);
if (error)
{
print_error(error,
"clGetDeviceInfo failed for CL_DEVICE_GLOBAL_MEM_SIZE");
return TEST_FAIL;
}
g_max_individual_allocation_size =
get_device_info_max_mem_alloc_size(device);
g_global_mem_size = get_device_info_global_mem_size(device);

log_info("Device reports CL_DEVICE_MAX_MEM_ALLOC_SIZE=%llu bytes (%gMB), "
"CL_DEVICE_GLOBAL_MEM_SIZE=%llu bytes (%gMB).\n",
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/api/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ test_definition test_list[] = {
ADD_TEST(native_kernel),

ADD_TEST(create_context_from_type),
ADD_TEST(create_context_from_type_device_type_all),
ADD_TEST(create_context_from_type_device_type_default),

ADD_TEST(platform_extensions),
ADD_TEST(get_platform_ids),
Expand Down Expand Up @@ -146,6 +148,8 @@ test_definition test_list[] = {
ADD_TEST_VERSION(consistency_3d_image_writes, Version(3, 0)),

ADD_TEST(min_image_formats),
ADD_TEST(set_command_queue_property),

ADD_TEST(negative_get_platform_info),
ADD_TEST(negative_get_platform_ids),

Expand Down
Loading

0 comments on commit 3bce0cc

Please sign in to comment.