rocr/xdna-driver: Initial support for amdxdna driver
Change-Id: I319b55d89dc644e7151228cb6c19d1a633171295
[ROCm/ROCR-Runtime commit: 86f40ae489]
このコミットが含まれているのは:
@@ -0,0 +1,75 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// The University of Illinois/NCSA
|
||||
// Open Source License (NCSA)
|
||||
//
|
||||
// Copyright (c) 2024, 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
|
||||
// notice, this list of conditions and the following disclaimers in
|
||||
// the documentation and/or other materials provided with the distribution.
|
||||
// - Neither the names of Advanced Micro Devices, Inc,
|
||||
// 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
|
||||
// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS WITH THE SOFTWARE.
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef HSA_RUNTIME_CORE_INC_AMD_XDNA_DRIVER_H_
|
||||
#define HSA_RUNTIME_CORE_INC_AMD_XDNA_DRIVER_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "core/inc/driver.h"
|
||||
|
||||
namespace rocr {
|
||||
namespace AMD {
|
||||
|
||||
class XdnaDriver : public core::Driver {
|
||||
public:
|
||||
XdnaDriver() = delete;
|
||||
XdnaDriver(std::string devnode_name);
|
||||
|
||||
static hsa_status_t DiscoverDriver();
|
||||
hsa_status_t QueryKernelModeDriver(core::DriverQuery query) override;
|
||||
|
||||
hsa_status_t GetMemoryProperties(uint32_t node_id,
|
||||
core::MemProperties &mprops) const override;
|
||||
hsa_status_t AllocateMemory(void **mem, size_t size, uint32_t node_id,
|
||||
core::MemFlags flags) override;
|
||||
hsa_status_t FreeMemory(void *mem, uint32_t node_id) override;
|
||||
hsa_status_t CreateQueue(core::Queue &queue) override;
|
||||
hsa_status_t DestroyQueue(core::Queue &queue) const override;
|
||||
|
||||
private:
|
||||
hsa_status_t QueryDriverVersion();
|
||||
};
|
||||
|
||||
} // namespace AMD
|
||||
} // namespace rocr
|
||||
|
||||
#endif // header guard
|
||||
@@ -43,6 +43,7 @@
|
||||
#ifndef HSA_RUNTME_CORE_INC_DRIVER_H_
|
||||
#define HSA_RUNTME_CORE_INC_DRIVER_H_
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#include "core/inc/agent.h"
|
||||
@@ -60,6 +61,15 @@ struct MemProperties {
|
||||
uint64_t virtual_base_addr_;
|
||||
};
|
||||
|
||||
struct DriverVersionInfo {
|
||||
uint32_t major;
|
||||
uint32_t minor;
|
||||
};
|
||||
|
||||
enum class DriverQuery { GET_DRIVER_VERSION };
|
||||
|
||||
enum class DriverType { XDNA = 0, NUM_DRIVER_TYPES };
|
||||
|
||||
/// @brief Kernel driver interface.
|
||||
///
|
||||
/// @details A class used to provide an interface between the core runtime
|
||||
@@ -68,15 +78,22 @@ struct MemProperties {
|
||||
class Driver {
|
||||
public:
|
||||
Driver() = delete;
|
||||
Driver(const std::string devnode_name, Agent::DeviceType agent_device_type);
|
||||
virtual ~Driver() {}
|
||||
Driver(DriverType kernel_driver_type, std::string devnode_name);
|
||||
virtual ~Driver() = default;
|
||||
|
||||
/// @brief Query the kernel-model driver.
|
||||
/// @retval HSA_STATUS_SUCCESS if the kernel-model driver query was
|
||||
/// successful.
|
||||
virtual hsa_status_t QueryKernelModeDriver(DriverQuery query) = 0;
|
||||
/// @brief Open a connection to the driver using name_.
|
||||
/// @retval HSA_STATUS_SUCCESS if the driver was opened successfully.
|
||||
hsa_status_t Open();
|
||||
/// @brief Close a connection to the open driver using fd_.
|
||||
/// @retval HSA_STATUS_SUCCESS if the driver was opened successfully.
|
||||
hsa_status_t Close();
|
||||
/// @brief Get driver version information.
|
||||
/// @retval DriverVersionInfo containing the driver's version information.
|
||||
DriverVersionInfo Version() const { return version_; }
|
||||
|
||||
virtual hsa_status_t GetMemoryProperties(uint32_t node_id, MemProperties &mprops) const = 0;
|
||||
|
||||
@@ -95,10 +112,13 @@ class Driver {
|
||||
|
||||
virtual hsa_status_t DestroyQueue(Queue &queue) const = 0;
|
||||
|
||||
/// Specify the agent device type this driver is for.
|
||||
const Agent::DeviceType agent_device_type_;
|
||||
/// Unique identifier for supported kernel-mode drivers.
|
||||
const DriverType kernel_driver_type_;
|
||||
|
||||
protected:
|
||||
DriverVersionInfo version_{std::numeric_limits<uint32_t>::max(),
|
||||
std::numeric_limits<uint32_t>::max()};
|
||||
|
||||
protected:
|
||||
const std::string devnode_name_;
|
||||
int fd_ = -1;
|
||||
};
|
||||
|
||||
@@ -63,10 +63,11 @@
|
||||
#include "core/inc/hsa_ext_amd_impl.h"
|
||||
|
||||
#include "core/inc/agent.h"
|
||||
#include "core/inc/amd_xdna_driver.h"
|
||||
#include "core/inc/exceptions.h"
|
||||
#include "core/inc/interrupt_signal.h"
|
||||
#include "core/inc/memory_region.h"
|
||||
#include "core/inc/signal.h"
|
||||
#include "core/inc/interrupt_signal.h"
|
||||
#include "core/inc/svm_profiler.h"
|
||||
#include "core/util/flag.h"
|
||||
#include "core/util/locks.h"
|
||||
@@ -155,9 +156,16 @@ class Runtime {
|
||||
/// @param [in] agent Pointer to the agent object.
|
||||
void RegisterAgent(Agent* agent, bool Enabled);
|
||||
|
||||
/// @brief Insert agent into the driver list.
|
||||
/// @param [in] driver Unique pointer to the driver object.
|
||||
void RegisterDriver(std::unique_ptr<Driver> &driver);
|
||||
|
||||
/// @brief Delete all agent objects from ::agents_.
|
||||
void DestroyAgents();
|
||||
|
||||
/// @brief Close and delete all agent driver objects from ::agent_drivers_.
|
||||
void DestroyDrivers();
|
||||
|
||||
/// @brief Set the number of links connecting the agents in the platform.
|
||||
void SetLinkCount(size_t num_link);
|
||||
|
||||
@@ -469,6 +477,22 @@ class Runtime {
|
||||
bool XnackEnabled() const { return xnack_enabled_; }
|
||||
void XnackEnabled(bool enable) { xnack_enabled_ = enable; }
|
||||
|
||||
Driver &AgentDriver(DriverType drv_type) {
|
||||
auto is_drv_type = [&](const std::unique_ptr<Driver> &d) {
|
||||
return d->kernel_driver_type_ == drv_type;
|
||||
};
|
||||
|
||||
auto driver(std::find_if(agent_drivers_.begin(), agent_drivers_.end(),
|
||||
is_drv_type));
|
||||
|
||||
if (driver == agent_drivers_.end()) {
|
||||
throw AMD::hsa_exception(HSA_STATUS_ERROR_INVALID_ARGUMENT,
|
||||
"Invalid agent device type, no driver found.");
|
||||
}
|
||||
|
||||
return **driver;
|
||||
}
|
||||
|
||||
protected:
|
||||
static void AsyncEventsLoop(void*);
|
||||
static void AsyncIPCSockServerConnLoop(void*);
|
||||
@@ -617,6 +641,10 @@ class Runtime {
|
||||
// registered & mapped arrays.
|
||||
KernelSharedMutex memory_lock_;
|
||||
|
||||
// Array containing driver interfaces for compatible agent kernel-mode
|
||||
// drivers. Currently supports AIE agents.
|
||||
std::vector<std::unique_ptr<Driver>> agent_drivers_;
|
||||
|
||||
// Array containing tools library handles.
|
||||
std::vector<os::LibHandle> tool_libs_;
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする