|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 | //
|
9 |
| -// This utility is used to launch standard programs onto the GPU in conjunction |
10 |
| -// with the LLVM 'libc' project. It is designed to mimic a standard emulator |
11 |
| -// workflow, allowing for unit tests to be run on the GPU directly. |
| 9 | +// This file opens a device image passed on the command line and passes it to |
| 10 | +// one of the loader implementations for launch. |
12 | 11 | //
|
13 | 12 | //===----------------------------------------------------------------------===//
|
14 | 13 |
|
15 |
| -#include "llvm-gpu-loader.h" |
| 14 | +#include "Loader.h" |
16 | 15 |
|
17 | 16 | #include "llvm/BinaryFormat/Magic.h"
|
18 |
| -#include "llvm/Object/ELF.h" |
19 |
| -#include "llvm/Object/ELFObjectFile.h" |
20 | 17 | #include "llvm/Support/CommandLine.h"
|
21 | 18 | #include "llvm/Support/Error.h"
|
22 | 19 | #include "llvm/Support/FileSystem.h"
|
23 | 20 | #include "llvm/Support/MemoryBuffer.h"
|
24 | 21 | #include "llvm/Support/Path.h"
|
25 | 22 | #include "llvm/Support/Signals.h"
|
26 | 23 | #include "llvm/Support/WithColor.h"
|
27 |
| -#include "llvm/TargetParser/Triple.h" |
28 | 24 |
|
29 | 25 | #include <cerrno>
|
30 | 26 | #include <cstdio>
|
@@ -129,40 +125,12 @@ int main(int argc, const char **argv, const char **envp) {
|
129 | 125 | strerror(errno)));
|
130 | 126 | }
|
131 | 127 |
|
| 128 | + // Drop the loader from the program arguments. |
132 | 129 | LaunchParameters params{threads_x, threads_y, threads_z,
|
133 | 130 | blocks_x, blocks_y, blocks_z};
|
134 |
| - |
135 |
| - Expected<llvm::object::ELF64LEObjectFile> elf_or_err = |
136 |
| - llvm::object::ELF64LEObjectFile::create(image); |
137 |
| - if (!elf_or_err) |
138 |
| - report_error(std::move(elf_or_err.takeError())); |
139 |
| - |
140 |
| - int ret = 1; |
141 |
| - if (elf_or_err->getArch() == Triple::amdgcn) { |
142 |
| -#ifdef AMDHSA_SUPPORT |
143 |
| - ret = load_amdhsa(new_argv.size(), new_argv.data(), envp, |
144 |
| - const_cast<char *>(image.getBufferStart()), |
145 |
| - image.getBufferSize(), params, print_resource_usage); |
146 |
| -#else |
147 |
| - report_error(createStringError( |
148 |
| - "Unsupported architecture; %s", |
149 |
| - Triple::getArchTypeName(elf_or_err->getArch()).bytes_begin())); |
150 |
| -#endif |
151 |
| - } else if (elf_or_err->getArch() == Triple::nvptx64) { |
152 |
| -#ifdef NVPTX_SUPPORT |
153 |
| - ret = load_nvptx(new_argv.size(), new_argv.data(), envp, |
154 |
| - const_cast<char *>(image.getBufferStart()), |
155 |
| - image.getBufferSize(), params, print_resource_usage); |
156 |
| -#else |
157 |
| - report_error(createStringError( |
158 |
| - "Unsupported architecture; %s", |
159 |
| - Triple::getArchTypeName(elf_or_err->getArch()).bytes_begin())); |
160 |
| -#endif |
161 |
| - } else { |
162 |
| - report_error(createStringError( |
163 |
| - "Unsupported architecture; %s", |
164 |
| - Triple::getArchTypeName(elf_or_err->getArch()).bytes_begin())); |
165 |
| - } |
| 131 | + int ret = load(new_argv.size(), new_argv.data(), envp, |
| 132 | + const_cast<char *>(image.getBufferStart()), |
| 133 | + image.getBufferSize(), params, print_resource_usage); |
166 | 134 |
|
167 | 135 | if (no_parallelism) {
|
168 | 136 | if (flock(fd, LOCK_UN) == -1)
|
|
0 commit comments