diff --git a/.gitignore b/.gitignore index 4ad2d60f..78629c12 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ compile_commands.json .vscode/ *.log *.csv + +# Generated flatbuffer header for simulation device +device/simulation/tt_simulation_device_generated.h diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index a8443120..d1315dcc 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -62,11 +62,34 @@ CPMAddPackage( GITHUB_REPOSITORY google/flatbuffers GIT_TAG v24.3.25 OPTIONS - "FLATBUFFERS_BUILD_FLATC OFF" + "FLATBUFFERS_BUILD_FLATC ON" "FLATBUFFERS_BUILD_TESTS OFF" "FLATBUFFERS_SKIP_MONSTER_EXTRA ON" "FLATBUFFERS_STRICT_MODE ON" ) +function(GENERATE_FBS_HEADER FBS_FILE) + get_filename_component(FBS_FILE_NAME ${FBS_FILE} NAME) + get_filename_component(FBS_FILE_DIR ${FBS_FILE} DIRECTORY) + set(FBS_GENERATED_HEADER "${FBS_FILE_DIR}/${FBS_FILE_NAME}_generated.h") + add_custom_command( + OUTPUT + ${FBS_GENERATED_HEADER} + COMMAND + flatc + ARGS + --cpp -o "${FBS_FILE_DIR}/" ${FBS_FILE} + DEPENDS + flatc + ${FBS_FILE} + COMMENT "Building C++ header for ${FBS_FILE}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + ) + add_custom_target( + flatbuffer_generated_header + DEPENDS + ${FBS_GENERATED_HEADER} + ) +endfunction() ############################################################################################################################ # libuv (for process management) diff --git a/device/CMakeLists.txt b/device/CMakeLists.txt index 87a4e77e..2035f32c 100644 --- a/device/CMakeLists.txt +++ b/device/CMakeLists.txt @@ -1,5 +1,9 @@ set(POSITION_INDEPENDENT_CODE ON) +GENERATE_FBS_HEADER( + ${PROJECT_SOURCE_DIR}/device/simulation/tt_simulation_device.fbs +) + set(UMD_DEVICE_SRCS architecture_implementation.cpp cpuset_lib.cpp @@ -24,6 +28,8 @@ add_library(device SHARED ${UMD_DEVICE_SRCS}) add_library(${PROJECT_NAME}::device ALIAS device) add_library(${PROJECT_NAME}_device ALIAS device) # For legacy I guess +add_dependencies(device flatbuffer_generated_header) + target_include_directories( device PUBLIC diff --git a/device/simulation/tt_simulation_device_generated.h b/device/simulation/tt_simulation_device_generated.h deleted file mode 100644 index 82c77443..00000000 --- a/device/simulation/tt_simulation_device_generated.h +++ /dev/null @@ -1,218 +0,0 @@ -// automatically generated by the FlatBuffers compiler, do not modify - - -#ifndef FLATBUFFERS_GENERATED_TTSIMULATIONDEVICE_H_ -#define FLATBUFFERS_GENERATED_TTSIMULATIONDEVICE_H_ - -#include "flatbuffers/flatbuffers.h" - -// Ensure the included flatbuffers.h is the same version as when this file was -// generated, otherwise it may not be compatible. -static_assert(FLATBUFFERS_VERSION_MAJOR == 24 && - FLATBUFFERS_VERSION_MINOR == 3 && - FLATBUFFERS_VERSION_REVISION == 25, - "Non-compatible flatbuffers version included"); - -struct tt_vcs_core; - -struct DeviceRequestResponse; -struct DeviceRequestResponseBuilder; - -enum DEVICE_COMMAND : int8_t { - DEVICE_COMMAND_WRITE = 0, - DEVICE_COMMAND_READ = 1, - DEVICE_COMMAND_WRITE_SYSMEM = 2, - DEVICE_COMMAND_READ_SYSMEM = 3, - DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT = 4, - DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT = 5, - DEVICE_COMMAND_EXIT = 6, - DEVICE_COMMAND_MIN = DEVICE_COMMAND_WRITE, - DEVICE_COMMAND_MAX = DEVICE_COMMAND_EXIT -}; - -inline const DEVICE_COMMAND (&EnumValuesDEVICE_COMMAND())[7] { - static const DEVICE_COMMAND values[] = { - DEVICE_COMMAND_WRITE, - DEVICE_COMMAND_READ, - DEVICE_COMMAND_WRITE_SYSMEM, - DEVICE_COMMAND_READ_SYSMEM, - DEVICE_COMMAND_ALL_TENSIX_RESET_DEASSERT, - DEVICE_COMMAND_ALL_TENSIX_RESET_ASSERT, - DEVICE_COMMAND_EXIT - }; - return values; -} - -inline const char * const *EnumNamesDEVICE_COMMAND() { - static const char * const names[8] = { - "WRITE", - "READ", - "WRITE_SYSMEM", - "READ_SYSMEM", - "ALL_TENSIX_RESET_DEASSERT", - "ALL_TENSIX_RESET_ASSERT", - "EXIT", - nullptr - }; - return names; -} - -inline const char *EnumNameDEVICE_COMMAND(DEVICE_COMMAND e) { - if (::flatbuffers::IsOutRange(e, DEVICE_COMMAND_WRITE, DEVICE_COMMAND_EXIT)) return ""; - const size_t index = static_cast(e); - return EnumNamesDEVICE_COMMAND()[index]; -} - -FLATBUFFERS_MANUALLY_ALIGNED_STRUCT(8) tt_vcs_core FLATBUFFERS_FINAL_CLASS { - private: - uint64_t x_; - uint64_t y_; - - public: - tt_vcs_core() - : x_(0), - y_(0) { - } - tt_vcs_core(uint64_t _x, uint64_t _y) - : x_(::flatbuffers::EndianScalar(_x)), - y_(::flatbuffers::EndianScalar(_y)) { - } - uint64_t x() const { - return ::flatbuffers::EndianScalar(x_); - } - uint64_t y() const { - return ::flatbuffers::EndianScalar(y_); - } -}; -FLATBUFFERS_STRUCT_END(tt_vcs_core, 16); - -struct DeviceRequestResponse FLATBUFFERS_FINAL_CLASS : private ::flatbuffers::Table { - typedef DeviceRequestResponseBuilder Builder; - enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE { - VT_COMMAND = 4, - VT_DATA = 6, - VT_CORE = 8, - VT_ADDRESS = 10, - VT_SIZE = 12 - }; - DEVICE_COMMAND command() const { - return static_cast(GetField(VT_COMMAND, 0)); - } - const ::flatbuffers::Vector *data() const { - return GetPointer *>(VT_DATA); - } - const tt_vcs_core *core() const { - return GetStruct(VT_CORE); - } - uint64_t address() const { - return GetField(VT_ADDRESS, 0); - } - uint32_t size() const { - return GetField(VT_SIZE, 0); - } - bool Verify(::flatbuffers::Verifier &verifier) const { - return VerifyTableStart(verifier) && - VerifyField(verifier, VT_COMMAND, 1) && - VerifyOffset(verifier, VT_DATA) && - verifier.VerifyVector(data()) && - VerifyField(verifier, VT_CORE, 8) && - VerifyField(verifier, VT_ADDRESS, 8) && - VerifyField(verifier, VT_SIZE, 4) && - verifier.EndTable(); - } -}; - -struct DeviceRequestResponseBuilder { - typedef DeviceRequestResponse Table; - ::flatbuffers::FlatBufferBuilder &fbb_; - ::flatbuffers::uoffset_t start_; - void add_command(DEVICE_COMMAND command) { - fbb_.AddElement(DeviceRequestResponse::VT_COMMAND, static_cast(command), 0); - } - void add_data(::flatbuffers::Offset<::flatbuffers::Vector> data) { - fbb_.AddOffset(DeviceRequestResponse::VT_DATA, data); - } - void add_core(const tt_vcs_core *core) { - fbb_.AddStruct(DeviceRequestResponse::VT_CORE, core); - } - void add_address(uint64_t address) { - fbb_.AddElement(DeviceRequestResponse::VT_ADDRESS, address, 0); - } - void add_size(uint32_t size) { - fbb_.AddElement(DeviceRequestResponse::VT_SIZE, size, 0); - } - explicit DeviceRequestResponseBuilder(::flatbuffers::FlatBufferBuilder &_fbb) - : fbb_(_fbb) { - start_ = fbb_.StartTable(); - } - ::flatbuffers::Offset Finish() { - const auto end = fbb_.EndTable(start_); - auto o = ::flatbuffers::Offset(end); - return o; - } -}; - -inline ::flatbuffers::Offset CreateDeviceRequestResponse( - ::flatbuffers::FlatBufferBuilder &_fbb, - DEVICE_COMMAND command = DEVICE_COMMAND_WRITE, - ::flatbuffers::Offset<::flatbuffers::Vector> data = 0, - const tt_vcs_core *core = nullptr, - uint64_t address = 0, - uint32_t size = 0) { - DeviceRequestResponseBuilder builder_(_fbb); - builder_.add_address(address); - builder_.add_size(size); - builder_.add_core(core); - builder_.add_data(data); - builder_.add_command(command); - return builder_.Finish(); -} - -inline ::flatbuffers::Offset CreateDeviceRequestResponseDirect( - ::flatbuffers::FlatBufferBuilder &_fbb, - DEVICE_COMMAND command = DEVICE_COMMAND_WRITE, - const std::vector *data = nullptr, - const tt_vcs_core *core = nullptr, - uint64_t address = 0, - uint32_t size = 0) { - auto data__ = data ? _fbb.CreateVector(*data) : 0; - return CreateDeviceRequestResponse( - _fbb, - command, - data__, - core, - address, - size); -} - -inline const DeviceRequestResponse *GetDeviceRequestResponse(const void *buf) { - return ::flatbuffers::GetRoot(buf); -} - -inline const DeviceRequestResponse *GetSizePrefixedDeviceRequestResponse(const void *buf) { - return ::flatbuffers::GetSizePrefixedRoot(buf); -} - -inline bool VerifyDeviceRequestResponseBuffer( - ::flatbuffers::Verifier &verifier) { - return verifier.VerifyBuffer(nullptr); -} - -inline bool VerifySizePrefixedDeviceRequestResponseBuffer( - ::flatbuffers::Verifier &verifier) { - return verifier.VerifySizePrefixedBuffer(nullptr); -} - -inline void FinishDeviceRequestResponseBuffer( - ::flatbuffers::FlatBufferBuilder &fbb, - ::flatbuffers::Offset root) { - fbb.Finish(root); -} - -inline void FinishSizePrefixedDeviceRequestResponseBuffer( - ::flatbuffers::FlatBufferBuilder &fbb, - ::flatbuffers::Offset root) { - fbb.FinishSizePrefixed(root); -} - -#endif // FLATBUFFERS_GENERATED_TTSIMULATIONDEVICE_H_