source: icGREP/icgrep-devel/icgrep/toolchain/NVPTXDriver.h @ 5462

Last change on this file since 5462 was 5462, checked in by lindanl, 2 years ago

Some fixes.

File size: 2.6 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef NVPTXDRIVER_H
8#define NVPTXDRIVER_H
9#include <string>
10#include <IR_Gen/FunctionTypeBuilder.h>
11#include <kernels/kernel.h>
12#include <kernels/streamset.h>
13
14namespace llvm { class ExecutionEngine; }
15namespace llvm { class Function; }
16namespace llvm { class Module; }
17namespace llvm { class TargetMachine; }
18namespace llvm { class formatted_raw_ostream; }
19namespace llvm { namespace cl { class OptionCategory; } }
20namespace kernel { class Kernel; }
21namespace kernel { class KernelBuilder; }
22namespace IDISA { class IDISA_Builder; }
23
24class NVPTXDriver {
25    friend class CBuilder;
26public:
27    NVPTXDriver(std::string && moduleName);
28
29    ~NVPTXDriver();
30   
31    const std::unique_ptr<kernel::KernelBuilder> & getBuilder();
32   
33    parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
34   
35    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
36   
37    kernel::Kernel * addKernelInstance(std::unique_ptr<kernel::Kernel> kb);
38   
39    void addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
40
41    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
42   
43    void generatePipelineIR();
44   
45    template <typename ExternalFunctionType>
46    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
47
48    void finalizeAndCompile(llvm::Function * mainFunc, std::string PTXFilename);
49   
50    void * getPointerToMain();
51
52protected:
53
54    llvm::Function * LinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
55
56private:
57    std::unique_ptr<llvm::LLVMContext>                      mContext;
58    llvm::Module * const                                    mMainModule;
59    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
60    llvm::TargetMachine *                                   mTarget;
61    llvm::ExecutionEngine *                                 mEngine;
62
63    std::vector<kernel::Kernel *>                           mPipeline;
64    // Owned kernels and buffers that will persist with this ParabixDriver instance.
65    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
66    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
67};
68
69#endif
Note: See TracBrowser for help on using the repository browser.