MCPcopy Create free account
hub / github.com/cactus-compute/cactus / test_graph_reset

Function test_graph_reset

tests/test_graph.cpp:1008–1035  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006}
1007
1008bool test_graph_reset() {
1009 CactusGraph graph;
1010
1011 size_t input_a = graph.input({2}, Precision::FP16);
1012 size_t result_id = graph.scalar_add(input_a, 5.0f);
1013
1014 std::vector<__fp16> data_a = {1, 2};
1015 graph.set_input(input_a, data_a.data(), Precision::FP16);
1016 graph.execute();
1017
1018 __fp16* output1 = static_cast<__fp16*>(graph.get_output(result_id));
1019 if (std::abs(static_cast<float>(output1[0]) - 6.0f) > 1e-2f ||
1020 std::abs(static_cast<float>(output1[1]) - 7.0f) > 1e-2f) return false;
1021
1022 graph.hard_reset();
1023 if (graph.get_node_count() != 0) return false;
1024
1025 size_t new_input = graph.input({2}, Precision::FP16);
1026 size_t new_result = graph.scalar_add(new_input, 5.0f);
1027
1028 std::vector<__fp16> data_b = {10, 20};
1029 graph.set_input(new_input, data_b.data(), Precision::FP16);
1030 graph.execute();
1031
1032 __fp16* output2 = static_cast<__fp16*>(graph.get_output(new_result));
1033 return (std::abs(static_cast<float>(output2[0]) - 15.0f) < 1e-2f &&
1034 std::abs(static_cast<float>(output2[1]) - 25.0f) < 1e-2f);
1035}
1036
1037bool test_gather_operation() {
1038 // Gather uses INT8 indices but can work with FP16 data

Callers 1

mainFunction · 0.85

Calls 8

scalar_addMethod · 0.80
dataMethod · 0.80
get_node_countMethod · 0.80
inputMethod · 0.45
set_inputMethod · 0.45
executeMethod · 0.45
get_outputMethod · 0.45
hard_resetMethod · 0.45

Tested by

no test coverage detected