diff --git a/core/device/sycl.cpp b/core/device/sycl.cpp index 55ddf7b6..4e2e26e1 100644 --- a/core/device/sycl.cpp +++ b/core/device/sycl.cpp @@ -688,8 +688,15 @@ int d_memset_async(void* dst, int value, int64_t bytes, RadStream st) { return RAD_OK; } -/* The list is read here, at the call. The contract (device.h) requires it unchanged until the - * stream passes the copy, so reading it early copies the same bytes. */ +/* The prefix as one copy, then one kernel in which work-group i copies range i in 4-byte words + * (ranges are only 4-byte aligned), as the HIP card's aql_copy_ranges does. The list is read by the + * kernel when it runs: it may live in device memory, or be written by earlier work on the stream + * (rad-kbench's timer keeps it on the card). The in-order queue puts the ranges after the prefix, + * so a range over the prefix wins, which a single kernel copying both at once would leave to + * scheduling. */ +constexpr size_t kRangeWg = 256; +constexpr int kRangeWords = 16; + int d_memcpy_ranges_async(void* dst, const void* src, int64_t prefix, const RadCopyRange* ranges, int n, RadStream st) { RAD_TRY(check_stream(st, "rad_memcpy_ranges_async")); @@ -711,9 +718,26 @@ int d_memcpy_ranges_async(void* dst, const void* src, int64_t prefix, const RadC const char* s = (const char*)src; SYCL_TRY("rad_memcpy_ranges_async", { if (prefix > 0) q.memcpy(d, s, (size_t)prefix); - for (int i = 0; i < n; ++i) - if (ranges[i].bytes > 0) - q.memcpy(d + ranges[i].dst, s + ranges[i].src, (size_t)ranges[i].bytes); + if (n > 0) { + q.parallel_for(sycl::nd_range<1>{(size_t)n * kRangeWg, kRangeWg}, [=](sycl::nd_item<1> it) { + const size_t t = it.get_local_id(0); + const RadCopyRange r = ranges[it.get_group(0)]; + const uint32_t* s4 = (const uint32_t*)(s + r.src); + uint32_t* d4 = (uint32_t*)(d + r.dst); + const int64_t nw = r.bytes / 4; + for (int64_t base = 0; base < nw; base += (int64_t)kRangeWg * kRangeWords) { + uint32_t v[kRangeWords]; + for (int k = 0; k < kRangeWords; ++k) { + const int64_t w = base + (int64_t)k * kRangeWg + (int64_t)t; + v[k] = s4[w < nw ? w : nw - 1]; + } + for (int k = 0; k < kRangeWords; ++k) { + const int64_t w = base + (int64_t)k * kRangeWg + (int64_t)t; + if (w < nw) d4[w] = v[k]; + } + } + }); + } }); return RAD_OK; }