Archived
sycl: rad_memcpy_ranges_async reads its range list on the device, as the contract says
The SYCL backend read the list on the host at the call. device.h says the kernel reads it when it runs, so it may live in device memory or be written by earlier work on the stream; rad-kbench's timer keeps it on the card, and --bench / --timing-only segfaulted in calibration. The prefix is now one copy and the ranges one kernel after it (a work-group a range, 4-byte words, as the HIP card's aql_copy_ranges), so a range over the prefix still lands last. device_test_sycl passes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
1 parent
7a58b31c80
commit
10455f2e1a
1 file changed
+29
-5
+29
-5
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user