Coverage Report

Created: 2021-04-14 04:30

/home/liu/buildslave/linux-x64-runtests/build/test/unit/nnc/graph.io.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
8
TEST_SETUP()
9
{
10
  ccv_nnc_init();
11
}
12
13
TEST_CASE("write graph (x + y) * (x + y) and read")
14
1
{
15
1
  ccv_nnc_symbolic_graph_t* const symbolic_graph = ccv_nnc_symbolic_graph_new();
16
1
  ccv_nnc_tensor_symbol_t x = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 1), "x");
17
1
  ccv_nnc_tensor_symbol_t y = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 1), "y");
18
1
  ccv_nnc_tensor_symbol_t z1 = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 1), "z1");
19
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWSUM_FORWARD(), TENSOR_SYMBOL_LIST(x, y), TENSOR_SYMBOL_LIST(z1), "sum1");
20
1
  ccv_nnc_tensor_symbol_t z2 = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 1), "z2");
21
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWSUM_FORWARD(), TENSOR_SYMBOL_LIST(x, y), TENSOR_SYMBOL_LIST(z2), "sum2");
22
1
  ccv_nnc_tensor_symbol_t z = ccv_nnc_tensor_symbol_new(symbolic_graph, CPU_TENSOR_NHWC(32F, 1), "z");
23
1
  ccv_nnc_graph_exec_symbol_new(symbolic_graph, CMD_EWPROD_FORWARD(), TENSOR_SYMBOL_LIST(z1, z2), TENSOR_SYMBOL_LIST(z), "prod");
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
  static char fn[] = "gen/write_graph__x___y_____x___y__and_read.graph";
27
1
  remove(fn);
28
1
  ccv_nnc_symbolic_graph_write(symbolic_graph, TENSOR_BIND_MAP(KV(x, 0), KV(y, 0), KV(z, 0)), fn);
29
1
  ccv_nnc_symbolic_graph_free(symbolic_graph);
30
1
  ccv_nnc_symbolic_graph_t* symbolic_graph_2 = 0;
31
1
  ccv_nnc_tensor_bind_t* tensor_binds = 0;
32
1
  int tensor_bind_size = 0;
33
1
  ccv_nnc_symbolic_graph_read(fn, &symbolic_graph_2, &tensor_binds, &tensor_bind_size);
34
1
  x = tensor_binds[0].symbol;
35
1
  y = tensor_binds[1].symbol;
36
1
  z = tensor_binds[2].symbol;
37
1
  ccfree(tensor_binds);
38
1
  ccv_nnc_graph_t* graph = 0;
39
1
  ccv_nnc_tensor_arena_t* tensor_arena = 0;
40
1
  ccv_nnc_graph_exec_arena_t* graph_exec_arena = 0;
41
1
  ccv_nnc_symbolic_graph_compile(symbolic_graph_2, ccv_nnc_default_compile_params, 0, 0, 0, 0, SYMBOLIC_GRAPH_SOURCES(symbolic_graph_2), SYMBOLIC_GRAPH_DESTINATIONS(symbolic_graph_2), &graph, &tensor_arena, &graph_exec_arena);
42
1
  GRAPH_GEN(graph, CCV_NNC_LONG_DOT_GRAPH);
43
1
  ccv_nnc_tensor_t* const x_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, x);
44
1
  x_tensor->data.f32[0] = 10;
45
1
  ccv_nnc_tensor_t* const y_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, y);
46
1
  y_tensor->data.f32[0] = 8;
47
1
  ccv_nnc_graph_run(graph, 0, TRAVERSE_FULL, 0, 0);
48
1
  ccv_nnc_tensor_t* const z_tensor = ccv_nnc_tensor_from_symbol(tensor_arena, z);
49
1
  REQUIRE_EQ_WITH_TOLERANCE(z_tensor->data.f32[0], (10 + 8) * (10 + 8), 1e-5, "result should be equal");
50
1
  ccv_nnc_symbolic_graph_free(symbolic_graph_2);
51
1
  ccv_nnc_graph_free(graph);
52
1
  ccv_nnc_tensor_arena_free(tensor_arena);
53
1
  ccv_nnc_graph_exec_arena_free(graph_exec_arena);
54
1
}
55
56
#include "case_main.h"