Skip to content

Commit

Permalink
Merge branch 'main' into negative_command_svm_mem
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-goras-mobica committed May 22, 2024
2 parents 190ad73 + fe76832 commit 3ced7dc
Show file tree
Hide file tree
Showing 39 changed files with 2,910 additions and 1,186 deletions.
2 changes: 2 additions & 0 deletions test_common/harness/errorHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ const char *GetChannelTypeName(cl_channel_type type)
case CL_SFIXED14_APPLE: return "CL_SFIXED14_APPLE";
#endif
case CL_UNORM_INT24: return "CL_UNORM_INT24";
case CL_UNSIGNED_INT_RAW10_EXT: return "CL_UNSIGNED_INT_RAW10_EXT";
case CL_UNSIGNED_INT_RAW12_EXT: return "CL_UNSIGNED_INT_RAW12_EXT";
default: return NULL;
}
}
Expand Down
3 changes: 3 additions & 0 deletions test_common/harness/imageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ uint32_t get_pixel_size(const cl_image_format *format)
return get_format_channel_count(format) * sizeof(cl_float);
case CL_UNORM_INT_101010_2: return 4;

case CL_UNSIGNED_INT_RAW10_EXT:
case CL_UNSIGNED_INT_RAW12_EXT: return 2;

default: return 0;
}
}
Expand Down
78 changes: 74 additions & 4 deletions test_common/harness/imageHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,42 @@ cl_uint compute_max_mip_levels(size_t width, size_t height, size_t depth);
cl_ulong compute_mipmapped_image_size(image_descriptor imageInfo);
size_t compute_mip_level_offset(image_descriptor *imageInfo, size_t lod);

constexpr size_t RAW10_EXT_CLUMP_SIZE = 5;
constexpr size_t RAW10_EXT_CLUMP_NUM_PIXELS = 4;
constexpr size_t RAW12_EXT_CLUMP_SIZE = 3;
constexpr size_t RAW12_EXT_CLUMP_NUM_PIXELS = 2;

inline bool is_width_compatible(image_descriptor imageInfo)
{
if (imageInfo.format->image_channel_data_type == CL_UNSIGNED_INT_RAW10_EXT
&& (imageInfo.width % RAW10_EXT_CLUMP_NUM_PIXELS) != 0)
{
return false;
}
if (imageInfo.format->image_channel_data_type == CL_UNSIGNED_INT_RAW12_EXT
&& (imageInfo.width % RAW12_EXT_CLUMP_NUM_PIXELS) != 0)
{
return false;
}
return true;
}

inline size_t calculate_row_pitch(image_descriptor imageInfo, size_t pixelSize)
{
if (imageInfo.format->image_channel_data_type == CL_UNSIGNED_INT_RAW10_EXT)
{
return (imageInfo.width * RAW10_EXT_CLUMP_SIZE)
/ RAW10_EXT_CLUMP_NUM_PIXELS;
}
if (imageInfo.format->image_channel_data_type == CL_UNSIGNED_INT_RAW12_EXT)
{
return (imageInfo.width * RAW12_EXT_CLUMP_SIZE)
/ RAW12_EXT_CLUMP_NUM_PIXELS;
}

return imageInfo.width * pixelSize;
}

template <class T>
void read_image_pixel(void *imageData, image_descriptor *imageInfo, int x,
int y, int z, T *outData, int lod)
Expand Down Expand Up @@ -255,10 +291,24 @@ void read_image_pixel(void *imageData, image_descriptor *imageInfo, int x,

// Advance to the right spot
char *ptr = (char *)imageData;
size_t pixelSize = get_pixel_size(format);

ptr += z * slice_pitch_lod + y * row_pitch_lod + x * pixelSize;

switch (format->image_channel_data_type)
{
case CL_UNSIGNED_INT_RAW10_EXT: {
ptr += z * slice_pitch_lod + y * row_pitch_lod
+ (x / RAW10_EXT_CLUMP_NUM_PIXELS) * RAW10_EXT_CLUMP_SIZE;
break;
}
case CL_UNSIGNED_INT_RAW12_EXT: {
ptr += z * slice_pitch_lod + y * row_pitch_lod
+ (x / RAW12_EXT_CLUMP_NUM_PIXELS) * RAW12_EXT_CLUMP_SIZE;
break;
}
default: {
size_t pixelSize = get_pixel_size(format);
ptr += z * slice_pitch_lod + y * row_pitch_lod + x * pixelSize;
break;
}
}
// OpenCL only supports reading floats from certain formats
switch (format->image_channel_data_type)
{
Expand Down Expand Up @@ -377,6 +427,26 @@ void read_image_pixel(void *imageData, image_descriptor *imageInfo, int x,
break;
}
#endif
case CL_UNSIGNED_INT_RAW10_EXT: {
cl_uchar *dPtr = (cl_uchar *)ptr;
i = x % RAW10_EXT_CLUMP_NUM_PIXELS;
uint8_t bit_index = i << 1;
uint16_t hi_val = dPtr[i] << 2;
uint16_t lo_val = (dPtr[4] & (0x3 << bit_index)) >> bit_index;

tempData[0] = (T)(hi_val | lo_val);
break;
}
case CL_UNSIGNED_INT_RAW12_EXT: {
cl_uchar *dPtr = (cl_uchar *)ptr;
i = x % RAW12_EXT_CLUMP_NUM_PIXELS;
uint8_t bit_index = i << 2;
uint16_t hi_val = dPtr[i] << 4;
uint16_t lo_val = (dPtr[2] & (0xF << bit_index)) >> bit_index;

tempData[0] = (T)(hi_val | lo_val);
break;
}
}


Expand Down
2 changes: 2 additions & 0 deletions test_common/harness/integer_ops_test_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "conversions.h"
#include "testHarness.h"

#include <vector>

// TODO: expand usage to other tests.

template <typename T> struct TestInfo
Expand Down
1 change: 1 addition & 0 deletions test_conformance/SVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(MODULE_NAME SVM)
set(${MODULE_NAME}_SOURCES
main.cpp
test_allocate_shared_buffer.cpp
test_allocate_shared_buffer_negative.cpp
test_byte_granularity.cpp
test_cross_buffer_pointers.cpp
test_enqueue_api.cpp
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/SVM/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ extern int test_svm_shared_address_space_fine_grain(cl_device_id deviceID, cl
extern int test_svm_cross_buffer_pointers_coarse_grain(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_svm_pointer_passing(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_svm_allocate_shared_buffer(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_svm_allocate_shared_buffer_negative(cl_device_id deviceID,
cl_context context,
cl_command_queue queue,
int num_elements);
extern int test_svm_shared_sub_buffers(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_svm_enqueue_api(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_svm_migrate(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
Expand Down
29 changes: 15 additions & 14 deletions test_conformance/SVM/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,21 @@ cl_int create_cl_objects(cl_device_id device_from_harness, const char** ppCodeSt
}

test_definition test_list[] = {
ADD_TEST( svm_byte_granularity),
ADD_TEST( svm_set_kernel_exec_info_svm_ptrs ),
ADD_TEST( svm_fine_grain_memory_consistency ),
ADD_TEST( svm_fine_grain_sync_buffers ),
ADD_TEST( svm_shared_address_space_fine_grain ),
ADD_TEST( svm_shared_sub_buffers ),
ADD_TEST( svm_shared_address_space_fine_grain_buffers ),
ADD_TEST( svm_allocate_shared_buffer ),
ADD_TEST( svm_shared_address_space_coarse_grain_old_api ),
ADD_TEST( svm_shared_address_space_coarse_grain_new_api ),
ADD_TEST( svm_cross_buffer_pointers_coarse_grain ),
ADD_TEST( svm_pointer_passing ),
ADD_TEST( svm_enqueue_api ),
ADD_TEST_VERSION( svm_migrate, Version(2, 1)),
ADD_TEST(svm_byte_granularity),
ADD_TEST(svm_set_kernel_exec_info_svm_ptrs),
ADD_TEST(svm_fine_grain_memory_consistency),
ADD_TEST(svm_fine_grain_sync_buffers),
ADD_TEST(svm_shared_address_space_fine_grain),
ADD_TEST(svm_shared_sub_buffers),
ADD_TEST(svm_shared_address_space_fine_grain_buffers),
ADD_TEST(svm_allocate_shared_buffer),
ADD_TEST(svm_allocate_shared_buffer_negative),
ADD_TEST(svm_shared_address_space_coarse_grain_old_api),
ADD_TEST(svm_shared_address_space_coarse_grain_new_api),
ADD_TEST(svm_cross_buffer_pointers_coarse_grain),
ADD_TEST(svm_pointer_passing),
ADD_TEST(svm_enqueue_api),
ADD_TEST_VERSION(svm_migrate, Version(2, 1)),
};

const int test_num = ARRAY_SIZE( test_list );
Expand Down
102 changes: 102 additions & 0 deletions test_conformance/SVM/test_allocate_shared_buffer_negative.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "common.h"

const cl_mem_flags svm_flag_set[] = {
CL_MEM_READ_WRITE,
CL_MEM_WRITE_ONLY,
CL_MEM_READ_ONLY,
CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER,
CL_MEM_WRITE_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER,
CL_MEM_READ_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER,
CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS,
CL_MEM_WRITE_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS,
CL_MEM_READ_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS,
0
};
const char* svm_flag_set_names[] = {
"CL_MEM_READ_WRITE",
"CL_MEM_WRITE_ONLY",
"CL_MEM_READ_ONLY",
"CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER",
"CL_MEM_WRITE_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER",
"CL_MEM_READ_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER",
"CL_MEM_READ_WRITE | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS",
"CL_MEM_WRITE_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS",
"CL_MEM_READ_ONLY | CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS",
"0"
};


int test_svm_allocate_shared_buffer_negative(cl_device_id deviceID,
cl_context context2,
cl_command_queue queue,
int num_elements)
{
clContextWrapper context = NULL;
clProgramWrapper program = NULL;
cl_uint num_devices = 0;
cl_int err = CL_SUCCESS;
clCommandQueueWrapper queues[MAXQ];

cl_device_svm_capabilities caps;
err = clGetDeviceInfo(deviceID, CL_DEVICE_SVM_CAPABILITIES,
sizeof(cl_device_svm_capabilities), &caps, NULL);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_SVM_CAPABILITIES");

// under construction...
err = create_cl_objects(deviceID, NULL, &context, &program, &queues[0],
&num_devices, CL_DEVICE_SVM_COARSE_GRAIN_BUFFER);
if (err) return -1;

size_t size = 1024;

// iteration over flag combos
int num_flags = sizeof(svm_flag_set) / sizeof(cl_mem_flags);
for (int i = 0; i < num_flags; i++)
{
if (((svm_flag_set[i] & CL_MEM_SVM_FINE_GRAIN_BUFFER) != 0
&& (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0)
|| ((svm_flag_set[i] & CL_MEM_SVM_ATOMICS) != 0
&& (caps & CL_DEVICE_SVM_ATOMICS) == 0))
{
log_info("Skipping clSVMalloc with flags: %s\n",
svm_flag_set_names[i]);
continue;
}

log_info("Testing clSVMalloc with flags: %s\n", svm_flag_set_names[i]);
cl_char* pBufData1 =
(cl_char*)clSVMAlloc(context, svm_flag_set[i], size, 0);
if (pBufData1 == NULL)
{
log_error("SVMalloc returned NULL");
return -1;
}

{
clMemWrapper buf1 = clCreateBuffer(context, CL_MEM_USE_HOST_PTR,
2 * size, pBufData1, &err);
test_failure_error(err, CL_INVALID_BUFFER_SIZE,
"clCreateBuffer did not return expected error"
"CL_INVALID_BUFFER_SIZE");
}

clSVMFree(context, pBufData1);
}

return 0;
}
Loading

0 comments on commit 3ced7dc

Please sign in to comment.