mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
Each code-object load synced the GPU's code caches before returning: on the R9700, 9.8-10 ms per load and about 600 ms for the 60 loads of a new LSE pass width. The prefill agent's profile of a cold 137-token prompt put 1.3 s of its 1.7 s TTFT in this stack. With a driver that serves CodeSync (build 258 on), a load now only marks the connection's code pending. The doorbell hook syncs once before the next doorbell of any of the connection's queues, outside the queue's mutex. Every AQL packet reaches the GPU through that hook, and no packet runs before its doorbell, so new code still never runs from stale caches. A failed sync stays owed and fails that queue with the error. The sync is CodeSync itself (selector 90), a kernel-ring cache invalidate with no queue created, so it never needs a queue slot. Drivers before 258 keep the old per-load sync, because their fallback puts a packet in a runtime queue, which from the doorbell path would land after the application's own packet. hsa-code-sync-coalesce-test, on a build 258 fake: eight loads cost no sync; the next doorbell runs exactly one, ahead of that doorbell; a later doorbell with nothing loaded runs none; one more load costs one more sync at its doorbell; nothing is put in the application's queue. The existing code-sync test still covers the old drivers' path.
81 lines
4.1 KiB
C++
81 lines
4.1 KiB
C++
// Host unit test: code syncs coalesced (driver build kCodeSyncDriverBuild
|
|
// on). Loading code objects only marks the connection's code pending; one
|
|
// sync runs before the next doorbell of any of its queues, ahead of that
|
|
// doorbell, and nothing more until code is loaded again. A program loading
|
|
// dozens of code objects (a new LSE pass width loads 55-60) pays one sync.
|
|
|
|
#include "mac_hsa.h"
|
|
#include "signal_kernels.h"
|
|
#include "transport_fake.h"
|
|
#include <hsa/hsa_ext_amd.h>
|
|
#include <cstdio>
|
|
#include <string>
|
|
|
|
static int failures = 0;
|
|
#define CHECK(cond, msg) do { \
|
|
if (!(cond)) { std::fprintf(stderr, "FAIL: %s (line %d)\n", std::string(msg).c_str(), __LINE__); ++failures; } \
|
|
else { std::fprintf(stderr, " ok: %s\n", std::string(msg).c_str()); } \
|
|
} while (0)
|
|
|
|
static hsa_status_t load(hsa_agent_t gpu, std::span<const uint8_t> object, hsa_executable_t &executable) {
|
|
hsa_code_object_reader_t reader{};
|
|
auto status = hsa_code_object_reader_create_from_memory(object.data(), object.size(), &reader);
|
|
if (status != HSA_STATUS_SUCCESS) return status;
|
|
status = hsa_executable_create_alt(HSA_PROFILE_BASE, HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT, nullptr, &executable);
|
|
if (status == HSA_STATUS_SUCCESS) status = hsa_executable_load_agent_code_object(executable, gpu, reader, nullptr, nullptr);
|
|
if (status == HSA_STATUS_SUCCESS) status = hsa_executable_freeze(executable, nullptr);
|
|
hsa_code_object_reader_destroy(reader);
|
|
return status;
|
|
}
|
|
|
|
int main() {
|
|
mac_hsa::FakeDeviceConfig config;
|
|
config.gcMajor = 12; config.gcMinor = 0; config.gcRevision = 0;
|
|
config.build = mac_hsa::kCodeSyncDriverBuild;
|
|
mac_hsa::setFakeDeviceConfig(config);
|
|
CHECK(hsa_init() == HSA_STATUS_SUCCESS, "hsa_init");
|
|
hsa_agent_t gpu{};
|
|
hsa_iterate_agents([](hsa_agent_t agent, void *data) -> hsa_status_t {
|
|
hsa_device_type_t type;
|
|
if (hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &type) == HSA_STATUS_SUCCESS &&
|
|
type == HSA_DEVICE_TYPE_GPU) *static_cast<hsa_agent_t *>(data) = agent;
|
|
return HSA_STATUS_SUCCESS;
|
|
}, &gpu);
|
|
const auto fake = mac_hsa::fakeConnection();
|
|
mac_hsa::IsaTarget isa;
|
|
mac_hsa::SignalKernelObjects objects;
|
|
CHECK(mac_hsa::resolveIsaTarget(120000, mac_hsa::TargetFeature::Off, mac_hsa::TargetFeature::Any, isa) &&
|
|
mac_hsa::selectSignalKernels(isa, objects) && !objects.operations.empty(), "a code object to load");
|
|
if (failures) return 1;
|
|
|
|
hsa_queue_t *queue = nullptr;
|
|
CHECK(hsa_queue_create(gpu, 64, HSA_QUEUE_TYPE_MULTI, nullptr, nullptr, 0, 0, &queue) == HSA_STATUS_SUCCESS,
|
|
"a queue");
|
|
const uint64_t before = fake->codeSyncCount();
|
|
hsa_executable_t executables[8]{};
|
|
bool loaded = true;
|
|
for (auto &executable : executables) loaded &= load(gpu, objects.operations, executable) == HSA_STATUS_SUCCESS;
|
|
CHECK(loaded, "eight code objects load");
|
|
CHECK(fake->codeSyncCount() == before && fake->queueCodeSyncCount() == 0, "no sync at load");
|
|
|
|
hsa_signal_store_screlease(queue->doorbell_signal, 0);
|
|
CHECK(fake->codeSyncCount() == before + 1, "one sync for all eight, at the next doorbell");
|
|
CHECK(fake->kicksAtLastCodeSync() == 0, "and ahead of that doorbell");
|
|
hsa_signal_store_screlease(queue->doorbell_signal, 0);
|
|
CHECK(fake->codeSyncCount() == before + 1, "a later doorbell with nothing loaded syncs nothing");
|
|
|
|
hsa_executable_t more{};
|
|
CHECK(load(gpu, objects.operations, more) == HSA_STATUS_SUCCESS, "one more load");
|
|
hsa_signal_store_screlease(queue->doorbell_signal, 0);
|
|
CHECK(fake->codeSyncCount() == before + 2 && fake->kicksAtLastCodeSync() == 2,
|
|
"its sync runs at the next doorbell, before it");
|
|
CHECK(fake->queueCodeSyncCount() == 0, "no packet was put in the application's queue");
|
|
|
|
for (auto executable : executables) hsa_executable_destroy(executable);
|
|
hsa_executable_destroy(more);
|
|
CHECK(hsa_queue_destroy(queue) == HSA_STATUS_SUCCESS, "queue destroyed");
|
|
hsa_shut_down();
|
|
std::fprintf(stderr, "\n%s: %d failure(s)\n", failures ? "FAIL" : "PASS", failures);
|
|
return failures ? 1 : 0;
|
|
}
|