31 template<jit::
float_scalar T,
bool SAFE_MATH=false>
44 virtual void run() = 0;
53 template<jit::
float_scalar T,
bool SAFE_MATH=false>
93 template<jit::
float_scalar T,
bool SAFE_MATH=false>
133 template<jit::
float_scalar T,
bool SAFE_MATH=false>
173 template<jit::
float_scalar T,
bool SAFE_MATH=false>
209 const std::string name,
const size_t size,
240 template<jit::
float_scalar T,
bool SAFE_MATH=false>
277 const std::string name,
const size_t size,
279 const size_t iterations) :
283 state, size, iterations);
310 template<jit::
float_scalar T,
bool SAFE_MATH=false>
314 std::function<T(
void)> max_kernel;
318 const size_t max_iterations;
340 const std::string name,
const size_t size,
343 const size_t max_iter=1000) :
345 state, name, size, context),
346 tolerance(tol), max_iterations(max_iter) {
365 size_t iterations = 0;
366 T max_residual = max_kernel();
367 T last_max = std::numeric_limits<T>::max();
368 T off_last_max = std::numeric_limits<T>::max();
369 while (std::abs(max_residual) > std::abs(tolerance) &&
370 std::abs(last_max - max_residual) > std::abs(tolerance) &&
371 std::abs(off_last_max - max_residual) > std::abs(tolerance) &&
372 iterations++ < max_iterations) {
373 last_max = max_residual;
374 if (!(iterations%2)) {
375 off_last_max = max_residual;
377 max_residual = max_kernel();
382 assert(iterations < max_iterations &&
383 "Workitem failed to converge.");
384 if (iterations > max_iterations) {
385 std::cerr <<
"Workitem failed to converge with in given iterations."
387 std::cerr <<
"Minimum residual reached: " << max_residual
399 template<jit::
float_scalar T,
bool SAFE_MATH=false>
405 std::vector<std::unique_ptr<item<T, SAFE_MATH>>> preitems;
407 std::vector<std::unique_ptr<item<T, SAFE_MATH>>> items;
409 std::vector<std::unique_ptr<item<T, SAFE_MATH>>> postitems;
425 manager(
const size_t index) : context(index), add_reduction(false) {}
434 template<order O=run_item>
438 }
else if constexpr (O ==
run_item) {
458 template<order O=run_item>
464 const std::string name,
const size_t size) {
472 }
else if constexpr (O ==
run_item) {
496 template<order O=run_item>
500 }
else if constexpr (O ==
run_item) {
514 template<order O=run_item>
518 }
else if constexpr (O ==
run_item) {
539 template<order O=run_item>
545 const std::string name,
const size_t size,
546 const size_t iterations) {
555 }
else if constexpr (O ==
run_item) {
589 template<order O=run_item>
595 const std::string name,
const size_t size,
597 const size_t max_iter=1000) {
598 add_reduction =
true;
607 }
else if constexpr (O ==
run_item) {
630 context.
compile(add_reduction);
632 for (
auto &
item : preitems) {
635 for (
auto &
item : items) {
638 for (
auto &
item : postitems) {
648 template<order O=run_item>
651 for (
auto &
item : preitems) {
654 }
else if constexpr (O ==
run_item) {
655 for (
auto &
item : items) {
659 for (
auto &
item : postitems) {
702 context.
print(index, nodes);
Class for JIT compile of the GPU kernels.
Definition jit.hpp:49
std::function< void(void)> create_copy_call(graph::copy_nodes< T, SAFE_MATH > setters)
Add copy.
Definition jit.hpp:247
void compile(const bool add_reduction=false)
Compile the kernel.
Definition jit.hpp:284
void wait()
Wait for kernel to finish.
Definition jit.hpp:354
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::input_nodes< T, SAFE_MATH > atomics, graph::shared_random_state< T, SAFE_MATH > state, const size_t num_rays)
Create a kernel calling function.
Definition jit.hpp:304
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:323
std::function< void(void)> create_zero_call(graph::input_nodes< T, SAFE_MATH > inputs)
Add zero.
Definition jit.hpp:237
void add_max_reduction(const size_t size)
Add max reduction kernel.
Definition jit.hpp:227
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print output.
Definition jit.hpp:334
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *source)
Copy contexts of buffer to device.
Definition jit.hpp:373
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition jit.hpp:346
std::function< void(void)> run_function(std::function< void(void)> callback)
Run a function.
Definition jit.hpp:363
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::input_nodes< T, SAFE_MATH > &atomics, graph::shared_random_state< T, SAFE_MATH > &state, const size_t size, const size_t iterations=1)
Add a kernel.
Definition jit.hpp:130
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition jit.hpp:384
Callback item.
Definition workflow.hpp:54
std::function< void(void)> callback
Callback function.
Definition workflow.hpp:57
callback_item(std::function< void(void)> callback)
Construct a workflow item.
Definition workflow.hpp:67
virtual void run()
Run the work item.
Definition workflow.hpp:82
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:59
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:75
Class representing a convergence work item.
Definition workflow.hpp:311
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:355
converge_item(graph::input_nodes< T, SAFE_MATH > &inputs, graph::output_nodes< T, SAFE_MATH > &outputs, graph::map_nodes< T, SAFE_MATH > &maps, graph::input_nodes< T, SAFE_MATH > &atomics, 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:335
virtual void run()
Run the workitem.
Definition workflow.hpp:364
Copy one buffer item to another.
Definition workflow.hpp:134
graph::copy_nodes< T, SAFE_MATH > maps
Input nodes.
Definition workflow.hpp:139
copy_item(graph::copy_nodes< T, SAFE_MATH > maps)
Construct a workflow item.
Definition workflow.hpp:147
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:137
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:155
virtual void run()
Run the work item.
Definition workflow.hpp:162
Interface class representing items.
Definition workflow.hpp:32
virtual void run()=0
Run the work item.
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)=0
Set the kernel function.
Run a work item in a fixed iteration loop.
Definition workflow.hpp:241
graph::input_nodes< T, SAFE_MATH > inputs
Input nodes.
Definition workflow.hpp:250
loop_item(graph::input_nodes< T, SAFE_MATH > &in, graph::output_nodes< T, SAFE_MATH > &out, graph::map_nodes< T, SAFE_MATH > &maps, graph::input_nodes< T, SAFE_MATH > &atomics, 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:272
graph::shared_random_state< T, SAFE_MATH > state
Random state node.
Definition workflow.hpp:256
graph::input_nodes< T, SAFE_MATH > atomics
Atomic nodes.
Definition workflow.hpp:254
graph::output_nodes< T, SAFE_MATH > outputs
Output nodes.
Definition workflow.hpp:252
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:291
const size_t kernel_size
Size of the GPU kernel.
Definition workflow.hpp:248
virtual void run()
Run the workitem.
Definition workflow.hpp:299
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:244
const std::string kernel_name
Name of the GPU kernel.
Definition workflow.hpp:246
Class representing a workflow manager.
Definition workflow.hpp:400
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::input_nodes< T, SAFE_MATH > atomics, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size)
Add a workflow item.
Definition workflow.hpp:459
void add_callback_item(std::function< void(void)> callback)
Add a pre callback function.
Definition workflow.hpp:435
void wait()
Wait for GPU queue to finish.
Definition workflow.hpp:668
void add_copy_item(graph::copy_nodes< T, SAFE_MATH > maps)
Add a copy item.
Definition workflow.hpp:515
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition workflow.hpp:689
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::input_nodes< T, SAFE_MATH > atomics, 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:590
void run()
Run work items.
Definition workflow.hpp:649
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print results.
Definition workflow.hpp:700
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::input_nodes< T, SAFE_MATH > atomics, graph::shared_random_state< T, SAFE_MATH > state, const std::string name, const size_t size, const size_t iterations)
Add a loop item.
Definition workflow.hpp:540
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy buffer contents to the device.
Definition workflow.hpp:678
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:722
manager(const size_t index)
Workflow manager constructor.
Definition workflow.hpp:425
void add_zero_item(graph::input_nodes< T, SAFE_MATH > in)
Add a zero item.
Definition workflow.hpp:497
void compile()
Compile the workflow items.
Definition workflow.hpp:629
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition workflow.hpp:712
Class representing a work item.
Definition workflow.hpp:174
virtual void run()
Run the work item.
Definition workflow.hpp:229
const std::string kernel_name
Name of the GPU kernel.
Definition workflow.hpp:179
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:221
graph::shared_random_state< T, SAFE_MATH > state
Random state node.
Definition workflow.hpp:189
graph::input_nodes< T, SAFE_MATH > inputs
Input nodes.
Definition workflow.hpp:183
work_item(graph::input_nodes< T, SAFE_MATH > &in, graph::output_nodes< T, SAFE_MATH > &out, graph::map_nodes< T, SAFE_MATH > &maps, graph::input_nodes< T, SAFE_MATH > &atomics, 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:204
graph::input_nodes< T, SAFE_MATH > atomics
Atomic nodes.
Definition workflow.hpp:187
const size_t kernel_size
Size of the GPU kernel.
Definition workflow.hpp:181
graph::output_nodes< T, SAFE_MATH > outputs
Output nodes.
Definition workflow.hpp:185
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:177
Clear buffer item.
Definition workflow.hpp:94
virtual void run()
Run the work item.
Definition workflow.hpp:122
std::function< void(void)> kernel
Kernel function.
Definition workflow.hpp:97
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:115
graph::input_nodes< T, SAFE_MATH > inputs
Input nodes.
Definition workflow.hpp:99
zero_item(graph::input_nodes< T, SAFE_MATH > in)
Construct a workflow item.
Definition workflow.hpp:107
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:269
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:2149
std::vector< std::pair< shared_variable< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > copy_nodes
Convenience type alias for copying buffers.
Definition node.hpp:2157
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:691
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:2153
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:706
Name space for workflows.
Definition workflow.hpp:14
order
Items order.
Definition workflow.hpp:16
@ pre_run_item
Pre items.
Definition workflow.hpp:18
@ post_run_item
Post items.
Definition workflow.hpp:22
@ run_item
Items.
Definition workflow.hpp:20