Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HIPRTC, glorious ersatz for NVRTC #1097

Merged
merged 20 commits into from
May 16, 2019
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c8ad49e
Add ersatz for NVRTC.
AlexVlx Apr 30, 2019
14ff2f7
Fix extraneous paren and use correct namespace.
AlexVlx Apr 30, 2019
a13dcd3
Use lowerCamelCase (yuck, yuck) consistently.
AlexVlx Apr 30, 2019
a26f81e
Link against FS when building hiprtc lib.
AlexVlx Apr 30, 2019
6d92e95
Correctly mark Manipulators. Fix dual compile.
AlexVlx Apr 30, 2019
4413c5c
Add unit tests. Extend HIT to accept linker options.
AlexVlx Apr 30, 2019
e4e4892
Merge branch 'master' of https://github.com/ROCm-Developer-Tools/HIP …
AlexVlx Apr 30, 2019
e01a715
Merge branch 'master' of https://github.com/ROCm-Developer-Tools/HIP …
AlexVlx May 7, 2019
6f32161
Make sure the HIPRTC library is installed.
AlexVlx May 7, 2019
5f0bb14
Better logging. Try to auto-detect the target.
AlexVlx May 7, 2019
7f70758
Stop specifying the target explicitly.
AlexVlx May 7, 2019
8cd6302
Merge branch 'master' of https://github.com/ROCm-Developer-Tools/HIP …
AlexVlx May 9, 2019
88e4605
Add missing flavour of `hipModuleLaunchKernel`.
AlexVlx May 9, 2019
bc69066
Program was already destroyed.
AlexVlx May 9, 2019
a0e6226
Merge branch 'master' of https://github.com/ROCm-Developer-Tools/HIP …
AlexVlx May 10, 2019
f030454
Don't use `--genco`. Fix mangled name trimming.
AlexVlx May 10, 2019
3d8f2e7
Re-sync with upstream.
AlexVlx May 14, 2019
800673e
Fix HIPRTC breakage due to upstream noise.
AlexVlx May 14, 2019
2225942
[dtests] Replace RUN -> TEST in hiprtc tests
mangupta May 15, 2019
4995119
[hit] Set HIP_PATH to HIP_ROOT_DIR for all tests
mangupta May 16, 2019
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
Prev Previous commit
Next Next commit
Better logging. Try to auto-detect the target.
  • Loading branch information
AlexVlx committed May 7, 2019
commit 5f0bb143bd396aa86892fb9498b0e06f6733a3a8
62 changes: 53 additions & 9 deletions src/hiprtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ THE SOFTWARE.

#include "../lpl_ca/pstreams/pstream.h"

#include <hsa/hsa.h>

#include <cxxabi.h>

#include <algorithm>
Expand Down Expand Up @@ -170,17 +172,21 @@ struct _hiprtcProgram {
bool compile(const std::vector<std::string>& args,
const std::experimental::filesystem::path& program_folder)
{
using namespace redi;
using namespace std;

redi::pstream compile{args.front(), args};

compile.close();
ipstream compile{args.front(), args, pstreambuf::pstderr};

ostringstream{log} << compile.rdbuf();
constexpr const auto tmp_size{1024u};
char tmp[tmp_size]{};
while (!compile.eof()) {
log.append(tmp, tmp + compile.readsome(tmp, tmp_size));
}

if (compile.rdbuf()->status() != EXIT_SUCCESS) return false;
compile.close();

cerr << log << endl;
if (compile.rdbuf()->exited() &&
compile.rdbuf()->status() != EXIT_SUCCESS) return false;

ifstream in{args.back()};
elf.resize(experimental::filesystem::file_size(args.back()));
Expand Down Expand Up @@ -364,7 +370,45 @@ namespace hip_impl

namespace
{
constexpr const char defaultTarget[]{"--targets=gfx900"};
const std::string& defaultTarget()
{
using namespace std;

static string r{"gfx900"};
static once_flag f{};

call_once(f, []() {
static hsa_agent_t a{};
hsa_iterate_agents([](hsa_agent_t x, void*) {
hsa_device_type_t t{};
hsa_agent_get_info(x, HSA_AGENT_INFO_DEVICE, &t);

if (t != HSA_DEVICE_TYPE_GPU) return HSA_STATUS_SUCCESS;

a = x;

return HSA_STATUS_INFO_BREAK;
}, nullptr);

if (!a.handle) return;

hsa_agent_iterate_isas(a, [](hsa_isa_t x, void*){
uint32_t n{};
hsa_isa_get_info_alt(x, HSA_ISA_INFO_NAME_LENGTH, &n);

if (n == 0) return HSA_STATUS_SUCCESS;

r.resize(n);
hsa_isa_get_info_alt(x, HSA_ISA_INFO_NAME, &r[0]);

r.erase(0, r.find("gfx"));

return HSA_STATUS_INFO_BREAK;
}, nullptr);
});

return r;
}

inline
void handleTarget(std::vector<std::string>& args)
Expand All @@ -384,7 +428,7 @@ namespace

break;
}
if (!hasTarget) args.emplace_back(defaultTarget);
if (!hasTarget) args.push_back("--targets=" + defaultTarget());
}
} // Unnamed namespace.

Expand Down Expand Up @@ -490,7 +534,7 @@ hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram p, std::size_t* sz)
if (!isValidProgram(p)) return HIPRTC_ERROR_INVALID_PROGRAM;
if (!p->compiled) return HIPRTC_ERROR_INVALID_PROGRAM;

*sz = p->log.size() + 1;
*sz = p->log.empty() ? 0 : p->log.size() + 1;

return HIPRTC_SUCCESS;
}
Expand Down