Graph Framework
Loading...
Searching...
No Matches
gpu::cpu_context< T, SAFE_MATH > Class Template Reference

Class representing a cpu context. More...

#include <cpu_context.hpp>

Public Member Functions

 cpu_context (const size_t index)
 Construct a cpu context.
 
void compile (const std::string kernel_source, std::vector< std::string > names, const bool add_reduction=false)
 Compile the kernels.
 
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, const jit::texture1d_list &tex1d_list, const jit::texture2d_list &tex2d_list)
 Create a kernel calling function.
 
std::function< T(void)> create_max_call (graph::shared_leaf< T, SAFE_MATH > &argument, std::function< void(void)> run)
 Create a max compute pipeline.
 
void wait ()
 Hold the current thread until the command buffer has completed.
 
void print_results (const size_t index, const graph::output_nodes< T, SAFE_MATH > &nodes)
 Print out the results.
 
check_value (const size_t index, const graph::shared_leaf< T, SAFE_MATH > &node)
 Check the value.
 
void copy_to_device (graph::shared_leaf< T, SAFE_MATH > node, T *source)
 Copy buffer contents to the device.
 
void copy_to_host (const graph::shared_leaf< T, SAFE_MATH > node, T *destination)
 Copy buffer contents to host.
 
void create_header (std::ostringstream &source_buffer)
 Create the source header.
 
void create_kernel_prefix (std::ostringstream &source_buffer, const std::string 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 size, const std::vector< bool > &is_constant, jit::register_map &registers, const jit::register_usage &usage, jit::texture1d_list &textures1d, jit::texture2d_list &textures2d)
 Create kernel prefix.
 
void create_kernel_postfix (std::ostringstream &source_buffer, graph::output_nodes< T, SAFE_MATH > &outputs, graph::map_nodes< T, SAFE_MATH > &setters, graph::shared_random_state< T, SAFE_MATH > state, jit::register_map &registers, jit::register_map &indices, const jit::register_usage &usage)
 Create kernel postfix.
 
void create_reduction (std::ostringstream &source_buffer, const size_t size)
 Create a reduction kernel.
 
T * get_buffer (graph::shared_leaf< T, SAFE_MATH > &node)
 Get the buffer for a node.
 

Static Public Member Functions

static size_t max_concurrency ()
 Get the maximum number of concurrent instances.
 
static std::string device_type ()
 Device discription.
 

Public Attributes

int remaining_const_memory
 Remaining constant memory in bytes. NOT USED.
 

Static Public Attributes

static constexpr size_t random_state_size = 1
 Size of random state needed.
 

Detailed Description

template<jit::float_scalar T, bool SAFE_MATH = false>
class gpu::cpu_context< T, SAFE_MATH >

Class representing a cpu context.

Template Parameters
TBase type of the calculation.
SAFE_MATHUse Safe Math operations.

Constructor & Destructor Documentation

◆ cpu_context()

template<jit::float_scalar T, bool SAFE_MATH = false>
gpu::cpu_context< T, SAFE_MATH >::cpu_context ( const size_t  index)
inline

Construct a cpu context.

Parameters
[in]indexConcurrent index. Not used.

Member Function Documentation

◆ check_value()

template<jit::float_scalar T, bool SAFE_MATH = false>
T gpu::cpu_context< T, SAFE_MATH >::check_value ( const size_t  index,
const graph::shared_leaf< T, SAFE_MATH > &  node 
)
inline

Check the value.

Parameters
[in]indexRay index to check value for.
[in]nodeNode to check the value for.
Returns
The value at the index.

◆ compile()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::compile ( const std::string  kernel_source,
std::vector< std::string >  names,
const bool  add_reduction = false 
)
inline

Compile the kernels.

Parameters
[in]kernel_sourceSource code buffer for the kernel.
[in]namesNames of the kernel functions.
[in]add_reductionInclude the reduction kernel.

◆ copy_to_device()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::copy_to_device ( graph::shared_leaf< T, SAFE_MATH >  node,
T *  source 
)
inline

Copy buffer contents to the device.

Parameters
[in]nodeNot to copy buffer to.
[in]sourceHost side buffer to copy from.

◆ copy_to_host()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::copy_to_host ( const graph::shared_leaf< T, SAFE_MATH >  node,
T *  destination 
)
inline

Copy buffer contents to host.

Parameters
[in]nodeNode to copy buffer from.
[in,out]destinationHost side buffer to copy to.

