mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
The device spec comes back as a versioned structure
QueryInfo tag 8 was never served by this driver (it declined with kIOReturnNotReady), and the HSA runtime asked for it as 32 scalar outputs, twice IOKit's limit, so mac_hsa_agent_get_device_spec always declined. The driver now answers tag 8 with a structure output, session_state.h's struct mlg_device_spec (version 1, the bytes filled, a mask of the field groups present). An async call gets it through OWNER_RESULT. Every field is upstream's own: - the GC geometry (gfx.config) and the KFD node's per-CU properties; - the CUs, shader arrays and render backends upstream left active (gfx.cu_info, backend_enable_mask, num_rbs); - on GC 12, the shader-array disable registers upstream reads for its own SA bitmap, read the same way without a GRBM select. No register is written. A caller with less room than the structure gets its first bytes, at least the header. mac_hsa_agent_get_device_spec keeps its 32-word layout. A group the driver does not report is zero. Words 23-27 (SH_MEM_CONFIG/BASES, the shader-array config registers and GRBM_GFX_CNTL) stay zero, since reading them needs a select, which is a register write. The CU bitmap words carry two shader arrays for each of four engines. mac_hsa.h says so. Tests: test-device-topology checks rt_device_spec against upstream state and register reads, including no register read off GC 12 or without hardware access. test-dext-compute-production checks the structure and its room. test-client-transports checks the HSA runtime reading it through an owner call and OWNER_RESULT; before this change it declined (0x1001).
This commit is contained in:
1 parent
5a437c81cc
commit
e317a1fb11
13 files changed
+357
-19
No files matched your search
@@ -4503,8 +4503,25 @@ MacLinuxGPUUserClient::ExternalMethod(uint64_t selector,
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
|
||||
// The device spec: a structure output (session_state.h), out[0] its size.
|
||||
if (in && arguments->scalarInputCount == 1 && in[0] == MLG_QUERY_DEVICE_SPEC) {
|
||||
struct mlg_device_spec spec = {};
|
||||
const size_t room = arguments->structureOutputMaximumSize < sizeof(spec) ?
|
||||
(size_t)arguments->structureOutputMaximumSize : sizeof(spec);
|
||||
const int n = dext_compute_device_spec(&spec, room);
|
||||
if (n < 0) return n == -ENOTREADY_L ? kIOReturnNotReady : kIOReturnBadArgument;
|
||||
arguments->structureOutput = OSData::withBytes(&spec, (size_t)n);
|
||||
if (!arguments->structureOutput) return kIOReturnNoMemory;
|
||||
if (out && arguments->scalarOutputCount >= 1) {
|
||||
out[0] = (uint64_t)n;
|
||||
arguments->scalarOutputCount = 1;
|
||||
} else {
|
||||
arguments->scalarOutputCount = 0;
|
||||
}
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
// in[0]=info tag; out[N]=type-specific payload (the reference's tags
|
||||
// 1/2/3/4/5/6/8).
|
||||
// 1/2/3/4/5/6).
|
||||
if (arguments->scalarInput == nullptr || arguments->scalarInputCount < 1 ||
|
||||
arguments->scalarOutput == nullptr || arguments->scalarOutputCount < 1)
|
||||
return kIOReturnBadArgument;
|
||||
|
||||
@@ -242,6 +242,14 @@ int dext_compute_quiescent(void)
|
||||
|
||||
void dext_compute_device_removed(void) {}
|
||||
|
||||
/* The device spec needs the upstream device: none in the host build. */
|
||||
int dext_compute_device_spec(void *out, size_t cap)
|
||||
{
|
||||
(void)out;
|
||||
(void)cap;
|
||||
return -ENOTREADY_L;
|
||||
}
|
||||
|
||||
/* QueryInfo (21): in tag, out values[]. Returns the number of out values
|
||||
* written on success (the caller copies them to scalarOutput + sets
|
||||
* scalarOutputCount), or a -E*_L error. */
|
||||
|
||||
@@ -140,6 +140,11 @@ int dext_compute_quiescent(void);
|
||||
/* QueryInfo (21): in tag, out values[]. Returns the number of out values
|
||||
* written on success, or a -E*_L error. */
|
||||
int dext_compute_query_info(uint64_t tag, uint64_t *out, int out_cap);
|
||||
/* QueryInfo tag 8 (session_state.h's struct mlg_device_spec): up to @cap
|
||||
* bytes of it in @out; the bytes filled, or a negative linuxu errno
|
||||
* (-ENOTREADY_L before the device is up, -EINVAL_L for room under the
|
||||
* header). */
|
||||
int dext_compute_device_spec(void *out, size_t cap);
|
||||
|
||||
/* BOAlloc (16): in size/domain/alignment/flags, out handle/gpu_va/cpu_addr. */
|
||||
int dext_compute_bo_alloc(uint64_t size, uint32_t domain, uint64_t alignment,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <rt/queue.h>
|
||||
#include "dext_aql.h"
|
||||
#include "dext_kfd.h"
|
||||
#include "session_state.h"
|
||||
|
||||
#define DEXT_RUNTIME_MAGIC 0x414d444750554142ull
|
||||
#define DEXT_RUNTIME_ABI 1u
|
||||
@@ -714,12 +715,49 @@ int dext_compute_query_info(uint64_t tag, uint64_t *out, int out_cap)
|
||||
return 6;
|
||||
}
|
||||
case 5: /* No upstream per-client VRAM accounting snapshot yet. */
|
||||
case 8: /* No raw GC register spec observer yet. */
|
||||
case 8: /* a structure: dext_compute_device_spec */
|
||||
default:
|
||||
return -ENOTREADY_L;
|
||||
}
|
||||
}
|
||||
|
||||
int dext_compute_device_spec(void *out, size_t cap)
|
||||
{
|
||||
struct rt_device_spec rt;
|
||||
struct mlg_device_spec spec;
|
||||
size_t n;
|
||||
if (!out || cap < 4 * sizeof(uint32_t)) return -EINVAL_L;
|
||||
if (!production_ready() || rt_device_spec(rt_compute_device(production.ctx), &rt) != 0)
|
||||
return -ENOTREADY_L;
|
||||
memset(&spec, 0, sizeof(spec));
|
||||
spec.version = MLG_DEVICE_SPEC_VERSION;
|
||||
spec.present = rt.present; /* RT_DEVICE_SPEC_* are MLG_DEVICE_SPEC_* */
|
||||
spec.shader_engines = rt.shader_engines;
|
||||
spec.shader_arrays_per_se = rt.shader_arrays_per_se;
|
||||
spec.backends_per_se = rt.backends_per_se;
|
||||
spec.cus_per_array = rt.cus_per_array;
|
||||
spec.wavefront_size = rt.wavefront_size;
|
||||
spec.max_waves_per_simd = rt.max_waves_per_simd;
|
||||
spec.scratch_slots_per_cu = rt.scratch_slots_per_cu;
|
||||
spec.lds_bytes = rt.lds_bytes;
|
||||
spec.active_cus = rt.active_cus;
|
||||
memcpy(spec.cu_bitmap, rt.cu_bitmap, sizeof(spec.cu_bitmap));
|
||||
spec.active_sa_bitmap = rt.active_sa_bitmap;
|
||||
spec.cc_sa_disable = rt.cc_sa_disable;
|
||||
spec.user_sa_disable = rt.user_sa_disable;
|
||||
spec.active_rb_bitmap = rt.active_rb_bitmap;
|
||||
spec.active_rbs = rt.active_rbs;
|
||||
n = cap < sizeof(spec) ? cap : sizeof(spec);
|
||||
spec.size = (uint32_t)n;
|
||||
memcpy(out, &spec, n);
|
||||
return (int)n;
|
||||
}
|
||||
_Static_assert(RT_DEVICE_SPEC_GEOMETRY == MLG_DEVICE_SPEC_GEOMETRY &&
|
||||
RT_DEVICE_SPEC_CUS == MLG_DEVICE_SPEC_CUS &&
|
||||
RT_DEVICE_SPEC_SHADER_ARRAYS == MLG_DEVICE_SPEC_SHADER_ARRAYS &&
|
||||
RT_DEVICE_SPEC_SA_DISABLE == MLG_DEVICE_SPEC_SA_DISABLE &&
|
||||
RT_DEVICE_SPEC_BACKENDS == MLG_DEVICE_SPEC_BACKENDS, "device spec groups");
|
||||
|
||||
int dext_compute_bo_alloc(uint64_t size, uint32_t domain, uint64_t alignment,
|
||||
uint64_t flags, uint64_t *out_handle,
|
||||
uint64_t *out_gpu_va, uint64_t *out_cpu_addr)
|
||||
|
||||
@@ -405,6 +405,35 @@ struct mlg_display_present {
|
||||
#define MLG_DRM_SELFTEST_WORDS 2u
|
||||
#define MLG_DRM_SELFTEST_RESULT_MAX 512u
|
||||
|
||||
/* QueryInfo tag 8: the device spec, as a structure output (struct
|
||||
* mlg_device_spec; through OWNER_RESULT for an async call), out[0] its
|
||||
* size. Every field is upstream's own: the GC geometry and the CUs, shader
|
||||
* arrays and render backends it left active (adev->gfx.config, cu_info,
|
||||
* the KFD node's properties), and, on GC 12, the shader-array disable
|
||||
* registers it reads (read only; no register is written). A field group
|
||||
* not set in @present was not reported. Clients size their buffer to the
|
||||
* struct they know and read @size of it; later versions only append. */
|
||||
#define MLG_QUERY_DEVICE_SPEC 8u
|
||||
#define MLG_DEVICE_SPEC_VERSION 1u
|
||||
#define MLG_DEVICE_SPEC_GEOMETRY (1u << 0) /* shader_engines .. lds_bytes */
|
||||
#define MLG_DEVICE_SPEC_CUS (1u << 1) /* active_cus, cu_bitmap */
|
||||
#define MLG_DEVICE_SPEC_SHADER_ARRAYS (1u << 2) /* active_sa_bitmap */
|
||||
#define MLG_DEVICE_SPEC_SA_DISABLE (1u << 3) /* cc_sa_disable, user_sa_disable */
|
||||
#define MLG_DEVICE_SPEC_BACKENDS (1u << 4) /* active_rb_bitmap, active_rbs */
|
||||
struct mlg_device_spec {
|
||||
uint32_t version; /* MLG_DEVICE_SPEC_VERSION */
|
||||
uint32_t size; /* bytes of this struct the driver filled */
|
||||
uint32_t present; /* MLG_DEVICE_SPEC_* */
|
||||
uint32_t reserved;
|
||||
uint32_t shader_engines, shader_arrays_per_se, backends_per_se, cus_per_array;
|
||||
uint32_t wavefront_size, max_waves_per_simd, scratch_slots_per_cu, lds_bytes;
|
||||
uint32_t active_cus;
|
||||
uint32_t cu_bitmap[4][4]; /* [shader engine][shader array], as KFD's */
|
||||
uint32_t active_sa_bitmap; /* bit se * arrays_per_se + sa */
|
||||
uint32_t cc_sa_disable, user_sa_disable; /* GRBM_CC/GC_USER_SA_UNIT_DISABLE, raw */
|
||||
uint32_t active_rb_bitmap, active_rbs;
|
||||
};
|
||||
|
||||
#define MLG_SYSFS_OP_READ 0u
|
||||
#define MLG_SYSFS_OP_LIST 1u
|
||||
#define MLG_SYSFS_PATH_MAX 256u
|
||||
|
||||
+12
-10
@@ -25,18 +25,20 @@ hsa_status_t mac_hsa_agent_get_driver_info(hsa_agent_t agent,
|
||||
mac_hsa_device_info_t *info,
|
||||
size_t info_size);
|
||||
|
||||
// Raw register-level device spec for the agent's GPU, read by the driver's
|
||||
// observer QueryInfo (info tag 8) from the GC_INFO discovery table and the
|
||||
// live harvest / disable-mask / SH-block registers. The block is 32 dwords:
|
||||
// [0] header, 0 when the driver has not resolved the GC IP yet
|
||||
// [1..8] physical geometry: shader engines, shader arrays/SE, backends/SE,
|
||||
// The agent's GPU spec, from the driver's QueryInfo tag 8: upstream amdgpu's
|
||||
// GC geometry and what it left active (session_state.h's struct
|
||||
// mlg_device_spec). The block is 32 dwords:
|
||||
// [0] header: the driver's spec version, 0 when the GC IP is not resolved
|
||||
// [1..8] geometry: shader engines, shader arrays/SE, backends/SE,
|
||||
// CUs/array, wavefront size, max waves/SIMD, scratch slots/CU, LDS bytes
|
||||
// [9] active CU count (harvested), [10..17] KFD 4x4 CU bitmap
|
||||
// [18] active SA bitmap, [19] CC SA disable, [20] user SA disable
|
||||
// [9] active CU count (harvested), [10..17] active CU bitmaps, as KFD's,
|
||||
// [10 + 2 * engine + array] for four engines of two arrays
|
||||
// [18] active SA bitmap, [19] GRBM_CC_GC_SA_UNIT_DISABLE raw,
|
||||
// [20] GRBM_GC_USER_SA_UNIT_DISABLE raw (GC 12; 0 elsewhere)
|
||||
// [21] active RB bitmap, [22] active RB count
|
||||
// [23] SH_MEM_CONFIG (VMID 0), [24] SH_MEM_BASES (VMID 0)
|
||||
// [25] CC_GC_SHADER_ARRAY_CONFIG raw, [26] GC_USER_SHADER_ARRAY_CONFIG raw
|
||||
// [27] GRBM_GFX_CNTL readback (0 after deselect)
|
||||
// [23..27] 0: SH_MEM_CONFIG/BASES, the shader-array config registers and
|
||||
// GRBM_GFX_CNTL need a GRBM or SRBM select (a register write), which
|
||||
// this read-only query does not make
|
||||
// [28..31] reserved
|
||||
// A driver that predates the tag declines with HSA_STATUS_ERROR_INVALID_ARGUMENT.
|
||||
typedef struct mac_hsa_device_spec_s {
|
||||
|
||||
@@ -93,6 +93,34 @@ static hsa_status_t openSessionClient(io_service_t service, io_connect_t &port)
|
||||
}
|
||||
}
|
||||
|
||||
// The driver's device spec (session_state.h) in mac_hsa_device_spec_t's
|
||||
// 32 words (mac_hsa.h): a group the driver did not report stays zero; the
|
||||
// CU bitmap words carry two shader arrays per engine for four engines.
|
||||
static void deviceSpecWords(const mlg_device_spec &spec, std::array<uint64_t, mac_hsa::kDeviceSpecDwords> &w)
|
||||
{
|
||||
w.fill(0);
|
||||
if (!(spec.present & MLG_DEVICE_SPEC_GEOMETRY)) return; // header 0: GC not resolved
|
||||
w[0] = spec.version;
|
||||
const uint32_t geometry[8] = {spec.shader_engines, spec.shader_arrays_per_se, spec.backends_per_se,
|
||||
spec.cus_per_array, spec.wavefront_size, spec.max_waves_per_simd,
|
||||
spec.scratch_slots_per_cu, spec.lds_bytes};
|
||||
for (unsigned i = 0; i < 8; ++i) w[1 + i] = geometry[i];
|
||||
if (spec.present & MLG_DEVICE_SPEC_CUS) {
|
||||
w[9] = spec.active_cus;
|
||||
for (unsigned se = 0; se < 4; ++se)
|
||||
for (unsigned sa = 0; sa < 2; ++sa) w[10 + se * 2 + sa] = spec.cu_bitmap[se][sa];
|
||||
}
|
||||
if (spec.present & MLG_DEVICE_SPEC_SHADER_ARRAYS) w[18] = spec.active_sa_bitmap;
|
||||
if (spec.present & MLG_DEVICE_SPEC_SA_DISABLE) {
|
||||
w[19] = spec.cc_sa_disable;
|
||||
w[20] = spec.user_sa_disable;
|
||||
}
|
||||
if (spec.present & MLG_DEVICE_SPEC_BACKENDS) {
|
||||
w[21] = spec.active_rb_bitmap;
|
||||
w[22] = spec.active_rbs;
|
||||
}
|
||||
}
|
||||
|
||||
// Whether each open connection's driver serves session calls async
|
||||
// (host/selector_call.h): checked on its first async call, forgotten when
|
||||
// it closes.
|
||||
@@ -256,13 +284,28 @@ public:
|
||||
}
|
||||
|
||||
hsa_status_t spec(std::array<uint64_t, kDeviceSpecDwords> &out) override {
|
||||
// Observer QueryInfo tag 8: raw register-level spec from the driver
|
||||
// (GC_INFO geometry + harvest masks + SH-block registers). Requires
|
||||
// the driver build that serves it; older drivers return
|
||||
// kIOReturnNotReady, which maps to an invalid-argument decline here.
|
||||
// QueryInfo tag 8. The Linux-shim driver answers a structure
|
||||
// (session_state.h's struct mlg_device_spec, through OWNER_RESULT);
|
||||
// one that predates it declines (kIOReturnNotReady or
|
||||
// kIOReturnBadArgument), which is an invalid-argument decline here.
|
||||
std::lock_guard lock(sessionMutex);
|
||||
auto status=ensureReady();
|
||||
if (status!=HSA_STATUS_SUCCESS) return status;
|
||||
if (linuxShim) {
|
||||
mlg_device_spec spec{};
|
||||
const uint64_t tag=MLG_QUERY_DEVICE_SPEC;
|
||||
uint64_t bytes=0;
|
||||
uint32_t count=1;
|
||||
size_t size=sizeof(spec);
|
||||
const auto result=rpcMethod(ownerPort,21,&tag,1,nullptr,0,&bytes,&count,&spec,&size);
|
||||
if (result==kIOReturnNotReady || result==kIOReturnBadArgument || result==kIOReturnUnsupported)
|
||||
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
if (result!=KERN_SUCCESS) return HSA_STATUS_ERROR;
|
||||
if (size<4*sizeof(uint32_t) || spec.version<1 || spec.size!=size || (count && bytes!=size))
|
||||
return HSA_STATUS_ERROR;
|
||||
deviceSpecWords(spec,out);
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
std::array<uint64_t,3> build{};
|
||||
status=scalar(43,{},build);
|
||||
if (status!=HSA_STATUS_SUCCESS) return status;
|
||||
|
||||
@@ -72,6 +72,24 @@ struct rt_compute_topology {
|
||||
char product_name[64];
|
||||
};
|
||||
|
||||
/* The GC geometry and what upstream left active (QueryInfo tag 8). */
|
||||
#define RT_DEVICE_SPEC_GEOMETRY (1u << 0)
|
||||
#define RT_DEVICE_SPEC_CUS (1u << 1)
|
||||
#define RT_DEVICE_SPEC_SHADER_ARRAYS (1u << 2)
|
||||
#define RT_DEVICE_SPEC_SA_DISABLE (1u << 3)
|
||||
#define RT_DEVICE_SPEC_BACKENDS (1u << 4)
|
||||
struct rt_device_spec {
|
||||
uint32_t present; /* RT_DEVICE_SPEC_* */
|
||||
uint32_t shader_engines, shader_arrays_per_se, backends_per_se, cus_per_array;
|
||||
uint32_t wavefront_size, max_waves_per_simd, scratch_slots_per_cu, lds_bytes;
|
||||
uint32_t active_cus;
|
||||
uint32_t cu_bitmap[4][4];
|
||||
uint32_t active_sa_bitmap;
|
||||
uint32_t cc_sa_disable, user_sa_disable;
|
||||
uint32_t active_rb_bitmap, active_rbs;
|
||||
};
|
||||
int rt_device_spec(struct amdgpu_device *adev, struct rt_device_spec *out);
|
||||
|
||||
struct rt_compute_bo_info {
|
||||
uint64_t size;
|
||||
uint64_t gpu_address;
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include "amdgpu_fru_eeprom.h"
|
||||
#include "kfd_priv.h"
|
||||
#include "kfd_topology.h"
|
||||
#include "soc15_common.h"
|
||||
#include "gc/gc_12_0_0_offset.h"
|
||||
#include "gc/gc_12_0_0_sh_mask.h"
|
||||
|
||||
_Static_assert(sizeof(((struct rt_compute_topology *)0)->product_name) ==
|
||||
AMDGPU_PRODUCT_NAME_LEN, "product name length");
|
||||
@@ -97,3 +100,59 @@ int rt_device_topology(struct amdgpu_device *adev, struct rt_compute_topology *o
|
||||
sizeof(out->product_name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* QueryInfo tag 8. Upstream's own state: the GC geometry (gfx.config), the
|
||||
* CUs it found active (gfx.cu_info, as KFD reports them), the render
|
||||
* backends (backend_enable_mask), the KFD node's per-CU properties. On GC
|
||||
* 12 the shader-array disable registers upstream reads for its own SA
|
||||
* bitmap (gfx_v12_0_get_sa_active_bitmap) are read the same way, without a
|
||||
* GRBM select: read only. */
|
||||
int rt_device_spec(struct amdgpu_device *adev, struct rt_device_spec *out)
|
||||
{
|
||||
struct rt_compute_topology topology;
|
||||
const struct amdgpu_gfx_config *c;
|
||||
const struct amdgpu_cu_info *cu;
|
||||
unsigned int ses, sas;
|
||||
|
||||
if (!adev || !out)
|
||||
return -EINVAL;
|
||||
memset(out, 0, sizeof(*out));
|
||||
c = &adev->gfx.config;
|
||||
cu = &adev->gfx.cu_info;
|
||||
if (!c->max_shader_engines || !c->max_sh_per_se)
|
||||
return -ENODEV; /* the GC IP is not resolved yet */
|
||||
if (rt_device_topology(adev, &topology))
|
||||
return -ENODEV;
|
||||
out->shader_engines = c->max_shader_engines;
|
||||
out->shader_arrays_per_se = c->max_sh_per_se;
|
||||
out->backends_per_se = c->max_backends_per_se;
|
||||
out->cus_per_array = c->max_cu_per_sh;
|
||||
out->wavefront_size = cu->wave_front_size;
|
||||
out->max_waves_per_simd = cu->max_waves_per_simd;
|
||||
out->scratch_slots_per_cu = topology.scratch_slots_per_cu;
|
||||
out->lds_bytes = topology.lds_bytes;
|
||||
out->present |= RT_DEVICE_SPEC_GEOMETRY;
|
||||
|
||||
ses = c->max_shader_engines < 4 ? c->max_shader_engines : 4;
|
||||
sas = c->max_sh_per_se < 4 ? c->max_sh_per_se : 4;
|
||||
out->active_cus = cu->number;
|
||||
for (unsigned int se = 0; se < ses; ++se)
|
||||
for (unsigned int sa = 0; sa < sas; ++sa) {
|
||||
out->cu_bitmap[se][sa] = cu->bitmap[0][se][sa];
|
||||
if (cu->bitmap[0][se][sa] && se * c->max_sh_per_se + sa < 32)
|
||||
out->active_sa_bitmap |= 1u << (se * c->max_sh_per_se + sa);
|
||||
}
|
||||
out->present |= RT_DEVICE_SPEC_CUS | RT_DEVICE_SPEC_SHADER_ARRAYS;
|
||||
|
||||
if (amdgpu_ip_version(adev, GC_HWIP, 0) >= IP_VERSION(12, 0, 0) &&
|
||||
amdgpu_ip_version(adev, GC_HWIP, 0) < IP_VERSION(13, 0, 0) && !adev->no_hw_access) {
|
||||
out->cc_sa_disable = RREG32_SOC15(GC, 0, regGRBM_CC_GC_SA_UNIT_DISABLE);
|
||||
out->user_sa_disable = RREG32_SOC15(GC, 0, regGRBM_GC_USER_SA_UNIT_DISABLE);
|
||||
out->present |= RT_DEVICE_SPEC_SA_DISABLE;
|
||||
}
|
||||
|
||||
out->active_rb_bitmap = (uint32_t)c->backend_enable_mask;
|
||||
out->active_rbs = c->num_rbs;
|
||||
out->present |= RT_DEVICE_SPEC_BACKENDS;
|
||||
return 0;
|
||||
}
|
||||
@@ -39,6 +39,7 @@
|
||||
#include <mlg_drm.h>
|
||||
#include <hsa/hsa.h>
|
||||
#include <hsa/hsa_ext_amd.h>
|
||||
#include <mac_hsa.h>
|
||||
#include "signal_kernels.h"
|
||||
#include "selector_call.h"
|
||||
|
||||
@@ -518,6 +519,27 @@ static kern_return_t query_info(IOUserClientMethodArguments *a)
|
||||
}
|
||||
case 12:
|
||||
return answer(a, {1, 2, 0x7f, 4242, kfdWindow, kWindowBytes, 0x10000, 0x7fffffffffffull});
|
||||
case MLG_QUERY_DEVICE_SPEC: { /* a structure, as the driver's QueryInfo handler answers it */
|
||||
mlg_device_spec spec{};
|
||||
spec.version = MLG_DEVICE_SPEC_VERSION;
|
||||
spec.present = MLG_DEVICE_SPEC_GEOMETRY | MLG_DEVICE_SPEC_CUS | MLG_DEVICE_SPEC_SHADER_ARRAYS |
|
||||
MLG_DEVICE_SPEC_SA_DISABLE | MLG_DEVICE_SPEC_BACKENDS;
|
||||
spec.shader_engines = 4; spec.shader_arrays_per_se = 2; spec.backends_per_se = 4;
|
||||
spec.cus_per_array = 8; spec.wavefront_size = 32; spec.max_waves_per_simd = 16;
|
||||
spec.scratch_slots_per_cu = 32; spec.lds_bytes = 65536; spec.active_cus = 64;
|
||||
for (unsigned se = 0; se < 4; ++se)
|
||||
for (unsigned sa = 0; sa < 2; ++sa) spec.cu_bitmap[se][sa] = 0xff00 | (se << 4) | sa;
|
||||
spec.active_sa_bitmap = 0xff; spec.cc_sa_disable = 0x12340000; spec.user_sa_disable = 0x56780000;
|
||||
spec.active_rb_bitmap = 0xffff; spec.active_rbs = 16;
|
||||
const size_t n = a->structureOutputMaximumSize < sizeof(spec) ? (size_t)a->structureOutputMaximumSize
|
||||
: sizeof(spec);
|
||||
if (n < 16) return kIOReturnBadArgument;
|
||||
spec.size = (uint32_t)n;
|
||||
a->structureOutput = OSData::withBytes(&spec, n);
|
||||
if (a->scalarOutputCount >= 1) { a->scalarOutput[0] = n; a->scalarOutputCount = 1; }
|
||||
else a->scalarOutputCount = 0;
|
||||
return kIOReturnSuccess;
|
||||
}
|
||||
case kTestTag: {
|
||||
uint8_t bytes[100];
|
||||
for (unsigned i = 0; i < sizeof(bytes); ++i) bytes[i] = (uint8_t)(0x30 + i);
|
||||
@@ -1039,6 +1061,19 @@ static void hsa_session()
|
||||
CHECK(hsa_agent_get_info(gpu, HSA_AGENT_INFO_QUEUES_MAX, &slots) == HSA_STATUS_SUCCESS);
|
||||
CHECK(slots == kQueueSlots);
|
||||
for (auto *q : queues) CHECK(hsa_queue_destroy(q) == HSA_STATUS_SUCCESS);
|
||||
// The device spec: the driver's structure, through OWNER_RESULT, in
|
||||
// mac_hsa.h's 32 words.
|
||||
mac_hsa_device_spec_t spec{};
|
||||
const hsa_status_t specStatus = mac_hsa_agent_get_device_spec(gpu, &spec, sizeof(spec));
|
||||
if (specStatus != HSA_STATUS_SUCCESS) {
|
||||
std::fprintf(stderr, "mac_hsa_agent_get_device_spec: %#x\n", specStatus);
|
||||
fail("the device spec was not answered");
|
||||
}
|
||||
CHECK(spec.words[0] == MLG_DEVICE_SPEC_VERSION && spec.words[1] == 4 && spec.words[2] == 2 &&
|
||||
spec.words[4] == 8 && spec.words[8] == 65536 && spec.words[9] == 64);
|
||||
CHECK(spec.words[10] == 0xff00 && spec.words[11] == 0xff01 && spec.words[17] == 0xff31);
|
||||
CHECK(spec.words[18] == 0xff && spec.words[19] == 0x12340000 && spec.words[20] == 0x56780000 &&
|
||||
spec.words[21] == 0xffff && spec.words[22] == 16 && spec.words[23] == 0 && spec.words[31] == 0);
|
||||
CHECK(hsa_shut_down() == HSA_STATUS_SUCCESS);
|
||||
CHECK(topologyAnswers >= 1 && queuesCreated >= 3);
|
||||
}
|
||||
@@ -1164,7 +1199,8 @@ int main(int argc, char **argv)
|
||||
close_waits();
|
||||
std::printf("PASS hsa transport: the HSA runtime's IOKit transport against the dext's session dispatch: "
|
||||
"cold bring-up with InitDevice, the 16-word topology through an owner call (%llu queue "
|
||||
"slots), three MULTI queues; owner calls with 16 scalars, and 14 with a structure\n",
|
||||
"slots), three MULTI queues, the device spec as a structure; owner calls with 16 scalars, "
|
||||
"and 14 with a structure\n",
|
||||
(unsigned long long)kQueueSlots);
|
||||
|
||||
// libmlg_drm from a cold GPU: the driver has no process for the client
|
||||
|
||||
@@ -20,6 +20,20 @@ void *kzalloc(size_t size, gfp_t flags) { (void)flags; return calloc(1, size); }
|
||||
/* Reached only for per-process XNACK with supported == true. */
|
||||
bool amdgpu_sriov_xnack_support(struct amdgpu_device *adev) { (void)adev; abort(); }
|
||||
void kfree(const void *p) { free((void *)p); }
|
||||
/* Not a virtual function here: never reached. */
|
||||
u32 amdgpu_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip, u32 xcc_id)
|
||||
{ (void)adev; (void)offset; (void)acc_flags; (void)hwip; (void)xcc_id; abort(); }
|
||||
/* The GC registers the device spec reads (read only): GC segment bases
|
||||
* 0x1000 and 0xa000 here; anything else is a register it must not read. */
|
||||
static unsigned reg_reads;
|
||||
uint32_t amdgpu_device_rreg(struct amdgpu_device *adev, uint32_t reg, uint32_t acc_flags)
|
||||
{
|
||||
(void)adev; (void)acc_flags;
|
||||
++reg_reads;
|
||||
if (reg == 0x1000 + 0x0fe9) return 0x00030000; /* GRBM_CC_GC_SA_UNIT_DISABLE */
|
||||
if (reg == 0xa000 + 0x5b92) return 0x00040000; /* GRBM_GC_USER_SA_UNIT_DISABLE */
|
||||
abort();
|
||||
}
|
||||
|
||||
static struct kfd_cache_properties caches[4];
|
||||
static void add_cache(unsigned i, uint32_t level, uint32_t kb, uint32_t type)
|
||||
@@ -112,6 +126,49 @@ int main(void)
|
||||
node1.xcc_mask = 0xc;
|
||||
assert(rt_device_topology(&adev, &t) == 0 && t.xcc_count == 4);
|
||||
|
||||
puts("device topology: KFD node/cache properties, XNACK mode and FRU name passed");
|
||||
/* The device spec: upstream's GC config and active CUs and RBs, the
|
||||
* KFD node's per-CU properties, GC 12's SA disable registers. */
|
||||
{
|
||||
static uint32_t gc_segments[2] = {0x1000, 0xa000};
|
||||
struct rt_device_spec spec;
|
||||
kfd.num_nodes = 1;
|
||||
node0.xcc_mask = 0x1;
|
||||
adev.ip_versions[GC_HWIP][0] = IP_VERSION(12, 0, 1);
|
||||
adev.reg_offset[GC_HWIP][0] = gc_segments;
|
||||
assert(rt_device_spec(&adev, &spec) == -ENODEV && reg_reads == 0); /* GC not resolved */
|
||||
adev.gfx.config.max_shader_engines = 4;
|
||||
adev.gfx.config.max_sh_per_se = 2;
|
||||
adev.gfx.config.max_backends_per_se = 4;
|
||||
adev.gfx.config.max_cu_per_sh = 8;
|
||||
adev.gfx.config.backend_enable_mask = 0xfff;
|
||||
adev.gfx.config.num_rbs = 12;
|
||||
adev.gfx.cu_info.wave_front_size = 32;
|
||||
adev.gfx.cu_info.max_waves_per_simd = 16;
|
||||
adev.gfx.cu_info.number = 56;
|
||||
for (unsigned se = 0; se < 4; ++se)
|
||||
for (unsigned sa = 0; sa < 2; ++sa)
|
||||
adev.gfx.cu_info.bitmap[0][se][sa] = se == 3 && sa == 1 ? 0 : 0xff;
|
||||
assert(rt_device_spec(&adev, &spec) == 0);
|
||||
assert(spec.present == (RT_DEVICE_SPEC_GEOMETRY | RT_DEVICE_SPEC_CUS |
|
||||
RT_DEVICE_SPEC_SHADER_ARRAYS | RT_DEVICE_SPEC_SA_DISABLE | RT_DEVICE_SPEC_BACKENDS));
|
||||
assert(spec.shader_engines == 4 && spec.shader_arrays_per_se == 2 &&
|
||||
spec.backends_per_se == 4 && spec.cus_per_array == 8 && spec.wavefront_size == 32 &&
|
||||
spec.max_waves_per_simd == 16 && spec.scratch_slots_per_cu == 32 &&
|
||||
spec.lds_bytes == 65536 && spec.active_cus == 56);
|
||||
assert(spec.cu_bitmap[0][0] == 0xff && spec.cu_bitmap[3][1] == 0 &&
|
||||
spec.active_sa_bitmap == 0x7f);
|
||||
assert(spec.cc_sa_disable == 0x00030000 && spec.user_sa_disable == 0x00040000 && reg_reads == 2);
|
||||
assert(spec.active_rb_bitmap == 0xfff && spec.active_rbs == 12);
|
||||
/* No register read on another GC, or with hardware access off. */
|
||||
adev.ip_versions[GC_HWIP][0] = IP_VERSION(11, 0, 0);
|
||||
assert(rt_device_spec(&adev, &spec) == 0 && !(spec.present & RT_DEVICE_SPEC_SA_DISABLE) &&
|
||||
!spec.cc_sa_disable && reg_reads == 2);
|
||||
adev.ip_versions[GC_HWIP][0] = IP_VERSION(12, 0, 1);
|
||||
adev.no_hw_access = true;
|
||||
assert(rt_device_spec(&adev, &spec) == 0 && !(spec.present & RT_DEVICE_SPEC_SA_DISABLE) &&
|
||||
reg_reads == 2);
|
||||
}
|
||||
|
||||
puts("device topology: KFD node/cache properties, XNACK mode, FRU name and device spec passed");
|
||||
return 0;
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <rt/compute.h>
|
||||
#include <rt/dispatch.h>
|
||||
#include <rt/gart.h>
|
||||
#include "../../dext/sources/session_state.h"
|
||||
#include "../../dext/sources/dext_compute.h"
|
||||
#include "../../dext/sources/dext_aql.h"
|
||||
#include "../../dext/sources/dext_kfd.h"
|
||||
@@ -155,6 +156,17 @@ int rt_device_topology(struct amdgpu_device *adev, struct rt_compute_topology *o
|
||||
{ assert(adev==fake_adev); if (topology_error) return topology_error; *out=topology; return 0; }
|
||||
int dext_aql_limits(struct rt_compute_ctx *ctx, struct dext_aql_limits *out)
|
||||
{ assert(ctx==&context); if (limits_error) return limits_error; *out=aql_limits; return 0; }
|
||||
static int spec_error;
|
||||
int rt_device_spec(struct amdgpu_device *adev, struct rt_device_spec *out)
|
||||
{
|
||||
assert(adev==fake_adev);
|
||||
if (spec_error) return spec_error;
|
||||
memset(out,0,sizeof(*out));
|
||||
out->present=RT_DEVICE_SPEC_GEOMETRY|RT_DEVICE_SPEC_CUS|RT_DEVICE_SPEC_BACKENDS;
|
||||
out->shader_engines=4; out->shader_arrays_per_se=2; out->cus_per_array=8;
|
||||
out->active_cus=64; out->cu_bitmap[3][1]=0xff; out->active_rbs=16;
|
||||
return 0;
|
||||
}
|
||||
static unsigned legacy_creates;
|
||||
int dext_aql_create(struct rt_compute_ctx *ctx, struct rt_compute_bo *ring,
|
||||
struct rt_compute_bo *meta, uint32_t packets,
|
||||
@@ -568,6 +580,20 @@ int main(int argc, char **argv)
|
||||
bounded_error=0;
|
||||
assert(dext_compute_aql_dispatch(&request,sizeof(request),out)==0);
|
||||
assert(dext_compute_stop()==0 && frees==1 && closes==1);
|
||||
} else if (!strcmp(argv[1],"device-spec")) {
|
||||
/* QueryInfo tag 8: the structure, cut to the caller's room above
|
||||
* its header, which states the bytes filled. */
|
||||
struct mlg_device_spec spec;
|
||||
memset(&spec,0xa5,sizeof(spec));
|
||||
assert(dext_compute_device_spec(&spec,sizeof(spec))==(int)sizeof(spec));
|
||||
assert(spec.version==MLG_DEVICE_SPEC_VERSION && spec.size==sizeof(spec) && !spec.reserved);
|
||||
assert(spec.present==(MLG_DEVICE_SPEC_GEOMETRY|MLG_DEVICE_SPEC_CUS|MLG_DEVICE_SPEC_BACKENDS));
|
||||
assert(spec.shader_engines==4 && spec.cus_per_array==8 && spec.active_cus==64 &&
|
||||
spec.cu_bitmap[3][1]==0xff && spec.active_rbs==16 && !spec.cc_sa_disable);
|
||||
assert(dext_compute_device_spec(&spec,32)==32 && spec.size==32);
|
||||
assert(dext_compute_device_spec(&spec,8)==-EINVAL_L);
|
||||
spec_error=-ENODEV;
|
||||
assert(dext_compute_device_spec(&spec,sizeof(spec))==-ENOTREADY_L);
|
||||
} else if (!strcmp(argv[1],"create-nospc")) {
|
||||
uint64_t ring=alloc_bo(2), meta=alloc_bo(2);
|
||||
create_error=-ENOSPC;
|
||||
|
||||
@@ -15,7 +15,7 @@ for scenario in open-failure dispatch-timeout dispatch bounded-timeout bounded-o
|
||||
bounded-nospc create-nospc query-topology geometry legacy-one-hqd kfd-two-queues \
|
||||
kfd-open-failure kfd-stop kfd-destroy-retained kfd-death-recovered kfd-death-kept \
|
||||
allocation-cleanup create-retained create-oom service-retained kick-poison \
|
||||
destroy-retained stop-retained stop-removed ordinary-errors close-retained; do
|
||||
destroy-retained stop-retained stop-removed ordinary-errors close-retained device-spec; do
|
||||
"$test_dir/test_dext_compute_production" "$scenario"
|
||||
done
|
||||
echo 'Production selector startup, ownership and quarantine checks passed'
|
||||
Reference in new issue
Block a user