Skip to content

Commit 1de52ff

Browse files
authored
Merge pull request #4 from ROCm-Developer-Tools/develop
Merge develop into main
2 parents 29ca18d + c41bcd6 commit 1de52ff

File tree

7 files changed

+2949
-3
lines changed

7 files changed

+2949
-3
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/README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,32 @@ Other environment variable controls:
3535

3636
### <a name="usage"></a> hipcc: usage
3737

38-
- WIP
38+
The built executables can be used the same way as the hipcc/hipconfig perl scripts.
39+
To use the newly built executables from the build folder use ./ in front of the executable name -
40+
Example:
41+
```shell
42+
./hipconfig --help
43+
./hipcc --help
44+
./hipcc --version
45+
./hipconfig --full
46+
```
47+
48+
when the excutables are copied to /opt/rocm/hip/bin or <anyfolder>hip/bin.
49+
The ./ is not required as the HIP path is added to the envirnoment variables list.
3950

4051
### <a name="building"></a> hipcc: building
4152

42-
- WIP
53+
```bash
54+
mkdir build
55+
cd build
56+
57+
cmake ..
58+
59+
make -j
60+
```
61+
62+
The hipcc and hipconfig executables are created in the current build folder. These executables need to be copied to /opt/rocm/hip/bin folder location. Packaging and installing will be handled in future releases.
4363

4464
### <a name="testing"></a> hipcc: testing
4565

46-
- WIP
66+
Currently hipcc/hipconfig executables are tested by building and executing HIP tests. Seperate tests for hipcc/hipconfig is currently not planned.

amd/hipcc/src/hipBin.cpp

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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+
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
121+
vector<string> argvcc;
122+
for (int i = 0; i < argc; i++) {
123+
argvcc.push_back(argv[i]);
124+
}
125+
// 0th index points to the first platform detected.
126+
// In the near future this vector will contain mulitple devices
127+
platformPtrs.at(0)->executeHipCCCmd(argvcc);
128+
}
129+
130+
131+
void HipBin::executeHipConfig(int argc, char* argv[]) {
132+
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
133+
for (unsigned int j = 0; j < platformPtrs.size(); j++) {
134+
if (argc == 1) {
135+
platformPtrs.at(j)->printFull();
136+
}
137+
for (int i = 1; i < argc; ++i) {
138+
HipBinCommand cmd;
139+
cmd = platformPtrs.at(j)->gethipconfigCmd(argv[i]);
140+
switch (cmd) {
141+
case help: platformPtrs.at(j)->printUsage();
142+
break;
143+
case path: cout << platformPtrs.at(j)->getHipPath();
144+
break;
145+
case roccmpath: cout << platformPtrs.at(j)->getRoccmPath();
146+
break;
147+
case cpp_config: cout << platformPtrs.at(j)->getCppConfig();
148+
break;
149+
case compiler: cout << CompilerTypeStr((
150+
platformPtrs.at(j)->getPlatformInfo()).compiler);
151+
break;
152+
case platform: cout << PlatformTypeStr((
153+
platformPtrs.at(j)->getPlatformInfo()).platform);
154+
break;
155+
case runtime: cout << RuntimeTypeStr((
156+
platformPtrs.at(j)->getPlatformInfo()).runtime);
157+
break;
158+
case hipclangpath: cout << platformPtrs.at(j)->getCompilerPath();
159+
break;
160+
case full: platformPtrs.at(j)->printFull();
161+
break;
162+
case version: cout << platformPtrs.at(j)->getHipVersion();
163+
break;
164+
case check: platformPtrs.at(j)->checkHipconfig();
165+
break;
166+
case newline: platformPtrs.at(j)->printFull();
167+
cout << endl;
168+
break;
169+
default:
170+
platformPtrs.at(j)->printUsage();
171+
break;
172+
}
173+
}
174+
}
175+
}
176+
177+
//===========================================================================
178+
//===========================================================================
179+
180+
int main(int argc, char* argv[]) {
181+
fs::path filename(argv[0]);
182+
filename = filename.filename();
183+
184+
HipBin hipBin;
185+
hipBin.executeHipBin(filename.string(), argc, argv);
186+
}

0 commit comments

Comments
 (0)