From 1d797c6c8af1a75de22c9464d6a8c339e6e8ce37 Mon Sep 17 00:00:00 2001 From: Snigdha Gupta Date: Fri, 3 Jan 2025 14:27:49 -0800 Subject: [PATCH] Added register interpreter class --- .../generations/register_interpreter.cpp | 115 ++++++++++++++++++ .../generations/register_interpreter.h | 47 +++++++ 2 files changed, 162 insertions(+) create mode 100755 src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.cpp create mode 100755 src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.h diff --git a/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.cpp b/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.cpp new file mode 100755 index 00000000000..df12c6839bd --- /dev/null +++ b/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.cpp @@ -0,0 +1,115 @@ +/** + * 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 + * 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. + */ +#include +#include "xdp/profile/writer/aie_debug/register_interpreter.h" +#include "xdp/profile/database/database.h" +#include "xdp/profile/database/static_info/aie_constructs.h" +#include "xdp/profile/database/static_info/aie_util.h" +#include "xdp/profile/database/dynamic_event_database.h" +#include "xdp/profile/plugin/vp_base/utility.h" + +#include +#include +#include + +namespace xdp { + + RegisterInterpreter::RegisterInterpreter() { } + + void RegisterInterpreter::readFromGenCSV(const std::string &filename, const std::string ®Name) { + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "Error opening file" << std::endl; + return false; + } + + std::string line; + std::getline(file, line); // Skip the header line + + RegData data; + bool readAll = false; + // Read each line from the CSV file + while (std::getline(file, line)) { + std::stringstream ss(line); + + // Read each column value + std::getline(ss, data.register_name, ','); + if (data.register_name != regName) { + if (readAll) break; + else continue; + } + std::getline(ss, data.address, ','); + std::getline(ss, data.field_name, ','); + std::getline(ss, data.bits, ','); + std::getline(ss, data.type, ','); + std::getline(ss, data.reset_value, ','); + std::getline(ss, data.description, ','); + + // Add the struct to the vector + aie_gen_data.push_back(data); + + readAll = true; + } + + file.close(); + return true; + } + + void RegisterInterpreter::registerInfo(const std::string ®Name, const uint64_t ®Val) { + auto aieGeneration = (db->getStaticInfo()).getAIEGeneration(mDeviceIndex); + std::string filename; + + if (aieGeneration >= 2 && aieGeneration <= 4) { + filename = "aie2_registers.csv"; + } else if (aieGeneration == 5) { + filename = "aie2ps_registers.csv"; + } else if (aieGeneration >= 40) { + filename = "aie4_registers.csv"; + } else { + filename = "aie1_registers.csv"; + } + readFromGenCSV(filename, regName); + + for (RegData data : aie_gen_data) { + int shift; + uint64_t mask; + std::size_t pos = data.bits.find(':'); + if (pos != std::string::npos) { + // bit range xx:xx + shift = std::stoi(data.bits.substr(0, pos)); + int end = std::stoi(data.bits.substr(pos + 1)); + int numBits = end - shift + 1; + mask = (1u << numBits) - 1; + } else { + // single bit + shift = std::stoi(data.bits); + mask = 1; + } + + uint64_t subval = (regVal >> shift) & mask; + fout << regName << "," + << data.field_name << "," + << data.bits << "," + << "0x" << std::hex << subval << "\n"; + } + } + +} // end namespace xdp + + + + + diff --git a/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.h b/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.h new file mode 100755 index 00000000000..771090f7078 --- /dev/null +++ b/src/runtime_src/xdp/profile/writer/aie_debug/generations/register_interpreter.h @@ -0,0 +1,47 @@ +/** + * 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 + * 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 REGISTER_INTERPRETER_DOT_H +#define REGISTER_INTERPRETER_DOT_H + +#include "xdp/profile/plugin/aie_debug/aie_debug_plugin.h" +#include + +namespace xdp { +class RegisterInterpreter + { +public: + RegisterInterpreter(); + ~RegisterInterpreter()=default; + + void readFromGenCSV(const std::string &filename, const std::string ®Name); + void registerInfo(const std::string ®Name, const uint64_t ®Val); + + private: + struct RegData { + std::string register_name; + uint64_t address; + std::string field_name; + std::string bits; + std::string type; + std::string reset_value; + std::string description; + }; + + std::vector aie_gen_data; + }; +} // end namespace xdp + +#endif