Skip to content
This repository was archived by the owner on Dec 24, 2024. It is now read-only.

Commit c42ff44

Browse files
committed
rocr/kfd-driver: Add initial KFD driver interface
Adds the initial KFD driver interface and use it to open the KFD from amd_topology.cpp. This change is to show the direction of the Driver interface for initially supporting the KFD and to get feedback on the approach. For now we wrap relevant ROCt calls behind this generic driver interface so that we can generalize core ROCr components like MemoryRegion, Runtime, etc. Now that ROCt is incorporated into ROCr, we can more fully integrate ROCt into the Driver interface. Ideally, we get to a point where the generic Driver interface can support KFD, XDNA, and potential future drivers. Change-Id: I4573fd6af1f8398233ee9d3814d9f3139dd0279c
1 parent 86f40ae commit c42ff44

File tree

6 files changed

+172
-2
lines changed

6 files changed

+172
-2
lines changed

runtime/hsa-runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ set_property(TARGET ${CORE_RUNTIME_TARGET} PROPERTY LINK_FLAGS ${HSA_SHARED_LINK
150150

151151
## Source files.
152152
set ( SRCS core/driver/driver.cpp
153+
core/driver/kfd/amd_kfd_driver.cpp
153154
core/driver/xdna/amd_xdna_driver.cpp
154155
core/util/lnx/os_linux.cpp
155156
core/util/small_heap.cpp
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// The University of Illinois/NCSA
4+
// Open Source License (NCSA)
5+
//
6+
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
7+
//
8+
// Developed by:
9+
//
10+
// AMD Research and AMD HSA Software Development
11+
//
12+
// Advanced Micro Devices, Inc.
13+
//
14+
// www.amd.com
15+
//
16+
// Permission is hereby granted, free of charge, to any person obtaining a copy
17+
// of this software and associated documentation files (the "Software"), to
18+
// deal with the Software without restriction, including without limitation
19+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
20+
// and/or sell copies of the Software, and to permit persons to whom the
21+
// Software is furnished to do so, subject to the following conditions:
22+
//
23+
// - Redistributions of source code must retain the above copyright notice,
24+
// this list of conditions and the following disclaimers.
25+
// - Redistributions in binary form must reproduce the above copyright
26+
// notice, this list of conditions and the following disclaimers in
27+
// the documentation and/or other materials provided with the distribution.
28+
// - Neither the names of Advanced Micro Devices, Inc,
29+
// nor the names of its contributors may be used to endorse or promote
30+
// products derived from this Software without specific prior written
31+
// permission.
32+
//
33+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
36+
// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
37+
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
39+
// DEALINGS WITH THE SOFTWARE.
40+
//
41+
////////////////////////////////////////////////////////////////////////////////
42+
43+
#include "core/inc/amd_kfd_driver.h"
44+
45+
#include <sys/ioctl.h>
46+
47+
#include <memory>
48+
#include <string>
49+
50+
#include "hsakmt/hsakmt.h"
51+
52+
#include "core/inc/runtime.h"
53+
54+
namespace rocr {
55+
namespace AMD {
56+
57+
KfdDriver::KfdDriver(std::string devnode_name)
58+
: core::Driver(core::DriverType::KFD, devnode_name) {}
59+
60+
hsa_status_t KfdDriver::DiscoverDriver() {
61+
if (hsaKmtOpenKFD() == HSAKMT_STATUS_SUCCESS) {
62+
std::unique_ptr<Driver> kfd_drv(new KfdDriver("/dev/kfd"));
63+
core::Runtime::runtime_singleton_->RegisterDriver(kfd_drv);
64+
return HSA_STATUS_SUCCESS;
65+
}
66+
return HSA_STATUS_ERROR;
67+
}
68+
69+
hsa_status_t KfdDriver::QueryKernelModeDriver(core::DriverQuery query) {
70+
return HSA_STATUS_SUCCESS;
71+
}
72+
73+
hsa_status_t KfdDriver::GetMemoryProperties(uint32_t node_id,
74+
core::MemProperties &mprops) const {
75+
return HSA_STATUS_SUCCESS;
76+
}
77+
78+
hsa_status_t KfdDriver::AllocateMemory(void **mem, size_t size,
79+
uint32_t node_id, core::MemFlags flags) {
80+
return HSA_STATUS_SUCCESS;
81+
}
82+
83+
hsa_status_t KfdDriver::FreeMemory(void *mem, uint32_t node_id) {
84+
return HSA_STATUS_SUCCESS;
85+
}
86+
87+
hsa_status_t KfdDriver::CreateQueue(core::Queue &queue) {
88+
return HSA_STATUS_SUCCESS;
89+
}
90+
91+
hsa_status_t KfdDriver::DestroyQueue(core::Queue &queue) const {
92+
return HSA_STATUS_SUCCESS;
93+
}
94+
95+
} // namespace AMD
96+
} // namespace rocr
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// The University of Illinois/NCSA
4+
// Open Source License (NCSA)
5+
//
6+
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved.
7+
//
8+
// Developed by:
9+
//
10+
// AMD Research and AMD HSA Software Development
11+
//
12+
// Advanced Micro Devices, Inc.
13+
//
14+
// www.amd.com
15+
//
16+
// Permission is hereby granted, free of charge, to any person obtaining a copy
17+
// of this software and associated documentation files (the "Software"), to
18+
// deal with the Software without restriction, including without limitation
19+
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
20+
// and/or sell copies of the Software, and to permit persons to whom the
21+
// Software is furnished to do so, subject to the following conditions:
22+
//
23+
// - Redistributions of source code must retain the above copyright notice,
24+
// this list of conditions and the following disclaimers.
25+
// - Redistributions in binary form must reproduce the above copyright
26+
// notice, this list of conditions and the following disclaimers in
27+
// the documentation and/or other materials provided with the distribution.
28+
// - Neither the names of Advanced Micro Devices, Inc,
29+
// nor the names of its contributors may be used to endorse or promote
30+
// products derived from this Software without specific prior written
31+
// permission.
32+
//
33+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
36+
// THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
37+
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
39+
// DEALINGS WITH THE SOFTWARE.
40+
//
41+
////////////////////////////////////////////////////////////////////////////////
42+
43+
#ifndef HSA_RUNTIME_CORE_INC_AMD_KFD_DRIVER_H_
44+
#define HSA_RUNTIME_CORE_INC_AMD_KFD_DRIVER_H_
45+
46+
#include "core/inc/driver.h"
47+
48+
#include <string>
49+
50+
namespace rocr {
51+
namespace AMD {
52+
53+
class KfdDriver : public core::Driver {
54+
public:
55+
KfdDriver(std::string devnode_name);
56+
57+
static hsa_status_t DiscoverDriver();
58+
59+
hsa_status_t QueryKernelModeDriver(core::DriverQuery query) override;
60+
hsa_status_t GetMemoryProperties(uint32_t node_id,
61+
core::MemProperties &mprops) const override;
62+
hsa_status_t AllocateMemory(void **mem, size_t size, uint32_t node_id,
63+
core::MemFlags flags) override;
64+
hsa_status_t FreeMemory(void *mem, uint32_t node_id) override;
65+
hsa_status_t CreateQueue(core::Queue &queue) override;
66+
hsa_status_t DestroyQueue(core::Queue &queue) const override;
67+
};
68+
69+
} // namespace AMD
70+
} // namespace rocr
71+
72+
#endif // header guard

runtime/hsa-runtime/core/inc/driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct DriverVersionInfo {
6868

6969
enum class DriverQuery { GET_DRIVER_VERSION };
7070

71-
enum class DriverType { XDNA = 0, NUM_DRIVER_TYPES };
71+
enum class DriverType { XDNA = 0, KFD, NUM_DRIVER_TYPES };
7272

7373
/// @brief Kernel driver interface.
7474
///

runtime/hsa-runtime/core/inc/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "core/inc/hsa_ext_amd_impl.h"
6464

6565
#include "core/inc/agent.h"
66+
#include "core/inc/amd_kfd_driver.h"
6667
#include "core/inc/amd_xdna_driver.h"
6768
#include "core/inc/exceptions.h"
6869
#include "core/inc/interrupt_signal.h"

runtime/hsa-runtime/core/runtime/amd_topology.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static const uint kKfdVersionMinor = 99;
7474

7575
void DiscoverDrivers(bool &gpu_found, bool &aie_found) {
7676
// Open connection to GPU and AIE kernel drivers.
77-
gpu_found = (hsaKmtOpenKFD() == HSAKMT_STATUS_SUCCESS);
77+
gpu_found = (KfdDriver::DiscoverDriver() == HSA_STATUS_SUCCESS);
7878
aie_found = (XdnaDriver::DiscoverDriver() == HSA_STATUS_SUCCESS);
7979
}
8080

0 commit comments

Comments
 (0)