/home/liu/actions-runner/_work/ccv/ccv/test/unit/nnc/numa.tests.c
Line | Count | Source |
1 | | #include "case.h" |
2 | | #include "ccv_case.h" |
3 | | #include "ccv_nnc_case.h" |
4 | | #include <ccv.h> |
5 | | #include <nnc/ccv_nnc.h> |
6 | | #include <nnc/ccv_nnc_easy.h> |
7 | | #include "3rdparty/dsfmt/dSFMT.h" |
8 | | |
9 | | TEST_SETUP() |
10 | | { |
11 | | ccv_nnc_init(); |
12 | | } |
13 | | |
14 | | TEST_CASE("simple graph x * 0.3 + 3 compiled with NUMA") |
15 | 1 | { |
16 | 1 | ccv_nnc_symbolic_graph_t* symbolic_graph = ccv_nnc_symbolic_graph_new(); |
17 | 1 | const ccv_nnc_tensor_symbol_t a = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_NUMA_TENSOR_NHWC(000, 32F, 1), "a"); |
18 | 1 | const ccv_nnc_tensor_symbol_t b = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_NUMA_TENSOR_NHWC(002, 32F, 1), "b"); |
19 | 1 | const ccv_nnc_tensor_symbol_t x = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_NUMA_TENSOR_NHWC(000, 32F, 1), "x"); |
20 | 1 | const ccv_nnc_tensor_symbol_t y = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_NUMA_TENSOR_NHWC(001, 32F, 1), "y"); |
21 | 1 | const ccv_nnc_tensor_symbol_t z = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_NUMA_TENSOR_NHWC(002, 32F, 1), "z"); |
22 | 1 | ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWPROD_FORWARD(), TENSOR_SYMBOL_LIST(x, a), TENSOR_SYMBOL_LIST(y), "prod"); |
23 | 1 | ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWSUM_FORWARD(), TENSOR_SYMBOL_LIST(y, b), TENSOR_SYMBOL_LIST(z), "sum"); |
24 | 1 | ccv_nnc_graph_exec_symbol_autogen(symbolic_graph, 0, 0, CCV_NNC_AUTOGEN_ALL_EXECS | CCV_NNC_AUTOGEN_SOURCES_AND_DESTINATIONS); |
25 | 1 | SYMBOLIC_GRAPH_GEN(symbolic_graph, CCV_NNC_LONG_DOT_GRAPH); |
26 | 1 | ccv_nnc_graph_t* graph = 0; |
27 | 1 | ccv_nnc_tensor_arena_t* tensor_arena = 0; |
28 | 1 | ccv_nnc_graph_exec_arena_t* graph_exec_arena = 0; |
29 | 1 | ccv_nnc_symbolic_graph_compile(symbolic_graph, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(symbolic_graph), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph), &graph, &tensor_arena, &graph_exec_arena); |
30 | 1 | GRAPH_GEN(graph, CCV_NNC_LONG_DOT_GRAPH); |
31 | 1 | ccv_nnc_tensor_t* const x_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, x); |
32 | 1 | x_tensor->data.f32[0] = 1.21; |
33 | 1 | ccv_nnc_tensor_t* const a_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, a); |
34 | 1 | a_tensor->data.f32[0] = 0.3; |
35 | 1 | ccv_nnc_tensor_t* const b_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, b); |
36 | 1 | b_tensor->data.f32[0] = 3; |
37 | 1 | ccv_nnc_tensor_t* const y_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, y); |
38 | 1 | ccv_nnc_tensor_t* const z_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, z); |
39 | 1 | REQUIRE(x_tensor->data.f32 != y_tensor->data.f32, "y cannot be assigned to the same place of x due to NUMA constraint"); |
40 | 1 | REQUIRE(z_tensor->data.f32 != x_tensor->data.f32, "z cannot be assigned to the same place of x due to NUMA constraint"); |
41 | 1 | REQUIRE(z_tensor->data.f32 != y_tensor->data.f32, "z cannot be assigned to the same place of y due to NUMA constraint"); |
42 | 1 | ccv_nnc_graph_exec_t source = ccv_nnc_graph_exec_source(graph_exec_arena); |
43 | 1 | ccv_nnc_graph_exec_t destination = ccv_nnc_graph_exec_destination(graph_exec_arena); |
44 | 1 | ccv_nnc_graph_run(graph, 0, &source, 1, &destination, 1, 0, 0); |
45 | 1 | REQUIRE_EQ_WITH_TOLERANCE(z_tensor->data.f32[0], 1.21 * 0.3 + 3, 1e-6, "should be equal to 1.21 * 0.3 + 3"); |
46 | 1 | ccv_nnc_graph_free(graph); |
47 | 1 | ccv_nnc_tensor_arena_free(tensor_arena); |
48 | 1 | ccv_nnc_graph_exec_arena_free(graph_exec_arena); |
49 | 1 | ccv_nnc_symbolic_graph_free(symbolic_graph); |
50 | 1 | } |
51 | | |
52 | | #include "case_main.h" |