Oakfield API Documentation 1.0.0
Numerical core APIs
Loading...
Searching...
No Matches
kernel_ir.h File Reference

Intermediate representation facilities for libsimcore operator fusion. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "field.h"
#include "math/special_functions.h"
#include "operator_identity.h"
Include dependency graph for kernel_ir.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SimIRType
 Type descriptor carried by each IR node. More...
 
union  SimIRDomainPayload
 Exact scalar payload used by scalar-domain-aware evaluators. More...
 
struct  SimIRDomainValue
 Scalar-domain-aware evaluation result. More...
 
struct  SimIRShape
 Maximum rank supported by shape descriptors. More...
 
struct  SimIRDiffSpec
 Optional metadata for creating differential nodes. More...
 
struct  SimIRWarpGuard
 Continuity guard metadata attached to warp specifications. More...
 
struct  SimIRWarpSpec
 Metadata for creating analytic warp nodes. More...
 
struct  SimIRNoiseSpec
 Optional metadata for creating stochastic noise nodes. More...
 
struct  SimIRNode
 Node record in a symbolic kernel IR expression graph. More...
 
struct  SimIRStatefulSpec
 Metadata for creating stateful IR nodes. More...
 
struct  SimIRBuilder
 Monotonic arena for IR node allocation. More...
 
struct  SimIREvaluatorComplex
 Callback surface for evaluating complex-valued IR expressions. More...
 
struct  SimIREvaluator
 Callback surface for evaluating real-valued IR expressions. More...
 
struct  SimIREvaluatorDomain
 Callback surface for evaluating scalar-domain-aware IR expressions. More...
 

Macros

#define SIM_IR_INVALID_NODE   ((SimIRNodeId)SIZE_MAX)
 
#define SIM_IR_INVALID_CONSTANT_INDEX   ((size_t)SIZE_MAX)
 
#define SIM_IR_SMALL_CONSTANT_CAPACITY   4U
 Generic IR node representation.
 

Typedefs

typedef size_t SimIRNodeId
 
typedef enum SimIRValueKind SimIRValueKind
 Enumerates the value category for an IR expression.
 
typedef struct SimIRType SimIRType
 Type descriptor carried by each IR node.
 
typedef union SimIRDomainPayload SimIRDomainPayload
 Exact scalar payload used by scalar-domain-aware evaluators.
 
typedef struct SimIRDomainValue SimIRDomainValue
 Scalar-domain-aware evaluation result.
 
typedef struct SimIRShape SimIRShape
 Maximum rank supported by shape descriptors.
 
typedef enum SimIRBoundaryPolicy SimIRBoundaryPolicy
 Boundary handling policy for differential operators.
 
typedef enum SimIRDiffMethod SimIRDiffMethod
 Finite-difference stencil selection for differential operators.
 
typedef enum SimIRNoiseLaw SimIRNoiseLaw
 Noise law describing the stochastic calculus interpretation.
 
typedef enum SimIRNoiseDistribution SimIRNoiseDistribution
 Probability distribution used when sampling stochastic nodes.
 
typedef enum SimIRParamKind SimIRParamKind
 Runtime parameter identifiers referenced by PARAM nodes.
 
typedef struct SimIRDiffSpec SimIRDiffSpec
 Optional metadata for creating differential nodes.
 
typedef enum SimIRWarpProfile SimIRWarpProfile
 Supported analytic warp profiles for dedicated IR nodes.
 
typedef enum SimIRCallKind SimIRCallKind
 Built-in call identifiers for unary analytic functions.
 
typedef struct SimIRWarpGuard SimIRWarpGuard
 Continuity guard metadata attached to warp specifications.
 
typedef struct SimIRWarpSpec SimIRWarpSpec
 Metadata for creating analytic warp nodes.
 
typedef struct SimIRNoiseSpec SimIRNoiseSpec
 Optional metadata for creating stochastic noise nodes.
 
typedef enum SimIRNodeType SimIRNodeType
 Enumerates IR node categories.
 
