Skip to content

[SYCL] Enable using of the copy method with shared_ptr with const T. #276

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
16 changes: 8 additions & 8 deletions sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class CG {

CG(CGTYPE Type, std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<void>> SharedPtrStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements)
: MType(Type), MArgsStorage(std::move(ArgsStorage)),
MAccStorage(std::move(AccStorage)),
Expand All @@ -347,7 +347,7 @@ class CG {
// Storage for accessors.
std::vector<detail::AccessorImplPtr> MAccStorage;
// Storage for shared_ptrs.
std::vector<std::shared_ptr<void>> MSharedPtrStorage;
std::vector<std::shared_ptr<const void>> MSharedPtrStorage;
// List of requirements that specify which memory is needed for the command
// group to be executed.
std::vector<Requirement *> MRequirements;
Expand All @@ -368,7 +368,7 @@ class CGExecKernel : public CG {
std::shared_ptr<detail::kernel_impl> SyclKernel,
std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<void>> SharedPtrStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements,
std::vector<ArgDesc> Args, std::string KernelName,
detail::OSModuleHandle OSModuleHandle,
Expand Down Expand Up @@ -396,7 +396,7 @@ class CGCopy : public CG {
CGCopy(CGTYPE CopyType, void *Src, void *Dst,
std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<void>> SharedPtrStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements)
: CG(CopyType, std::move(ArgsStorage), std::move(AccStorage),
std::move(SharedPtrStorage), std::move(Requirements)),
Expand All @@ -414,7 +414,7 @@ class CGFill : public CG {
CGFill(std::vector<char> Pattern, void *Ptr,
std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<void>> SharedPtrStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements)
: CG(FILL, std::move(ArgsStorage), std::move(AccStorage),
std::move(SharedPtrStorage), std::move(Requirements)),
Expand All @@ -429,7 +429,7 @@ class CGUpdateHost : public CG {
public:
CGUpdateHost(void *Ptr, std::vector<std::vector<char>> ArgsStorage,
std::vector<detail::AccessorImplPtr> AccStorage,
std::vector<std::shared_ptr<void>> SharedPtrStorage,
std::vector<std::shared_ptr<const void>> SharedPtrStorage,
std::vector<Requirement *> Requirements)
: CG(UPDATE_HOST, std::move(ArgsStorage), std::move(AccStorage),
std::move(SharedPtrStorage), std::move(Requirements)),
Expand All @@ -438,6 +438,6 @@ class CGUpdateHost : public CG {
Requirement *getReqToUpdate() { return MPtr; }
};

} // namespace cl
} // namespace sycl
} // namespace detail
} // namespace sycl
} // namespace cl
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class handler {
std::vector<std::vector<char>> MArgsStorage;
std::vector<detail::AccessorImplPtr> MAccStorage;
std::vector<std::shared_ptr<detail::stream_impl>> MStreamStorage;
std::vector<std::shared_ptr<void>> MSharedPtrStorage;
std::vector<std::shared_ptr<const void>> MSharedPtrStorage;
// The list of arguments for the kernel.
std::vector<detail::ArgDesc> MArgs;
// The list of associated accessors with this handler.
Expand Down Expand Up @@ -924,7 +924,7 @@ class handler {
// Make sure data shared_ptr points to is not released until we finish
// work with it.
MSharedPtrStorage.push_back(Src);
T_Dst *RawSrcPtr = Src.get();
T_Src *RawSrcPtr = Src.get();
copy(RawSrcPtr, Dst);
}

Expand Down
27 changes: 27 additions & 0 deletions sycl/test/basic_tests/handler/handler_mem_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ template <typename T> void test_fill(T Val);
template <typename T> void test_copy_ptr_acc();
template <typename T> void test_copy_acc_ptr();
template <typename T> void test_copy_shared_ptr_acc();
template <typename T> void test_copy_shared_ptr_const_acc();
template <typename T> void test_copy_acc_shared_ptr();
template <typename T> void test_copy_acc_acc();
template <typename T> void test_update_host();
Expand Down Expand Up @@ -73,6 +74,14 @@ int main() {
test_copy_shared_ptr_acc<point<int>>();
test_copy_shared_ptr_acc<point<float>>();
}
// handler.copy(const shared_ptr, acc)
{
test_copy_shared_ptr_const_acc<int>();
test_copy_shared_ptr_const_acc<int>();
test_copy_shared_ptr_const_acc<point<int>>();
test_copy_shared_ptr_const_acc<point<int>>();
test_copy_shared_ptr_const_acc<point<float>>();
}
// handler.copy(acc, shared_ptr)
{
test_copy_acc_shared_ptr<int>();
Expand Down Expand Up @@ -202,6 +211,24 @@ template <typename T> void test_copy_shared_ptr_acc() {
}
}

template <typename T> void test_copy_shared_ptr_const_acc() {
constexpr size_t Size = 10;
T Data[Size] = {0};
std::shared_ptr<const T> Values(new T[Size]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
{
buffer<T, 1> Buffer(Data, range<1>(Size));
queue Queue;
Queue.submit([&](handler &Cgh) {
accessor<T, 1, access::mode::write, access::target::global_buffer>
Accessor(Buffer, Cgh, range<1>(Size));
Cgh.copy(Values, Accessor);
});
}
for (size_t I = 0; I < Size; ++I) {
assert(Data[I] == Values.get()[I]);
}
}

template <typename T> void test_copy_acc_shared_ptr() {
const size_t Size = 10;
T Data[Size] = {0};
Expand Down