Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
DeviceArgument.h
Go to the documentation of this file.
1#ifndef HALIDE_DEVICE_ARGUMENT_H
2#define HALIDE_DEVICE_ARGUMENT_H
3
4/** \file
5 * Defines helpers for passing arguments to separate devices, such as GPUs.
6 */
7#include <string>
8
9#include "Closure.h"
10#include "Expr.h"
11#include "ModulusRemainder.h"
12
13namespace Halide {
14namespace Internal {
15
16/** A DeviceArgument looks similar to an Halide::Argument, but has behavioral
17 * differences that make it specific to the GPU pipeline; the fact that
18 * neither is-a nor has-a Halide::Argument is deliberate. In particular, note
19 * that a Halide::Argument that is a buffer can be read or write, but not both,
20 * while a DeviceArgument that is a buffer can be read *and* write for some GPU
21 * backends. */
23 /** The name of the argument */
24 std::string name;
25
26 /** An argument is either a primitive type (for parameters), or a
27 * buffer pointer.
28 *
29 * If is_buffer == false, then type fully encodes the expected type
30 * of the scalar argument.
31 *
32 * If is_buffer == true, then type.bytes() should be used to determine
33 * elem_size of the buffer; additionally, type.code *should* reflect
34 * the expected interpretation of the buffer data (e.g. float vs int),
35 * but there is no runtime enforcement of this at present.
36 */
37 bool is_buffer = false;
38
39 /** If is_buffer == true and memory_type == GPUTexture, this argument should be
40 * passed and accessed through texture sampler operations instead of
41 * directly as a memory array
42 */
44
45 /** If is_buffer is true, this is the dimensionality of the buffer.
46 * If is_buffer is false, this value is ignored (and should always be set to zero) */
48
49 /** If this is a scalar parameter, then this is its type.
50 *
51 * If this is a buffer parameter, this is used to determine elem_size
52 * of the halide_buffer_t.
53 *
54 * Note that type.lanes() should always be 1 here. */
56
57 /** The static size of the argument if known, or zero otherwise. */
58 size_t size = 0;
59
60 /** The index of the first element of the argument when packed into a wider
61 * type, such as packing scalar floats into vec4 for GLSL. */
62 size_t packed_index = 0;
63
64 /** For buffers, these two variables can be used to specify whether the
65 * buffer is read or written. By default, we assume that the argument
66 * buffer is read-write and set both flags. */
67 bool read = false;
68 bool write = false;
69
70 /** Alignment information for integer parameters. */
72
73 DeviceArgument() = default;
74
75 DeviceArgument(const std::string &_name,
76 bool _is_buffer,
77 MemoryType _mem,
78 Type _type,
79 uint8_t _dimensions,
80 size_t _size = 0)
81 : name(_name),
82 is_buffer(_is_buffer),
83 memory_type(_mem),
84 dimensions(_dimensions),
85 type(_type),
86 size(_size),
87
88 read(_is_buffer),
89 write(_is_buffer) {
90 }
91};
92
93/** A Closure modified to inspect GPU-specific memory accesses, and
94 * produce a vector of DeviceArgument objects. */
95class HostClosure : public Closure {
96public:
97 HostClosure() = default;
98
99 /** Get a description of the captured arguments. */
100 std::vector<DeviceArgument> arguments();
101
102protected:
104
105 void visit(const For *loop) override;
106 void visit(const Call *op) override;
107};
108
109} // namespace Internal
110} // namespace Halide
111
112#endif
Provides Closure class.
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Routines for statically determining what expressions are divisible by.
A helper class to manage closures.
Definition Closure.h:26
void visit(const Let *op) override
A Closure modified to inspect GPU-specific memory accesses, and produce a vector of DeviceArgument ob...
void visit(const Call *op) override
std::vector< DeviceArgument > arguments()
Get a description of the captured arguments.
void visit(const For *loop) override
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
MemoryType
An enum describing different address spaces to be used with Func::store_in.
Definition Expr.h:353
@ Auto
Let Halide select a storage type automatically.
unsigned __INT8_TYPE__ uint8_t
A function call.
Definition IR.h:490
A DeviceArgument looks similar to an Halide::Argument, but has behavioral differences that make it sp...
size_t packed_index
The index of the first element of the argument when packed into a wider type, such as packing scalar ...
bool read
For buffers, these two variables can be used to specify whether the buffer is read or written.
size_t size
The static size of the argument if known, or zero otherwise.
Type type
If this is a scalar parameter, then this is its type.
uint8_t dimensions
If is_buffer is true, this is the dimensionality of the buffer.
ModulusRemainder alignment
Alignment information for integer parameters.
MemoryType memory_type
If is_buffer == true and memory_type == GPUTexture, this argument should be passed and accessed throu...
std::string name
The name of the argument.
bool is_buffer
An argument is either a primitive type (for parameters), or a buffer pointer.
DeviceArgument(const std::string &_name, bool _is_buffer, MemoryType _mem, Type _type, uint8_t _dimensions, size_t _size=0)
A for loop.
Definition IR.h:819
The result of modulus_remainder analysis.
Types in the halide type system.
Definition Type.h:283