Skip to content

Commit

Permalink
Replace xclOpen/Close in XDP (Xilinx#7985)
Browse files Browse the repository at this point in the history
  • Loading branch information
IshitaGhosh authored Mar 4, 2024
1 parent 3a3fda2 commit 22815fe
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "core/common/message.h"
#include "core/common/system.h"
#include "core/common/xrt_profiling.h"
#include "core/include/xrt/xrt_device.h"

#include "xdp/profile/database/database.h"
#include "xdp/profile/device/device_intf.h"
Expand All @@ -41,29 +42,30 @@ namespace xdp {
{
db->registerInfo(info::device_offload) ;

// Open all of the devices that exist so we can keep our own pointer
// to access them.
uint32_t index = 0 ;
void* handle = xclOpen(index, "/dev/null", XCL_INFO) ;

while (handle != nullptr)
{
// First, keep track of all open handles
deviceHandles.push_back(handle) ;

// Second, add all the information and a writer for this device
std::string path = util::getDebugIpLayoutPath(handle);
if (path != "") {
addDevice(path);

// Now, keep track of the device ID for this device so we can use
// our own handle
deviceIdToHandle[db->addDevice(path)] = handle ;
// Open all existing devices so that XDP can access the owned handles
uint32_t numDevices = xrt_core::get_total_devices(true).second;
uint32_t index = 0;
while (index < numDevices) {
try {
xrtDevices.push_back(std::make_unique<xrt::device>(index));

auto ownedHandle = xrtDevices[index]->get_handle()->get_device_handle();
std::string path = util::getDebugIpLayoutPath(ownedHandle);

if ("" != path) {
addDevice(path);

// Now, map device ID of this device with device handle owned by XDP
deviceIdToHandle[db->addDevice(path)] = ownedHandle;
}

// Move on to the next device
++index;
} catch (const std::runtime_error& e) {
std::string msg = "Could not open device at index " + std::to_string(index) + e.what();
xrt_core::message::send(xrt_core::message::severity_level::error, "XRT", msg);
continue;
}

// Move on to the next device
++index ;
handle = xclOpen(index, "/dev/null", XCL_INFO) ;
}
}

Expand All @@ -83,11 +85,6 @@ namespace xdp {
}

clearOffloaders();

for (auto h : deviceHandles)
{
xclClose(h) ;
}
}

void HALDeviceOffloadPlugin::readTrace()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (C) 2016-2022 Xilinx, Inc
* Copyright (C) 2023 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. - All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
Expand All @@ -18,11 +18,16 @@
#ifndef HAL_DEVICE_OFFLOAD_PLUGIN_DOT_H
#define HAL_DEVICE_OFFLOAD_PLUGIN_DOT_H

#include <vector>
#include <map>
#include <memory>
#include <vector>

#include "xdp/profile/plugin/device_offload/device_offload_plugin.h"

namespace xrt {
class device;
}

namespace xdp {

// This plugin should be completely agnostic of what the host code profiling
Expand All @@ -35,7 +40,7 @@ namespace xdp {
// from a device at any time (even if the user has closed their
// handles) we need to open all the devices and keep our own handles
// to them.
std::vector<void*> deviceHandles ;
std::vector<std::unique_ptr<xrt::device>> xrtDevices ;
std::map<uint64_t, void*> deviceIdToHandle ;

virtual void readTrace() ;
Expand Down
58 changes: 30 additions & 28 deletions src/runtime_src/xdp/profile/plugin/noc/noc_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (C) 2020-2021 Xilinx, Inc
* Copyright (C) 2022-2023 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2022-2024 Advanced Micro Devices, Inc. - All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
Expand All @@ -17,15 +17,16 @@

#define XDP_PLUGIN_SOURCE

#include "xdp/profile/database/static_info/aie_constructs.h"
#include "xdp/profile/plugin/noc/noc_plugin.h"
#include "xdp/profile/writer/noc/noc_writer.h"
#include "xdp/profile/plugin/vp_base/info.h"

#include "core/common/system.h"
#include "core/common/time.h"
#include "core/common/config_reader.h"
#include "core/include/experimental/xrt-next.h"
#include "core/include/xrt/xrt_device.h"

#include "xdp/profile/database/static_info/aie_constructs.h"
#include "xdp/profile/plugin/noc/noc_plugin.h"
#include "xdp/profile/writer/noc/noc_writer.h"
#include "xdp/profile/plugin/vp_base/info.h"

#include <boost/algorithm/string.hpp>

Expand All @@ -36,28 +37,29 @@ namespace xdp {
{
db->registerPlugin(this);
db->registerInfo(info::noc);
// Just like HAL and power profiling, go through devices
// that exist and open a file for each
uint64_t index = 0;
void* handle = xclOpen(index, "/dev/null", XCL_INFO);
while (handle != nullptr) {
// Determine the name of the device
struct xclDeviceInfo2 info;
xclGetDeviceInfo2(handle, &info);
std::string deviceName = std::string(info.mName);
mDevices.push_back(deviceName);

std::string outputFile = "noc_profile_" + deviceName + ".csv";
VPWriter* writer = new NOCProfilingWriter(outputFile.c_str(),
deviceName.c_str(),
index) ;
writers.push_back(writer);
db->getStaticInfo().addOpenedFile(writer->getcurrentFileName(), "NOC_PROFILE") ;

// Move on to next device
xclClose(handle);
++index;
handle = xclOpen(index, "/dev/null", XCL_INFO);

uint32_t numDevices = xrt_core::get_total_devices(true).second;
uint32_t index = 0;
while (index < numDevices) {
try {
auto xrtDevice = std::make_unique<xrt::device>(index);
auto ownedHandle = xrtDevice->get_handle()->get_device_handle();
// Determine the name of the device
struct xclDeviceInfo2 info;
xclGetDeviceInfo2(ownedHandle, &info);
std::string deviceName = std::string(info.mName);
mDevices.push_back(deviceName);

std::string outputFile = "noc_profile_" + deviceName + ".csv";
VPWriter* writer = new NOCProfilingWriter(outputFile.c_str(),
deviceName.c_str(),
index) ;
writers.push_back(writer);
db->getStaticInfo().addOpenedFile(writer->getcurrentFileName(), "NOC_PROFILE") ;
} catch (const std::runtime_error &) {
break;
}
++index;
}

// Get polling interval (in msec)
Expand Down
97 changes: 52 additions & 45 deletions src/runtime_src/xdp/profile/plugin/power/power_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Copyright (C) 2020-2022 Xilinx, Inc
* Copyright (C) 2023 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. - All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
Expand All @@ -18,14 +18,18 @@
#define XDP_PLUGIN_SOURCE

#include <map>
#include <string>

#include "xdp/profile/plugin/power/power_plugin.h"
#include "xdp/profile/writer/power/power_writer.h"
#include "xdp/profile/plugin/vp_base/info.h"
#include "core/common/config_reader.h"
#include "core/common/message.h"
#include "core/common/system.h"
#include "core/common/time.h"
#include "core/common/config_reader.h"
#include "core/include/experimental/xrt-next.h"
#include "core/include/xrt/xrt_device.h"

#include "xdp/profile/plugin/power/power_plugin.h"
#include "xdp/profile/writer/power/power_writer.h"
#include "xdp/profile/plugin/vp_base/info.h"

namespace xdp {

Expand Down Expand Up @@ -69,49 +73,52 @@ namespace xdp {
// different boards. We number them all individually.
std::map<std::string, uint64_t> deviceNumbering ;

// Just like HAL level device profiling, go through the devices
// that exist in order to find all of the sysfs paths
uint64_t index = 0 ;
void* handle = xclOpen(index, "/dev/null", XCL_INFO) ;
while (handle != nullptr)
{
// For each device, keep track of the paths to the sysfs files
std::vector<std::string> paths ;
for (auto f : powerFiles)
{
char sysfsPath[512] ;
xclGetSysfsPath(handle, "xmc", f, sysfsPath, 512) ;
paths.push_back(sysfsPath) ;
}
filePaths.push_back(paths) ;

// Determine the name of the device
struct xclDeviceInfo2 info ;
xclGetDeviceInfo2(handle, &info) ;
std::string deviceName = std::string(info.mName) ;

if (deviceNumbering.find(deviceName) == deviceNumbering.end()) {
deviceNumbering[deviceName] = 0 ;
}
deviceName += "-" ;
deviceName += std::to_string(deviceNumbering[deviceName]) ;
deviceNumbering[deviceName]++ ;

std::string outputFile = "power_profile_" + deviceName + ".csv" ;

VPWriter* writer = new PowerProfilingWriter(outputFile.c_str(),
deviceName.c_str(),
index) ;
writers.push_back(writer) ;
(db->getStaticInfo()).addOpenedFile(writer->getcurrentFileName(),
uint32_t numDevices = xrt_core::get_total_devices(true).second;
uint32_t index = 0;
while (index < numDevices) {
try {
auto xrtDevice = std::make_unique<xrt::device>(index);
auto ownedHandle = xrtDevice->get_handle()->get_device_handle();

// For each device, keep track of the paths to the sysfs files
std::vector<std::string> paths ;
for (auto f : powerFiles)
{
char sysfsPath[512] ;
xclGetSysfsPath(ownedHandle, "xmc", f, sysfsPath, 512) ;
paths.push_back(sysfsPath) ;
}
filePaths.push_back(paths) ;

// Determine the name of the device
struct xclDeviceInfo2 info ;
xclGetDeviceInfo2(ownedHandle, &info) ;
std::string deviceName = std::string(info.mName) ;

if (deviceNumbering.find(deviceName) == deviceNumbering.end()) {
deviceNumbering[deviceName] = 0 ;
}
deviceName += "-" ;
deviceName += std::to_string(deviceNumbering[deviceName]) ;
deviceNumbering[deviceName]++ ;

std::string outputFile = "power_profile_" + deviceName + ".csv" ;

VPWriter* writer = new PowerProfilingWriter(outputFile.c_str(),
deviceName.c_str(),
index) ;
writers.push_back(writer) ;
(db->getStaticInfo()).addOpenedFile(writer->getcurrentFileName(),
"XRT_POWER_PROFILE") ;

// Move on to the next device
xclClose(handle) ;
++index ;
handle = xclOpen(index, "/dev/null", XCL_INFO) ;
// Move on to the next device
++index;
} catch (const std::runtime_error& e) {
std::string msg = "Could not open device at index " + std::to_string(index) + e.what();
xrt_core::message::send(xrt_core::message::severity_level::error, "XRT", msg);
continue;
}
}

// Start the power profiling thread
pollingThread = std::thread(&PowerProfilingPlugin::pollPower, this) ;
}
Expand Down

0 comments on commit 22815fe

Please sign in to comment.