Skip to content

Commit 5fb5cfa

Browse files
committed
SWDEV-296926 - hipcc/hipconfig binary src
1 parent 2c48269 commit 5fb5cfa

File tree

6 files changed

+2927
-0
lines changed

6 files changed

+2927
-0
lines changed

amd/hipcc/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
cmake_minimum_required(VERSION 3.16.3)
2+
project (hipcc)
3+
4+
# specify the C++ standard
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED True)
7+
8+
set ( LINK_LIBS libstdc++fs.so)
9+
add_executable(hipcc src/hipBin.cpp)
10+
if (NOT WIN32) #c++17 does not require the std lib linking
11+
target_link_libraries(hipcc ${LINK_LIBS} ) # for hipcc
12+
endif()
13+
14+
project (hipconfig)
15+
add_executable(hipconfig src/hipBin.cpp)
16+
if (NOT WIN32) #c++17 does not require the std lib linking
17+
target_link_libraries(hipconfig ${LINK_LIBS} ) # for hipconfig
18+
endif()
19+
20+
set(HIP_VERSION_MAJOR 4 PARENT_SCOPE)
21+
set(HIP_VERSION_MINOR 4 PARENT_SCOPE)
22+
set(HIP_VERSION_PATCH 4 PARENT_SCOPE)

