Skip to content

Commit

Permalink
#71: Added ttmlir versioning (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapspatel authored Jul 11, 2024
1 parent a637748 commit c6b37f9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
33 changes: 30 additions & 3 deletions cmake/modules/TTMLIRVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
# get git commit hash
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE TTMLIR_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# get the latest tag from Git
execute_process(
COMMAND git describe --tags --abbrev=0
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# get the number of commits since the latest tag
execute_process(
COMMAND git rev-list ${GIT_TAG}..HEAD --count
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_COMMITS
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Extract the major and minor version from the tag (assumes tags are in "major.minor" format)
string(REGEX MATCH "^v([0-9]+)\\.([0-9]+)$" GIT_TAG_MATCH ${GIT_TAG})
set(PROJECT_VERSION_MAJOR ${CMAKE_MATCH_1})
set(PROJECT_VERSION_MINOR ${CMAKE_MATCH_2})
set(PROJECT_VERSION_PATCH ${GIT_COMMITS})

message(STATUS "Project commit hash: ${TTMLIR_GIT_HASH}")
message(STATUS "Project version: ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")

add_definitions("-DTTMLIR_GIT_HASH=${TTMLIR_GIT_HASH}")
add_definitions("-DTTMLIR_VERSION_MAJOR=0")
add_definitions("-DTTMLIR_VERSION_MINOR=0")
add_definitions("-DTTMLIR_VERSION_RELEASE=0")
add_definitions("-DTTMLIR_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}")
add_definitions("-DTTMLIR_VERSION_MINOR=${PROJECT_VERSION_MINOR}")
add_definitions("-DTTMLIR_VERSION_PATCH=${PROJECT_VERSION_PATCH}")
2 changes: 1 addition & 1 deletion include/ttmlir/Target/Common/version.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace tt.target;
struct Version {
major: uint16;
minor: uint16;
release: uint32;
patch: uint32;
}
12 changes: 6 additions & 6 deletions include/ttmlir/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ namespace ttmlir {
#ifndef TTMLIR_VERSION_MINOR
#error "TTMLIR_VERSION_MINOR must be defined"
#endif
#ifndef TTMLIR_VERSION_RELEASE
#error "TTMLIR_VERSION_RELEASE must be defined"
#ifndef TTMLIR_VERSION_PATCH
#error "TTMLIR_VERSION_PATCH must be defined"
#endif

struct Version {
unsigned major;
unsigned minor;
unsigned release;
unsigned patch;

constexpr Version(unsigned major, unsigned minor, unsigned release)
: major(major), minor(minor), release(release) {}
constexpr Version(unsigned major, unsigned minor, unsigned patch)
: major(major), minor(minor), patch(patch) {}

constexpr bool operator<=(const Version &other) const {
return major < other.major ||
Expand All @@ -41,7 +41,7 @@ struct Version {

inline constexpr Version getVersion() {
return Version(TTMLIR_VERSION_MAJOR, TTMLIR_VERSION_MINOR,
TTMLIR_VERSION_RELEASE);
TTMLIR_VERSION_PATCH);
}

#define XSTR(s) STR(s)
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/TTMetal/Transforms/SerializeToBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class TTMetalSerializeToBinary

::ttmlir::Version ttmlirVersion = ::ttmlir::getVersion();
::tt::target::Version binaryVersion(
ttmlirVersion.major, ttmlirVersion.minor, ttmlirVersion.release);
ttmlirVersion.major, ttmlirVersion.minor, ttmlirVersion.patch);

std::vector<::flatbuffers::Offset<::tt::target::metal::CommandQueue>>
commandQueues = {
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/TTNN/Transforms/SerializeToBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class TTNNSerializeToBinary

::ttmlir::Version ttmlirVersion = ::ttmlir::getVersion();
::tt::target::Version binaryVersion(
ttmlirVersion.major, ttmlirVersion.minor, ttmlirVersion.release);
ttmlirVersion.major, ttmlirVersion.minor, ttmlirVersion.patch);

ModuleOp module = getOperation();
auto systemDesc = toFlatbuffer(
Expand Down
1 change: 1 addition & 0 deletions runtime/include/tt/runtime/detail/ttnn.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#pragma clang diagnostic ignored "-Wunneeded-internal-declaration"
#pragma clang diagnostic ignored "-Wunused-local-typedef"
#pragma clang diagnostic ignored "-Wunused-function"
#pragma clang diagnostic ignored "-Wpessimizing-move"
#define FMT_HEADER_ONLY
#include "ttnn//operations/reduction/generic/generic_reductions.hpp"
#include "ttnn/device.hpp"
Expand Down
4 changes: 2 additions & 2 deletions runtime/lib/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ std::string getVersion(Flatbuffer binary) {
auto const *version = getBinary(binary)->version();
return std::to_string(version->major()) + "." +
std::to_string(version->minor()) + "." +
std::to_string(version->release());
std::to_string(version->patch());
}

std::string_view getTTMLIRGitHash(Flatbuffer binary) {
Expand Down Expand Up @@ -116,7 +116,7 @@ std::string getVersion(Flatbuffer binary) {
auto const *version = getBinary(binary)->version();
return std::to_string(version->major()) + "." +
std::to_string(version->minor()) + "." +
std::to_string(version->release());
std::to_string(version->patch());
}

std::string_view getTTMLIRGitHash(Flatbuffer binary) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/ttnn/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ std::pair<SystemDesc, DeviceIds> getCurrentSystemDesc() {
::flatbuffers::FlatBufferBuilder fbb;
::ttmlir::Version ttmlirVersion = ::ttmlir::getVersion();
::tt::target::Version version(ttmlirVersion.major, ttmlirVersion.minor,
ttmlirVersion.release);
ttmlirVersion.patch);
::tt::target::Dim2d deviceGrid = toFlatbuffer(device.logical_grid_size());
std::vector<::flatbuffers::Offset<tt::target::ChipDesc>> chipDescs = {
::tt::target::CreateChipDesc(fbb, toFlatbuffer(device.arch()),
Expand Down

0 comments on commit c6b37f9

Please sign in to comment.