Graph Framework
Loading...
Searching...
No Matches
graph_c_binding.cpp File Reference

Implimentation of the c binding library. More...

Classes

struct  graph_c_context_type< T, SAFE_MATH >
 C context with specific type. More...
 

Functions

graph_c_contextgraph_construct_context (const enum graph_type type, const bool use_safe_math)
 Construct a C context.
 
void graph_destroy_context (graph_c_context *c)
 Destroy C context.
 
graph_node graph_variable (STRUCT_TAG graph_c_context *c, const size_t size, const char *symbol)
 Create variable node.
 
graph_node graph_constant (STRUCT_TAG graph_c_context *c, const double value)
 Create constant node.
 
void graph_set_variable (STRUCT_TAG graph_c_context *c, graph_node var, const void *source)
 Set a variable value.
 
graph_node graph_constant_c (STRUCT_TAG graph_c_context *c, const double real_value, const double img_value)
 Create complex constant node.
 
graph_node graph_pseudo_variable (STRUCT_TAG graph_c_context *c, graph_node var)
 Create a pseudo variable.
 
graph_node graph_remove_pseudo (STRUCT_TAG graph_c_context *c, graph_node var)
 Remove pseudo.
 
graph_node graph_add (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create add node.
 
graph_node graph_sub (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create Substract node.
 
graph_node graph_mul (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create Multiply node.
 
graph_node graph_div (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create Divide node.
 
graph_node graph_sqrt (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create Sqrt node.
 
graph_node graph_exp (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create exp node.
 
graph_node graph_log (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create log node.
 
graph_node graph_pow (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create Pow node.
 
graph_node graph_erfi (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create imaginary error function node.
 
graph_node graph_sin (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create sine node.
 
graph_node graph_cos (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create cosine node.
 
graph_node graph_atan (STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
 Create arctangent node.
 
graph_node graph_random_state (STRUCT_TAG graph_c_context *c, const uint32_t seed)
 Construct a random state node.
 
graph_node graph_random (STRUCT_TAG graph_c_context *c, graph_node arg)
 Create random node.
 
graph_node graph_piecewise_1D (STRUCT_TAG graph_c_context *c, graph_node arg, const double scale, const double offset, const void *source, const size_t source_size)
 Create 1D piecewise node.
 
graph_node graph_piecewise_2D (STRUCT_TAG graph_c_context *c, const size_t num_cols, graph_node x_arg, const double x_scale, const double x_offset, graph_node y_arg, const double y_scale, const double y_offset, const void *source, const size_t source_size)
 Create 2D piecewise node.
 
size_t graph_get_max_concurrency (graph_c_context *c)
 Create 2D piecewise node with complex arguments.
 
void graph_set_device_number (STRUCT_TAG graph_c_context *c, const size_t num)
 Choose the device number.
 
void graph_add_pre_item (STRUCT_TAG graph_c_context *c, graph_node *inputs, size_t num_inputs, graph_node *outputs, size_t num_outputs, graph_node *map_inputs, graph_node *map_outputs, size_t num_maps, graph_node random_state, const char *name, const size_t size)
 Add pre workflow item.
 
void graph_add_item (STRUCT_TAG graph_c_context *c, graph_node *inputs, size_t num_inputs, graph_node *outputs, size_t num_outputs, graph_node *map_inputs, graph_node *map_outputs, size_t num_maps, graph_node random_state, const char *name, const size_t size)
 Add workflow item.
 
void graph_add_converge_item (STRUCT_TAG graph_c_context *c, graph_node *inputs, size_t num_inputs, graph_node *outputs, size_t num_outputs, graph_node *map_inputs, graph_node *map_outputs, size_t num_maps, graph_node random_state, const char *name, const size_t size, const double tol, const size_t max_iter)
 Add a converge item.
 
void graph_compile (graph_c_context *c)
 Compile the work items.
 
void graph_pre_run (graph_c_context *c)
 Run pre work items.
 
void graph_run (graph_c_context *c)
 Run work items.
 
void graph_wait (graph_c_context *c)
 Wait for work items to complete.
 
void graph_copy_to_device (STRUCT_TAG graph_c_context *c, graph_node node, void *source)
 Copy data to a device buffer.
 
void graph_copy_to_host (STRUCT_TAG graph_c_context *c, graph_node node, void *destination)
 Copy data to a host buffer.
 
void graph_print (STRUCT_TAG graph_c_context *c, const size_t index, graph_node *nodes, const size_t num_nodes)
 Print a value from nodes.
 
graph_node graph_df (STRUCT_TAG graph_c_context *c, graph_node fnode, graph_node xnode)
 Take derivative ∂f∂x.
 

Detailed Description

Implimentation of the c binding library.

Function Documentation

◆ graph_add()

graph_node graph_add ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create add node.

Create Addition node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
left + right

◆ graph_add_converge_item()

void graph_add_converge_item ( STRUCT_TAG graph_c_context c,
graph_node inputs,
size_t  num_inputs,
graph_node outputs,
size_t  num_outputs,
graph_node map_inputs,
graph_node map_outputs,
size_t  num_maps,
graph_node  random_state,
const char *  name,
const size_t  size,
const double  tol,
const size_t  max_iter 
)

Add a converge item.

Parameters
[in]cThe graph C context.
[in]inputsArray of input nodes.
[in]num_inputsNumber of inputs.
[in]outputsArray of output nodes.
[in]num_outputsNumber of outputs.
[in]map_inputsArray of map input nodes.
[in]map_outputsArray of map output nodes.
[in]num_mapsNumber of maps.
[in]random_stateOptional random state, can be NULL if not used.
[in]nameName for the kernel.
[in]sizeNumber of elements to operate on.
[in]tolTolarance to converge the function to.
[in]max_iterMaximum number of iterations before giving up.

◆ graph_add_item()

void graph_add_item ( STRUCT_TAG graph_c_context c,
graph_node inputs,
size_t  num_inputs,
graph_node outputs,
size_t  num_outputs,
graph_node map_inputs,
graph_node map_outputs,
size_t  num_maps,
graph_node  random_state,
const char *  name,
const size_t  size 
)

Add workflow item.

Parameters
[in]cThe graph C context.
[in]inputsArray of input nodes.
[in]num_inputsNumber of inputs.
[in]outputsArray of output nodes.
[in]num_outputsNumber of outputs.
[in]map_inputsArray of map input nodes.
[in]map_outputsArray of map output nodes.
[in]num_mapsNumber of maps.
[in]random_stateOptional random state, can be NULL if not used.
[in]nameName for the kernel.
[in]sizeNumber of elements to operate on.

◆ graph_add_pre_item()

void graph_add_pre_item ( STRUCT_TAG graph_c_context c,
graph_node inputs,
size_t  num_inputs,
graph_node outputs,
size_t  num_outputs,
graph_node map_inputs,
graph_node map_outputs,
size_t  num_maps,
graph_node  random_state,
const char *  name,
const size_t  size 
)

Add pre workflow item.

Parameters
[in]cThe graph C context.
[in]inputsArray of input nodes.
[in]num_inputsNumber of inputs.
[in]outputsArray of output nodes.
[in]num_outputsNumber of outputs.
[in]map_inputsArray of map input nodes.
[in]map_outputsArray of map output nodes.
[in]num_mapsNumber of maps.
[in]random_stateOptional random state, can be NULL if not used.
[in]nameName for the kernel.
[in]sizeNumber of elements to operate on.

◆ graph_atan()

graph_node graph_atan ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create arctangent node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
atan(left, right)

◆ graph_compile()

void graph_compile ( graph_c_context c)

Compile the work items.

Parameters
[in]cThe graph C context.

◆ graph_constant()

graph_node graph_constant ( STRUCT_TAG graph_c_context c,
const double  value 
)

Create constant node.

Parameters
[in]cThe graph C context.
[in]valueThe value to create the constant.
Returns
The created constant.

◆ graph_constant_c()

graph_node graph_constant_c ( STRUCT_TAG graph_c_context c,
const double  real_value,
const double  img_value 
)

Create complex constant node.

Parameters
[in]cThe graph C context.
[in]real_valueThe real component.
[in]img_valueThe imaginary component.
Returns
The complex constant.

◆ graph_construct_context()

graph_c_context * graph_construct_context ( const enum graph_type  type,
const bool  use_safe_math 
)

Construct a C context.

Parameters
[in]typeBase type.
[in]use_safe_mathControl is safe math is used.
Returns
A contructed C context.

◆ graph_copy_to_device()

void graph_copy_to_device ( STRUCT_TAG graph_c_context c,
graph_node  node,
void *  source 
)

Copy data to a device buffer.

Parameters
[in]cThe graph C context.
[in]nodeNode to copy to.
[in]sourceSource to copy from.

◆ graph_copy_to_host()

void graph_copy_to_host ( STRUCT_TAG graph_c_context c,
graph_node  node,
void *  destination 
)

Copy data to a host buffer.

Parameters
[in]cThe graph C context.
[in]nodeNode to copy from.
[in]destinationHost side buffer to copy to.

◆ graph_cos()

graph_node graph_cos ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create cosine node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
cos(arg)

◆ graph_destroy_context()

void graph_destroy_context ( graph_c_context c)

Destroy C context.

Parameters
[in,out]cThe c context to delete.

◆ graph_df()

graph_node graph_df ( STRUCT_TAG graph_c_context c,
graph_node  fnode,
graph_node  xnode 
)

Take derivative ∂f∂x.

Parameters
[in]cThe graph C context.
[in]fnodeThe function expression to take the derivative of.
[in]xnodeThe expression to take the derivative with respect to.

◆ graph_div()

graph_node graph_div ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create Divide node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
left/right

◆ graph_erfi()

graph_node graph_erfi ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create imaginary error function node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
erfi(arg)

◆ graph_exp()

graph_node graph_exp ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create exp node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
exp(arg)

◆ graph_get_max_concurrency()

size_t graph_get_max_concurrency ( graph_c_context c)

Create 2D piecewise node with complex arguments.

Parameters
[in]cThe graph C context.
Returns
The number of concurrent devices.

◆ graph_log()

graph_node graph_log ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create log node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
log(arg)

◆ graph_mul()

graph_node graph_mul ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create Multiply node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
left*right

◆ graph_piecewise_1D()

graph_node graph_piecewise_1D ( STRUCT_TAG graph_c_context c,
graph_node  arg,
const double  scale,
const double  offset,
const void *  source,
const size_t  source_size 
)

Create 1D piecewise node.

Parameters
[in]cThe graph C context.
[in]argThe function argument.
[in]scaleScale factor argument.
[in]offsetOffset factor argument.
[in]sourceSource buffer to fill elements.
[in]source_sizeNumber of elements in the source buffer.
Returns
A 1D piecewise node.

◆ graph_piecewise_2D()

graph_node graph_piecewise_2D ( STRUCT_TAG graph_c_context c,
const size_t  num_cols,
graph_node  x_arg,
const double  x_scale,
const double  x_offset,
graph_node  y_arg,
const double  y_scale,
const double  y_offset,
const void *  source,
const size_t  source_size 
)

Create 2D piecewise node.

Parameters
[in]cThe graph C context.
[in]num_colsNumber of columns.
[in]x_argThe function x argument.
[in]x_scaleScale factor x argument.
[in]x_offsetOffset factor x argument.
[in]y_argThe function y argument.
[in]y_scaleScale factor y argument.
[in]y_offsetOffset factor y argument.
[in]sourceSource buffer to fill elements.
[in]source_sizeNumber of elements in the source buffer.
Returns
A 2D piecewise node.

◆ graph_pow()

graph_node graph_pow ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create Pow node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
pow(left, right)

◆ graph_pre_run()

void graph_pre_run ( graph_c_context c)

Run pre work items.

Parameters
[in]cThe graph C context.

◆ graph_print()

void graph_print ( STRUCT_TAG graph_c_context c,
const size_t  index,
graph_node nodes,
const size_t  num_nodes 
)

Print a value from nodes.

Parameters
[in]cThe graph C context.
[in]indexParticle index to print.
[in]nodesNodes to print.
[in]num_nodesNumber of nodes.

◆ graph_pseudo_variable()

graph_node graph_pseudo_variable ( STRUCT_TAG graph_c_context c,
graph_node  var 
)

Create a pseudo variable.

Parameters
[in]cThe graph C context.
[in]varThe variable to set.
Returns
THe pseudo variable.

◆ graph_random()

graph_node graph_random ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create random node.

Parameters
[in]cThe graph C context.
[in]argA random state node.
Returns
random(state)

◆ graph_random_state()

graph_node graph_random_state ( STRUCT_TAG graph_c_context c,
const uint32_t  seed 
)

Construct a random state node.

Parameters
[in]cThe graph C context.
[in]seedIntial random seed.
Returns
A random state node.

◆ graph_remove_pseudo()

graph_node graph_remove_pseudo ( STRUCT_TAG graph_c_context c,
graph_node  var 
)

Remove pseudo.

Parameters
[in]cThe graph C context.
[in]varThe variable to set.
Returns
The graph with pseudo variables removed.

◆ graph_run()

void graph_run ( graph_c_context c)

Run work items.

Parameters
[in]cThe graph C context.

◆ graph_set_device_number()

void graph_set_device_number ( STRUCT_TAG graph_c_context c,
const size_t  num 
)

Choose the device number.

Parameters
[in]cThe graph C context.
[in]numThe device number.

◆ graph_set_variable()

void graph_set_variable ( STRUCT_TAG graph_c_context c,
graph_node  var,
const void *  source 
)

Set a variable value.

Parameters
[in]cThe graph C context.
[in]varThe variable to set.
[in]sourceThe source pointer.

◆ graph_sin()

graph_node graph_sin ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create sine node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
sin(arg)

◆ graph_sqrt()

graph_node graph_sqrt ( STRUCT_TAG graph_c_context c,
graph_node  arg 
)

Create Sqrt node.

Parameters
[in]cThe graph C context.
[in]argThe left opperand.
Returns
sqrt(arg)

◆ graph_sub()

graph_node graph_sub ( STRUCT_TAG graph_c_context c,
graph_node  left,
graph_node  right 
)

Create Substract node.

Parameters
[in]cThe graph C context.
[in]leftThe left opperand.
[in]rightThe right opperand.
Returns
left - right

◆ graph_variable()

graph_node graph_variable ( STRUCT_TAG graph_c_context c,
const size_t  size,
const char *  symbol 
)

Create variable node.

Parameters
[in]cThe graph C context.
[in]sizeSize of the data buffer.
[in]symbolSymbol of the variable used in equations.
Returns
The created variable.

◆ graph_wait()

void graph_wait ( graph_c_context c)

Wait for work items to complete.

Parameters
[in]cThe graph C context.