MCPcopy Create free account
hub / github.com/Xilinx/Vitis_Libraries / test

Function test

utils/L1/examples/load_balance_processing/tb.cpp:31–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29}
30
31int test() {
32 hls::stream<ap_uint<W_STRM> > istrm;
33 hls::stream<bool> e_istrm;
34 hls::stream<ap_uint<W_STRM> > ostrm;
35 hls::stream<bool> e_ostrm;
36
37 std::cout << std::dec << "W_STRM = " << W_STRM << std::endl;
38 std::cout << std::dec << "W_PU = " << W_PU << std::endl;
39 std::cout << std::dec << "NPU = " << NPU << std::endl;
40 std::cout << std::dec << "NS = " << NS << std::endl;
41 /*
42 * 1. Generate test data and merege them to a wide width stream
43 * 2. Updata the data in hardware
44 * 3. Fetch back the updated data and calculate their dot product.
45 *
46 * Distribution on load balance is NOT order-preserving, so calculate their dot product to verify the result.
47 */
48
49 // Generate data
50 ap_uint<W_STRM> gld = 0;
51 for (int i = 0; i < NS; ++i) {
52 ap_uint<W_STRM> bd = 0;
53 // generate test data
54 for (int j = 0; j < W_STRM / W_PU; ++j) {
55 ap_uint<W_PRC> p = i;
56 ap_uint<W_DSC> d = i % 10;
57 ap_uint<W_PU> data = 0;
58 data.range(W_PRC - 1, 0) = p;
59 data.range(W_DSC + W_PRC - 1, W_PRC) = d;
60 // combine to a wide width data
61 bd.range((j + 1) * W_PU - 1, j * W_PU) = data;
62 // calculate the golden result
63 ap_uint<W_PU> nd = update_data(data);
64 gld += calculate(nd);
65 }
66 istrm.write(bd);
67 e_istrm.write(false);
68 }
69 e_istrm.write(true);
70 // Update data in hardware
71 test_core(istrm, e_istrm, ostrm, e_ostrm);
72
73 // Fetch bach the updated data and calculate their dot product.
74 int nerror = 0;
75 int count = 0;
76 ap_uint<W_STRM> total = 0;
77 while (!e_ostrm.read()) {
78 ap_uint<W_STRM> bd = ostrm.read();
79 // calculate the test result
80 for (int j = 0; j < W_STRM / W_PU; ++j) {
81 ap_uint<W_PU> data = bd.range((j + 1) * W_PU - 1, j * W_PU);
82 total += calculate(data);
83 }
84 count++;
85 }
86 std::cout << "\n total=" << total << " gld=" << gld << std::endl;
87 if (total != gld) {
88 nerror = 1;

Callers 1

mainFunction · 0.70

Calls 5

update_dataFunction · 0.70
calculateFunction · 0.70
test_coreFunction · 0.70
writeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected