Graph Framework
Loading...
Searching...
No Matches
gpu::metal_context< SAFE_MATH > Class Template Reference

Class representing a metal gpu context. More...

#include <metal_context.hpp>

Public Member Functions

 metal_context (const size_t index)
 Construct a metal 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< float, SAFE_MATH > inputs, graph::output_nodes< float, SAFE_MATH > outputs, graph::shared_random_state< float, 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< float(void)> create_max_call (graph::shared_leaf< float, SAFE_MATH > &argument, std::function< void(void)> run)
 Create a max compute kernel calling function.
 
MTLCompileOptions * compile_options ()
 Get the compile options.
 
void wait ()
 Hold the current thread until the command buffer has completed.
 
void print_results (const size_t index, const graph::output_nodes< float, SAFE_MATH > &nodes)
 Print out the results.
 
float check_value (const size_t index, const graph::shared_leaf< float, SAFE_MATH > &node)
 Check the value.
 
void copy_to_device (graph::shared_leaf< float, SAFE_MATH > node, float *source)
 Copy buffer contents to the device.
 
void copy_to_host (graph::shared_leaf< float, SAFE_MATH > node, float *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< float, SAFE_MATH > &inputs, graph::output_nodes< float, SAFE_MATH > &outputs, graph::shared_random_state< float, 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< float, SAFE_MATH > &outputs, graph::map_nodes< float, SAFE_MATH > &setters, graph::shared_random_state< float, 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 reduction.
 
float * get_buffer (graph::shared_leaf< float, 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 = 1024
 Size of random state needed.
 

Detailed Description

template<bool SAFE_MATH = false>
class gpu::metal_context< SAFE_MATH >

Class representing a metal gpu context.

Template Parameters
SAFE_MATHUse Safe Math operations.

Constructor & Destructor Documentation

◆ metal_context()

template<bool SAFE_MATH = false>
gpu::metal_context< SAFE_MATH >::metal_context ( const size_t  index)
inline

Construct a metal context.

Parameters
[in]indexConcurrent index.

Member Function Documentation

◆ check_value()

template<bool SAFE_MATH = false>
float gpu::metal_context< SAFE_MATH >::check_value ( const size_t  index,
const graph::shared_leaf< float, 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<bool SAFE_MATH = false>
void gpu::metal_context< 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<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::copy_to_device ( graph::shared_leaf< float, SAFE_MATH >  node,
float *  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<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::copy_to_host ( graph::shared_leaf< float, SAFE_MATH >  node,
float *  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<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::create_header ( std::ostringstream &  source_buffer)
inline

Create the source header.

Parameters
[in,out]source_bufferSource buffer stream.

◆ create_kernel_call()

template<bool SAFE_MATH = false>
std::function< void(void)> gpu::metal_context< SAFE_MATH >::create_kernel_call ( const std::string  kernel_name,
graph::input_nodes< float, SAFE_MATH >  inputs,
graph::output_nodes< float, SAFE_MATH >  outputs,
graph::shared_random_state< float, 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<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::create_kernel_postfix ( std::ostringstream &  source_buffer,
graph::output_nodes< float, SAFE_MATH > &  outputs,
graph::map_nodes< float, SAFE_MATH > &  setters,
graph::shared_random_state< float, 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<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::create_kernel_prefix ( std::ostringstream &  source_buffer,
const std::string  name,
graph::input_nodes< float, SAFE_MATH > &  inputs,
graph::output_nodes< float, SAFE_MATH > &  outputs,
graph::shared_random_state< float, 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<bool SAFE_MATH = false>
std::function< float(void)> gpu::metal_context< SAFE_MATH >::create_max_call ( graph::shared_leaf< float, SAFE_MATH > &  argument,
std::function< void(void)>  run 
)
inline

Create a max compute kernel calling function.

Parameters
[in]argumentNode to reduce.
[in]runFunction to run before reduction.
Returns
A lambda function to run the kernel.

◆ create_reduction()

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

Create reduction.

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

◆ get_buffer()

template<bool SAFE_MATH = false>
float * gpu::metal_context< SAFE_MATH >::get_buffer ( graph::shared_leaf< float, SAFE_MATH > &  node)
inline

Get the buffer for a node.

Parameters
[in]nodeNode to get the buffer for.

◆ max_concurrency()

template<bool SAFE_MATH = false>
static size_t gpu::metal_context< SAFE_MATH >::max_concurrency ( )
inlinestatic

Get the maximum number of concurrent instances.

Returns
The maximum available concurrency.

◆ print_results()

template<bool SAFE_MATH = false>
void gpu::metal_context< SAFE_MATH >::print_results ( const size_t  index,
const graph::output_nodes< float, SAFE_MATH > &  nodes 
)
inline

Print out the results.

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

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