docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
gpu_reduce_dispatcher.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <string>
5#include <vector>
6
11#include "sdfg/codegen/utils.h"
15#include "sdfg/types/type.h"
16
17namespace sdfg {
18namespace gpu {
19
49protected:
51
52 // --- Backend policy hooks -------------------------------------------------
53
55 virtual std::string schedule_value() const = 0;
56
58 virtual codegen::TargetType target_type() const = 0;
59
61 virtual std::unique_ptr<codegen::LanguageExtension> create_device_language_extension() const = 0;
62
64 virtual bool is_device_pointer_storage(const types::StorageType& storage) const = 0;
65
67 virtual std::string kernel_file_extension() const = 0;
68
70 virtual void emit_kernel_includes(codegen::CodeSnippetFactory& library_snippet_factory) const = 0;
71
73 virtual void emit_library_preamble(codegen::PrettyPrinter& library_stream) const = 0;
74
76 virtual void emit_kernel_call(
77 codegen::PrettyPrinter& main_stream,
78 const std::string& kernel_name,
79 symbolic::Expression& num_blocks,
80 symbolic::Expression& block_size,
81 std::vector<std::string>& arguments_device
82 ) = 0;
83
84 // --- Shared implementation ------------------------------------------------
85
91
93 codegen::PrettyPrinter& stream, const std::string& kernel_name, std::vector<std::string>& arguments_declaration
94 );
95
105 codegen::CodeSnippetFactory& library_snippet_factory,
106 codegen::PrettyPrinter& library_stream,
107 GPUDimension dimension,
108 bool declare_scope_variables,
109 std::vector<std::string>& scope_variables
110 );
111
117 codegen::PrettyPrinter& library_stream,
118 codegen::CodeSnippetFactory& library_snippet_factory,
120 );
121
122public:
124 codegen::LanguageExtension& language_extension,
126 analysis::AnalysisManager& analysis_manager,
128 codegen::InstrumentationPlan& instrumentation_plan,
129 codegen::ArgCapturePlan& arg_capture_plan
130 );
131
133 codegen::PrettyPrinter& main_stream,
134 codegen::PrettyPrinter& globals_stream,
135 codegen::CodeSnippetFactory& library_snippet_factory
136 ) override;
137
139};
140
141} // namespace gpu
142} // namespace sdfg
Definition structured_sdfg.h:30
Definition analysis.h:53
Definition arg_capture_plan.h:36
Originally started out as a handler for additional source files, like hardware-accelerator kernels th...
Definition code_snippet_factory.h:69
Definition instrumentation_info.h:37
Definition instrumentation_plan.h:26
Definition language_extension.h:39
Base class for dispatching control flow nodes to code.
Definition node_dispatcher.h:41
Definition utils.h:16
virtual codegen::TargetType target_type() const =0
Target type used for instrumentation info.
virtual void emit_kernel_includes(codegen::CodeSnippetFactory &library_snippet_factory) const =0
Emit the backend include directives required by the generated kernel.
virtual void emit_library_preamble(codegen::PrettyPrinter &library_stream) const =0
Emit any extra preamble at the top of the kernel translation unit.
void dispatch_node(codegen::PrettyPrinter &main_stream, codegen::PrettyPrinter &globals_stream, codegen::CodeSnippetFactory &library_snippet_factory) override
void dispatch_atomic_merge(codegen::PrettyPrinter &library_stream, codegen::CodeSnippetFactory &library_snippet_factory, const structured_control_flow::ReductionInfo &reduction)
Emit the device-side helper(s) and the atomic merge statement that combines a thread's private partia...
virtual void emit_kernel_call(codegen::PrettyPrinter &main_stream, const std::string &kernel_name, symbolic::Expression &num_blocks, symbolic::Expression &block_size, std::vector< std::string > &arguments_device)=0
Emit the host-side kernel launch.
virtual bool is_device_pointer_storage(const types::StorageType &storage) const =0
True if storage designates a device-resident generic pointer for this backend.
virtual std::string schedule_value() const =0
Schedule value string identifying this backend's GPU schedule ("CUDA"/"ROCM").
virtual std::string kernel_file_extension() const =0
File extension for the kernel translation unit ("cu"/"rocm.cpp").
virtual std::unique_ptr< codegen::LanguageExtension > create_device_language_extension() const =0
Create the backend device-code language extension (CUDA/HIP).
void dispatch_reduce_core(codegen::CodeSnippetFactory &library_snippet_factory, codegen::PrettyPrinter &library_stream, GPUDimension dimension, bool declare_scope_variables, std::vector< std::string > &scope_variables)
Emit the privatize + grid-stride reduce loop + atomic merge into the given (device) stream,...
GPUReduceDispatcher(codegen::LanguageExtension &language_extension, StructuredSDFG &sdfg, analysis::AnalysisManager &analysis_manager, structured_control_flow::Reduce &node, codegen::InstrumentationPlan &instrumentation_plan, codegen::ArgCapturePlan &arg_capture_plan)
structured_control_flow::Reduce & node_
Definition gpu_reduce_dispatcher.h:50
bool is_nested_in_gpu_kernel()
True if this Reduce is nested inside an enclosing GPU kernel (an ancestor Map with this backend's GPU...
codegen::InstrumentationInfo instrumentation_info() const override
Bad design.
void dispatch_header(codegen::PrettyPrinter &stream, const std::string &kernel_name, std::vector< std::string > &arguments_declaration)
Represents a loop with an associative/commutative reduction carried dependency.
Definition reduce.h:106
Represents the storage location and management characteristics of data.
Definition type.h:64
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
StringEnum TargetType
Definition instrumentation_info.h:32
Definition cuda_arch.h:11
GPUDimension
Shared GPU dimension enum for CUDA/ROCm targets Represents the X, Y, Z dimensions used for GPU kernel...
Definition gpu_types.h:10
Definition analysis.h:7
Dispatcher base class for code generation from control flow nodes.
A single reduction carried by a Reduce loop.
Definition reduce.h:73
Symbolic system for integer-based symbol analysis.
Core type system definitions for sdfglib.