File: test_dpu_controller.cpp

package info (click to toggle)
vart 2.5-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,404 kB
  • sloc: cpp: 30,188; python: 7,493; sh: 969; makefile: 37; ansic: 36
file content (74 lines) | stat: -rw-r--r-- 2,468 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright 2019 Xilinx Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <xrt.h>

#include <iostream>
#include <vitis/ai/env_config.hpp>

#include "vitis/ai/parse_value.hpp"
#include "vitis/ai/profiling.hpp"
#include "xir/dpu_controller.hpp"
#include "xir/xrt_device_handle.hpp"
DEF_ENV_PARAM_2(CU_NAME, "DPUCZDX8G", std::string);

using namespace std;
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

static uint32_t get_reg(xclDeviceHandle xcl_handle, uint64_t cu_addr) {
  uint32_t value = 0;
  size_t size = sizeof(value);
  auto read_result =
      xclRead(xcl_handle, XCL_ADDR_KERNEL_CTRL, cu_addr, &value, size);
  CHECK_EQ(read_result, size)
      << "xclRead has error!"                              //
      << "read_result " << read_result << " "              //
      << "cu_addr " << std::hex << "0x" << cu_addr << " "  //
      ;
  return value;
}

int main(int argc, char* argv[]) {
  auto h = xir::XrtDeviceHandle::get_instance();

  auto dpu = xir::DpuController::get_instance();
  auto w = 0ul;
  vitis::ai::parse_value(argv[1], w);
  auto p = 0ul;
  vitis::ai::parse_value(argv[2], p);
  auto c = 0ul;
  vitis::ai::parse_value(argv[3], c);
  auto idx = 0ul;
  vitis::ai::parse_value(argv[4], idx);
  auto count = std::stoi(argv[5]);

  //
  auto cu_name = ENV_PARAM(CU_NAME);
  auto handle = h->get_handle(cu_name, idx);
  auto cu_addr = h->get_cu_addr(cu_name, idx);
  for (auto i = 0; i < count; ++i) {
    auto start = std::chrono::steady_clock::now();
    auto start_cycle = get_reg(handle, cu_addr + 0x1a0);
    dpu->run(idx, c, {p, w});
    auto end = std::chrono::steady_clock::now();
    auto end_cycle = get_reg(handle, cu_addr + 0x1a0);
    auto ms = std::chrono::duration_cast<std::chrono::microseconds>(end - start)
                  .count();
    auto cycle = end_cycle - start_cycle;
    cout << ms << " " << start_cycle << " " << end_cycle << " " << cycle
         << "\n";
  }
  return 0;
}