|
| 1 | +// Copyright 2026 The IREE Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | + |
| 7 | +// Nightly ROCm on MI300X returns a USER-kind queue doorbell signal (not |
| 8 | +// DOORBELL-kind), so the cached doorbell union slot is a signal value, not a |
| 9 | +// writable MMIO address. A raw atomic store to that slot faults — every H2D |
| 10 | +// copy / kernel dispatch would SEGV; the doorbell must be rung via |
| 11 | +// hsa_signal_store_screlease for USER/interrupt-kind doorbells. |
| 12 | +// |
| 13 | +// Each AQL submission rings the doorbell, so a stream of copies with integrity |
| 14 | +// checks exercises that path repeatedly on the affected hardware. GPU required; |
| 15 | +// the SEGV only reproduces on a USER-kind-doorbell runtime. |
| 16 | + |
| 17 | +#include <algorithm> |
| 18 | +#include <cstdint> |
| 19 | +#include <vector> |
| 20 | + |
| 21 | +#include <catch2/catch_test_macros.hpp> |
| 22 | +#include "hip_loader.hpp" |
| 23 | +#include "hip_test_fixture.hpp" |
| 24 | + |
| 25 | +TEST_CASE_METHOD(HipTestFixture, |
| 26 | + "Repeated H2D/D2H roundtrips ring the doorbell correctly", |
| 27 | + "[memcpy][doorbell][nightly]") { |
| 28 | + const size_t kCount = 1u << 20; // 1M uint32 = 4 MiB |
| 29 | + const size_t kBytes = kCount * sizeof(uint32_t); |
| 30 | + std::vector<uint32_t> host_in(kCount); |
| 31 | + std::vector<uint32_t> host_out(kCount, 0u); |
| 32 | + for (size_t i = 0; i < kCount; ++i) { |
| 33 | + host_in[i] = static_cast<uint32_t>(i * 2654435761u); |
| 34 | + } |
| 35 | + |
| 36 | + void* dev = nullptr; |
| 37 | + REQUIRE(hip().hipMalloc(&dev, kBytes) == hipSuccess); |
| 38 | + |
| 39 | + // 32 doorbell rings (H2D + D2H each). On USER-kind-doorbell hardware a raw |
| 40 | + // doorbell store faults on the first ring; a correct runtime copies and the |
| 41 | + // data round-trips intact. |
| 42 | + for (int iter = 0; iter < 32; ++iter) { |
| 43 | + REQUIRE(hip().hipMemcpy(dev, host_in.data(), kBytes, |
| 44 | + hipMemcpyHostToDevice) == hipSuccess); |
| 45 | + std::fill(host_out.begin(), host_out.end(), 0u); |
| 46 | + REQUIRE(hip().hipMemcpy(host_out.data(), dev, kBytes, |
| 47 | + hipMemcpyDeviceToHost) == hipSuccess); |
| 48 | + REQUIRE(host_out == host_in); |
| 49 | + } |
| 50 | + |
| 51 | + REQUIRE(hip().hipFree(dev) == hipSuccess); |
| 52 | +} |
0 commit comments