diff --git a/src/runtime/micro/host_driven/utvm_runtime.h b/src/runtime/micro/host_driven/utvm_runtime.h index 1a4486c12d7c..8758c3ad89a1 100644 --- a/src/runtime/micro/host_driven/utvm_runtime.h +++ b/src/runtime/micro/host_driven/utvm_runtime.h @@ -32,21 +32,7 @@ extern "C" { #include #include -/*! - * \brief TODO - */ -enum UTVMReturnCode { - UTVM_ERR_OK = 0, - UTVM_ERR_NOT_FINISHED = -1, - UTVM_ERR_TIMER_NOT_IMPLEMENTED = -2, - UTVM_ERR_TIMER_OVERFLOW = -3, - UTVM_ERR_WS_DOUBLE_FREE = -4, - UTVM_ERR_WS_OUT_OF_SPACE = -5, - UTVM_ERR_WS_TOO_MANY_ALLOCS = -6, - UTVM_ERR_WS_ZERO_SIZE_ALLOC = -7, - UTVM_ERR_WS_UNALIGNED_START = -8, - UTVM_ERR_WS_UNALIGNED_ALLOC_SIZE = -9, -}; +#include "utvm_runtime_enum.h" /*! * \brief Task structure for uTVM diff --git a/src/runtime/micro/host_driven/utvm_runtime_enum.h b/src/runtime/micro/host_driven/utvm_runtime_enum.h new file mode 100644 index 000000000000..17f803612cb9 --- /dev/null +++ b/src/runtime/micro/host_driven/utvm_runtime_enum.h @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License 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. + */ + +/*! + * \file utvm_runtime_enum.h + * \brief Defines constants used both on the host and on device. + */ +#ifndef TVM_RUNTIME_MICRO_HOST_DRIVEN_UTVM_RUNTIME_ENUM_H_ +#define TVM_RUNTIME_MICRO_HOST_DRIVEN_UTVM_RUNTIME_ENUM_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*! + * \brief TODO + */ +enum UTVMReturnCode { + UTVM_ERR_OK = 0, + UTVM_ERR_NOT_FINISHED = -1, + UTVM_ERR_TIMER_NOT_IMPLEMENTED = -2, + UTVM_ERR_TIMER_OVERFLOW = -3, + UTVM_ERR_WS_DOUBLE_FREE = -4, + UTVM_ERR_WS_OUT_OF_SPACE = -5, + UTVM_ERR_WS_TOO_MANY_ALLOCS = -6, + UTVM_ERR_WS_ZERO_SIZE_ALLOC = -7, + UTVM_ERR_WS_UNALIGNED_START = -8, + UTVM_ERR_WS_UNALIGNED_ALLOC_SIZE = -9, +}; + +#ifdef __cplusplus +} // TVM_EXTERN_C +#endif + +#endif // TVM_RUNTIME_MICRO_HOST_DRIVEN_UTVM_RUNTIME_ENUM_H_ diff --git a/src/runtime/micro/micro_common.cc b/src/runtime/micro/micro_common.cc index 020df625c709..eba77f3dadbc 100644 --- a/src/runtime/micro/micro_common.cc +++ b/src/runtime/micro/micro_common.cc @@ -99,5 +99,33 @@ size_t GetSectionSize(const std::string& binary_path, SectionKind section, return UpperAlignValue(size, word_size.bytes()); } +std::ostream& operator<<(std::ostream& os, const TargetVal& v) { + std::ios_base::fmtflags f(os.flags()); + os << std::dec << "0x"; + switch (v.width_bits()) { + case 8: + os << uint8_t(v.uint32()); + break; + case 16: + os << uint16_t(v.uint32()); + break; + case 32: + os << v.uint32(); + break; + case 64: + os << v.uint64(); + break; + default: + os << (v.uint64() & ((1 << v.width_bits()) - 1)); + } + os.flags(f); + return os; +} + +std::ostream& operator<<(std::ostream& os, const TargetPtr& v) { + os << "*" << v.value_; + return os; +} + } // namespace runtime } // namespace tvm diff --git a/src/runtime/micro/micro_common.h b/src/runtime/micro/micro_common.h index 4375791e0210..2c4684b357a8 100644 --- a/src/runtime/micro/micro_common.h +++ b/src/runtime/micro/micro_common.h @@ -132,6 +132,9 @@ class TargetVal { value_ = other.value_ & Bitmask(); return *this; } + + private: + friend std::ostream& operator<<(std::ostream& os, const TargetVal& v); }; // TODO(weberlo, areusch): just get rid of `TargetPtr`. @@ -201,6 +204,8 @@ class TargetPtr { private: /*! \brief raw value storing the pointer */ TargetVal value_; + + friend std::ostream& operator<<(std::ostream& os, const TargetPtr& v); }; /*! diff --git a/src/runtime/micro/target_data_layout_encoder.h b/src/runtime/micro/target_data_layout_encoder.h index 97781773eecc..0744dd1755cf 100644 --- a/src/runtime/micro/target_data_layout_encoder.h +++ b/src/runtime/micro/target_data_layout_encoder.h @@ -26,7 +26,7 @@ #include -#include "host_driven/utvm_runtime.h" +#include "host_driven/utvm_runtime_enum.h" namespace tvm { namespace runtime {