[PATCH] D85262: [llvm] Expose untyped accessor to evaluation result tensors
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 4 17:57:18 PDT 2020
mtrofin created this revision.
mtrofin added reviewers: davidxl, ebrevdo, yundiqian.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
mtrofin requested review of this revision.
These were implementation detail, but become necessary for generic data
copying.
Also added const variations to them, and move assignment, since we had a
move ctor (and the move assignment helps in a subsequent patch).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85262
Files:
llvm/include/llvm/Analysis/Utils/TFUtils.h
llvm/lib/Analysis/TFUtils.cpp
llvm/unittests/Analysis/TFUtilsTest.cpp
Index: llvm/unittests/Analysis/TFUtilsTest.cpp
===================================================================
--- llvm/unittests/Analysis/TFUtilsTest.cpp
+++ llvm/unittests/Analysis/TFUtilsTest.cpp
@@ -56,6 +56,8 @@
EXPECT_TRUE(ER.hasValue());
float Ret = *ER->getTensorValue<float>(0);
EXPECT_EQ(static_cast<size_t>(Ret), 80);
+ EXPECT_EQ(ER->getUntypedTensorValue(0),
+ reinterpret_cast<const void *>(ER->getTensorValue<float>(0)));
}
// The input vector should be unchanged
for (auto I = 0; I < KnownSize; ++I) {
Index: llvm/lib/Analysis/TFUtils.cpp
===================================================================
--- llvm/lib/Analysis/TFUtils.cpp
+++ llvm/lib/Analysis/TFUtils.cpp
@@ -292,10 +292,21 @@
TFModelEvaluator::EvaluationResult::EvaluationResult(EvaluationResult &&Other)
: Impl(std::move(Other.Impl)) {}
+TFModelEvaluator::EvaluationResult &
+TFModelEvaluator::EvaluationResult::operator=(EvaluationResult &&Other) {
+ Impl = std::move(Other.Impl);
+ return *this;
+}
+
void *TFModelEvaluator::EvaluationResult::getUntypedTensorValue(size_t Index) {
return TF_TensorData(Impl->getOutput()[Index]);
}
+const void *
+TFModelEvaluator::EvaluationResult::getUntypedTensorValue(size_t Index) const {
+ return TF_TensorData(Impl->getOutput()[Index]);
+}
+
#define TFUTILS_GETDATATYPE_IMPL(T, S, E) \
template <> int TensorSpec::getDataType<T>() { return TF_##E; }
Index: llvm/include/llvm/Analysis/Utils/TFUtils.h
===================================================================
--- llvm/include/llvm/Analysis/Utils/TFUtils.h
+++ llvm/include/llvm/Analysis/Utils/TFUtils.h
@@ -101,18 +101,29 @@
class EvaluationResult {
public:
EvaluationResult(const EvaluationResult &) = delete;
+ EvaluationResult &operator=(const EvaluationResult &Other) = delete;
+
EvaluationResult(EvaluationResult &&Other);
+ EvaluationResult &operator=(EvaluationResult &&Other);
+
~EvaluationResult();
- /// Get a pointer to the first element of the tensor at Index.
+ /// Get a (const) pointer to the first element of the tensor at Index.
template <typename T> T *getTensorValue(size_t Index) {
return static_cast<T *>(getUntypedTensorValue(Index));
}
+ template <typename T> const T *getTensorValue(size_t Index) const {
+ return static_cast<T *>(getUntypedTensorValue(Index));
+ }
+
+ /// Get a (const) pointer to the untyped data of the tensor.
+ void *getUntypedTensorValue(size_t Index);
+ const void *getUntypedTensorValue(size_t Index) const;
+
private:
friend class TFModelEvaluator;
EvaluationResult(std::unique_ptr<EvaluationResultImpl> Impl);
- void *getUntypedTensorValue(size_t Index);
std::unique_ptr<EvaluationResultImpl> Impl;
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85262.283082.patch
Type: text/x-patch
Size: 2845 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/c3852f0e/attachment.bin>
More information about the llvm-commits
mailing list