Skip to content

Commit

Permalink
[ODLA] Add version api
Browse files Browse the repository at this point in the history
  • Loading branch information
Weiming Zhao committed Nov 29, 2021
1 parent 1577a50 commit dc639ad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
11 changes: 11 additions & 0 deletions ODLA/include/ODLA/odla_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* \details This file defines the ODLA version number.
*/

#include <ODLA/odla_common.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/halo/lib/transforms/typecast.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
76 changes: 31 additions & 45 deletions lib/transforms/typecast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@

namespace halo {

template <typename Tsrc, typename Tdst>
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<Tdst> ret;
auto n = orig_type.GetTotalNumOfElements();
ret.reserve(n);
for (unsigned int i = 0; i < n; ++i) {
ret.push_back(static_cast<float>(c->GetData<Tsrc>(i)));
}
c->SetData(halo::Type{new_type, orig_type.GetDimSizes()}, ret.data());
return true;
}

bool TypeCast::RunOnFunction(Function* func) {
bool changed = false;
// Replace arguments.
Expand All @@ -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<float> ret;
ret.reserve(orig_type.GetTotalNumOfElements());
for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) {
ret.push_back(static_cast<float>((*it)->GetData<double>(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<int> ret;
ret.reserve(orig_type.GetTotalNumOfElements());
for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) {
ret.push_back(static_cast<int>((*it)->GetData<int64_t>(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<float> ret;
ret.reserve(orig_type.GetTotalNumOfElements());
for (unsigned int i = 0; i < orig_type.GetTotalNumOfElements(); ++i) {
ret.push_back(static_cast<float>((*it)->GetData<double>(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<double, float>(c.get(), DataType::FLOAT64,
DataType::FLOAT32);
changed |= ReplaceConstant<int64_t, int32_t>(c.get(), DataType::INT64,
DataType::INT32);
}

for (auto& c : func->Constants()) {
changed |= ReplaceConstant<double, float>(c.get(), DataType::FLOAT64,
DataType::FLOAT32);
changed |= ReplaceConstant<int64_t, int32_t>(c.get(), DataType::INT64,
DataType::INT32);
}

for (auto& bb : *func) {
Expand All @@ -101,6 +87,6 @@ bool TypeCast::RunOnFunction(Function* func) {
}
}
return changed;
} // namespace halo
}

} // end namespace halo

0 comments on commit dc639ad

Please sign in to comment.