STT-tensorflow/tensorflow/lite/tools/tool_params.h
A. Unique TensorFlower e25d3e084b Merged commit includes the following changes:
319411158  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Integrate LLVM at https://github.com/llvm/llvm-project/commit/d6343e607ac8

--
319410296  by A. Unique TensorFlower<gardener@tensorflow.org>:

    [XLA] Implement extra prefetch limit for while uses.

    Outstanding prefetch limits can prevent prefetches from being scheduled for
    the duration of while loops. Since using alternate memory for the while loops
    can be more beneficial, allow specifying additional prefetch limit when the use
    is a while HLO.

--
319406145  by A. Unique TensorFlower<gardener@tensorflow.org>:

    [XLA:CPU] Teach dot_op_emitter how to tile&vectorize linalg matmuls

    And turn them on by default.

    This is on-par with the existing emitter, sometimes better and unlocks more
    potential. The strategy classes are duplicated right now, but I expect them to
    graduate to mlir core soon.

    I'm planning to remove the custom LLVM IR emitters if this turns out to be
    stable enough.

--
319402982  by A. Unique TensorFlower<gardener@tensorflow.org>:

    PR : [ROCm] Enabling optimized FusedBatchNormInferenceMetaKernel for half

    Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/40327

    This PR enables optimized FusedBatchNormInferenceMetaKernel for half on ROCm.
    Copybara import of the project:

    --
    5f658e2bc1b20794239658bffe0d7bf9cb89c81f by Eugene Kuznetsov <eugene.kuznetsov@amd.com>:

    Enabling optimized FusedBatchNormInferenceMetaKernel for half

--
319393611  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Integrate LLVM at https://github.com/llvm/llvm-project/commit/68498ce8af37

--
319374663  by A. Unique TensorFlower<gardener@tensorflow.org>:

    compat: Update forward compatibility horizon to 2020-07-02

--
319374662  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Update GraphDef version to 450.

--
319371388  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Update framework_build_test targets

--
319363982  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Resolve the permission denied error on Python 3.7 pip install.

--
319361498  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Add an option to only log parameters whose values are parsed from cmdline flags in the benchmark tool.

--
319356677  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Fix bug in ReadNonConstantTensor

    assigning new value to the reference don't update the reference, so use pointer instead.

--
319350974  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Fix the header inclusion path issue with TensorFlowLiteC

--
319342653  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Fix the relationship between tpu_executor and tpu_executor_base build targets.

--
319342578  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Internal change

319340968  by A. Unique TensorFlower<gardener@tensorflow.org>:

    Internal change

PiperOrigin-RevId: 319411158
2020-07-02 10:46:26 -07:00

149 lines
4.0 KiB
C++

/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
Licensed 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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_TOOLS_TOOL_PARAMS_H_
#define TENSORFLOW_LITE_TOOLS_TOOL_PARAMS_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
namespace tflite {
namespace tools {
template <typename T>
class TypedToolParam;
class ToolParam {
protected:
enum class ParamType { TYPE_INT32, TYPE_FLOAT, TYPE_BOOL, TYPE_STRING };
template <typename T>
static ParamType GetValueType();
public:
template <typename T>
static std::unique_ptr<ToolParam> Create(const T& default_value) {
return std::unique_ptr<ToolParam>(new TypedToolParam<T>(default_value));
}
template <typename T>
TypedToolParam<T>* AsTyped() {
AssertHasSameType(GetValueType<T>(), type_);
return static_cast<TypedToolParam<T>*>(this);
}
template <typename T>
const TypedToolParam<T>* AsConstTyped() const {
AssertHasSameType(GetValueType<T>(), type_);
return static_cast<const TypedToolParam<T>*>(this);
}
virtual ~ToolParam() {}
explicit ToolParam(ParamType type) : has_value_set_(false), type_(type) {}
bool HasValueSet() const { return has_value_set_; }
virtual void Set(const ToolParam&) {}
virtual std::unique_ptr<ToolParam> Clone() const = 0;
protected:
bool has_value_set_;
private:
static void AssertHasSameType(ParamType a, ParamType b);
const ParamType type_;
};
template <typename T>
class TypedToolParam : public ToolParam {
public:
explicit TypedToolParam(const T& value)
: ToolParam(GetValueType<T>()), value_(value) {}
void Set(const T& value) {
value_ = value;
has_value_set_ = true;
}
T Get() const { return value_; }
void Set(const ToolParam& other) override {
Set(other.AsConstTyped<T>()->Get());
}
std::unique_ptr<ToolParam> Clone() const override {
return std::unique_ptr<ToolParam>(new TypedToolParam<T>(value_));
}
private:
T value_;
};
// A map-like container for holding values of different types.
class ToolParams {
public:
void AddParam(const std::string& name, std::unique_ptr<ToolParam> value) {
params_[name] = std::move(value);
}
bool HasParam(const std::string& name) const {
return params_.find(name) != params_.end();
}
bool Empty() const { return params_.empty(); }
const ToolParam* GetParam(const std::string& name) const {
const auto& entry = params_.find(name);
if (entry == params_.end()) return nullptr;
return entry->second.get();
}
template <typename T>
void Set(const std::string& name, const T& value) {
AssertParamExists(name);
params_.at(name)->AsTyped<T>()->Set(value);
}
template <typename T>
bool HasValueSet(const std::string& name) const {
AssertParamExists(name);
return params_.at(name)->AsConstTyped<T>()->HasValueSet();
}
template <typename T>
T Get(const std::string& name) const {
AssertParamExists(name);
return params_.at(name)->AsConstTyped<T>()->Get();
}
// Set the value of all same parameters from 'other'.
void Set(const ToolParams& other);
// Merge the value of all parameters from 'other'. 'overwrite' indicates
// whether the value of the same paratmeter is overwritten or not.
void Merge(const ToolParams& other, bool overwrite = false);
private:
void AssertParamExists(const std::string& name) const;
std::unordered_map<std::string, std::unique_ptr<ToolParam>> params_;
};
} // namespace tools
} // namespace tflite
#endif // TENSORFLOW_LITE_TOOLS_TOOL_PARAMS_H_