Halide 16.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
ParamMap.h
Go to the documentation of this file.
1#ifndef HALIDE_PARAM_MAP_H
2#define HALIDE_PARAM_MAP_H
3
4/** \file
5 * Defines a collection of parameters to be passed as formal arguments
6 * to a JIT invocation.
7 */
8#include <map>
9
10#include "Param.h"
11#include "Parameter.h"
12
13namespace Halide {
14
15class ImageParam;
16
17class ParamMap {
18public:
19 struct ParamMapping {
21 const ImageParam *image_param{nullptr};
25
26 template<typename T>
27 ParamMapping(const Param<T> &p, const T &val)
28 : parameter(&p.parameter()) {
29 *((T *)&value) = val;
30 }
31
35
36 template<typename T, int Dims>
40
44
45 template<typename T, int Dims>
49 };
50
51private:
52 struct ParamArg {
53 Internal::Parameter mapped_param;
54 Buffer<> *buf_out_param = nullptr;
55
56 ParamArg() = default;
57 ParamArg(const ParamMapping &pm)
58 : mapped_param(pm.parameter->type(), false, 0, pm.parameter->name()) {
59 mapped_param.set_scalar(pm.parameter->type(), pm.value);
60 }
61 ParamArg(Buffer<> *buf_ptr)
62 : buf_out_param(buf_ptr) {
63 }
64 ParamArg(const ParamArg &) = default;
65 };
66 mutable std::map<const Internal::Parameter, ParamArg> mapping;
67
68 void set(const ImageParam &p, const Buffer<> &buf, Buffer<> *buf_out_param);
69
70public:
71 ParamMap() = default;
72
73 HALIDE_ATTRIBUTE_DEPRECATED("ParamMap is deprecated in Halide 16 and will be removed in Halide 17. "
74 "Callers requiring threadsafe JIT calls should migrate to use compile_to_callable() instead.")
76
79 "Callers requiring threadsafe JIT calls should migrate to use compile_to_callable() instead.")
80 void set(const Param<T> &p, T val) {
81 Internal::Parameter v(p.type(), false, 0, p.name());
83 ParamArg pa;
84 pa.mapped_param = v;
85 pa.buf_out_param = nullptr;
86 mapping[p.parameter()] = pa;
87 }
88
89 HALIDE_ATTRIBUTE_DEPRECATED("ParamMap is deprecated in Halide 16 and will be removed in Halide 17. "
90 "Callers requiring threadsafe JIT calls should migrate to use compile_to_callable() instead.")
91 void set(const ImageParam &p, const Buffer<> &buf) {
92 set(p, buf, nullptr);
93 }
94
95 size_t size() const {
96 return mapping.size();
97 }
98
99 /** If there is an entry in the ParamMap for this Parameter, return it.
100 * Otherwise return the parameter itself. */
101 // @{
103
105 // @}
106
107 /** A const ref to an empty ParamMap. Useful for default function
108 * arguments, which would otherwise require a copy constructor
109 * (with llvm in c++98 mode) */
110 static const ParamMap &empty_map() {
112 return empty_param_map;
113 }
114};
115
116} // namespace Halide
117
118#endif
#define HALIDE_ATTRIBUTE_DEPRECATED(x)
Classes for declaring scalar parameters to halide pipelines.
Defines the internal representation of parameters to halide piplines.
An Image parameter to a halide pipeline.
Definition ImageParam.h:23
A reference-counted handle to a parameter to a halide pipeline.
Definition Parameter.h:28
HALIDE_NO_USER_CODE_INLINE void set_scalar(T val)
If the parameter is a scalar parameter, set its current value.
Definition Parameter.h:90
A scalar parameter to a halide pipeline.
Definition Param.h:22
const Buffer & buf
Definition ParamMap.h:91
size_t size() const
Definition ParamMap.h:95
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
Definition ParamMap.h:110
HALIDE_ATTRIBUTE_DEPRECATED("ParamMap is deprecated in Halide 16 and will be removed in Halide 17. " "Callers requiring threadsafe JIT calls should migrate to use compile_to_callable() instead.") ParamMap(const std T val
Definition ParamMap.h:80
ParamMap()=default
ParamArg pa
Definition ParamMap.h:83
Internal::Parameter & map(Internal::Parameter &p, Buffer<> *&buf_out_param) const
HALIDE_ATTRIBUTE_DEPRECATED("ParamMap is deprecated in Halide 16 and will be removed in Halide 17. " "Callers requiring threadsafe JIT calls should migrate to use compile_to_callable() instead.") void set(const ImageParam &p
const Internal::Parameter & map(const Internal::Parameter &p, Buffer<> *&buf_out_param) const
If there is an entry in the ParamMap for this Parameter, return it.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Definition IROperator.h:358
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:321
ParamMapping(const ImageParam &p, Buffer< T, Dims > *buf_ptr)
Definition ParamMap.h:46
const ImageParam * image_param
Definition ParamMap.h:21
ParamMapping(const ImageParam &p, Buffer<> *buf_ptr)
Definition ParamMap.h:41
ParamMapping(const ImageParam &p, Buffer<> &buf)
Definition ParamMap.h:32
const Internal::Parameter * parameter
Definition ParamMap.h:20
ParamMapping(const Param< T > &p, const T &val)
Definition ParamMap.h:27
halide_scalar_value_t value
Definition ParamMap.h:22
ParamMapping(const ImageParam &p, Buffer< T, Dims > &buf)
Definition ParamMap.h:37
halide_scalar_value_t is a simple union able to represent all the well-known scalar values in a filte...