Skip to content

Commit

Permalink
Merge pull request #311 from RossBrunton/goodfail
Browse files Browse the repository at this point in the history
Improve handling of error cases
  • Loading branch information
RossBrunton authored Feb 1, 2024
2 parents 47bdb64 + 257d955 commit e057930
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <CL/cl.h>
#include <extension/intel_unified_shared_memory.h>

#ifdef OCL_EXTENSION_cl_intel_unified_shared_memory
Expand Down Expand Up @@ -531,20 +532,37 @@ cl_int MemFillImpl(cl_command_queue command_queue, void *dst_ptr,
// Push Mux fill buffer operation
auto mux_error =
ExamineUSMAlloc(usm_alloc, device, return_event, mux_buffer);
OCL_CHECK(mux_error, return CL_OUT_OF_RESOURCES);
if (mux_error) {
auto error = cl::getErrorFrom(mux_error);
if (return_event) {
return_event->complete(error);
}
return error;
}
offset = getUSMOffset(dst_ptr, usm_alloc);
}

// TODO CA-2863 Define correct return code for this situation where device
// USM allocation device is not the same as command queue device
OCL_CHECK(mux_buffer == nullptr, return CL_INVALID_COMMAND_QUEUE);
if (mux_buffer == nullptr) {
if (return_event) {
return_event->complete(CL_INVALID_COMMAND_QUEUE);
}
return CL_INVALID_COMMAND_QUEUE;
}

const std::lock_guard<std::mutex> lock(
command_queue->context->getCommandQueueMutex());

auto mux_command_buffer = command_queue->getCommandBuffer(
{event_wait_list, num_events_in_wait_list}, return_event);
OCL_CHECK(!mux_command_buffer, return CL_OUT_OF_RESOURCES);
if (!mux_command_buffer) {
auto error = cl::getErrorFrom(mux_command_buffer.error());
if (return_event) {
return_event->complete(error);
}
return error;
}

auto mux_error =
muxCommandFillBuffer(*mux_command_buffer, mux_buffer, offset, size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ struct clSetProgramSpecializationConstantSuccessTest
}
cl_event taskEvent;
ASSERT_SUCCESS(clEnqueueTask(commandQueue, kernel, 0, nullptr, &taskEvent));
std::array<cl_event, 8> resultEvents;
std::array<cl_event, 8> resultEvents{};
ASSERT_SUCCESS(clEnqueueReadBuffer(commandQueue, boolBuffer, CL_FALSE, 0,
sizeof(bool) * 2, boolResults.data(), 1,
&taskEvent, &resultEvents[0]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEST_F(USMCommandQueueTest, MemFill_ValidUsage) {
}
}

std::array<cl_event, MAX_NUM_POINTERS> wait_events;
std::array<cl_event, MAX_NUM_POINTERS> wait_events{};
size_t num_events = 0;

for (auto ptr : allPointers()) {
Expand Down Expand Up @@ -380,7 +380,7 @@ TEST_F(USMCommandQueueTest, MigrateMem_InvalidUsage) {
// Test for valid API usage of clEnqueueMigrateMemINTEL()
TEST_F(USMCommandQueueTest, MigrateMem_ValidUsage) {
for (auto ptr : allPointers()) {
std::array<cl_event, 1> events;
std::array<cl_event, 1> events{};
cl_int err = clEnqueueMigrateMemINTEL(
queue, ptr, bytes, CL_MIGRATE_MEM_OBJECT_HOST, 0, nullptr, &events[0]);
EXPECT_SUCCESS(err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEST_F(USMEventInfoTest, clEnqueueMemFillINTEL_EventInfo) {
cl_int err;

for (auto ptr : allPointers()) {
cl_event wait_event;
cl_event wait_event{};
err = clEnqueueMemFillINTEL(queue, ptr, pattern, sizeof(pattern),
sizeof(pattern) * 2, 0, nullptr, &wait_event);
EXPECT_SUCCESS(err);
Expand Down Expand Up @@ -115,7 +115,7 @@ TEST_F(USMEventInfoTest, clEnqueueMemcpyINTEL_EventInfo) {
continue;
}

std::array<cl_event, 2> events;
std::array<cl_event, 2> events{};
void *offset_ptr = getPointerOffset(ptr_a, sizeof(cl_int));
cl_int err = clEnqueueMemcpyINTEL(queue, CL_TRUE, offset_ptr, ptr_a,
sizeof(cl_int), 0, nullptr, &events[0]);
Expand Down Expand Up @@ -176,7 +176,7 @@ TEST_F(USMEventInfoTest, clEnqueueMemAdviseINTEL_EventInfo) {
// Create a user event to block advise command happening immediately
cl_int err;
cl_event user_event = clCreateUserEvent(context, &err);
cl_event wait_event;
cl_event wait_event{};
ASSERT_SUCCESS(err);

// Enqueue a no-op advise command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TYPED_TEST(USMMemCpyTest, DeviceToHost) {
if (!host_ptr) {
GTEST_SKIP();
}
std::array<cl_event, 3> events;
std::array<cl_event, 3> events{};

// Zero initialize device buffer
const TypeParam zero_pattern = test_patterns<TypeParam>::zero_pattern;
Expand Down Expand Up @@ -434,7 +434,7 @@ TYPED_TEST(USMMemCpyTest, HostToDevice) {
std::memset(host_ptr, 0, bytes);

// Reset device allocation before use as copy destination
std::array<cl_event, 3> events;
std::array<cl_event, 3> events{};
const TypeParam zero_pattern = test_patterns<TypeParam>::zero_pattern;
cl_int err = clEnqueueMemFillINTEL(queue, device_ptr, &zero_pattern,
sizeof(zero_pattern), bytes, 0, nullptr,
Expand Down Expand Up @@ -540,7 +540,7 @@ TYPED_TEST(USMMemCpyTest, HostToHost) {
GTEST_SKIP();
}

std::array<cl_event, 2> events;
std::array<cl_event, 2> events{};

// Initialize host allocation A
const TypeParam pattern1 = test_patterns<TypeParam>::pattern1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ TYPED_TEST(USMMemFillTest, DeviceAllocation) {
std::memset(host_ptr, 0, bytes);
}

std::array<cl_event, 3> wait_events;
std::array<cl_event, 3> wait_events{};
const TypeParam zero_pattern = test_patterns<TypeParam>::zero_pattern;
cl_int err = clEnqueueMemFillINTEL(queue, device_ptr, &zero_pattern,
sizeof(zero_pattern), bytes, 0, nullptr,
Expand Down Expand Up @@ -320,7 +320,7 @@ TYPED_TEST(USMMemFillTest, SharedAllocation) {
std::memset(host_ptr, 0, bytes);
}

std::array<cl_event, 3> wait_events;
std::array<cl_event, 3> wait_events{};
const TypeParam zero_pattern = test_patterns<TypeParam>::zero_pattern;
cl_int err = clEnqueueMemFillINTEL(queue, shared_ptr, &zero_pattern,
sizeof(zero_pattern), bytes, 0, nullptr,
Expand Down Expand Up @@ -375,7 +375,7 @@ TYPED_TEST(USMMemFillTest, UserAllocation) {
std::vector<TypeParam, UCL::aligned_allocator<TypeParam, sizeof(TypeParam)>>
user_data(elements);

std::array<cl_event, 3> wait_events;
std::array<cl_event, 3> wait_events{};
// Zero initialize user memory containing 8 TypeParam elements before
// beginning testing
const TypeParam zero_pattern = test_patterns<TypeParam>::zero_pattern;
Expand Down

0 comments on commit e057930

Please sign in to comment.