1 #ifndef HALIDE_CODEGEN_GPU_HOST_H
2 #define HALIDE_CODEGEN_GPU_HOST_H
3 
4 /** \file
5  * Defines the code-generator for producing GPU host code
6  */
7 
8 #include <map>
9 #include <string>
10 
11 #include "CodeGen_ARM.h"
12 #include "CodeGen_MIPS.h"
13 #include "CodeGen_PowerPC.h"
14 #include "CodeGen_RISCV.h"
15 #include "CodeGen_WebAssembly.h"
16 #include "CodeGen_X86.h"
17 #include "IR.h"
18 
19 namespace Halide {
20 namespace Internal {
21 
22 struct CodeGen_GPU_Dev;
23 struct GPU_Argument;
24 
25 /** A code generator that emits GPU code from a given Halide stmt. */
26 template<typename CodeGen_CPU>
27 class CodeGen_GPU_Host : public CodeGen_CPU {
28 public:
29     /** Create a GPU code generator. GPU target is selected via
30      * CodeGen_GPU_Options. Processor features can be enabled using the
31      * appropriate flags from Target */
32     CodeGen_GPU_Host(Target);
33 
34     ~CodeGen_GPU_Host() override;
35 
36 protected:
37     void compile_func(const LoweredFunc &func, const std::string &simple_name, const std::string &extern_name) override;
38 
39     /** Declare members of the base class that must exist to help the
40      * compiler do name lookup. Annoying but necessary, because the
41      * compiler doesn't know that CodeGen_CPU will in fact inherit
42      * from CodeGen for every instantiation of this template. */
43     using CodeGen_CPU::allocations;
44     using CodeGen_CPU::builder;
45     using CodeGen_CPU::codegen;
46     using CodeGen_CPU::context;
47     using CodeGen_CPU::create_alloca_at_entry;
48     using CodeGen_CPU::function;
49     using CodeGen_CPU::get_user_context;
50     using CodeGen_CPU::halide_buffer_t_type;
51     using CodeGen_CPU::i16_t;
52     using CodeGen_CPU::i32_t;
53     using CodeGen_CPU::i64_t;
54     using CodeGen_CPU::i8_t;
55     using CodeGen_CPU::init_module;
56     using CodeGen_CPU::llvm_type_of;
57     using CodeGen_CPU::module;
58     using CodeGen_CPU::register_destructor;
59     using CodeGen_CPU::sym_exists;
60     using CodeGen_CPU::sym_get;
61     using CodeGen_CPU::sym_pop;
62     using CodeGen_CPU::sym_push;
63     using CodeGen_CPU::target;
64     using CodeGen_CPU::type_t_type;
65     using CodeGen_CPU::visit;
66 
67     /** Nodes for which we need to override default behavior for the GPU runtime */
68     // @{
69     void visit(const For *) override;
70     // @}
71 
72     std::string function_name;
73 
74     llvm::Value *get_module_state(const std::string &api_unique_name,
75                                   bool create = true);
76 
77 private:
78     /** Child code generator for device kernels. */
79     std::map<DeviceAPI, CodeGen_GPU_Dev *> cgdev;
80 };
81 
82 }  // namespace Internal
83 }  // namespace Halide
84 
85 #endif
86