rocr: Remove KMT usage from CPU agent
Use the core Driver object in the CPU agent to make it OS/driver
agnostic.
Implement the GetMemoryProperties() and GetCacheProperties methods
for the KFD driver.
[ROCm/ROCR-Runtime commit: a9f6bc8d0e]
Этот коммит содержится в:
коммит произвёл
Yat Sin, David
родитель
69c014290d
Коммит
727159b4db
+19
-3
@@ -178,9 +178,25 @@ hsa_status_t KfdDriver::GetAgentProperties(core::Agent &agent) const {
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t
|
||||
KfdDriver::GetMemoryProperties(uint32_t node_id,
|
||||
core::MemoryRegion &mem_region) const {
|
||||
hsa_status_t KfdDriver::GetMemoryProperties(uint32_t node_id,
|
||||
std::vector<HsaMemoryProperties>& mem_props) const {
|
||||
if (!mem_props.data()) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if (hsaKmtGetNodeMemoryProperties(node_id, mem_props.size(), mem_props.data()) !=
|
||||
HSAKMT_STATUS_SUCCESS)
|
||||
return HSA_STATUS_ERROR;
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t KfdDriver::GetCacheProperties(uint32_t node_id, uint32_t processor_id,
|
||||
std::vector<HsaCacheProperties>& cache_props) const {
|
||||
if (!cache_props.data()) return HSA_STATUS_ERROR_INVALID_ARGUMENT;
|
||||
|
||||
if (hsaKmtGetNodeCacheProperties(node_id, processor_id, cache_props.size(), cache_props.data()) !=
|
||||
HSAKMT_STATUS_SUCCESS)
|
||||
return HSA_STATUS_ERROR;
|
||||
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
+8
-3
@@ -175,12 +175,17 @@ hsa_status_t XdnaDriver::GetAgentProperties(core::Agent &agent) const {
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t
|
||||
XdnaDriver::GetMemoryProperties(uint32_t node_id,
|
||||
core::MemoryRegion &mem_region) const {
|
||||
hsa_status_t XdnaDriver::GetMemoryProperties(uint32_t node_id,
|
||||
std::vector<HsaMemoryProperties>& mem_props) const {
|
||||
return HSA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
hsa_status_t XdnaDriver::GetCacheProperties(uint32_t node_id, uint32_t processor_id,
|
||||
std::vector<HsaCacheProperties>& cache_props) const {
|
||||
// AIE currently has no caches.
|
||||
return HSA_STATUS_ERROR_INVALID_CACHE;
|
||||
}
|
||||
|
||||
hsa_status_t
|
||||
XdnaDriver::AllocateMemory(const core::MemoryRegion &mem_region,
|
||||
core::MemoryRegion::AllocateFlags alloc_flags,
|
||||
|
||||
@@ -2,24 +2,24 @@
|
||||
//
|
||||
// The University of Illinois/NCSA
|
||||
// Open Source License (NCSA)
|
||||
//
|
||||
// Copyright (c) 2014-2020, Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
//
|
||||
// Copyright (c) 2014-2025, Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Developed by:
|
||||
//
|
||||
//
|
||||
// AMD Research and AMD HSA Software Development
|
||||
//
|
||||
//
|
||||
// Advanced Micro Devices, Inc.
|
||||
//
|
||||
//
|
||||
// www.amd.com
|
||||
//
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal with the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
//
|
||||
// - Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimers.
|
||||
// - Redistributions in binary form must reproduce the above copyright
|
||||
@@ -29,7 +29,7 @@
|
||||
// nor the names of its contributors may be used to endorse or promote
|
||||
// products derived from this Software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
@@ -47,8 +47,6 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "hsakmt/hsakmt.h"
|
||||
|
||||
#include "core/inc/runtime.h"
|
||||
#include "core/inc/agent.h"
|
||||
#include "core/inc/queue.h"
|
||||
|
||||
@@ -61,10 +61,21 @@ class Queue;
|
||||
|
||||
namespace AMD {
|
||||
|
||||
/// @brief AMD Kernel Fusion Driver (KFD) for AMD GPU and CPU agents.
|
||||
///
|
||||
/// @details The user-mode driver into the Linux KFD for AMD GPU and CPU HSA
|
||||
/// agents. Provides APIs for the ROCr core to discover the topology produced
|
||||
/// by the KFD, allocate memory out of the KFD, manage DMA bufs, allocate queues,
|
||||
/// and more.
|
||||
class KfdDriver final : public core::Driver {
|
||||
public:
|
||||
KfdDriver(std::string devnode_name);
|
||||
|
||||
/// @brief Determine of the KFD is present on the system and attemp to open it if found.
|
||||
///
|
||||
/// @param[out] Driver object for the KFD.
|
||||
/// @return HSA_STATUS_SUCCESS if driver found and opened.
|
||||
/// @return HSA_STATUS_ERROR if unable to find or open the KFD.
|
||||
static hsa_status_t DiscoverDriver(std::unique_ptr<core::Driver>& driver);
|
||||
|
||||
hsa_status_t Init() override;
|
||||
@@ -77,9 +88,10 @@ public:
|
||||
hsa_status_t GetEdgeProperties(std::vector<HsaIoLinkProperties>& io_link_props,
|
||||
uint32_t node_id) const override;
|
||||
hsa_status_t GetAgentProperties(core::Agent &agent) const override;
|
||||
hsa_status_t
|
||||
GetMemoryProperties(uint32_t node_id,
|
||||
core::MemoryRegion &mem_region) const override;
|
||||
hsa_status_t GetMemoryProperties(uint32_t node_id,
|
||||
std::vector<HsaMemoryProperties>& mem_props) const override;
|
||||
hsa_status_t GetCacheProperties(uint32_t node_id, uint32_t processor_id,
|
||||
std::vector<HsaCacheProperties>& cache_props) const override;
|
||||
hsa_status_t AllocateMemory(const core::MemoryRegion &mem_region,
|
||||
core::MemoryRegion::AllocateFlags alloc_flags,
|
||||
void **mem, size_t size,
|
||||
|
||||
@@ -153,9 +153,10 @@ public:
|
||||
hsa_status_t GetEdgeProperties(std::vector<HsaIoLinkProperties>& io_link_props,
|
||||
uint32_t node_id) const override;
|
||||
hsa_status_t GetAgentProperties(core::Agent &agent) const override;
|
||||
hsa_status_t
|
||||
GetMemoryProperties(uint32_t node_id,
|
||||
core::MemoryRegion &mem_region) const override;
|
||||
hsa_status_t GetMemoryProperties(uint32_t node_id,
|
||||
std::vector<HsaMemoryProperties>& mem_props) const override;
|
||||
hsa_status_t GetCacheProperties(uint32_t node_id, uint32_t processor_id,
|
||||
std::vector<HsaCacheProperties>& cache_props) const override;
|
||||
hsa_status_t AllocateMemory(const core::MemoryRegion &mem_region,
|
||||
core::MemoryRegion::AllocateFlags alloc_flags,
|
||||
void **mem, size_t size,
|
||||
|
||||
@@ -108,8 +108,7 @@ public:
|
||||
|
||||
/// @brief Get the edge (IO link) properties of a specific node (that is
|
||||
/// managed by this driver) in the topology graph.
|
||||
/// @param[out] io_link_props IO link properties of the node specified by \p
|
||||
/// node_id.
|
||||
/// @param[out] io_link_props IO link properties of the node specified by @p node_id.
|
||||
/// @param[in] node_id ID of the node whose link properties are being queried.
|
||||
virtual hsa_status_t GetEdgeProperties(std::vector<HsaIoLinkProperties>& io_link_props,
|
||||
uint32_t node_id) const = 0;
|
||||
@@ -118,22 +117,26 @@ public:
|
||||
/// object.
|
||||
/// @param agent Agent whose properties we're getting.
|
||||
/// @retval HSA_STATUS_SUCCESS if the driver successfully returns the agent's
|
||||
/// properties.
|
||||
/// properties.
|
||||
virtual hsa_status_t GetAgentProperties(Agent &agent) const = 0;
|
||||
|
||||
/// @brief Get the memory properties of a specific node.
|
||||
/// @param node_id Node ID of the agent
|
||||
/// @param[in, out] mem_region MemoryRegion object whose properties will be
|
||||
/// retrieved.
|
||||
/// @param[in] node_id Node ID of the agent.
|
||||
/// @param[out] mem_props Memory properties of the node specified by @p node_id.
|
||||
/// @retval HSA_STATUS_SUCCESS if the driver sucessfully returns the node's
|
||||
/// memory properties.
|
||||
/// memory properties.
|
||||
virtual hsa_status_t GetMemoryProperties(uint32_t node_id,
|
||||
MemoryRegion &mem_region) const = 0;
|
||||
std::vector<HsaMemoryProperties>& mem_props) const = 0;
|
||||
|
||||
/// @brief Get the cache properties of a specific node.
|
||||
/// @param[in] node_ide Node ID of the agent.
|
||||
/// @param[out] cache_props Cache properties of the node specified by @p node_id.
|
||||
/// @retval HSA_STATUS_SUCCESS if the driver successfully returns the node's cache properties.
|
||||
virtual hsa_status_t GetCacheProperties(uint32_t node_id, uint32_t processor_id,
|
||||
std::vector<HsaCacheProperties>& cache_props) const = 0;
|
||||
|
||||
/// @brief Allocate agent-accessible memory (system or agent-local memory).
|
||||
///
|
||||
/// @param[out] mem pointer to newly allocated memory.
|
||||
///
|
||||
/// @retval HSA_STATUS_SUCCESS if memory was successfully allocated or
|
||||
/// hsa_status_t error code if the memory allocation failed.
|
||||
virtual hsa_status_t AllocateMemory(const MemoryRegion &mem_region,
|
||||
@@ -170,7 +173,7 @@ public:
|
||||
/// @param[in] mem virtual address associated with the handle
|
||||
/// @param[in] offset memory offset in bytes
|
||||
/// @param[in] size memory size in bytes
|
||||
/// @param[perms] perms new permissions
|
||||
/// @param[out] perms new permissions
|
||||
virtual hsa_status_t Map(core::ShareableHandle handle, void *mem,
|
||||
size_t offset, size_t size,
|
||||
hsa_access_permission_t perms) = 0;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// The University of Illinois/NCSA
|
||||
// Open Source License (NCSA)
|
||||
//
|
||||
// Copyright (c) 2014-2020, Advanced Micro Devices, Inc. All rights reserved.
|
||||
// Copyright (c) 2014-2025, Advanced Micro Devices, Inc. All rights reserved.
|
||||
//
|
||||
// Developed by:
|
||||
//
|
||||
@@ -73,8 +73,7 @@ void CpuAgent::InitRegionList() {
|
||||
const bool is_apu_node = (properties_.NumFComputeCores > 0);
|
||||
|
||||
std::vector<HsaMemoryProperties> mem_props(properties_.NumMemoryBanks);
|
||||
if (HSAKMT_STATUS_SUCCESS ==
|
||||
hsaKmtGetNodeMemoryProperties(node_id(), properties_.NumMemoryBanks, &mem_props[0])) {
|
||||
if (HSA_STATUS_SUCCESS == driver().GetMemoryProperties(node_id(), mem_props)) {
|
||||
std::vector<HsaMemoryProperties>::iterator system_prop =
|
||||
std::find_if(mem_props.begin(), mem_props.end(), [](HsaMemoryProperties prop) -> bool {
|
||||
return (prop.SizeInBytes > 0 && prop.HeapType == HSA_HEAPTYPE_SYSTEM);
|
||||
@@ -107,9 +106,8 @@ void CpuAgent::InitRegionList() {
|
||||
void CpuAgent::InitCacheList() {
|
||||
// Get CPU cache information.
|
||||
cache_props_.resize(properties_.NumCaches);
|
||||
if (HSAKMT_STATUS_SUCCESS !=
|
||||
hsaKmtGetNodeCacheProperties(node_id(), properties_.CComputeIdLo,
|
||||
properties_.NumCaches, &cache_props_[0])) {
|
||||
if (HSA_STATUS_SUCCESS !=
|
||||
driver().GetCacheProperties(node_id(), properties_.CComputeIdLo, cache_props_)) {
|
||||
cache_props_.clear();
|
||||
} else {
|
||||
// Only store CPU D-cache.
|
||||
|
||||
Ссылка в новой задаче
Block a user