21 template<jit::
float_scalar T,
bool SAFE_MATH=false>
53 const std::string name,
const size_t size,
84 template<jit::
float_scalar T,
bool SAFE_MATH=false>
87 const size_t num_iterations;
106 const std::string name,
const size_t size,
108 const size_t iterations) :
110 num_iterations(iterations) {}
116 for (
size_t i = 0; i < num_iterations; i++) {
128 template<jit::
float_scalar T,
bool SAFE_MATH=false>
132 std::function<T(
void)> max_kernel;
136 const size_t max_iterations;
156 const std::string name,
const size_t size,
159 const size_t max_iter=1000) :
161 tolerance(tol), max_iterations(max_iter) {
180 size_t iterations = 0;
181 T max_residual = max_kernel();
182 T last_max = std::numeric_limits<T>::max();
183 T off_last_max = std::numeric_limits<T>::max();
184 while (std::abs(max_residual) > std::abs(tolerance) &&
185 std::abs(last_max - max_residual) > std::abs(tolerance) &&
186 std::abs(off_last_max - max_residual) > std::abs(tolerance) &&
187 iterations++ < max_iterations) {
188 last_max = max_residual;
189 if (!(iterations%2)) {
190 off_last_max = max_residual;
192 max_residual = max_kernel();
197 assert(iterations < max_iterations &&
198 "Workitem failed to converge.");
199 if (iterations > max_iterations) {
200 std::cerr <<
"Workitem failed to converge with in given iterations."
202 std::cerr <<
"Minimum residual reached: " << max_residual
214 template<jit::
float_scalar T,
bool SAFE_MATH=false>
220 std::vector<std::unique_ptr<work_item<T, SAFE_MATH>>> preitems;
222 std::vector<std::unique_ptr<work_item<T, SAFE_MATH>>> items;
238 manager(
const size_t index) : context(index), add_reduction(false) {}
254 const std::string name,
const size_t size) {
275 const std::string name,
const size_t size) {
297 const std::string name,
const size_t size,
298 const size_t iterations) {
322 const std::string name,
const size_t size,
324 const size_t max_iter=1000) {
325 add_reduction =
true;
337 context.
compile(add_reduction);
339 for (
auto &item : preitems) {
340 item->create_kernel_call(context);
342 for (
auto &item : items) {
343 item->create_kernel_call(context);
351 for (
auto &item : preitems) {
360 for (
auto &item : items) {
402 context.
print(index, nodes);
Class for JIT compile of the GPU kernels.
Definition jit.hpp:49
void compile(const bool add_reduction=false)
Compile the kernel.
Definition jit.hpp:230
void wait()
Wait for kernel to finish.
Definition jit.hpp:297
std::function< T(void)> create_max_call(graph::shared_leaf< T, SAFE_MATH > &argument, std::function< void(void)> run)
Create a max compute kernel calling function.
Definition jit.hpp:266
void add_max_reduction(const size_t size)
Add max reduction kernel.
Definition jit.hpp:193
std::function< void(void)> create_kernel_call(const std::string kernel_name, graph::input_nodes< T, SAFE_MATH > inputs, graph::output_nodes< T, SAFE_MATH > outputs, graph::shared_random_state< T, SAFE_MATH > state, const size_t num_rays)
Create a kernel calling function.
Definition jit.hpp:249
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print output.
Definition jit.hpp:277
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *source)
Copy contexts of buffer to device.
Definition jit.hpp:307
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition jit.hpp:289
void add_kernel(const std::string name, graph::input_nodes< T, SAFE_MATH > inputs, graph::output_nodes< T, SAFE_MATH > outputs, graph::map_nodes< T, SAFE_MATH > setters, graph::shared_random_state< T, SAFE_MATH > state, const size_t size)
Add a kernel.
Definition jit.hpp:116
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition jit.hpp:318
Class representing a convergence work item.
Definition workflow.hpp:129
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:170
converge_item(graph::input_nodes< T, SAFE_MATH > inputs, graph::output_nodes< T, SAFE_MATH > outputs, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, jit::context< T, SAFE_MATH > &context, const T tol=1.0E-30, const size_t max_iter=1000)
Construct a workflow item.
Definition workflow.hpp:152
virtual void run()
Run the workitem.
Definition workflow.hpp:179
Run a work item in a fixed iteration loop.
Definition workflow.hpp:85
loop_item(graph::input_nodes< T, SAFE_MATH > inputs, graph::output_nodes< T, SAFE_MATH > outputs, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, jit::context< T, SAFE_MATH > &context, const size_t iterations)
Construct a workflow item.
Definition workflow.hpp:102
virtual void run()
Run the workitem.
Definition workflow.hpp:115
Class representing a workflow manager.
Definition workflow.hpp:215
void add_preitem(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size)
Add a pre workflow item.
Definition workflow.hpp:250
void run()
Run work items.
Definition workflow.hpp:359
void wait()
Wait for GPU queue to finish.
Definition workflow.hpp:368
void pre_run()
Run pre work items.
Definition workflow.hpp:350
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition workflow.hpp:389
void add_loop_item(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, const size_t iterations)
Add a workflow item.
Definition workflow.hpp:293
void add_converge_item(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, const T tol=1.0E-30, const size_t max_iter=1000)
Add a converge item.
Definition workflow.hpp:318
void add_item(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size)
Add a workflow item.
Definition workflow.hpp:271
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print results.
Definition workflow.hpp:400
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy buffer contents to the device.
Definition workflow.hpp:378
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:422
manager(const size_t index)
Workflow manager constructor.
Definition workflow.hpp:238
void compile()
Compile the workflow items.
Definition workflow.hpp:336
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition workflow.hpp:412
Class representing a work item.
Definition workflow.hpp:22
virtual void run()
Run the work item.
Definition workflow.hpp:73
const std::string kernel_name
Name of the GPU kernel.
Definition workflow.hpp:25
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:65
graph::shared_random_state< T, SAFE_MATH > state
Random state node.
Definition workflow.hpp:33
work_item(graph::input_nodes< T, SAFE_MATH > in, graph::output_nodes< T, SAFE_MATH > out, graph::map_nodes< T, SAFE_MATH > maps, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, jit::context< T, SAFE_MATH > &context)
Construct a workflow item.
Definition workflow.hpp:49
graph::input_nodes< T, SAFE_MATH > inputs
Input nodes.
Definition workflow.hpp:29
const size_t kernel_size
Name of the GPU kernel.
Definition workflow.hpp:27
graph::output_nodes< T, SAFE_MATH > outputs
Output nodes.
Definition workflow.hpp:31
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:35
subroutine assert(test, message)
Assert check.
Definition f_binding_test.f90:38
Class to just in time compile a kernel.
std::shared_ptr< random_state_node< T, SAFE_MATH > > shared_random_state
Convenience type alias for shared sqrt nodes.
Definition random.hpp:263
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:1711
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:676
std::vector< std::pair< shared_leaf< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > map_nodes
Convenience type alias for mapping end codes back to inputs.
Definition node.hpp:1715
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:691
Name space for workflows.
Definition workflow.hpp:14