samples/graph_ops.c
rml_graph ConnectPreprocessingGraph(const rml_graph graph,
                                    const char* input_names[],
                                    const rml_tensor_info* input_infos)
{
    // Preprocessing graph includes exponential tone-mapping
    // ldr_color = beta - exp(alpha * hdr_color)
    // alpha = -1.0
    // beta = 1.0
    /* Create a context */
    rml_graph preprocess_graph = NULL;
    RML_CHECK(rmlCreateGraph(&preprocess_graph));

    // Create placeholder per input
    rml_op color_op = CreatePlaceholderOp(preprocess_graph, input_names[0], input_infos[0].shape);
    rml_op albedo_op = CreatePlaceholderOp(preprocess_graph, input_names[1], input_infos[1].shape);
    rml_op depth_op = CreatePlaceholderOp(preprocess_graph, input_names[2], input_infos[2].shape);
    rml_op normal_op = CreatePlaceholderOp(preprocess_graph, input_names[3], input_infos[3].shape);

    // Create alpha
    float alpha_const = -1.0f;
    rml_op alpha_op = CreateScalarOp(preprocess_graph, "alpha", RML_DTYPE_FLOAT32, &alpha_const);

    // Create beta
    float beta_const = 1.0f;
    rml_op beta_op = CreateScalarOp(preprocess_graph, "beta", RML_DTYPE_FLOAT32, &beta_const);

    // Create mul, exp and sub opearions
    rml_op mul_op = CreateBinaryOp(preprocess_graph, "mul", RML_OP_MUL, alpha_op, color_op);
    rml_op exp_op = CreateUnaryOp(preprocess_graph, "exp", RML_OP_EXP, mul_op);
    rml_op sub_op = CreateBinaryOp(preprocess_graph, "sub", RML_OP_SUB, beta_op, exp_op);

    // Create axis for concatenation
    int axis = -1;
    rml_op axis_op = CreateScalarOp(preprocess_graph, "concat/axis", RML_DTYPE_INT32, &axis);

    // Create inputs for concatenation
    rml_op inputs[NUM_INPUTS] = {sub_op, albedo_op, depth_op, normal_op};
    // Concatenate tone-mapped color with albedo, depth and normal
    rml_op_desc concat_desc = {RML_OP_CONCAT, "concat", .concat = {NUM_INPUTS, inputs, axis_op}};

    rml_op op_concat = NULL;
    RML_CHECK(rmlCreateOperation(preprocess_graph, &concat_desc, &op_concat));

    // Get tail graph inputs
    rml_strings tail_inputs;
    RML_CHECK(rmlGetGraphInputNames(graph, &tail_inputs));

    // Get head graph outputs
    rml_strings head_outputs;
    RML_CHECK(rmlGetGraphOutputNames(preprocess_graph, &head_outputs));

    // Connect preprocessing graph with base graph
    rml_graph connected_graph = NULL;
    RML_CHECK(rmlConnectGraphs(preprocess_graph,
                               graph,
                               1,
                               &head_outputs.items[0],
                               &tail_inputs.items[0],
                               &connected_graph));

    return connected_graph;
}
/*
 * Create preprocessing graph and connect it with base graph
 *
 * @param graph - base graph to be connected with preprocesssing graph
 * @param input_names - list of unique input names of preprocessing graph
 * @param input_shapes - list of input shapes of preprocessing graph
 * @return - connected graph
 */
Create preprocessing graph and connect it with base graph

@param graph - base graph to be connected with preprocesssing graph
@param input_names - list of unique input names of preprocessing graph
@param input_shapes - list of input shapes of preprocessing graph
@return - connected graph
Create preprocessing graph and connect it with base graph @param graph - base graph to be connected with preprocesssing graph @param input_names - list of unique input names of preprocessing graph @param input_shapes - list of input shapes of preprocessing graph @return - connected graph
rml_graph ConnectPreprocessingGraph(const rml_graph graph,
                                    const char* input_names[],
                                    const rml_tensor_info* input_infos)
{
    rml_graph preprocess_graph = NULL;
    RML_CHECK(rmlCreateGraph(&preprocess_graph));
    rml_op color_op = CreatePlaceholderOp(preprocess_graph, input_names[0], input_infos[0].shape);
    rml_op albedo_op = CreatePlaceholderOp(preprocess_graph, input_names[1], input_infos[1].shape);
    rml_op depth_op = CreatePlaceholderOp(preprocess_graph, input_names[2], input_infos[2].shape);
    rml_op normal_op = CreatePlaceholderOp(preprocess_graph, input_names[3], input_infos[3].shape);
    float alpha_const = -1.0f;
    rml_op alpha_op = CreateScalarOp(preprocess_graph, "alpha", RML_DTYPE_FLOAT32, &alpha_const);
    float beta_const = 1.0f;
    rml_op beta_op = CreateScalarOp(preprocess_graph, "beta", RML_DTYPE_FLOAT32, &beta_const);
    rml_op mul_op = CreateBinaryOp(preprocess_graph, "mul", RML_OP_MUL, alpha_op, color_op);
    rml_op exp_op = CreateUnaryOp(preprocess_graph, "exp", RML_OP_EXP, mul_op);
    rml_op sub_op = CreateBinaryOp(preprocess_graph, "sub", RML_OP_SUB, beta_op, exp_op);
    int axis = -1;
    rml_op axis_op = CreateScalarOp(preprocess_graph, "concat/axis", RML_DTYPE_INT32, &axis);
    rml_op inputs[NUM_INPUTS] = {sub_op, albedo_op, depth_op, normal_op};
    rml_op_desc concat_desc = {RML_OP_CONCAT, "concat", .concat = {NUM_INPUTS, inputs, axis_op}};
    rml_op op_concat = NULL;
    RML_CHECK(rmlCreateOperation(preprocess_graph, &concat_desc, &op_concat));
    rml_strings tail_inputs;
    RML_CHECK(rmlGetGraphInputNames(graph, &tail_inputs));
    rml_strings head_outputs;
    RML_CHECK(rmlGetGraphOutputNames(preprocess_graph, &head_outputs));
    rml_graph connected_graph = NULL;
    RML_CHECK(rmlConnectGraphs(preprocess_graph,
                               graph,
                               1,
                               &head_outputs.items[0],
                               &tail_inputs.items[0],
                               &connected_graph));
    return connected_graph;
}
rml_graph ConnectPreprocessingGraph ( const rml_graph graph , const char * input_names [ ] , const rml_tensor_info * input_infos ) { rml_graph preprocess_graph = NULL ; RML_CHECK ( rmlCreateGraph ( & preprocess_graph ) ) ; rml_op color_op = CreatePlaceholderOp ( preprocess_graph , input_names [ 0 ] , input_infos [ 0 ] . shape ) ; rml_op albedo_op = CreatePlaceholderOp ( preprocess_graph , input_names [ 1 ] , input_infos [ 1 ] . shape ) ; rml_op depth_op = CreatePlaceholderOp ( preprocess_graph , input_names [ 2 ] , input_infos [ 2 ] . shape ) ; rml_op normal_op = CreatePlaceholderOp ( preprocess_graph , input_names [ 3 ] , input_infos [ 3 ] . shape ) ; float alpha_const = -1.0f ; rml_op alpha_op = CreateScalarOp ( preprocess_graph , " " , RML_DTYPE_FLOAT32 , & alpha_const ) ; float beta_const = 1.0f ; rml_op beta_op = CreateScalarOp ( preprocess_graph , " " , RML_DTYPE_FLOAT32 , & beta_const ) ; rml_op mul_op = CreateBinaryOp ( preprocess_graph , " " , RML_OP_MUL , alpha_op , color_op ) ; rml_op exp_op = CreateUnaryOp ( preprocess_graph , " " , RML_OP_EXP , mul_op ) ; rml_op sub_op = CreateBinaryOp ( preprocess_graph , " " , RML_OP_SUB , beta_op , exp_op ) ; int axis = -1 ; rml_op axis_op = CreateScalarOp ( preprocess_graph , " " , RML_DTYPE_INT32 , & axis ) ; rml_op inputs [ NUM_INPUTS ] = { sub_op , albedo_op , depth_op , normal_op } ; rml_op_desc concat_desc = { RML_OP_CONCAT , " " , . concat = { NUM_INPUTS , inputs , axis_op } } ; rml_op op_concat = NULL ; RML_CHECK ( rmlCreateOperation ( preprocess_graph , & concat_desc , & op_concat ) ) ; rml_strings tail_inputs ; RML_CHECK ( rmlGetGraphInputNames ( graph , & tail_inputs ) ) ; rml_strings head_outputs ; RML_CHECK ( rmlGetGraphOutputNames ( preprocess_graph , & head_outputs ) ) ; rml_graph connected_graph = NULL ; RML_CHECK ( rmlConnectGraphs ( preprocess_graph , graph , 1 , & head_outputs . items [ 0 ] , & tail_inputs . items [ 0 ] , & connected_graph ) ) ; return connected_graph ; }
Create preprocessing graph and connect it with base graph
Create preprocessing graph and connect it with base graph
// Preprocessing graph includes exponential tone-mapping
 // ldr_color = beta - exp(alpha * hdr_color)
 // alpha = -1.0
 // beta = 1.0
 /* Create a context */ // Create placeholder per input
 // Create alpha
 // Create beta
 // Create mul, exp and sub opearions
 // Create axis for concatenation
 // Create inputs for concatenation
 // Concatenate tone-mapped color with albedo, depth and normal
 // Get tail graph inputs
 // Get head graph outputs
 // Connect preprocessing graph with base graph
