Halide
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 
13 namespace Halide {
14 
15 class ImageParam;
16 
17 class ParamMap {
18 public:
19  struct ParamMapping {
20  const Internal::Parameter *parameter{nullptr};
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 
33  : image_param(&p), buf(buf), buf_out_param(nullptr) {
34  }
35 
36  template<typename T, int Dims>
38  : image_param(&p), buf(buf), buf_out_param(nullptr) {
39  }
40 
41  ParamMapping(const ImageParam &p, Buffer<> *buf_ptr)
42  : image_param(&p), buf_out_param(buf_ptr) {
43  }
44 
45  template<typename T, int Dims>
47  : image_param(&p), buf_out_param((Buffer<> *)buf_ptr) {
48  }
49  };
50 
51 private:
52  struct ParamArg {
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 
70 public:
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.")
75  ParamMap(const std::initializer_list<ParamMapping> &init);
76 
77  template<typename T>
78  HALIDE_ATTRIBUTE_DEPRECATED("ParamMap is deprecated in Halide 16 and will be removed in Halide 17. "
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());
82  v.set_scalar<T>(val);
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() {
111  static ParamMap empty_param_map;
112  return empty_param_map;
113  }
114 };
115 
116 } // namespace Halide
117 
118 #endif
Halide::Internal::Parameter::set_scalar
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
Parameter.h
Halide::Internal::Parameter
A reference-counted handle to a parameter to a halide pipeline.
Definition: Parameter.h:28
Halide::ImageParam
An Image parameter to a halide pipeline.
Definition: ImageParam.h:23
Halide::ParamMap::ParamMapping::parameter
const Internal::Parameter * parameter
Definition: ParamMap.h:20
Halide::ParamMap
Definition: ParamMap.h:17
Halide::ParamMap::ParamMapping::ParamMapping
ParamMapping(const Param< T > &p, const T &val)
Definition: ParamMap.h:27
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::ParamMap::buf_out_param
pa buf_out_param
Definition: ParamMap.h:85
Halide::ParamMap::ParamMapping::value
halide_scalar_value_t value
Definition: ParamMap.h:22
halide_scalar_value_t
halide_scalar_value_t is a simple union able to represent all the well-known scalar values in a filte...
Definition: HalideRuntime.h:1662
Halide::ParamMap::ParamMapping::image_param
const ImageParam * image_param
Definition: ParamMap.h:21
Halide::ParamMap::ParamMapping
Definition: ParamMap.h:19
Halide::Buffer<>
Halide::ParamMap::size
size_t size() const
Definition: ParamMap.h:95
Halide::ParamMap::mapped_param
pa mapped_param
Definition: ParamMap.h:84
Halide::ParamMap::buf
const Buffer & buf
Definition: ParamMap.h:91
Halide::ParamMap::HALIDE_ATTRIBUTE_DEPRECATED
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
Halide::ParamMap::ParamMapping::ParamMapping
ParamMapping(const ImageParam &p, Buffer< T, Dims > *buf_ptr)
Definition: ParamMap.h:46
Halide::ParamMap::ParamMapping::ParamMapping
ParamMapping(const ImageParam &p, Buffer<> *buf_ptr)
Definition: ParamMap.h:41
Halide::ParamMap::ParamMapping::buf
Buffer buf
Definition: ParamMap.h:23
Halide::ParamMap::ParamMapping::ParamMapping
ParamMapping(const ImageParam &p, Buffer<> &buf)
Definition: ParamMap.h:32
Halide::ParamMap::ParamMapping::buf_out_param
Buffer * buf_out_param
Definition: ParamMap.h:24
Halide::ParamMap::pa
ParamArg pa
Definition: ParamMap.h:83
Halide::ParamMap::ParamMapping::ParamMapping
ParamMapping(const ImageParam &p, Buffer< T, Dims > &buf)
Definition: ParamMap.h:37
Halide::ParamMap::val
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
Param.h
Halide::ParamMap::map
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.
Halide::Param
A scalar parameter to a halide pipeline.
Definition: Param.h:22
Halide::ParamMap::ParamMap
ParamMap()=default
Halide::ParamMap::empty_map
static const ParamMap & empty_map()
A const ref to an empty ParamMap.
Definition: ParamMap.h:110