Skip to content

Commit

Permalink
Merge pull request #4 from ROCm-Developer-Tools/develop
Browse files Browse the repository at this point in the history
Merge develop into main
  • Loading branch information
searlmc1 authored Dec 6, 2021
2 parents 29ca18d + c41bcd6 commit 1de52ff
Show file tree
Hide file tree
Showing 7 changed files with 2,949 additions and 3 deletions.
22 changes: 22 additions & 0 deletions amd/hipcc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.16.3)
project (hipcc)

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

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

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

set(HIP_VERSION_MAJOR 4 PARENT_SCOPE)
set(HIP_VERSION_MINOR 4 PARENT_SCOPE)
set(HIP_VERSION_PATCH 4 PARENT_SCOPE)
26 changes: 23 additions & 3 deletions amd/hipcc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,32 @@ Other environment variable controls:

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

- WIP
The built executables can be used the same way as the hipcc/hipconfig perl scripts.
To use the newly built executables from the build folder use ./ in front of the executable name -
Example:
```shell
./hipconfig --help
./hipcc --help
./hipcc --version
./hipconfig --full
```

when the excutables are copied to /opt/rocm/hip/bin or <anyfolder>hip/bin.
The ./ is not required as the HIP path is added to the envirnoment variables list.

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

- WIP
```bash
mkdir build
cd build

cmake ..

make -j
```

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.

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

- WIP
Currently hipcc/hipconfig executables are tested by building and executing HIP tests. Seperate tests for hipcc/hipconfig is currently not planned.
186 changes: 186 additions & 0 deletions amd/hipcc/src/hipBin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
Copyright (c) 2021 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.
*/

#include "hipBin_util.h"
#include "hipBin_amd.h"
#include "hipBin_nvidia.h"
#include <vector>
#include <string>

class HipBinUtil;
class HipBinBase;
class HipBinAmd;
class HipBinNvidia;
class HipBin;


class HipBin {
private:
HipBinUtil* hipBinUtilPtr_;
vector<HipBinBase*> hipBinBasePtrs_;
vector<PlatformInfo> platformVec_;
HipBinBase* hipBinNVPtr_;
HipBinBase* hipBinAMDPtr_;

public:
HipBin();
~HipBin();
vector<HipBinBase*>& getHipBinPtrs();
vector<PlatformInfo>& getPlaformInfo();
void executeHipBin(string filename, int argc, char* argv[]);
void executeHipConfig(int argc, char* argv[]);
void executeHipCC(int argc, char* argv[]);
};


// Implementation ================================================
//===========================================================================

HipBin::HipBin() {
hipBinUtilPtr_ = hipBinUtilPtr_->getInstance();
hipBinNVPtr_ = new HipBinNvidia();
hipBinAMDPtr_ = new HipBinAmd();
bool platformDetected = false;
if (hipBinAMDPtr_->detectPlatform()) {
// populates the struct with AMD info
const PlatformInfo& platformInfo = hipBinAMDPtr_->getPlatformInfo();
platformVec_.push_back(platformInfo);
hipBinBasePtrs_.push_back(hipBinAMDPtr_);
platformDetected = true;
} else if (hipBinNVPtr_->detectPlatform()) {
// populates the struct with Nvidia info
const PlatformInfo& platformInfo = hipBinNVPtr_->getPlatformInfo();
platformVec_.push_back(platformInfo);
hipBinBasePtrs_.push_back(hipBinNVPtr_);
platformDetected = true;
}
// if no device is detected, then it is defaulted to AMD
if (!platformDetected) {
cout << "Device not supported - Defaulting to AMD" << endl;
// populates the struct with AMD info
const PlatformInfo& platformInfo = hipBinAMDPtr_->getPlatformInfo();
platformVec_.push_back(platformInfo);
hipBinBasePtrs_.push_back(hipBinAMDPtr_);
}
}

HipBin::~HipBin() {
delete hipBinNVPtr_;
delete hipBinAMDPtr_;
// clearing the vector so no one accesses the pointers
hipBinBasePtrs_.clear();
// clearing the platform vector as the pointers are deleted
platformVec_.clear();
delete hipBinUtilPtr_;
}

vector<PlatformInfo>& HipBin::getPlaformInfo() {
return platformVec_; // Return the populated platform info.
}


vector<HipBinBase*>& HipBin::getHipBinPtrs() {
return hipBinBasePtrs_; // Return the populated device pointers.
}


void HipBin::executeHipBin(string filename, int argc, char* argv[]) {
if (hipBinUtilPtr_->substringPresent(filename, "hipconfig")) {
executeHipConfig(argc, argv);
} else if (hipBinUtilPtr_->substringPresent(filename, "hipcc")) {
executeHipCC(argc, argv);
} else {
cout << "Command " << filename
<< " not supported. Name the exe as hipconfig"
<< " or hipcc and then try again ..." << endl;
}
}


void HipBin::executeHipCC(int argc, char* argv[]) {
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
vector<string> argvcc;
for (int i = 0; i < argc; i++) {
argvcc.push_back(argv[i]);
}
// 0th index points to the first platform detected.
// In the near future this vector will contain mulitple devices
platformPtrs.at(0)->executeHipCCCmd(argvcc);
}


void HipBin::executeHipConfig(int argc, char* argv[]) {
vector<HipBinBase*>& platformPtrs = getHipBinPtrs();
for (unsigned int j = 0; j < platformPtrs.size(); j++) {
if (argc == 1) {
platformPtrs.at(j)->printFull();
}
for (int i = 1; i < argc; ++i) {
HipBinCommand cmd;
cmd = platformPtrs.at(j)->gethipconfigCmd(argv[i]);
switch (cmd) {
case help: platformPtrs.at(j)->printUsage();
break;
case path: cout << platformPtrs.at(j)->getHipPath();
break;
case roccmpath: cout << platformPtrs.at(j)->getRoccmPath();
break;
case cpp_config: cout << platformPtrs.at(j)->getCppConfig();
break;
case compiler: cout << CompilerTypeStr((
platformPtrs.at(j)->getPlatformInfo()).compiler);
break;
case platform: cout << PlatformTypeStr((
platformPtrs.at(j)->getPlatformInfo()).platform);
break;
case runtime: cout << RuntimeTypeStr((
platformPtrs.at(j)->getPlatformInfo()).runtime);
break;
case hipclangpath: cout << platformPtrs.at(j)->getCompilerPath();
break;
case full: platformPtrs.at(j)->printFull();
break;
case version: cout << platformPtrs.at(j)->getHipVersion();
break;
case check: platformPtrs.at(j)->checkHipconfig();
break;
case newline: platformPtrs.at(j)->printFull();
cout << endl;
break;
default:
platformPtrs.at(j)->printUsage();
break;
}
}
}
}

//===========================================================================
//===========================================================================

int main(int argc, char* argv[]) {
fs::path filename(argv[0]);
filename = filename.filename();

HipBin hipBin;
hipBin.executeHipBin(filename.string(), argc, argv);
}
Loading

0 comments on commit 1de52ff

Please sign in to comment.