Move rocm_smi related function to rocm_smi folder. Move amd_smi to
top level include/ and src/ folder. Remove obsolte oam folder.
Change the CMakeLists.txt to update folder locations.

Change-Id: I52e6be739e49f3b0545865f25364787f5985e9c3
Этот коммит содержится в:
Bill(Shuzhou) Liu
2022-09-20 14:57:30 -04:00
родитель 1ec3a2182e
Коммит 0c91ef919d
98 изменённых файлов: 177 добавлений и 1715 удалений
+48
Просмотреть файл
@@ -0,0 +1,48 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_AMD_SMI_COMMON_H_
#define AMD_SMI_INCLUDE_AMD_SMI_COMMON_H_
#endif // AMD_SMI_INCLUDE_AMD_SMI_COMMON_H_
+65
Просмотреть файл
@@ -0,0 +1,65 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_AMD_SMI_DEVICE_H_
#define AMD_SMI_INCLUDE_AMD_SMI_DEVICE_H_
#include "amd_smi/amd_smi.h"
namespace amd {
namespace smi {
class AMDSmiDevice {
public:
explicit AMDSmiDevice(device_type_t device) : device_type_(device) {}
virtual ~AMDSmiDevice() {}
device_type_t get_device_type() const { return device_type_;}
private:
device_type_t device_type_;
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_AMD_SMI_DEVICE_H_
+82
Просмотреть файл
@@ -0,0 +1,82 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_IMPL_AMD_SMI_DRM_H_
#define AMD_SMI_INCLUDE_IMPL_AMD_SMI_DRM_H_
#include <unistd.h>
#include <vector>
#include <memory>
#include <mutex> // NOLINT
#include "amd_smi/amd_smi.h"
#include "amd_smi/impl/amd_smi_lib_loader.h"
namespace amd {
namespace smi {
class AMDSmiDrm {
public:
amdsmi_status_t init();
amdsmi_status_t cleanup();
int get_drm_fd_by_index(uint32_t gpu_index) const;
amdsmi_status_t amdgpu_query_info(int fd, unsigned info_id,
unsigned size, void *value);
amdsmi_status_t amdgpu_query_fw(int fd, unsigned info_id, unsigned fw_type,
unsigned size, void *value);
amdsmi_status_t amdgpu_query_hw_ip(int fd, unsigned info_id,
unsigned hw_ip_type, unsigned size, void *value);
amdsmi_status_t amdgpu_query_vbios(int fd, void *info);
private:
using DrmCmdWriteFunc = int (*)(int, unsigned long, void *, unsigned long);
std::vector<int> drm_fds_; // drm file descriptor by gpu_index
AMDSmiLibraryLoader lib_loader_; // lazy load libdrm
DrmCmdWriteFunc drm_cmd_write_; // drmCommandWrite
std::mutex drm_mutex_;
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_IMPL_AMD_SMI_DRM_H_
+76
Просмотреть файл
@@ -0,0 +1,76 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_IMPL_AMD_SMI_GPU_DEVICE_H_
#define AMD_SMI_INCLUDE_IMPL_AMD_SMI_GPU_DEVICE_H_
#include "amd_smi/amd_smi.h"
#include "amd_smi/impl/amd_smi_device.h"
#include "amd_smi/impl/amd_smi_drm.h"
namespace amd {
namespace smi {
class AMDSmiGPUDevice: public AMDSmiDevice {
public:
explicit AMDSmiGPUDevice(uint32_t gpu_id, AMDSmiDrm& drm):
AMDSmiDevice(AMD_GPU), gpu_id_(gpu_id), drm_(drm) {}
uint32_t get_gpu_id() const;
amdsmi_status_t amdgpu_query_info(unsigned info_id,
unsigned size, void *value) const;
amdsmi_status_t amdgpu_query_hw_ip(unsigned info_id, unsigned hw_ip_type,
unsigned size, void *value) const;
amdsmi_status_t amdgpu_query_fw(unsigned info_id, unsigned fw_type,
unsigned size, void *value) const;
amdsmi_status_t amdgpu_query_vbios(void *info) const;
private:
uint32_t gpu_id_;
AMDSmiDrm& drm_;
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_IMPL_AMD_SMI_GPU_DEVICE_H_
+82
Просмотреть файл
@@ -0,0 +1,82 @@
/*
Copyright (c) 2020 - present Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in 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:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
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
AUTHORS 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 IN
THE SOFTWARE.
*/
#ifndef AMD_SMI_INCLUDE_IMPL_AMD_SMI_LIB_LOADER_H_
#define AMD_SMI_INCLUDE_IMPL_AMD_SMI_LIB_LOADER_H_
#include <dlfcn.h>
#include <string.h>
#include <map>
#include <iostream>
#include <mutex> // NOLINT(build/c++11)
#include "amd_smi/amd_smi.h"
namespace amd {
namespace smi {
class AMDSmiLibraryLoader {
public:
AMDSmiLibraryLoader();
amdsmi_status_t load(const char* filename);
template<typename T> amdsmi_status_t load_symbol(T* func_handler,
const char* func_name);
amdsmi_status_t unload();
~AMDSmiLibraryLoader();
private:
void* libHandler_;
std::mutex library_mutex_;
};
template<typename T> amdsmi_status_t AMDSmiLibraryLoader::load_symbol(
T* func_handler,
const char* func_name) {
if (!libHandler_) {
return AMDSMI_STATUS_FAIL_LOAD_MODULE;
}
if (!func_handler || !func_name) {
return AMDSMI_STATUS_FAIL_LOAD_SYMBOL;
}
std::lock_guard<std::mutex> guard(library_mutex_);
*reinterpret_cast<void**>(func_handler) =
dlsym(libHandler_, func_name);
if (*func_handler == nullptr) {
char* error = dlerror();
std::cerr << "AMDSmiLibraryLoader: Fail to load the symbol "
<< func_name << ": " << error << std::endl;
return AMDSMI_STATUS_FAIL_LOAD_SYMBOL;
}
return AMDSMI_STATUS_SUCCESS;
}
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_IMPL_AMD_SMI_LIB_LOADER_H_
+71
Просмотреть файл
@@ -0,0 +1,71 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_AMD_SMI_SOCKET_H_
#define AMD_SMI_INCLUDE_AMD_SMI_SOCKET_H_
#include <string>
#include <algorithm>
#include <vector>
#include "amd_smi/amd_smi.h"
#include "amd_smi/impl/amd_smi_device.h"
namespace amd {
namespace smi {
class AMDSmiSocket {
public:
explicit AMDSmiSocket(const std::string& id) : socket_identifier_(id) {}
~AMDSmiSocket();
const std::string& get_socket_id() const { return socket_identifier_;}
void add_device(AMDSmiDevice* device) { devices_.push_back(device); }
std::vector<AMDSmiDevice*>& get_devices() { return devices_;}
private:
std::string socket_identifier_;
std::vector<AMDSmiDevice*> devices_;
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_AMD_SMI_SOCKET_H_
+91
Просмотреть файл
@@ -0,0 +1,91 @@
/*
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All rights reserved.
*
* Developed by:
*
* AMD Research and AMD ROC 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 <Name of Development Group, Name of Institution>,
* 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 AMD_SMI_INCLUDE_AMD_SMI_SYSTEM_H_
#define AMD_SMI_INCLUDE_AMD_SMI_SYSTEM_H_
#include <vector>
#include <set>
#include "amd_smi/amd_smi.h"
#include "amd_smi/impl/amd_smi_socket.h"
#include "amd_smi/impl/amd_smi_device.h"
#include "amd_smi/impl/amd_smi_drm.h"
namespace amd {
namespace smi {
// Singleton: Only one system in an application
class AMDSmiSystem {
public:
static AMDSmiSystem& getInstance() {
static AMDSmiSystem instance;
return instance;
}
amdsmi_status_t init(uint64_t flags);
amdsmi_status_t cleanup();
std::vector<AMDSmiSocket*>& get_sockets() {return sockets_;}
amdsmi_status_t handle_to_socket(amdsmi_socket_handle socket_handle,
AMDSmiSocket** socket);
amdsmi_status_t handle_to_device(amdsmi_device_handle device_handle,
AMDSmiDevice** device);
amdsmi_status_t gpu_index_to_handle(uint32_t gpu_index,
amdsmi_device_handle* device_handle);
private:
AMDSmiSystem() : init_flag_(AMDSMI_INIT_ALL_DEVICES) {}
uint64_t init_flag_;
AMDSmiDrm drm_;
std::vector<AMDSmiSocket*> sockets_;
std::set<AMDSmiDevice*> devices_; // Track valid devices
};
} // namespace smi
} // namespace amd
#endif // AMD_SMI_INCLUDE_AMD_SMI_SYSTEM_H_
Разница между файлами не показана из-за своего большого размера Загрузить разницу