amd/hipcc/src/hipBin.cpp

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
*/
22+
23+
#include "hipBin_util.h"
24+
#include "hipBin_amd.h"
25+
#include "hipBin_nvidia.h"
26+
#include <vector>
27+
#include <string>
28+
29+
class HipBinUtil;
30+
class HipBinBase;
31+
class HipBinAmd;
32+
class HipBinNvidia;
33+
class HipBin;
34+
35+
36+
class HipBin {
37+
private:
38+
HipBinUtil* hipBinUtilPtr_;
39+
vector<HipBinBase*> hipBinBasePtrs_;
40+
vector<PlatformInfo> platformVec_;
41+
HipBinBase* hipBinNVPtr_;
42+
HipBinBase* hipBinAMDPtr_;
43+
44+
public:
45+
HipBin();
46+
~HipBin();
47+
vector<HipBinBase*>& getHipBinPtrs();
48+
vector<PlatformInfo>& getPlaformInfo();
49+
void executeHipBin(string filename, int argc, char* argv[]);
50+
void executeHipConfig(int argc, char* argv[]);
51+
void executeHipCC(int argc, char* argv[]);
52+
};
53+
54+
55+
// Implementation ================================================
56+
//===========================================================================
57+
58+
HipBin::HipBin() {
59+
hipBinUtilPtr_ = hipBinUtilPtr_->getInstance();
60+
hipBinNVPtr_ = new HipBinNvidia();
61+
hipBinAMDPtr_ = new HipBinAmd();
62+
bool platformDetected = false;
63+
if (hipBinAMDPtr_->detectPlatform()) {
64+
// populates the struct with AMD info
65+
const PlatformInfo& platformInfo = hipBinAMDPtr_->getPlatformInfo();
66+
platformVec_.push_back(platformInfo);
67+
hipBinBasePtrs_.push_back(hipBinAMDPtr_);
68+
platformDetected = true;
69+
} else if (hipBinNVPtr_->detectPlatform()) {
70+
// populates the struct with Nvidia info
71+
const PlatformInfo& platformInfo = hipBinNVPtr_->getPlatformInfo();
72+
platformVec_.push_back(platformInfo);
73+
hipBinBasePtrs_.push_back(hipBinNVPtr_);
74+
platformDetected = true;
75+
}
76+
// if no device is detected, then it is defaulted to AMD
77+
if (!platformDetected) {
78+
cout << "Device not supported - Defaulting to AMD" << endl;
79+
// populates the struct with AMD info
80+
const PlatformInfo& platformInfo = hipBinAMDPtr_->getPlatformInfo();
81+
platformVec_.push_back(platformInfo);
82+
hipBinBasePtrs_.push_back(hipBinAMDPtr_);
83+
}
84+
}
85+
86+
HipBin::~HipBin() {
87+
delete hipBinNVPtr_;
88+
delete hipBinAMDPtr_;
89+
// clearing the vector so no one accesses the pointers
90+
hipBinBasePtrs_.clear();
91+
// clearing the platform vector as the pointers are deleted
92+
platformVec_.clear();
93+
delete hipBinUtilPtr_;
94+
}
95+
96+
vector<PlatformInfo>& HipBin::getPlaformInfo() {
97+
return platformVec_; // Return the populated platform info.
98+
}
99+
100+
101+
vector<HipBinBase*>& HipBin::getHipBinPtrs() {
102+
return hipBinBasePtrs_; // Return the populated device pointers.
103+
}
104+
105+
106+
void HipBin::executeHipBin(string filename, int argc, char* argv[]) {
107+
if (hipBinUtilPtr_->substringPresent(filename, "hipconfig")) {
108+
executeHipConfig(argc, argv);
109+
} else if (hipBinUtilPtr_->substringPresent(filename, "hipcc")) {
110+
executeHipCC(argc, argv);
111+
} else {
112+
cout << "Command " << filename
113+
<< " not supported. Name the exe as hipconfig"
114+
<< " or hipcc and then try again ..." << endl;
115+
}
116+
}
117+
118+
119+
void HipBin::executeHipCC(int argc, char* argv[]) {
120+
cout << "HIPCC executable" <<endl;
121+
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
122+
vector<string> argvcc;
123+
for (int i = 0; i < argc; i++) {
124+
argvcc.push_back(argv[i]);
125+
}
126+
// 0th index points to the first platform detected.
127+
// In the near future this vector will contain mulitple devices
128+
platformPtrs.at(0)->executeHipCCCmd(argvcc);
129+
}
130+
131+
132+
void HipBin::executeHipConfig(int argc, char* argv[]) {
133+
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
134+
for (unsigned int j = 0; j < platformPtrs.size(); j++) {
135+
if (argc == 1) {
136+
platformPtrs.at(j)->printFull();
137+
}
138+
for (int i = 1; i < argc; ++i) {
139+
HipBinCommand cmd;
140+
cmd = platformPtrs.at(j)->gethipconfigCmd(argv[i]);
141+
switch (cmd) {
142+
case help: platformPtrs.at(j)->printUsage();
143+
break;
144+
case path: cout << platformPtrs.at(j)->getHipPath();
145+
break;
146+
case roccmpath: cout << platformPtrs.at(j)->getRoccmPath();
147+
break;
148+
case cpp_config: cout << platformPtrs.at(j)->getCppConfig();
149+
break;
150+
case compiler: cout << CompilerTypeStr((
151+
platformPtrs.at(j)->getPlatformInfo()).compiler);
152+
break;
153+
case platform: cout << PlatformTypeStr((
154+
platformPtrs.at(j)->getPlatformInfo()).platform);
155+
break;
156+
case runtime: cout << RuntimeTypeStr((
157+
platformPtrs.at(j)->getPlatformInfo()).runtime);
158+
break;
159+
case hipclangpath: cout << platformPtrs.at(j)->getCompilerPath();
160+
break;
161+
case full: platformPtrs.at(j)->printFull();
162+
break;
163+
case version: cout << platformPtrs.at(j)->getHipVersion();
164+
break;
165+
case check: platformPtrs.at(j)->checkHipconfig();
166+
break;
167+
case newline: platformPtrs.at(j)->printFull();
168+
cout << endl;
169+
break;
170+
default:
171+
platformPtrs.at(j)->printUsage();
172+
break;
173+
}
174+
}
175+
}
176+
}
177+
178+
//===========================================================================
179+
//===========================================================================
180+
181+
int main(int argc, char* argv[]) {
182+
fs::path filename(argv[0]);
183+
filename = filename.filename();
184+
185+
HipBin hipBin;
186+
hipBin.executeHipBin(filename.string(), argc, argv);
187+
}

0 commit comments

Comments
 (0)