Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
DispatcherCUDA.h
Go to the documentation of this file.
1#ifndef PROTEUS_FRONTEND_DISPATCHER_CUDA_H
2#define PROTEUS_FRONTEND_DISPATCHER_CUDA_H
3
4#if PROTEUS_ENABLE_CUDA
5
6#include "proteus/Error.h"
10
11#include <llvm/Bitcode/BitcodeReader.h>
12#include <llvm/Linker/Linker.h>
13#include <llvm/Support/MemoryBuffer.h>
14
15namespace proteus {
16
17class DispatcherCUDA : public DispatcherDevice<JitEngineDeviceCUDA> {
18public:
19 static DispatcherCUDA &instance() {
20 static DispatcherCUDA D{"DispatcherCUDA", JitEngineDeviceCUDA::instance()};
21 return D;
22 }
23
24 DispatcherCUDA(const std::string &Label, JitEngineDeviceCUDA &Jit)
25 : DispatcherDevice(Label, TargetModelType::CUDA, Jit) {}
26
27protected:
28 void linkDeviceLibraries(Module &M) override {
29 TIMESCOPE(DispatcherCUDA, linkDeviceLibraries);
30 const auto &Toolchain = resolveCUDAToolchain();
31 auto LibDeviceBuffer = llvm::MemoryBuffer::getFile(Toolchain.LibDevicePath);
32 if (!LibDeviceBuffer || !LibDeviceBuffer.get())
33 reportFatalError("DispatchCUDA: failed to read libdevice from " +
34 Toolchain.LibDevicePath + " (" + Toolchain.Origin + ")");
35
36 auto LibDeviceModule = llvm::parseBitcodeFile(
37 LibDeviceBuffer->get()->getMemBufferRef(), M.getContext());
38 if (!LibDeviceModule)
39 reportFatalError("DispatchCUDA: failed to parse libdevice from " +
40 Toolchain.LibDevicePath + " (" + Toolchain.Origin + ")");
41
42 llvm::Linker Linker(M);
43 Linker.linkInModule(std::move(LibDeviceModule.get()),
44 llvm::Linker::Flags::LinkOnlyNeeded);
45 }
46};
47
48} // namespace proteus
49
50#endif
51
52#endif // PROTEUS_FRONTEND_DISPATCHER_CUDA_H
#define TIMESCOPE(...)
Definition TimeTracing.h:66
Definition MemoryCache.h:27
TargetModelType
Definition TargetModel.h:8
void reportFatalError(const llvm::Twine &Reason, const char *FILE, unsigned Line)
Definition Error.cpp:14
const ResolvedCUDAToolchain & resolveCUDAToolchain()
Definition CUDAToolchain.cpp:245