AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
Kernel.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#ifndef AGX_KERNEL_H
18#define AGX_KERNEL_H
19
20
21#include <agx/Referenced.h>
22#include <agx/Task.h>
23#include <agxData/Value.h>
24#include <agx/Vector.h>
25
26#ifdef _MSC_VER
27# pragma warning(push)
28# pragma warning(disable : 4251 ) // class X needs to have dll-interface to be used by clients of class Y
29#endif
30
31
32namespace agx
33{
34 class TiXmlElement;
35
40
46 {
47 public:
49
50 static Kernel *load(TiXmlElement *eKernel, Device *device);
51 virtual void configure(TiXmlElement *eKernel) override;
52
53 public:
54 Kernel(const agx::Name& name, agx::Device* device, const agx::Job::Callback& dispatcher);
55
59 agx::UInt getNumWorkItems() const;
60
64 virtual float getComputeTime();
65
69 agx::UInt getNumJobsPerThread() const;
70
74 agx::UInt getMinJobSize() const;
75
79 agx::UInt getMaxJobSize() const;
80
84 agx::UInt getCostPerElement() const;
85
90
95
100
105
106
107
111 // void setSplittingParameter(ArrayParameter *parameter);
112
113 virtual void preDispatch() {}
114
115 virtual void rebind() override;
116
117 protected:
118 virtual ~Kernel();
119 virtual void parameterAddedCallback(Parameter* parameter) override;
120 virtual void parameterRemovedCallback(Parameter* parameter) override;
123
124 private:
125 agxData::Val<UInt> m_numJobsPerThread;
126 agxData::Val<UInt> m_minJobSize;
127 agxData::Val<UInt> m_maxJobSize;
128 agxData::Val<UInt> m_costPerElement;
129 // ArrayParameterRef m_splittingParameter;
130 };
131
132
133 //---------------------------------------------------------------
134
139 {
140 public:
142
143 public:
144 static CpuKernel *load(TiXmlElement *eKernel, Device *device);
145
146 public:
147 CpuKernel(const agx::Name& name, RangeDispatch rangeDispatch);
148 CpuKernel(const agx::Name& name, Job::Callback serialDispatch);
149
150 UInt getNumJobs() const;
151
152 const RangeDispatch& getRangeDispatch() const;
153
154 protected:
155 virtual ~CpuKernel();
157 virtual RangeJob *allocateRangeJobs(size_t numJobs) = 0;
158
159 protected: // Should be private, is protected for custom job generators
160 // Vector<RangeJob> m_rangeJobs;
163 };
164
165
166 //---------------------------------------------------------------
167
173 {
174 public:
175 typedef std::function<void (const RangeJob&)> LambdaCallback;
176 typedef std::function<UInt ()> DataSetSizeCallback;
177
178 public:
186 LambdaKernel(const agx::Name& name, LambdaCallback lambdaCallback, DataSetSizeCallback sizeCallback);
187
188 private:
189 void generateJobs();
190 virtual RangeJob *allocateRangeJobs(size_t numJobs) override;
191 void callOnJobRange(const RangeJob& job);
192
193 protected:
195
196 private:
197 DataSetSizeCallback m_sizeCallback;
198 LambdaCallback m_lambda;
199 };
200
201 //---------------------------------------------------------------
202
203
204 /* Implementation */
205 // inline const Kernel::ImplementationTable& Kernel::getImplementations() const { return m_implementations; }
206 // inline const Kernel::Implementation& Kernel::getImplementation(const String& name) const { agxAssert(m_implementations.contains(name)); return m_implementations.find(name)->second; }
207 // inline const Kernel::Implementation& Kernel::getActiveImplementation() const { return m_activeImplementation; }
208 AGX_FORCE_INLINE UInt Kernel::getNumJobsPerThread() const { return m_numJobsPerThread; }
209 AGX_FORCE_INLINE UInt Kernel::getMinJobSize() const { return m_minJobSize; }
210 AGX_FORCE_INLINE UInt Kernel::getMaxJobSize() const { return m_maxJobSize; }
211 AGX_FORCE_INLINE UInt Kernel::getCostPerElement() const { return m_costPerElement; }
212
214 {
215 if (!m_numWorkItems)
216 const_cast<Kernel *>(this)->locateNumWorkItemsValue();
217
218 return m_numWorkItems->get();
219 }
220
222
224}
225
226
227#ifdef _MSC_VER
228# pragma warning(pop)
229#endif
230
231#endif /* _AGX_KERNEL_H_ */
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXCORE_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Only use as member allocated variable.
Definition: Value.h:285
Templated value-reference.
Definition: Value.h:263
const T & get() const
Definition: Value.h:454
Templated callback with one argument.
Definition: Callback.h:101
A kernel which executes on the CPU using native C/C++ code.
Definition: Kernel.h:139
const RangeDispatch & getRangeDispatch() const
Definition: Kernel.h:221
UInt m_numJobs
Definition: Kernel.h:162
void generateJobs()
RangeDispatch m_rangeDispatch
Definition: Kernel.h:161
CpuKernel(const agx::Name &name, RangeDispatch rangeDispatch)
RangeJob::RangeCallback RangeDispatch
Definition: Kernel.h:141
virtual ~CpuKernel()
virtual RangeJob * allocateRangeJobs(size_t numJobs)=0
CpuKernel(const agx::Name &name, Job::Callback serialDispatch)
UInt getNumJobs() const
Definition: Kernel.h:223
static CpuKernel * load(TiXmlElement *eKernel, Device *device)
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition: Device.h:58
A kernel is an abstract representation of data parallel tasks.
Definition: Kernel.h:46
agxData::ValueRefT< UInt > m_numWorkItems
Definition: Kernel.h:122
void setCostPerElement(agx::UInt cost)
Set the per-element cost estimate.
virtual float getComputeTime()
void setNumJobsPerThread(agx::UInt numJobs)
Set the number of jobs per thread.
void setMinJobSize(agx::UInt min)
Set the minimum number of work elements per job.
virtual void parameterAddedCallback(Parameter *parameter) override
agx::UInt getMaxJobSize() const
Definition: Kernel.h:210
Kernel(const agx::Name &name, agx::Device *device, const agx::Job::Callback &dispatcher)
virtual void rebind() override
agx::UInt getNumJobsPerThread() const
Definition: Kernel.h:208
agx::UInt getNumWorkItems() const
Definition: Kernel.h:213
agx::UInt getCostPerElement() const
Definition: Kernel.h:211
void setMaxJobSize(agx::UInt max)
Set the maximum number of work elements per job.
virtual void parameterRemovedCallback(Parameter *parameter) override
virtual void preDispatch()
Explicitly set the splitting parameter.
Definition: Kernel.h:113
static Kernel * load(TiXmlElement *eKernel, Device *device)
static agx::Model * ClassModel()
virtual ~Kernel()
void locateNumWorkItemsValue()
agx::UInt getMinJobSize() const
Definition: Kernel.h:209
virtual void configure(TiXmlElement *eKernel) override
std::function< void(const RangeJob &)> LambdaCallback
Definition: Kernel.h:175
Vector< RangeJob > m_rangeJobs
Definition: Kernel.h:194
LambdaKernel(const agx::Name &name, LambdaCallback lambdaCallback, DataSetSizeCallback sizeCallback)
Constructor.
std::function< UInt()> DataSetSizeCallback
Definition: Kernel.h:176
A model is an abstract representation of the class of an agx::Object.
Definition: Model.h:41
Representation of a name string.
Definition: Name.h:33
ParallelTask.
Definition: Task.h:515
A representation of a task/kernel parameter, which can be bound using a string path or explicitly to ...
Definition: Parameter.h:62
A range job executes a kernel implementation on a subset of the data.
Definition: Job.h:282
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint64_t UInt
Definition: Integer.h:27