◆ create_header()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::create_header ( std::ostringstream &  source_buffer)
inline

Create the source header.

Parameters
[in,out]source_bufferSource buffer stream.

◆ create_kernel_call()

template<jit::float_scalar T, bool SAFE_MATH = false>
std::function< void(void)> gpu::cpu_context< T, SAFE_MATH >::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,
const jit::texture1d_list tex1d_list,
const jit::texture2d_list tex2d_list 
)
inline

Create a kernel calling function.

Parameters
[in]kernel_nameName of the kernel for later reference.
[in]inputsInput nodes of the kernel.
[in]outputsOutput nodes of the kernel.
[in]stateRandom states.
[in]num_raysNumber of rays to trace.
[in]tex1d_listList of 1D textures.
[in]tex2d_listList of 1D textures.
Returns
A lambda function to run the kernel.

◆ create_kernel_postfix()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::create_kernel_postfix ( std::ostringstream &  source_buffer,
graph::output_nodes< T, SAFE_MATH > &  outputs,
graph::map_nodes< T, SAFE_MATH > &  setters,
graph::shared_random_state< T, SAFE_MATH >  state,
jit::register_map registers,
jit::register_map indices,
const jit::register_usage usage 
)
inline

Create kernel postfix.

Parameters
[in,out]source_bufferSource buffer stream.
[in]outputsOutput nodes of the graph to compute.
[in]settersMap outputs back to input values.
[in]stateRandom states.
[in,out]registersMap of used registers.
[in,out]indicesMap of used indices.
[in]usageList of register usage count.

◆ create_kernel_prefix()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::create_kernel_prefix ( std::ostringstream &  source_buffer,
const std::string  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  size,
const std::vector< bool > &  is_constant,
jit::register_map registers,
const jit::register_usage usage,
jit::texture1d_list textures1d,
jit::texture2d_list textures2d 
)
inline

Create kernel prefix.

Parameters
[in,out]source_bufferSource buffer stream.
[in]nameName to call the kernel.
[in]inputsInput variables of the kernel.
[in]outputsOutput nodes of the graph to compute.
[in]stateRandom states.
[in]sizeSize of the input buffer.
[in]is_constantFlags if the input is read only.
[in,out]registersMap of used registers.
[in]usageList of register usage count.
[in]textures1dList of 1D kernel textures.
[in]textures2dList of 2D kernel textures.

◆ create_max_call()

template<jit::float_scalar T, bool SAFE_MATH = false>
std::function< T(void)> gpu::cpu_context< T, SAFE_MATH >::create_max_call ( graph::shared_leaf< T, SAFE_MATH > &  argument,
std::function< void(void)>  run 
)
inline

Create a max compute pipeline.

Parameters
[in]argumentNode to reduce.
[in]runFunction to run before reduction.

◆ create_reduction()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::create_reduction ( std::ostringstream &  source_buffer,
const size_t  size 
)
inline

Create a reduction kernel.

Parameters
[in,out]source_bufferSource buffer stream.
[in]sizeSize of the input buffer.

◆ get_buffer()

template<jit::float_scalar T, bool SAFE_MATH = false>
T * gpu::cpu_context< T, SAFE_MATH >::get_buffer ( graph::shared_leaf< T, SAFE_MATH > &  node)
inline

Get the buffer for a node.

GPU contexts have the concept of a host side and device side buffer which the CPU doesn't. Create a second map of host buffers and reference the memory pointer from that. This allows one thread to run the kernel while a different thread can use the results.

Parameters
[in]nodeNode to get the buffer for.

◆ max_concurrency()

template<jit::float_scalar T, bool SAFE_MATH = false>
static size_t gpu::cpu_context< T, SAFE_MATH >::max_concurrency ( )
inlinestatic

Get the maximum number of concurrent instances.

Returns
The maximum available concurrency.

◆ print_results()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::print_results ( const size_t  index,
const graph::output_nodes< T, SAFE_MATH > &  nodes 
)
inline

Print out the results.

Parameters
[in]indexParticle index to print.
[in]nodesNodes to output.

◆ wait()

template<jit::float_scalar T, bool SAFE_MATH = false>
void gpu::cpu_context< T, SAFE_MATH >::wait ( )
inline

Hold the current thread until the command buffer has completed.

This syncs the host buffers with the kernel arguments so a kernel can run while another thread reads the results.


The documentation for this class was generated from the following file: