Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for clCommandSVMMemcpyKHR & clCommandSVMMemfillKHR #1821

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions test_common/harness/typeWrappers.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,48 @@ using clSamplerWrapper =
using clEventWrapper =
wrapper_details::Wrapper<cl_event, clRetainEvent, clReleaseEvent>;

class clSVMWrapper {
void *Ptr = nullptr;
cl_context Ctx = nullptr;

public:
clSVMWrapper() = default;

clSVMWrapper(cl_context C, size_t Size,
cl_svm_mem_flags F = CL_MEM_READ_WRITE)
: Ctx(C)
{
Ptr = clSVMAlloc(C, F, Size, 0);
}

clSVMWrapper &operator=(void *other) = delete;
clSVMWrapper(clSVMWrapper const &other) = delete;
clSVMWrapper &operator=(clSVMWrapper const &other) = delete;
clSVMWrapper(clSVMWrapper &&other)
{
Ptr = other.Ptr;
Ctx = other.Ctx;
other.Ptr = nullptr;
other.Ctx = nullptr;
}
clSVMWrapper &operator=(clSVMWrapper &&other)
{
Ptr = other.Ptr;
Ctx = other.Ctx;
other.Ptr = nullptr;
other.Ctx = nullptr;
return *this;
}

~clSVMWrapper()
{
if (Ptr) clSVMFree(Ctx, Ptr);
}

void *operator()() const { return Ptr; }
};


class clProtectedImage {
public:
clProtectedImage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set(MODULE_NAME CL_KHR_COMMAND_BUFFER)
set(${MODULE_NAME}_SOURCES
main.cpp
basic_command_buffer.cpp
svm_command_basic.cpp
command_buffer_printf.cpp
command_buffer_get_command_buffer_info.cpp
command_buffer_set_kernel_arg.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
} \
}

