MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / check_reproducibility

Function check_reproducibility

src/opr/test/rand.cpp:32–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30};
31
32void check_reproducibility(
33 std::shared_ptr<ComputingGraph> graph, size_t size,
34 thin_function<SymbolVar(uint64_t seed)> make) {
35 // out[func][opr][run]
36 HostTensorND out[2][2][2];
37
38 auto run = [&](int fid) {
39 SymbolVar o0 = make(0), o1 = make(1);
40 HostTensorND host_o0, host_o1;
41 auto func = graph->compile(
42 {make_callback_copy(o0, host_o0), make_callback_copy(o1, host_o1)});
43 for (int i = 0; i < 2; ++i) {
44 func->execute();
45 out[fid][0][i].copy_from(host_o0);
46 out[fid][1][i].copy_from(host_o1);
47 }
48 };
49 run(0);
50 run(1);
51
52 for (int i = 0; i < 2; ++i) {
53 for (int j = 0; j < 2; ++j)
54 MGB_ASSERT_TENSOR_EQ(out[0][i][j], out[1][i][j]);
55 }
56
57 auto max_diff = [&](int off0, int off1) {
58 float diff = 0;
59 auto p0 = out[0][off0 / 2][off0 % 2].ptr<float>(),
60 p1 = out[0][off1 / 2][off1 % 2].ptr<float>();
61 for (size_t i = 0; i < size; ++i) {
62 update_max(diff, std::abs(p0[i] - p1[i]));
63 }
64 return diff;
65 };
66
67 for (int i = 0; i < 4; ++i) {
68 for (int j = i + 1; j < 4; ++j)
69 ASSERT_GT(max_diff(i, j), 0.3) << i << " " << j;
70 }
71}
72
73void check_reproducibility_with_int32_output(
74 std::shared_ptr<ComputingGraph> graph, size_t size,

Callers 1

TESTFunction · 0.85

Calls 8

make_callback_copyFunction · 0.85
update_maxFunction · 0.85
makeFunction · 0.70
runFunction · 0.50
absFunction · 0.50
compileMethod · 0.45
executeMethod · 0.45
copy_fromMethod · 0.45

Tested by

no test coverage detected