[PATCH] D85262: [llvm] Expose untyped accessor to evaluation result tensors
Mircea Trofin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 5 10:10:12 PDT 2020
mtrofin updated this revision to Diff 283285.
mtrofin marked 2 inline comments as done.
mtrofin added a comment.
updated description
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85262/new/
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) {
@@ -137,4 +139,4 @@
EXPECT_EQ(Spec3DLarge.getElementCount(), 80);
EXPECT_EQ(Spec3DLarge.getElementByteSize(), sizeof(float));
EXPECT_EQ(Spec1D.getElementByteSize(), sizeof(int16_t));
-}
\ No newline at end of file
+}
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.283285.patch
Type: text/x-patch
Size: 3071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200805/bbd59bc2/attachment.bin>
More information about the llvm-commits
mailing list