// If it is supported get the addresses of all the APIs here.
#define GET_EXTENSION_ADDRESS(FUNC) \
FUNC = reinterpret_cast<FUNC##_fn>( \
clGetExtensionFunctionAddressForPlatform(platform, #FUNC)); \
if (FUNC == nullptr) \
{ \
log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed" \
" with " #FUNC "\n"); \
return TEST_FAIL; \
}


// Helper test fixture for constructing OpenCL objects used in testing
// a variety of simple command-buffer enqueue scenarios.
struct BasicCommandBufferTest : CommandBufferTestBase
Expand Down Expand Up @@ -70,6 +82,7 @@ struct BasicCommandBufferTest : CommandBufferTestBase
clCommandBufferWrapper command_buffer;
};


template <class T>
int MakeAndRunTest(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@
#include "../basic_command_buffer.h"
#include "../command_buffer_test_base.h"

// If it is supported get the addresses of all the APIs here.
#define GET_EXTENSION_ADDRESS(FUNC) \
FUNC = reinterpret_cast<FUNC##_fn>( \
clGetExtensionFunctionAddressForPlatform(platform, #FUNC)); \
if (FUNC == nullptr) \
{ \
log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed" \
" with " #FUNC "\n"); \
return TEST_FAIL; \
}

struct BasicMutableCommandBufferTest : BasicCommandBufferTest
{
BasicMutableCommandBufferTest(cl_device_id device, cl_context context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//
#include "basic_command_buffer.h"
#include "svm_command_basic.h"
#include "harness/typeWrappers.h"
#include "procs.h"

Expand Down Expand Up @@ -197,6 +198,74 @@ struct CopyBufferKHR : public BasicCommandBufferTest
const cl_char pattern_2 = 0x28;
};

struct CopySVMBufferKHR : public BasicSVMCommandBufferTest
{
using BasicSVMCommandBufferTest::BasicSVMCommandBufferTest;

cl_int Run() override
{
cl_int error = clCommandSVMMemFillKHR(
command_buffer, nullptr, svm_in_mem(), &pattern_1,
sizeof(cl_char), data_size(), 0, nullptr, nullptr, nullptr);
test_error(error, "clCommandSVMMemFillKHR failed");

error = clCommandSVMMemcpyKHR(command_buffer, nullptr, svm_out_mem(),
svm_in_mem(), data_size(), 0, nullptr,
nullptr, nullptr);
test_error(error, "clCommandSVMMemcpyKHR failed");

error = clFinalizeCommandBufferKHR(command_buffer);
test_error(error, "clFinalizeCommandBufferKHR failed");

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

std::vector<cl_char> output_data_1(data_size());
error =
clEnqueueSVMMemcpy(queue, CL_TRUE, output_data_1.data(),
svm_out_mem(), data_size(), 0, nullptr, nullptr);
test_error(error, "clEnqueueSVMMemcpy failed");

for (size_t i = 0; i < data_size(); i++)
{
CHECK_VERIFICATION_ERROR(pattern_1, output_data_1[i], i);
}

/* Check second enqueue of command buffer */
error = clEnqueueSVMMemFill(queue, svm_in_mem(), &pattern_2,
sizeof(cl_char), data_size(), 0, nullptr,
nullptr);
test_error(error, "clEnqueueSVMMemFill failed");

error = clEnqueueSVMMemFill(queue, svm_out_mem(), &pattern_2,
sizeof(cl_char), data_size(), 0, nullptr,
nullptr);
test_error(error, "clEnqueueSVMMemFill failed");

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

std::vector<cl_char> output_data_2(data_size());

error =
clEnqueueSVMMemcpy(queue, CL_TRUE, output_data_2.data(),
svm_out_mem(), data_size(), 0, nullptr, nullptr);
test_error(error, "clEnqueueSVMMemcpy failed");

for (size_t i = 0; i < data_size(); i++)
{
CHECK_VERIFICATION_ERROR(pattern_1, output_data_2[i], i);
}

return CL_SUCCESS;
}

const cl_char pattern_1 = 0x14;
const cl_char pattern_2 = 0x28;
};

struct CopyBufferToImageKHR : public BasicCommandBufferTest
{
using BasicCommandBufferTest::BasicCommandBufferTest;
Expand Down Expand Up @@ -510,6 +579,14 @@ int test_copy_buffer(cl_device_id device, cl_context context,
return MakeAndRunTest<CopyBufferKHR>(device, context, queue, num_elements);
}

int test_copy_svm_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return MakeAndRunTest<CopySVMBufferKHR>(device, context, queue,
num_elements);
}


int test_copy_buffer_to_image(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//
#include "basic_command_buffer.h"
#include "svm_command_basic.h"
#include "harness/typeWrappers.h"
#include "procs.h"

Expand Down Expand Up @@ -171,6 +172,64 @@ struct FillBufferKHR : public BasicCommandBufferTest
const char pattern_2 = 0x30;
};

struct FillSVMBufferKHR : public BasicSVMCommandBufferTest
{
using BasicSVMCommandBufferTest::BasicSVMCommandBufferTest;

cl_int Run() override
{
cl_int error = clCommandSVMMemFillKHR(
command_buffer, nullptr, svm_in_mem(), &pattern_1,
sizeof(cl_char), data_size(), 0, nullptr, nullptr, nullptr);
test_error(error, "clCommandSVMMemFillKHR failed");

error = clFinalizeCommandBufferKHR(command_buffer);
test_error(error, "clFinalizeCommandBufferKHR failed");

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

std::vector<cl_char> output_data_1(data_size());

error =
clEnqueueSVMMemcpy(queue, CL_TRUE, output_data_1.data(),
svm_in_mem(), data_size(), 0, nullptr, nullptr);
test_error(error, "clEnqueueSVMMemcpy failed");

for (size_t i = 0; i < data_size(); i++)
{
CHECK_VERIFICATION_ERROR(pattern_1, output_data_1[i], i);
}

/* Check second enqueue of command buffer */
error = clEnqueueSVMMemFill(queue, svm_in_mem(), &pattern_2,
sizeof(cl_char), data_size(), 0, nullptr,
nullptr);
test_error(error, "clEnqueueSVMMemFill failed");

error = clEnqueueCommandBufferKHR(0, nullptr, command_buffer, 0,
nullptr, nullptr);
test_error(error, "clEnqueueCommandBufferKHR failed");

std::vector<cl_char> output_data_2(data_size());

error =
clEnqueueSVMMemcpy(queue, CL_TRUE, output_data_2.data(),
svm_in_mem(), data_size(), 0, nullptr, nullptr);
test_error(error, "clEnqueueSVMMemcpy failed");

for (size_t i = 0; i < data_size(); i++)
{
CHECK_VERIFICATION_ERROR(pattern_1, output_data_2[i], i);
}

return CL_SUCCESS;
}

const char pattern_1 = 0x15;
const char pattern_2 = 0x30;
};
};

int test_fill_buffer(cl_device_id device, cl_context context,
Expand All @@ -179,6 +238,14 @@ int test_fill_buffer(cl_device_id device, cl_context context,
return MakeAndRunTest<FillBufferKHR>(device, context, queue, num_elements);
}

int test_fill_svm_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return MakeAndRunTest<FillSVMBufferKHR>(device, context, queue,
num_elements);
}


int test_fill_image(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
Expand Down
2 changes: 2 additions & 0 deletions test_conformance/extensions/cl_khr_command_buffer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ test_definition test_list[] = {
ADD_TEST(simultaneous_queue_substitution),
ADD_TEST(fill_image),
ADD_TEST(fill_buffer),
ADD_TEST(fill_svm_buffer),
ADD_TEST(copy_image),
ADD_TEST(copy_buffer),
ADD_TEST(copy_svm_buffer),
ADD_TEST(copy_buffer_to_image),
ADD_TEST(copy_image_to_buffer),
ADD_TEST(copy_buffer_rect),
Expand Down
4 changes: 4 additions & 0 deletions test_conformance/extensions/cl_khr_command_buffer/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,14 @@ extern int test_fill_image(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_fill_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_fill_svm_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_copy_image(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_copy_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_copy_svm_buffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_copy_buffer_to_image(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_copy_image_to_buffer(cl_device_id device, cl_context context,
Expand Down
Loading
Loading