You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2020/05/15 16:27:54 UTC
[incubator-tvm] branch master updated: Add ostream formatters for
TargetPtr/TargetVal. (#5592)
This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push:
new de523d3 Add ostream formatters for TargetPtr/TargetVal. (#5592)
de523d3 is described below
commit de523d3376b502299955b20ef06fc5f537956552
Author: Andrew Reusch <ar...@octoml.ai>
AuthorDate: Fri May 15 09:27:44 2020 -0700
Add ostream formatters for TargetPtr/TargetVal. (#5592)
---
src/runtime/micro/host_driven/utvm_runtime.h | 16 +------
src/runtime/micro/host_driven/utvm_runtime_enum.h | 51 +++++++++++++++++++++++
src/runtime/micro/micro_common.cc | 28 +++++++++++++
src/runtime/micro/micro_common.h | 5 +++
src/runtime/micro/target_data_layout_encoder.h | 2 +-
5 files changed, 86 insertions(+), 16 deletions(-)
diff --git a/src/runtime/micro/host_driven/utvm_runtime.h b/src/runtime/micro/host_driven/utvm_runtime.h
index 1a4486c..8758c3a 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 <tvm/runtime/c_backend_api.h>
#include <tvm/runtime/c_runtime_api.h>
-/*!
- * \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 0000000..17f8036
--- /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 020df62..eba77f3 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 4375791..2c4684b 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 9778177..0744dd1 100644
--- a/src/runtime/micro/target_data_layout_encoder.h
+++ b/src/runtime/micro/target_data_layout_encoder.h
@@ -26,7 +26,7 @@
#include <vector>
-#include "host_driven/utvm_runtime.h"
+#include "host_driven/utvm_runtime_enum.h"
namespace tvm {
namespace runtime {