Halide
CodeGen_D3D12Compute_Dev.h
Go to the documentation of this file.
1 #ifndef HALIDE_CODEGEN_D3D12_COMPUTE_DEV_H
2 #define HALIDE_CODEGEN_D3D12_COMPUTE_DEV_H
3 
4 /** \file
5  * Defines the code-generator for producing D3D12-compatible HLSL kernel code
6  */
7 
8 #include <sstream>
9 
10 #include "CodeGen_C.h"
11 #include "CodeGen_GPU_Dev.h"
12 #include "Target.h"
13 
14 namespace Halide {
15 namespace Internal {
16 
18 public:
20 
21  /** Compile a GPU kernel into the module. This may be called many times
22  * with different kernels, which will all be accumulated into a single
23  * source module shared by a given Halide pipeline. */
24  void add_kernel(Stmt stmt,
25  const std::string &name,
26  const std::vector<DeviceArgument> &args) override;
27 
28  /** (Re)initialize the GPU kernel module. This is separate from compile,
29  * since a GPU device module will often have many kernels compiled into it
30  * for a single pipeline. */
31  void init_module() override;
32 
33  std::vector<char> compile_to_src() override;
34 
35  std::string get_current_kernel_name() override;
36 
37  void dump() override;
38 
39  std::string print_gpu_name(const std::string &name) override;
40 
41  std::string api_unique_name() override {
42  return "d3d12compute";
43  }
44 
45 protected:
46  friend struct StoragePackUnpack;
47 
49  public:
50  CodeGen_D3D12Compute_C(std::ostream &s, Target t)
51  : CodeGen_C(s, t) {
52  }
53  void add_kernel(Stmt stmt,
54  const std::string &name,
55  const std::vector<DeviceArgument> &args);
56 
57  protected:
58  friend struct StoragePackUnpack;
59 
60  std::string print_type(Type type, AppendSpaceIfNeeded space_option = DoNotAppendSpace) override;
61  std::string print_storage_type(Type type);
62  std::string print_type_maybe_storage(Type type, bool storage, AppendSpaceIfNeeded space);
63  std::string print_reinterpret(Type type, const Expr &e) override;
64  std::string print_extern_call(const Call *op) override;
65 
66  std::string print_vanilla_cast(Type type, const std::string &value_expr);
67  std::string print_reinforced_cast(Type type, const std::string &value_expr);
68  std::string print_cast(Type target_type, Type source_type, const std::string &value_expr);
69  std::string print_reinterpret_cast(Type type, const std::string &value_expr);
70 
71  std::string print_assignment(Type t, const std::string &rhs) override;
72 
73  using CodeGen_C::visit;
74  void visit(const Evaluate *op) override;
75  void visit(const Min *) override;
76  void visit(const Max *) override;
77  void visit(const Div *) override;
78  void visit(const Mod *) override;
79  void visit(const For *) override;
80  void visit(const Ramp *op) override;
81  void visit(const Broadcast *op) override;
82  void visit(const Call *op) override;
83  void visit(const Load *op) override;
84  void visit(const Store *op) override;
85  void visit(const Select *op) override;
86  void visit(const Allocate *op) override;
87  void visit(const Free *op) override;
88  void visit(const Cast *op) override;
89  void visit(const Atomic *op) override;
90  void visit(const FloatImm *op) override;
91 
93  };
94 
95  std::ostringstream src_stream;
96  std::string cur_kernel_name;
98 };
99 
100 } // namespace Internal
101 } // namespace Halide
102 
103 #endif
Halide::Internal::CodeGen_D3D12Compute_Dev::print_gpu_name
std::string print_gpu_name(const std::string &name) override
Returns the specified name transformed by the variable naming rules for the GPU language backend.
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::StoragePackUnpack
friend struct StoragePackUnpack
Definition: CodeGen_D3D12Compute_Dev.h:58
Halide::Internal::Allocate
Allocate a scratch area called with the given name, type, and size.
Definition: IR.h:352
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_type_maybe_storage
std::string print_type_maybe_storage(Type type, bool storage, AppendSpaceIfNeeded space)
Halide::Internal::CodeGen_D3D12Compute_Dev::src_stream
std::ostringstream src_stream
Definition: CodeGen_D3D12Compute_Dev.h:95
Halide::Internal::CodeGen_D3D12Compute_Dev::api_unique_name
std::string api_unique_name() override
This routine returns the GPU API name that is combined into runtime routine names to ensure each GPU ...
Definition: CodeGen_D3D12Compute_Dev.h:41
CodeGen_C.h
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_reinterpret_cast
std::string print_reinterpret_cast(Type type, const std::string &value_expr)
Halide::Internal::CodeGen_C::visit
void visit(const Variable *) override
Halide::Internal::For
A for loop.
Definition: IR.h:698
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_type
std::string print_type(Type type, AppendSpaceIfNeeded space_option=DoNotAppendSpace) override
Emit the C name for a halide type.
Halide::Internal::CodeGen_D3D12Compute_Dev::compile_to_src
std::vector< char > compile_to_src() override
Halide::Internal::FloatImm
Floating point constants.
Definition: Expr.h:234
Halide::Internal::Broadcast
A vector with 'lanes' elements, in which every element is 'value'.
Definition: IR.h:241
Halide::Internal::Div
The ratio of two expressions.
Definition: IR.h:65
Target.h
Halide::Internal::Scope
A common pattern when traversing Halide IR is that you need to keep track of stuff when you find a Le...
Definition: ModulusRemainder.h:17
Halide::Internal::Cast
The actual IR nodes begin here.
Definition: IR.h:29
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_reinforced_cast
std::string print_reinforced_cast(Type type, const std::string &value_expr)
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::add_kernel
void add_kernel(Stmt stmt, const std::string &name, const std::vector< DeviceArgument > &args)
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition: Expr.h:409
Halide::Internal::CodeGen_C
This class emits C++ code equivalent to a halide Stmt.
Definition: CodeGen_C.h:24
Halide::Internal::CodeGen_D3D12Compute_Dev::cur_kernel_name
std::string cur_kernel_name
Definition: CodeGen_D3D12Compute_Dev.h:96
Halide::Internal::CodeGen_D3D12Compute_Dev::init_module
void init_module() override
(Re)initialize the GPU kernel module.
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_Dev
CodeGen_D3D12Compute_Dev(Target target)
Halide::Internal::Load
Load a value from a named symbol if predicate is true.
Definition: IR.h:199
Halide::Internal::Free
Free the resources associated with the given buffer.
Definition: IR.h:388
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Internal::CodeGen_C::AppendSpaceIfNeeded
AppendSpaceIfNeeded
Definition: CodeGen_C.h:89
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::Max
The greater of two values.
Definition: IR.h:94
Halide::Internal::CodeGen_GPU_Dev
A code generator that emits GPU code from a given Halide stmt.
Definition: CodeGen_GPU_Dev.h:17
Halide::Internal::CodeGen_D3D12Compute_Dev::StoragePackUnpack
friend struct StoragePackUnpack
Definition: CodeGen_D3D12Compute_Dev.h:46
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::CodeGen_D3D12Compute_C
CodeGen_D3D12Compute_C(std::ostream &s, Target t)
Definition: CodeGen_D3D12Compute_Dev.h:50
Halide::Internal::CodeGen_D3D12Compute_Dev::d3d12compute_c
CodeGen_D3D12Compute_C d3d12compute_c
Definition: CodeGen_D3D12Compute_Dev.h:97
Halide::Internal::Ramp
A linear ramp vector node.
Definition: IR.h:229
CodeGen_GPU_Dev.h
Halide::Internal::Evaluate
Evaluate and discard an expression, presumably because it has some side-effect.
Definition: IR.h:450
Halide::Internal::Store
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition: IR.h:315
Halide::Internal::Min
The lesser of two values.
Definition: IR.h:85
Halide::Internal::Mod
The remainder of a / b.
Definition: IR.h:76
Halide::Internal::CodeGen_D3D12Compute_Dev::add_kernel
void add_kernel(Stmt stmt, const std::string &name, const std::vector< DeviceArgument > &args) override
Compile a GPU kernel into the module.
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_cast
std::string print_cast(Type target_type, Type source_type, const std::string &value_expr)
Halide::Internal::Call
A function call.
Definition: IR.h:464
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_storage_type
std::string print_storage_type(Type type)
Halide::Internal::CodeGen_D3D12Compute_Dev::dump
void dump() override
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_reinterpret
std::string print_reinterpret(Type type, const Expr &e) override
Emit a statement to reinterpret an expression as another type.
Halide::Internal::Select
A ternary operator.
Definition: IR.h:186
Halide::Internal::CodeGen_D3D12Compute_Dev
Definition: CodeGen_D3D12Compute_Dev.h:17
Halide::Output::stmt
@ stmt
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C
Definition: CodeGen_D3D12Compute_Dev.h:48
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::Atomic
Lock all the Store nodes in the body statement.
Definition: IR.h:809
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::visit
void visit(const Evaluate *op) override
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_vanilla_cast
std::string print_vanilla_cast(Type type, const std::string &value_expr)
Halide::Internal::CodeGen_D3D12Compute_Dev::get_current_kernel_name
std::string get_current_kernel_name() override
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_extern_call
std::string print_extern_call(const Call *op) override
Bottleneck to allow customization of calls to generic Extern/PureExtern calls.
Halide::Internal::CodeGen_C::DoNotAppendSpace
@ DoNotAppendSpace
Definition: CodeGen_C.h:90
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::print_assignment
std::string print_assignment(Type t, const std::string &rhs) override
Emit an SSA-style assignment, and set id to the freshly generated name.
Halide::Internal::CodeGen_D3D12Compute_Dev::CodeGen_D3D12Compute_C::groupshared_allocations
Scope groupshared_allocations
Definition: CodeGen_D3D12Compute_Dev.h:92
Halide::Target
A struct representing a target machine and os to generate code for.
Definition: Target.h:19