From 336bdc1cef83848c71f6dc0e3c552bd71725274c Mon Sep 17 00:00:00 2001 From: liuruilong Date: Tue, 5 Jun 2018 14:37:24 +0800 Subject: [PATCH] delete unused files --- src/framework/dim.h | 93 +++++++++++-------------- src/framework/tensor_util.cpp | 48 ------------- src/framework/tensor_util.h | 1 - src/platform/data_type.h | 125 ---------------------------------- src/platform/hostdevice.h | 25 ------- src/platform/macros.h | 25 ------- 6 files changed, 39 insertions(+), 278 deletions(-) delete mode 100644 src/platform/data_type.h delete mode 100644 src/platform/hostdevice.h delete mode 100644 src/platform/macros.h diff --git a/src/framework/dim.h b/src/framework/dim.h index 6740386c05..4d30883193 100644 --- a/src/framework/dim.h +++ b/src/framework/dim.h @@ -19,8 +19,6 @@ limitations under the License. */ #include #include -#include "platform/hostdevice.h" - namespace paddle_mobile { namespace framework { @@ -30,42 +28,35 @@ struct Dim { static constexpr int dimensions = i; template - HOSTDEVICE Dim(int64_t _head, Args... _tail) : head(_head), tail(_tail...) { + Dim(int64_t _head, Args... _tail) : head(_head), tail(_tail...) { static_assert(sizeof...(_tail) == i - 1, "Dim initialized with the wrong number of parameters"); } - HOSTDEVICE Dim(int64_t _head, const Dim &_tail) : head(_head), tail(_tail) {} - HOSTDEVICE Dim() : head(0), tail() {} /** Construct a Dim from a linear index and size. Uses Fortran * order * indexing. */ - HOSTDEVICE Dim(int64_t idx, const Dim &size) : head(idx % size.head), tail(idx / size.head, size.tail) {} /** Construct a Dim with each dimension set to the given index */ - HOSTDEVICE Dim(int64_t idx) : head(idx), tail(idx) {} - HOSTDEVICE bool operator==(const Dim &o) const { return (head == o.head) && (tail == o.tail); } - HOSTDEVICE bool operator!=(const Dim &o) const { return !(*this == o); } - HOSTDEVICE int64_t &operator[](int idx); - HOSTDEVICE + int64_t operator[](int idx) const; - HOST std::string to_string() const; + std::string to_string() const; int64_t head; Dim tail; @@ -76,13 +67,10 @@ template <> struct Dim<0> { static constexpr int dimensions = 0; - HOSTDEVICE Dim(int64_t _head) {} - HOSTDEVICE Dim() {} - HOSTDEVICE Dim(int idx, const Dim<0> &size) { #ifndef __CUDA_ARCH__ if (idx > 0) { @@ -93,15 +81,12 @@ struct Dim<0> { #endif } - HOSTDEVICE bool operator==(const Dim<0> &o) const { return true; } - HOSTDEVICE bool operator!=(const Dim<0> &o) const { return false; } - HOSTDEVICE int64_t &operator[](int idx); - HOSTDEVICE + int64_t operator[](int idx) const; }; @@ -112,12 +97,12 @@ template struct DimGetter { // Return a copy if Dim is const template - HOSTDEVICE static int64_t impl(const D &d) { + static int64_t impl(const D &d) { return DimGetter::impl(d.tail); } // Return a reference if Dim is mutable template - HOSTDEVICE static int64_t &impl(D &d) { + static int64_t &impl(D &d) { return DimGetter::impl(d.tail); } }; @@ -127,18 +112,18 @@ template <> struct DimGetter<0> { // Return a copy if Dim is const template - HOSTDEVICE static int64_t impl(const D &d) { + static int64_t impl(const D &d) { return d.head; } // Return a reference if Dim is mutable template - HOSTDEVICE static int64_t &impl(D &d) { + static int64_t &impl(D &d) { return d.head; } }; template -HOSTDEVICE int64_t &indexer(Dim &dim, int idx) { +int64_t &indexer(Dim &dim, int idx) { #ifndef __CUDA_ARCH__ if (idx < 0) { throw std::invalid_argument("Tried to access a negative dimension"); @@ -153,7 +138,7 @@ HOSTDEVICE int64_t &indexer(Dim &dim, int idx) { } template <> -HOSTDEVICE int64_t &indexer<0>(Dim<0> &dim, int idx) { +int64_t &indexer<0>(Dim<0> &dim, int idx) { #ifndef __CUDA_ARCH__ throw std::invalid_argument("Invalid index"); #else @@ -170,7 +155,7 @@ HOSTDEVICE int64_t &indexer<0>(Dim<0> &dim, int idx) { } template -HOSTDEVICE int64_t indexer(const Dim &dim, int idx) { +int64_t indexer(const Dim &dim, int idx) { #ifndef __CUDA_ARCH__ if (idx < 0) { throw std::invalid_argument("Tried to access a negative dimension"); @@ -185,7 +170,7 @@ HOSTDEVICE int64_t indexer(const Dim &dim, int idx) { } template <> -HOSTDEVICE int64_t indexer<0>(const Dim<0> &dim, int idx) { +int64_t indexer<0>(const Dim<0> &dim, int idx) { #ifndef __CUDA_ARCH__ throw std::invalid_argument("Invalid index"); #else @@ -204,83 +189,83 @@ HOSTDEVICE int64_t indexer<0>(const Dim<0> &dim, int idx) { } // namespace // Static access to constant Dim template -HOSTDEVICE int64_t get(const Dim &d) { +int64_t get(const Dim &d) { return DimGetter::impl(d); } // Static access to mutable Dim template -HOSTDEVICE int64_t &get(Dim &d) { +int64_t &get(Dim &d) { return DimGetter::impl(d); } // Dynamic access to constant Dim template -HOSTDEVICE int64_t Dim::operator[](int i) const { +int64_t Dim::operator[](int i) const { // std::cout << "l: " << l << std::endl; return indexer(*this, i); } // Dynamic access to mutable Dim template -HOSTDEVICE int64_t &Dim::operator[](int i) { +int64_t &Dim::operator[](int i) { return indexer(*this, i); } // Dynamic access to constant Dim -inline HOSTDEVICE int64_t Dim<0>::operator[](int i) const { +inline int64_t Dim<0>::operator[](int i) const { return indexer(*this, i); } // Dynamic access to mutable Dim -inline HOSTDEVICE int64_t &Dim<0>::operator[](int i) { +inline int64_t &Dim<0>::operator[](int i) { return indexer(*this, i); } // Dynamic access to constant Dim // without std::enable_if will try to instantiate this on get<0>(d) template -HOSTDEVICE typename std::enable_if<(l > 0), int64_t>::type get(const Dim &d, +typename std::enable_if<(l > 0), int64_t>::type get(const Dim &d, int i) { return d[i]; } // Dynamic access to mutable Dim template -HOSTDEVICE typename std::enable_if<(l > 0), int64_t &>::type get(Dim &d, +typename std::enable_if<(l > 0), int64_t &>::type get(Dim &d, int i) { return d[i]; } // Dot product of two dims template -HOSTDEVICE int64_t linearize(const Dim &a, const Dim &b) { +int64_t linearize(const Dim &a, const Dim &b) { return a.head * b.head + linearize(a.tail, b.tail); } // Base case dot product of two Dims // Notice it is inline because it is no longer a template template <> -HOSTDEVICE inline int64_t linearize(const Dim<0> &a, const Dim<0> &b) { +inline int64_t linearize(const Dim<0> &a, const Dim<0> &b) { return 0; } // Product of a Dim template -HOSTDEVICE int64_t product(const Dim &a, int prod = 1) { +int64_t product(const Dim &a, int prod = 1) { return prod * a.head * product(a.tail); } // Base case product of a Dim // Notice it is inline because it is no longer a template template <> -HOSTDEVICE inline int64_t product(const Dim<0> &a, int prod) { +inline int64_t product(const Dim<0> &a, int prod) { return prod; } // Is 0 <= idx_i < size_i for all i? template -HOSTDEVICE bool contained(const Dim &idx, const Dim &size) { +bool contained(const Dim &idx, const Dim &size) { return ((0 <= idx.head) && (idx.head < size.head) && contained(idx.tail, size.tail)); } @@ -288,7 +273,7 @@ HOSTDEVICE bool contained(const Dim &idx, const Dim &size) { // Base case of is 0 <= idx_i < size_i ? // Notice it is inline because it is no longer a template template <> -HOSTDEVICE inline bool contained(const Dim<0> &idx, const Dim<0> &size) { +inline bool contained(const Dim<0> &idx, const Dim<0> &size) { return true; } @@ -296,7 +281,7 @@ HOSTDEVICE inline bool contained(const Dim<0> &idx, const Dim<0> &size) { * \brief Compute exclusive prefix-multiply of a Dim. */ template -HOSTDEVICE Dim ex_prefix_mul(const Dim &src, int mul = 1) { +Dim ex_prefix_mul(const Dim &src, int mul = 1) { return Dim(mul, ex_prefix_mul(src.tail, mul * src.head)); } @@ -304,7 +289,7 @@ HOSTDEVICE Dim ex_prefix_mul(const Dim &src, int mul = 1) { // Base case of ex_prefix_mul // Notice it is inline because it is no longer a template template <> -HOSTDEVICE inline Dim<0> ex_prefix_mul(const Dim<0> &src, int mul) { +inline Dim<0> ex_prefix_mul(const Dim<0> &src, int mul) { return Dim<0>(); } ///\endcond @@ -313,18 +298,18 @@ HOSTDEVICE inline Dim<0> ex_prefix_mul(const Dim<0> &src, int mul) { * Add two dimensions together */ template -HOSTDEVICE Dim dim_plus(const Dim &a, const Dim &b) { +Dim dim_plus(const Dim &a, const Dim &b) { return Dim(a.head + b.head, dim_plus(a.tail, b.tail)); } // Base case template <> -HOSTDEVICE inline Dim<0> dim_plus(const Dim<0> &a, const Dim<0> &b) { +inline Dim<0> dim_plus(const Dim<0> &a, const Dim<0> &b) { return Dim<0>(); } template -HOSTDEVICE Dim operator+(const Dim &lhs, const Dim &rhs) { +Dim operator+(const Dim &lhs, const Dim &rhs) { return dim_plus(lhs, rhs); } @@ -332,18 +317,18 @@ HOSTDEVICE Dim operator+(const Dim &lhs, const Dim &rhs) { * Multiply two dimensions together */ template -HOSTDEVICE Dim dim_mult(const Dim &a, const Dim &b) { +Dim dim_mult(const Dim &a, const Dim &b) { return Dim(a.head * b.head, dim_mult(a.tail, b.tail)); } // Base case template <> -HOSTDEVICE inline Dim<0> dim_mult(const Dim<0> &a, const Dim<0> &b) { +inline Dim<0> dim_mult(const Dim<0> &a, const Dim<0> &b) { return Dim<0>(); } template -HOSTDEVICE Dim operator*(const Dim &lhs, const Dim &rhs) { +Dim operator*(const Dim &lhs, const Dim &rhs) { return dim_mult(lhs, rhs); } @@ -358,7 +343,7 @@ HOSTDEVICE Dim operator*(const Dim &lhs, const Dim &rhs) { */ template -HOSTDEVICE Dim normalize_strides(const Dim &size, const Dim &stride) { +Dim normalize_strides(const Dim &size, const Dim &stride) { int norm_stride = size.head == 1 ? 0 : stride.head; return Dim(norm_stride, normalize_strides(size.tail, stride.tail)); } @@ -366,7 +351,7 @@ HOSTDEVICE Dim normalize_strides(const Dim &size, const Dim &stride) { ///\cond HIDDEN template <> -HOSTDEVICE inline Dim<0> normalize_strides(const Dim<0> &size, +inline Dim<0> normalize_strides(const Dim<0> &size, const Dim<0> &stride) { return Dim<0>(); } @@ -382,7 +367,7 @@ HOSTDEVICE inline Dim<0> normalize_strides(const Dim<0> &size, */ template -HOSTDEVICE Dim make_dim(Args... idxes) { +Dim make_dim(Args... idxes) { return Dim(idxes...); } @@ -409,7 +394,7 @@ inline std::ostream &operator<<(std::ostream &os, const Dim<0> &d) { } template -HOST std::string Dim::to_string() const { +std::string Dim::to_string() const { std::stringstream stream; stream << *this; @@ -418,7 +403,7 @@ HOST std::string Dim::to_string() const { } template -HOSTDEVICE Dim linear_to_dimension(int linear_index, Dim extents) { +Dim linear_to_dimension(int linear_index, Dim extents) { Dim result; for (int i = 0; i < D - 1; ++i) { diff --git a/src/framework/tensor_util.cpp b/src/framework/tensor_util.cpp index 23b775b095..1b0cc002bf 100644 --- a/src/framework/tensor_util.cpp +++ b/src/framework/tensor_util.cpp @@ -39,9 +39,6 @@ void TensorCopy(const Tensor &src, Tensor *dst) { } void TensorCopySync(const Tensor &src, Tensor *dst) { - // VLOG(3) << "TensorCopySync " << src.dims() << " from " << - // src.place() - // << " to " << dst_place; src.check_memory_size(); dst->Resize(src.dims()); dst->set_layout(src.layout()); @@ -69,41 +66,6 @@ struct AnyDTypeVisitor { } }; -template -inline void AnyImpl(Predicate predicate, const Tensor &tensor, - framework::Tensor *out) { - VisitDataType(ToDataType(tensor.type()), - AnyDTypeVisitor(predicate, tensor, out)); -} - -template -struct AnyVisitor { - const framework::Tensor &tensor_; - Predicate predicate_; - - AnyVisitor(const framework::Tensor &tensor, Predicate predicate) - : tensor_(tensor), predicate_(std::move(predicate)) {} - - bool operator()(void) const { - framework::Tensor out; - out.Resize({1}); - out.mutable_data(); - AnyImpl(predicate_, tensor_, &out); - return this->GetResult(out); - } - - bool GetResult(const framework::Tensor &out) const { - return *out.data(); - } -}; - -template -inline bool Any(const framework::Tensor &tensor, Predicate predicate) { - AnyVisitor visitor(tensor, predicate); - // return platform::VisitPlace(visitor); - return visitor(); -} - struct ContainsNANPredicate { template auto operator()(const T &eigen_vec) const @@ -113,11 +75,6 @@ struct ContainsNANPredicate { } }; -bool TensorContainsNAN(const framework::Tensor &tensor) { - ContainsNANPredicate predicate; - return Any(tensor, predicate); -} - struct ContainsInfPredicate { template auto operator()(const T &eigen_vec) const @@ -127,11 +84,6 @@ struct ContainsInfPredicate { } }; -bool TensorContainsInf(const framework::Tensor &tensor) { - ContainsInfPredicate predicate; - return Any(tensor, predicate); -} - struct DeserializedDataFunctor { DeserializedDataFunctor(void **buf, Tensor *tensor) : buf_(buf), tensor_(tensor) {} diff --git a/src/framework/tensor_util.h b/src/framework/tensor_util.h index 9af873d34a..898482fee8 100644 --- a/src/framework/tensor_util.h +++ b/src/framework/tensor_util.h @@ -15,7 +15,6 @@ limitations under the License. */ #pragma once #include #include "memory/t_malloc.h" -#include "platform/data_type.h" #include "tensor.h" namespace paddle_mobile { diff --git a/src/platform/data_type.h b/src/platform/data_type.h deleted file mode 100644 index 44e0158a7c..0000000000 --- a/src/platform/data_type.h +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright (c) 2018 PaddlePaddle 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. */ - -#pragma once - -#include -#include - -#include "framework/program/tensor_desc.h" - -namespace paddle_mobile { -namespace framework { - -inline VarType_Type ToDataType(std::type_index type) { - /*if (typeid(platform::float16).hash_code() == type.hash_code()) { - return proto::VarType::FP16; - } else */ - if (typeid(const float).hash_code() == type.hash_code()) { - // CPPLint complains Using C-style cast. Use - // static_cast() instead - // One fix to this is to replace float with const float because - // typeid(T) == typeid(const T) - // http://en.cppreference.com/w/cpp/language/typeid - return VARTYPE_TYPE_FP32; - } else if (typeid(const double).hash_code() == type.hash_code()) { - return VARTYPE_TYPE_FP64; - } else if (typeid(const int).hash_code() == type.hash_code()) { - return VARTYPE_TYPE_INT32; - } else if (typeid(const int64_t).hash_code() == type.hash_code()) { - return VARTYPE_TYPE_INT64; - } else if (typeid(const bool).hash_code() == type.hash_code()) { - return VARTYPE_TYPE_BOOL; - } else { - // PADDLE_THROW("Not supported"); - // std::cout << "Not supported"; - } -} - -inline std::type_index ToTypeIndex(VarType_Type type) { - switch (type) { - // case proto::VarType::FP16: - // return typeid(platform::float16); - case VARTYPE_TYPE_FP32: - return typeid(float); - case VARTYPE_TYPE_FP64: - return typeid(double); - case VARTYPE_TYPE_INT32: - return typeid(int); - case VARTYPE_TYPE_INT64: - return typeid(int64_t); - case VARTYPE_TYPE_BOOL: - return typeid(bool); - default: - // PADDLE_THROW("Not support type %d", type); - printf("Not support type %d", type); - } -} - -template -inline void VisitDataType(VarType_Type type, Visitor visitor) { - switch (type) { - // case proto::VarType::FP16: - // visitor.template operator()(); - // break; - case VARTYPE_TYPE_FP32: - visitor.template operator()(); - break; - case VARTYPE_TYPE_FP64: - visitor.template operator()(); - break; - case VARTYPE_TYPE_INT32: - visitor.template operator()(); - break; - case VARTYPE_TYPE_INT64: - visitor.template operator()(); - break; - case VARTYPE_TYPE_BOOL: - visitor.template operator()(); - break; - default: - // PADDLE_THROW("Not supported"); - printf("Not supported"); - } -} - -inline std::string DataTypeToString(const VarType_Type type) { - switch (type) { - case VARTYPE_TYPE_FP16: - return "float16"; - case VARTYPE_TYPE_FP32: - return "float32"; - case VARTYPE_TYPE_FP64: - return "float64"; - case VARTYPE_TYPE_INT16: - return "int16"; - case VARTYPE_TYPE_INT32: - return "int32"; - case VARTYPE_TYPE_INT64: - return "int64"; - case VARTYPE_TYPE_BOOL: - return "bool"; - default: - // PADDLE_THROW("Not support type %d", type); - printf("Not support type %d", type); - } -} - -inline std::ostream &operator<<(std::ostream &out, const VarType_Type &type) { - out << DataTypeToString(type); - return out; -} - -} // namespace framework -} // namespace paddle_mobile diff --git a/src/platform/hostdevice.h b/src/platform/hostdevice.h deleted file mode 100644 index 6139fb94b9..0000000000 --- a/src/platform/hostdevice.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2018 PaddlePaddle 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. */ - -#pragma once - -#ifdef __CUDACC__ -#define HOSTDEVICE __host__ __device__ -#define DEVICE __device__ -#define HOST __host__ -#else -#define HOSTDEVICE -#define DEVICE -#define HOST -#endif diff --git a/src/platform/macros.h b/src/platform/macros.h deleted file mode 100644 index ce133562ca..0000000000 --- a/src/platform/macros.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright (c) 2018 PaddlePaddle 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. */ - -#pragma once - -// Disable the copy and assignment operator for a class. -#ifndef DISABLE_COPY_AND_ASSIGN -#define DISABLE_COPY_AND_ASSIGN(classname) \ - private: \ - classname(const classname &) = delete; \ - classname(classname &&) = delete; \ - classname &operator=(const classname &) = delete; \ - classname &operator=(classname &&) = delete -#endif -- GitLab