docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
gpu_schedule_type.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include "sdfg/exceptions.h"
9
10namespace sdfg {
11namespace gpu {
12
25template<typename Derived>
27public:
32 schedule.set_property("dimension", std::to_string(dimension));
33 }
34
39 return static_cast<GPUDimension>(std::stoi(schedule.properties().at("dimension")));
40 }
41
49
58 if (schedule.properties().find("block_size") == schedule.properties().end()) {
59 if (dimension(schedule) == GPUDimension::X) {
60 return Derived::default_block_size_x();
61 } else if (dimension(schedule) == GPUDimension::Y) {
62 return symbolic::integer(8);
63 } else if (dimension(schedule) == GPUDimension::Z) {
64 return symbolic::integer(4);
65 } else {
66 throw InvalidSDFGException("Invalid GPU dimension");
67 }
68 }
69 std::string expr_str = schedule.properties().at("block_size");
70 return symbolic::integer(std::stoi(expr_str));
71 }
72
77 if (schedule.properties().find("nested_sync") == schedule.properties().end()) {
78 return false;
79 }
80 std::string val = schedule.properties().at("nested_sync");
81 return val == "true";
82 }
83
88 schedule.set_property("nested_sync", nested_sync ? "true" : "false");
89 }
90
95 auto schedule_type = structured_control_flow::
97 dimension(schedule_type, GPUDimension::X);
98 return schedule_type;
99 }
100};
101
108 return static_cast<GPUDimension>(std::stoi(schedule.properties().at("dimension")));
109}
110
116inline void gpu_dimension(structured_control_flow::ScheduleType& schedule, const GPUDimension& dimension) {
117 schedule.set_property("dimension", std::to_string(dimension));
118}
119
130 if (schedule.properties().find("block_size") == schedule.properties().end()) {
131 auto dim = gpu_dimension(schedule);
132 if (dim == GPUDimension::X) {
133 // Default block size depends on the backend
134 if (schedule.value() == "ROCM") {
135 return symbolic::integer(64);
136 }
137 return symbolic::integer(32);
138 } else if (dim == GPUDimension::Y) {
139 return symbolic::integer(8);
140 } else if (dim == GPUDimension::Z) {
141 return symbolic::integer(4);
142 } else {
143 throw InvalidSDFGException("Invalid GPU dimension");
144 }
145 }
146 std::string expr_str = schedule.properties().at("block_size");
147 return symbolic::integer(std::stoi(expr_str));
148}
149
157 schedule.set_property("block_size", serializer.expression(block_size));
158}
159
160} // namespace gpu
161} // namespace sdfg
Definition exceptions.h:8
Base class for GPU schedule types (CUDA/ROCm) using CRTP pattern.
Definition gpu_schedule_type.h:26
static void nested_sync(structured_control_flow::ScheduleType &schedule, const bool nested_sync)
Set nested synchronization flag.
Definition gpu_schedule_type.h:87
static structured_control_flow::ScheduleType create()
Create a new GPU schedule type.
Definition gpu_schedule_type.h:94
static GPUDimension dimension(const structured_control_flow::ScheduleType &schedule)
Get the GPU dimension from a schedule.
Definition gpu_schedule_type.h:38
static void block_size(structured_control_flow::ScheduleType &schedule, const symbolic::Expression block_size)
Set the block size for a schedule.
Definition gpu_schedule_type.h:45
static void dimension(structured_control_flow::ScheduleType &schedule, const GPUDimension &dimension)
Set the GPU dimension for a schedule.
Definition gpu_schedule_type.h:31
static bool nested_sync(const structured_control_flow::ScheduleType &schedule)
Check if nested synchronization is enabled.
Definition gpu_schedule_type.h:76
static symbolic::Integer block_size(const structured_control_flow::ScheduleType &schedule)
Get the block size from a schedule Returns default values if not explicitly set:
Definition gpu_schedule_type.h:57
Definition json_serializer.h:22
Represents a schedule type for Map nodes.
Definition structured_loop.h:31
const std::unordered_map< std::string, std::string > & properties() const
Get all schedule properties.
Definition structured_loop.h:53
void set_property(const std::string &key, const std::string &value)
Set a schedule property.
Definition structured_loop.h:70
const std::string & value() const
Get the schedule type identifier.
Definition structured_loop.h:45
Integer integer(int64_t value)
Creates an integer constant.
SymEngine::RCP< const SymEngine::Basic > Expression
Reference-counted pointer to a symbolic expression (SymEngine Basic).
Definition symbolic.h:83
SymEngine::RCP< const SymEngine::Integer > Integer
Reference-counted pointer to a SymEngine Integer constant.
Definition symbolic.h:77
Definition cuda_arch.h:11
symbolic::Integer gpu_block_size(const structured_control_flow::ScheduleType &schedule)
Get the block size from any GPU schedule type Returns default values if not explicitly set:
Definition gpu_schedule_type.h:129
GPUDimension
Shared GPU dimension enum for CUDA/ROCm targets Represents the X, Y, Z dimensions used for GPU kernel...
Definition gpu_types.h:10
@ Z
Definition gpu_types.h:10
@ Y
Definition gpu_types.h:10
@ X
Definition gpu_types.h:10
GPUDimension gpu_dimension(const structured_control_flow::ScheduleType &schedule)
Get the GPU dimension from any GPU schedule type.
Definition gpu_schedule_type.h:107
Definition cutout_serializer.h:13
@ Offloader
Definition structured_loop.h:22
Definition analysis.h:7