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>
88 std::function<T(
void)> max_kernel;
92 const size_t max_iterations;
112 const std::string name,
const size_t size,
115 const size_t max_iter=1000) :
117 tolarance(tol), max_iterations(max_iter) {
136 size_t iterations = 0;
137 T max_residule = max_kernel();
138 T last_max = std::numeric_limits<T>::max();
139 T off_last_max = std::numeric_limits<T>::max();
140 while (std::abs(max_residule) > std::abs(tolarance) &&
141 std::abs(last_max - max_residule) > std::abs(tolarance) &&
142 std::abs(off_last_max - max_residule) > std::abs(tolarance) &&
143 iterations++ < max_iterations) {
144 last_max = max_residule;
145 if (!(iterations%2)) {
146 off_last_max = max_residule;
148 max_residule = max_kernel();
153 assert(iterations < max_iterations &&
154 "Workitem failed to converge.");
155 if (iterations > max_iterations) {
156 std::cerr <<
"Workitem failed to converge with in given iterations."
158 std::cerr <<
"Minimum residule reached: " << max_residule
170 template<jit::
float_scalar T,
bool SAFE_MATH=false>
176 std::vector<std::unique_ptr<work_item<T, SAFE_MATH>>> preitems;
178 std::vector<std::unique_ptr<work_item<T, SAFE_MATH>>> items;
188 manager(
const size_t index) : context(index), add_reduction(false) {}
204 const std::string name,
const size_t size) {
225 const std::string name,
const size_t size) {
248 const std::string name,
const size_t size,
250 const size_t max_iter=1000) {
251 add_reduction =
true;
263 context.
compile(add_reduction);
265 for (
auto &item : preitems) {
266 item->create_kernel_call(context);
268 for (
auto &item : items) {
269 item->create_kernel_call(context);
277 for (
auto &item : preitems) {
286 for (
auto &item : items) {
328 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 workitem.
Definition workflow.hpp:85
virtual void create_kernel_call(jit::context< T, SAFE_MATH > &context)
Set the kernel function.
Definition workflow.hpp:126
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:108
virtual void run()
Run the workitem.
Definition workflow.hpp:135
Class representing a workflow manager.
Definition workflow.hpp:171
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:200
void run()
Run work items.
Definition workflow.hpp:285
void wait()
Wait for GPU queue to finish.
Definition workflow.hpp:294
void pre_run()
Run prework items.
Definition workflow.hpp:276
void copy_to_host(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy contexts of buffer to host.
Definition workflow.hpp:315
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:244
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:221
void print(const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
Print results.
Definition workflow.hpp:326
void copy_to_device(graph::shared_leaf< T, SAFE_MATH > &node, T *destination)
Copy buffer contents to the device.
Definition workflow.hpp:304
jit::context< T, SAFE_MATH > & get_context()
Get the jit context.
Definition workflow.hpp:348
manager(const size_t index)
Workflow manager constructor.
Definition workflow.hpp:188
void compile()
Compile the workflow items.
Definition workflow.hpp:262
T check_value(const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
Check the value.
Definition workflow.hpp:338
Class representing a workitem.
Definition workflow.hpp:22
virtual void run()
Run the workitem.
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:272
std::vector< shared_variable< T, SAFE_MATH > > input_nodes
Convenience type alias for a vector of inputs.
Definition node.hpp:1730
std::shared_ptr< leaf_node< T, SAFE_MATH > > shared_leaf
Convenience type alias for shared leaf nodes.
Definition node.hpp:673
std::vector< std::pair< shared_leaf< T, SAFE_MATH >, shared_variable< T, SAFE_MATH > > > map_nodes
Convenience type alias for maping end codes back to inputs.
Definition node.hpp:1734
std::vector< shared_leaf< T, SAFE_MATH > > output_nodes
Convenience type alias for a vector of output nodes.
Definition node.hpp:688
Name space for workflows.
Definition workflow.hpp:14