Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
cmake_minimum_required(VERSION 3.16.3)
project (hipcc.bin)

# Specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set (LINK_LIBS libstdc++fs.so)
project (hipcc.bin)
add_executable(hipcc.bin src/hipBin.cpp)
if (NOT WIN32) # C++17 does not require the std lib linking
target_link_libraries(hipcc.bin ${LINK_LIBS} ) # for hipcc
endif()

project (hipconfig)
project (hipconfig.bin)
add_executable(hipconfig.bin src/hipBin.cpp)
if (NOT WIN32) # C++17 does not require the std lib linking
target_link_libraries(hipconfig.bin ${LINK_LIBS} ) # for hipconfig
endif()

# If not building as a standalone, put the binary in /bin
if(DEFINED HIPCC_BUILD_PATH)
Expand Down
16 changes: 13 additions & 3 deletions src/hipBin_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ string RuntimeTypeStr(RuntimeType runtime) {

enum OsType {
lnx = 0,
windows
windows,
macos
// add new OS types to be added here
};

Expand All @@ -130,6 +131,8 @@ string OsTypeStr(OsType os) {
return "linux";
case windows:
return "windows";
case macos:
return "macOS";
// add new OS types to be added here
default:
return "invalid OsType";
Expand Down Expand Up @@ -276,6 +279,8 @@ HipBinBase::HipBinBase() {
void HipBinBase::readOSInfo() {
#if defined _WIN32 || defined _WIN64
osInfo_ = windows;
#elif defined __APPLE__ || defined __MACOSX
osInfo_ = macos;
#elif defined __unix || defined __linux__
osInfo_ = lnx;
#endif
Expand Down Expand Up @@ -389,8 +394,13 @@ void HipBinBase::getSystemInfo() const {
system("wmic path win32_VideoController get AdapterCompatibility,"
"InstalledDisplayDrivers,Name | findstr /B /C:\"Advanced Micro Devices\"");
} else {
assert(os == lnx);
cout << endl << "== Linux Kernel" << endl;
if (os == lnx) {
cout << endl << "== Linux Kernel" << endl;
} else if (os == macos) {
cout << endl << "== macOS Kernel" << endl;
} else {
assert(false);
}
cout << "Hostname : " << std::flush;
system("hostname");
system("uname -a");
Expand Down
11 changes: 6 additions & 5 deletions src/hipBin_spirv.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,13 @@ const string &HipBinSpirv::getCompilerPath() const { return hipClangPath_; }

void HipBinSpirv::printCompilerInfo() const {
const string &hipClangPath = getCompilerPath();
fs::path hipLlvmPath = hipClangPath;

cout << endl;

string cmd = hipClangPath + "/clang++ --version";
string cmd = (hipLlvmPath / "clang++ --version").string();
system(cmd.c_str()); // hipclang version
cmd = hipClangPath + "/llc --version";
cmd = (hipLlvmPath / "llc --version").string();
system(cmd.c_str()); // llc version
cout << "hip-clang-cxxflags :" << endl;
cout << hipInfo_.cxxflags << endl;
Expand Down Expand Up @@ -449,7 +450,8 @@ string HipBinSpirv::getCppConfig() { return hipInfo_.cxxflags; }
string HipBinSpirv::getDeviceLibPath() const { return ""; }

bool HipBinSpirv::detectPlatform() {
if (getOSInfo() == windows) {
auto os = getOSInfo();
if (os == windows) {
return false;
}

Expand All @@ -467,8 +469,7 @@ bool HipBinSpirv::detectPlatform() {
*/

HipInfo hipInfo;
fs::path currentBinaryPath = fs::canonical("/proc/self/exe");
currentBinaryPath = currentBinaryPath.parent_path();
fs::path currentBinaryPath = hipBinUtilPtr_->getSelfPath();
fs::path sharePathBuild = currentBinaryPath.string() + "/../share";
fs::path sharePathInstall =
var.hipPathEnv_.empty() ? "" : var.hipPathEnv_ + "/share";
Expand Down
34 changes: 22 additions & 12 deletions src/hipBin_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ namespace fs = std::filesystem;
#include <algorithm>
#include <vector>

#if defined(__APPLE__) || defined(__MACOSX)
#include <mach-o/dyld.h>
#endif

#if defined(_WIN32) || defined(_WIN64)
#include <tchar.h>
Expand Down Expand Up @@ -193,7 +196,7 @@ string HipBinUtil::mktempFile(string name) {
return name;
}

// gets the path of the executable name
// gets the directory path of the running executable
string HipBinUtil::getSelfPath() const {
int MAX_PATH_CHAR = 1024;
int bufferSize = 0;
Expand All @@ -206,17 +209,24 @@ string HipBinUtil::getSelfPath() const {
path = string(wide.begin(), wide.end());
#else
char buff[MAX_PATH_CHAR];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len > 0) {
buff[len] = '\0';
path = string(buff);
fs::path exePath(path);
path = exePath.parent_path().string();
} else {
cout << "readlink: Error reading the exe path" << endl;
perror("readlink");
exit(-1);
}
#if defined(__APPLE__) || defined(__MACOSX)
uint32_t len = sizeof(buff) - 1;
if(_NSGetExecutablePath(buff, &len) || len <= 0) {
cout << "hipcc: Error reading the exe path" << endl;
exit(-1);
}
#else
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
if (len <= 0) {
cout << "hipcc: Error reading the exe path" << endl;
perror("readlink");
exit(-1);
}
#endif
buff[len] = '\0';
path = string(buff);
fs::path exePath(path);
path = exePath.remove_filename().string();
#endif
return path;
}
Expand Down