Add rocm-smi c++ utility classes

Change-Id: I4362151abf84f89942bf2895b45fca498a28dfc9
This commit is contained in:
Chris Freehill
2017-07-24 23:27:46 -05:00
vanhempi a12c5628ea
commit 8424fd6f23
8 muutettua tiedostoa jossa 1166 lisäystä ja 292 poistoa
+51
Näytä tiedosto
@@ -0,0 +1,51 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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 ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_H_
#define ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_H_
#include "common/rocm_smi/rocm_smi_monitor.h"
#include "common/rocm_smi/rocm_smi_device.h"
#include "common/rocm_smi/rocm_smi_main.h"
#endif // ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_H_
+196
Näytä tiedosto
@@ -0,0 +1,196 @@
/* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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.
*
*/
#include <assert.h>
#include <sys/stat.h>
#include <string>
#include <map>
#include <fstream>
#include <cstdint>
#include <iostream>
#include <sstream>
#include <vector>
#include "common/rocm_smi/rocm_smi_main.h"
#include "common/rocm_smi/rocm_smi_device.h"
namespace rocrtst {
namespace smi {
static const char *kDevPerfLevelFName = "power_dpm_force_performance_level";
static const char *kDevDevIDFName = "device";
static const char *kDevOverDriveLevelFName = "pp_sclk_od";
static const char *kDevGPUSClkFName = "pp_dpm_sclk";
static const char *kDevGPUMClkFName = "pp_dpm_mclk";
static const std::map<DevInfoTypes, const char *> kDevAttribNameMap = {
{kDevPerfLevel, kDevPerfLevelFName},
{kDevOverDriveLevel, kDevOverDriveLevelFName},
{kDevDevID, kDevDevIDFName},
{kDevGPUMClk, kDevGPUMClkFName},
{kDevGPUSClk, kDevGPUSClkFName},
};
static bool isRegularFile(std::string fname) {
struct stat file_stat;
stat(fname.c_str(), &file_stat);
return S_ISREG(file_stat.st_mode);
}
Device::Device(std::string p) : path_(p) {
monitor_ = nullptr;
}
Device:: ~Device() {
}
// TODO(cfreehil): cache values that are constant
int Device::readDevInfoStr(DevInfoTypes type, std::string *retStr) {
auto tempPath = path_;
assert(retStr != nullptr);
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
std::ifstream fs;
fs.open(tempPath);
if (!fs.is_open() || !isRegularFile(tempPath)) {
return -1;
}
fs >> *retStr;
fs.close();
return 0;
}
int Device::readDevInfoMultiLineStr(DevInfoTypes type,
std::vector<std::string> *retVec) {
auto tempPath = path_;
std::string line;
assert(retVec != nullptr);
tempPath += "/device/";
tempPath += kDevAttribNameMap.at(type);
std::ifstream fs(tempPath);
std::stringstream buffer;
if (!isRegularFile(tempPath)) {
return -1;
}
while (std::getline(fs, line)) {
retVec->push_back(line);
}
return 0;
}
int Device::readDevInfo(DevInfoTypes type, uint32_t *val) {
assert(val != nullptr);
std::string tempStr;
switch (type) {
case kDevDevID:
if (readDevInfoStr(type, &tempStr)) {
return -1;
}
*val = std::stoi(tempStr, 0, 16);
break;
case kDevOverDriveLevel:
if (readDevInfoStr(type, &tempStr)) {
return -1;
}
*val = std::stoi(tempStr, 0);
break;
default:
return -1;
}
return 0;
}
int Device::readDevInfo(DevInfoTypes type, std::vector<std::string> *val) {
assert(val != nullptr);
switch (type) {
case kDevGPUMClk:
case kDevGPUSClk:
if (readDevInfoMultiLineStr(type, val)) {
return -1;
}
break;
default:
return -1;
}
return 0;
}
int Device::readDevInfo(DevInfoTypes type, std::string *val) {
assert(val != nullptr);
switch (type) {
case kDevPerfLevel:
case kDevOverDriveLevel:
case kDevDevID:
if (readDevInfoStr(type, val)) {
return -1;
}
break;
default:
return -1;
}
return 0;
}
} // namespace smi
} // namespace rocrtst
+92
Näytä tiedosto
@@ -0,0 +1,92 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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 ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_DEVICE_H_
#define ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_DEVICE_H_
#include <string>
#include <memory>
#include <utility>
#include <cstdint>
#include <vector>
#include "common/rocm_smi/rocm_smi_monitor.h"
namespace rocrtst {
namespace smi {
enum DevInfoTypes {
kDevPerfLevel,
kDevOverDriveLevel,
kDevDevID,
kDevGPUMClk,
kDevGPUSClk
};
class Device {
public:
explicit Device(std::string path);
~Device(void);
void set_monitor(std::shared_ptr<Monitor> m) {monitor_ = m;}
std::string path(void) const {return path_;}
const std::shared_ptr<Monitor>& monitor() {return monitor_;}
int readDevInfo(DevInfoTypes type, uint32_t *val);
int readDevInfo(DevInfoTypes type, std::string *val);
int readDevInfo(DevInfoTypes type, std::vector<std::string> *retVec);
private:
std::shared_ptr<Monitor> monitor_;
std::string path_;
int readDevInfoStr(DevInfoTypes type, std::string *retStr);
int readDevInfoMultiLineStr(DevInfoTypes type,
std::vector<std::string> *retVec);
};
} // namespace smi
} // namespace rocrtst
#endif // ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_DEVICE_H_
+235
Näytä tiedosto
@@ -0,0 +1,235 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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.
*
*/
#include <sys/stat.h>
#include <dirent.h>
#include <assert.h>
#include <string.h>
#include <string>
#include <cstdint>
#include <memory>
#include <fstream>
#include <vector>
#include <set>
#include <utility>
#include <functional>
#include "common/rocm_smi/rocm_smi.h"
#include "common/rocm_smi/rocm_smi_main.h"
static const char *kPathDRMRoot = "/sys/class/drm";
static const char *kPathHWMonRoot = "/sys/class/hwmon";
static const char *kDeviceNamePrefix = "card";
static const char *kAMDMonitorTypes[] = {"radeon", "amdgpu", ""};
namespace rocrtst {
namespace smi {
static bool FileExists(char const *filename) {
struct stat buf;
return (stat(filename, &buf) == 0);
}
// Return 0 if same file, 1 if not, and -1 for error
static int SameFile(const std::string fileA, const std::string fileB) {
struct stat aStat;
struct stat bStat;
int ret;
ret = stat(fileA.c_str(), &aStat);
if (ret) {
return -1;
}
ret = stat(fileB.c_str(), &bStat);
if (ret) {
return -1;
}
if (aStat.st_dev != bStat.st_dev) {
return 1;
}
if (aStat.st_ino != bStat.st_ino) {
return 1;
}
return 0;
}
static int SameDevice(const std::string fileA, const std::string fileB) {
return SameFile(fileA + "/device", fileB + "/device");
}
void ShowAllTemperatures();
RocmSMI::RocmSMI() {
auto i = 0;
while (std::string(kAMDMonitorTypes[i]) != "") {
amd_monitor_types_.insert(kAMDMonitorTypes[i]);
++i;
}
}
RocmSMI::~RocmSMI() {
devices_.clear();
monitors_.clear();
}
void
RocmSMI::AddToDeviceList(std::string dev_name) {
auto ret = 0;
auto dev_path = std::string(kPathDRMRoot);
dev_path += "/";
dev_path += dev_name;
auto dev = std::shared_ptr<Device>(new Device(dev_path));
auto m = monitors_.begin();
while (m != monitors_.end()) {
ret = SameDevice(dev->path(), (*m)->path());
if (ret == 0) {
dev->set_monitor(*m);
m = monitors_.erase(m);
} else {
assert(ret == 1);
++m;
}
}
devices_.push_back(dev);
return;
}
uint32_t RocmSMI::DiscoverDevices(void) {
auto ret = 0;
ret = DiscoverAMDMonitors();
if (ret) {
return ret;
}
auto drm_dir = opendir(kPathDRMRoot);
auto dentry = readdir(drm_dir);
while (dentry != nullptr) {
if (memcmp(dentry->d_name, kDeviceNamePrefix, strlen(kDeviceNamePrefix))
== 0) {
AddToDeviceList(dentry->d_name);
}
dentry = readdir(drm_dir);
}
if (closedir(drm_dir)) {
return 1;
}
return 0;
}
uint32_t RocmSMI::DiscoverAMDMonitors(void) {
auto mon_dir = opendir(kPathHWMonRoot);
auto dentry = readdir(mon_dir);
std::string mon_name;
std::string tmp;
while (dentry != nullptr) {
if (dentry->d_name[0] == '.') {
dentry = readdir(mon_dir);
continue;
}
mon_name = kPathHWMonRoot;
mon_name += "/";
mon_name += dentry->d_name;
tmp = mon_name + "/name";
if (FileExists(tmp.c_str())) {
std::ifstream fs;
fs.open(tmp);
if (!fs.is_open()) {
return 1;
}
std::string mon_type;
fs >> mon_type;
fs.close();
if (amd_monitor_types_.find(mon_type) != amd_monitor_types_.end()) {
monitors_.push_back(std::shared_ptr<Monitor>(new Monitor(mon_name)));
}
}
dentry = readdir(mon_dir);
}
if (closedir(mon_dir)) {
return 1;
}
return 0;
}
void RocmSMI::IterateSMIDevices(
std::function<bool(std::shared_ptr<Device>&, void *)> func, void *p) {
auto d = devices_.begin();
while (d != devices_.end()) {
if (func(*d, p)) {
return;
}
++d;
}
}
} // namespace smi
} // namespace rocrtst
+83
Näytä tiedosto
@@ -0,0 +1,83 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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 ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MAIN_H_
#define ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MAIN_H_
#include <vector>
#include <memory>
#include <functional>
#include <set>
#include <string>
#include "common/rocm_smi/rocm_smi_device.h"
#include "common/rocm_smi/rocm_smi_monitor.h"
namespace rocrtst {
namespace smi {
class RocmSMI {
public:
RocmSMI(void);
~RocmSMI(void);
uint32_t DiscoverDevices(void);
// Will execute "func" for every Device object known about, or until func
// returns true;
void IterateSMIDevices(
std::function<bool(std::shared_ptr<Device>&, void *)> func, void *);
private:
std::vector<std::shared_ptr<Device>> devices_;
std::vector<std::shared_ptr<Monitor>> monitors_;
std::set<std::string> amd_monitor_types_;
void AddToDeviceList(std::string dev_name);
uint32_t DiscoverAMDMonitors(void);
};
} // namespace smi
} // namespace rocrtst
#endif // ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MAIN_H_
+136
Näytä tiedosto
@@ -0,0 +1,136 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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.
*
*/
#include <assert.h>
#include <fstream>
#include <string>
#include <cstdint>
#include <map>
#include <iostream>
#include "common/rocm_smi/rocm_smi_main.h"
#include "common/rocm_smi/rocm_smi_monitor.h"
namespace rocrtst {
namespace smi {
struct MonitorNameEntry {
MonitorTypes type;
const char *name;
};
static const char *kMonTempFName = "temp1_input";
static const char *kMonFanSpeedFName = "pwm1";
static const char *kMonMaxFanSpeedFName = "pwm1_max";
static const char *kMonNameFName = "name";
static const std::map<MonitorTypes, const char *> kMonitorNameMap = {
{kMonName, kMonNameFName},
{kMonTemp, kMonTempFName},
{kMonFanSpeed, kMonFanSpeedFName},
{kMonMaxFanSpeed, kMonMaxFanSpeedFName}
};
Monitor::Monitor(std::string path) : path_(path) {
}
Monitor::~Monitor(void) {
}
int Monitor::readMonitorStr(MonitorTypes type, std::string *retStr) {
auto tempPath = path_;
assert(retStr != nullptr);
tempPath += "/";
tempPath += kMonitorNameMap.at(type);
std::ifstream fs;
fs.open(tempPath);
if (!fs.is_open()) {
return -1;
}
fs >> *retStr;
fs.close();
return 0;
}
int Monitor::readMonitor(MonitorTypes type, uint32_t *val) {
assert(val != nullptr);
std::string tempStr;
switch (type) {
case kMonTemp: // Temperature in millidegrees
case kMonFanSpeed:
case kMonMaxFanSpeed:
if (readMonitorStr(type, &tempStr)) {
return -1;
}
*val = std::stoi(tempStr);
return 0;
default:
return -1;
}
}
// This string version should work for all valid monitor types
int Monitor::readMonitor(MonitorTypes type, std::string *val) {
assert(val != nullptr);
if (readMonitorStr(type, val)) {
return -1;
}
return 0;
}
} // namespace smi
} // namespace rocrtst
+78
Näytä tiedosto
@@ -0,0 +1,78 @@
/*
* =============================================================================
* ROC Runtime Conformance Release License
* =============================================================================
* The University of Illinois/NCSA
* Open Source License (NCSA)
*
* Copyright (c) 2017, 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 ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MONITOR_H_
#define ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MONITOR_H_
#include <string>
#include <cstdint>
namespace rocrtst {
namespace smi {
enum MonitorTypes {
kMonName,
kMonTemp, // Temperature in millidegrees
kMonFanSpeed,
kMonMaxFanSpeed,
};
class Monitor {
public:
explicit Monitor(std::string path);
~Monitor(void);
const std::string path(void) const {return path_;}
int readMonitor(MonitorTypes type, uint32_t *val);
int readMonitor(MonitorTypes type, std::string *val);
private:
std::string path_;
int readMonitorStr(MonitorTypes type, std::string *retStr);
};
} // namespace smi
} // namespace rocrtst
#endif // ROCRTST_COMMON_ROCM_SMI_ROCM_SMI_MONITOR_H_
+295 -292
Näytä tiedosto
@@ -1,292 +1,295 @@
#
# Minimum version of cmake required
#
cmake_minimum_required(VERSION 2.8.0)
#
# GCC 4.8 or higher compiler required.
#
# Setup build environment
#
# 1) Set env. variable specifying the location of ROCR header files
#
# export ROCR_DIR="Root for RocR install"
#
# 2) Set env. variable ROCRTST_BLD_TYPE to either "Debug" or "Release".
# If not set, the default value is "Debug" is bound.
#
# export ROCRTST_BLD_TYPE=Debug or ROCRTST_BLD_TYPE=Release
#
# 3) Set env. variable ROCRTST_BLD_BITS to either "32" or "64"
# If not set, the default value of "64" is bound.
#
# export ROCRTST_BLD_BITS=32 or ROCRTST_BLD_BITS=64
#
# 4) Set env. variable TARGET_DEVICE to indicate gpu type (e.g., gfx803,
# gfx900, ...)
#
# Building rocrtst Suite
#
# 1) Create build folder e.g. "rocrtst/build" - any name will do
# 2) Cd into build folder
# 3) Run "cmake .."
# 4) Run "make"
#
#
# Currently support for Windows platform is not present
#
if(WIN32)
MESSAGE("rocrtst Suite is not supported on Windows platform")
RETURN()
endif()
#
# Process environment variables relating to Build type, size and RT version
#
string(TOLOWER "$ENV{ROCRTST_BLD_TYPE}" tmp)
if("${tmp}" STREQUAL debug)
set(BUILD_TYPE "Debug")
set(ISDEBUG 1)
else()
set(BUILD_TYPE "Release")
set(ISDEBUG 0)
endif()
if("$ENV{ROCRTST_BLD_BITS}" STREQUAL 32)
set (ONLY64STR "")
set (IS64BIT 0)
else()
set (ONLY64STR "64")
set (IS64BIT 1)
endif()
set(ROCR_INC_DIR $ENV{ROCR_DIR}/hsa/include)
set(ROCR_LIB_DIR $ENV{ROCR_DIR}/lib)
#
# Determine ROCR Header files are present
#
if(NOT EXISTS ${ROCR_INC_DIR}/hsa/hsa.h)
MESSAGE("ERROR: ${ROCR_INC_DIR}/hsa/hsa.h does not exist. Check ROCR_DIR env. variable.")
RETURN()
endif()
# Determine ROCR Library files are present
#
if (${IS64BIT} EQUAL 0)
if(NOT EXISTS ${ROCR_LIB_DIR}/libhsa-runtime.so)
MESSAGE("ERROR: Environment variable ROCR_LIB_DIR pointing to ROCR libraries is not set")
RETURN()
endif()
else()
if(NOT EXISTS ${ROCR_LIB_DIR}/libhsa-runtime64.so)
MESSAGE("ERROR: Environment variable ROCR_LIB_DIR pointing to ROCR libraries is not set")
RETURN()
endif()
endif()
if (DEFINED ENV{OPENCL_DIR})
set(CLANG $ENV{OPENCL_DIR}/bin/x86_64/clang)
set(OPENCL_DIR $ENV{OPENCL_DIR})
if (NOT EXISTS ${CLANG})
message("ERROR: path to clang (${CLANG}) is not valid. Is env. variable OPENCL_DIR correct?")
return()
endif()
if (DEFINED ENV{OPENCL_VER})
set(OPENCL_VER $ENV{OPENCL_VER})
else()
message("OPENCL_VER environment variable is not set. Using default")
set(OPENCL_VER "2.0")
endif()
else()
message("WARNING: OPENCL_DIR environment variable is not set. Kernels will not be built.")
endif()
if (DEFINED ENV{TARGET_DEVICE})
set(TARGET_DEVICE $ENV{TARGET_DEVICE})
else()
message("ERROR: TARGET_DEVICE environment variable is not defined.")
message("Please define a valid clang target (e.g., gfx803, gfx900,...).")
return()
endif()
#
# Set Name for rocrtst Suite Project
#
set(ROCRTST_SUITE_NAME "rocrtst${ONLY64STR}")
project (${ROCRTST_SUITE_NAME})
#
# Print out the build configuration being used:
#
# Build Src directory
# Build Binary directory
# Build Type: Debug Vs Release, 32 Vs 64
# Compiler Version, etc
#
message("")
message("Build Configuration:")
message("-------------IS64BIT: " ${IS64BIT})
message("-----------BuildType: " ${BUILD_TYPE})
message("------------Compiler: " ${CMAKE_CXX_COMPILER})
message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION})
message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR})
message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR})
message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib)
message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin)
message("-------Target Device: " ${TARGET_DEVICE})
message("----------Clang path: " ${CLANG})
message("-------OpenCL version " ${OPENCL_VER})
message("")
set(KERNELS_DIR ${PROJECT_SOURCE_DIR}/kernels)
#
# Set the build type based on user input
#
set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
#
# Flag to enable / disable verbose output.
#
SET( CMAKE_VERBOSE_MAKEFILE on )
#
# Compiler pre-processor definitions.
#
# Define MACRO "DEBUG" if build type is "Debug"
if(${BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG)
endif()
add_definitions(-D__linux__)
add_definitions(-DLITTLEENDIAN_CPU=1)
#
# Linux Compiler options
#
set(CMAKE_CXX_FLAGS "-std=c++11 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmerge-all-constants")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fms-extensions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
#
# Extend the compiler flags for 64-bit builds
#
if (IS64BIT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -msse -msse2")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
#
# Add compiler flags to include symbol information for debug builds
#
if(ISDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0")
endif()
MESSAGE("ISDEBUG STEP:Done")
set(ROCRTST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
# Set Name for Google Test Framework and build it as a
# static library to be linked with user test programs
#
set(GOOGLE_TEST_FRWK_NAME "google-test-frwk${ONLY64STR}")
add_subdirectory(${ROCRTST_ROOT}/gtest "${PROJECT_BINARY_DIR}/gtest")
set (ROCRTST_LIBS ${ROCRTST_LIBS} ${GOOGLE_TEST_FRWK_NAME}
hsa-runtime-tools${ONLY64STR})
MESSAGE("ROCRTST_LIBS SET STEP:Done")
#
#
# Other source directories
aux_source_directory(${ROCRTST_ROOT}/common common_srcs)
#
# Specify the directory containing various libraries of ROCR
# to be linked against for building ROC Perf applications
#
LINK_DIRECTORIES(${ROCR_LIB_DIR})
#
# Extend the list of libraries to be used for linking ROC Perf Apps
#
set(ROCRTST_LIBS ${ROCRTST_LIBS} hsa-runtime${ONLY64STR})
# Set Name for rocrtst
MESSAGE(${ROCRTST_LIBS})
set(ROCRTST "rocrtst${ONLY64STR}")
#
# Source files for building rocrtst
#
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} performanceSources)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/test_common testCommonSources)
aux_source_directory(${ROCRTST_ROOT}/suites/test_common testCommonSources)
# Header file include path
include_directories(${ROCR_INC_DIR})
include_directories(${ROCRTST_ROOT})
include_directories(${ROCRTST_ROOT}/gtest/include)
# Use this function to build any samples that have kernels to be built
function(build_kernel S_NAME)
set(SNAME_KERNEL "${S_NAME}_kernels.hsaco")
set(TARG_NAME "${S_NAME}_hsaco")
set(HSACO_TARG_LIST ${HSACO_TARG_LIST} ${TARG_NAME} PARENT_SCOPE)
separate_arguments(CLANG_ARG_LIST UNIX_COMMAND "-target amdgcn-amdh-amdhsa -mcpu=${TARGET_DEVICE} -include ${OPENCL_DIR}/include/opencl-c.h ${BITCODE_LIBS} -cl-std=CL${OPENCL_VER} ${CL_FILE_LIST} -o ${PROJECT_BINARY_DIR}/${SNAME_KERNEL}")
add_custom_target(${TARG_NAME} ${CLANG} ${CLANG_ARG_LIST}
COMMENT "BUILDING KERNEL..."
VERBATIM)
endfunction(build_kernel)
######################
# Kernel Build Section
######################
set(KERN_SUFFIX "kernels.hsaco")
set(BITCODE_PREF "-Xclang -mlink-bitcode-file -Xclang")
set(BITCODE_PREF "${BITCODE_PREF} ${OPENCL_DIR}/lib/x86_64/bitcode")
set(COMMON_BITCODE_LIBS "${BITCODE_PREF}/opencl.amdgcn.bc")
set(COMMON_BITCODE_LIBS "${COMMON_BITCODE_LIBS} ${BITCODE_PREF}/ockl.amdgcn.bc")
# To build kernels, repeat the pattern used below for the P2P kernel; this
# pattern sets the bitcode libraries required by the kernel which will be
# used in the build_kernel() call, which builds the kernel.
# Test Case Template example
set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
set(CL_FILE_LIST "${KERNELS_DIR}/test_case_template_kernels.cl")
build_kernel("test_case_template")
# P2P Memory Access
#set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
#set(CL_FILE_LIST "${KERNELS_DIR}/p2p_mem_access_kernels.cl")
#build_kernel("p2p_mem_access")
# Dispatch Time
set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
set(CL_FILE_LIST "${KERNELS_DIR}/dispatch_time_kernels.cl")
build_kernel("dispatch_time")
# Build rules
add_executable(${ROCRTST} ${performanceSources} ${common_srcs} ${testCommonSources})
target_link_libraries(${ROCRTST} ${ROCRTST_LIBS} c stdc++ dl pthread rt)
add_custom_target(rocrtst_kernels DEPENDS ${HSACO_TARG_LIST})
INSTALL(TARGETS ${ROCRTST}
ARCHIVE DESTINATION ${PROJECT_BINARY_DIR}/lib
LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/lib
RUNTIME DESTINATION ${PROJECT_BINARY_DIR}/bin)
#
# Minimum version of cmake required
#
cmake_minimum_required(VERSION 2.8.0)
#
# GCC 4.8 or higher compiler required.
#
# Setup build environment
#
# 1) Set env. variable specifying the location of ROCR header files
#
# export ROCR_DIR="Root for RocR install"
#
# 2) Set env. variable ROCRTST_BLD_TYPE to either "Debug" or "Release".
# If not set, the default value is "Debug" is bound.
#
# export ROCRTST_BLD_TYPE=Debug or ROCRTST_BLD_TYPE=Release
#
# 3) Set env. variable ROCRTST_BLD_BITS to either "32" or "64"
# If not set, the default value of "64" is bound.
#
# export ROCRTST_BLD_BITS=32 or ROCRTST_BLD_BITS=64
#
# 4) Set env. variable TARGET_DEVICE to indicate gpu type (e.g., gfx803,
# gfx900, ...)
#
# Building rocrtst Suite
#
# 1) Create build folder e.g. "rocrtst/build" - any name will do
# 2) Cd into build folder
# 3) Run "cmake .."
# 4) Run "make"
#
#
# Currently support for Windows platform is not present
#
if(WIN32)
MESSAGE("rocrtst Suite is not supported on Windows platform")
RETURN()
endif()
#
# Process environment variables relating to Build type, size and RT version
#
string(TOLOWER "$ENV{ROCRTST_BLD_TYPE}" tmp)
if("${tmp}" STREQUAL debug)
set(BUILD_TYPE "Debug")
set(ISDEBUG 1)
else()
set(BUILD_TYPE "Release")
set(ISDEBUG 0)
endif()
if("$ENV{ROCRTST_BLD_BITS}" STREQUAL 32)
set (ONLY64STR "")
set (IS64BIT 0)
else()
set (ONLY64STR "64")
set (IS64BIT 1)
endif()
set(ROCR_INC_DIR $ENV{ROCR_DIR}/hsa/include)
set(ROCR_LIB_DIR $ENV{ROCR_DIR}/lib)
#
# Determine ROCR Header files are present
#
if(NOT EXISTS ${ROCR_INC_DIR}/hsa/hsa.h)
MESSAGE("ERROR: ${ROCR_INC_DIR}/hsa/hsa.h does not exist. Check ROCR_DIR env. variable.")
RETURN()
endif()
# Determine ROCR Library files are present
#
if (${IS64BIT} EQUAL 0)
if(NOT EXISTS ${ROCR_LIB_DIR}/libhsa-runtime.so)
MESSAGE("ERROR: Environment variable ROCR_LIB_DIR pointing to ROCR libraries is not set")
RETURN()
endif()
else()
if(NOT EXISTS ${ROCR_LIB_DIR}/libhsa-runtime64.so)
MESSAGE("ERROR: Environment variable ROCR_LIB_DIR pointing to ROCR libraries is not set")
RETURN()
endif()
endif()
if (DEFINED ENV{OPENCL_DIR})
set(CLANG $ENV{OPENCL_DIR}/bin/x86_64/clang)
set(OPENCL_DIR $ENV{OPENCL_DIR})
if (NOT EXISTS ${CLANG})
message("ERROR: path to clang (${CLANG}) is not valid. Is env. variable OPENCL_DIR correct?")
return()
endif()
if (DEFINED ENV{OPENCL_VER})
set(OPENCL_VER $ENV{OPENCL_VER})
else()
message("OPENCL_VER environment variable is not set. Using default")
set(OPENCL_VER "2.0")
endif()
else()
message("WARNING: OPENCL_DIR environment variable is not set. Kernels will not be built.")
endif()
if (DEFINED ENV{TARGET_DEVICE})
set(TARGET_DEVICE $ENV{TARGET_DEVICE})
else()
message("ERROR: TARGET_DEVICE environment variable is not defined.")
message("Please define a valid clang target (e.g., gfx803, gfx900,...).")
return()
endif()
#
# Set Name for rocrtst Suite Project
#
set(ROCRTST_SUITE_NAME "rocrtst${ONLY64STR}")
project (${ROCRTST_SUITE_NAME})
#
# Print out the build configuration being used:
#
# Build Src directory
# Build Binary directory
# Build Type: Debug Vs Release, 32 Vs 64
# Compiler Version, etc
#
message("")
message("Build Configuration:")
message("-------------IS64BIT: " ${IS64BIT})
message("-----------BuildType: " ${BUILD_TYPE})
message("------------Compiler: " ${CMAKE_CXX_COMPILER})
message("-------------Version: " ${CMAKE_CXX_COMPILER_VERSION})
message("--------Proj Src Dir: " ${PROJECT_SOURCE_DIR})
message("--------Proj Bld Dir: " ${PROJECT_BINARY_DIR})
message("--------Proj Lib Dir: " ${PROJECT_BINARY_DIR}/lib)
message("--------Proj Exe Dir: " ${PROJECT_BINARY_DIR}/bin)
message("-------Target Device: " ${TARGET_DEVICE})
message("----------Clang path: " ${CLANG})
message("-------OpenCL version " ${OPENCL_VER})
message("")
set(KERNELS_DIR ${PROJECT_SOURCE_DIR}/kernels)
#
# Set the build type based on user input
#
set(CMAKE_BUILD_TYPE ${BUILD_TYPE})
#
# Flag to enable / disable verbose output.
#
SET( CMAKE_VERBOSE_MAKEFILE on )
#
# Compiler pre-processor definitions.
#
# Define MACRO "DEBUG" if build type is "Debug"
if(${BUILD_TYPE} STREQUAL "Debug")
add_definitions(-DDEBUG)
endif()
add_definitions(-D__linux__)
add_definitions(-DLITTLEENDIAN_CPU=1)
#
# Linux Compiler options
#
set(CMAKE_CXX_FLAGS "-std=c++11 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-math-errno")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmerge-all-constants")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fms-extensions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
#
# Extend the compiler flags for 64-bit builds
#
if (IS64BIT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -msse -msse2")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
endif()
#
# Add compiler flags to include symbol information for debug builds
#
if(ISDEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -O0")
endif()
MESSAGE("ISDEBUG STEP:Done")
set(ROCRTST_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
# Set Name for Google Test Framework and build it as a
# static library to be linked with user test programs
#
set(GOOGLE_TEST_FRWK_NAME "google-test-frwk${ONLY64STR}")
add_subdirectory(${ROCRTST_ROOT}/gtest "${PROJECT_BINARY_DIR}/gtest")
set (ROCRTST_LIBS ${ROCRTST_LIBS} ${GOOGLE_TEST_FRWK_NAME}
hsa-runtime-tools${ONLY64STR})
MESSAGE("ROCRTST_LIBS SET STEP:Done")
#
#
# Other source directories
aux_source_directory(${ROCRTST_ROOT}/common common_srcs)
aux_source_directory(${ROCRTST_ROOT}/common/rocm_smi common_smi_srcs)
#
# Specify the directory containing various libraries of ROCR
# to be linked against for building ROC Perf applications
#
LINK_DIRECTORIES(${ROCR_LIB_DIR})
#
# Extend the list of libraries to be used for linking ROC Perf Apps
#
set(ROCRTST_LIBS ${ROCRTST_LIBS} hsa-runtime${ONLY64STR})
# Set Name for rocrtst
MESSAGE(${ROCRTST_LIBS})
set(ROCRTST "rocrtst${ONLY64STR}")
#
# Source files for building rocrtst
#
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} performanceSources)
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/test_common testCommonSources)
aux_source_directory(${ROCRTST_ROOT}/suites/test_common testCommonSources)
# Header file include path
include_directories(${ROCR_INC_DIR})
include_directories(${ROCRTST_ROOT})
include_directories(${ROCRTST_ROOT}/gtest/include)
# Use this function to build any samples that have kernels to be built
function(build_kernel S_NAME)
set(SNAME_KERNEL "${S_NAME}_kernels.hsaco")
set(TARG_NAME "${S_NAME}_hsaco")
set(HSACO_TARG_LIST ${HSACO_TARG_LIST} ${TARG_NAME} PARENT_SCOPE)
separate_arguments(CLANG_ARG_LIST UNIX_COMMAND "-target amdgcn-amdh-amdhsa -mcpu=${TARGET_DEVICE} -include ${OPENCL_DIR}/include/opencl-c.h ${BITCODE_LIBS} -cl-std=CL${OPENCL_VER} ${CL_FILE_LIST} -o ${PROJECT_BINARY_DIR}/${SNAME_KERNEL}")
add_custom_target(${TARG_NAME} ${CLANG} ${CLANG_ARG_LIST}
COMMENT "BUILDING KERNEL..."
VERBATIM)
endfunction(build_kernel)
######################
# Kernel Build Section
######################
set(KERN_SUFFIX "kernels.hsaco")
set(BITCODE_PREF "-Xclang -mlink-bitcode-file -Xclang")
set(BITCODE_PREF "${BITCODE_PREF} ${OPENCL_DIR}/lib/x86_64/bitcode")
set(COMMON_BITCODE_LIBS "${BITCODE_PREF}/opencl.amdgcn.bc")
set(COMMON_BITCODE_LIBS "${COMMON_BITCODE_LIBS} ${BITCODE_PREF}/ockl.amdgcn.bc")
# To build kernels, repeat the pattern used below for the P2P kernel; this
# pattern sets the bitcode libraries required by the kernel which will be
# used in the build_kernel() call, which builds the kernel.
# Test Case Template example
set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
set(CL_FILE_LIST "${KERNELS_DIR}/test_case_template_kernels.cl")
build_kernel("test_case_template")
# P2P Memory Access
#set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
#set(CL_FILE_LIST "${KERNELS_DIR}/p2p_mem_access_kernels.cl")
#build_kernel("p2p_mem_access")
# Dispatch Time
set(BITCODE_LIBS "${COMMON_BITCODE_LIBS}")
set(CL_FILE_LIST "${KERNELS_DIR}/dispatch_time_kernels.cl")
build_kernel("dispatch_time")
# Build rules
add_executable(${ROCRTST} ${performanceSources} ${common_srcs}
${common_smi_srcs} ${testCommonSources})
target_link_libraries(${ROCRTST} ${ROCRTST_LIBS} c stdc++ dl pthread rt)
add_custom_target(rocrtst_kernels DEPENDS ${HSACO_TARG_LIST})
INSTALL(TARGETS ${ROCRTST}
ARCHIVE DESTINATION ${PROJECT_BINARY_DIR}/lib
LIBRARY DESTINATION ${PROJECT_BINARY_DIR}/lib
RUNTIME DESTINATION ${PROJECT_BINARY_DIR}/bin)