Documentation for linking into a C code base.
This section assumes the reader is already familar with developing C codes. The simplist method to link framework code into a C code is to create a C++ function with
extern "C" {
void c_callable_function() {
const T b = 0.6;
auto y = m*x + b;
auto dydx = y->df(x);
x->set({1.0, 2.0, 3.0});
work.add_item({
}, {
y, dydx
}, {}, NULL, "my_first_kernel", 3);
work.compile();
work.run();
work.print(0, {x, y, dydx});
work.print(1, {x, y, dydx});
work.print(2, {x, y, dydx});
}
}
Class representing a workflow manager.
Definition workflow.hpp:171
constexpr shared_leaf< T, SAFE_MATH > zero()
Forward declare for zero.
Definition node.hpp:994
shared_variable< T, SAFE_MATH > variable_cast(shared_leaf< T, SAFE_MATH > x)
Cast to a variable node.
Definition node.hpp:1746
shared_leaf< T, SAFE_MATH > variable(const size_t s, const std::string &symbol)
Construct a variable.
Definition node.hpp:1674
void c_binding() {
const bool use_safe_math = 0;
double temp[3];
temp[0] = 1.0;
temp[1] = 2.0;
temp[2] = 3.0;
graoh_set_variable(c_context, x, temp);
inputs[0] = x;
outputs[0] = y;
outputs[1] = dydx;
"x", 3);
inputs2[0] = x;
inputs2[1] = y;
inputs2[2] = dydx;
}
graph_node graph_constant(STRUCT_TAG graph_c_context *c, const double value)
Create constant node.
Definition graph_c_binding.cpp:164
graph_node graph_add(STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
Create add node.
Definition graph_c_binding.cpp:498
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.
Definition graph_c_binding.cpp:3118
void graph_compile(graph_c_context *c)
Compile the work items.
Definition graph_c_binding.cpp:2813
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.
Definition graph_c_binding.cpp:2127
graph_node graph_mul(STRUCT_TAG graph_c_context *c, graph_node left, graph_node right)
Create Multiply node.
Definition graph_c_binding.cpp:630
void graph_set_device_number(STRUCT_TAG graph_c_context *c, const size_t num)
Choose the device number.
Definition graph_c_binding.cpp:1729
graph_node graph_variable(STRUCT_TAG graph_c_context *c, const size_t size, const char *symbol)
Create variable node.
Definition graph_c_binding.cpp:99
graph_c_context * graph_construct_context(const enum graph_type type, const bool use_safe_math)
Construct a C context.
Definition graph_c_binding.cpp:40
void graph_run(graph_c_context *c)
Run work items.
Definition graph_c_binding.cpp:2911
graph_node graph_df(STRUCT_TAG graph_c_context *c, graph_node fnode, graph_node xnode)
Take derivative ∂f∂x.
Definition graph_c_binding.cpp:3204
void graph_destroy_context(graph_c_context *c)
Destroy C context.
Definition graph_c_binding.cpp:87
Header file for the c binding library.
void * graph_node
Graph node type for C interface.
Definition graph_c_binding.h:147
graph_c_context type.
Definition graph_c_binding.h:162