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

[SYCL][COMPAT] Move clashing functions into anonymous namespace #15446

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
22 changes: 22 additions & 0 deletions sycl/include/syclcompat/memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,9 @@ static inline T *malloc_shared(size_t count,
return static_cast<T *>(sycl::malloc_shared(count * sizeof(T), q));
}

// Anonymous namespace to disable ADL for functions which might clash (memcpy,
// memset, free)
namespace {
/// Allocate memory block for 3D array on the device.
/// \param size Size of the memory block, in bytes.
/// \param q Queue to execute the allocate task.
Expand All @@ -612,6 +615,7 @@ static inline void *malloc(size_t &pitch, size_t x, size_t y,
sycl::queue q = get_default_queue()) {
return detail::malloc(pitch, x, y, 1, q);
}
} // namespace

/// Wait on the queue \p q and free the memory \p ptr.
/// \param ptr Point to free.
Expand All @@ -626,6 +630,7 @@ static inline void wait_and_free(void *ptr,
}
}

namespace {
/// Free the memory \p ptr on the default queue without synchronizing
/// \param ptr Point to free.
/// \returns no return value.
Expand All @@ -634,6 +639,7 @@ static inline void free(void *ptr, sycl::queue q = get_default_queue()) {
sycl::free(ptr, q);
}
}
} // namespace

/// Enqueues the release of all pointers in /p pointers on the /p q.
/// The command waits on all passed /p events and returns an event that
Expand All @@ -659,6 +665,7 @@ inline sycl::event enqueue_free(const std::vector<void *> &pointers,
return event;
}

namespace {
/// Synchronously copies \p size bytes from the address specified by \p from_ptr
/// to the address specified by \p to_ptr. The function will
/// return after the copy is completed.
Expand All @@ -673,6 +680,8 @@ static void memcpy(void *to_ptr, const void *from_ptr, size_t size,
detail::memcpy(q, to_ptr, from_ptr, size).wait();
}

} // namespace

/// Asynchronously copies \p size bytes from the address specified by \p
/// from_ptr to the address specified by \p to_ptr. The return of the function
/// does NOT guarantee the copy is completed.
Expand Down Expand Up @@ -705,6 +714,7 @@ memcpy_async(type_identity_t<T> *to_ptr, const type_identity_t<T> *from_ptr,
static_cast<const void *>(from_ptr), count * sizeof(T));
}

namespace {
/// Synchronously copies \p count T's from the address specified by \p from_ptr
/// to the address specified by \p to_ptr. The function will
/// return after the copy is completed.
Expand Down Expand Up @@ -745,6 +755,8 @@ static inline void memcpy(void *to_ptr, size_t to_pitch, const void *from_ptr,
detail::memcpy(q, to_ptr, from_ptr, to_pitch, from_pitch, x, y));
}

} // namespace

/// Asynchronously copies 2D matrix specified by \p x and \p y from the address
/// specified by \p from_ptr to the address specified by \p to_ptr, while \p
/// \p from_pitch and \p to_pitch are the range of dim x in bytes of the matrix
Expand All @@ -767,6 +779,7 @@ static inline sycl::event memcpy_async(void *to_ptr, size_t to_pitch,
return detail::combine_events(events, q);
}

namespace {
/// Synchronously copies a subset of a 3D matrix specified by \p to to another
/// 3D matrix specified by \p from. The from and to position info are specified
/// by \p from_pos and \p to_pos The copied matrix size is specified by \p size.
Expand All @@ -785,6 +798,7 @@ static inline void memcpy(pitched_data to, sycl::id<3> to_pos,
sycl::queue q = get_default_queue()) {
sycl::event::wait(detail::memcpy(q, to, to_pos, from, from_pos, size));
}
} // namespace

/// Asynchronously copies a subset of a 3D matrix specified by \p to to another
/// 3D matrix specified by \p from. The from and to position info are specified
Expand All @@ -806,6 +820,7 @@ static inline sycl::event memcpy_async(pitched_data to, sycl::id<3> to_pos,
return detail::combine_events(events, q);
}

namespace {
/// Synchronously sets \p pattern to the first \p count elements starting from
/// \p dev_ptr. The function will return after the fill operation is completed.
///
Expand All @@ -820,6 +835,7 @@ static void inline fill(void *dev_ptr, const T &pattern, size_t count,
sycl::queue q = get_default_queue()) {
detail::fill(q, dev_ptr, pattern, count).wait();
}
} // namespace

/// Asynchronously sets \p pattern to the first \p count elements starting from
/// \p dev_ptr.
Expand Down Expand Up @@ -864,6 +880,7 @@ static inline void memcpy_async(const memcpy_parameter &param,
}
} // namespace experimental

namespace {
/// Synchronously sets \p value to the first \p size bytes starting from \p
/// dev_ptr. The function will return after the memset operation is completed.
///
Expand All @@ -876,6 +893,7 @@ static void memset(void *dev_ptr, int value, size_t size,
sycl::queue q = get_default_queue()) {
detail::memset(q, dev_ptr, value, size).wait();
}
} // namespace

/// \brief Sets 2 bytes data \p value to the first \p size elements starting
/// from \p dev_ptr in \p q synchronously.
Expand Down Expand Up @@ -936,6 +954,7 @@ memset_d32_async(void *dev_ptr, unsigned int value, size_t size,
return detail::fill<unsigned int>(q, dev_ptr, value, size);
}

namespace {
/// \brief Sets 1 byte data \p val to the pitched 2D memory region pointed by \p
/// ptr in \p q synchronously.
/// \param [in] ptr Pointer to the virtual device memory.
Expand All @@ -948,6 +967,7 @@ static inline void memset(void *ptr, size_t pitch, int val, size_t x, size_t y,
sycl::queue q = get_default_queue()) {
sycl::event::wait(detail::memset<unsigned char>(q, ptr, pitch, val, x, y));
}
} // namespace

/// \brief Sets 2 bytes data \p val to the pitched 2D memory region pointed by
/// ptr in \p q synchronously.
Expand Down Expand Up @@ -1026,6 +1046,7 @@ memset_d32_async(void *ptr, size_t pitch, unsigned int val, size_t x, size_t y,
return detail::combine_events(events, q);
}

namespace {
/// Sets \p value to the 3D memory region specified by \p pitch in \p q. \p size
/// specify the setted 3D memory size. The function will return after the
/// memset operation is completed.
Expand All @@ -1039,6 +1060,7 @@ static inline void memset(pitched_data pitch, int val, sycl::range<3> size,
sycl::queue q = get_default_queue()) {
sycl::event::wait(detail::memset<unsigned char>(q, pitch, val, size));
}
} // namespace

/// Sets \p value to the 3D memory region specified by \p pitch in \p q. \p size
/// specify the setted 3D memory size. The return of the function does NOT
Expand Down
12 changes: 12 additions & 0 deletions sycl/test/syclcompat/memory_adl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -fsyntax-only
// Test that no syclcompat:: functions clash with global namespace fns due to ADL
#include <sycl/sycl.hpp>
#include <syclcompat/syclcompat.hpp>

int main(){
syclcompat::device_info dummy_info;
syclcompat::device_info dummy_info_2;
memset(&dummy_info, 0, sizeof(syclcompat::device_info));
memcpy(&dummy_info, &dummy_info_2, sizeof(syclcompat::device_info));
free(&dummy_info);
}
Loading