typedef SimResult(* SimIRStatefulEvalFn) (void *userdata, const struct KernelIR *kernel, size_t element_index, size_t component, double *out_value)
 Callback signature for stateful IR nodes.
 
typedef struct SimIRNode SimIRNode
 Node record in a symbolic kernel IR expression graph.
 
typedef struct SimIRStatefulSpec SimIRStatefulSpec
 Metadata for creating stateful IR nodes.
 
typedef struct SimIRBuilder SimIRBuilder
 Monotonic arena for IR node allocation.
 
typedef SimResult(* SimIRFieldEvalFn) (void *userdata, size_t field_id, SimIRType type, double *out_value)
 Resolve a real-valued field reference during IR evaluation.
 
typedef SimResult(* SimIRDiffEvalFn) (void *userdata, const SimIRBuilder *builder, const SimIRNode *node, SimIRNodeId operand, double operand_value, double *out_value)
 Evaluate a real-valued differential node during IR evaluation.
 
typedef SimResult(* SimIRNoiseEvalFn) (void *userdata, const SimIRNode *node, double *out_value)
 Sample a real-valued stochastic node during IR evaluation.
 
typedef SimResult(* SimIRParamEvalFn) (void *userdata, SimIRParamKind param, double *out_value)
 Resolve a real-valued runtime parameter during IR evaluation.
 
typedef SimResult(* SimIRFieldEvalFnComplex) (void *userdata, size_t field_id, SimIRType type, SimComplexDouble *out_value)
 Resolve a complex-valued field reference during IR evaluation.
 
typedef SimResult(* SimIRDiffEvalFnComplex) (void *userdata, const SimIRBuilder *builder, const SimIRNode *node, SimIRNodeId operand, SimComplexDouble operand_value, SimComplexDouble *out_value)
 Evaluate a complex-valued differential node during IR evaluation.
 
typedef SimResult(* SimIRNoiseEvalFnComplex) (void *userdata, const SimIRNode *node, SimComplexDouble *out_value)
 Sample a complex-valued stochastic node during IR evaluation.
 
typedef struct SimIREvaluatorComplex SimIREvaluatorComplex
 Callback surface for evaluating complex-valued IR expressions.
 
typedef struct SimIREvaluator SimIREvaluator
 Callback surface for evaluating real-valued IR expressions.
 
typedef SimResult(* SimIRFieldEvalFnDomain) (void *userdata, size_t field_id, SimIRType type, SimScalarDomain domain, SimIRDomainValue *out_value)
 Resolve a scalar-domain-aware field reference during IR evaluation.
 
typedef SimResult(* SimIRDiffEvalFnDomain) (void *userdata, const SimIRBuilder *builder, const SimIRNode *node, SimIRNodeId operand, SimScalarDomain domain, SimIRDomainValue operand_value, SimIRDomainValue *out_value)
 Evaluate a scalar-domain-aware differential node during IR evaluation.
 
typedef SimResult(* SimIRNoiseEvalFnDomain) (void *userdata, const SimIRNode *node, SimScalarDomain domain, SimIRDomainValue *out_value)
 Sample a scalar-domain-aware stochastic node during IR evaluation.
 
typedef SimResult(* SimIRParamEvalFnDomain) (void *userdata, SimIRParamKind param, SimScalarDomain domain, SimIRDomainValue *out_value)
 Resolve a scalar-domain-aware runtime parameter during IR evaluation.
 
typedef struct SimIREvaluatorDomain SimIREvaluatorDomain
 Callback surface for evaluating scalar-domain-aware IR expressions.
 

Enumerations

enum  SimIRValueKind { SIM_IR_VALUE_SCALAR = 0 , SIM_IR_VALUE_VECTOR }
 Enumerates the value category for an IR expression. More...
 
enum  SimIRBoundaryPolicy { SIM_IR_BOUNDARY_NEUMANN = 0 , SIM_IR_BOUNDARY_DIRICHLET , SIM_IR_BOUNDARY_PERIODIC , SIM_IR_BOUNDARY_REFLECTIVE }
 Boundary handling policy for differential operators. More...
 
enum  SimIRDiffMethod { SIM_IR_DIFF_METHOD_AUTO = 0 , SIM_IR_DIFF_METHOD_CENTRAL , SIM_IR_DIFF_METHOD_FORWARD , SIM_IR_DIFF_METHOD_BACKWARD }
 Finite-difference stencil selection for differential operators. More...
 
enum  SimIRNoiseLaw { SIM_IR_NOISE_LAW_ITO = 0 , SIM_IR_NOISE_LAW_STRATONOVICH }
 Noise law describing the stochastic calculus interpretation. More...
 
enum  SimIRNoiseDistribution { SIM_IR_NOISE_DISTRIBUTION_UNIFORM = 0 , SIM_IR_NOISE_DISTRIBUTION_GAUSSIAN }
 Probability distribution used when sampling stochastic nodes. More...
 
enum  SimIRParamKind { SIM_IR_PARAM_DT = 0 , SIM_IR_PARAM_STEP_INDEX , SIM_IR_PARAM_SQRT_DT , SIM_IR_PARAM_TIME }
 Runtime parameter identifiers referenced by PARAM nodes. More...
 
enum  SimIRWarpProfile {
  SIM_IR_WARP_PROFILE_DIGAMMA = 0 , SIM_IR_WARP_PROFILE_TRIGAMMA = 1 , SIM_IR_WARP_PROFILE_DIGAMMA_7_TAIL = 2 , SIM_IR_WARP_PROFILE_DIGAMMA_5_TAIL = 3 ,
  SIM_IR_WARP_PROFILE_DIGAMMA_ADAPTIVE = 4 , SIM_IR_WARP_PROFILE_DIGAMMA_MORTICI = 5
}
 Supported analytic warp profiles for dedicated IR nodes. More...
 
enum  SimIRCallKind {
  SIM_IR_CALL_SIN = 0 , SIM_IR_CALL_COS , SIM_IR_CALL_EXP , SIM_IR_CALL_ABS ,
  SIM_IR_CALL_LOG , SIM_IR_CALL_TANH , SIM_IR_CALL_SINH , SIM_IR_CALL_SIGN
}
 Built-in call identifiers for unary analytic functions. More...
 
enum  SimIRNodeType {
  SIM_IR_NODE_CONSTANT = 0 , SIM_IR_NODE_FIELD_REF , SIM_IR_NODE_ADD , SIM_IR_NODE_SUB ,
  SIM_IR_NODE_MUL , SIM_IR_NODE_DIV , SIM_IR_NODE_POW , SIM_IR_NODE_DIFF ,
  SIM_IR_NODE_NOISE , SIM_IR_NODE_WARP , SIM_IR_NODE_PARAM , SIM_IR_NODE_COMPLEX_PACK ,
  SIM_IR_NODE_COMPLEX_ROTATE , SIM_IR_NODE_INDEX , SIM_IR_NODE_CALL , SIM_IR_NODE_FLOOR ,
  SIM_IR_NODE_MOD , SIM_IR_NODE_COORD , SIM_IR_NODE_STATEFUL
}
 Enumerates IR node categories. More...
 

Functions

SimResult sim_ir_warp_sample_response (const struct SimWarpSampleSpec *spec, SimIRWarpProfile profile, double tolerance, SimSpecialFallbackFn fallback, void *fallback_userdata, double *out_response)
 
SimResult sim_ir_builder_init (SimIRBuilder *builder)
 Initialize an empty IR builder.
 
void sim_ir_builder_set_default_boundary (SimIRBuilder *builder, SimIRBoundaryPolicy boundary)
 Set the default boundary policy used by shorthand differential helpers.
 
void sim_ir_builder_reset (SimIRBuilder *builder)
 Reset builder counts while retaining allocated storage.
 
void sim_ir_builder_apply_opcode (SimIRBuilder *builder, SimIROpcode opcode, bool preserve_existing)
 Apply a semantic opcode to nodes stored in a builder.
 
SimResult sim_ir_builder_apply_opcode_reachable (SimIRBuilder *builder, SimIROpcode opcode, bool preserve_existing, const SimIRNodeId *roots, size_t root_count)
 Apply a semantic opcode to reachable nodes starting from the provided roots.
 
SimResult sim_ir_collect_reachable (const SimIRBuilder *builder, const SimIRNodeId *roots, size_t root_count, unsigned char *out_reachable, size_t reachable_count)
 Mark nodes reachable from a set of roots.
 
void sim_ir_diff_spec_init (SimIRDiffSpec *spec, const SimIRBuilder *builder)
 Initialize a diff spec with safe defaults.
 
void sim_ir_builder_destroy (SimIRBuilder *builder)
 Release resources held by an IR builder.
 
const SimIRNodesim_ir_builder_get (const SimIRBuilder *builder, SimIRNodeId id)
 Retrieve an immutable pointer to a node.
 
SimIRType sim_ir_builder_node_type (const SimIRBuilder *builder, SimIRNodeId id)
 Query the value type of a node.
 
SimWarpLevel sim_ir_builder_node_warp_class (const SimIRBuilder *builder, SimIRNodeId id)
 Retrieve the warp classification associated with a node.
 
SimResult sim_ir_builder_set_node_warp_class (SimIRBuilder *builder, SimIRNodeId id, SimWarpLevel warp_class)
 Assign a warp classification to a node for downstream code generation.
 
SimIRNodeId sim_ir_builder_constant_typed (SimIRBuilder *builder, double value, SimIRType type)
 Create a constant node with explicit type annotation.
 
SimIRNodeId sim_ir_builder_constant_i64_typed (SimIRBuilder *builder, int64_t value, SimIRType type)
 Create an exact signed integer constant node with explicit type annotation.
 
SimIRNodeId sim_ir_builder_constant_u64_typed (SimIRBuilder *builder, uint64_t value, SimIRType type)
 Create an exact unsigned integer constant node with explicit type annotation.
 
SimIRNodeId sim_ir_builder_constant_vector_typed (SimIRBuilder *builder, const double *values, size_t components, SimIRType type)
 Create a vector constant node with explicit type annotation.
 
SimIRNodeId sim_ir_builder_constant_complex (SimIRBuilder *builder, double real, double imag)
 Create a complex constant node from real/imag components.
 
SimIRNodeId sim_ir_builder_constant_vector (SimIRBuilder *builder, const double *values, size_t components)
 Add a per-lane constant vector to the builder and return a node id.
 
bool sim_ir_kernel_has_unsupported_complex_semantics (const struct KernelIR *kernel)
 Query whether a kernel contains true complex-domain nodes whose semantics are not representable by the simple pointwise GPU emitters.
 
SimIRNodeId sim_ir_builder_constant (SimIRBuilder *builder, double value)
 Create a constant node.
 
SimIRNodeId sim_ir_builder_param (SimIRBuilder *builder, SimIRParamKind param)
 Create a runtime parameter node.
 
SimIRNodeId sim_ir_builder_index (SimIRBuilder *builder)
 Create a linear element-index node.
 
SimIRNodeId sim_ir_builder_call (SimIRBuilder *builder, SimIRCallKind kind, SimIRNodeId operand)
 Create a unary analytic call node (elementwise for vector values).
 
SimIRNodeId sim_ir_builder_floor (SimIRBuilder *builder, SimIRNodeId operand)
 Create a floor node.
 
SimIRNodeId sim_ir_builder_mod (SimIRBuilder *builder, SimIRNodeId lhs, SimIRNodeId rhs)
 Create a modulo node.
 
SimIRNodeId sim_ir_builder_coord (SimIRBuilder *builder, size_t field_id, size_t axis)
 Create a coordinate lookup node.
 
SimIRNodeId sim_ir_builder_field_ref_typed (SimIRBuilder *builder, size_t field_id, SimIRType type)
 Create a field reference node with an explicit value type.
 
SimIRNodeId sim_ir_builder_field_ref (SimIRBuilder *builder, size_t field_id)
 Create a field reference node.
 
SimIRNodeId sim_ir_builder_binary (SimIRBuilder *builder, SimIRNodeType type, SimIRNodeId lhs, SimIRNodeId rhs)
 Create a binary operation node.
 
SimIRNodeId sim_ir_builder_pow (SimIRBuilder *builder, SimIRNodeId lhs, SimIRNodeId rhs)
 Create a power node (pow for real, cpow for complex).
 
SimIRNodeId sim_ir_builder_diff_spec (SimIRBuilder *builder, const SimIRDiffSpec *spec)
 Create a differential term node using an extended specification.
 
SimIRNodeId sim_ir_builder_diff (SimIRBuilder *builder, SimIRNodeId operand, size_t axis, double dx, double scale)
 Create a differential term node.
 
SimIRNodeId sim_ir_builder_noise_spec (SimIRBuilder *builder, const SimIRNoiseSpec *spec)
 Create a stochastic noise node with extended metadata.
 
SimIRNodeId sim_ir_builder_stateful_spec (SimIRBuilder *builder, const SimIRStatefulSpec *spec)
 Create a stateful callback node with extended metadata.
 
SimIRNodeId sim_ir_builder_stateful (SimIRBuilder *builder, SimIRStatefulEvalFn eval, void *userdata, const char *label)
 Create a stateful callback node with a scalar result type.
 
SimIRNodeId sim_ir_builder_noise (SimIRBuilder *builder, uint32_t seed, double amplitude)
 Create a stochastic noise node.
 
SimIRNodeId sim_ir_builder_warp_spec (SimIRBuilder *builder, const SimIRWarpSpec *spec)
 Create an analytic warp node using the extended specification.
 
SimIRNodeId sim_ir_builder_warp (SimIRBuilder *builder, SimIRNodeId operand, SimIRWarpProfile profile, double bias, double delta, double lambda)
 Create an analytic warp node with explicit parameters.
 
SimIRNodeId sim_ir_builder_complex_pack (SimIRBuilder *builder, SimIRNodeId real, SimIRNodeId imag)
 Pack real/imag scalar nodes into a complex-valued vector.
 
SimIRNodeId sim_ir_builder_complex_rotate (SimIRBuilder *builder, SimIRNodeId operand, SimIRNodeId angle)
 Create a complex rotation node using a scalar angle.
 
SimIRType sim_ir_type_scalar (void)
 Construct a scalar value type descriptor.
 
SimIRType sim_ir_type_scalar_domain_typed (SimScalarDomain domain)
 Construct a scalar value type descriptor for an explicit scalar domain.
 
SimIRType sim_ir_type_vector (size_t components)
 Construct a vector value type descriptor with the requested lane count.
 
SimIRType sim_ir_type_complex (void)
 Construct a complex scalar value type descriptor (2 lanes).
 
bool sim_ir_type_is_scalar (SimIRType type)
 Return true if the provided type describes a scalar expression.
 
bool sim_ir_type_equal (SimIRType lhs, SimIRType rhs)
 Compare two type descriptors for equality.
 
SimScalarDomain sim_ir_type_scalar_domain (SimIRType type)
 Return the scalar-domain descriptor attached to an IR type.
 
double sim_ir_warp_profile_eval (SimIRWarpProfile profile, double x, double tolerance)
 Evaluate a warp profile at the provided sample.
 
double sim_ir_warp_difference (SimIRWarpProfile profile, double sample, double delta, double tolerance)
 Compute the symmetric warp difference f(x+δ) − f(x−δ).
 
SimResult sim_ir_evaluate_domain (const SimIRBuilder *builder, SimIRNodeId root, const SimIREvaluatorDomain *evaluator, SimIRDomainValue *out_value)
 Evaluate an IR expression using a unified scalar-domain evaluator surface.
 
SimResult sim_ir_evaluate (const SimIRBuilder *builder, SimIRNodeId root, const SimIREvaluator *evaluator, double *out_value)
 Evaluate an IR expression recursively using user-provided callbacks.
 
SimResult sim_ir_evaluate_complex (const SimIRBuilder *builder, SimIRNodeId root, const SimIREvaluatorComplex *evaluator, SimComplexDouble *out_value)
 Evaluate an IR expression recursively using complex-valued callbacks.
 

Detailed Description

Intermediate representation facilities for libsimcore operator fusion.

KernelIR is a typed expression graph used by operators and backends to describe pointwise numeric work independently of a concrete execution engine. Builders own node and constant-pool storage; backend launch packages borrow builders, field bindings, outputs, and runtime parameters only for the duration of a launch.

Macro Definition Documentation

◆ SIM_IR_INVALID_NODE

#define SIM_IR_INVALID_NODE   ((SimIRNodeId)SIZE_MAX)

Sentinel value returned when node creation fails.

Typedef Documentation

◆ SimIRNodeId

typedef size_t SimIRNodeId

Identifier for an IR node.

Enumeration Type Documentation

◆ SimIRBoundaryPolicy

Boundary handling policy for differential operators.

Enumerator
SIM_IR_BOUNDARY_NEUMANN 

Zero-gradient boundary (mirrors center value).

SIM_IR_BOUNDARY_DIRICHLET 

Fixed-value boundary (assumed zero when unspecified).

SIM_IR_BOUNDARY_PERIODIC 

Wrap indices across the domain.

SIM_IR_BOUNDARY_REFLECTIVE 

Reflect indices to remain in bounds.

◆ SimIRCallKind

Built-in call identifiers for unary analytic functions.

Enumerator
SIM_IR_CALL_SIN 

Sine function.

SIM_IR_CALL_COS 

Cosine function.

SIM_IR_CALL_EXP 

Exponential function.

SIM_IR_CALL_ABS 

Absolute value.

SIM_IR_CALL_LOG 

Natural logarithm.

SIM_IR_CALL_TANH 

Hyperbolic tangent.

SIM_IR_CALL_SINH 

Hyperbolic sine.

SIM_IR_CALL_SIGN 

Sign (copysign(1, x)).

◆ SimIRDiffMethod

Finite-difference stencil selection for differential operators.

Enumerator
SIM_IR_DIFF_METHOD_AUTO 

Adaptive: central when possible, else one-sided.

SIM_IR_DIFF_METHOD_CENTRAL 

Central difference (uses boundary substitution when needed).

SIM_IR_DIFF_METHOD_FORWARD 

Forward difference.

SIM_IR_DIFF_METHOD_BACKWARD 

Backward difference.

◆ SimIRNodeType

Enumerates IR node categories.

Enumerator
SIM_IR_NODE_CONSTANT 

Scalar literal.

SIM_IR_NODE_FIELD_REF 

Reference to a field.

SIM_IR_NODE_ADD 

Binary addition.

SIM_IR_NODE_SUB 

Binary subtraction.

SIM_IR_NODE_MUL 

Binary multiplication.

SIM_IR_NODE_DIV 

Binary division.

SIM_IR_NODE_POW 

Binary power (pow for real, cpow for complex).

SIM_IR_NODE_DIFF 

Differential term (finite difference placeholder).

SIM_IR_NODE_NOISE 

Stochastic noise term.

SIM_IR_NODE_WARP 

Analytic warp response.

SIM_IR_NODE_PARAM 

Runtime parameter lookup (e.g., dt).

SIM_IR_NODE_COMPLEX_PACK 

Pack real/imag scalars into a complex vector.

SIM_IR_NODE_COMPLEX_ROTATE 

Complex phase rotation by a scalar angle.

SIM_IR_NODE_INDEX 

Linear element index within the field.

SIM_IR_NODE_CALL 

Unary analytic call node (sin/cos/exp/abs/log).

SIM_IR_NODE_FLOOR 

Floor operation on a scalar operand.

SIM_IR_NODE_MOD 

Modulo operation on scalar operands.

SIM_IR_NODE_COORD 

Coordinate lookup along an axis.

SIM_IR_NODE_STATEFUL 

Stateful callback-driven node (CPU-only).

◆ SimIRNoiseDistribution

Probability distribution used when sampling stochastic nodes.

Enumerator
SIM_IR_NOISE_DISTRIBUTION_UNIFORM 

Uniform samples in [-amplitude, amplitude].

SIM_IR_NOISE_DISTRIBUTION_GAUSSIAN 

Gaussian samples with stddev = amplitude.

◆ SimIRNoiseLaw

Noise law describing the stochastic calculus interpretation.

Enumerator
SIM_IR_NOISE_LAW_ITO 

Itô interpretation (default).

SIM_IR_NOISE_LAW_STRATONOVICH 

Stratonovich interpretation.

◆ SimIRParamKind

Runtime parameter identifiers referenced by PARAM nodes.

Enumerator
SIM_IR_PARAM_DT 

Current timestep (seconds).

SIM_IR_PARAM_STEP_INDEX 

Monotonic step index (integer-valued).

SIM_IR_PARAM_SQRT_DT 

Square root of timestep (seconds^0.5).

SIM_IR_PARAM_TIME 

Current simulation time (seconds).

◆ SimIRValueKind

Enumerates the value category for an IR expression.

Enumerator
SIM_IR_VALUE_SCALAR 

Scalar-valued expression.

SIM_IR_VALUE_VECTOR 

Vector-valued expression with SimIRType::components lanes.

◆ SimIRWarpProfile

Supported analytic warp profiles for dedicated IR nodes.

Enumerator
SIM_IR_WARP_PROFILE_DIGAMMA 

Digamma warp (psi, 12-tail default).

SIM_IR_WARP_PROFILE_TRIGAMMA 

Trigamma warp (psi_1).

SIM_IR_WARP_PROFILE_DIGAMMA_7_TAIL 

Digamma (7-term Stirling tail).

SIM_IR_WARP_PROFILE_DIGAMMA_5_TAIL 

Digamma (5-term Stirling tail).

SIM_IR_WARP_PROFILE_DIGAMMA_ADAPTIVE 

Digamma (adaptive-tail).

SIM_IR_WARP_PROFILE_DIGAMMA_MORTICI 

Digamma (Mortici speedy).

Function Documentation

◆ sim_ir_builder_apply_opcode()

void sim_ir_builder_apply_opcode ( SimIRBuilder builder,
SimIROpcode  opcode,
bool  preserve_existing 
)

Apply a semantic opcode to nodes stored in a builder.

Parameters
builderTarget builder.
opcodeOpcode to assign (falls back to OAK_OP_MISC when invalid).
preserve_existingWhen true, only nodes tagged OAK_OP_MISC are updated.

◆ sim_ir_builder_apply_opcode_reachable()

SimResult sim_ir_builder_apply_opcode_reachable ( SimIRBuilder builder,
SimIROpcode  opcode,
bool  preserve_existing,
const SimIRNodeId roots,
size_t  root_count 
)

Apply a semantic opcode to reachable nodes starting from the provided roots.

Parameters
builderTarget builder.
opcodeOpcode to assign (falls back to OAK_OP_MISC when invalid).
preserve_existingWhen true, only nodes tagged OAK_OP_MISC are updated.
rootsArray of root node identifiers to traverse.
root_countNumber of roots in roots.

◆ sim_ir_builder_binary()

SimIRNodeId sim_ir_builder_binary ( SimIRBuilder builder,
SimIRNodeType  type,
SimIRNodeId  lhs,
SimIRNodeId  rhs 
)

Create a binary operation node.

Parameters
builderTarget builder.
typeOperation type; must be one of the binary node kinds.
lhsLeft operand.
rhsRight operand.
Returns
Node identifier or SIM_IR_INVALID_NODE.

◆ sim_ir_builder_constant()

SimIRNodeId sim_ir_builder_constant ( SimIRBuilder builder,
double  value 
)

Create a constant node.

Parameters
builderTarget builder.
valueLiteral value.
Returns
Identifier of the created node or SIM_IR_INVALID_NODE on failure.

◆ sim_ir_builder_constant_vector()

SimIRNodeId sim_ir_builder_constant_vector ( SimIRBuilder builder,
const double *  values,
size_t  components 
)

Add a per-lane constant vector to the builder and return a node id.

Values are copied into the builder's constant pool; the returned node is a constant node with its value_type set to vector(components).

◆ sim_ir_builder_destroy()

void sim_ir_builder_destroy ( SimIRBuilder builder)

Release resources held by an IR builder.

Parameters
builderBuilder to destroy; may be NULL.

◆ sim_ir_builder_diff()

SimIRNodeId sim_ir_builder_diff ( SimIRBuilder builder,
SimIRNodeId  operand,
size_t  axis,
double  dx,
double  scale 
)

Create a differential term node.

Parameters
builderTarget builder.
operandOperand node identifier.
axisAxis index for the derivative.
dxGrid spacing along axis.
scaleScaling factor applied to the differential.
Returns
Node identifier or SIM_IR_INVALID_NODE.

◆ sim_ir_builder_field_ref()

SimIRNodeId sim_ir_builder_field_ref ( SimIRBuilder builder,
size_t  field_id 
)

Create a field reference node.

Parameters
builderTarget builder.
field_idIdentifier of the referenced field.
Returns
New node identifier or SIM_IR_INVALID_NODE on failure.

◆ sim_ir_builder_get()

const SimIRNode * sim_ir_builder_get ( const SimIRBuilder builder,
SimIRNodeId  id 
)

Retrieve an immutable pointer to a node.

Parameters
builderBuilder instance.
idNode identifier.
Returns
Pointer to the node or NULL if id is invalid.

◆ sim_ir_builder_init()

SimResult sim_ir_builder_init ( SimIRBuilder builder)

Initialize an empty IR builder.

Parameters
[out]builderBuilder instance to initialize.
Returns
SIM_RESULT_OK on success.

◆ sim_ir_builder_noise()

SimIRNodeId sim_ir_builder_noise ( SimIRBuilder builder,
uint32_t  seed,
double  amplitude 
)

Create a stochastic noise node.

Parameters
builderTarget builder.
seedSeed value for deterministic noise streams.
amplitudeNoise amplitude.
Returns
Node identifier or SIM_IR_INVALID_NODE.

◆ sim_ir_builder_reset()

void sim_ir_builder_reset ( SimIRBuilder builder)

Reset builder counts while retaining allocated storage.

Clears nodes/constants counts but keeps capacity for reuse.

◆ sim_ir_builder_set_default_boundary()

void sim_ir_builder_set_default_boundary ( SimIRBuilder builder,
SimIRBoundaryPolicy  boundary 
)

Set the default boundary policy used by shorthand differential helpers.

Parameters
builderTarget builder.
boundaryBoundary policy; falls back to NEUMANN when invalid.

◆ sim_ir_collect_reachable()

SimResult sim_ir_collect_reachable ( const SimIRBuilder builder,
const SimIRNodeId roots,
size_t  root_count,
unsigned char *  out_reachable,
size_t  reachable_count 
)

Mark nodes reachable from a set of roots.

Parameters
builderBuilder instance.
rootsRoot node identifiers to traverse.
root_countNumber of roots in roots.
out_reachableByte array to receive reachability flags (size >= builder->count).
reachable_countSize of out_reachable in bytes.

◆ sim_ir_diff_spec_init()

void sim_ir_diff_spec_init ( SimIRDiffSpec spec,
const SimIRBuilder builder 
)

Initialize a diff spec with safe defaults.

Sets order/stencil_order=1, scale=1, dx=1, boundary=builder default (if provided) or NEUMANN, and result_type to scalar.

◆ sim_ir_evaluate_domain()

SimResult sim_ir_evaluate_domain ( const SimIRBuilder builder,
SimIRNodeId  root,
const SimIREvaluatorDomain evaluator,
SimIRDomainValue out_value 
)

Evaluate an IR expression using a unified scalar-domain evaluator surface.

This API selects real vs complex execution semantics from SimIRType.scalar_domain. Existing sim_ir_evaluate* paths remain as compatibility wrappers/fast paths.

◆ sim_ir_kernel_has_unsupported_complex_semantics()

bool sim_ir_kernel_has_unsupported_complex_semantics ( const struct KernelIR kernel)

Query whether a kernel contains true complex-domain nodes whose semantics are not representable by the simple pointwise GPU emitters.

Kernels that opt into componentwise complex-lane semantics are treated as supported.