From dc639adaaf3e0267e2e4bcd5ea316ea428ffe86c Mon Sep 17 00:00:00 2001 From: Weiming Zhao Date: Mon, 29 Nov 2021 20:01:15 +0000 Subject: [PATCH] [ODLA] Add version api --- CMakeLists.txt | 2 +- ODLA/include/ODLA/odla_version.h | 11 ++++ include/halo/lib/transforms/typecast.h | 2 +- lib/transforms/typecast.cc | 76 +++++++++++--------------- 4 files changed, 44 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b34b3a629..70c4e25b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ cmake_minimum_required(VERSION 3.14.5) set(PROJECT_NAME "HALO" HOMEPAGE_URL "https://github.com/alibaba/heterogeneity-aware-lowering-and-optimization") -set(PROJECT_VERSION "0.7.0") +set(PROJECT_VERSION "0.7.2") project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C CXX ASM) diff --git a/ODLA/include/ODLA/odla_version.h b/ODLA/include/ODLA/odla_version.h index 01f982b50..2c4776097 100644 --- a/ODLA/include/ODLA/odla_version.h +++ b/ODLA/include/ODLA/odla_version.h @@ -22,6 +22,8 @@ * \details This file defines the ODLA version number. */ +#include + #ifdef __cplusplus extern "C" { #endif @@ -33,6 +35,15 @@ extern "C" { //! \brief ODLA version number. #define ODLA_VERSION_NUMBER ((ODLA_MAJOR)*100 + (ODLA_MINOR)*10 + (OLDA_PATCH)) +const char* ODLAAPIVersion __attribute__((weak)) = + ODLA_VERSION_STR(ODLA_MAJOR, ODLA_MINOR, ODLA_PATCH); + +//! \brief Get version string of the library. +/*! + \return NULL-terminated string of version info. +*/ +const odla_char* odla_GetVersionString(); + #ifdef __cplusplus } // C extern #endif diff --git a/include/halo/lib/transforms/typecast.h b/include/halo/lib/transforms/typecast.h index 990bb87c2..a2343b11f 100644 --- a/include/halo/lib/transforms/typecast.h +++ b/include/halo/lib/transforms/typecast.h @@ -25,7 +25,7 @@ namespace halo { /// This pass eliminates usage of int64 by casting down. class TypeCast final : public FunctionPass { public: - TypeCast() : FunctionPass("Cast down int64 to int32") {} + TypeCast() : FunctionPass("Cast down int64/fp64 to int32/fp32") {} bool RunOnFunction(Function* func) override; }; diff --git a/lib/transforms/typecast.cc b/lib/transforms/typecast.cc index 7153b77c4..68d9b83c2 100644 --- a/lib/transforms/typecast.cc +++ b/lib/transforms/typecast.cc @@ -23,6 +23,22 @@ namespace halo { +template +static bool ReplaceConstant(Constant* c, DataType src_type, DataType new_type) { + const auto& orig_type = c->GetResultType(0); + if (orig_type.GetDataType() != src_type) { + return false; + } + std::vector ret; + auto n = orig_type.GetTotalNumOfElements(); + ret.reserve(n); + for (unsigned int i = 0; i < n; ++i) { + ret.push_back(static_cast(c->GetData(i))); + } + c->SetData(halo::Type{new_type, orig_type.GetDimSizes()}, ret.data()); + return true; +} + bool TypeCast::RunOnFunction(Function* func) { bool changed = false; // Replace arguments. @@ -38,51 +54,21 @@ bool TypeCast::RunOnFunction(Function* func) { changed |= true; } } - { - Module* m = func->GetParent(); - Function::ConstantList& constants = m->Constants(); - for (auto it = constants.begin(), ie = constants.end(); it != ie; ++it) { - const auto& orig_type = (*it)->GetResultType(0); - if (orig_type.GetDataType() == DataType::FLOAT64) { - std::vector ret; - ret.reserve(orig_type.GetTotalNumOfElements()); - for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) { - ret.push_back(static_cast((*it)->GetData(i))); - } - (*it)->SetData(halo::Type{DataType::FLOAT32, orig_type.GetDimSizes()}, - ret.data()); - changed = true; - } - } - } + // Replace constants. - ConstantBuilder cb(func); - Function::ConstantList& constants = func->Constants(); - for (auto it = constants.begin(), ie = constants.end(); it != ie; ++it) { - const auto& orig_type = (*it)->GetResultType(0); - if (orig_type.GetDataType() == DataType::INT64) { - std::vector ret; - ret.reserve(orig_type.GetTotalNumOfElements()); - for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) { - ret.push_back(static_cast((*it)->GetData(i))); - } - Constant* c_ret = cb.CreateConstant( - (*it)->GetName() + "_castdown", - halo::Type{DataType::INT32, orig_type.GetDimSizes()}, ret.data()); - (*it)->ReplaceAllUsesWith(0, *c_ret); - changed = true; - } else if (orig_type.GetDataType() == DataType::FLOAT64) { - std::vector ret; - ret.reserve(orig_type.GetTotalNumOfElements()); - for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) { - ret.push_back(static_cast((*it)->GetData(i))); - } - Constant* c_ret = cb.CreateConstant( - (*it)->GetName() + "_castdown", - halo::Type{DataType::FLOAT32, orig_type.GetDimSizes()}, ret.data()); - (*it)->ReplaceAllUsesWith(0, *c_ret); - changed = true; - } + Module* m = func->GetParent(); + for (auto& c : m->Constants()) { + changed |= ReplaceConstant(c.get(), DataType::FLOAT64, + DataType::FLOAT32); + changed |= ReplaceConstant(c.get(), DataType::INT64, + DataType::INT32); + } + + for (auto& c : func->Constants()) { + changed |= ReplaceConstant(c.get(), DataType::FLOAT64, + DataType::FLOAT32); + changed |= ReplaceConstant(c.get(), DataType::INT64, + DataType::INT32); } for (auto& bb : *func) { @@ -101,6 +87,6 @@ bool TypeCast::RunOnFunction(Function* func) { } } return changed; -} // namespace halo +} } // end namespace halo