device/sycl: range copies stage host sources on the device first -- 650 us -> gone a step upload

The step upload's range kernel read its range list and sources from pinned host memory, a link
round trip a load (PCIe x1 on the B65): 3 calls a speculative round at 650 us. Their span and the
list now cross in one transfer each into a per-stream device buffer. device_test_sycl passes;
greedy output identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-25 13:28:00 +01:00
1 parent 36b8941096
commit 1b2cc6d826
1 file changed
+29 -1
+29 -1
View File
@@ -447,6 +447,8 @@ struct SyclStream {
RadSyclStream pub;
sycl::queue q;
std::atomic<int> gates{0}; /* closed gates on this stream (rad_stream_gate) */
char* stage = nullptr; /* rad_memcpy_ranges_async's device copy of host sources */
size_t stage_n = 0;
SyclStream(const sycl::context& c, const sycl::device& d, const sycl::property_list& pl)
: pub{}, q(c, d, async_handler, pl) {}
};
@@ -504,6 +506,7 @@ void d_stream_destroy(RadStream st) {
} catch (const sycl::exception& e) {
RAD_WARN("device: rad_stream_destroy: %s", e.what());
}
if (s->stage) sycl::free(s->stage, s->q);
s->pub.magic = 0;
delete s;
}
@@ -713,11 +716,36 @@ int d_memcpy_ranges_async(void* dst, const void* src, int64_t prefix, const RadC
dst, src);
return RAD_E_UNSUPPORTED;
}
sycl::queue& q = as_stream(st)->q;
SyclStream* ss = as_stream(st);
sycl::queue& q = ss->q;
char* d = (char*)dst;
const char* s = (const char*)src;
SYCL_TRY("rad_memcpy_ranges_async", {
if (prefix > 0) q.memcpy(d, s, (size_t)prefix);
/* Sources and ranges in host memory (the step upload's pinned staging): read by the copy
* kernel they cost a link round trip a load -- 650 us a call over a PCIe x1 link -- so
* their span and the range list cross first in one transfer each, into a device buffer
* of the stream's (in order, so the next call's copy waits for this kernel). */
if (n > 0 && ptr_kind(src) != sycl::usm::alloc::device && ptr_kind(ranges) != sycl::usm::alloc::device) {
int64_t lo = INT64_MAX, hi = 0;
for (int i = 0; i < n; ++i) {
lo = std::min<int64_t>(lo, ranges[i].src);
hi = std::max<int64_t>(hi, ranges[i].src + ranges[i].bytes);
}
lo &= ~(int64_t)15;
const size_t span = (size_t)(hi - lo + 15) / 16 * 16, rb = (size_t)n * sizeof(RadCopyRange);
if (ss->stage_n < span + rb) {
q.wait();
if (ss->stage) sycl::free(ss->stage, q);
ss->stage_n = (span + rb) * 2;
ss->stage = (char*)sycl::malloc_device(ss->stage_n, q);
if (!ss->stage) { ss->stage_n = 0; throw sycl::exception(sycl::make_error_code(sycl::errc::memory_allocation), "range staging"); }
}
q.memcpy(ss->stage, s + lo, (size_t)(hi - lo));
q.memcpy(ss->stage + span, ranges, rb);
s = ss->stage - lo;
ranges = (const RadCopyRange*)(ss->stage + span);
}
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);