Skip to content

[SYCL] Fix handler::copy [from|to] [raw|shared] pointer. #782

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

Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions sycl/source/detail/memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,13 @@ void copyH2D(SYCLMemObjI *SYCLMemObj, char *SrcMem, QueueImplPtr SrcQueue,
PI_CALL(RT::piEnqueueMemBufferWrite(
Queue, DstMem,
/*blocking_write=*/CL_FALSE, DstOffset[0], DstAccessRange[0],
SrcMem + DstOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent));
SrcMem + SrcOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent));
} else {
size_t BufferRowPitch = (1 == DimSrc) ? 0 : SrcSize[0];
size_t BufferSlicePitch = (3 == DimSrc) ? SrcSize[0] * SrcSize[1] : 0;
size_t BufferRowPitch = (1 == DimDst) ? 0 : DstSize[0];
size_t BufferSlicePitch = (3 == DimDst) ? DstSize[0] * DstSize[1] : 0;

size_t HostRowPitch = (1 == DimDst) ? 0 : DstSize[0];
size_t HostSlicePitch = (3 == DimDst) ? DstSize[0] * DstSize[1] : 0;
size_t HostRowPitch = (1 == DimSrc) ? 0 : SrcSize[0];
size_t HostSlicePitch = (3 == DimSrc) ? SrcSize[0] * SrcSize[1] : 0;
PI_CALL(RT::piEnqueueMemBufferWriteRect(
Queue, DstMem,
/*blocking_write=*/CL_FALSE, &DstOffset[0], &SrcOffset[0],
Expand Down Expand Up @@ -266,7 +266,7 @@ void copyD2H(SYCLMemObjI *SYCLMemObj, RT::PiMem SrcMem, QueueImplPtr SrcQueue,
if (1 == DimDst && 1 == DimSrc) {
PI_CALL(RT::piEnqueueMemBufferRead(
Queue, SrcMem,
/*blocking_read=*/CL_FALSE, DstOffset[0], DstAccessRange[0],
/*blocking_read=*/CL_FALSE, SrcOffset[0], SrcAccessRange[0],
DstMem + DstOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent));
} else {
size_t BufferRowPitch = (1 == DimSrc) ? 0 : SrcSize[0];
Expand Down
77 changes: 77 additions & 0 deletions sycl/test/basic_tests/handler/handler_copy_with_offset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// RUN: %clangxx -fsycl %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
//==--- handler_copy_with_offset.cpp - SYCL handler copy with offset test --==//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>

#include <cassert>
#include <exception>
#include <memory>
#include <numeric>
#include <vector>

using namespace cl::sycl;
constexpr access::mode read = access::mode::read;
constexpr access::mode write = access::mode::write;
constexpr access::target global_buffer = access::target::global_buffer;

int main() {
{
constexpr size_t Size = 8;

vector_class<char> DataRaw(Size, 'x');
{
buffer<char> Buffer{DataRaw.data(), range<1>{Size}};

vector_class<char> DataGold(Size);
std::iota(DataGold.begin(), DataGold.end(), '0');

queue Queue;
Queue.submit([&](handler &CGH) {
range<1> AccessRange{4};
id<1> AccessOffset{2};
auto Accessor = Buffer.get_access<write, global_buffer>(
CGH, AccessRange, AccessOffset);
CGH.copy(DataGold.data(), Accessor);
});
Queue.wait();
}

vector_class<char> Expected{'x', 'x', '0', '1', '2', '3', 'x', 'x'};
if (DataRaw != Expected)
throw std::runtime_error("Check of hadler.copy(ptr, acc) was failed");
}

{
constexpr size_t Size = 8;
vector_class<char> DataRaw(Size, 'x');
{
vector_class<char> DataGold(Size);
std::iota(DataGold.begin(), DataGold.end(), '0');
buffer<char> Buffer{DataGold.data(), range<1>{Size}};

queue Queue;
Queue.submit([&](handler &CGH) {
range<1> AccessRange{4};
id<1> AccessOffset{2};
auto Accessor = Buffer.get_access<read, global_buffer>(CGH, AccessRange,
AccessOffset);
CGH.copy(Accessor, DataRaw.data());
});
Queue.wait();
}
vector_class<char> Expected{'2', '3', '4', '5', 'x', 'x', 'x', 'x'};
if (DataRaw != Expected)
throw std::runtime_error("Check of hadler.copy(acc, ptr) was failed");
}
return 0;
}
4 changes: 2 additions & 2 deletions sycl/test/regression/memcpy-update-leafs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main() {
return 0;
}

// CHECK: PI ---> RT::piEnqueueMemBufferWrite( Queue, DstMem, CL_FALSE, DstOffset[0], DstAccessRange[0], SrcMem + DstOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent)
// CHECK-NOT: PI ---> RT::piEnqueueMemBufferWrite( Queue, DstMem, CL_FALSE, DstOffset[0], DstAccessRange[0], SrcMem + DstOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent)
// CHECK: PI ---> RT::piEnqueueMemBufferWrite( Queue, DstMem, CL_FALSE, DstOffset[0], DstAccessRange[0], SrcMem + SrcOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent)
// CHECK-NOT: PI ---> RT::piEnqueueMemBufferWrite( Queue, DstMem, CL_FALSE, DstOffset[0], DstAccessRange[0], SrcMem + SrcOffset[0], DepEvents.size(), &DepEvents[0], &OutEvent)
// CHECK-NOT: PI ---> (MappedPtr = RT::piEnqueueMemBufferMap( Queue->getHandleRef(), pi::cast<RT::PiMem>(Mem), CL_FALSE, Flags, AccessOffset[0], AccessRange[0], DepEvents.size(), DepEvents.empty() ? nullptr : &DepEvents[0], &OutEvent, &Error), Error)
// CHECK-NOT: PI ---> RT::piEnqueueMemUnmap( UseExclusiveQueue ? Queue->getExclusiveQueueHandleRef() : Queue->getHandleRef(), pi::cast<RT::PiMem>(Mem), MappedPtr, DepEvents.size(), DepEvents.empty() ? nullptr : &DepEvents[0], &OutEvent)