Skip to content

Commit 73ba5a1

Browse files
committed
Put functions which might clash in anonymous namespace
Some syclcompat:: functions clash with global namespace (C-style) functions because of Argument Dependent Lookup. These are: - memcpy - memset - free To prevent ADL from finding syclcompat:: funcs, they have beeen moved into an anonymous namespace.
1 parent 57eb129 commit 73ba5a1

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

sycl/include/syclcompat/memory.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,9 @@ static inline T *malloc_shared(size_t count,
588588
return static_cast<T *>(sycl::malloc_shared(count * sizeof(T), q));
589589
}
590590

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

10431065
/// Sets \p value to the 3D memory region specified by \p pitch in \p q. \p size
10441066
/// specify the setted 3D memory size. The return of the function does NOT
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -fsyntax-only
2+
// Test that no syclcompat:: functions clash with global namespace fns due to ADL
3+
#include <sycl/sycl.hpp>
4+
#include <syclcompat/syclcompat.hpp>
5+
6+
int main(){
7+
syclcompat::device_info dummy_info;
8+
syclcompat::device_info dummy_info_2;
9+
memset(&dummy_info, 0, sizeof(syclcompat::device_info));
10+
memcpy(&dummy_info, &dummy_info_2, sizeof(syclcompat::device_info));
11+
free(&dummy_info);
12+
}

0 commit comments

Comments
 (0)