Skip to content

Commit

Permalink
Create common utilities folder for XDP plugins that use the AIE driver (
Browse files Browse the repository at this point in the history
  • Loading branch information
nishraptor authored Jan 18, 2024
1 parent 2215092 commit 23d66ef
Show file tree
Hide file tree
Showing 30 changed files with 345 additions and 670 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
#include "xdp/profile/device/aie_trace/client/aie_trace_offload_client.h"
#include "xdp/profile/device/device_intf.h"

#include "xdp/profile/plugin/aie_trace/win/transactions/op_buf.hpp"
#include "xdp/profile/plugin/aie_trace/win/transactions/op_init.hpp"
#include "xdp/profile/plugin/aie_trace/win/transactions/op_types.h"

constexpr std::uint64_t CONFIGURE_OPCODE = std::uint64_t{2};

namespace xdp {
using severity_level = xrt_core::message::severity_level;

Expand Down Expand Up @@ -60,17 +54,10 @@ namespace xdp {

constexpr std::uint64_t DDR_AIE_ADDR_OFFSET = std::uint64_t{0x80000000};

try {
mKernel = xrt::kernel(context, "XDP_KERNEL");
}
catch (std::exception& e) {
std::stringstream msg;
msg << "Unable to find XDP_KERNEL kernel from hardware context. Failed to "
"configure AIE Trace Offloading."
<< e.what();
xrt_core::message::send(severity_level::warning, "XRT", msg.str());
transactionHandler = std::make_unique<aie::ClientTransaction>(context, "AIE Trace Offload");

if (!transactionHandler->initializeKernel("XDP_KERNEL"))
return false;
}

xdp::aie::driver_config meta_config = metadata->getAIEConfigMetadata();

Expand Down Expand Up @@ -107,7 +94,7 @@ namespace xdp {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
tracemsg.c_str());
xrt_bos.emplace_back(xrt::bo(context.get_device(), bufAllocSz,
XRT_BO_FLAGS_HOST_ONLY, mKernel.group_id(0)));
XRT_BO_FLAGS_HOST_ONLY, transactionHandler->getGroupID(0)));

if (!xrt_bos.empty()) {
auto bo_map = xrt_bos.back().map<uint8_t*>();
Expand Down Expand Up @@ -139,30 +126,10 @@ namespace xdp {
RC = XAie_DmaChannelEnable(&aieDevInst, loc, s2mm_ch_id, DMA_S2MM);

uint8_t* txn_ptr = XAie_ExportSerializedTransaction(&aieDevInst, 1, 0);
op_buf instr_buf;
instr_buf.addOP(transaction_op(txn_ptr));
xrt::bo instr_bo;

// Configuration bo
try {
instr_bo = xrt::bo(context.get_device(), instr_buf.ibuf_.size(),
XCL_BO_FLAGS_CACHEABLE, mKernel.group_id(1));
}
catch (std::exception& e) {
std::stringstream msg;
msg << "Unable to create instruction buffer for AIE Trace transaction. "
"Not configuring AIE Trace Offloading. "
<< e.what() << std::endl;
xrt_core::message::send(severity_level::warning, "XRT", msg.str());

if (!transactionHandler->submitTransaction(txn_ptr))
return false;
}

instr_bo.write(instr_buf.ibuf_.data());
instr_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE);
auto run = mKernel(CONFIGURE_OPCODE, instr_bo,
instr_bo.size() / sizeof(int), 0, 0, 0, 0);
run.wait2();


xrt_core::message::send(
severity_level::info, "XRT",
"Successfully scheduled AIE Trace Offloading Transaction Buffer.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "core/include/xrt/xrt_hw_context.h"
#include "core/include/xrt/xrt_kernel.h"
#include "xdp/profile/plugin/aie_trace/aie_trace_metadata.h"
#include "xdp/profile/device/common/client_transaction.h"


extern "C" {
#include <xaiengine.h>
Expand Down Expand Up @@ -106,16 +108,17 @@ class AIETraceOffload
uint64_t totalSz;
uint64_t numStream;
uint64_t bufAllocSz;
std::vector<AIETraceBufferInfo> buffers;
std::vector<AIETraceBufferInfo> buffers;

//Internal use only
// Set this for verbose trace offload
bool m_debug = false;
xrt::hw_context context;
XAie_DevInst aieDevInst = {0};
xrt::kernel mKernel;
std::unique_ptr<aie::ClientTransaction> transactionHandler;

std::shared_ptr<AieTraceMetadata> metadata;
std::vector<xrt::bo> xrt_bos;
xrt::hw_context context;

// Continuous Trace Offload (For PLIO)
bool traceContinuous;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2022-2023 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
* License is located 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.
*/

#define XDP_PLUGIN_SOURCE

#include "aie_driver_common_util.h"
#include "xdp/profile/database/static_info/aie_util.h"

#include <boost/algorithm/string.hpp>
#include <cmath>
#include <cstring>
#include <iostream>
#include <memory>
#include <regex>
#include <set>

extern "C" {
#include <xaiengine.h>
#include <xaiengine/xaiegbl_params.h>
}

#include "core/common/message.h"

// ***************************************************************
// Anonymous namespace for helper functions local to this file
// ***************************************************************
namespace xdp::aie {
using severity_level = xrt_core::message::severity_level;

} // namespace xdp::aie
35 changes: 35 additions & 0 deletions src/runtime_src/xdp/profile/device/common/aie_driver_common_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Copyright (C) 2022-2023 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
* License is located 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.
*/

#ifndef AIE_DRIVER_COMMON_UTIL_DOT_H
#define AIE_DRIVER_COMMON_UTIL_DOT_H

#include <cstdint>
#include "xdp/profile/database/static_info/aie_constructs.h"

namespace xdp::aie {
/**
* @brief Get metric sets for core modules
* @details Depending on hardware generation, these sets can be supplemented
* with counter events as those are dependent on counter #.
* @return Map of metric set names with vectors of event IDs
*/
// std::map<std::string, std::vector<XAie_Events>> getCoreEventSets();


} // namespace xdp::aie

#endif
101 changes: 101 additions & 0 deletions src/runtime_src/xdp/profile/device/common/client_transaction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (C) 2022-2023 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
* License is located 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.
*/

#define XDP_PLUGIN_SOURCE

#include <sstream>

#include "client_transaction.h"
#include "core/common/message.h"

#include "transactions/op_types.h"
#include "transactions/op_buf.hpp"
#include "transactions/op_init.hpp"

extern "C" {
#include <xaiengine.h>
#include <xaiengine/xaiegbl_params.h>
}

// ***************************************************************
// Anonymous namespace for helper functions local to this file
// ***************************************************************
namespace xdp::aie {
using severity_level = xrt_core::message::severity_level;
static constexpr uint32_t size_4K = 0x1000;
constexpr std::uint64_t CONFIGURE_OPCODE = std::uint64_t{2};

bool
ClientTransaction::initializeKernel(std::string kernelName)
{
try {
kernel = xrt::kernel(context, kernelName);
} catch (std::exception &e){
std::stringstream msg;
msg << "Unable to find " << kernelName << " kernel from hardware context. Failed to configure " << transactionName << ". " << e.what();
xrt_core::message::send(severity_level::warning, "XRT", msg.str());
return false;
}

return true;
}

bool
ClientTransaction::submitTransaction(uint8_t* txn_ptr) {
op_buf instr_buf;
instr_buf.addOP(transaction_op(txn_ptr));
xrt::bo instr_bo;

// Configuration bo
try {
instr_bo = xrt::bo(context.get_device(), instr_buf.ibuf_.size(), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(1));
} catch (std::exception &e){
std::stringstream msg;
msg << "Unable to create instruction buffer for " << transactionName << " transaction. Unable to configure " << transactionName<< ". " << e.what() << std::endl;
xrt_core::message::send(severity_level::warning, "XRT", msg.str());
return false;
}

instr_bo.write(instr_buf.ibuf_.data());
instr_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE);
auto run = kernel(CONFIGURE_OPCODE, instr_bo, instr_bo.size()/sizeof(int), 0, 0, 0, 0);
run.wait2();

xrt_core::message::send(severity_level::info, "XRT","Successfully scheduled " + transactionName + " instruction buffer.");
return true;
}

xrt::bo
ClientTransaction::syncResults() {
// results BO syncs profile result from device
xrt::bo result_bo;
try {
result_bo = xrt::bo(context.get_device(), size_4K, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(1));
} catch (std::exception &e) {
std::stringstream msg;
msg << "Unable to create result buffer for " << transactionName << ". Cannot get " << transactionName << " Results." << e.what() << std::endl;
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg.str());
return nullptr;
}

result_bo.sync(XCL_BO_SYNC_BO_FROM_DEVICE);

return result_bo;
}



} // namespace xdp::aie
43 changes: 43 additions & 0 deletions src/runtime_src/xdp/profile/device/common/client_transaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Copyright (C) 2022-2023 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
* License is located 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.
*/

#ifndef CLIENT_TRANSACTION_DOT_H
#define CLIENT_TRANSACTION_DOT_H

#include <cstdint>
#include <string>

#include "core/include/xrt/xrt_hw_context.h"
#include "core/include/xrt/xrt_kernel.h"

namespace xdp::aie {
class ClientTransaction {
public:
ClientTransaction(xrt::hw_context c, std::string tName) : context(c), transactionName(tName) {}
bool initializeKernel(std::string kernelName);
bool submitTransaction(uint8_t* txn_ptr);
xrt::bo syncResults();
void setTransactionName(std::string newTransactionName) {transactionName = newTransactionName;}
int getGroupID(int id) {return kernel.group_id(id); }
private:
std::string transactionName;
xrt::kernel kernel;
xrt::hw_context context;
};

} // namespace xdp::aie

#endif
8 changes: 6 additions & 2 deletions src/runtime_src/xdp/profile/plugin/aie_debug/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ file(GLOB AIE_DEBUG_PLUGIN_FILES
"${PROFILE_DIR}/plugin/aie_debug/*.cpp"
)

file(GLOB AIE_DRIVER_COMMON_UTIL_FILES
"${PROFILE_DIR}/device/common/*.h"
"${PROFILE_DIR}/device/common/*.cpp"
)

if (XDP_MINIMAL_BUILD STREQUAL "yes")
add_library(xdp_aie_debug_plugin MODULE ${AIE_DEBUG_PLUGIN_FILES})
add_library(xdp_aie_debug_plugin MODULE ${AIE_DEBUG_PLUGIN_FILES} ${AIE_DRIVER_COMMON_UTIL_FILES})
add_dependencies(xdp_aie_debug_plugin xdp_core xrt_coreutil)
include_directories(xdp_aie_debug_plugin PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/transactions)
target_link_libraries(xdp_aie_debug_plugin PRIVATE xdp_core xrt_coreutil xaiengine)
target_compile_definitions(xdp_aie_debug_plugin PRIVATE XDP_MINIMAL_BUILD=1 -DXAIE_FEATURE_MSVC)
target_include_directories(xdp_aie_debug_plugin PRIVATE ${AIERT_DIR}/include)
Expand Down
Loading

0 comments on commit 23d66ef

Please sign in to comment.