Archived
device and plugin boundary: kv_resolve, the streamed store rows, ABI 30
This commit is contained in:
1 parent
32881da9fd
commit
486c933161
34 files changed
+3643
-29
No files matched your search
+44
-5
@@ -2668,9 +2668,10 @@ int64_t a_gate_room(RadStream rs) {
|
||||
|
||||
/* Waits for the mark, then for the card's link gate if a collective has ever held it (under TP
|
||||
* the all-reduce shares the link and the step waits on it, not on these copies), copies, writes
|
||||
* `done`, then the list's number. */
|
||||
* `done`, then the list's number. RAD_XP_NO_YIELD skips the gate: a list the compute stream waits on
|
||||
* cannot outlast a hold whose release is behind that wait (core/kvstream/stage.cpp). */
|
||||
int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* dst, const uint64_t* bytes,
|
||||
uint32_t* done, uint32_t done_val) {
|
||||
uint32_t* done, uint32_t done_val, unsigned flags) {
|
||||
DmaQueue* dq = xp_queue(ord);
|
||||
if (!dq) return RAD_E_UNSUPPORTED;
|
||||
Sig* in = (Sig*)mark;
|
||||
@@ -2684,7 +2685,8 @@ int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* d
|
||||
10u /* interval */ | (0xfffu << 16) /* retry forever */ };
|
||||
rc = dma_put(dq, poll, 6);
|
||||
}
|
||||
if (rc == RAD_OK && n > 0 && lane && lane->ever_held && lane->gate.handle) {
|
||||
if (rc == RAD_OK && n > 0 && lane && lane->ever_held && lane->gate.handle &&
|
||||
!(flags & RAD_XP_NO_YIELD)) {
|
||||
const uint64_t ga = (uint64_t)lane->gate.handle + offsetof(amd_signal_t, value);
|
||||
const uint32_t gate[6] = { kSdmaPoll | (3u << 28) /* equal */ | (1u << 31) /* memory */,
|
||||
(uint32_t)ga, (uint32_t)(ga >> 32), 0u, 1u /* the low bit */,
|
||||
@@ -2719,6 +2721,34 @@ int a_xp_list(int ord, void* mark, int n, const uint64_t* src, const uint64_t* d
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* An event the DMA engine completes (rad_event_dma): a fresh completion word for the event, which
|
||||
* a rad_xp_list writes 0 to as its `done` once its bytes have landed, so a stream that waits on the
|
||||
* event stops until the copy is done.
|
||||
*
|
||||
* The word comes back at 0 and the *caller* arms it with a write of 1 on the stream, because the arm
|
||||
* must be ordered: a host store here would land ahead of a wait still queued for the group's previous
|
||||
* copy (which would then block on this 1 and never see its 0), and an event record would not do
|
||||
* either -- a record completes by decrementing its signal to 0, which is the value the wait is
|
||||
* looking for. A fresh signal each time keeps two uses of one word from overlapping at all. */
|
||||
int a_event_dma(RadEvent re, RadStream rs, uint32_t** word) {
|
||||
if (!word) { device_set_error("rad_event_dma: null word"); return RAD_E_INVAL; }
|
||||
if (capturing()) {
|
||||
device_set_error("rad_event_dma: a tape cannot record a DMA list; the caller must re-run "
|
||||
"this call with the tape paused");
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
Event* e = ev_of(re);
|
||||
Stream* s = ours(rs);
|
||||
if (!e || !s) { device_set_error("rad_event_dma: null or foreign argument"); return RAD_E_INVAL; }
|
||||
Sig* g = sig_get(e->host);
|
||||
if (!g) { device_set_error("rad_event_dma: no signal could be made"); return RAD_E_DEVICE; }
|
||||
hsa_signal_silent_store_relaxed(g->h, 0);
|
||||
g->agent = s->agent;
|
||||
record_adopt(e, g);
|
||||
*word = (uint32_t*)(uintptr_t)sig_value_addr(g);
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
int64_t a_xp_behind(int ord) {
|
||||
DmaQueue* dq = (ord >= 0 && ord < kMaxDevices) ? &g_dma_xp[ord] : nullptr;
|
||||
if (!dq || !dq->tried.load(std::memory_order_acquire) || !dq->ok) return 0;
|
||||
@@ -3376,9 +3406,17 @@ void* pin_pieces(int64_t bytes) {
|
||||
char* const p = (char*)at;
|
||||
|
||||
prefer_numa_node(p, len, current_card_numa_node());
|
||||
/* RADIANCE_NO_HUGE_PAGES asks for small pages, before the pin faults them in: the KV mirror's
|
||||
* scattered 2 KiB reads are the case page size is supposed to matter for, and this is how that
|
||||
* is measured rather than assumed (core/kvstream/mirror.cpp). Not a supported mode. */
|
||||
const bool small_pages = std::getenv("RADIANCE_NO_HUGE_PAGES") != nullptr;
|
||||
if (len >= ((int64_t)2 << 20)) {
|
||||
::madvise(p, (size_t)len, MADV_HUGEPAGE);
|
||||
warn_if_no_huge_pages();
|
||||
if (small_pages) {
|
||||
::madvise(p, (size_t)len, MADV_NOHUGEPAGE);
|
||||
} else {
|
||||
::madvise(p, (size_t)len, MADV_HUGEPAGE);
|
||||
warn_if_no_huge_pages();
|
||||
}
|
||||
}
|
||||
(void)::madvise(p, (size_t)len, MADV_DONTFORK);
|
||||
|
||||
@@ -3604,6 +3642,7 @@ const DeviceBackend* aql_backend_if_present(void) {
|
||||
g_aql.stream_gate = a_stream_gate;
|
||||
g_aql.gate_open = a_gate_open;
|
||||
g_aql.gate_room = a_gate_room;
|
||||
g_aql.event_dma = a_event_dma;
|
||||
return &g_aql;
|
||||
}();
|
||||
return b;
|
||||
|
||||
+20
-2
@@ -113,13 +113,27 @@ extern "C" void* rad_link_gate(RadStream s);
|
||||
* counts lists handed over and not yet finished. The prefetch ring is uncached device memory
|
||||
* (rad_dev_alloc_uncached): the engine writes it and kernels read it, so no cache may hold a
|
||||
* slot's previous contents. */
|
||||
/* An event the DMA engine completes instead of a dispatch: it is recorded on `s` (a write of 1 to
|
||||
* its completion word, in stream order) and `*word` returns that word for `rad_xp_list` to write 0
|
||||
* to as the list's `done`, once the list's bytes have landed. `rad_event_wait(s, ev)` then stops `s`
|
||||
* until the copy is done, device-side: no host round trip on the step path. The caller waits for
|
||||
* the group's previous copy before arming the next, so the word's older 0 cannot release a later
|
||||
* wait. RAD_E_STATE while a tape is recording: a list is not a queue packet, so a recorded pass
|
||||
* must re-run the call with the tape paused (core/kvstream/stage.cpp). */
|
||||
extern "C" int rad_event_dma(RadEvent ev, RadStream s, uint32_t** word);
|
||||
extern "C" int rad_xp_supported(int device);
|
||||
extern "C" int rad_xp_stream_create(RadStream* out);
|
||||
extern "C" int rad_ride(RadStream s, void** token);
|
||||
extern "C" int rad_ride_wait(RadStream s, void* token);
|
||||
extern "C" void rad_ride_release(void* token, RadStream after, int64_t packets);
|
||||
/* `flags` RAD_XP_NO_YIELD: the list does not give way to a link a stream of this card holds. A copy
|
||||
* the compute stream itself waits on must set it -- a yield it cannot outlast is a deadlock (the
|
||||
* hold's release is behind the wait) -- at the cost of taking its share of the link in one piece
|
||||
* (core/kvstream/stage.cpp). The expert prefetch passes 0: nothing waits for it. */
|
||||
#define RAD_XP_NO_YIELD 1u
|
||||
extern "C" int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val,
|
||||
unsigned flags);
|
||||
extern "C" int64_t rad_xp_behind(int device);
|
||||
extern "C" void* rad_dev_alloc_uncached(int64_t bytes);
|
||||
extern "C" void rad_dev_free_uncached(void* p);
|
||||
@@ -316,7 +330,7 @@ struct DeviceBackend {
|
||||
int (*ride_wait)(RadStream s, void* token);
|
||||
void (*ride_release)(void* token, RadStream after, int64_t packets);
|
||||
int (*xp_list)(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
|
||||
const uint64_t* bytes, uint32_t* done, uint32_t done_val, unsigned flags);
|
||||
int64_t (*xp_behind)(int device);
|
||||
void* (*alloc_uncached)(int64_t bytes);
|
||||
void (*free_uncached)(void* p);
|
||||
@@ -325,6 +339,10 @@ struct DeviceBackend {
|
||||
int (*stream_gate)(RadStream s, void** gate);
|
||||
int (*gate_open)(void* gate);
|
||||
int64_t (*gate_room)(RadStream s);
|
||||
|
||||
/* ---- an event a DMA list completes: see rad_event_dma. Null (unsupported) on a backend with
|
||||
* no DMA queue that writes a completion word. */
|
||||
int (*event_dma)(RadEvent e, RadStream s, uint32_t** word);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -549,6 +549,11 @@ void rad_event_destroy(RadEvent e) {
|
||||
dev()->event_destroy(e);
|
||||
}
|
||||
int rad_event_record(RadEvent e, RadStream s) { return dev()->event_record(e, s); }
|
||||
int rad_event_dma(RadEvent e, RadStream s, uint32_t** w) {
|
||||
if (const auto f = dev()->event_dma) return f(e, s, w);
|
||||
rad::device_set_error("rad_event_dma: the device backend has no DMA queue to complete an event");
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
int rad_event_wait(RadStream s, RadEvent e) { return dev()->event_wait(s, e); }
|
||||
int rad_event_query(RadEvent e) { return dev()->event_query(e); }
|
||||
int rad_event_sync(RadEvent e) {
|
||||
@@ -630,8 +635,8 @@ void rad_ride_release(void* token, RadStream after, int64_t packets) {
|
||||
if (const auto f = dev()->ride_release) f(token, after, packets);
|
||||
}
|
||||
int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst, const uint64_t* bytes,
|
||||
uint32_t* done, uint32_t done_val) {
|
||||
if (const auto f = dev()->xp_list) return f(device, mark, n, src, dst, bytes, done, done_val);
|
||||
uint32_t* done, uint32_t done_val, unsigned flags) {
|
||||
if (const auto f = dev()->xp_list) return f(device, mark, n, src, dst, bytes, done, done_val, flags);
|
||||
return RAD_E_UNSUPPORTED;
|
||||
}
|
||||
int64_t rad_xp_behind(int device) {
|
||||
|
||||
@@ -816,6 +816,7 @@ const DeviceBackend g_host = {
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
|
||||
|
||||
h_stream_gate, h_gate_open, h_gate_room,
|
||||
nullptr, /* no DMA queue, so no event it could complete */
|
||||
};
|
||||
|
||||
} /* namespace */
|
||||
|
||||
Reference in new issue
Block a user