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
Don't use --genco. Fix mangled name trimming.
  • Loading branch information
AlexVlx committed May 10, 2019
commit f0304546944f3ef496c2586222d4c8c87d00a29a
48 changes: 30 additions & 18 deletions src/hiprtc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ struct _hiprtcProgram {

if (name.find("void ") == 0) name.erase(0, strlen("void "));

auto dx{name.find('<')};
if (dx != string::npos) {
auto dx{name.find_first_of("(<")};

if (dx == string::npos) return name;

if (name[dx] == '<') {
auto cnt{1u};
do {
++dx;
Expand All @@ -133,11 +136,7 @@ struct _hiprtcProgram {

name.erase(++dx);
}
else {
const auto dy{name.find('(')};

if (dy != string::npos) name.erase(dy);
}
else name.erase(dx);

return name;
}
Expand Down Expand Up @@ -172,6 +171,8 @@ struct _hiprtcProgram {
bool compile(const std::vector<std::string>& args,
const std::experimental::filesystem::path& program_folder)
{
using namespace ELFIO;
using namespace hip_impl;
using namespace redi;
using namespace std;

Expand All @@ -188,29 +189,40 @@ struct _hiprtcProgram {
if (compile.rdbuf()->exited() &&
compile.rdbuf()->status() != EXIT_SUCCESS) return false;

ifstream in{args.back()};
elf.resize(experimental::filesystem::file_size(args.back()));
in.read(elf.data(), elf.size());
elfio reader;
if (!reader.load(args.back())) return false;

const auto it{find_section_if(reader, [](const section* x) {
return x->get_name() == ".kernel";
})};

if (!it) return false;

Bundled_code_header h{it->get_data()};

if (bundles(h).empty()) return false;

elf.assign(bundles(h).back().blob.cbegin(),
bundles(h).back().blob.cend());

return true;
}

bool readLoweredNames()
{
using namespace ELFIO;
using namespace hip_impl;
using namespace std;

if (names.empty()) return true;

Bundled_code_header h{elf.data()};
istringstream blob{string{bundles(h).back().blob.cbegin(),
bundles(h).back().blob.cend()}};
istringstream blob{string{elf.cbegin(), elf.cend()}};

ELFIO::elfio reader;
elfio reader;

if (!reader.load(blob)) return false;

const auto it{find_section_if(reader, [](const ELFIO::section* x) {
const auto it{find_section_if(reader, [](const section* x) {
return x->get_type() == SHT_SYMTAB;
})};

Expand Down Expand Up @@ -423,12 +435,12 @@ namespace

if (dx == dy) continue;

x.replace(0, x.find('=', min(dx, dy)), "--targets");
x.replace(0, x.find('=', min(dx, dy)), "--amdgpu-target");
hasTarget = true;

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

Expand All @@ -453,7 +465,7 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram p, int n, const char** o)

const auto src{p->writeTemporaryFiles(tmp.path())};

vector<string> args{hipcc, "--genco"};
vector<string> args{hipcc, "-shared"};
if (n) args.insert(args.cend(), o, o + n);

handleTarget(args);
Expand Down