diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..f24e032 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "app/src/main/cpp/pytorch"] + path = app/src/main/cpp/pytorch + url = https://github.com/pytorch/pytorch.git diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index a7461cd..d50b8d9 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,87 +1,52 @@ cmake_minimum_required(VERSION 3.4.1) add_library( - native-lib - SHARED - src/main/cpp/native-lib.cpp - ) -find_library( - android-lib - android - ) - -include(AndroidNdkModules) -android_ndk_import_module_cpufeatures() - -add_library( - caffe2 - STATIC - IMPORTED - ) -set_target_properties( - caffe2 - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCaffe2_CPU.a - ) -add_library( - thread_pool - STATIC - IMPORTED - ) -set_target_properties( - thread_pool - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCAFFE2_PTHREADPOOL.a - ) -add_library( - glog + native-lib SHARED - IMPORTED - ) -set_target_properties( - glog - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libglog.so - ) - -add_library( - protobuf - SHARED - IMPORTED - ) -set_target_properties( - protobuf - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libprotobuf.a - ) - -add_library( - NNPACK - STATIC - IMPORTED - ) -set_target_properties( - NNPACK - PROPERTIES IMPORTED_LOCATION - ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCAFFE2_NNPACK.a - ) + src/main/cpp/native-lib.cpp +) +find_library( + android-lib + android +) include_directories( src/main/cpp ) +set(PYTORCH_PATH src/main/cpp/pytorch) +execute_process( + COMMAND bash scripts/build_host_protoc.sh + WORKING_DIRECTORY ${PYTORCH_PATH} + RESULT_VARIABLE build_host_protoc_result +) +if (NOT build_host_protoc_result EQUAL 0) + message(FATAL_ERROR "Cannot build host protoc. ${build_host_protoc_result}") +endif() +get_filename_component(CAFFE2_CUSTOM_PROTOC_EXECUTABLE ${PYTORCH_PATH}/build_host_protoc/bin/protoc ABSOLUTE) +set(BUILD_TEST OFF CACHE BOOL "" FORCE) +set(BUILD_BINARY OFF CACHE BOOL "" FORCE) +set(BUILD_PYTHON OFF CACHE BOOL "" FORCE) +set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE) +set(USE_CUDA OFF CACHE BOOL "" FORCE) +set(USE_GFLAGS OFF CACHE BOOL "" FORCE) +set(USE_OPENCV OFF CACHE BOOL "" FORCE) +set(USE_LMDB OFF CACHE BOOL "" FORCE) +set(USE_LEVELDB OFF CACHE BOOL "" FORCE) +set(USE_MPI OFF CACHE BOOL "" FORCE) +set(USE_OPENMP OFF CACHE BOOL "" FORCE) +set(USE_MOBILE_OPENGL OFF CACHE BOOL "" FORCE) +add_subdirectory( ${PYTORCH_PATH} ) +include_directories( $ ) + find_library( - log-lib - log - ) + log-lib + log +) target_link_libraries( - native-lib - -Wl,--whole-archive - caffe2 - -Wl,--no-whole-archive - NNPACK - thread_pool - glog - protobuf - cpufeatures - ${log-lib} - ${android-lib}) \ No newline at end of file + native-lib + -Wl,--whole-archive + caffe2 + -Wl,--no-whole-archive + ${log-lib} + ${android-lib} +) \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index e6aef77..57f250d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,13 +11,15 @@ android { testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { + arguments "-DANDROID_STL=c++_shared" cppFlags "-frtti -fexceptions -std=c++11" + targets "native-lib" } } ndk { // Specifies the ABI configurations of your native // libraries Gradle should build and package with your APK. - abiFilters 'armeabi-v7a' + abiFilters 'arm64-v8a' } } buildTypes { diff --git a/app/src/main/cpp/caffe2/contrib/aten/aten_op_template.h b/app/src/main/cpp/caffe2/contrib/aten/aten_op_template.h deleted file mode 100644 index 3030d70..0000000 --- a/app/src/main/cpp/caffe2/contrib/aten/aten_op_template.h +++ /dev/null @@ -1,186 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include - -// a map from descriptor strings (see [DESCRIPTORS]) -// to the key in the switch statement that implements them -static std::unordered_map op_to_key = { - ${mappings} -}; - -namespace caffe2 { - -using at::Half; // for AT_FORALL_SCALAR_TYPES - -std::function deleterFor(at::Tensor t) { - // return a closure that holds a handle to t until it is called - // to keep the aten memory alive - return [t](void * ptr) mutable { - t.reset(); - }; -} - -template -class ATenOp : public Operator { - public: - ATenOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - VLOG(2) << "ATen OpDef: " << ProtoDebugString(operator_def) << "\n"; - switch(findImplementation(operator_def)) { - ${implementations} - default: - CAFFE_THROW("Unexpected key value for aten operator"); - } - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - return run_op(); - } -private: - // actual operator implementation is initialized in ctor. - std::function run_op; - at::Backend backend() const; - - TypeMeta typeMetaFor(const at::Tensor & t) { - return typeMetaFor(t.type().scalarType()); - } - TypeMeta typeMetaFor(at::ScalarType st) { - #define DEFINE_CASE(ctype,aten_name,_) \ - case at::k##aten_name: \ - return TypeMeta::Make(); - switch(st) { - AT_FORALL_SCALAR_TYPES(DEFINE_CASE) - default: - CAFFE_THROW("Unknown ATen Type"); - } - #undef DEFINE_CASE - } - - at::Type & typeFor(const Tensor & ten) { - return at::getType(backend(), atScalarTypeFor(ten.meta())); - } - at::Tensor tensorWrapping(Tensor & ten) { - return typeFor(ten).tensorFromBlob(ten.raw_mutable_data(), ten.dims()); - } - at::ScalarType atScalarTypeFor(const TypeMeta & meta) { - #define DEFINE_IF(ctype,aten_name,_) \ - if(meta.Match()) { \ - return at::k##aten_name; \ - } - AT_FORALL_SCALAR_TYPES(DEFINE_IF) - #undef DEFINE_IF - CAFFE_THROW("Unknown type meta"); // TODO: improve error message... - } - void assignTo(Tensor * dst, const at::Tensor & src_) { - at::Tensor src = src_.contiguous(); - auto at_sizes = src.sizes(); - std::vector dims(at_sizes.begin(),at_sizes.end()); - dst->Resize(dims); - dst->ShareExternalPointer(src.data_ptr(), typeMetaFor(src), 0, deleterFor(src)); - } - - // the AT_FORALL_SCALAR_TYPES macro just gives a 'i' or 'd' argument - // for each type to specify if it is stored as a integer or a double. - // We need this workaround here to extract the value in the scalar losslessly - // because in some cases like 'sum' Torch promotes float to double - // and will complain if we downcast it with toFloat, causing it - // to lose precision - double extract_d(const at::Scalar & s) { - return s.toDouble(); - } - int64_t extract_i(const at::Scalar & s) { - return s.toLong(); - } - - void assignTo(Tensor * dst, at::Type & inferred_type, at::Scalar scalar) { - switch(inferred_type.scalarType()) { - #define DEFINE_CASE(ctype,aten_name,native) \ - case at::k##aten_name: { \ - auto value = extract_##native(scalar); \ - assignToValue(dst, at::convert(value)); \ - } break; - AT_FORALL_SCALAR_TYPES(DEFINE_CASE) - #undef DEFINE_CASE - default: - CAFFE_THROW("Unknown ATen Type"); - } - } - template - void assignToValue(Tensor * dst, T v) { - dst->Resize(std::vector()); - math::Set(1, v, dst->template mutable_data(), &context_); - } - int findImplementation(const OperatorDef& operator_def) { - CAFFE_ENFORCE(HasArgument("operator")); - std::string op = OperatorBase::GetSingleArgument("operator", ""); - // construct descriptor string ([DESCRIPTORS]) given the attributes - // and inputs of this operator_def, and look up the implementation key - // for this variant - std::stringstream descriptor; - descriptor << op << "-" << InputSize(); - std::vector attrs; - for(size_t i = 0; i < operator_def.arg_size(); i++) { - auto & attr = operator_def.arg(i); - if(attr.name() == "operator" || attr.name() == "type" ) - continue; - attrs.push_back(attr.name()); - } - std::sort(attrs.begin(), attrs.end()); - for(auto & a : attrs) - descriptor << "-" << a; - std::string descriptor_s = descriptor.str(); - if(op_to_key.count(descriptor_s) == 0) { - std::stringstream ss; - ss << "Attempting to run unknown ATen operator configuration: " - << descriptor_s; - CAFFE_THROW(ss.str()); - } - return op_to_key.at(descriptor_s); - } - at::Scalar readScalarAttribute(const std::string & name) { - if(OperatorBase::HasSingleArgumentOfType(name)) { - return OperatorBase::GetSingleArgument(name, 0); - } else { - CAFFE_ENFORCE(OperatorBase::HasSingleArgumentOfType(name)); - return OperatorBase::GetSingleArgument(name, 0); - } - } - template - T readAttribute(const std::string & name) { - CAFFE_ENFORCE(OperatorBase::HasSingleArgumentOfType(name)); - return OperatorBase::GetSingleArgument(name, 0); - } - std::vector readIntList(const std::string & name) { - CAFFE_ENFORCE(OperatorBase::HasArgument(name)); - return OperatorBase::GetRepeatedArgument(name, {}); - } - at::ScalarType stringToScalarType(const std::string & name) { - #define DEFINE_IF(type,aten) \ - if(#type == name) \ - return at::k##aten; - DEFINE_IF(float16, Half) - DEFINE_IF(float, Float) - DEFINE_IF(double, Double) - DEFINE_IF(uint8, Byte) - DEFINE_IF(int8, Char) - DEFINE_IF(int16, Short) - DEFINE_IF(int32, Int) - DEFINE_IF(int64, Long) - CAFFE_THROW("unsupported type annotation: ", name); - } - at::Type & stringToType(const std::string & name) { - return at::getType(backend(), stringToScalarType(name)); - } - at::Type * readTypeAttribute(const std::string & name) { - CAFFE_ENFORCE(OperatorBase::HasSingleArgumentOfType(name)); - return &stringToType(OperatorBase::GetSingleArgument(name, "")); - } -}; - -} diff --git a/app/src/main/cpp/caffe2/contrib/gloo/allreduce_ops.h b/app/src/main/cpp/caffe2/contrib/gloo/allreduce_ops.h deleted file mode 100644 index 74d75bc..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/allreduce_ops.h +++ /dev/null @@ -1,169 +0,0 @@ -#pragma once - -#include - -#include "caffe2/contrib/gloo/common.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -#include -#include -#include - -namespace caffe2 { -namespace gloo { - -template -class AllreduceOp final : public Operator { - enum Mode { RING_FULL, RING_CHUNKED, HALVING_DOUBLING }; - - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - AllreduceOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - status_blob_( - OperatorBase::GetSingleArgument("status_blob", "")), - gpu_direct_( - OperatorBase::GetSingleArgument("gpu_direct", false)) { - if (status_blob_ != "") { - ws_->CreateBlob(status_blob_); - } - } - - virtual ~AllreduceOp() {} - - bool RunOnDevice() override { - std::call_once(once_, [&] { initialize(); }); - - // If any parameter has changed in between runs, the initialized - // algorithm is invalid and cannot be used. - update(current_); - CAFFE_ENFORCE(current_ == init_, "Inputs/outputs have changed"); - - try { - algorithm_->run(); - } catch (::gloo::IoException& ioe) { - LOG(ERROR) << "Caught gloo IO exception: " << ioe.what(); - if (status_blob_ != "") { - signalFailure(ws_->GetBlob(status_blob_), ioe); - return false; - } else { - throw ioe; - } - } - return true; - } - - protected: - void initialize() { - Mode mode = HALVING_DOUBLING; - auto bytes = Input(1).nbytes(); - - // Store which inputs/outputs this instance initialized with - update(init_); - - // Verify inputs == ouputs - CAFFE_ENFORCE_EQ(init_.inputs.size(), init_.outputs.size()); - for (auto i = 0; i < init_.inputs.size(); i++) { - CAFFE_ENFORCE_EQ(init_.inputs[i], init_.outputs[i]); - } - - // Verify tensors all have same size - size_t size = Input(1).size(); - for (auto i = 2; i < InputSize(); i++) { - CAFFE_ENFORCE_EQ(Input(i).size(), size); - } - - // Verify tensors all have same type - TypeMeta meta = Input(1).meta(); - for (auto i = 2; i < InputSize(); i++) { - CAFFE_ENFORCE(Input(i).meta() == meta); - } - - switch (mode) { - case RING_FULL: - initializeRingFull(); - return; - case RING_CHUNKED: - initializeRingChunked(); - return; - case HALVING_DOUBLING: - initializeHalvingDoubling(); - return; - } - - CAFFE_ENFORCE(false, "Unreachable code"); - } - - void initializeHalvingDoubling(); - void initializeRingFull(); - void initializeRingChunked(); - - std::once_flag once_; - std::unique_ptr<::gloo::Algorithm> algorithm_; - - // Captures the parameters passed to Gloo when first initialized. - // An instance is updated every time this op runs and is compared - // to the reference instance for equality. If any parameter has - // changed from run to run, the initialized algorithm is invalid. - struct GlooParameters { - std::shared_ptr<::gloo::Context> context; - std::vector inputs; - std::vector outputs; - size_t size; - TypeMeta meta; - - template - std::vector getInputs() { - std::vector result; - result.reserve(inputs.size()); - for (auto& input : inputs) { - result.push_back(reinterpret_cast(input)); - } - return result; - } - - template - std::vector getOutputs() { - std::vector result; - result.reserve(outputs.size()); - for (auto& output : outputs) { - result.push_back(reinterpret_cast(output)); - } - return result; - } - - template - bool IsType() const { - return meta.Match(); - } - - bool operator==(GlooParameters const& other) const { - return context == other.context && inputs == other.inputs && - outputs == other.outputs && size == other.size; - } - }; - - void update(GlooParameters& params) { - params.context = OperatorBase::Input>(0); - params.inputs.resize(InputSize() - 1); - params.outputs.resize(OutputSize()); - for (auto i = 0; i < params.inputs.size(); i++) { - params.inputs[i] = Input(i + 1).template raw_data(); - params.outputs[i] = Output(i)->template raw_mutable_data(); - } - params.size = Output(0)->size(); - params.meta = Output(0)->meta(); - } - - GlooParameters init_; - GlooParameters current_; - Workspace* ws_; - std::string status_blob_; - const bool gpu_direct_; -}; - -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/gloo/barrier_ops.h b/app/src/main/cpp/caffe2/contrib/gloo/barrier_ops.h deleted file mode 100644 index 1543a60..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/barrier_ops.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "caffe2/contrib/gloo/common.h" -#include "caffe2/core/operator.h" - -#include -#include -#include -#include - -namespace caffe2 { -namespace gloo { - -template -class BarrierOp final : public Operator { - public: - BarrierOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - status_blob_( - OperatorBase::GetSingleArgument("status_blob", "")) { - if (status_blob_ != "") { - ws_->CreateBlob(status_blob_); - } - } - - virtual ~BarrierOp() {} - - bool RunOnDevice() override { - auto context = OperatorBase::Input>(0); - std::call_once(once_, [&] { - initContext_ = context; - // Use an all-to-one barrier synchronizing against rank 0 - algorithm_.reset(new ::gloo::BarrierAllToOne(initContext_, 0)); - }); - - // If any parameter has changed in between runs, the initialized - // algorithm is invalid and cannot be used. - CAFFE_ENFORCE(context == initContext_, "Context has changed"); - - try { - algorithm_->run(); - } catch (::gloo::IoException& ioe) { - LOG(ERROR) << "Caught gloo IO exception: " << ioe.what(); - if (status_blob_ != "") { - signalFailure(ws_->GetBlob(status_blob_), ioe); - return false; - } else { - throw ioe; - } - } - return true; - } - - protected: - std::once_flag once_; - std::shared_ptr<::gloo::Context> initContext_; - std::unique_ptr<::gloo::Algorithm> algorithm_; - Workspace* ws_; - std::string status_blob_; -}; -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/gloo/broadcast_ops.h b/app/src/main/cpp/caffe2/contrib/gloo/broadcast_ops.h deleted file mode 100644 index f0e6fbb..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/broadcast_ops.h +++ /dev/null @@ -1,149 +0,0 @@ -#pragma once - -#include - -#include "caffe2/contrib/gloo/common.h" -#include "caffe2/core/operator.h" - -#include -#include -#include - -namespace caffe2 { -namespace gloo { - -template -class BroadcastOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - BroadcastOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - root_(OperatorBase::template GetSingleArgument("root", 0)), - ws_(ws), - status_blob_( - OperatorBase::GetSingleArgument("status_blob", "")) { - if (status_blob_ != "") { - ws_->CreateBlob(status_blob_); - } - } - - virtual ~BroadcastOp() {} - - bool RunOnDevice() override { - std::call_once(once_, [&] { initialize(); }); - - // If any parameter has changed in between runs, the initialized - // algorithm is invalid and cannot be used. - update(current_); - CAFFE_ENFORCE(current_ == init_, "Inputs/outputs have changed"); - - try { - algorithm_->run(); - } catch (::gloo::IoException& ioe) { - LOG(ERROR) << "Caught gloo IO exception: " << ioe.what(); - if (status_blob_ != "") { - signalFailure(ws_->GetBlob(status_blob_), ioe); - return false; - } else { - throw ioe; - } - } - return true; - } - - protected: - void initialize() { - // Store which inputs/outputs this instance initialized with - update(init_); - - // Verify inputs == ouputs - CAFFE_ENFORCE_EQ(init_.inputs.size(), init_.outputs.size()); - for (auto i = 0; i < init_.inputs.size(); i++) { - CAFFE_ENFORCE_EQ(init_.inputs[i], init_.outputs[i]); - } - - // Verify tensors all have same size - size_t size = Input(1).size(); - for (auto i = 2; i < InputSize(); i++) { - CAFFE_ENFORCE_EQ(Input(i).size(), size); - } - - // Verify tensors all have same size - TypeMeta meta = Input(1).meta(); - for (auto i = 2; i < InputSize(); i++) { - CAFFE_ENFORCE(Input(i).meta() == meta); - } - - // Finally initialize the algorithm - initializeAlgorithm(); - } - - void initializeAlgorithm(); - - const int root_; - std::once_flag once_; - std::unique_ptr<::gloo::Algorithm> algorithm_; - - // Captures the parameters passed to Gloo when first initialized. - // An instance is updated every time this op runs and is compared - // to the reference instance for equality. If any parameter has - // changed from run to run, the initialized algorithm is invalid. - struct GlooParameters { - std::shared_ptr<::gloo::Context> context; - std::vector inputs; - std::vector outputs; - size_t size; - TypeMeta meta; - - template - std::vector getInputs() { - std::vector result; - result.reserve(inputs.size()); - for (auto& input : inputs) { - result.push_back(reinterpret_cast(input)); - } - return result; - } - - template - std::vector getOutputs() { - std::vector result; - result.reserve(outputs.size()); - for (auto& output : outputs) { - result.push_back(reinterpret_cast(output)); - } - return result; - } - - template - bool IsType() const { - return meta.Match(); - } - - bool operator==(GlooParameters const& other) const { - return context == other.context && inputs == other.inputs && - outputs == other.outputs && size == other.size && meta == other.meta; - } - }; - - void update(GlooParameters& params) { - params.context = OperatorBase::Input>(0); - params.inputs.resize(InputSize() - 1); - params.outputs.resize(OutputSize()); - for (auto i = 0; i < params.inputs.size(); i++) { - params.inputs[i] = Input(i + 1).template raw_data(); - params.outputs[i] = Output(i)->template raw_mutable_data(); - } - params.size = Output(0)->size(); - params.meta = Output(0)->meta(); - } - - GlooParameters init_; - GlooParameters current_; - Workspace* ws_; - std::string status_blob_; -}; - -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/gloo/common.h b/app/src/main/cpp/caffe2/contrib/gloo/common.h deleted file mode 100644 index e99b494..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/common.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "caffe2/core/blob.h" - -#include -#include - -namespace caffe2 { -namespace gloo { - -void signalFailure(Blob* status_blob, std::exception& exception); - -struct createDeviceAttr { - // "tcp" or "ibverbs" - std::string transport; - - // E.g. "eth0" (tcp), or "mlx5_0" (ibverbs). - // This may be empty to make Gloo figure it out. - std::string interface; -}; - -std::shared_ptr<::gloo::transport::Device> createDevice( - const createDeviceAttr attr); - -#if defined(GLOO_USE_MPI) && GLOO_USE_MPI -void mpiInitialize(); -void mpiFinalize(); -#endif - -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/gloo/common_world_ops.h b/app/src/main/cpp/caffe2/contrib/gloo/common_world_ops.h deleted file mode 100644 index 16f0dc4..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/common_world_ops.h +++ /dev/null @@ -1,260 +0,0 @@ -#pragma once - -#include "caffe2/contrib/gloo/common.h" -#include "caffe2/contrib/gloo/store_handler.h" -#include "caffe2/core/operator.h" -#include "caffe2/distributed/store_handler.h" - -#include -#include -#include -#include - -#if defined(GLOO_USE_MPI) && GLOO_USE_MPI -#include -#endif - -namespace caffe2 { -namespace gloo { - -template -class CreateCommonWorld final : public Operator { - public: - using CommonWorld = std::shared_ptr<::gloo::Context>; - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - CreateCommonWorld(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - size_(OperatorBase::template GetSingleArgument("size", 0)), - rank_(OperatorBase::template GetSingleArgument("rank", 0)), - sync_(OperatorBase::template GetSingleArgument("sync", false)), - transport_(OperatorBase::template GetSingleArgument( - "transport", "tcp")), - interface_(OperatorBase::template GetSingleArgument( - "interface", "")), - mpi_rendezvous_(OperatorBase::template GetSingleArgument( - "mpi_rendezvous", false)), - status_blob_( - OperatorBase::GetSingleArgument("status_blob", "")), - timeout_ms_(OperatorBase::GetSingleArgument("timeout_ms", -1)), - ws_(ws) { - CAFFE_ENFORCE( - operator_def.has_name(), "CreateCommonWorld operator requires name"); - CAFFE_ENFORCE(rank_ >= 0 && rank_ < size_); - name_ = operator_def.name(); - if (status_blob_ != "") { - ws_->CreateBlob(status_blob_); - } - initialize(); - -#if defined(GLOO_USE_MPI) && GLOO_USE_MPI - if (mpi_rendezvous_) { - mpiInitialize(); - } -#endif - } - - virtual ~CreateCommonWorld() { -#if defined(GLOO_USE_MPI) && GLOO_USE_MPI - if (mpi_rendezvous_) { - mpiFinalize(); - } -#endif - } - - CommonWorld rendezvousWithMPI() { -#if defined(GLOO_USE_MPI) && GLOO_USE_MPI - auto context = std::make_shared<::gloo::mpi::Context>(MPI_COMM_WORLD); - if (timeout_ms_ != -1) { - context->setTimeout(std::chrono::milliseconds(timeout_ms_)); - } - context->connectFullMesh(device_); - return context; -#else - CAFFE_THROW( - "Gloo was not compiled with MPI support. ", - "Please recompile with -DUSE_MPI=1."); -#endif - } - - CommonWorld rendezvousWithStore( - const std::unique_ptr& handler) { - // Use PrefixStore to isolate different CreateCommonWorld instances - StoreHandlerWrapper wrapper(*handler); - ::gloo::rendezvous::PrefixStore store(name_, wrapper); - auto context = std::make_shared<::gloo::rendezvous::Context>(rank_, size_); - if (timeout_ms_ != -1) { - context->setTimeout(std::chrono::milliseconds(timeout_ms_)); - } - context->connectFullMesh(store, device_); - return context; - } - - bool RunOnDevice() override { - try { - CommonWorld context; - if (mpi_rendezvous_) { - context = rendezvousWithMPI(); - } else { - CAFFE_ENFORCE_EQ(InputSize(), 1, "Expected store handler input"); - const auto& handler = - OperatorBase::Input>(STORE_HANDLER); - context = rendezvousWithStore(handler); - } - - // Switch pairs to synchronous mode if configured to do so - if (sync_) { - for (int i = 0; i < context->size; i++) { - auto& pair = context->getPair(i); - if (pair) { - pair->setSync(true, false); - } - } - } - - *OperatorBase::Output(COMM) = std::move(context); - } catch (::gloo::IoException& ioe) { - LOG(ERROR) << "Caught gloo IO exception: " << ioe.what(); - return handleException(ioe); - } catch (::caffe2::StoreHandlerTimeoutException& te) { - LOG(ERROR) << "Caught store handler timeout exception: " << te.what(); - return handleException(te); - } - return true; - } - - private: - bool handleException(std::exception& ex) { - if (status_blob_ != "") { - signalFailure(ws_->GetBlob(status_blob_), ex); - return false; - } else { - throw ex; - } - } - - void initialize() { - // Share single device between all common worlds. - static std::once_flag once; - static std::shared_ptr<::gloo::transport::Device> device; - std::call_once(once, [&]() { - createDeviceAttr attr; - attr.transport = transport_; - attr.interface = interface_; - device = createDevice(attr); - }); - device_ = device; - - // Context specific initialization. - initializeForContext(); - } - - void initializeForContext(); - - const int size_; - const int rank_; - const bool sync_; - const std::string transport_; - const std::string interface_; - const bool mpi_rendezvous_; - const std::string status_blob_; - const int timeout_ms_; - Workspace* ws_; - - std::string name_; - std::shared_ptr<::gloo::transport::Device> device_; - - INPUT_TAGS(STORE_HANDLER); - OUTPUT_TAGS(COMM); -}; - -template -class CloneCommonWorld final : public Operator { - public: - using CommonWorld = std::shared_ptr<::gloo::Context>; - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - CloneCommonWorld(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - sync_(OperatorBase::template GetSingleArgument("sync", false)), - ws_(ws), - status_blob_( - OperatorBase::GetSingleArgument("status_blob", "")) { - if (status_blob_ != "") { - ws_->CreateBlob(status_blob_); - } - } - - virtual ~CloneCommonWorld() {} - - bool RunOnDevice() override { - try { - auto existing = OperatorBase::Input(EXISTING_COMM); - ::gloo::rendezvous::ContextFactory factory(existing); - auto clone = factory.makeContext(existing->getDevice()); - - // Switch pairs to synchronous mode if configured to do so - if (sync_) { - for (int i = 0; i < clone->size; i++) { - auto& pair = clone->getPair(i); - if (pair) { - pair->setSync(true, false); - } - } - } - - *OperatorBase::Output(CLONED_COMM) = std::move(clone); - } catch (::gloo::IoException& ioe) { - LOG(ERROR) << "Caught gloo IO exception: " << ioe.what(); - return handleException(ioe); - } - return true; - } - - private: - bool handleException(std::exception& ex) { - if (status_blob_ != "") { - signalFailure(ws_->GetBlob(status_blob_), ex); - return false; - } else { - throw ex; - } - } - - const bool sync_; - Workspace* ws_; - std::string status_blob_; - - INPUT_TAGS(EXISTING_COMM); - OUTPUT_TAGS(CLONED_COMM); -}; - -class DestroyCommonWorld final : public Operator { - public: - DestroyCommonWorld(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - cw_name_ = operator_def.input(0); - } - - bool RunOnDevice() override { - if (OperatorBase::InputBlob(0).GetRaw() == nullptr) { - return true; - } - const auto& context = - OperatorBase::Input>(0); - - if (context) { - LOG(INFO) << "Closing connections: " << cw_name_; - context->closeConnections(); - } - return true; - } - - private: - std::string cw_name_; -}; - -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/gloo/context.h b/app/src/main/cpp/caffe2/contrib/gloo/context.h deleted file mode 100644 index 7b427bd..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/context.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include diff --git a/app/src/main/cpp/caffe2/contrib/gloo/store_handler.h b/app/src/main/cpp/caffe2/contrib/gloo/store_handler.h deleted file mode 100644 index 1770972..0000000 --- a/app/src/main/cpp/caffe2/contrib/gloo/store_handler.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include "caffe2/distributed/store_handler.h" - -#include - -namespace caffe2 { -namespace gloo { - -class StoreHandlerWrapper : public ::gloo::rendezvous::Store { - public: - explicit StoreHandlerWrapper(StoreHandler& handler) : handler_(handler) {} - - virtual ~StoreHandlerWrapper() {} - - virtual void set(const std::string& key, const std::vector& data) - override; - - virtual std::vector get(const std::string& key) override; - - virtual void wait(const std::vector& keys) override { - wait(keys, ::gloo::rendezvous::Store::kDefaultTimeout); - } - - virtual void wait( - const std::vector& keys, - const std::chrono::milliseconds& timeout) override; - - protected: - StoreHandler& handler_; -}; - -} // namespace gloo -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/nccl/cuda_nccl_gpu.h b/app/src/main/cpp/caffe2/contrib/nccl/cuda_nccl_gpu.h deleted file mode 100644 index 0b0a466..0000000 --- a/app/src/main/cpp/caffe2/contrib/nccl/cuda_nccl_gpu.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include - -#include "caffe2/core/common_gpu.h" -#include "caffe2/core/context_gpu.h" -#include "caffe2/core/logging.h" - -#include -#include - -#define NCCL_VERSION_MIN(major, minor, patch) \ - ((NCCL_MAJOR > major) || \ - ((NCCL_MAJOR == major) && ((NCCL_MINOR > minor) || \ - ((NCCL_MINOR == minor) && (NCCL_PATCH >= patch)) ))) - -namespace caffe2 { - -namespace nccl { - -#define CAFFE_NCCL_CHECK(condition) \ - do { \ - ncclResult_t status = (condition); \ - CAFFE_ENFORCE_EQ( \ - status, \ - ncclSuccess, \ - " ", \ - "Error at: ", \ - __FILE__, \ - __LINE__, \ - ": ", \ - ncclGetErrorString(status)); \ - } while (0) - -struct NCCLElement { - const TensorCUDA* src{nullptr}; - TensorCUDA* dst{nullptr}; - int device{0}; -}; - -struct NCCLExecution { - int stream_gpu_id{0}; - cudaStream_t stream{nullptr}; - std::vector elements; - size_t root{0}; -}; - -template -class NCCL { - public: - static void AllReduce(const NCCLExecution& ex); - static void Broadcast(const NCCLExecution& ex); - static void Reduce(const NCCLExecution& ex); - static void AllGather(const NCCLExecution& ex); - static void ReduceScatter(const NCCLExecution& ex); -}; -} -} diff --git a/app/src/main/cpp/caffe2/contrib/nervana/nervana.h b/app/src/main/cpp/caffe2/contrib/nervana/nervana.h deleted file mode 100644 index 9714e39..0000000 --- a/app/src/main/cpp/caffe2/contrib/nervana/nervana.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CAFFE2_FB_NERVANA_INIT_H_ -#define CAFFE2_FB_NERVANA_INIT_H_ - -#include "caffe2/core/init.h" -#include "caffe2/core/flags.h" - -#include "nervana_c_api.h" - -/** - * A flag that specifies the nervana cubin path. - */ -CAFFE2_DECLARE_string(nervana_cubin_path); - -namespace caffe2 { - -/** - * An empty class to be used in identifying the engine in the math functions. - */ -class NervanaEngine {}; - -/** - * Returns whether the nervana kernels are loaded or not. - */ -bool NervanaKernelLoaded(); - -/** - * An initialization function that is run once by caffe2::GlobalInit() - * that initializes the nervana kernels. - */ -bool Caffe2InitializeNervanaKernels(); - -} // namespace caffe2 - -#endif // CAFFE2_FB_NERVANA_INIT_H_ diff --git a/app/src/main/cpp/caffe2/contrib/nervana/nervana_c_api.h b/app/src/main/cpp/caffe2/contrib/nervana/nervana_c_api.h deleted file mode 100644 index bbcf255..0000000 --- a/app/src/main/cpp/caffe2/contrib/nervana/nervana_c_api.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2015 Baidu USA, Inc. 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 - -#ifdef __cplusplus -extern "C" { -#else -#include -#endif - -/** Load all the sgemm and hgemm cubins from the given path - * \param [in] base_path path to the kernel cubins - * \return true on success and false if an error was encountered - */ -bool nervana_loadKernels(const char* const base_path); - -/** Unload all currently loaded cubins - * \return true on success and false if an error was encountered - */ -bool nervana_unloadKernels(); - -/** Return the number of bytes required for the random state - * used in stochastic rounding. - * \return bytes required for random state - */ - size_t nervana_randStateSizeBytes(); - -/** Perform BLAS sgemm on alpha * A * B + beta * C, with the - * additional options of stochastic rounding and applying a - * rectified linear unit (relu) to the result. This routine expects - * all matrices to be in row-major order. - * \param [in] A Pointer to the data for matrix A - * \param [in] B Pointer to the data for matrix B - * \param [in, out] C Pointer to the data for matrix C - * \param [in] m number of rows of C - * \param [in] n number of columns of C - * \param [in] k inner dimension of multiplication - * \param [in] lda leading dimension of two-dimensional array A - * \param [in] ldb leading dimension of two-dimensional array B - * \param [in] ldc leading dimension of two-dimensional array C - * \param [in] alpha scalar used for multiplication - * \param [in] beta scalar used for multiplication - * \param [in, out] rand_state pointer to memory used for random state - * use nervana_randStateSizeBytes to allocate the correct size - * if stochastic_round is false, this can be NULL - * \param [in] stochastic_round true if stochastic rounding should be used - * \param [in] apply_relu true if a relu should be applied to the result - * \param [in] stream The cudaStream on which the kernel should be launched - * \param [in] grid Choose a specific grid configuration: 0=32x128, 1=128x32, 2=128x64, 3=128x128 - */ - bool nervana_sgemm(float *A, float *B, float *C, - bool a_t, bool b_t, - int m, int n, int k, - int lda, int ldb, int ldc, - float alpha, float beta, - unsigned int *rand_state, - bool stochastic_round, bool apply_relu, - CUstream stream, int grid=-1 - ); - -/** Perform BLAS hgemm on alpha * A * B + beta * C, with the - * additional options of stochastic rounding and applying a - * rectified linear unit (relu) to the result. This routine expects - * all matrices to be in row-major order. - * \param [in] A Pointer to the data for matrix A - * \param [in] B Pointer to the data for matrix B - * \param [in, out] C Pointer to the data for matrix C - * \param [in] m number of rows of C - * \param [in] n number of columns of C - * \param [in] k inner dimension of multiplication - * \param [in] lda leading dimension of two-dimensional array A - * \param [in] ldb leading dimension of two-dimensional array B - * \param [in] ldc leading dimension of two-dimensional array C - * \param [in] alpha scalar used for multiplication - * \param [in] beta scalar used for multiplication - * \param [in, out] rand_state pointer to memory used for random state - * use nervana_randStateSizeBytes to allocate the correct size - * if stochastic_round is false, this can be NULL - * \param [in] stochastic_round true if stochastic rounding should be used - * \param [in] apply_relu true if a relu should be applied to the result - * \param [in] stream The cudaStream on which the kernel should be launched - * \param [in] grid Choose a specific grid configuration: 0=32x128, 1=128x32, 2=128x64, 3=128x128 - */ - bool nervana_hgemm(short *A, short *B, short *C, - bool a_t, bool b_t, - int m, int n, int k, - int lda, int ldb, int ldc, - float alpha, float beta, - unsigned int *rand_state, - bool stochastic_round, bool apply_relu, - CUstream stream, int grid=-1 - ); - - bool nervana_sgemm_colmajor(float *A, float *B, float *C, - bool a_t, bool b_t, - int m, int n, int k, - int lda, int ldb, int ldc, - float alpha, float beta, - unsigned int *rand_state, - bool stochastic_round, bool apply_relu, - CUstream stream, int grid=-1 - ); - - bool nervana_hgemm_colmajor(short *A, short *B, short *C, - bool a_t, bool b_t, - int m, int n, int k, - int lda, int ldb, int ldc, - float alpha, float beta, - unsigned int *rand_state, - bool stochastic_round, bool apply_relu, - CUstream stream, int grid=-1 - ); - -#ifdef __cplusplus -} -#endif diff --git a/app/src/main/cpp/caffe2/contrib/observers/time_observer.h b/app/src/main/cpp/caffe2/contrib/observers/time_observer.h deleted file mode 100644 index 5719d38..0000000 --- a/app/src/main/cpp/caffe2/contrib/observers/time_observer.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef CAFFE2_CONTRIB_OBSERVERS_TIME_OBSERVER_H_ -#define CAFFE2_CONTRIB_OBSERVERS_TIME_OBSERVER_H_ - -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/observer.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/timer.h" - -namespace caffe2 { - -template -class TimeObserver final : public ObserverBase { - public: - explicit TimeObserver(T* subject) : ObserverBase(subject) {} - inline float average_time() const { - return total_time_ / iterations_; - } - float average_time_children() const { - float sum = 0.0f; - for (auto* op : this->subject_->GetOperators()) { - auto* observer = - dynamic_cast_if_rtti*>(op->GetObserver()); - sum += observer->average_time(); - } - return sum / this->subject_->GetOperators().size(); - } - ~TimeObserver() {} - - private: - Timer timer_; - float start_time_ = 0.0f; - float total_time_ = 0.0f; - int iterations_ = 0; - - bool Start() override; - bool Stop() override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_CONTRIB_OBSERVERS_TIME_OBSERVER_H_ diff --git a/app/src/main/cpp/caffe2/contrib/prof/htrace_conf.h b/app/src/main/cpp/caffe2/contrib/prof/htrace_conf.h deleted file mode 100644 index 97286cb..0000000 --- a/app/src/main/cpp/caffe2/contrib/prof/htrace_conf.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "caffe2/core/flags.h" - -CAFFE2_DECLARE_string(caffe2_htrace_span_log_path); - -namespace caffe2 { - -const string defaultHTraceConf(const string& net_name); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/prof/prof_dag_net.h b/app/src/main/cpp/caffe2/contrib/prof/prof_dag_net.h deleted file mode 100644 index 3895989..0000000 --- a/app/src/main/cpp/caffe2/contrib/prof/prof_dag_net.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include "caffe2/core/net_dag.h" -#include "caffe2/proto/prof_dag.pb.h" - -namespace caffe2 { - -struct Stats { - float sum; - float sqrsum; - size_t cnt; -}; - -/** - * This net type is identical to DAGNet, except that it - * measures the time taken for each and every operator. - * - * To collect statistics from stable runs, this net ignores the first run. - * Thus, at least two runs are required for this net to print operator metrics. - */ -class ProfDAGNet : public DAGNetBase { - public: - ProfDAGNet(const std::shared_ptr& net_def, Workspace* ws); - ~ProfDAGNet(); - bool SupportsAsync() override { - return false; - } - bool RunAsync() override; - ProfDAGProtos GetOperatorStats(); - - protected: - bool RunAt(const std::vector& chain) override; - void PrintStats(); - void ValidateOpTensorDevices(); - ProfDAGProto ProtoMsg(std::pair op_stat) const; - std::vector time_per_op_; - CaffeMap time_per_op_type_; - int runs_ = 0; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/contrib/prof/prof_dag_stats_op.h b/app/src/main/cpp/caffe2/contrib/prof/prof_dag_stats_op.h deleted file mode 100644 index f300218..0000000 --- a/app/src/main/cpp/caffe2/contrib/prof/prof_dag_stats_op.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ -#define CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ - -#include "caffe2/contrib/prof/prof_dag_net.h" -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// This operator outputs the ProfDAGNet stats -template -class GetProfDagStatsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - GetProfDagStatsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - net_name_( - OperatorBase::GetSingleArgument("net_name", "")) { - ws_ = ws; - } - ~GetProfDagStatsOp() {} - - bool RunOnDevice() override { - // Read operator statistics for net_name_ - CAFFE_ENFORCE(!net_name_.empty(), "You need to provide net_name"); - auto* net = ws_->GetNet(net_name_); - - auto prof_dag_net = dynamic_cast_if_rtti(net); - CAFFE_ENFORCE(prof_dag_net); - auto stats = prof_dag_net->GetOperatorStats(); - - // Write protobuf message to the output blob - std::string serialized_data; - CAFFE_ENFORCE(stats.SerializeToString(&serialized_data)); - Output(0)->Resize(1); - Output(0)->template mutable_data()[0] = serialized_data; - - return true; - } - - protected: - std::string net_name_; - Workspace* ws_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ diff --git a/app/src/main/cpp/caffe2/contrib/shm_mutex/shm_mutex.h b/app/src/main/cpp/caffe2/contrib/shm_mutex/shm_mutex.h deleted file mode 100644 index d9a97d7..0000000 --- a/app/src/main/cpp/caffe2/contrib/shm_mutex/shm_mutex.h +++ /dev/null @@ -1,343 +0,0 @@ -/* - * This implements a machine-wide mutex to be used - * to synchronize CUDA calls (memory allocation and frees) and - * NCCL calls. This prevents a potential deadlock that - * can occur. - * - * The implementation has a few caveats: - * - it assumes that PID are not reused - * - there is a possible race between the creation (shm_open followed - * by ftruncate) and the spin on 'isInitialized' (if the memory region is - * not all zeroes). - * - * There are two implementations of the mutex and they vary mostly by how - * they wait: - * - The ShmTicketMutex_t is a simple ticket based lock and processes will - * queue up and only attempt to grab the lock when it is their turn - * - The ShmTTSetMutex_t is a simple test-test-and-set mutex. It is possibly - * faster for low contention. - * - * Use both as you would use any std::mutex. Both mutexes support try_lock as - * well. - */ -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "caffe2/core/logging.h" - -const int kTicketDelay = 1000; -const int kTimeout = 1000; - -class ShmProcessMutexCheck { - public: - static ShmProcessMutexCheck& getInstance(); - ShmProcessMutexCheck(const ShmProcessMutexCheck&) = delete; - ShmProcessMutexCheck& operator=(const ShmProcessMutexCheck&) = delete; - - bool addLock(const std::string& name); - bool removeLock(const std::string& name); - - protected: - ShmProcessMutexCheck() = default; - std::mutex m_; - std::unordered_set shmLocks_; -}; - -template -struct shm_traits; - -using ShmBaseHeader = struct { - std::atomic isInitialized; - std::atomic countMapped; - std::atomic owner; -}; - -template -class ShmProcessMutex { - public: - using header_t = typename shm_traits::header_t; - - explicit ShmProcessMutex(const char* name) - : name_(name), check_(ShmProcessMutexCheck::getInstance()) { - CAFFE_ENFORCE(check_.addLock(name_), "Creating duplicate lock: ", name_); - myPid_ = getpid(); - // Try to open and map the shared memory location - int fd = -1; - while (true) { - fd = shm_open(name, O_RDWR, 0); - if (fd == -1) { - CAFFE_ENFORCE( - errno == ENOENT, - "shm_open failed with not ENOENT: ", - strerror(errno)); - - // Create new object - fd = shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0700); - if (fd == -1 && errno == EEXIST) { - // Some other process created first; loop around to re-open - continue; - } - CAFFE_ENFORCE( - fd != -1, "shm_open failed with create: ", strerror(errno)); - // At this point, we are the creator of the shared object. - // Initialize the header_ (it's all 0 right now) - auto rv = ftruncate(fd, sizeof(header_t)); - CAFFE_ENFORCE(rv != -1, "ftruncate: ", strerror(errno)); - - // Map memory and initialize - header_ = (header_t*)mmap( - nullptr, - sizeof(header_t), - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - 0); - CAFFE_ENFORCE(header_ != MAP_FAILED, "mmap: ", strerror(errno)); - - header_->countMapped = 1; - header_->owner = 0; - header_->isInitialized.store(true, std::memory_order_release); - close(fd); - break; - } else { - // Object exists, we just map it - header_ = (header_t*)mmap( - nullptr, - sizeof(header_t), - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - 0); - CAFFE_ENFORCE(header_ != MAP_FAILED, "mmap: ", strerror(errno)); - - // Wait for memory to be initialized - while (header_->isInitialized.load(std::memory_order_acquire) == 0) { - // Spin; should be done soon - } - // Now check if we can register ourself by incrementing countMapped. - // If we are "locked-out" (shared object being destroyed), retry - if (header_->countMapped.fetch_add(1, std::memory_order_relaxed) < 0) { - header_->countMapped.fetch_sub(1, std::memory_order_relaxed); - int rv = munmap(header_, sizeof(header_t)); - CAFFE_ENFORCE(rv == 0, "munmap (to retry) failed: ", strerror(errno)); - close(fd); - continue; - } - close(fd); - break; - } - } - } - - ~ShmProcessMutex() { - if (header_ != nullptr) { - // We are participating in a lock. Destroy - internalDestroy(); - } - } - - // Copy and assignment operator are implicitly deleted - - ShmProcessMutex(ShmProcessMutex&& toMove) noexcept - : header_(toMove.header_), - myPid_(toMove.myPid_), - name_(toMove.name_), - check_(toMove.check_) { - toMove.header_ = nullptr; - toMove.myPid_ = -1; - } - - ShmProcessMutex& operator=(ShmProcessMutex&& toMove) { - CAFFE_ENFORCE(toMove.myPid_ == this->myPid_); - if (&toMove != this) { - internalDestroy(); - header_ = toMove.header_; - name_ = toMove.name_; - toMove.header_ = nullptr; - toMove.myPid_ = -1; - } - return *this; - } - - void lock() { - pid_t expectedPid = 0; - while (not header_->owner.compare_exchange_weak( - expectedPid, - myPid_, - std::memory_order_relaxed, - std::memory_order_relaxed)) { - if (expectedPid == 0) { - continue; - } - // Someone else has the lock. We check if that process is - // still alive - if (kill(expectedPid, 0) < 0 && errno == ESRCH) { - // The process no longer exists. Try to "steal" the lock - continue; - } - while (true) { - if (static_cast(this)->waitForLock()) { - return; - } - expectedPid = header_->owner.load(std::memory_order_relaxed); - if (expectedPid == 0 || (kill(expectedPid, 0) < 0 && errno == ESRCH)) { - break; - } - } - } - } - - bool try_lock() { - pid_t expectedPid = 0; - bool firstTry = true; - while (not header_->owner.compare_exchange_weak( - expectedPid, - myPid_, - std::memory_order_relaxed, - std::memory_order_relaxed)) { - if (expectedPid == 0) { - continue; - } - // Someone else has the lock. We check if that process is - // still alive - if (firstTry && kill(expectedPid, 0) < 0 && errno == ESRCH) { - firstTry = false; - // The process no longer exists. Try to "steal" the lock once - continue; - } - return false; - } - return true; - } - - void unlock() noexcept { - header_->owner.store(0, std::memory_order_relaxed); - static_cast(this)->subUnlock(); - } - - protected: - header_t* header_; - pid_t myPid_; - std::string name_; - - ShmProcessMutexCheck& check_; - - private: - void internalDestroy() { - CAFFE_ENFORCE(header_ != nullptr, "Internal error"); - CAFFE_ENFORCE(check_.removeLock(name_), "Double free of lock: ", name_); - // Unmap the memory. If we are the last one, "lock" the - // shared memory and free it if successful - int oldCount = header_->countMapped.fetch_sub(1, std::memory_order_relaxed); - bool doUnlink = false; - if (oldCount == 1) { - // We were the last one. We attempt to lock out - // future processes by exchanging with something very negative - // This simplifies the checks when checking for lock out - oldCount = 0; - if (header_->countMapped.compare_exchange_strong( - oldCount, - INT_MIN, - std::memory_order_relaxed, - std::memory_order_relaxed)) { - doUnlink = true; - } - } - int rv = munmap(header_, sizeof(header_t)); - CAFFE_ENFORCE(rv == 0, "munmap failed: ", strerror(errno)); - if (doUnlink) { - rv = shm_unlink(name_.c_str()); - CAFFE_ENFORCE(rv == 0, "shm_unlink failed: ", strerror(errno)); - } - } -}; - -template -class ShmTTSetMutex : public ShmProcessMutex> { - public: - friend class ShmProcessMutex>; - explicit ShmTTSetMutex(const char* name, int timeout = kTimeout) - : ShmProcessMutex(name), timeout_(timeout) {} - - protected: - bool waitForLock() { - int delay = timeout_; - pid_t expectedPid = 0; - while (--delay > 0 && - this->header_->owner.load(std::memory_order_relaxed)) { - // Empty loop - __asm__ __volatile__(""); - } - return this->header_->owner.compare_exchange_strong( - expectedPid, this->myPid_, std::memory_order_relaxed); - } - - void subUnlock() noexcept {} - int timeout_; -}; - -template -class ShmTicketMutex : public ShmProcessMutex> { - public: - friend class ShmProcessMutex>; - explicit ShmTicketMutex(const char* name, int delay = kTicketDelay) - : ShmProcessMutex(name), delay_(delay) {} - - protected: - bool waitForLock() { - pid_t expectedPid = 0; - int slot = this->header_->ticket.fetch_add(1, std::memory_order_relaxed); - for (;;) { - int spintime = - (slot - this->header_->now.load(std::memory_order_relaxed)) * delay_; - for (int i = 0; i < spintime; i++) { - // Empty loop - __asm__ __volatile__(""); - } - if (this->header_->now.load(std::memory_order_relaxed) == slot) { - break; - } - } - return this->header_->owner.compare_exchange_strong( - expectedPid, this->myPid_, std::memory_order_relaxed); - } - - void subUnlock() noexcept { - this->header_->now.fetch_add(1, std::memory_order_relaxed); - } - - int delay_; -}; - -template -struct shm_traits> { - using header_t = T; -}; - -template -struct shm_traits> { - using header_t = T; -}; - -using TicketStruct = struct : ShmBaseHeader { - std::atomic ticket; - std::atomic now; -}; - -template class ShmTicketMutex; -template class ShmTTSetMutex; - -using ShmTicketMutex_t = ShmTicketMutex; -using ShmTTSetMutex_t = ShmTTSetMutex; diff --git a/app/src/main/cpp/caffe2/contrib/torch/torch_op.h b/app/src/main/cpp/caffe2/contrib/torch/torch_op.h deleted file mode 100644 index c586036..0000000 --- a/app/src/main/cpp/caffe2/contrib/torch/torch_op.h +++ /dev/null @@ -1,575 +0,0 @@ -#pragma once -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" - -extern "C" { -#include -#include -#include -#include -#include -} - -namespace caffe2 { - -namespace torch { - -template -struct TyTraits {}; - -template <> -struct TyTraits { - static const char* moduleTy; - static const char* prelude; - static const char* tensorTy; - using Tensor = THFloatTensor; -}; - -template -class Torch final { - public: - using Traits = TyTraits; - Torch() { - L_ = luaL_newstate(); - luaL_openlibs(L_); - luaL_loadstring(L_, Traits::prelude); - int err = lua_pcall(L_, 0, 0, 0); - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L_, -1)); - }; - - ~Torch() { - lua_close(L_); - } - - lua_State* L() { - return L_; - } - - static const char* tensorTy(const Blob& blob) { - CAFFE_ENFORCE(blob.template IsType>()); - const auto& tc = blob.template Get>(); - CAFFE_ENFORCE( - tc.template IsType() + tc.meta().name(), ", ", tc.size()); - return Traits::tensorTy; - } - - void setContext(Context* /*context*/) {} - - void setTensor(typename Traits::Tensor* t, Blob* blob) { - CAFFE_ENFORCE_EQ(tensorTy(*blob), Traits::tensorTy); - auto* tc = blob->template GetMutable>(); - CAFFE_ENFORCE_EQ(THFloatTensor_nElement(t), tc->size()); - THFloatStorage* storage = THFloatStorage_newWithData( - tc->template mutable_data(), tc->size()); - THFloatStorage_clearFlag(storage, TH_STORAGE_FREEMEM); - THFloatStorage* original = t->storage; - t->storage = storage; - THFloatStorage_free(original); - } - - std::vector tensorShape(typename Traits::Tensor* t) { - auto* size = t->size; - return std::vector(size, size + THFloatTensor_nDimension(t)); - } - - typename Traits::Tensor* newTensorAs(const Tensor& tc) { - THLongStorage* thshape = THLongStorage_newWithSize(tc.ndim()); - for (uint32_t i = 0; i < tc.ndim(); ++i) { - THLongStorage_set(thshape, i, tc.dim(i)); - } - THFloatTensor* d = THFloatTensor_newWithSize(thshape, nullptr); - THLongStorage_free(thshape); - return d; - } - - typename Traits::Tensor* blobToTensor(Blob* blob) { - CAFFE_ENFORCE_EQ(tensorTy(*blob), Traits::tensorTy); - auto* tc = blob->template GetMutable>(); - - size_t size = tc->size(); - THLongStorage* thshape = THLongStorage_newWithSize(tc->ndim()); - for (int i = 0; i < tc->ndim(); ++i) { - THLongStorage_set(thshape, i, tc->dim(i)); - } - THFloatStorage* storage = - THFloatStorage_newWithData(tc->template mutable_data(), size); - THFloatStorage_clearFlag(storage, TH_STORAGE_FREEMEM); - auto* th = THFloatTensor_newWithStorage(storage, 0, thshape, nullptr); - THFloatStorage_free(storage); - THLongStorage_free(thshape); - CAFFE_ENFORCE_EQ( - THFloatTensor_storage(th)->data, tc->template mutable_data()); - return th; - } - - std::vector pushTable( - const std::vector& blobs) { - if (blobs.empty()) { - lua_pushnil(L()); - return {}; - } - - if (blobs.size() == 1) { - auto* th = blobToTensor(blobs[0]); - luaT_pushudata(L(), th, tensorTy(*blobs[0])); - return {th}; - } - - std::vector res; - lua_createtable(L(), blobs.size(), 0); - int index = 1; - for (auto* blob : blobs) { - auto* th = blobToTensor(blob); - res.push_back(th); - luaT_pushudata(L(), th, tensorTy(*blob)); - lua_rawseti(L(), -2, index++); - } - return res; - } - - void verifyOutput(Blob* dst, typename Traits::Tensor* torchDst) { - if (!luaT_isudata(L(), -1, Traits::tensorTy)) { - LOG(FATAL) << "Unsupported Torch tensor type " << luaT_typename(L(), -1); - } - - // Invariant: dst has the same size as src, and has the same data - // values as src. - auto* src = static_cast( - luaT_toudata(L(), -1, Traits::tensorTy)); - auto* thDst = static_cast(torchDst); - auto* tcDst = dst->template GetMutable>(); - CAFFE_ENFORCE(src->storage->data); - CAFFE_ENFORCE(src->storage->size); - CAFFE_ENFORCE_EQ(src->storage->data, thDst->storage->data); - CAFFE_ENFORCE_EQ(src->storage->data, tcDst->template data()); - CAFFE_ENFORCE_EQ(src->storage->size, thDst->storage->size); - CAFFE_ENFORCE_EQ(src->storage->size, tcDst->size()); - } - - void verifyOutputs( - const std::vector& blobs, - const std::vector& tensors) { - CAFFE_ENFORCE_EQ(tensors.size(), blobs.size()); - - if (blobs.empty()) { - return; - } - - if (blobs.size() == 1) { - verifyOutput(blobs[0], tensors[0]); - return; - } - - CAFFE_ENFORCE(lua_istable(L(), -1)); - lua_pushnil(L()); - for (auto i = 0; i < blobs.size(); ++i) { - CAFFE_ENFORCE(lua_next(L(), -2)); - verifyOutput(blobs[i], tensors[i]); - lua_pop(L(), 1); - } - lua_pop(L(), 1); - } - -private: - lua_State* L_; -}; -} - -template -class TorchOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using OperatorBase::Outputs; - using OperatorBase::Inputs; - TorchOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - lua_State* L = state_.L(); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - const auto initString = "return " + - OperatorBase::GetSingleArgument("init", "") + ":" + - torch::Torch::Traits::moduleTy + "()"; - CAFFE_ENFORCE_EQ(luaL_loadstring(L, initString.c_str()), 0); - int err = lua_pcall(L, 0, 1, 0); - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - // Get number of parameters - uint32_t numParams = 0; - lua_getfield(L, -1, "parameters"); - lua_pushvalue(L, -2); - CAFFE_ENFORCE_EQ(lua_pcall(L, 1, LUA_MULTRET, 0), 0); - if (lua_gettop(L) == 1) { - numParams = 0; - } else { - CAFFE_ENFORCE_EQ(lua_gettop(L), 3); - numParams = lua_objlen(L, -2); - lua_pop(L, 2); - } - CAFFE_ENFORCE_EQ( - numParams, OperatorBase::GetSingleArgument("num_params", 0)); - // TODO: free parameters? - self_ = luaL_ref(L, LUA_REGISTRYINDEX); - } - - void reshapeBlobs( - const std::vector& inputBlobs, - const std::vector& paramBlobs, - const std::vector& outputBlobs) { - auto cacheEqual = [=]() { - if (cachedInputSizes_.size() != inputBlobs.size()) { - return false; - } - - for (auto i = 0; i < inputBlobs.size(); ++i) { - const auto& current = - inputBlobs[i]->template Get>().dims(); - const auto& cached = cachedInputSizes_[i]; - if (current != cached) { - return false; - } - } - return true; - }; - - if (cacheEqual()) { - return; - } - LOG(INFO) << "Cached blobs not equal, running :updateOutput to reshape"; - lua_State* L = state_.L(); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - lua_rawgeti(L, LUA_REGISTRYINDEX, self_); - lua_getfield(L, -1, "updateOutput"); - lua_pushvalue(L, -2); // self - if (inputBlobs.size() == 1) { - const auto& tc = inputBlobs[0]->template Get>(); - auto* inputData = state_.newTensorAs(tc); - luaT_pushudata(L, inputData, torch::Torch::Traits::tensorTy); - } else if (inputBlobs.size() > 1) { - lua_createtable(L, inputBlobs.size(), 0); - for (auto i = 0; i < inputBlobs.size(); ++i) { - const auto* blob = inputBlobs[i]; - const auto& tc = blob->template Get>(); - auto* inputData = state_.newTensorAs(tc); - luaT_pushudata(L, inputData, torch::Torch::Traits::tensorTy); - lua_rawseti(L, -2, i + 1); - } - } - int err = lua_pcall(L, 2, 0, 0); - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - if (paramBlobs.size() != 0) { - lua_getfield(L, -1, "parameters"); - lua_pushvalue(L, -2); - int err2 = lua_pcall(L, 1, LUA_MULTRET, 0); - CAFFE_ENFORCE_EQ(err2, 0); - CAFFE_ENFORCE_EQ(lua_gettop(L), 3); - lua_pushnil(L); - int i = 0; - while (lua_next(L, -3) && i < paramBlobs.size()) { - CAFFE_ENFORCE( - luaT_isudata(L, -1, torch::Torch::Traits::tensorTy)); - auto* param = - static_cast::Traits::Tensor*>( - luaT_toudata(L, -1, torch::Torch::Traits::tensorTy)); - auto paramShape = state_.tensorShape(param); - auto* blob = paramBlobs[i]; - auto* tc = blob->template GetMutable>(); - if (tc->size() == 0) { - tc->Resize(paramShape); - tc->template mutable_data(); - } else { - CAFFE_ENFORCE(tc->dims() == paramShape); - } - lua_pop(L, 1); - i++; - } - CAFFE_ENFORCE_EQ(i, paramBlobs.size()); - lua_pop(L, 2); - } - lua_getfield(L, -1, "output"); - if (outputBlobs.size() == 0) { - } else if (outputBlobs.size() == 1) { - CAFFE_ENFORCE( - luaT_isudata(L, -1, torch::Torch::Traits::tensorTy)); - auto* output = - static_cast::Traits::Tensor*>( - luaT_toudata(L, -1, torch::Torch::Traits::tensorTy)); - auto outputShape = state_.tensorShape(output); - auto* blob = outputBlobs[0]; - auto* tc = blob->template GetMutable>(); - tc->Resize(outputShape); - tc->template mutable_data(); - } else { - lua_pushnil(L); - auto i = 0; - while (lua_next(L, -2) && i < outputBlobs.size()) { - CAFFE_ENFORCE( - luaT_isudata(L, -1, torch::Torch::Traits::tensorTy)); - auto* output = - static_cast::Traits::Tensor*>( - luaT_toudata(L, -1, torch::Torch::Traits::tensorTy)); - auto outputShape = state_.tensorShape(output); - auto* blob = outputBlobs[i]; - auto* tc = blob->template GetMutable>(); - if (tc->size() == 0) { - tc->Resize(outputShape); - tc->template mutable_data(); - } else { - CAFFE_ENFORCE(tc->dims() == outputShape); - } - ++i; - } - CAFFE_ENFORCE_EQ(i, outputBlobs.size()); - } - lua_pop(L, 2); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - - cachedInputSizes_.clear(); - for (const auto* blob : inputBlobs) { - const auto& dims = blob->template Get>().dims(); - cachedInputSizes_.push_back(dims); - } - } - - protected: - torch::Torch state_; - int self_{0}; - std::vector> cachedInputSizes_; -}; - -template -class TorchOp : public TorchOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using OperatorBase::Outputs; - using OperatorBase::Inputs; - using TorchOpBase::state_; - using TorchOpBase::self_; - - using TorchOpBase::TorchOpBase; - - bool RunOnDevice() final { - const auto numInputs = - OperatorBase::GetSingleArgument("num_inputs", 1); - const auto numParams = - OperatorBase::GetSingleArgument("num_params", 0); - const auto numOutputs = - OperatorBase::GetSingleArgument("num_outputs", 1); - CAFFE_ENFORCE_EQ(InputSize(), numInputs + numParams); - CAFFE_ENFORCE_EQ(OutputSize(), numOutputs); - - std::vector inputBlobs; - for (auto i = 0; i < numInputs; ++i) { - inputBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector paramBlobs; - for (auto i = numInputs; i < numInputs + numParams; ++i) { - paramBlobs.push_back(const_cast(Inputs()[i])); - } - // Outputs must already be pre-sized - this->reshapeBlobs(inputBlobs, paramBlobs, Outputs()); - - lua_State* L = state_.L(); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - state_.setContext(&context_); - - // Deserialize self table - lua_rawgeti(L, LUA_REGISTRYINDEX, self_); - - auto torchOutputs = state_.pushTable(Outputs()); - // set the output field - lua_setfield(L, -2, "output"); - // set the parameters - if (numParams != 0) { - // get the parameters into the stack - lua_getfield(L, -1, "parameters"); - lua_pushvalue(L, -2); - int err = lua_pcall(L, 1, 1, 0); - CAFFE_ENFORCE_EQ(err, 0); - // iterate the parameters table to put tblobs inside - lua_pushnil(L); - auto i = 0; - while (lua_next(L, -2) && i < numParams) { - CAFFE_ENFORCE( - luaT_isudata(L, -1, state_.tensorTy(*paramBlobs[i])), - luaT_typename(L, -1)); - auto* udata = luaT_toudata(L, -1, state_.tensorTy(*paramBlobs[i])); - state_.setTensor( - static_cast::Traits::Tensor*>(udata), - const_cast(paramBlobs[i])); - i++; - lua_pop(L, 1); - } - CAFFE_ENFORCE_EQ(i, numParams); - lua_pop(L, 1); // pop the parameter table - } - // call updateOutput - // | self - lua_getfield(L, -1, "updateOutput"); - // | self | updateOutput - lua_pushvalue(L, -2); - // | self | updateOutput | self - auto torchInputs = state_.pushTable(inputBlobs); - // | self | updateOutput | self | inputs - int err = lua_pcall(L, 2, 1, 0); // doesn't need the output - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - state_.verifyOutputs(Outputs(), torchOutputs); - lua_pop(L, 2); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - return true; - } -}; - -template -class TorchInitOp : public TorchOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using OperatorBase::Outputs; - using OperatorBase::Inputs; - using TorchOpBase::TorchOpBase; - - bool RunOnDevice() final { - const auto numInputs = - OperatorBase::GetSingleArgument("num_inputs", 1); - const auto numParams = - OperatorBase::GetSingleArgument("num_params", 0); - const auto numOutputs = - OperatorBase::GetSingleArgument("num_outputs", 1); - std::vector inputBlobs; - for (auto i = 0; i < numInputs; ++i) { - inputBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector paramBlobs; - for (auto i = numInputs; i < numInputs + numParams; ++i) { - paramBlobs.push_back(const_cast(Inputs()[i])); - } - this->reshapeBlobs(inputBlobs, paramBlobs, Outputs()); - return true; - } -}; - -template -class TorchGradientOp : public TorchOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using OperatorBase::Outputs; - using OperatorBase::Inputs; - using TorchOpBase::state_; - using TorchOpBase::self_; - using TorchOpBase::TorchOpBase; - - bool RunOnDevice() final { - const auto numInputs = - OperatorBase::GetSingleArgument("num_inputs", 1); - const auto numParams = - OperatorBase::GetSingleArgument("num_params", 0); - const auto numOutputs = - OperatorBase::GetSingleArgument("num_outputs", 1); - lua_State* L = state_.L(); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - // inputs, params, outputs, grad outputs - CAFFE_ENFORCE_EQ(InputSize(), numInputs + numParams + 2 * numOutputs); - // grad inputs, grad params - CAFFE_ENFORCE_EQ(OutputSize(), numInputs + numParams); - state_.setContext(&context_); - - std::vector outputBlobs; - for (auto i = numInputs + numParams; i < numInputs + numParams + numOutputs; - ++i) { - outputBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector inputBlobs; - for (auto i = 0; i < numInputs; ++i) { - inputBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector gradOutputBlobs; - for (auto i = numInputs + numParams + numOutputs; - i < numInputs + numParams + numOutputs + numOutputs; - ++i) { - gradOutputBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector gradInputBlobs; - for (auto i = 0; i < numInputs; ++i) { - gradInputBlobs.push_back(Outputs()[i]); - } - std::vector paramBlobs; - for (auto i = numInputs; i < numInputs + numParams; ++i) { - paramBlobs.push_back(const_cast(Inputs()[i])); - } - std::vector gradParamBlobs; - for (auto i = numInputs; i < numInputs + numParams; ++i) { - gradParamBlobs.push_back(Outputs()[i]); - } - - // Ensure shapes are correct. - for (auto i = 0; i < OutputSize(); ++i) { - Output(i)->ResizeLike(Input(i)); - Output(i)->template mutable_data(); - } - - lua_rawgeti(L, LUA_REGISTRYINDEX, self_); - state_.pushTable(outputBlobs); - lua_setfield(L, -2, "output"); - - const auto& torchGradInputs = state_.pushTable(gradInputBlobs); - lua_setfield(L, -2, "gradInput"); - if (numParams != 0) { - // get the parameters into the stack - lua_getfield(L, -1, "parameters"); - lua_pushvalue(L, -2); - int err = lua_pcall(L, 1, LUA_MULTRET, 0); - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - // iterate the parameters table to put tblobs inside - lua_pushnil(L); - auto i = 0; - while (lua_next(L, -3) && i < numParams) { - CAFFE_ENFORCE(luaT_isudata(L, -1, state_.tensorTy(*paramBlobs[i]))); - auto* udata = luaT_toudata(L, -1, state_.tensorTy(*paramBlobs[i])); - state_.setTensor( - static_cast::Traits::Tensor*>(udata), - const_cast(paramBlobs[i])); - i++; - lua_pop(L, 1); - } - CAFFE_ENFORCE_EQ(i, numParams); - // iterate the grad of params - lua_pushnil(L); - i = 0; - while (lua_next(L, -2) && i < numParams) { - CAFFE_ENFORCE(luaT_isudata(L, -1, state_.tensorTy(*gradParamBlobs[i]))); - auto* udata = luaT_toudata(L, -1, state_.tensorTy(*gradParamBlobs[i])); - state_.setTensor( - static_cast::Traits::Tensor*>(udata), - const_cast(gradParamBlobs[i])); - i++; - lua_pop(L, 1); - } - CAFFE_ENFORCE_EQ(i, numParams); - lua_pop(L, 2); // pop the parameters - } - lua_getfield(L, -1, "zeroGradParameters"); - lua_pushvalue(L, -2); - CAFFE_ENFORCE_EQ(lua_pcall(L, 1, 0, 0), 0); - state_.pushTable(inputBlobs); - state_.pushTable(gradOutputBlobs); - // call - lua_getfield(L, -3, "accGradParameters"); - lua_pushvalue(L, -4); - lua_pushvalue(L, -4); - lua_pushvalue(L, -4); - lua_pushnumber(L, 1); - int err = lua_pcall(L, 4, 0, 0); // doesn't need the output - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - lua_getfield(L, -3, "updateGradInput"); - lua_pushvalue(L, -4); - lua_pushvalue(L, -4); - lua_pushvalue(L, -4); - err = lua_pcall(L, 3, 1, 0); // doesn't need the output - CAFFE_ENFORCE_EQ(err, 0, lua_tostring(L, -1)); - state_.verifyOutputs(gradInputBlobs, torchGradInputs); - lua_pop(L, 4); - CAFFE_ENFORCE_EQ(lua_gettop(L), 0); - return true; - } -}; -} diff --git a/app/src/main/cpp/caffe2/contrib/warpctc/ctc_op.h b/app/src/main/cpp/caffe2/contrib/warpctc/ctc_op.h deleted file mode 100644 index 1a1bcac..0000000 --- a/app/src/main/cpp/caffe2/contrib/warpctc/ctc_op.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" -#include "caffe2/core/common_cudnn.h" - -#define CTC_CHECK(condition) \ - do { \ - ctcStatus_t status = condition; \ - CAFFE_ENFORCE_EQ( \ - status, \ - CTC_STATUS_SUCCESS, \ - " Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - ::ctcGetStatusString(status)); \ - } while (0) - -namespace caffe2 { - -namespace detail { - -template -ctcComputeInfo workspaceInfo(const Context& context); - -} - -template -class CTCOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CTCOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - // inputs - const auto& inputs = Input(INPUTS); - const auto minibatchSize = inputs.dim(1); - const auto alphabetSize = inputs.dim(2); - const auto& labels = OperatorBase::template Input(LABELS); - const auto& labelLengths = - OperatorBase::template Input(LABEL_LENGTHS); - const auto& inputLengths = - OperatorBase::template Input(INPUT_LENGTHS); - - // outputs - auto* costs = OperatorBase::template Output(COSTS); - costs->ResizeLike(labelLengths); - auto* gradients = Output(GRADIENTS); - gradients->ResizeLike(inputs); - auto* workspace = Output(WORKSPACE); - - size_t workspaceSizeBytes; - CTC_CHECK(get_workspace_size( - labelLengths.template data(), - inputLengths.template data(), - alphabetSize, - minibatchSize, - detail::workspaceInfo(context_), - &workspaceSizeBytes)); - workspace->Resize(workspaceSizeBytes); - CTC_CHECK(compute_ctc_loss( - inputs.template data(), - gradients->template mutable_data(), - labels.template data(), - labelLengths.template data(), - inputLengths.template data(), - alphabetSize, - minibatchSize, - costs->template mutable_data(), - workspace->template mutable_data(), - detail::workspaceInfo(context_))); - return true; - } - -private: - INPUT_TAGS(INPUTS, LABELS, LABEL_LENGTHS, INPUT_LENGTHS); - OUTPUT_TAGS(GRADIENTS, COSTS, WORKSPACE); -}; -} - -#undef CTC_CHECK diff --git a/app/src/main/cpp/caffe2/core/allocator.h b/app/src/main/cpp/caffe2/core/allocator.h deleted file mode 100644 index 6f94153..0000000 --- a/app/src/main/cpp/caffe2/core/allocator.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef CAFFE2_CORE_ALLOCATOR_H_ -#define CAFFE2_CORE_ALLOCATOR_H_ - -#include - -#include "caffe2/core/logging.h" - -CAFFE2_DECLARE_bool(caffe2_report_cpu_memory_usage); -CAFFE2_DECLARE_bool(caffe2_cpu_allocator_do_zero_fill); - -namespace caffe2 { - -// Use 32-byte alignment should be enough for computation up to AVX512. -constexpr size_t gCaffe2Alignment = 32; - -using MemoryDeleter = void (*)(void*); - -// A helper function that is basically doing nothing. -void NoDelete(void*); - -// A virtual allocator class to do memory allocation and deallocation. -struct CPUAllocator { - CPUAllocator() {} - virtual ~CPUAllocator() noexcept {} - virtual std::pair New(size_t nbytes) = 0; - virtual MemoryDeleter GetDeleter() = 0; -}; - -// A virtual struct that is used to report Caffe2's memory allocation and -// deallocation status -class MemoryAllocationReporter { - public: - MemoryAllocationReporter() : allocated_(0) {} - void New(void* ptr, size_t nbytes); - void Delete(void* ptr); - - private: - std::mutex mutex_; - std::unordered_map size_table_; - size_t allocated_; -}; - -struct DefaultCPUAllocator final : CPUAllocator { - DefaultCPUAllocator() {} - ~DefaultCPUAllocator() override {} - std::pair New(size_t nbytes) override { - void* data = nullptr; -#ifdef __ANDROID__ - data = memalign(gCaffe2Alignment, nbytes); -#elif defined(_MSC_VER) - data = _aligned_malloc(nbytes, gCaffe2Alignment); -#else - CAFFE_ENFORCE_EQ(posix_memalign(&data, gCaffe2Alignment, nbytes), 0); -#endif - CAFFE_ENFORCE(data); - if (FLAGS_caffe2_cpu_allocator_do_zero_fill) { - memset(data, 0, nbytes); - } - return {data, Delete}; - } - -#ifdef _MSC_VER - static void Delete(void* data) { - _aligned_free(data); - } -#else - static void Delete(void* data) { - free(data); - } -#endif - - MemoryDeleter GetDeleter() override { - return Delete; - } -}; - -// Get the CPU Alloctor. -CPUAllocator* GetCPUAllocator(); -// Sets the CPU allocator to the given allocator: the caller gives away the -// ownership of the pointer. -void SetCPUAllocator(CPUAllocator* alloc); - -} // namespace caffe2 - -#endif // CAFFE2_CORE_ALLOCATOR_H_ diff --git a/app/src/main/cpp/caffe2/core/asan.h b/app/src/main/cpp/caffe2/core/asan.h deleted file mode 100644 index c4526df..0000000 --- a/app/src/main/cpp/caffe2/core/asan.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -// Detect address sanitizer as some stuff doesn't work with it - -#undef CAFFE2_ASAN_ENABLED - -// for clang -#if defined(__has_feature) -#if ((__has_feature(address_sanitizer))) -#define CAFFE2_ASAN_ENABLED 1 -#endif -#endif - -// for gcc -#if defined(__SANITIZE_ADDRESS__) -#if __SANITIZE_ADDRESS__ -#if !defined(CAFFE2_ASAN_ENABLED) -#define CAFFE2_ASAN_ENABLED 1 -#endif -#endif -#endif - -#if !defined(CAFFE2_ASAN_ENABLED) -#define CAFFE2_ASAN_ENABLED 0 -#endif diff --git a/app/src/main/cpp/caffe2/core/blob.h b/app/src/main/cpp/caffe2/core/blob.h deleted file mode 100644 index 9604a48..0000000 --- a/app/src/main/cpp/caffe2/core/blob.h +++ /dev/null @@ -1,228 +0,0 @@ -#ifndef CAFFE2_CORE_BLOB_H_ -#define CAFFE2_CORE_BLOB_H_ - -#include -#include -#include -#include -#include - -#include "caffe2/core/blob_serializer_base.h" -#include "caffe2/core/common.h" -#include "caffe2/core/typeid.h" -#include "caffe2/core/logging.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -/** - * @brief Blob is a general container that hosts a typed pointer. - * - * A Blob hosts a pointer as well as its type, and takes charge of deleting it - * properly when the blob is deallocated or re-allocated with a new type. A blob - * could contain anything, although the most common case is to contain a Tensor. - */ -class Blob { - public: - /** - * Initializes an empty Blob. - */ - Blob() : meta_(), pointer_(nullptr) {} - ~Blob() { Reset(); } - - Blob(Blob&& other) noexcept - : meta_(std::move(other.meta_)), - pointer_(std::move(other.pointer_)), - destroy_(std::move(other.destroy_)) { - other.meta_ = {}; - other.pointer_ = nullptr; - other.destroy_ = nullptr; - } - - Blob& operator=(Blob&& other) noexcept { - meta_ = std::move(other.meta_); - pointer_ = std::move(other.pointer_); - destroy_ = std::move(other.destroy_); - other.meta_ = {}; - other.pointer_ = nullptr; - other.destroy_ = nullptr; - return *this; - } - - /** - * Checks if the content stored in the blob is of type T. - */ - template - bool IsType() const { return meta_.Match(); } - - /** - * Returns the meta info of the blob. - */ - inline const TypeMeta& meta() const { return meta_; } - - /** - * Returns a printable typename of the blob. - */ - inline const char* TypeName() const { return meta_.name(); } - - /** - * @brief Gets the const reference of the stored object. The code checks if - * the stored object is of the desired type. - */ - template - const T& Get() const { - CAFFE_ENFORCE(IsType(), - "wrong type for the Blob instance. Blob contains ", - meta_.name(), " while caller expects ", TypeMeta::Name()); - return *static_cast(pointer_); - } - - const void* GetRaw() const { - return pointer_; - } - void* GetRaw() { - return pointer_; - } - - /** - * @brief Gets a mutable pointer to the stored object. - * - * If the current object is not of the right type, a new object is created - * and the old object is freed. Note that type T should have a default - * constructor. Otherwise, create the object yourself first, and use - * Reset(). - */ - template - T* GetMutable(bool* is_new_object=nullptr) { - if (IsType()) { - if (is_new_object) *is_new_object = false; - return static_cast(pointer_); - } else { - if (is_new_object) *is_new_object = true; - VLOG(1) << "Create new mutable object " << TypeMeta::Name(); - return Reset(new T()); - } - } - - /** - * Sets the underlying object to the allocated one. The Blob then takes over - * the ownership of the passed in pointer. If there is already an object in - * the Blob, the old object is freed. - * - * This is used when the underlying class T does not have a default ctor, or - * complex initializations needs to be done outside the blob. - */ - template - T* Reset(T* allocated) { - if (pointer_ && destroy_) { - destroy_(pointer_); - } - meta_ = TypeMeta::Make(); - pointer_ = static_cast(allocated); - destroy_ = &Destroy; - return allocated; - } - - /** - * Sets the underlying object to the allocated one, but does not take over - * the ownership of the passed in pointer. If there is already an object in - * the Blob, the old object is freed. - * - * Unlike Reset, this does not take over the ownership of the pointer and the - * caller is responsible for making sure that the lifetime of the allocated - * blob outlasts the lifetime of any access to this blob, until another Reset - * call is made or the blob is destructed. - */ - template - typename std::remove_const::type* ShareExternal( - typename std::remove_const::type* allocated) { - return static_cast(ShareExternal( - static_cast(allocated), - TypeMeta::Make::type>())); - } - - void* ShareExternal(void* allocated, const TypeMeta& meta) { - if (pointer_ && destroy_) { - destroy_(pointer_); - } - meta_ = meta; - pointer_ = static_cast(allocated); - destroy_ = nullptr; - return allocated; - } - - /** - * Resets the Blob to an empty one. - */ - inline void Reset() { - if (pointer_ && destroy_) { - destroy_(pointer_); - } - pointer_ = nullptr; - meta_ = TypeMeta(); - destroy_ = nullptr; - } - - /** - * Serializes the current blob, if possible. Note that this serialization uses - * the registration mechanism and one has to implement specific serialization - * approaches for specific classes. Acceptor should take care of writing data - * to the actual storage. - */ - void Serialize( - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor, - int chunk_size = kDefaultChunkSize) const; - - /** - * @brief Convenience function to serialize a blob to a string. - * - * This is a conveinence function to serialize small Blobs that produce - * manageable serialized strings. To serialize big blobs such as - * large sparse tensors, use the fully-functional interface in - * blob_serializer_base.h. - * - * NOTE: this function doesn't do chunking and might break with big tensors. - */ - string Serialize(const string& name) const; - - /** - * @brief Swaps the underlying storage of two blobs. - */ - void swap(Blob& rhs) { - using std::swap; - swap(meta_, rhs.meta_); - swap(pointer_, rhs.pointer_); - swap(destroy_, rhs.destroy_); - } - - /** - * Deserializes from a string containing either BlobProto or TensorProto. If - * the deserialization fails, the content in the blob should no longer be - * trusted. - */ - void Deserialize(const string& content); - void Deserialize(const BlobProto& proto); - - private: - /** - * @brief A destroy call that is used to properly deconstruct objects. - */ - template - static void Destroy(void* pointer) { - delete static_cast(pointer); - } - typedef void (*DestroyCall)(void *); - TypeMeta meta_; - void* pointer_ = nullptr; - DestroyCall destroy_ = nullptr; - - DISABLE_COPY_AND_ASSIGN(Blob); -}; - -inline void swap(Blob& lhs, Blob& rhs) { - lhs.swap(rhs); -} - -} // namespace caffe2 -#endif // CAFFE2_CORE_BLOB_H_ diff --git a/app/src/main/cpp/caffe2/core/blob_serialization.h b/app/src/main/cpp/caffe2/core/blob_serialization.h deleted file mode 100644 index c61678f..0000000 --- a/app/src/main/cpp/caffe2/core/blob_serialization.h +++ /dev/null @@ -1,566 +0,0 @@ -#ifndef CAFFE2_CORE_BLOB_SERIALIZATION_H_ -#define CAFFE2_CORE_BLOB_SERIALIZATION_H_ - -#include -#include - -#include - -#include "caffe2/core/blob.h" -#include "caffe2/core/blob_serializer_base.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/typeid.h" -#include "caffe2/core/types.h" -#include "caffe2/utils/simple_queue.h" - -CAFFE2_DECLARE_int(caffe2_tensor_chunk_size); -CAFFE2_DECLARE_int(caffe2_max_tensor_serializer_threads); -CAFFE2_DECLARE_bool(caffe2_serialize_fp16_as_bytes); - -namespace caffe2 { - -constexpr auto kTensorBlobType = "Tensor"; -// String used to separate chunk id from the blob name when storing in DB -constexpr auto kChunkIdSeparator = "#%"; - -// The Blob serialization registry and serializer creator functions. -CAFFE_DECLARE_TYPED_REGISTRY( - BlobSerializerRegistry, - CaffeTypeId, - BlobSerializerBase); -#define REGISTER_BLOB_SERIALIZER(id, ...) \ - CAFFE_REGISTER_TYPED_CLASS(BlobSerializerRegistry, id, __VA_ARGS__) -// Creates an operator with the given operator definition. -inline unique_ptr CreateSerializer(CaffeTypeId id) { - return BlobSerializerRegistry()->Create(id); -} - -/** - * @brief TensorSerializer is the serializer for Tensors. - * - * TensorSerializer takes in a blob that contains a Tensor, and serializes it - * into a TensorProto protocol buffer. - */ -template -class TensorSerializer : public BlobSerializerBase { - public: - TensorSerializer() : context_() {} - ~TensorSerializer() override {} - /** - * Serializes a Blob. Note that this blob has to contain Tensor, - * otherwise this function produces a fatal error. - */ - void Serialize( - const Blob& blob, - const string& name, - SerializationAcceptor acceptor) override; - void SerializeWithChunkSize( - const Blob& blob, - const string& name, - SerializationAcceptor acceptor, - int chunk_size) override; - - void Serialize(const Tensor& tensor, const string& name, - TensorProto* proto, size_t chunkBegin, int32_t chunkSize); - - private: - // A utility function to store the device context detauls. - void StoreDeviceDetail(const Tensor& input, TensorProto* proto); - Context context_; -}; - -/** - * @brief BlobDeserializerBase is an abstract class that deserializes a blob - * from a BlobProto or a TensorProto. - */ -class BlobDeserializerBase { - public: - virtual ~BlobDeserializerBase() {} - - // Deserializes from a BlobProto object. - virtual void Deserialize(const BlobProto& proto, Blob* blob) = 0; -}; - -CAFFE_DECLARE_REGISTRY(BlobDeserializerRegistry, BlobDeserializerBase); -#define REGISTER_BLOB_DESERIALIZER(name, ...) \ - CAFFE_REGISTER_CLASS(BlobDeserializerRegistry, name, __VA_ARGS__) -// Creates an operator with the given operator definition. -inline unique_ptr CreateDeserializer(const string& type) { - return BlobDeserializerRegistry()->Create(type); -} - -/** - * @brief TensorDeserializer is the deserializer for Tensors. - * - * The device that the deserialized Tensor will live under is determined by the - * device_detail field. If you want to specify the device of the deserialized - * tensor, change the TensorProto's corresponding fields before calling - * Deserialize. - */ -template -class TensorDeserializer : public BlobDeserializerBase { - public: - void Deserialize(const BlobProto& proto, Blob* blob) override; - void Deserialize(const TensorProto& proto, Tensor* tensor); -}; - -//////////////////////////////////////////////////////////////////////////////// -// Implementations -//////////////////////////////////////////////////////////////////////////////// - -namespace detail { -template -inline void CopyToProtoAsIs( - const size_t size, - const SrcType* src, - google::protobuf::RepeatedField* field, - Context* context) { - static_assert( - sizeof(SrcType) == sizeof(DstType), - "The source type and dest type cannot be copied as-is. Did " - "you mean CopyToProtoWithCast?"); - field->Reserve(size); - for (int i = 0; i < size; ++i) { - field->Add(0); - } - context->template Copy( - size, src, reinterpret_cast(field->mutable_data())); - // Make sure that we finish the copy into the protobuf. - context->FinishDeviceComputation(); -} - -template -inline void CopyToProtoWithCast( - const size_t size, - const SrcType* src, - google::protobuf::RepeatedField* field, - Context* context) { - // TODO: we are having one unnecessary copy here if the context is already - // CPUContext. Remove it if it is performance critical. - unique_ptr buffer(new SrcType[size]); - context->template Copy( - size, src, buffer.get()); - context->FinishDeviceComputation(); - field->Reserve(size); - for (int i = 0; i < size; ++i) { - field->Add(static_cast(buffer[i])); - } -} - -template -inline void CopyFromProtoAsIs( - const size_t size, - const google::protobuf::RepeatedField& field, - DstType* dst, - Context* context) { - static_assert( - sizeof(SrcType) == sizeof(DstType), - "The source type and dest type cannot be copied as-is. Did " - "you mean CopyFromProtoWithCast?"); - CAFFE_ENFORCE_EQ(size, field.size(), "Incorrect proto field size."); - context->template Copy( - size, reinterpret_cast(field.data()), dst); -} - -template -inline void CopyFromProtoWithCast( - const size_t size, - const google::protobuf::RepeatedField& field, - DstType* dst, - Context* context) { - CAFFE_ENFORCE_EQ(size, field.size(), "Incorrect proto field size."); - // TODO: we are having one unnecessary copy here if the context is already - // CPUContext. Remove it if it is performance critical. - unique_ptr buffer(new DstType[size]); - const SrcType* src = field.data(); - for (int i = 0; i < size; ++i) { - buffer[i] = static_cast(src[i]); - } - context->template Copy(size, buffer.get(), dst); -} - -} // namespace detail - -template -void TensorSerializer::Serialize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor) { - this->SerializeWithChunkSize(blob, name, acceptor, kDefaultChunkSize); -} - -template -void TensorSerializer::SerializeWithChunkSize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor, - int chunk_size) { - CAFFE_ENFORCE(blob.IsType>()); - const auto& tensor = blob.template Get>(); - if (chunk_size == kNoChunking) { - chunk_size = tensor.size() + 1; // to account for empty tensors - } else if (chunk_size == kDefaultChunkSize) { - chunk_size = FLAGS_caffe2_tensor_chunk_size; - } - - auto processChunk = [&](int64_t chunkStart) { - BlobProto blob_proto; - blob_proto.set_name(name); - blob_proto.set_type(kTensorBlobType); - TensorProto& proto = *blob_proto.mutable_tensor(); - proto.set_name(name); - this->Serialize( - tensor, name, blob_proto.mutable_tensor(), chunkStart, chunk_size); - acceptor( - MakeString(name, kChunkIdSeparator, chunkStart / chunk_size), - blob_proto.SerializeAsString()); - }; - -#ifndef __ANDROID__ - std::vector> futures; - // Poorman's IOBound ThreadPool - SimpleQueue chunkQueue; - auto task = [&]() { - size_t chunkStart; - while (chunkQueue.Pop(&chunkStart)) { - processChunk(chunkStart); - } - }; - if (tensor.size() > chunk_size) { - for (int i = 0; i < FLAGS_caffe2_max_tensor_serializer_threads; ++i) { - futures.emplace_back(std::async(std::launch::async, task)); - } - } -#endif - - VLOG(1) << "Serializing blob " << name; - // Serialize whole vector. If vector is empty, it's shape still needs to be - // serialized in empty proto - for (size_t chunkBegin = 0; - chunkBegin < std::max(tensor.size(), static_cast(1)); - chunkBegin += chunk_size) { - VLOG(2) << "Starting a chunk at " << chunkBegin; -#ifndef __ANDROID__ - if (tensor.size() > chunk_size) { - chunkQueue.Push(chunkBegin); - } else { - // Sync mode for small tensors - processChunk(chunkBegin); - } -#else - // Since Android does not have std::future, we will always do sync mode - processChunk(chunkBegin); -#endif - } - -#ifndef __ANDROID__ - chunkQueue.NoMoreJobs(); - for (auto& fut : futures) { - fut.get(); - } -#endif -} - -template -void TensorSerializer::Serialize( - const Tensor& input, - const string& /*name*/, - TensorProto* proto_ptr, - size_t chunkBegin, - int32_t chunkSize) { - CAFFE_ENFORCE( - chunkBegin <= input.size(), - "Chunk begin is out of tensor: ", - chunkBegin, - ' ', - input.size()); - if (chunkBegin + chunkSize > input.size()) { - chunkSize = input.size() - chunkBegin; - } - - CAFFE_ENFORCE( - input.raw_data() || chunkSize == 0, - "The input does not have data input yet. This is probably because you " - "created a tensor of non-zero shape but never filled its data via " - "mutable_data() calls. This means that it makes no sense to serialize " - "the tensor content."); - - TensorProto& proto = *proto_ptr; - proto.mutable_segment()->set_begin(chunkBegin); - proto.mutable_segment()->set_end(chunkBegin + chunkSize); - - for (int i = 0; i < input.ndim(); ++i) { - proto.add_dims(input.dim(i)); - } - const TensorProto::DataType data_type = TypeMetaToDataType(input.meta()); - proto.set_data_type(data_type); - StoreDeviceDetail(input, &proto); - - // A lot of copypaste is error prone. Should we create a macro for this? - switch (data_type) { - case TensorProto_DataType_FLOAT: - detail::CopyToProtoAsIs( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_float_data(), - &this->context_); - break; - case TensorProto_DataType_INT32: - detail::CopyToProtoAsIs( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_BYTE: - LOG(FATAL) << "This should not happen. When serializing, " - "BYTE is deprecated and moved to UINT8."; - break; - case TensorProto_DataType_STRING: - { - proto.mutable_string_data()->Reserve(chunkSize); - const string* content = input.template data(); - for (int i = chunkBegin; i < chunkBegin + chunkSize; ++i) { - proto.add_string_data(content[i]); - } - break; - } - case TensorProto_DataType_BOOL: - detail::CopyToProtoWithCast( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_UINT8: - detail::CopyToProtoWithCast( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_INT8: - detail::CopyToProtoWithCast( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_UINT16: - detail::CopyToProtoWithCast( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_INT16: - detail::CopyToProtoWithCast( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int32_data(), - &this->context_); - break; - case TensorProto_DataType_INT64: - detail::CopyToProtoAsIs( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_int64_data(), - &this->context_); - break; - case TensorProto_DataType_FLOAT16: { - if (FLAGS_caffe2_serialize_fp16_as_bytes) { - const int kValue = 1; - CAFFE_ENFORCE_EQ( - reinterpret_cast(&kValue)[0], - 1, - "Serialization of FLOAT16 on big endian platform " - "is not written yet."); - unique_ptr buffer(new char[2 * chunkSize]); - this->context_.template Copy( - 2 * chunkSize, - reinterpret_cast( - input.template data() + chunkBegin), - buffer.get()); - this->context_.FinishDeviceComputation(); - proto.set_byte_data(buffer.release(), 2 * chunkSize); - } else { - detail::CopyToProtoWithCast( - chunkSize, - reinterpret_cast(input.template data()) + - chunkBegin, - proto.mutable_int32_data(), - &this->context_); - } - } break; - case TensorProto_DataType_DOUBLE: - detail::CopyToProtoAsIs( - chunkSize, - input.template data() + chunkBegin, - proto.mutable_double_data(), - &this->context_); - break; - case TensorProto_DataType_UNDEFINED: - LOG(FATAL) << "TensorSerializer does not have a serialization " - "implementation for " << input.meta().name(); - break; - // Note: we intentially do not provide "default:" so if any new data types - // are added, the compiler should warn the user to add the case here. - } -} - -template -void TensorDeserializer::Deserialize( - const BlobProto& blob_proto, - Blob* blob) { - Deserialize(blob_proto.tensor(), blob->GetMutable>()); -} - -template -void TensorDeserializer::Deserialize( - const TensorProto& proto, - Tensor* tensor) { - // We create a local context for deserializing. Since Caffe2 contexts are - // usually lightweighted, this should not involve too much overhead. - Context context(proto.device_detail()); - context.SwitchToDevice(0); - vector dims; - for (const TIndex d : proto.dims()) { - dims.push_back(d); - } - tensor->Resize(dims); - - int64_t chunkBegin = 0; - auto chunkEnd = tensor->size(); - if (proto.has_segment()) { - chunkBegin = proto.segment().begin(); - chunkEnd = proto.segment().end(); - } - CAFFE_ENFORCE( - 0 <= chunkBegin && chunkBegin <= chunkEnd && chunkEnd <= tensor->size(), - "Invalid chunk ", - chunkBegin, - ' ', - chunkEnd, - " with total tensor size ", - tensor->size()); - auto chunkSize = chunkEnd - chunkBegin; - - switch (proto.data_type()) { - case TensorProto_DataType_FLOAT: - detail::CopyFromProtoAsIs( - chunkSize, - proto.float_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_INT32: - detail::CopyFromProtoAsIs( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_BYTE: - // Since BYTE stores the data in a string field instead of a repreated - // field we will have it special cased. - CAFFE_ENFORCE_EQ( - chunkSize, proto.byte_data().size(), "Incorrect proto field size."); - context.template Copy( - chunkSize, - reinterpret_cast(proto.byte_data().data()), - tensor->template mutable_data() + chunkBegin); - break; - case TensorProto_DataType_STRING: - // Special handing of string because it is a non-fundamental type. - { - string* content = tensor->template mutable_data(); - for (int i = 0; i < chunkSize; ++i) { - content[i + chunkBegin] = proto.string_data(i); - } - } - break; - case TensorProto_DataType_BOOL: - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_UINT8: - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_INT8: - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_UINT16: - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_INT16: - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_INT64: - detail::CopyFromProtoAsIs( - chunkSize, - proto.int64_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_FLOAT16: - if (proto.has_byte_data()) { - const int kValue = 1; - CAFFE_ENFORCE_EQ( - reinterpret_cast(&kValue)[0], - 1, - "Serialization of FLOAT16 on big endian platform " - "is not written yet."); - CAFFE_ENFORCE_EQ( - 2 * chunkSize, - proto.byte_data().size(), - "Incorrect proto field size."); - context.template Copy( - chunkSize, - reinterpret_cast(proto.byte_data().data()), - tensor->template mutable_data() + chunkBegin); - } else { - // Backward compatibility with models which used int32_data field - detail::CopyFromProtoWithCast( - chunkSize, - proto.int32_data(), - reinterpret_cast( - tensor->template mutable_data()) + - chunkBegin, - &context); - } - break; - case TensorProto_DataType_DOUBLE: - detail::CopyFromProtoAsIs( - chunkSize, - proto.double_data(), - tensor->template mutable_data() + chunkBegin, - &context); - break; - case TensorProto_DataType_UNDEFINED: - CAFFE_THROW("Cannot deserialize from a TensorProto UNDEFINED data type."); - } - context.FinishDeviceComputation(); -} - -} // namespace caffe2 - -#endif // CAFFE2_CORE_BLOB_SERIALIZATION_H_ diff --git a/app/src/main/cpp/caffe2/core/blob_serializer_base.h b/app/src/main/cpp/caffe2/core/blob_serializer_base.h deleted file mode 100644 index 4bf4724..0000000 --- a/app/src/main/cpp/caffe2/core/blob_serializer_base.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include -#include - -namespace caffe2 { - -class Blob; - -constexpr int kDefaultChunkSize = -1; -constexpr int kNoChunking = 0; - -/** - * @brief BlobSerializerBase is an abstract class that serializes a blob to a - * string. - * - * This class exists purely for the purpose of registering type-specific - * serialization code. If you need to serialize a specific type, you should - * write your own Serializer class, and then register it using - * REGISTER_BLOB_SERIALIZER. For a detailed example, see TensorSerializer for - * details. - */ -class BlobSerializerBase { - public: - virtual ~BlobSerializerBase() {} - using SerializationAcceptor = - std::function; - /** - * @brief The virtual function that returns a serialized string for the input - * blob. - * @param blob - * the input blob to be serialized. - * @param name - * the blob name to be used in the serialization implementation. It is up - * to the implementation whether this name field is going to be used or - * not. - * @param acceptor - * a lambda which accepts key value pairs to save them to storage. - * serailizer can use it to save blob in several chunks - * acceptor should be thread-safe - */ - virtual void Serialize(const Blob& blob, const std::string& name, - SerializationAcceptor acceptor) = 0; - - virtual void SerializeWithChunkSize( - const Blob& blob, - const std::string& name, - SerializationAcceptor acceptor, - int /*chunk_size*/) { - // Base implementation. - Serialize(blob, name, acceptor); - } -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/core/blob_stats.h b/app/src/main/cpp/caffe2/core/blob_stats.h deleted file mode 100644 index f4ef21d..0000000 --- a/app/src/main/cpp/caffe2/core/blob_stats.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include "caffe2/core/blob.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/typeid.h" - -#include - -namespace caffe2 { - -struct BlobStatGetter { - virtual size_t sizeBytes(const Blob& blob) const = 0; - virtual ~BlobStatGetter() {} -}; - -struct BlobStatRegistry { - private: - std::unordered_map> map_; - void doRegister(CaffeTypeId id, std::unique_ptr&& v); - - public: - template - struct Registrar { - Registrar() { - BlobStatRegistry::instance().doRegister( - TypeMeta::Id(), std::unique_ptr(new Getter)); - } - }; - - const BlobStatGetter* get(CaffeTypeId id); - static BlobStatRegistry& instance(); -}; - -#define REGISTER_BLOB_STAT_GETTER(Type, BlobStatGetterClass) \ - static BlobStatRegistry::Registrar \ - CAFFE_ANONYMOUS_VARIABLE(BlobStatRegistry) - -namespace BlobStat { - -/** - * Return size in bytes of the blob, if available for a blob of given type. - * If not available, return 0. - */ -size_t sizeBytes(const Blob& blob); -} -} diff --git a/app/src/main/cpp/caffe2/core/common.h b/app/src/main/cpp/caffe2/core/common.h deleted file mode 100644 index 6163cc3..0000000 --- a/app/src/main/cpp/caffe2/core/common.h +++ /dev/null @@ -1,227 +0,0 @@ -#ifndef CAFFE2_CORE_COMMON_H_ -#define CAFFE2_CORE_COMMON_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __APPLE__ -#include -#endif - -#if defined(_MSC_VER) -#include -#else -#include -#endif - -// Macros used during the build of this caffe2 instance. This header file -// is automatically generated by the cmake script during build. -#include "caffe2/core/macros.h" - -namespace caffe2 { - -// Data type for caffe2 Index/Size. We use size_t to be safe here as well as for -// large matrices that are common in sparse math. -typedef int64_t TIndex; - -// Note(Yangqing): NVCC does not play well with unordered_map on some platforms, -// forcing us to use std::map instead of unordered_map. This may affect speed -// in some cases, but in most of the computation code we do not access map very -// often, so it should be fine for us. I am putting a CaffeMap alias so we can -// change it more easily if things work out for unordered_map down the road. -template -using CaffeMap = std::map; -// using CaffeMap = std::unordered_map; - -// Using statements for common classes that we refer to in caffe2 very often. -// Note that we only place it inside caffe2 so the global namespace is not -// polluted. -/* using override */ -using std::set; -using std::string; -using std::unique_ptr; -using std::vector; - -// Just in order to mark things as not implemented. Do not use in final code. -#define CAFFE_NOT_IMPLEMENTED CAFFE_THROW("Not Implemented.") - -// suppress an unused variable. -#ifdef _MSC_VER -#define CAFFE2_UNUSED -#define CAFFE2_USED -#else -#define CAFFE2_UNUSED __attribute__((__unused__)) -#define CAFFE2_USED __attribute__((__used__)) -#endif //_MSC_VER - -// Disable the copy and assignment operator for a class. Note that this will -// disable the usage of the class in std containers. -#ifndef DISABLE_COPY_AND_ASSIGN -#define DISABLE_COPY_AND_ASSIGN(classname) \ -private: \ - classname(const classname&) = delete; \ - classname& operator=(const classname&) = delete -#endif - -// Define enabled when building for iOS or Android devices -#if !defined(CAFFE2_MOBILE) -#if defined(__ANDROID__) -#define CAFFE2_ANDROID 1 -#define CAFFE2_MOBILE 1 -#elif (defined(__APPLE__) && \ - (TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE)) -#define CAFFE2_IOS 1 -#define CAFFE2_MOBILE 1 -#elif (defined(__APPLE__) && TARGET_OS_MAC) -#define CAFFE2_IOS 1 -#define CAFFE2_MOBILE 0 -#else -#define CAFFE2_MOBILE 0 -#endif // ANDROID / IOS / MACOS -#endif // CAFFE2_MOBILE - -// Define alignment macro that is cross platform -#if defined(_MSC_VER) -#define CAFFE2_ALIGNED(x) __declspec(align(x)) -#else -#define CAFFE2_ALIGNED(x) __attribute__((aligned(x))) -#endif - -/** - * Macro for marking functions as having public visibility. - * Ported from folly/CPortability.h - */ -#ifndef __GNUC_PREREQ -#if defined __GNUC__ && defined __GNUC_MINOR__ -#define __GNUC_PREREQ(maj, min) \ - ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else -#define __GNUC_PREREQ(maj, min) 0 -#endif -#endif - -#if defined(__GNUC__) -#if __GNUC_PREREQ(4, 9) -#define CAFFE2_EXPORT [[gnu::visibility("default")]] -#else -#define CAFFE2_EXPORT __attribute__((__visibility__("default"))) -#endif -#else -#define CAFFE2_EXPORT -#endif - -// make_unique is a C++14 feature. If we don't have 14, we will emulate -// its behavior. This is copied from folly/Memory.h -#if __cplusplus >= 201402L || \ - (defined __cpp_lib_make_unique && __cpp_lib_make_unique >= 201304L) || \ - (defined(_MSC_VER) && _MSC_VER >= 1900) -/* using override */ -using std::make_unique; -#else - -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -// Allows 'make_unique(10)'. (N3690 s20.9.1.4 p3-4) -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(const size_t n) { - return std::unique_ptr(new typename std::remove_extent::type[n]()); -} - -// Disallows 'make_unique()'. (N3690 s20.9.1.4 p5) -template -typename std::enable_if< - std::extent::value != 0, std::unique_ptr>::type -make_unique(Args&&...) = delete; - -#endif - -// to_string implementation for Android related stuff. -#ifndef __ANDROID__ -using std::to_string; -using std::stoi; -#else -template -std::string to_string(T value) -{ - std::ostringstream os; - os << value; - return os.str(); -} - -inline int stoi(const string& str) -{ - std::stringstream ss; - int n = 0; - ss << str; - ss >> n; - return n; -} -#endif - -// dynamic cast reroute: if RTTI is disabled, go to reinterpret_cast -template -inline Dst dynamic_cast_if_rtti(Src ptr) { -#ifdef __GXX_RTTI - return dynamic_cast(ptr); -#else - return reinterpret_cast(ptr); -#endif -} - -// SkipIndices are used in operator_fallback_gpu.h and operator_fallback_mkl.h -// as utilty functions that marks input / output indices to skip when we use a -// CPU operator as the fallback of GPU/MKL operator option. -template -class SkipIndices { - private: - template - static inline bool ContainsInternal(const int i) { - return (i == V); - } - template - static inline bool ContainsInternal(const int i) { - return (i == First) && ContainsInternal(i); - } - - public: - static inline bool Contains(const int i) { - return ContainsInternal(i); - } -}; - -template <> -class SkipIndices<> { - public: - static inline bool Contains(const int /*i*/) { - return false; - } -}; - -// A global variable to mark if Caffe2 has cuda linked to the current runtime. -// Do not directly use this variable, but instead use the HasCudaRuntime() -// function below. -extern bool g_caffe2_has_cuda_linked; - -// HasCudaRuntime() tells the program whether the binary has Cuda runtime -// linked. This function should not be used in static initialization functions -// as the underlying boolean variable is going to be switched on when one -// loads libcaffe2_gpu.so. -inline bool HasCudaRuntime() { - return g_caffe2_has_cuda_linked; -} - -} // namespace caffe2 - -#endif // CAFFE2_CORE_COMMON_H_ diff --git a/app/src/main/cpp/caffe2/core/common_cudnn.h b/app/src/main/cpp/caffe2/core/common_cudnn.h deleted file mode 100644 index 4388701..0000000 --- a/app/src/main/cpp/caffe2/core/common_cudnn.h +++ /dev/null @@ -1,469 +0,0 @@ -#ifndef CAFFE2_CORE_COMMON_CUDNN_H_ -#define CAFFE2_CORE_COMMON_CUDNN_H_ - -#include -#include - -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/common_gpu.h" -#include "caffe2/core/context.h" -#include "caffe2/core/context_gpu.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/types.h" -#include "caffe2/proto/caffe2.pb.h" - -static_assert( - CUDNN_VERSION >= 5000, - "Caffe2 requires cudnn version 5.0 or above."); - -#define CUDNN_VERSION_MIN(major, minor, patch) \ - (CUDNN_VERSION >= ((major) * 1000 + (minor) * 100 + (patch))) - -namespace caffe2 { - -namespace internal { -/** - * A helper function to obtain cudnn error strings. - */ -inline const char* cudnnGetErrorString(cudnnStatus_t status) { - switch (status) { - case CUDNN_STATUS_SUCCESS: - return "CUDNN_STATUS_SUCCESS"; - case CUDNN_STATUS_NOT_INITIALIZED: - return "CUDNN_STATUS_NOT_INITIALIZED"; - case CUDNN_STATUS_ALLOC_FAILED: - return "CUDNN_STATUS_ALLOC_FAILED"; - case CUDNN_STATUS_BAD_PARAM: - return "CUDNN_STATUS_BAD_PARAM"; - case CUDNN_STATUS_INTERNAL_ERROR: - return "CUDNN_STATUS_INTERNAL_ERROR"; - case CUDNN_STATUS_INVALID_VALUE: - return "CUDNN_STATUS_INVALID_VALUE"; - case CUDNN_STATUS_ARCH_MISMATCH: - return "CUDNN_STATUS_ARCH_MISMATCH"; - case CUDNN_STATUS_MAPPING_ERROR: - return "CUDNN_STATUS_MAPPING_ERROR"; - case CUDNN_STATUS_EXECUTION_FAILED: - return "CUDNN_STATUS_EXECUTION_FAILED"; - case CUDNN_STATUS_NOT_SUPPORTED: - return "CUDNN_STATUS_NOT_SUPPORTED"; - case CUDNN_STATUS_LICENSE_ERROR: - return "CUDNN_STATUS_LICENSE_ERROR"; - default: - return "Unknown cudnn error number"; - } -} -} // namespace internal - -// A macro that wraps around a cudnn statement so we can check if the cudnn -// execution finishes or not. -#define CUDNN_ENFORCE(condition) \ - do { \ - cudnnStatus_t status = condition; \ - CAFFE_ENFORCE_EQ( \ - status, \ - CUDNN_STATUS_SUCCESS, \ - ", Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - ::caffe2::internal::cudnnGetErrorString(status)); \ - } while (0) -#define CUDNN_CHECK(condition) \ - do { \ - cudnnStatus_t status = condition; \ - CHECK(status == CUDNN_STATUS_SUCCESS) \ - << ::caffe2::internal::cudnnGetErrorString(status); \ - } while (0) - -// report the version of cuDNN Caffe2 was compiled with -inline size_t cudnnCompiledVersion() { - return CUDNN_VERSION; -} -// report the runtime version of cuDNN -inline size_t cudnnRuntimeVersion() { - return cudnnGetVersion(); -} - -// Check compatibility of compiled and runtime cuDNN versions -inline void CheckCuDNNVersions() { - // Version format is major*1000 + minor*100 + patch - // Major, minor and patch versions must all match - bool version_match = cudnnCompiledVersion() == cudnnRuntimeVersion(); - CAFFE_ENFORCE(version_match, - "cuDNN compiled (", cudnnCompiledVersion(), ") and " - "runtime (", cudnnRuntimeVersion(), ") versions mismatch"); -} - -/** - * cudnnTypeWrapper is a wrapper class that allows us to refer to the cudnn type - * in a template function. The class is specialized explicitly for different - * data types below. - */ -template -class cudnnTypeWrapper; - -template <> -class cudnnTypeWrapper { - public: - static const cudnnDataType_t type = CUDNN_DATA_FLOAT; - typedef const float ScalingParamType; - typedef float BNParamType; - static ScalingParamType* kOne() { - static ScalingParamType v = 1.0; - return &v; - } - static const ScalingParamType* kZero() { - static ScalingParamType v = 0.0; - return &v; - } -}; - -template <> -class cudnnTypeWrapper { - public: - static const cudnnDataType_t type = CUDNN_DATA_DOUBLE; - typedef const double ScalingParamType; - typedef double BNParamType; - static ScalingParamType* kOne() { - static ScalingParamType v = 1.0; - return &v; - } - static ScalingParamType* kZero() { - static ScalingParamType v = 0.0; - return &v; - } -}; - -template <> -class cudnnTypeWrapper { - public: - static const cudnnDataType_t type = CUDNN_DATA_HALF; - typedef const float ScalingParamType; - typedef float BNParamType; - static ScalingParamType* kOne() { - static ScalingParamType v = 1.0; - return &v; - } - static ScalingParamType* kZero() { - static ScalingParamType v = 0.0; - return &v; - } -}; - -/** - * A wrapper function to convert the Caffe storage order to cudnn storage order - * enum values. - */ -inline cudnnTensorFormat_t GetCudnnTensorFormat(const StorageOrder& order) { - switch (order) { - case StorageOrder::NHWC: - return CUDNN_TENSOR_NHWC; - case StorageOrder::NCHW: - return CUDNN_TENSOR_NCHW; - default: - LOG(FATAL) << "Unknown cudnn equivalent for order: " << order; - } - // Just to suppress compiler warnings - return CUDNN_TENSOR_NCHW; -} - -/** - * cudnnTensorDescWrapper is the placeholder that wraps around a - * cudnnTensorDescriptor_t, allowing us to do descriptor change as-needed during - * runtime. - */ -class cudnnTensorDescWrapper { - public: - cudnnTensorDescWrapper() { - CUDNN_ENFORCE(cudnnCreateTensorDescriptor(&desc_)); - } - ~cudnnTensorDescWrapper() noexcept { - CUDNN_CHECK(cudnnDestroyTensorDescriptor(desc_)); - } - - inline cudnnTensorDescriptor_t Descriptor( - const cudnnTensorFormat_t format, - const cudnnDataType_t type, - const vector& dims, - bool* changed) { - if (type_ == type && format_ == format && dims_ == dims) { - // if not changed, simply return the current descriptor. - if (changed) - *changed = false; - return desc_; - } - CAFFE_ENFORCE_EQ( - dims.size(), 4, "Currently only 4-dimensional descriptor supported."); - format_ = format; - type_ = type; - dims_ = dims; - CUDNN_ENFORCE(cudnnSetTensor4dDescriptor( - desc_, - format, - type, - dims_[0], - (format == CUDNN_TENSOR_NCHW ? dims_[1] : dims_[3]), - (format == CUDNN_TENSOR_NCHW ? dims_[2] : dims_[1]), - (format == CUDNN_TENSOR_NCHW ? dims_[3] : dims_[2]))); - if (changed) - *changed = true; - return desc_; - } - - template - inline cudnnTensorDescriptor_t Descriptor( - const StorageOrder& order, - const vector& dims) { - return Descriptor( - GetCudnnTensorFormat(order), cudnnTypeWrapper::type, dims, nullptr); - } - - private: - cudnnTensorDescriptor_t desc_; - cudnnTensorFormat_t format_; - cudnnDataType_t type_; - vector dims_; - DISABLE_COPY_AND_ASSIGN(cudnnTensorDescWrapper); -}; - -class cudnnFilterDescWrapper { - public: - cudnnFilterDescWrapper() { - CUDNN_ENFORCE(cudnnCreateFilterDescriptor(&desc_)); - } - ~cudnnFilterDescWrapper() noexcept { - CUDNN_CHECK(cudnnDestroyFilterDescriptor(desc_)); - } - - inline cudnnFilterDescriptor_t Descriptor( - const StorageOrder& order, - const cudnnDataType_t type, - const vector& dims, - bool* changed) { - if (type_ == type && order_ == order && dims_ == dims) { - // if not changed, simply return the current descriptor. - if (changed) - *changed = false; - return desc_; - } - CAFFE_ENFORCE_EQ( - dims.size(), 4, "Currently only 4-dimensional descriptor supported."); - order_ = order; - type_ = type; - dims_ = dims; - CUDNN_ENFORCE(cudnnSetFilter4dDescriptor( - desc_, - type, - GetCudnnTensorFormat(order), - dims_[0], - // TODO - confirm that this is correct for NHWC - (order == StorageOrder::NCHW ? dims_[1] : dims_[3]), - (order == StorageOrder::NCHW ? dims_[2] : dims_[1]), - (order == StorageOrder::NCHW ? dims_[3] : dims_[2]))); - if (changed) - *changed = true; - return desc_; - } - - template - inline cudnnFilterDescriptor_t Descriptor( - const StorageOrder& order, - const vector& dims) { - return Descriptor(order, cudnnTypeWrapper::type, dims, nullptr); - } - - private: - cudnnFilterDescriptor_t desc_; - StorageOrder order_; - cudnnDataType_t type_; - vector dims_; - DISABLE_COPY_AND_ASSIGN(cudnnFilterDescWrapper); -}; - -class CuDNNWrapper; -/** - * CuDNNHandles wraps around cudnnHandle_t so they can be - * properly destructed when threads exit. - */ -class CuDNNHandles { - friend class CuDNNWrapper; - - private: - CuDNNHandles() { - for (int i = 0; i < CAFFE2_COMPILE_TIME_MAX_GPUS; ++i) { - cudnn_handle_[i] = nullptr; - } - } - - ~CuDNNHandles() noexcept { - for (int i = 0; i < CAFFE2_COMPILE_TIME_MAX_GPUS; ++i) { - if (cudnn_handle_[i]) { - CUDNN_CHECK(cudnnDestroy(cudnn_handle_[i])); - } - } - } - - cudnnHandle_t cudnn_handle_[CAFFE2_COMPILE_TIME_MAX_GPUS]; -}; - -/** - * CuDNNWorkspace is a wrapper around a raw cuda pointer that holds the cudnn - * scratch space. This struct is meant to be only used in CuDNNWrapper to - * provide a program-wide scratch space for CuDNN. The reason behind it is that - * cudnn function calls are usually very efficient, hence one probably does not - * want to run multiple cudnn calls at the same time. As a result, one should - * not need more than one cudnn workspace per device. - */ -struct CuDNNWorkspace { - ~CuDNNWorkspace() noexcept {} - - void* get(size_t nbytes) { - if (nbytes_ < nbytes) { - reset(); - auto data_and_deleter = CUDAContext::New(nbytes); - data_ = {data_and_deleter.first, data_and_deleter.second}; - nbytes_ = nbytes; - } - CAFFE_ENFORCE_GE(nbytes_, nbytes); - return data_.get(); - } - - void reset() { - data_ = nullptr; - nbytes_ = 0; - } - - private: - std::unique_ptr data_{nullptr, NoDelete}; - size_t nbytes_{0}; -}; - -// CuDNNState is the owner of the CuDNNWorkspace, and serializes all -// executions of operations that use the state onto it's own stream -// (so multiple Net workers can reuse the same workspace from -// different threads and CUDA streams). -class CuDNNState { - public: - explicit CuDNNState(size_t gpu_id) : gpu_id_(gpu_id) { - DeviceGuard g(gpu_id_); - CUDNN_ENFORCE(cudnnCreate(&cudnn_handle_)); - CUDA_ENFORCE(cudaEventCreate(&before_)); - CUDA_ENFORCE(cudaEventCreate(&after_)); - CUDA_ENFORCE(cudaStreamCreate(&stream_)); - CUDNN_ENFORCE(cudnnSetStream(cudnn_handle_, stream_)); - } - - ~CuDNNState() noexcept { - DeviceGuard g(gpu_id_); - CUDNN_CHECK(cudnnDestroy(cudnn_handle_)); - CUDA_CHECK(cudaStreamDestroy(stream_)); - CUDA_CHECK(cudaEventDestroy(after_)); - CUDA_CHECK(cudaEventDestroy(before_)); - } - - cudnnHandle_t& cudnn_handle() { - return cudnn_handle_; - } - - CuDNNWorkspace& workspace() { - return workspace_; - } - - template - void execute(cudaStream_t stream, F&& f) { - CUDA_ENFORCE(cudaEventRecord(before_, stream)); - CUDA_ENFORCE(cudaStreamWaitEvent(stream_, before_, 0)); - f(this); - CUDA_ENFORCE(cudaEventRecord(after_, stream_)); - CUDA_ENFORCE(cudaStreamWaitEvent(stream, after_, 0)); - } - - private: - cudnnHandle_t cudnn_handle_{nullptr}; - cudaEvent_t before_{nullptr}; - cudaEvent_t after_{nullptr}; - cudaStream_t stream_{nullptr}; - CuDNNWorkspace workspace_; - size_t gpu_id_{0}; - DISABLE_COPY_AND_ASSIGN(CuDNNState); -}; - -/** - * CuDNNWrapper is a class that wraps the cudnn handles and cudnn workspaces. - * - * The wrapper ensures that for each thread and each gpu, there is one - * identical cudnn handle, which is also associated with the thread-local - * per-device cuda stream. The wrapper also hosts the device-specific cudnn - * workspace (scratch space for some cudnn functions). - * - */ -class CuDNNWrapper { - public: - /** - * Creates a cudnn wrapper associated with a CUDAContext object. Note that - * the CUDAContext object should outlive the CuDNNWrapper. - */ - explicit CuDNNWrapper(CUDAContext* context) : context_(context) {} - - /** - * Returns the inline cudnn handle that executes on the current - * thread's cuda_stream. - */ - cudnnHandle_t& inline_cudnn_handle() { - int gpu_id = context_->cuda_gpu_id(); - auto& cudnn_handle_ = tls_cudnn_handles_.cudnn_handle_[gpu_id]; - if (!cudnn_handle_) { - context_->SwitchToDevice(); - CUDNN_ENFORCE(cudnnCreate(&cudnn_handle_)); - } - CUDNN_ENFORCE(cudnnSetStream(cudnn_handle_, context_->cuda_stream())); - return cudnn_handle_; - } - - // Executes the closure F on the CuDNNState associated with state_idx - template - void with_cudnn_state(size_t state_idx, F&& f) { - CAFFE_ENFORCE( - state_idx < CAFFE2_COMPILE_TIME_MAX_CUDNN_STATES, "Invalid state_idx"); - auto& sync_state = cudnn_states()[context_->cuda_gpu_id()][state_idx]; - - DeviceGuard dg(context_->cuda_gpu_id()); - - // We need to serialize execution on the CuDNNState as we can't - // allow multiple threads to race through the cudaEventRecord - // calls (so a worker thread might wait on another worker thread's - // execution) - std::lock_guard g(sync_state.mutex); - if (!sync_state.state.get()) { - sync_state.state.reset(new CuDNNState(context_->cuda_gpu_id())); - } - CHECK_NOTNULL(sync_state.state.get())->execute(context_->cuda_stream(), f); - } - - protected: - // Pointer to an external cuda context that the cudnn wrapper will use. - CUDAContext* context_; - static thread_local CuDNNHandles tls_cudnn_handles_; - - static constexpr size_t CAFFE2_COMPILE_TIME_MAX_CUDNN_STATES = 4; - - struct SyncedCuDNNState { - std::mutex mutex; - std::unique_ptr state; - }; - - using PerGPUCuDNNStates = std::array< - std::array, - CAFFE2_COMPILE_TIME_MAX_GPUS>; - static PerGPUCuDNNStates& cudnn_states(); - - DISABLE_COPY_AND_ASSIGN(CuDNNWrapper); -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_COMMON_CUDNN_H_ diff --git a/app/src/main/cpp/caffe2/core/common_gpu.h b/app/src/main/cpp/caffe2/core/common_gpu.h deleted file mode 100644 index 35c77b2..0000000 --- a/app/src/main/cpp/caffe2/core/common_gpu.h +++ /dev/null @@ -1,306 +0,0 @@ -#ifndef CAFFE2_CORE_COMMON_GPU_H_ -#define CAFFE2_CORE_COMMON_GPU_H_ - -#include -#include -#include - -// Disable strict aliasing errors for CUDA 9. -// The cuda_fp16.h header in CUDA 9 RC triggers this diagnostic. -// It is included by cusparse.h as well, so guarding the -// inclusion of that header here is not enough. -#if CUDA_VERSION >= 9000 -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -#endif // CUDA_VERSION >= 9000 - -#include -#include -#include - -#include "caffe2/core/logging.h" -#include "caffe2/core/common.h" - -// This is a macro defined for cuda fp16 support. In default, cuda fp16 is -// supported by NVCC 7.5, but it is also included in the Tegra X1 platform with -// a (custom?) NVCC 7.0. As a result, we would normally just check the cuda -// version here, but would also allow a use to pass in the flag -// CAFFE_HAS_CUDA_FP16 manually. - -#ifndef CAFFE_HAS_CUDA_FP16 -#if CUDA_VERSION >= 7050 -#define CAFFE_HAS_CUDA_FP16 -#endif // CUDA_VERSION >= 7050 -#endif // CAFFE_HAS_CUDA_FP16 - -#ifdef CAFFE_HAS_CUDA_FP16 -#include -#endif - -// Re-enable strict aliasing diagnostic if it was disabled. -#if CUDA_VERSION >= 9000 -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif // __GNUC__ -#endif // CUDA_VERSION >= 9000 - -/** - * The maximum number of GPUs that caffe2 recognizes. - */ -#define CAFFE2_COMPILE_TIME_MAX_GPUS 16 -/** - * The maximum number of peers that each gpu can have when doing p2p setup. - * Currently, according to NVidia documentation, each device can support a - * system-wide maximum of eight peer connections. - * When Caffe2 sets up peer access resources, if we have more than 8 gpus, - * we will enable peer access in groups of 8. - */ -#define CAFFE2_CUDA_MAX_PEER_SIZE 8 - -namespace caffe2 { - -#if CUDA_VERSION >= 9000 -/** - * Empty class to identify TensorCore-based math - */ -class TensorCoreEngine {}; -#endif - -/** - * A runtime function to report the cuda version that Caffe2 is built with. - */ -inline int CudaVersion() { return CUDA_VERSION; } - -/** - * Returns the number of devices. - */ -int NumCudaDevices(); - -/** - * Check if the current running session has a cuda gpu present. - * - * Note that this is different from having caffe2 built with cuda. Building - * Caffe2 with cuda only guarantees that this function exists. If there are no - * cuda gpus present in the machine, or there are hardware configuration - * problems like an insufficient driver, this function will still return false, - * meaning that there is no usable GPU present. - * - * In the open source build, it is possible that Caffe2's GPU code is - * dynamically loaded, and as a result a library could be only linked to the - * CPU code, but want to test if cuda is later available or not. In this case, - * one should use HasCudaRuntime() from common.h. - */ -inline bool HasCudaGPU() { return NumCudaDevices() > 0; } - -/** - * Sets the default GPU id for Caffe2. - * - * If an operator is set to run on Cuda GPU but no gpu id is given, we will use - * the default gpu id to run the operator. Before this function is explicitly - * called, GPU 0 will be the default GPU id. - */ -void SetDefaultGPUID(const int deviceid); - -/** - * Gets the default GPU id for Caffe2. - */ -int GetDefaultGPUID(); - -/** - * Gets the current GPU id. This is a simple wrapper around cudaGetDevice(). - */ -int CaffeCudaGetDevice(); - -/** - * Gets the current GPU id. This is a simple wrapper around cudaGetDevice(). - */ -void CaffeCudaSetDevice(const int id); - -/** - * Gets the GPU id that the current pointer is located at. - */ -int GetGPUIDForPointer(const void* ptr); - -/** - * Gets the device property for the given device. This function is thread safe. - */ -const cudaDeviceProp& GetDeviceProperty(const int device); - -/** - * Runs a device query function and prints out the results to LOG(INFO). - */ -void DeviceQuery(const int deviceid); - -/** - * Return a peer access pattern by returning a matrix (in the format of a - * nested vector) of boolean values specifying whether peer access is possible. - * - * This function returns false if anything wrong happens during the query of - * the GPU access pattern. - */ -bool GetCudaPeerAccessPattern(vector >* pattern); - -/** - * Return the availability of TensorCores for math - */ -bool TensorCoreAvailable(); - -/** - * Return a human readable cublas error string. - */ -const char* cublasGetErrorString(cublasStatus_t error); - -/** - * Return a human readable curand error string. - */ -const char* curandGetErrorString(curandStatus_t error); - -// CUDA: various checks for different function calls. -#define CUDA_ENFORCE(condition, ...) \ - do { \ - cudaError_t error = condition; \ - CAFFE_ENFORCE_EQ( \ - error, \ - cudaSuccess, \ - "Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - cudaGetErrorString(error), ##__VA_ARGS__); \ - } while (0) -#define CUDA_CHECK(condition) \ - do { \ - cudaError_t error = condition; \ - CHECK(error == cudaSuccess) << cudaGetErrorString(error); \ - } while (0) - -#define CUDA_DRIVERAPI_ENFORCE(condition) \ - do { \ - CUresult result = condition; \ - if (result != CUDA_SUCCESS) { \ - const char* msg; \ - cuGetErrorName(result, &msg); \ - CAFFE_THROW("Error at: ", __FILE__, ":", __LINE__, ": ", msg); \ - } \ - } while (0) -#define CUDA_DRIVERAPI_CHECK(condition) \ - do { \ - CUresult result = condition; \ - if (result != CUDA_SUCCESS) { \ - const char* msg; \ - cuGetErrorName(result, &msg); \ - LOG(FATAL) << "Error at: " << __FILE__ << ":" << __LINE__ << ": " \ - << msg; \ - } \ - } while (0) - -#define CUBLAS_ENFORCE(condition) \ - do { \ - cublasStatus_t status = condition; \ - CAFFE_ENFORCE_EQ( \ - status, \ - CUBLAS_STATUS_SUCCESS, \ - "Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - ::caffe2::cublasGetErrorString(status)); \ - } while (0) -#define CUBLAS_CHECK(condition) \ - do { \ - cublasStatus_t status = condition; \ - CHECK(status == CUBLAS_STATUS_SUCCESS) \ - << ::caffe2::cublasGetErrorString(status); \ - } while (0) - -#define CURAND_ENFORCE(condition) \ - do { \ - curandStatus_t status = condition; \ - CAFFE_ENFORCE_EQ( \ - status, \ - CURAND_STATUS_SUCCESS, \ - "Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - ::caffe2::curandGetErrorString(status)); \ - } while (0) -#define CURAND_CHECK(condition) \ - do { \ - curandStatus_t status = condition; \ - CHECK(status == CURAND_STATUS_SUCCESS) \ - << ::caffe2::curandGetErrorString(status); \ - } while (0) - -#define CUDA_1D_KERNEL_LOOP(i, n) \ - for (int i = blockIdx.x * blockDim.x + threadIdx.x; \ - i < (n); \ - i += blockDim.x * gridDim.x) - -// CUDA_KERNEL_ASSERT is a macro that wraps an assert() call inside cuda -// kernels. This is not supported by Apple platforms so we special case it. -// See http://docs.nvidia.com/cuda/cuda-c-programming-guide/#assertion -#ifdef __APPLE__ -#define CUDA_KERNEL_ASSERT(...) -#else // __APPLE__ -#define CUDA_KERNEL_ASSERT(...) assert(__VA_ARGS__) -#endif // __APPLE__ - -// The following helper functions are here so that you can write a kernel call -// when you are not particularly interested in maxing out the kernels' -// performance. Usually, this will give you a reasonable speed, but if you -// really want to find the best performance, it is advised that you tune the -// size of the blocks and grids more reasonably. -// A legacy note: this is derived from the old good Caffe days, when I simply -// hard-coded the number of threads and wanted to keep backward compatibility -// for different computation capabilities. -// For more info on CUDA compute capabilities, visit the NVidia website at: -// http://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#compute-capabilities - -// The number of cuda threads to use. 512 is used for backward compatibility, -// and it is observed that setting it to 1024 usually does not bring much -// performance gain (which makes sense, because warp size being 32 means that -// blindly setting a huge block for a random kernel isn't optimal). -constexpr int CAFFE_CUDA_NUM_THREADS = 512; -// The maximum number of blocks to use in the default kernel call. We set it to -// 4096 which would work for compute capability 2.x (where 65536 is the limit). -// This number is very carelessly chosen. Ideally, one would like to look at -// the hardware at runtime, and pick the number of blocks that makes most -// sense for the specific runtime environment. This is a todo item. -constexpr int CAFFE_MAXIMUM_NUM_BLOCKS = 4096; - -/** - * @brief Compute the number of blocks needed to run N threads. - */ -inline int CAFFE_GET_BLOCKS(const int N) { - return std::min((N + CAFFE_CUDA_NUM_THREADS - 1) / CAFFE_CUDA_NUM_THREADS, - CAFFE_MAXIMUM_NUM_BLOCKS); -} - -class DeviceGuard { - public: - explicit DeviceGuard(int newDevice) : previous_(CaffeCudaGetDevice()) { - if (previous_ != newDevice) { - CaffeCudaSetDevice(newDevice); - } - } - - ~DeviceGuard() noexcept { - CaffeCudaSetDevice(previous_); - } - - private: - int previous_; -}; - -} // namespace caffe2 -#endif // CAFFE2_CORE_COMMON_GPU_H_ diff --git a/app/src/main/cpp/caffe2/core/common_omp.h b/app/src/main/cpp/caffe2/core/common_omp.h deleted file mode 100644 index 36c4b9f..0000000 --- a/app/src/main/cpp/caffe2/core/common_omp.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CAFFE2_CORE_COMMON_OMP_H_ -#define CAFFE2_CORE_COMMON_OMP_H_ - -#ifdef _OPENMP -#include -#endif // _OPENMP - -#endif // CAFFE2_CORE_COMMON_OMP_H_ diff --git a/app/src/main/cpp/caffe2/core/context.h b/app/src/main/cpp/caffe2/core/context.h deleted file mode 100644 index 9b1aece..0000000 --- a/app/src/main/cpp/caffe2/core/context.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef CAFFE2_CORE_CONTEXT_H_ -#define CAFFE2_CORE_CONTEXT_H_ - -#include -#include -#include -#include - -#include "caffe2/core/allocator.h" -#include "caffe2/core/event.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/typeid.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/math.h" - -CAFFE2_DECLARE_bool(caffe2_report_cpu_memory_usage); - -namespace caffe2 { - -/** - * The CPU Context, representing the bare minimum of what a Context class in - * Caffe2 should implement. - * - * See operator.h, especially Operator, for how Context are used in - * actual operator implementations that are associated with specific devices. - * In general, the Context class is passed in as a template argument, and - * the operator can use the functions defined in the context to execute whatever - * computation it has. - * - * A Context defines all the necessities to run an operator on a specific - * device. Specific Context classes have the freedom to choose what functions it - * implements, but there are a few functions that you should consider - * implementing if you want to write your own context class: - * - void SwitchToDevice(): any necessary code to switch to the device before - * running anything. - * - void WaitEvent(const Event& ev): make the current context to wait on - * an event. For example, for cuda, this is the equivalent of - * cudaStreamWaitEvent. For CPU context, it essentially synchronizes the - * event. - * - void Record(Event* ev): record the async activities on the current context - * to the event. For example, for cuda, this is the equivalent of - * cudaEventRecord on the current stream. For CPU context, it is always - * synchronous. - * - void FinishDeviceComputation(): any wrapping-up work after all the - * computation of the operator is done. If there are errors during the - * execution, throw exception. For example, in a CUDAContext, this function - * carries out a stream synchronization and spots potential errors for - * the cuda kernel calls. - * - static std::pair New(size_t nbytes): allocates - memory and returns a deleter. - * - template void CopyBytes(...): does - * cross context memory copy. - * - template void Copy(...): - * usually a simple wrapper around the above CopyBytes function. - * - * We intentionally did not create a base class for the various possible Context - * classes there might be, since they are intended to be specified during - * compile time using templates rather than via polymorphism. You should also - * not have classes derived from existing context classes. - */ -class CPUContext final { - public: - typedef std::mt19937 rand_gen_type; - CPUContext() : random_seed_(math::randomNumberSeed()) {} - explicit CPUContext(const DeviceOption& option) - : random_seed_( - option.has_random_seed() ? option.random_seed() - : math::randomNumberSeed()) { - CAFFE_ENFORCE_EQ(option.device_type(), CPU); - } - - ~CPUContext() noexcept {} - - inline void SwitchToDevice(int /*stream_id*/) {} - inline void SwitchToDevice() { - SwitchToDevice(0); - } - - inline void WaitEvent(const Event& ev) { - ev.Wait(CPU, this); - } - inline void Record(Event* ev) const { - CAFFE_ENFORCE(ev, "Event must not be null."); - ev->Record(CPU, this); - } - - inline void FinishDeviceComputation() {} - - inline rand_gen_type& RandGenerator() { - if (!random_generator_.get()) { - random_generator_.reset(new rand_gen_type(random_seed_)); - } - return *random_generator_.get(); - } - - static std::pair New(size_t nbytes) { - auto data_and_deleter = GetCPUAllocator()->New(nbytes); - if (FLAGS_caffe2_report_cpu_memory_usage) { - reporter_.New(data_and_deleter.first, nbytes); - data_and_deleter.second = ReportAndDelete; - } - return data_and_deleter; - } - - // Two copy functions that deals with cross-device copies. - template - inline void CopyBytes(size_t nbytes, const void* src, void* dst); - - template - inline void Copy(size_t n, const T* src, T* dst) { - if (std::is_fundamental::value) { - CopyBytes(n * sizeof(T), - static_cast(src), - static_cast(dst)); - } else { - for (int i = 0; i < n; ++i) { - dst[i] = src[i]; - } - } - } - - template - inline void - CopyItems(const TypeMeta& meta, size_t n, const void* src, void* dst) { - if (meta.copy()) { - meta.copy()(src, dst, n); - } else { - CopyBytes(n * meta.itemsize(), src, dst); - } - } - - protected: - // TODO(jiayq): instead of hard-coding a generator, make it more flexible. - int random_seed_{1701}; - std::unique_ptr random_generator_; - static MemoryAllocationReporter reporter_; - - private: - static void ReportAndDelete(void* ptr) { - reporter_.Delete(ptr); - GetCPUAllocator()->GetDeleter()(ptr); - } -}; - -template<> -inline void CPUContext::CopyBytes( - size_t nbytes, const void* src, void* dst) { - if (nbytes == 0) { - return; - } - CAFFE_ENFORCE(src); - CAFFE_ENFORCE(dst); - memcpy(dst, src, nbytes); -} - -} // namespace caffe2 - -#endif // CAFFE2_CORE_CONTEXT_H_ diff --git a/app/src/main/cpp/caffe2/core/context_gpu.h b/app/src/main/cpp/caffe2/core/context_gpu.h deleted file mode 100644 index 9a70195..0000000 --- a/app/src/main/cpp/caffe2/core/context_gpu.h +++ /dev/null @@ -1,282 +0,0 @@ -#ifndef CAFFE2_CORE_CONTEXT_GPU_H_ -#define CAFFE2_CORE_CONTEXT_GPU_H_ - -#include -#include - -#include "caffe2/core/common_gpu.h" -#include "caffe2/core/context.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/types.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/core/logging.h" - -namespace caffe2 { - -enum class CudaMemoryPoolType { - NONE = 0, - CUB = 1, -}; - -/** - * Gets the current memory pool type used by Caffe2. - * - * The memory pool is set up during caffe2's global initialization time. - */ -CudaMemoryPoolType GetCudaMemoryPoolType(); - -/** - * A struct to host thread-local cuda objects. - * - * In Caffe2, each thread has its own non-default cuda stream as well as - * related objects such as cublas and curand handles. This is achieved by - * having the ThreadLocalCUDAObjects wrapper that takes care of allocating - * and deallocating these objects at the thread scope. This class is solely - * used inside CUDAContext and should not be used externally. - */ -class ThreadLocalCUDAObjects { - friend class CUDAContext; - private: - ThreadLocalCUDAObjects() { - for (int i = 0; i < CAFFE2_COMPILE_TIME_MAX_GPUS; ++i) { - cuda_streams_[i] = vector(); - cublas_handles_[i] = vector(); - } - } - - cudaStream_t GetStream(int gpu, int stream_id) { - vector &gpu_streams = cuda_streams_[gpu]; - if (gpu_streams.size() <= stream_id) { - gpu_streams.resize(stream_id + 1, nullptr); - } - if (!gpu_streams[stream_id]) { - DeviceGuard guard(gpu); - CUDA_ENFORCE(cudaStreamCreateWithFlags( - &gpu_streams[stream_id], cudaStreamNonBlocking)); - } - return gpu_streams[stream_id]; - } - - cublasHandle_t GetHandle(int gpu, int stream_id) { - DeviceGuard guard(gpu); - vector &gpu_handles = cublas_handles_[gpu]; - if (gpu_handles.size() <= stream_id) { - gpu_handles.resize(stream_id + 1, nullptr); - } - if (!gpu_handles[stream_id]) { - CUBLAS_ENFORCE(cublasCreate(&gpu_handles[stream_id])); - // The default is CUBLAS_POINTER_MODE_HOST. You can override - // it after obtaining the cublas handle, but do that with - // caution. - CUBLAS_ENFORCE(cublasSetPointerMode( - gpu_handles[stream_id], CUBLAS_POINTER_MODE_HOST)); - CUBLAS_ENFORCE( - cublasSetStream(gpu_handles[stream_id], GetStream(gpu, stream_id))); - } - return gpu_handles[stream_id]; - } - - ~ThreadLocalCUDAObjects() noexcept { - for (int i = 0; i < CAFFE2_COMPILE_TIME_MAX_GPUS; ++i) { - for (auto& handle : cublas_handles_[i]) { - if (handle) { - CUBLAS_CHECK(cublasDestroy(handle)); - } - } - for (auto& stream : cuda_streams_[i]) { - if (stream) { - CUDA_CHECK(cudaStreamDestroy(stream)); - } - } - } - } - vector cuda_streams_[CAFFE2_COMPILE_TIME_MAX_GPUS]; - vector cublas_handles_[CAFFE2_COMPILE_TIME_MAX_GPUS]; -}; - -class CUDAContext final { - public: - // The default cuda context constructor. - explicit CUDAContext(const int gpu_id = -1); - explicit CUDAContext(const DeviceOption& option); - - ~CUDAContext() { - if (curand_generator_) { - CURAND_ENFORCE(curandDestroyGenerator(curand_generator_)); - } - FinishDeviceComputation(); - } - - inline void SwitchToDevice(int stream_id) { - set_stream_id(stream_id); - CaffeCudaSetDevice(gpu_id_); - } - inline void SwitchToDevice() { - SwitchToDevice(0); - } - - inline void WaitEvent(const Event& ev) { - ev.Wait(CUDA, this); - } - - inline void Record(Event* ev) const { - CAFFE_ENFORCE(ev, "Event must not be null."); - ev->Record(CUDA, this); - } - - void FinishDeviceComputation() { - cudaStreamSynchronize(cuda_objects_.GetStream(gpu_id_, stream_id_)); - cudaError_t error = cudaGetLastError(); - if (error != cudaSuccess) { - CAFFE_THROW("Encountered CUDA error: ", cudaGetErrorString(error)); - } - } - - inline int cuda_gpu_id() const { return gpu_id_; } - - inline cudaStream_t cuda_stream() { - return cuda_stream(gpu_id_, stream_id_); - } - - inline cudaStream_t cuda_stream() const { - return cuda_stream(gpu_id_, stream_id_); - } - - static cudaStream_t cuda_stream(int gpu_id, int stream_id) { - return cuda_objects_.GetStream(gpu_id, stream_id); - } - - cublasHandle_t cublas_handle() { - return cuda_objects_.GetHandle(gpu_id_, stream_id_); - } - - curandGenerator_t& curand_generator() { - if (!curand_generator_) { - DeviceGuard guard(gpu_id_); - CURAND_ENFORCE( - curandCreateGenerator(&curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)); - CURAND_ENFORCE( - curandSetPseudoRandomGeneratorSeed(curand_generator_, random_seed_)); - CHECK_NOTNULL(curand_generator_); - } - CURAND_ENFORCE(curandSetStream(curand_generator_, cuda_stream())); - return curand_generator_; - } - - static std::pair New(size_t nbytes); - - // Get a mutex to lock out cudaMalloc / cudaFree calls when - // NCCL kernels are being launched. Should remove threat of - // deadlocks - static std::mutex& mutex(); - - // Functions to query memory stats. Only available if flag - // --caffe2_gpu_memory_tracking is enabled. - static std::vector TotalMemoryByGpu(); - static std::vector MaxMemoryByGpu(); - - template - inline void CopyBytes(size_t nbytes, const void* src, void* dst) { - CUDA_ENFORCE(cudaMemcpyAsync( - dst, - src, - nbytes, - cudaMemcpyDefault, - cuda_objects_.GetStream(gpu_id_, stream_id_))); - } - - template - inline void Copy(int n, const T* src, T* dst) { - CopyBytes(n * sizeof(T), - static_cast(src), - static_cast(dst)); - } - - template - inline void - CopyItems(const TypeMeta& meta, size_t n, const void* src, void* dst) { - CAFFE_ENFORCE(!meta.copy(), "CUDAContext requires fundamental types."); - CopyBytes(n * meta.itemsize(), src, dst); - } - - protected: - static void Delete(void* data); - void set_stream_id(int stream_id) { - stream_id_ = stream_id; - } - - int gpu_id_; - int stream_id_ = 0; - int random_seed_; - curandGenerator_t curand_generator_{nullptr}; - static thread_local ThreadLocalCUDAObjects cuda_objects_; -}; - -// For the CPU context, we also allow a (probably expensive) function -// to copy the data from a cuda context. Inside the function, we create -// a temporary CUDAContext object to carry out the copy. From the caller's -// side, these functions are synchronous with respect to the host, similar -// to a normal CPUContext::CopyBytes call. -template<> -inline void CPUContext::CopyBytes( - size_t nbytes, const void* src, void* dst) { - CUDAContext context(GetGPUIDForPointer(src)); - context.CopyBytes(nbytes, src, dst); -} -template<> -inline void CPUContext::CopyBytes( - size_t nbytes, const void* src, void* dst) { - CUDAContext context(GetGPUIDForPointer(dst)); - context.CopyBytes(nbytes, src, dst); -} - -/** - * An allocator that does the CPU memory allocation with pinned memory. - * - * This is needed because if we want to do any asynchronous cuda memcpy, - * the underlying CPU memory also needs to be allocated into pinned memory - * space. As a result, whenever Caffe2 is built with GPU and there is - * GPU present during runtime, at global initialization time we will set - * the CPU memory allocator to allocate pinned memory. - */ -struct PinnedCPUAllocator final : CPUAllocator { - PinnedCPUAllocator() {} - ~PinnedCPUAllocator() override {} - std::pair New(size_t nbytes) override { - void* data; - std::lock_guard lock(CUDAContext::mutex()); - CUDA_ENFORCE(cudaMallocHost(&data, nbytes)); - memset(data, 0, nbytes); - return {data, Delete}; - } - - MemoryDeleter GetDeleter() override { - return Delete; - } - - private: - static void Delete(void* data) { - // Caffe2 uses a lazy way to figure out if one is actually going to use GPUs - // or not. If a CUDAContext::New() call is made, inside the CUDAContext - // function we will switch the cpu side allocator to a PinnedCPUAllocator. - // But, if one calls CPUContext::New() before any cuda allocations, - // PinnedCPUAllocator can still delete the corresponding memory. - std::lock_guard lock(CUDAContext::mutex()); - cudaError_t err = cudaFreeHost(data); - if (err == cudaErrorInvalidValue) { - free(data); - // Calling cudaGetLastError will reset the cuda error. - cudaGetLastError(); - } else { - // For all other errors, still do a cuda check. - CUDA_ENFORCE(err); - } - } -}; - -// For simplicity, we will typedef Tensor to TensorCPU. -typedef Tensor TensorCUDA; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_CONTEXT_GPU_H_ diff --git a/app/src/main/cpp/caffe2/core/db.h b/app/src/main/cpp/caffe2/core/db.h deleted file mode 100644 index 98b1370..0000000 --- a/app/src/main/cpp/caffe2/core/db.h +++ /dev/null @@ -1,311 +0,0 @@ -#ifndef CAFFE2_CORE_DB_H_ -#define CAFFE2_CORE_DB_H_ - -#include - -#include "caffe2/core/blob_serialization.h" -#include "caffe2/core/registry.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { -namespace db { - -/** - * The mode of the database, whether we are doing a read, write, or creating - * a new database. - */ -enum Mode { READ, WRITE, NEW }; - -/** - * An abstract class for the cursor of the database while reading. - */ -class Cursor { - public: - Cursor() { } - virtual ~Cursor() { } - /** - * Seek to a specific key (or if the key does not exist, seek to the - * immediate next). This is optional for dbs, and in default, SupportsSeek() - * returns false meaning that the db cursor does not support it. - */ - virtual void Seek(const string& key) = 0; - virtual bool SupportsSeek() { return false; } - /** - * Seek to the first key in the database. - */ - virtual void SeekToFirst() = 0; - /** - * Go to the next location in the database. - */ - virtual void Next() = 0; - /** - * Returns the current key. - */ - virtual string key() = 0; - /** - * Returns the current value. - */ - virtual string value() = 0; - /** - * Returns whether the current location is valid - for example, if we have - * reached the end of the database, return false. - */ - virtual bool Valid() = 0; - - DISABLE_COPY_AND_ASSIGN(Cursor); -}; - -/** - * An abstract class for the current database transaction while writing. - */ -class Transaction { - public: - Transaction() { } - virtual ~Transaction() { } - /** - * Puts the key value pair to the database. - */ - virtual void Put(const string& key, const string& value) = 0; - /** - * Commits the current writes. - */ - virtual void Commit() = 0; - - DISABLE_COPY_AND_ASSIGN(Transaction); -}; - -/** - * An abstract class for accessing a database of key-value pairs. - */ -class DB { - public: - DB(const string& /*source*/, Mode mode) : mode_(mode) {} - virtual ~DB() { } - /** - * Closes the database. - */ - virtual void Close() = 0; - /** - * Returns a cursor to read the database. The caller takes the ownership of - * the pointer. - */ - virtual std::unique_ptr NewCursor() = 0; - /** - * Returns a transaction to write data to the database. The caller takes the - * ownership of the pointer. - */ - virtual std::unique_ptr NewTransaction() = 0; - - protected: - Mode mode_; - - DISABLE_COPY_AND_ASSIGN(DB); -}; - -// Database classes are registered by their names so we can do optional -// dependencies. -CAFFE_DECLARE_REGISTRY(Caffe2DBRegistry, DB, const string&, Mode); -#define REGISTER_CAFFE2_DB(name, ...) \ - CAFFE_REGISTER_CLASS(Caffe2DBRegistry, name, __VA_ARGS__) - -/** - * Returns a database object of the given database type, source and mode. The - * caller takes the ownership of the pointer. If the database type is not - * supported, a nullptr is returned. The caller is responsible for examining the - * validity of the pointer. - */ -inline unique_ptr CreateDB( - const string& db_type, const string& source, Mode mode) { - auto result = Caffe2DBRegistry()->Create(db_type, source, mode); - VLOG(1) << ((!result) ? "not found db " : "found db ") << db_type; - return result; -} - -/** - * Returns whether or not a database exists given the database type and path. - */ -inline bool DBExists(const string& db_type, const string& full_db_name) { - // Warning! We assume that creating a DB throws an exception if the DB - // does not exist. If the DB constructor does not follow this design - // pattern, - // the returned output (the existence tensor) can be wrong. - try { - std::unique_ptr db( - caffe2::db::CreateDB(db_type, full_db_name, caffe2::db::READ)); - return true; - } catch (...) { - return false; - } -} - -/** - * A reader wrapper for DB that also allows us to serialize it. - */ -class DBReader { - public: - - friend class DBReaderSerializer; - DBReader() {} - - DBReader( - const string& db_type, - const string& source, - const int32_t num_shards = 1, - const int32_t shard_id = 0) { - Open(db_type, source, num_shards, shard_id); - } - - explicit DBReader(const DBReaderProto& proto) { - Open(proto.db_type(), proto.source()); - if (proto.has_key()) { - CAFFE_ENFORCE(cursor_->SupportsSeek(), - "Encountering a proto that needs seeking but the db type " - "does not support it."); - cursor_->Seek(proto.key()); - } - num_shards_ = 1; - shard_id_ = 0; - } - - explicit DBReader(std::unique_ptr db) - : db_type_(""), - source_(""), - db_(std::move(db)) { - CAFFE_ENFORCE(db_.get(), "Passed null db"); - cursor_ = db_->NewCursor(); - } - - void Open( - const string& db_type, - const string& source, - const int32_t num_shards = 1, - const int32_t shard_id = 0) { - // Note(jiayq): resetting is needed when we re-open e.g. leveldb where no - // concurrent access is allowed. - cursor_.reset(); - db_.reset(); - db_type_ = db_type; - source_ = source; - db_ = CreateDB(db_type_, source_, READ); - CAFFE_ENFORCE(db_, "Cannot open db: ", source_, " of type ", db_type_); - InitializeCursor(num_shards, shard_id); - } - - void Open( - unique_ptr&& db, - const int32_t num_shards = 1, - const int32_t shard_id = 0) { - cursor_.reset(); - db_.reset(); - db_ = std::move(db); - CAFFE_ENFORCE(db_.get(), "Passed null db"); - InitializeCursor(num_shards, shard_id); - } - - public: - /** - * Read a set of key and value from the db and move to next. Thread safe. - * - * The string objects key and value must be created by the caller and - * explicitly passed in to this function. This saves one additional object - * copy. - * - * If the cursor reaches its end, the reader will go back to the head of - * the db. This function can be used to enable multiple input ops to read - * the same db. - * - * Note(jiayq): we loosen the definition of a const function here a little - * bit: the state of the cursor is actually changed. However, this allows - * us to pass in a DBReader to an Operator without the need of a duplicated - * output blob. - */ - void Read(string* key, string* value) const { - CAFFE_ENFORCE(cursor_ != nullptr, "Reader not initialized."); - std::unique_lock mutex_lock(reader_mutex_); - *key = cursor_->key(); - *value = cursor_->value(); - - // In sharded mode, each read skips num_shards_ records - for (int s = 0; s < num_shards_; s++) { - cursor_->Next(); - if (!cursor_->Valid()) { - MoveToBeginning(); - break; - } - } - } - - /** - * @brief Seeks to the first key. Thread safe. - */ - void SeekToFirst() const { - CAFFE_ENFORCE(cursor_ != nullptr, "Reader not initialized."); - std::unique_lock mutex_lock(reader_mutex_); - MoveToBeginning(); - } - - /** - * Returns the underlying cursor of the db reader. - * - * Note that if you directly use the cursor, the read will not be thread - * safe, because there is no mechanism to stop multiple threads from - * accessing the same cursor. You should consider using Read() explicitly. - */ - inline Cursor* cursor() const { - LOG(ERROR) << "Usually for a DBReader you should use Read() to be " - "thread safe. Consider refactoring your code."; - return cursor_.get(); - } - - private: - void InitializeCursor(const int32_t num_shards, const int32_t shard_id) { - CAFFE_ENFORCE(num_shards >= 1); - CAFFE_ENFORCE(shard_id >= 0); - CAFFE_ENFORCE(shard_id < num_shards); - num_shards_ = num_shards; - shard_id_ = shard_id; - cursor_ = db_->NewCursor(); - SeekToFirst(); - } - - void MoveToBeginning() const { - cursor_->SeekToFirst(); - for (auto s = 0; s < shard_id_; s++) { - cursor_->Next(); - CAFFE_ENFORCE( - cursor_->Valid(), "Db has less rows than shard id: ", s, shard_id_); - } - } - - string db_type_; - string source_; - unique_ptr db_; - unique_ptr cursor_; - mutable std::mutex reader_mutex_; - uint32_t num_shards_; - uint32_t shard_id_; - - DISABLE_COPY_AND_ASSIGN(DBReader); -}; - -class DBReaderSerializer : public BlobSerializerBase { - public: - /** - * Serializes a DBReader. Note that this blob has to contain DBReader, - * otherwise this function produces a fatal error. - */ - void Serialize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor) override; -}; - -class DBReaderDeserializer : public BlobDeserializerBase { - public: - void Deserialize(const BlobProto& proto, Blob* blob) override; -}; - -} // namespace db -} // namespace caffe2 - -#endif // CAFFE2_CORE_DB_H_ diff --git a/app/src/main/cpp/caffe2/core/event.h b/app/src/main/cpp/caffe2/core/event.h deleted file mode 100644 index b8a6e59..0000000 --- a/app/src/main/cpp/caffe2/core/event.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef CAFFE2_CORE_EVENT_H_ -#define CAFFE2_CORE_EVENT_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -constexpr int MaxDeviceTypes = DeviceType::COMPILE_TIME_MAX_DEVICE_TYPES; -class Event; - -// For the following functions, void* shall be interpreted as the corresponding -// context object corresponding to the device type associated with the -// functions. -typedef void (*EventCreateFunction)(const DeviceOption& option, Event*); -typedef void (*EventRecordFunction)(const void*, Event*); -typedef void (*EventWaitFunction)(const Event*, void*); -typedef void (*EventFinishFunction)(const Event*); - -class Event { - public: - explicit Event(const DeviceOption& option) - : event_(), type_(option.device_type()) { - CAFFE_ENFORCE_LT(type_, MaxDeviceTypes); - CAFFE_ENFORCE(event_creator_[type_]); - event_creator_[type_](option, this); - } - - // Nothing needs to be done in the destructor, as the event creator should - // set the proper destruction process for the unique_ptr. - ~Event() {} - - void Record(int recorder_type, const void* context) { - CAFFE_ENFORCE_EQ( - recorder_type, - type_, - "You are trying to record with a wrong device type."); - CAFFE_ENFORCE(event_recorder_[recorder_type]); - event_recorder_[recorder_type](context, this); - } - - void Wait(int waiter_type, void* context) const { - CAFFE_ENFORCE(event_waiter_[waiter_type][type_]); - event_waiter_[waiter_type][type_](this, context); - } - - void Finish() const { - CAFFE_ENFORCE(event_finisher_[type_]); - event_finisher_[type_](this); - } - - // event_ is going to be accessed by the EventCreate/Record/Wait/Finish - // functions, but one should not use it outside the own Event functionalities. - // In the future we may move it to a private member. - std::shared_ptr event_; - - private: - int type_; - static EventCreateFunction event_creator_[MaxDeviceTypes]; - static EventRecordFunction event_recorder_[MaxDeviceTypes]; - static EventWaitFunction event_waiter_[MaxDeviceTypes][MaxDeviceTypes]; - static EventFinishFunction event_finisher_[MaxDeviceTypes]; - - template - friend struct EventCreateFunctionRegisterer; - template - friend struct EventRecordFunctionRegisterer; - template - friend struct EventWaitFunctionRegisterer; - template - friend struct EventFinishFunctionRegisterer; -}; - -template -struct EventCreateFunctionRegisterer { - explicit EventCreateFunctionRegisterer(EventCreateFunction f) { - static_assert(d < MaxDeviceTypes, ""); - Event::event_creator_[d] = f; - } -}; -#define REGISTER_EVENT_CREATE_FUNCTION(d, f) \ - namespace { \ - static EventCreateFunctionRegisterer g_event_create_##d(f); \ - } - -template -struct EventRecordFunctionRegisterer { - explicit EventRecordFunctionRegisterer(EventRecordFunction f) { - static_assert(d < MaxDeviceTypes, ""); - Event::event_recorder_[d] = f; - } -}; -#define REGISTER_EVENT_RECORD_FUNCTION(d, f) \ - namespace { \ - static EventRecordFunctionRegisterer g_event_record_##d(f); \ - } - -template -struct EventWaitFunctionRegisterer { - explicit EventWaitFunctionRegisterer(EventWaitFunction f) { - static_assert(waiter_type < MaxDeviceTypes, ""); - static_assert(event_type < MaxDeviceTypes, ""); - Event::event_waiter_[waiter_type][event_type] = f; - } -}; -#define REGISTER_EVENT_WAIT_FUNCTION(w, d, f) \ - namespace { \ - static EventWaitFunctionRegisterer g_event_record_##w##_##d(f); \ - } - -template -struct EventFinishFunctionRegisterer { - explicit EventFinishFunctionRegisterer(EventFinishFunction f) { - static_assert(d < MaxDeviceTypes, ""); - Event::event_finisher_[d] = f; - } -}; -#define REGISTER_EVENT_FINISH_FUNCTION(d, f) \ - namespace { \ - static EventFinishFunctionRegisterer g_event_finish_##d(f); \ - } - -} // namespace caffe2 - -#endif // CAFFE2_CORE_EVENT_H_ diff --git a/app/src/main/cpp/caffe2/core/flags.h b/app/src/main/cpp/caffe2/core/flags.h deleted file mode 100644 index bd542fb..0000000 --- a/app/src/main/cpp/caffe2/core/flags.h +++ /dev/null @@ -1,162 +0,0 @@ -/** - * @file flags.h - * @brief Commandline flags support for Caffe2. - * - * This is a portable commandline flags tool for caffe2, so we can optionally - * choose to use gflags or a lightweighted custom implementation if gflags is - * not possible on a certain platform. If you have gflags installed, set the - * macro CAFFE2_USE_GFLAGS will seamlessly route everything to gflags. - * - * To define a flag foo of type bool default to true, do the following in the - * *global* namespace: - * CAFFE2_DEFINE_bool(foo, true, "An example."); - * - * To use it in another .cc file, you can use CAFFE2_DECLARE_* as follows: - * CAFFE2_DECLARE_bool(foo); - * - * In both cases, you can then access the flag via caffe2::FLAGS_foo. - */ - -#ifndef CAFFE2_CORE_FLAGS_H_ -#define CAFFE2_CORE_FLAGS_H_ - -#include "caffe2/core/registry.h" - -namespace caffe2 { -/** - * Sets the usage message when a commandline tool is called with "--help". - */ -void SetUsageMessage(const string& str); - -/** - * Returns the usage message for the commandline tool set by SetUsageMessage. - */ -const char* UsageMessage(); - -/** - * Parses the commandline flags. - * - * This command parses all the commandline arguments passed in via pargc - * and argv. Once it is finished, partc and argv will contain the remaining - * commandline args that caffe2 does not deal with. Note that following - * convention, argv[0] contains the binary name and is not parsed. - */ -bool ParseCaffeCommandLineFlags(int* pargc, char*** pargv); -/** - * Checks if the commandline flags has already been passed. - */ -bool CommandLineFlagsHasBeenParsed(); - -} // namespace caffe2 - - -//////////////////////////////////////////////////////////////////////////////// -// Below are gflags and non-gflags specific implementations. -//////////////////////////////////////////////////////////////////////////////// - -#ifdef CAFFE2_USE_GFLAGS - -#include - -// gflags before 2.0 uses namespace google and after 2.1 uses namespace gflags. -// Using GFLAGS_GFLAGS_H_ to capture this change. -#ifndef GFLAGS_GFLAGS_H_ -namespace gflags = google; -#endif // GFLAGS_GFLAGS_H_ - -#define CAFFE2_GFLAGS_DEF_WRAPPER(type, name, default_value, help_str) \ - DEFINE_##type(name, default_value, help_str); \ - namespace caffe2 { \ - using ::FLAGS_##name; \ - } - -#define CAFFE2_DEFINE_int(name, default_value, help_str) \ - CAFFE2_GFLAGS_DEF_WRAPPER(int32, name, default_value, help_str) -#define CAFFE2_DEFINE_int64(name, default_value, help_str) \ - CAFFE2_GFLAGS_DEF_WRAPPER(int64, name, default_value, help_str) -#define CAFFE2_DEFINE_double(name, default_value, help_str) \ - CAFFE2_GFLAGS_DEF_WRAPPER(double, name, default_value, help_str) -#define CAFFE2_DEFINE_bool(name, default_value, help_str) \ - CAFFE2_GFLAGS_DEF_WRAPPER(bool, name, default_value, help_str) -#define CAFFE2_DEFINE_string(name, default_value, help_str) \ - CAFFE2_GFLAGS_DEF_WRAPPER(string, name, default_value, help_str) - -// DECLARE_typed_var should be used in header files and in the global namespace. -#define CAFFE2_GFLAGS_DECLARE_WRAPPER(type, name) \ - DECLARE_##type(name); \ - namespace caffe2 { \ - using ::FLAGS_##name; \ - } // namespace caffe2 - -#define CAFFE2_DECLARE_int(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(int32, name) -#define CAFFE2_DECLARE_int64(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(int64, name) -#define CAFFE2_DECLARE_double(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(double, name) -#define CAFFE2_DECLARE_bool(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(bool, name) -#define CAFFE2_DECLARE_string(name) CAFFE2_GFLAGS_DECLARE_WRAPPER(string, name) - -#else // CAFFE2_USE_GFLAGS - -namespace caffe2 { - -class Caffe2FlagParser { - public: - Caffe2FlagParser() {} - bool success() { return success_; } - - protected: - template - bool Parse(const string& content, T* value); - bool success_; -}; - -CAFFE_DECLARE_REGISTRY(Caffe2FlagsRegistry, Caffe2FlagParser, const string&); - -} // namespace caffe2 - -// The macros are defined outside the caffe2 namespace. In your code, you should -// write the CAFFE2_DEFINE_* and CAFFE2_DECLARE_* macros outside any namespace -// as well. - -#define CAFFE2_DEFINE_typed_var(type, name, default_value, help_str) \ - namespace caffe2 { \ - type FLAGS_##name = default_value; \ - namespace { \ - class Caffe2FlagParser_##name : public Caffe2FlagParser { \ - public: \ - explicit Caffe2FlagParser_##name(const string& content) { \ - success_ = Caffe2FlagParser::Parse(content, &FLAGS_##name); \ - } \ - }; \ - } \ - RegistererCaffe2FlagsRegistry g_Caffe2FlagsRegistry_##name( \ - #name, Caffe2FlagsRegistry(), \ - RegistererCaffe2FlagsRegistry::DefaultCreator, \ - "(" #type ", default " #default_value ") " help_str); \ - } - -#define CAFFE2_DEFINE_int(name, default_value, help_str) \ - CAFFE2_DEFINE_typed_var(int, name, default_value, help_str) -#define CAFFE2_DEFINE_int64(name, default_value, help_str) \ - CAFFE2_DEFINE_typed_var(int64_t, name, default_value, help_str) -#define CAFFE2_DEFINE_double(name, default_value, help_str) \ - CAFFE2_DEFINE_typed_var(double, name, default_value, help_str) -#define CAFFE2_DEFINE_bool(name, default_value, help_str) \ - CAFFE2_DEFINE_typed_var(bool, name, default_value, help_str) -#define CAFFE2_DEFINE_string(name, default_value, help_str) \ - CAFFE2_DEFINE_typed_var(string, name, default_value, help_str) - -// DECLARE_typed_var should be used in header files and in the global namespace. -#define CAFFE2_DECLARE_typed_var(type, name) \ - namespace caffe2 { \ - extern type FLAGS_##name; \ - } // namespace caffe2 - -#define CAFFE2_DECLARE_int(name) CAFFE2_DECLARE_typed_var(int, name) -#define CAFFE2_DECLARE_int64(name) CAFFE2_DECLARE_typed_var(int64_t, name) -#define CAFFE2_DECLARE_double(name) CAFFE2_DECLARE_typed_var(double, name) -#define CAFFE2_DECLARE_bool(name) CAFFE2_DECLARE_typed_var(bool, name) -#define CAFFE2_DECLARE_string(name) CAFFE2_DECLARE_typed_var(string, name) - -#endif // CAFFE2_USE_GFLAGS - -#endif // CAFFE2_CORE_FLAGS_H_ diff --git a/app/src/main/cpp/caffe2/core/graph.h b/app/src/main/cpp/caffe2/core/graph.h deleted file mode 100644 index 52adb49..0000000 --- a/app/src/main/cpp/caffe2/core/graph.h +++ /dev/null @@ -1,179 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" -#include "caffe2/utils/string_utils.h" - -#include -#include -#include - -namespace caffe2 { - -namespace transform { - -/** - * Graph representation of an operator. - */ -struct Node { - public: - // Empty constructor for resize - Node() {} - - // Alternate constructor - Node( - const OperatorDef& op, - bool active, - std::map> parents, - std::map> children) - : op(op), active(active), parents(parents), children(children) {} - - // The OperatorDef which this node represents. - OperatorDef op; - - // Keeps track of if an operator has been deleted through a transformation. - bool active = true; - - // Stores a pair (idx, blob_list), - // idx = index of the child - // blob_list = a list of strings, containing the blobs that connect the nodes - std::map> parents; - std::map> children; -}; - -/** - * Graph representation of a Netdef. - */ -struct Graph { - public: - /** - * Given a subgraph, gets all of the parents of the subgraph, as well as - * their associated blob names. Sorted by blob names. - * - * := (name of blob writing into subgraph, - * index of node that writes into subgraph using that blob) - */ - const std::vector> GetSubgraphInput( - const std::vector& subgraph); - - /** - * Given a subgraph, gets all of the children of the subgraph, as well as - * their associated blob names. Sorted by blob names. - * - * := (name of blob reading from subgraph, - * index of node that reads from subgraph using that blob) - */ - const std::vector> GetSubgraphOutput( - const std::vector& subgraph); - - /** - * Graph generation. - * Given a netdef, returns a Graph. - * - * Each node represents an operator. - * An edge exists between two nodes if the parent op writes to a blob, which - * is the input of the child blob, with no other op writing to the blob in - * between the execution order. - * - * Time Complexity: O(E), where E is the number of blobs - */ - explicit Graph(const NetDef& net_def); - - /** - * Generates a NetDef Representation for the current graph. - * Nodes are visited in topological order, which is proper Opdef ordering. - * TODO(benz): - * There exists conflicts with repeated blob names, where topological sorting - * is not sufficient for correct netdef representation, unless blobs are - * renamed. - * For example, if after a transformation, We have operator ancestry: - * A --> B --> C, and also A --> D --> E, where B -> C and D -> E uses the - * same blob name, then A, B, D, E, C is a correct topological ordering, - * but D will write to the blob that C reads from, instead of B. - * Currently believe that there will always be ambiguity unless blobs are - * renamed. - * This is solved by performing SSA on all transformed blob names. - */ - NetDef GetNetDef(); - - /** - * Deactivate a subgraph, and get rid of all edges into this subgraph. - */ - void DeactivateSubgraph(std::vector subgraph); - - const size_t size() const { - return nodes_.size(); - } - - void push_node(const Node& new_node) { - return nodes_.push_back(new_node); - } - - void resize_nodes(size_t new_size) { - nodes_.resize(new_size); - } - - // Index safe, less verbose way to access nodes - inline const Node& node(size_t idx) const { - return nodes_.at(idx); - } - - inline Node& node(size_t idx) { - return nodes_.at(idx); - } - - inline bool is_node_active(size_t idx) { - return node(idx).active; - } - - inline const std::set& external_input() const { - return external_input_; - } - - inline const std::set& external_output() const { - return external_output_; - } - - private: - const std::vector> GetSubgraphPerimeterHelper( - bool from_children, - const std::vector& match); - - // Stores the netdef representation. Is updated upon calls to GetNetDef. - NetDef netdef_; - - // Stores which blobs the graph reads from, and writes to. - std::set external_input_; - std::set external_output_; - - // Keeps track of all the Operators currently within graph, even if inactive. - std::vector nodes_; -}; - -} // namespace transform - -// Adds an operator def to a netdef. -// Returns the ptr, if you want to add anything extra (such as device_option) -OperatorDef* AddOp( - NetDef* netdef_ptr, - string op_type, - std::vector inputs, - std::vector outputs); - -/** - * This allows for the use of * and | to match operator types, - * engines, or any other property that is represented by strings. - * - * For example, if we wanted to match an operator to Conv or FC, we can give: - * "Conv|FC" as the type() of that op. - */ -bool MatchStrings(string p, string s); - -/** - * This ensures that each named arg that exists in the pattern exists in g_op, - * is equal in value. - */ -bool MatchArguments(const OperatorDef& p_op, const OperatorDef& g_op); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/core/init.h b/app/src/main/cpp/caffe2/core/init.h deleted file mode 100644 index b20866e..0000000 --- a/app/src/main/cpp/caffe2/core/init.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef CAFFE2_CORE_INIT_H_ -#define CAFFE2_CORE_INIT_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/flags.h" -#include "caffe2/core/logging.h" - -namespace caffe2 { - -namespace internal { -class Caffe2InitializeRegistry { - public: - typedef bool (*InitFunction)(int*, char***); - // Registry() is defined in .cpp file to make registration work across - // multiple shared libraries loaded with RTLD_LOCAL - static Caffe2InitializeRegistry* Registry(); - - void Register(InitFunction function, bool run_early, - const char* description) { - if (run_early) { - early_init_functions_.emplace_back(function, description); - } else { - init_functions_.emplace_back(function, description); - } - } - - bool RunRegisteredEarlyInitFunctions(int* pargc, char*** pargv) { - return RunRegisteredInitFunctionsInternal( - early_init_functions_, pargc, pargv); - } - - bool RunRegisteredInitFunctions(int* pargc, char*** pargv) { - return RunRegisteredInitFunctionsInternal(init_functions_, pargc, pargv); - } - - private: - // Run all registered initialization functions. This has to be called AFTER - // all static initialization are finished and main() has started, since we are - // using logging. - bool RunRegisteredInitFunctionsInternal( - vector>& functions, - int* pargc, char*** pargv) { - for (const auto& init_pair : functions) { - VLOG(1) << "Running init function: " << init_pair.second; - if (!(*init_pair.first)(pargc, pargv)) { - LOG(ERROR) << "Initialization function failed."; - return false; - } - } - return true; - } - - Caffe2InitializeRegistry() {} - vector > early_init_functions_; - vector > init_functions_; -}; -} // namespace internal - -class InitRegisterer { - public: - InitRegisterer(internal::Caffe2InitializeRegistry::InitFunction function, - bool run_early, const char* description) { - internal::Caffe2InitializeRegistry::Registry() - ->Register(function, run_early, description); - } -}; - -#define REGISTER_CAFFE2_INIT_FUNCTION(name, function, description) \ - namespace { \ - ::caffe2::InitRegisterer g_caffe2_initregisterer_##name( \ - function, false, description); \ - } // namespace - -#define REGISTER_CAFFE2_EARLY_INIT_FUNCTION(name, function, description) \ - namespace { \ - ::caffe2::InitRegisterer g_caffe2_initregisterer_##name( \ - function, true, description); \ - } // namespace - -/** - * @brief Initialize the global environment of caffe2. - * - * Caffe2 uses a registration pattern for initialization functions. Custom - * initialization functions should take the signature - * bool (*func)(int*, char***) - * where the pointers to argc and argv are passed in. Caffe2 then runs the - * initialization in three phases: - * (1) Functions registered with REGISTER_CAFFE2_EARLY_INIT_FUNCTION. Note that - * since it is possible the logger is not initialized yet, any logging in - * such early init functions may not be printed correctly. - * (2) Parses Caffe-specific commandline flags, and initializes caffe logging. - * (3) Functions registered with REGISTER_CAFFE2_INIT_FUNCTION. - * If there is something wrong at each stage, the function returns false. If - * the global initialization has already been run, the function returns false - * as well. - */ -bool GlobalInit(int* pargc, char*** argv); - -} // namespace caffe2 -#endif // CAFFE2_CORE_INIT_H_ diff --git a/app/src/main/cpp/caffe2/core/logging.h b/app/src/main/cpp/caffe2/core/logging.h deleted file mode 100644 index ad9a57e..0000000 --- a/app/src/main/cpp/caffe2/core/logging.h +++ /dev/null @@ -1,303 +0,0 @@ -#ifndef CAFFE2_CORE_LOGGING_H_ -#define CAFFE2_CORE_LOGGING_H_ - -#include -#include -#include -#include -#include - -#include "caffe2/core/flags.h" -#include "caffe2/proto/caffe2.pb.h" - -// CAFFE2_LOG_THRESHOLD is a compile time flag that would allow us to turn off -// logging at compile time so no logging message below that level is produced -// at all. The value should be between INT_MIN and CAFFE_FATAL. -#ifndef CAFFE2_LOG_THRESHOLD -// If we have not defined the compile time log threshold, we keep all the -// log cases. -#define CAFFE2_LOG_THRESHOLD INT_MIN -#endif // CAFFE2_LOG_THRESHOLD - -// Below are different implementations for glog and non-glog cases. -#ifdef CAFFE2_USE_GOOGLE_GLOG -#include "caffe2/core/logging_is_google_glog.h" -#else // !CAFFE2_USE_GOOGLE_GLOG -#include "caffe2/core/logging_is_not_google_glog.h" -#endif // CAFFE2_USE_GOOGLE_GLOG - -CAFFE2_DECLARE_int(caffe2_log_level); -CAFFE2_DECLARE_bool(caffe2_use_fatal_for_enforce); - -namespace caffe2 { -// Functions that we use for initialization. -bool InitCaffeLogging(int* argc, char** argv); - -constexpr bool IsUsingGoogleLogging() { -#ifdef CAFFE2_USE_GOOGLE_GLOG - return true; -#else - return false; -#endif -} - -/** - * A utility to allow one to show log info to stderr after the program starts. - * - * This is similar to calling GLOG's --logtostderr, or setting caffe2_log_level - * to smaller than INFO. You are recommended to only use this in a few sparse - * cases, such as when you want to write a tutorial or something. Normally, use - * the commandline flags to set the log level. - */ -void ShowLogInfoToStderr(); - -inline void MakeStringInternal(std::stringstream& /*ss*/) {} - -template -inline void MakeStringInternal(std::stringstream& ss, const T& t) { - ss << t; -} - -template -inline void -MakeStringInternal(std::stringstream& ss, const T& t, const Args&... args) { - MakeStringInternal(ss, t); - MakeStringInternal(ss, args...); -} - -template -string MakeString(const Args&... args) { - std::stringstream ss; - MakeStringInternal(ss, args...); - return string(ss.str()); -} - -// Specializations for already-a-string types. -template <> -inline string MakeString(const string& str) { - return str; -} -inline string MakeString(const char* c_str) { - return string(c_str); -} - -template -inline string Join(const string& delimiter, const Container& v) { - std::stringstream s; - int cnt = static_cast(v.size()) - 1; - for (auto i = v.begin(); i != v.end(); ++i, --cnt) { - s << (*i) << (cnt ? delimiter : ""); - } - return s.str(); -} - -// Obtains the base name from a full path. -string StripBasename(const std::string& full_path); - -// Replace all occurrences of "from" substring to "to" string. -// Returns number of replacements -size_t ReplaceAll(string& s, const char* from, const char* to); - -void SetStackTraceFetcher(std::function fetcher); - -void SetOperatorLogger(std::function tracer); -std::function GetOperatorLogger(); - -class EnforceNotMet : public std::exception { - public: - EnforceNotMet( - const char* file, - const int line, - const char* condition, - const string& msg, - const void* caller=nullptr); - void AppendMessage(const string& msg); - string msg() const; - inline const vector& msg_stack() const { - return msg_stack_; - } - - const char* what() const noexcept override; - - const void* caller() const noexcept; - - private: - vector msg_stack_; - string full_msg_; - string stack_trace_; - const void* caller_; -}; - -#define CAFFE_ENFORCE(condition, ...) \ - do { \ - if (!(condition)) { \ - throw ::caffe2::EnforceNotMet( \ - __FILE__, __LINE__, #condition, ::caffe2::MakeString(__VA_ARGS__)); \ - } \ - } while (false) - -#define CAFFE_ENFORCE_WITH_CALLER(condition, ...) \ - do { \ - if (!(condition)) { \ - throw ::caffe2::EnforceNotMet( \ - __FILE__, __LINE__, #condition, ::caffe2::MakeString(__VA_ARGS__), this); \ - } \ - } while (false) - -#define CAFFE_THROW(...) \ - throw ::caffe2::EnforceNotMet( \ - __FILE__, __LINE__, "", ::caffe2::MakeString(__VA_ARGS__)) - -/** - * Rich logging messages - * - * CAFFE_ENFORCE_THAT can be used with one of the "checker functions" that - * capture input argument values and add it to the exception message. E.g. - * `CAFFE_ENFORCE_THAT(Equals(foo(x), bar(y)), "Optional additional message")` - * would evaluate both foo and bar only once and if the results are not equal - - * include them in the exception message. - * - * Some of the basic checker functions like Equals or Greater are already - * defined below. Other header might define customized checkers by adding - * functions to caffe2::enforce_detail namespace. For example: - * - * namespace caffe2 { namespace enforce_detail { - * inline EnforceFailMessage IsVector(const vector& shape) { - * if (shape.size() == 1) { return EnforceOK(); } - * return MakeString("Shape ", shape, " is not a vector"); - * } - * }} - * - * With further usages like `CAFFE_ENFORCE_THAT(IsVector(Input(0).dims()))` - * - * Convenient wrappers for binary operations like CAFFE_ENFORCE_EQ are provided - * too. Please use them instead of CHECK_EQ and friends for failures in - * user-provided input. - */ - -namespace enforce_detail { - -struct EnforceOK {}; - -class EnforceFailMessage { - public: -#ifdef _MSC_VER - // MSVC + NVCC ignores constexpr and will issue a warning if included. - /* implicit */ EnforceFailMessage(EnforceOK) : msg_(nullptr) {} -#else - constexpr /* implicit */ EnforceFailMessage(EnforceOK) : msg_(nullptr) {} -#endif - EnforceFailMessage(EnforceFailMessage&&) = default; - EnforceFailMessage(const EnforceFailMessage&) = delete; - EnforceFailMessage& operator=(EnforceFailMessage&&) = delete; - EnforceFailMessage& operator=(const EnforceFailMessage&) = delete; - - // Catch all wrong usages like CAFFE_ENFORCE_THAT(x < y) - template - /* implicit */ EnforceFailMessage(Args...) { - static_assert( - // This stands for an "impossible" condition. Plain `false` doesn't - // trick compiler enough. - sizeof...(Args) == std::numeric_limits::max(), - "CAFFE_ENFORCE_THAT has to be used with one of special check functions " - "like `Equals`. Use CAFFE_ENFORCE for simple boolean checks."); - } - - /* implicit */ EnforceFailMessage(std::string&& msg) { - msg_ = new std::string(std::move(msg)); - } - inline bool bad() const { - return msg_ != nullptr; - } - std::string get_message_and_free(std::string&& extra) const { - std::string r; - if (extra.empty()) { - r = std::move(*msg_); - } else { - r = ::caffe2::MakeString(std::move(*msg_), ". ", std::move(extra)); - } - delete msg_; - return r; - } - - private: - std::string* msg_; -}; - -#define BINARY_COMP_HELPER(name, op) \ - template \ - inline EnforceFailMessage name(const T1& x, const T2& y) { \ - if (x op y) { \ - return EnforceOK(); \ - } \ - return MakeString(x, " vs ", y); \ - } -BINARY_COMP_HELPER(Equals, ==) -BINARY_COMP_HELPER(NotEquals, !=) -BINARY_COMP_HELPER(Greater, >) -BINARY_COMP_HELPER(GreaterEquals, >=) -BINARY_COMP_HELPER(Less, <) -BINARY_COMP_HELPER(LessEquals, <=) -#undef BINARY_COMP_HELPER - -#define CAFFE_ENFORCE_THAT_IMPL(condition, expr, ...) \ - do { \ - using namespace ::caffe2::enforce_detail; \ - const EnforceFailMessage& CAFFE_ENFORCE_THAT_IMPL_r_ = (condition); \ - if (CAFFE_ENFORCE_THAT_IMPL_r_.bad()) { \ - throw ::caffe2::EnforceNotMet( \ - __FILE__, \ - __LINE__, \ - expr, \ - CAFFE_ENFORCE_THAT_IMPL_r_.get_message_and_free( \ - ::caffe2::MakeString(__VA_ARGS__))); \ - } \ - } while (false) - -#define CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(condition, expr, ...) \ - do { \ - using namespace ::caffe2::enforce_detail; \ - const EnforceFailMessage& CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_ = \ - (condition); \ - if (CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_.bad()) { \ - throw ::caffe2::EnforceNotMet( \ - __FILE__, \ - __LINE__, \ - expr, \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER_r_.get_message_and_free( \ - ::caffe2::MakeString(__VA_ARGS__)), \ - this); \ - } \ - } while (false) -} - -#define CAFFE_ENFORCE_THAT(condition, ...) \ - CAFFE_ENFORCE_THAT_IMPL((condition), #condition, __VA_ARGS__) - -#define CAFFE_ENFORCE_EQ(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(Equals((x), (y)), #x " == " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_NE(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(NotEquals((x), (y)), #x " != " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_LE(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(LessEquals((x), (y)), #x " <= " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_LT(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(Less((x), (y)), #x " < " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_GE(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(GreaterEquals((x), (y)), #x " >= " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_GT(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL(Greater((x), (y)), #x " > " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_EQ_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(Equals((x), (y)), #x " == " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_NE_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(NotEquals((x), (y)), #x " != " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_LE_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(LessEquals((x), (y)), #x " <= " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_LT_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(Less((x), (y)), #x " < " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_GE_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(GreaterEquals((x), (y)), #x " >= " #y, __VA_ARGS__) -#define CAFFE_ENFORCE_GT_WITH_CALLER(x, y, ...) \ - CAFFE_ENFORCE_THAT_IMPL_WITH_CALLER(Greater((x), (y)), #x " > " #y, __VA_ARGS__) -} // namespace caffe2 - -#endif // CAFFE2_CORE_LOGGING_H_ diff --git a/app/src/main/cpp/caffe2/core/logging_is_google_glog.h b/app/src/main/cpp/caffe2/core/logging_is_google_glog.h deleted file mode 100644 index 7dd2b4f..0000000 --- a/app/src/main/cpp/caffe2/core/logging_is_google_glog.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CAFFE2_CORE_LOGGING_IS_GOOGLE_GLOG_H_ -#define CAFFE2_CORE_LOGGING_IS_GOOGLE_GLOG_H_ - -#include // because some of the caffe2 code uses e.g. std::setw -// Using google glog. For glog 0.3.2 versions, stl_logging.h needs to be before -// logging.h to actually use stl_logging. Because template magic. -// In addition, we do not do stl logging in .cu files because nvcc does not like -// it. Some mobile platforms do not like stl_logging, so we add an -// overload in that case as well. - -#if !defined(__CUDACC__) && !defined(CAFFE2_USE_MINIMAL_GOOGLE_GLOG) -#include -#else // !defined(__CUDACC__) && !!defined(CAFFE2_USE_MINIMAL_GOOGLE_GLOG) - -// here, we need to register a fake overload for vector/string - here, -// we just ignore the entries in the logs. - -#define INSTANTIATE_FOR_CONTAINER(container) \ - template \ - std::ostream& operator<<(std::ostream& out, const container&) { \ - return out; \ - } - -INSTANTIATE_FOR_CONTAINER(std::vector) -INSTANTIATE_FOR_CONTAINER(std::map) -INSTANTIATE_FOR_CONTAINER(std::set) -#undef INSTANTIATE_FOR_CONTAINER - -#endif - -#include - - -#endif // CAFFE2_CORE_LOGGING_IS_GOOGLE_GLOG_H_ diff --git a/app/src/main/cpp/caffe2/core/logging_is_not_google_glog.h b/app/src/main/cpp/caffe2/core/logging_is_not_google_glog.h deleted file mode 100644 index db7464a..0000000 --- a/app/src/main/cpp/caffe2/core/logging_is_not_google_glog.h +++ /dev/null @@ -1,210 +0,0 @@ -#ifndef CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ -#define CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/flags.h" - -// Log severity level constants. -const int FATAL = 3; -#if !defined(_MSC_VER) || !defined(ERROR) -// Windows defines the ERROR macro already, and as a result we will -// simply use that one. The downside is that one will now mix LOG(INFO) -// and LOG(ERROR) because ERROR is defined to be zero. Anyway, the -// recommended way is to use glog so fixing this is a low-pri item. -const int ERROR = 2; -#endif -const int WARNING = 1; -const int INFO = 0; -const char CAFFE2_SEVERITY_PREFIX[] = "FEWIV"; - -namespace caffe2 { -class MessageLogger { - public: - MessageLogger(const char *file, int line, int severity); - ~MessageLogger(); - // Return the stream associated with the logger object. - std::stringstream &stream() { return stream_; } - - private: - // When there is a fatal log, we simply abort. - void DealWithFatal() { abort(); } - - const char* tag_; - std::stringstream stream_; - int severity_; -}; - -// This class is used to explicitly ignore values in the conditional -// logging macros. This avoids compiler warnings like "value computed -// is not used" and "statement has no effect". -class LoggerVoidify { - public: - LoggerVoidify() { } - // This has to be an operator with a precedence lower than << but - // higher than ?: - void operator&(const std::ostream &s) { } -}; - -// Log a message and terminate. -template -void LogMessageFatal(const char *file, int line, const T &message) { - MessageLogger(file, line, FATAL).stream() << message; -} - -// Helpers for CHECK_NOTNULL(). Two are necessary to support both raw pointers -// and smart pointers. -template -T& CheckNotNullCommon(const char *file, int line, const char *names, T& t) { - if (t == nullptr) { - LogMessageFatal(file, line, std::string(names)); - } - return t; -} - -template -T* CheckNotNull(const char *file, int line, const char *names, T* t) { - return CheckNotNullCommon(file, line, names, t); -} - -template -T& CheckNotNull(const char *file, int line, const char *names, T& t) { - return CheckNotNullCommon(file, line, names, t); -} -} // namespace caffe2 - -// ---------------------- Logging Macro definitions -------------------------- - - -static_assert(CAFFE2_LOG_THRESHOLD <= FATAL, - "CAFFE2_LOG_THRESHOLD should at most be FATAL."); -// If n is under the compile time caffe log threshold, The _CAFFE_LOG(n) -// should not generate anything in optimized code. -#define LOG(n) \ - if (n >= CAFFE2_LOG_THRESHOLD) \ - ::caffe2::MessageLogger((char*)__FILE__, __LINE__, n).stream() -#define VLOG(n) LOG((-n)) - -#define LOG_IF(n, condition) \ - if (n >= CAFFE2_LOG_THRESHOLD && (condition)) \ - ::caffe2::MessageLogger((char*)__FILE__, __LINE__, n).stream() -#define VLOG_IF(n, condition) LOG_IF((-n), (condition)) - -// Log only if condition is met. Otherwise evaluates to void. -#define FATAL_IF(condition) \ - condition ? (void) 0 : ::caffe2::LoggerVoidify() & \ - ::caffe2::MessageLogger((char*)__FILE__, __LINE__, FATAL).stream() - -// Check for a given boolean condition. -#define CHECK(condition) FATAL_IF(condition) \ - << "Check failed: " #condition " " - -#ifndef NDEBUG -// Debug only version of CHECK -#define DCHECK(condition) FATAL_IF(condition) \ - << "Check failed: " #condition " " -#else -// Optimized version - generates no code. -#define DCHECK(condition) if(false) CHECK(condition) -#endif // NDEBUG - -#define CHECK_OP(val1, val2, op) FATAL_IF((val1 op val2)) \ - << "Check failed: " #val1 " " #op " " #val2 " " - -// Check_op macro definitions -#define CHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) -#define CHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) -#define CHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) -#define CHECK_LT(val1, val2) CHECK_OP(val1, val2, <) -#define CHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) -#define CHECK_GT(val1, val2) CHECK_OP(val1, val2, >) - -#ifndef NDEBUG -// Debug only versions of CHECK_OP macros. -#define DCHECK_EQ(val1, val2) CHECK_OP(val1, val2, ==) -#define DCHECK_NE(val1, val2) CHECK_OP(val1, val2, !=) -#define DCHECK_LE(val1, val2) CHECK_OP(val1, val2, <=) -#define DCHECK_LT(val1, val2) CHECK_OP(val1, val2, <) -#define DCHECK_GE(val1, val2) CHECK_OP(val1, val2, >=) -#define DCHECK_GT(val1, val2) CHECK_OP(val1, val2, >) -#else // !NDEBUG -// These versions generate no code in optimized mode. -#define DCHECK_EQ(val1, val2) if(false) CHECK_OP(val1, val2, ==) -#define DCHECK_NE(val1, val2) if(false) CHECK_OP(val1, val2, !=) -#define DCHECK_LE(val1, val2) if(false) CHECK_OP(val1, val2, <=) -#define DCHECK_LT(val1, val2) if(false) CHECK_OP(val1, val2, <) -#define DCHECK_GE(val1, val2) if(false) CHECK_OP(val1, val2, >=) -#define DCHECK_GT(val1, val2) if(false) CHECK_OP(val1, val2, >) -#endif // NDEBUG - -// Check that a pointer is not null. -#define CHECK_NOTNULL(val) \ - ::caffe2::CheckNotNull( \ - __FILE__, __LINE__, "Check failed: '" #val "' Must be non NULL", (val)) - -#ifndef NDEBUG -// Debug only version of CHECK_NOTNULL -#define DCHECK_NOTNULL(val) \ - ::caffe2::CheckNotNull( \ - __FILE__, __LINE__, "Check failed: '" #val "' Must be non NULL", (val)) -#else // !NDEBUG -// Optimized version - generates no code. -#define DCHECK_NOTNULL(val) if (false) CHECK_NOTNULL(val) -#endif // NDEBUG - -// ---------------------- Support for std objects -------------------------- -// These are adapted from glog to support a limited set of logging capability -// for STL objects. - -namespace caffe2 { -// Forward declare these two, and define them after all the container streams -// operators so that we can recurse from pair -> container -> container -> pair -// properly. -template -std::ostream& operator<<( - std::ostream& out, const std::pair& p); -template -void PrintSequence(std::ostream& ss, Iter begin, Iter end); - -#define INSTANTIATE_FOR_CONTAINER(container) \ -template \ -std::ostream& operator<<( \ - std::ostream& out, const container& seq) { \ - PrintSequence(out, seq.begin(), seq.end()); \ - return out; \ -} - -INSTANTIATE_FOR_CONTAINER(std::vector) -INSTANTIATE_FOR_CONTAINER(std::map) -INSTANTIATE_FOR_CONTAINER(std::set) -#undef INSTANTIATE_FOR_CONTAINER - -template -inline std::ostream& operator<<( - std::ostream& out, const std::pair& p) { - out << '(' << p.first << ", " << p.second << ')'; - return out; -} - -template -inline void PrintSequence(std::ostream& out, Iter begin, Iter end) { - // Output at most 100 elements -- appropriate if used for logging. - for (int i = 0; begin != end && i < 100; ++i, ++begin) { - if (i > 0) out << ' '; - out << *begin; - } - if (begin != end) { - out << " ..."; - } -} -} // namespace caffe2 - -#endif // CAFFE2_CORE_LOGGING_IS_NOT_GOOGLE_GLOG_H_ diff --git a/app/src/main/cpp/caffe2/core/macros.h b/app/src/main/cpp/caffe2/core/macros.h deleted file mode 100644 index 5382a73..0000000 --- a/app/src/main/cpp/caffe2/core/macros.h +++ /dev/null @@ -1,43 +0,0 @@ -// Automatically generated header file for caffe2 macros. These -// macros are used to build the Caffe2 binary, and if you are -// building a dependent library, they will need to be set as well -// for your program to link correctly. - -#pragma once - -// Caffe2 version. The plan is to increment the minor version every other week -// as a track point for bugs, until we find a proper versioning cycle. - -#define CAFFE2_VERSION_MAJOR 0 -#define CAFFE2_VERSION_MINOR 8 -#define CAFFE2_VERSION_PATCH 1 -#define CAFFE2_GIT_VERSION "" - -static_assert( - CAFFE2_VERSION_MINOR < 100, - "Programming error: you set a minor version that is too big."); -static_assert( - CAFFE2_VERSION_PATCH < 100, - "Programming error: you set a patch version that is too big."); - -#define CAFFE2_VERSION \ - (CAFFE2_VERSION_MAJOR * 10000 + CAFFE2_VERSION_MINOR * 100 + \ - CAFFE2_VERSION_PATCH) - -/* #undef CAFFE2_ANDROID */ -/* #undef CAFFE2_FORCE_FALLBACK_CUDA_MPI */ -/* #undef CAFFE2_HAS_MKL_DNN */ -/* #undef CAFFE2_HAS_MKL_SGEMM_PACK */ -/* #undef CAFFE2_PERF_WITH_AVX */ -/* #undef CAFFE2_PERF_WITH_AVX2 */ -/* #undef CAFFE2_THREADPOOL_MAIN_IMBALANCE */ -/* #undef CAFFE2_THREADPOOL_STATS */ -#define CAFFE2_UNIQUE_LONG_TYPEMETA -/* #undef CAFFE2_USE_ACCELERATE */ -#define CAFFE2_USE_EIGEN_FOR_BLAS -/* #undef CAFFE2_USE_FBCODE */ -/* #undef CAFFE2_USE_GFLAGS */ -/* #undef CAFFE2_USE_GOOGLE_GLOG */ -/* #undef CAFFE2_USE_LITE_PROTO */ -/* #undef CAFFE2_USE_MKL */ -/* #undef CAFFE2_USE_NVTX */ diff --git a/app/src/main/cpp/caffe2/core/memonger.h b/app/src/main/cpp/caffe2/core/memonger.h deleted file mode 100644 index fe65ae5..0000000 --- a/app/src/main/cpp/caffe2/core/memonger.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef CAFFE2_CORE_MEMONGER_H_ -#define CAFFE2_CORE_MEMONGER_H_ - -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { -namespace memonger { - -NetDef optimize_inference_net( - const NetDef& net, - const std::set& static_blobs); - -NetDef compute_blob_recycling_for_dag( - const NetDef& net, - const std::vector& heads, - const std::vector& op_indices, - const std::unordered_set& shareable_blob_names, - const string& namescope, - const std::unordered_set& dont_share_blob_names, - const std::unordered_map>& blob_shapes); - -} // memonger -} // caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/core/net.h b/app/src/main/cpp/caffe2/core/net.h deleted file mode 100644 index 98161b6..0000000 --- a/app/src/main/cpp/caffe2/core/net.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef CAFFE2_CORE_NET_H_ -#define CAFFE2_CORE_NET_H_ - -#include -#include -#include -#include // NOLINT -#include -#include -#include - -#include "caffe2/core/blob.h" -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/observer.h" -#include "caffe2/core/operator_schema.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/simple_queue.h" - -namespace caffe2 { - -class NetBase; -typedef ObserverBase NetObserver; -typedef std::function(NetBase*)> - NetObserverCreator; - -class OperatorBase; -class Workspace; -// Net is a thin struct that owns all the operators together with the operator -// contexts. -class NetBase { - public: - NetBase(const std::shared_ptr& net_def, Workspace* ws); - virtual ~NetBase() noexcept {} - virtual bool RunAsync() = 0; - virtual bool SupportsAsync() = 0; - inline const vector& events() const { - return events_; - } - - inline bool Run() { - if (!RunAsync()) { - return false; - } - for (const Event* event : events_) { - event->Finish(); - } - return true; - } - - /** - * Benchmarks a network. - * - * This function returns a vector of float recording the number of milli- - * seconds spent during the benchmark. The 0-th item is the time spent per - * each network run, and if a net instantiation supports run_individual, - * the remainder of the vector returns the number of milliseconds spent per - * opeartor. - */ - virtual vector TEST_Benchmark( - const int /*warmup_runs*/, - const int /*main_runs*/, - const bool /*run_individual*/) { - LOG(ERROR) << "Benchmark not implemented for this net type."; - return vector(); - } - - inline const vector& external_output() const { - return external_output_; - } - - inline const vector& external_input() const { - return external_input_; - } - - /* Used to attach Observers to operators of a Net - * - * Returns pointers to objects owned with unique_ptrs. - * Use with caution. - */ - virtual vector GetOperators() const = 0; - - void SetObserver(std::unique_ptr observer) { - observer_ = std::move(observer); - } - - void RemoveObserver() { - observer_ = nullptr; - } - - NetObserver* GetObserver() { - return observer_.get(); - } - - const string& Name() const { - return name_; - } - - protected: - vector external_input_; - vector external_output_; - string name_; - std::unique_ptr observer_; - vector events_; - - DISABLE_COPY_AND_ASSIGN(NetBase); -}; - -CAFFE_DECLARE_REGISTRY( - NetRegistry, - NetBase, - const std::shared_ptr&, - Workspace*); -#define REGISTER_NET_CREATOR(key, ...) \ - CAFFE_REGISTER_CREATOR(NetRegistry, key, __VA_ARGS__) -#define REGISTER_NET(name, ...) \ - CAFFE_REGISTER_CLASS(NetRegistry, name, __VA_ARGS__) - -/** - * @brief Creates a network, accessing / creating blobs in the given workspace. - * - * Note that this is different from Workspace::CreateNet. The latter adds the - * created net object to the workspace's net map, while this function returns - * a standalone net object. - */ -unique_ptr CreateNet(const NetDef& net_def, Workspace* ws); -unique_ptr CreateNet( - const std::shared_ptr& net_def, - Workspace* ws); - -void SetGlobalNetObserverCreator(NetObserverCreator creator); - -} // namespace caffe2 - -#endif // CAFFE2_CORE_NET_H_ diff --git a/app/src/main/cpp/caffe2/core/net_async_dag_gpu.h b/app/src/main/cpp/caffe2/core/net_async_dag_gpu.h deleted file mode 100644 index 473c11a..0000000 --- a/app/src/main/cpp/caffe2/core/net_async_dag_gpu.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CAFFE2_CORE_NET_ASYNC_DAG_GPU_H_ -#define CAFFE2_CORE_NET_ASYNC_DAG_GPU_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/net_dag.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -// Run an event-driven graph - before each operator chain, wait on each parent -// operator for the chain source, then execute each operator. Due to the chain -// construction mechanism, operators in the same chain implicitly runs on the -// same stream. -// AsyncDAGNet is only registered in gpu mode, because CPU code is always sync -// and a CPU only AsyncDAG net is essentially a DAG net. -class AsyncDAGNet : public DAGNetBase { - public: - AsyncDAGNet(const std::shared_ptr& net_def, Workspace* ws); - bool SupportsAsync() override { - return true; - } - bool RunAt(const std::vector& chain) override; - bool RunAsync() override; - - protected: - // Tracks whether a given op has had an event recorded in each - // RunAt() iteration. - std::vector eventRecorded_; - DISABLE_COPY_AND_ASSIGN(AsyncDAGNet); -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_NET_ASYNC_DAG_GPU_H_ diff --git a/app/src/main/cpp/caffe2/core/net_dag.h b/app/src/main/cpp/caffe2/core/net_dag.h deleted file mode 100644 index ba1d59e..0000000 --- a/app/src/main/cpp/caffe2/core/net_dag.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef CAFFE2_CORE_NET_DAG_H_ -#define CAFFE2_CORE_NET_DAG_H_ - -#include -#include -#include -#include // NOLINT -#include -#include -#include - -#include "caffe2/core/blob.h" -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/net.h" -#include "caffe2/core/observer.h" -#include "caffe2/core/operator_schema.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/simple_queue.h" - -namespace caffe2 { - -namespace internal { -struct OperatorNode { - unique_ptr operator_; - vector children_; - vector parents_; - std::atomic runtime_parent_count_; - bool is_chain_start_ = false; -}; - -struct OpGraphNode { - vector children_; - vector parents_; - int visited_inputs = 0; - int num_orig_parents; -}; -} - -class DAGNetBase : public NetBase { - public: - using ExecutionChains = std::unordered_map>; - DAGNetBase(const std::shared_ptr& net_def, Workspace* ws); - ~DAGNetBase() override; - bool RunAsync() override; - // WorkerFunction() is a function wrapper to allow us to run worker threads. - // It checks out one ready-to-run operator from the job queue, runs it, - // notifies all its children, and for any children that is ready, enqueues - // it to the job queue. - void WorkerFunction(); - vector TEST_Benchmark( - const int warmup_runs, - const int main_runs, - const bool run_individual) override; - - const ExecutionChains& TEST_execution_chains() const { - return execution_chains_; - } - - vector GetOperators() const override { - vector op_list; - for (auto& op_node : operator_nodes_) { - op_list.push_back(op_node.operator_.get()); - } - return op_list; - } - - protected: - virtual bool RunAt(const std::vector& chain) = 0; - - vector operator_nodes_; - ExecutionChains execution_chains_; - vector initial_frontier_; - std::unique_ptr> job_queue_; - std::vector workers_; - int num_workers_; - int num_workers_first_iteration_; - int remaining_ops_; - - bool success_; - int iter_; - std::mutex remaining_ops_mutex_; - std::condition_variable cv_; - std::mutex run_in_progress_; - - DISABLE_COPY_AND_ASSIGN(DAGNetBase); -}; - -class DAGNet : public DAGNetBase { - public: - using DAGNetBase::DAGNetBase; - - protected: - bool RunAt(const std::vector& chain) override; - bool SupportsAsync() override { - return false; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_NET_DAG_H_ diff --git a/app/src/main/cpp/caffe2/core/net_simple.h b/app/src/main/cpp/caffe2/core/net_simple.h deleted file mode 100644 index 8ca3b77..0000000 --- a/app/src/main/cpp/caffe2/core/net_simple.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef CAFFE2_CORE_NET_SIMPLE_H_ -#define CAFFE2_CORE_NET_SIMPLE_H_ - -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/net.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -// This is the very basic structure you need to run a network - all it -// does is simply to run everything in sequence. If you want more fancy control -// such as a DAG-like execution, check out other better net implementations. -class SimpleNet : public NetBase { - public: - SimpleNet(const std::shared_ptr& net_def, Workspace* ws); - bool SupportsAsync() override { - return false; - } - bool RunAsync() override; - vector TEST_Benchmark( - const int warmup_runs, - const int main_runs, - const bool run_individual) override; - - /* - * This returns a list of pointers to objects stored in unique_ptrs. - * Used by Observers. - * - * Think carefully before using. - */ - vector GetOperators() const override { - vector op_list; - for (auto& op : operators_) { - op_list.push_back(op.get()); - } - return op_list; - } - - protected: - vector> operators_; - - DISABLE_COPY_AND_ASSIGN(SimpleNet); -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_NET_SIMPLE_H_ diff --git a/app/src/main/cpp/caffe2/core/net_simple_async.h b/app/src/main/cpp/caffe2/core/net_simple_async.h deleted file mode 100644 index 5d84805..0000000 --- a/app/src/main/cpp/caffe2/core/net_simple_async.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef CAFFE2_CORE_NET_SIMPLE_ASYNC_H_ -#define CAFFE2_CORE_NET_SIMPLE_ASYNC_H_ - -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/net.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -// This is the very basic structure you need to run a network - all it -// does is simply to run everything in sequence. If you want more fancy control -// such as a DAG-like execution, check out other better net implementations. -class AsyncSimpleNet : public NetBase { - public: - AsyncSimpleNet(const std::shared_ptr& net_def, Workspace* ws); - - bool SupportsAsync() override { - return true; - } - bool RunAsync() override; - - vector TEST_Benchmark( - const int warmup_runs, - const int main_runs, - const bool run_individual) override; - - /* - * This returns a list of pointers to objects stored in unique_ptrs. - * Used by Observers. - * - * Think carefully before using. - */ - vector GetOperators() const override { - vector op_list; - for (auto& op : operators_) { - op_list.push_back(op.get()); - } - return op_list; - } - - protected: - vector> operators_; - - DISABLE_COPY_AND_ASSIGN(AsyncSimpleNet); -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_NET_SIMPLE_ASYNC_H_ diff --git a/app/src/main/cpp/caffe2/core/observer.h b/app/src/main/cpp/caffe2/core/observer.h deleted file mode 100644 index 0b2e4ec..0000000 --- a/app/src/main/cpp/caffe2/core/observer.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -namespace caffe2 { - -/** - * Use this to implement a Observer using the Observer Pattern template. - */ - -template -class ObserverBase { - public: - explicit ObserverBase(T* subject) : subject_(subject) {} - - virtual bool Start() { - return false; - } - virtual bool Stop() { - return false; - } - - virtual ~ObserverBase() noexcept {}; - - T* subject() const { - return subject_; - } - - protected: - T* subject_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/core/operator.h b/app/src/main/cpp/caffe2/core/operator.h deleted file mode 100644 index be5cbf5..0000000 --- a/app/src/main/cpp/caffe2/core/operator.h +++ /dev/null @@ -1,690 +0,0 @@ -#ifndef CAFFE2_CORE_OPERATOR_H_ -#define CAFFE2_CORE_OPERATOR_H_ - -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/blob.h" -#include "caffe2/core/common.h" -#include "caffe2/core/net.h" -#include "caffe2/core/observer.h" -#include "caffe2/core/operator_gradient.h" -#include "caffe2/core/operator_schema.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -class OperatorBase { - public: - explicit OperatorBase(const OperatorDef& operator_def, Workspace* ws); - virtual ~OperatorBase() noexcept {} - - /** @brief Checks if the operator has an argument of the given name. - */ - inline bool HasArgument(const string& name) const { - CAFFE_ENFORCE(operator_def_, "operator_def was null!"); - return ArgumentHelper::HasArgument(*operator_def_, name); - } - - // Functions that deal with arguments. Basically, this allows us to map an - // argument name to a specific type of argument that we are trying to access. - template - inline T GetSingleArgument(const string& name, const T& default_value) const { - CAFFE_ENFORCE(operator_def_, "operator_def was null!"); - return ArgumentHelper::GetSingleArgument( - *operator_def_, name, default_value); - } - template - inline bool HasSingleArgumentOfType(const string& name) const { - CAFFE_ENFORCE(operator_def_, "operator_def was null!"); - return ArgumentHelper::HasSingleArgumentOfType( - *operator_def_, name); - } - template - inline vector GetRepeatedArgument( - const string& name, - const vector& default_value = {}) const { - CAFFE_ENFORCE(operator_def_, "operator_def was null!"); - return ArgumentHelper::GetRepeatedArgument( - *operator_def_, name, default_value); - } - - // Get the inputs and outputs as specific types. - template - inline const T& Input(int idx) { - DCHECK_LT(idx, inputs_.size()); - try { - return inputs_.at(idx)->template Get(); - } catch (::caffe2::EnforceNotMet& enf) { - if (has_debug_def()) { - enf.AppendMessage(".\nOffending Blob name: "); - enf.AppendMessage(debug_def().input(idx)); - enf.AppendMessage(".\n"); - } - throw enf; - } - } - - template - inline T* Output(int idx) { - return outputs_.at(idx)->template GetMutable(); - } - - inline const Blob& InputBlob(int idx) { - return *inputs_.at(idx); - } - - inline Blob* OutputBlob(int idx) { - return outputs_.at(idx); - } - - template - inline bool InputIsType(int idx) { - return inputs_.at(idx)->template IsType(); - } - - template - inline bool OutputIsType(int idx) { - return outputs_.at(idx)->template IsType(); - } - - inline int InputSize() { return inputs_.size(); } - inline int OutputSize() { return outputs_.size(); } - inline const vector& Inputs() const { return inputs_; } - inline const vector& Outputs() { return outputs_; } - vector InputTensorShapes(); - - virtual void WaitEvent(const Event& ev) { - CAFFE_NOT_IMPLEMENTED; - } - - inline void Wait(const OperatorBase& other) { - WaitEvent(other.event()); - } - - virtual void Record() { - CAFFE_NOT_IMPLEMENTED; - } - - virtual bool Run(int /* unused */ /*stream_id*/ = 0) { - CAFFE_NOT_IMPLEMENTED; - } - - // RunAsync, if implemenented by the specific operators, will schedule the - // computation on the corresponding context and record the event in its - // event_ member object. If the specific operator does not support RunAsync, - // it will simply be synchronous as a fallback. - virtual bool RunAsync(int stream_id = 0) { - return Run(stream_id); - } - - virtual void AddRelatedBlobInfo(EnforceNotMet* err) { - if (!has_debug_def()) { - return; - } - - bool found_input; - if (err->caller() != nullptr) { - for (int i = 0; i < inputs_.size(); i++) { - if (inputs_[i]->GetRaw() == err->caller()) { - found_input = true; - err->AppendMessage( - "\n** while accessing input: " + debug_def().input(i)); - break; - } - } - for (int i = 0; i < outputs_.size(); i++) { - if (outputs_[i]->GetRaw() == err->caller()) { - if (found_input) { - err->AppendMessage("\n OR "); - } - err->AppendMessage( - "\n** while accessing output: " + debug_def().output(i)); - break; - } - } - } - } - - inline const OperatorDef& debug_def() const { - CAFFE_ENFORCE(has_debug_def(), "operator_def was null!"); - return *operator_def_; - } - - inline void set_debug_def( - const std::shared_ptr& operator_def) { - operator_def_ = operator_def; - } - - inline bool has_debug_def() const { - return operator_def_ != nullptr; - } - - public: - void SetObserver(std::unique_ptr> observer) { - observer_ = std::move(observer); - } - - void RemoveObserver() { - observer_ = nullptr; - } - - void RecordLastFailedOpNetPosition() { - if (net_position_ != kNoNetPositionSet) { - VLOG(1) << "Operator with id " << net_position_ << " failed"; - operator_ws_->last_failed_op_net_position = net_position_; - } else { - VLOG(1) << "Failed operator doesn't have id set"; - } - } - - int net_position() const { - return net_position_; - } - - void set_net_position(int idx) { - net_position_ = idx; - } - - const DeviceOption& device_option() { - return device_option_; - } - - const Event& event() const { - return event_; - } - - const std::string& type() { - CAFFE_ENFORCE(operator_def_.get() != nullptr); - return operator_def_->type(); - } - - public: - static constexpr int kNoNetPositionSet = -1; - - ObserverBase* GetObserver() { - return observer_.get(); - } - - const ObserverBase* GetObserver() const { - return observer_.get(); - } - - private: - Workspace* operator_ws_; - std::shared_ptr operator_def_; - DeviceOption device_option_; - vector inputs_; - vector outputs_; - - int net_position_{kNoNetPositionSet}; - - protected: - std::unique_ptr> observer_; - // An event used by asynchronous execution. - Event event_; - - DISABLE_COPY_AND_ASSIGN(OperatorBase); -}; - -// If your operator does not need any specialized contructor or destructor, -// you can simply use this to save two lines of code. -#define USE_SIMPLE_BASE_CTOR_DTOR(name) \ - name(const OperatorDef& operator_def, Workspace* ws) \ - : OperatorBase(operator_def, ws) {} \ - virtual ~name() noexcept {} - -// OP_SINGLE_ARG provides a shorter initialization choice for initialization of -// member variables for the class constructors. -#define OP_SINGLE_ARG(type, name, variable, default) \ - variable(OperatorBase::GetSingleArgument(name, (default))) - -// INPUT_TAGS and OUTPUT_TAGS are optional features to name the indices of the -// operator's inputs and outputs, in order to avoid confusion. For example, for -// a fully convolution layer that has input, weight and bias, you can define its -// input tags as: -// INPUT_TAGS(INPUT, WEIGHT, BIAS); -// And in the code, instead of doing -// auto& weight = Input(1); -// you can now do -// auto& weight = Input(WEIGHT); -// to make it more clear. -#define INPUT_TAGS(first_input, ...) \ - enum _InputTags { first_input = 0, __VA_ARGS__ } -#define OUTPUT_TAGS(first_input, ...) \ - enum _OutputTags { first_input = 0, __VA_ARGS__ } - - -// Operator is the class that you usually want to derive, if your operator will -// run on different devices. You should then implement the RunOnDevice() -// function. -template -class Operator : public OperatorBase { - public: - explicit Operator(const OperatorDef& operator_def, Workspace* ws) - : OperatorBase(operator_def, ws), - context_(operator_def.device_option()) { - // In the constructor, we switch to the device so that the child class - // constructors will run on that device. - context_.SwitchToDevice(0); - } - ~Operator() noexcept override {} - - inline const Tensor& Input(int idx) { - return OperatorBase::template Input >(idx); } - inline Tensor* Output(int idx) { - return OperatorBase::template Output>(idx); - } - - void WaitEvent(const Event& ev) final { - context_.SwitchToDevice(); - context_.WaitEvent(ev); - } - - void Record() final { - context_.SwitchToDevice(); - context_.Record(&event_); - } - - // The run function of Operator switches to the device, and then carries out - // the actual computation with RunOnDevice(). You should implement RunOnDevice - // instead of Run(). - bool Run(int stream_id = 0) final { - try { - if (observer_) { - observer_->Start(); - } - context_.SwitchToDevice(stream_id); - bool result = RunOnDevice(); - if (!result) { - this->RecordLastFailedOpNetPosition(); - } - context_.FinishDeviceComputation(); // throws on error - if (observer_) { - observer_->Stop(); - } - - return result; - } catch (EnforceNotMet& err) { - if (has_debug_def()) { - err.AppendMessage( - "Error from operator: \n" + ProtoDebugString(debug_def())); - AddRelatedBlobInfo(&err); - } - this->RecordLastFailedOpNetPosition(); - throw; - } catch (...) { - this->RecordLastFailedOpNetPosition(); - throw; - } - } - - bool RunAsync(int stream_id = 0) final { - try { - context_.SwitchToDevice(stream_id); - auto result = RunOnDevice(); - if (!result) { - this->RecordLastFailedOpNetPosition(); - } - context_.Record(&event_); - return result; - } catch (EnforceNotMet& err) { - if (has_debug_def()) { - err.AppendMessage( - "Error from operator: \n" + ProtoDebugString(debug_def())); - AddRelatedBlobInfo(&err); - } - this->RecordLastFailedOpNetPosition(); - throw; - } catch (...) { - this->RecordLastFailedOpNetPosition(); - throw; - } - } - - virtual bool RunOnDevice() = 0; - - protected: - Context context_; -}; - -#define USE_OPERATOR_BASE_FUNCTIONS \ - /* using override */ using OperatorBase::HasArgument; \ - /* using override */ using OperatorBase::GetSingleArgument; \ - /* using override */ using OperatorBase::HasSingleArgumentOfType; \ - /* using override */ using OperatorBase::GetRepeatedArgument; \ - /* using override */ using OperatorBase::InputIsType; \ - /* using override */ using OperatorBase::InputSize; \ - /* using override */ using OperatorBase::OutputSize - -#define USE_OPERATOR_FUNCTIONS(context) \ - USE_OPERATOR_BASE_FUNCTIONS; \ - /* using override */ using Operator::context_; \ - /* using override */ using Operator::Input; \ - /* using override */ using Operator::Output - -#define USE_OPERATOR_CONTEXT_FUNCTIONS USE_OPERATOR_FUNCTIONS(Context) - -#define USE_SIMPLE_CTOR_DTOR(name) \ - name(const OperatorDef& operator_def, Workspace* ws) \ - : Operator(operator_def, ws) {} \ - virtual ~name() noexcept {} - -// Helpers to implement runtime op polymorphism. Often it's convenient to make -// an op work on different input types (e.g. i32 vs i64 indices) or special-case -// it for particular input size (e.g. ScatterWeightedSum for block size of 1 -// doesn't need to call Eigen). -// -// DispatchHelper provides compile-time generation of nested "if" statements, -// e.g. `DispatchHelper>::call(this, block_size);` -// unrolls into: -// if (block_size == 1) { -// return DoRunWithValue<1>(); -// } else if (block_size = 4) { -// return DoRunWithValue<4>(); -// } else { -// return DoRunWithValue<-1>(); -// }` -// -// DoRunWithValue implementation can use template arguments to do "if" -// statements -// or proxy to functions in math.h which often provide fixed size -// implementation. -// -// Similarly `TensorTypes(this, Input(0))` provides branching -// based on type of the first input and calls DoRunWithType. -// -// Note, that the same instance of Op class is used as the method, not class is -// templated. We might consider adding static class-level polymorphism later. -// -// Convenient macro USE_DISPATCH_HELPER is provided for declaring friendship in -// case DoRunWithValue or DoRunWithType are declared non-public. - -#define USE_DISPATCH_HELPER \ - template \ - friend struct DispatchHelper - -template -struct FixedValues {}; - -template -struct TensorTypes {}; - -// Special tag that can be listed in TensorTypes to denote that a special -// implementation in 'RunWithOtherType' needs to be called instead of failing -// Obviously this needs to be the last item in lists, e.g. -// TensorTypes -struct GenericTensorImplementation {}; - -// Same as TensorTypes but call DoRunWithType2 -template -struct TensorTypes2 {}; - -template -struct DispatchHelper; - -template -struct DispatchHelper, ExtraArgs...> { - template - static bool call(Op* op, int value) { - if (FirstVal == value) { - return op->template DoRunWithValue(); - } - return DispatchHelper, ExtraArgs...>::template call< - Op>(op, value); - } -}; - -template -struct DispatchHelper, ExtraArgs...> { - template - static bool call(Op* op, TIndex /*size*/) { - return op->template DoRunWithValue(); - } -}; - -#define CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER( \ - TensorTypes, DoRunWithType, DoRunWithOtherType) \ - template \ - struct DispatchHelper, ExtraArgs...> { \ - template \ - static bool call(Op* op, const TypeMeta& meta) { \ - static_assert( \ - !std::is_same::value, \ - "GenericTensorImplementation must be the last in TensorTypes list"); \ - if (meta.Match()) { \ - return op->template DoRunWithType(); \ - } \ - return DispatchHelper, ExtraArgs...>:: \ - template call(op, meta); \ - } \ - template \ - static bool call(Op* op, const Tensor& tensor) { \ - return call(op, tensor.meta()); \ - } \ - template \ - static bool call(Op* op, const Blob& blob) { \ - return call(op, blob.meta()); \ - } \ - }; \ - \ - template \ - struct DispatchHelper, ExtraArgs...> { \ - template \ - static bool call(Op* /* unused */, const TypeMeta& meta) { \ - CAFFE_THROW("Unsupported type of tensor: ", meta.name()); \ - } \ - template \ - static bool call(Op* op, const Tensor& tensor) { \ - return call(op, tensor.meta()); \ - } \ - template \ - static bool call(Op* op, const Blob& blob) { \ - return call(op, blob.meta()); \ - } \ - }; \ - \ - template \ - struct DispatchHelper< \ - TensorTypes, \ - ExtraArgs...> { \ - template \ - static bool call(Op* op, const TypeMeta&) { \ - return op->template DoRunWithOtherType(); \ - } \ - template \ - static bool call(Op* op, const Tensor& tensor) { \ - return call(op, tensor.meta()); \ - } \ - template \ - static bool call(Op* op, const Blob& blob) { \ - return call(op, blob.meta()); \ - } \ - }; -CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER( - TensorTypes, - DoRunWithType, - DoRunWithOtherType) -CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER( - TensorTypes2, - DoRunWithType2, - DoRunWithOtherType2) -#undef CAFFE2_DEFINE_TENSOR_TYPES_DISPATCHER - -// The device type registry. This works in two phases: -// (1) gDeviceTypeRegistry() maps the device types values to the actual operator -// registry function. -// (2) Then, one can call the operator registry function to further create the -// operators. -typedef Registry - OperatorRegistry; -typedef Registry* ( - *RegistryFunction)(); -std::map* gDeviceTypeRegistry(); - -struct DeviceTypeRegisterer { - explicit DeviceTypeRegisterer(int32_t type, RegistryFunction func) { - if (gDeviceTypeRegistry()->count(type)) { - std::cerr << "Device type " << type - << "registered twice. This should not happen. Did you have " - "duplicated numbers assigned to different devices?"; - std::exit(1); - } - // Calling the registry function to get the actual registry pointer. - gDeviceTypeRegistry()->emplace(type, func()); - } -}; - -#define CAFFE_REGISTER_DEVICE_TYPE(type, registry_function) \ - namespace { \ - static DeviceTypeRegisterer CAFFE_ANONYMOUS_VARIABLE( \ - DeviceType)(type, ®istry_function); \ - } - -// The operator registry. Since we are not expecting a great number of devices, -// we will simply have an if-then type command and allocate the actual -// generation to device-specific registerers. -// Note that although we have CUDA and CUDNN here, the registerers themselves do -// not depend on specific cuda or cudnn libraries. This means that we will be -// able to compile it even when there is no cuda available - we simply do not -// link any cuda or cudnn operators. -CAFFE_DECLARE_REGISTRY( - CPUOperatorRegistry, - OperatorBase, - const OperatorDef&, - Workspace*); -#define REGISTER_CPU_OPERATOR_CREATOR(key, ...) \ - CAFFE_REGISTER_CREATOR(CPUOperatorRegistry, key, __VA_ARGS__) -#define REGISTER_CPU_OPERATOR(name, ...) \ - extern void CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(); \ - static void CAFFE2_UNUSED CAFFE_ANONYMOUS_VARIABLE_CPU##name() { \ - CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(); \ - } \ - CAFFE_REGISTER_CLASS(CPUOperatorRegistry, name, __VA_ARGS__) -#define REGISTER_CPU_OPERATOR_STR(str_name, ...) \ - CAFFE_REGISTER_TYPED_CLASS(CPUOperatorRegistry, str_name, __VA_ARGS__) - -#define REGISTER_CPU_OPERATOR_WITH_ENGINE(name, engine, ...) \ - CAFFE_REGISTER_CLASS(CPUOperatorRegistry, name##_ENGINE_##engine, __VA_ARGS__) - -CAFFE_DECLARE_REGISTRY( - CUDAOperatorRegistry, - OperatorBase, - const OperatorDef&, - Workspace*); -#define REGISTER_CUDA_OPERATOR_CREATOR(key, ...) \ - CAFFE_REGISTER_CREATOR(CUDAOperatorRegistry, key, __VA_ARGS__) -#define REGISTER_CUDA_OPERATOR(name, ...) \ - extern void CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(); \ - static void CAFFE2_UNUSED CAFFE_ANONYMOUS_VARIABLE_CUDA##name() { \ - CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(); \ - } \ - CAFFE_REGISTER_CLASS(CUDAOperatorRegistry, name, __VA_ARGS__) -#define REGISTER_CUDA_OPERATOR_STR(str_name, ...) \ - CAFFE_REGISTER_TYPED_CLASS(CUDAOperatorRegistry, str_name, __VA_ARGS__) - -#define REGISTER_CUDA_OPERATOR_WITH_ENGINE(name, engine, ...) \ - CAFFE_REGISTER_CLASS( \ - CUDAOperatorRegistry, name##_ENGINE_##engine, __VA_ARGS__) - -// Macros for cudnn since we use it often -#define REGISTER_CUDNN_OPERATOR(name, ...) \ - REGISTER_CUDA_OPERATOR_WITH_ENGINE(name, CUDNN, __VA_ARGS__) - -// StaticLinkingProtector is a helper class that ensures that the Caffe2 -// library is linked correctly with whole archives (in the case of static -// linking). What happens is that when CreateOperator is called for the first -// time, it instantiates an OperatorLinkingProtector object to check if the -// operator registry is empty. If it is empty, this means that we are not -// properly linking the library. -// -// You should not need to use this class. -struct StaticLinkingProtector { - StaticLinkingProtector() { - const int registered_ops = CPUOperatorRegistry()->Keys().size(); - // Note: this is a check failure instead of an exception, because if - // the linking is wrong, Caffe2 won't be able to run properly anyway, - // so it's better to fail loud. - // If Caffe2 is properly linked with whole archive, there should be more - // than zero registered ops. - if (registered_ops == 0) { - LOG(FATAL) << - "You might have made a build error: the Caffe2 library does not seem " - "to be linked with whole-static library option. To do so, use " - "-Wl,-force_load (clang) or -Wl,--whole-archive (gcc) to link the " - "Caffe2 library."; - } - } -}; - -// An exception that can be thrown by an operator constructor that notifies -// that it does not support the given setting. This can be usually used for -// specific engines that only implement a subset of the features required by -// the original operator schema. -// TODO(jiayq): make more feature-complete exception message. -class UnsupportedOperatorFeature : public std::exception { - public: - UnsupportedOperatorFeature(const string& msg) : msg_(msg) {} - const char* what() const noexcept override { - return msg_.c_str(); - } - - private: - string msg_; -}; - -// A helper macro that should ONLY be used in the operator constructor to check -// if needed features are met. If not, throws the UnsupportedOperatorFeature -// exception with the given message. -#define OPERATOR_NEEDS_FEATURE(condition, ...) \ - if (!(condition)) { \ - throw UnsupportedOperatorFeature(::caffe2::MakeString(__VA_ARGS__)); \ - } - -// Creates an operator with the given operator definition. -// Throws on error and never returns nullptr -unique_ptr CreateOperator( - const OperatorDef& operator_def, - Workspace* ws, - int net_position = OperatorBase::kNoNetPositionSet); - -// User can set the preferred engines as a list of engine names, in -// descending order of preference. -using EnginePrefType = std::vector; -// {device_type -> {operator_name -> EnginePrefType}} -using PerOpEnginePrefType = - CaffeMap>; -// {device_type -> EnginePrefType} -using GlobalEnginePrefType = CaffeMap; -void SetPerOpEnginePref(const PerOpEnginePrefType& per_op_engine_pref); -void SetGlobalEnginePref(const GlobalEnginePrefType& global_engine_pref); -void SetEnginePref( - const PerOpEnginePrefType& per_op_engine_pref, - const GlobalEnginePrefType& global_engine_pref); -void SetOpEnginePref( - const std::string& op_type, - const CaffeMap& op_pref); - -TensorShapes InferBlobShapesAndTypesFromWorkspace( - Workspace* ws, - const vector>& nets); - -TensorShapes InferBlobShapesAndTypesFromMap( - const CaffeMap>& blob_dimensions, - const vector>& nets); - -std::map> ValidateTensorDevices( - OperatorBase& op, - const OperatorDef& op_def); - -} // namespace caffe2 - -#endif // CAFFE2_CORE_OPERATOR_H_ diff --git a/app/src/main/cpp/caffe2/core/operator_gradient.h b/app/src/main/cpp/caffe2/core/operator_gradient.h deleted file mode 100644 index 701bd1e..0000000 --- a/app/src/main/cpp/caffe2/core/operator_gradient.h +++ /dev/null @@ -1,330 +0,0 @@ -#ifndef CAFFE2_CORE_OPERATOR_GRADIENT_H_ -#define CAFFE2_CORE_OPERATOR_GRADIENT_H_ - -#include "caffe2/core/operator_schema.h" -#include "caffe2/core/registry.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -/* @brief A struct that abstracts on top of dense and sparse blobs. - * - * For a dense blob, its gradient name should be written into dense_, and for - * a sparse blob, its gradient name should be written into indice_ for - * the sparse indices and value_ for the values. - */ -struct GradientWrapper { - string dense_; - string indices_; - string values_; - - inline bool IsDense() const { - return dense_.size(); - } - inline bool IsSparse() const { - return (indices_.size() || values_.size()); - } - inline bool IsEmpty() const { - return (!IsDense() && !IsSparse()); - } -}; - -/** - * A struct that holds the gradient operators and related gradient maps. - */ -struct GradientOpsMeta { - vector ops_; - vector g_input_; - - GradientOpsMeta() {} - GradientOpsMeta( - const vector& ops, - const vector& v) - : ops_(ops), g_input_(v) {} -}; - -class GradientMakerBase { - public: - GradientMakerBase( - const OperatorDef& def, - const vector& g_output) - : def_(def), g_output_(g_output), g_input_(def.input_size()){}; - virtual ~GradientMakerBase() {} - virtual bool CopyDeviceOption() const { - return true; - } - virtual bool CopyEngine() const { - return true; - } - virtual bool CopyArguments() const { - return true; - } - - virtual void VerifyOp() const { - auto* schema = OpSchemaRegistry::Schema(def_.type()); - if (schema) { - CAFFE_ENFORCE( - schema->Verify(def_), - "(GradientMaker) Operator def did not pass schema checking: ", - ProtoDebugString(def_)); - } - } - - /** - * @brief Returns the gradient ops meta. - * - * If your gradient op generator only use standard input and output - * manipulations, you can simply implement GetGradientDefs() that - * returns vector. In that, you can call GI, GI_V and GI_I - * that will automatically create the gradient registration for you. - * - * If you need to do custom gradient name registration, overload this - * function directly. - */ - virtual GradientOpsMeta Get() { - VerifyOp(); - vector new_defs = GetGradientDefs(); - for (auto& opdef : new_defs) { - opdef.set_is_gradient_op(true); - } - return GradientOpsMeta(new_defs, g_input_); - }; - - const OperatorDef& Def() const { - return def_; - } - - protected: - virtual vector GetGradientDefs() { - CAFFE_NOT_IMPLEMENTED; - } - - // Helper functions to return names for the gradient computation. - // I(idx), O(idx): return the input and output names. - // GO(idx): return the name of the gradient for output idx. - // GI(idx), GI_I(idx), GI_V(idx): return the name of the gradient for - // input idx, and also registers that name into the gradient - // registry to be returned. - string I(const int i) { - CAFFE_ENFORCE((i >= 0) && (i < def_.input().size())); - return def_.input(i); - } - string O(const int i) { - CAFFE_ENFORCE((i >= 0) && (i < def_.output().size())); - return def_.output(i); - } - string GI(const int i) { - CAFFE_ENFORCE( - !g_input_.at(i).IsSparse(), - "Input ", - def_.input(i), - " already set to sparse."); - g_input_.at(i).dense_ = GradientName(def_.input(i)); - return GradientName(def_.input(i)); - } - string GI_I(const int i) { - CAFFE_ENFORCE( - !g_input_.at(i).IsDense(), - "Input ", - def_.input(i), - " already set to dense."); - g_input_.at(i).indices_ = GradientSliceIndices(def_.input(i)); - return GradientSliceIndices(def_.input(i)); - } - string GI_V(const int i) { - CAFFE_ENFORCE( - !g_input_.at(i).IsDense(), - "Input ", - def_.input(i), - " already set to dense."); - g_input_.at(i).values_ = GradientSliceValues(def_.input(i)); - return GradientSliceValues(def_.input(i)); - } - string GO(const int i) { - CAFFE_ENFORCE( - g_output_.at(i).IsDense(), - "Gradient of output ", - def_.output(i), - (g_output_.at(i).IsSparse() ? " is sparse (expected dense)." - : " is not provided!")); - return g_output_.at(i).dense_; - } - string GO_I(const int i) { - CAFFE_ENFORCE( - g_output_.at(i).IsSparse(), - "Gradient of output ", - def_.output(i), - (g_output_.at(i).IsDense() ? " is dense (expected sparse)." - : " is not provided!")); - return g_output_.at(i).indices_; - } - string GO_V(const int i) { - CAFFE_ENFORCE( - g_output_.at(i).IsSparse(), - "Gradient of output ", - def_.output(i), - (g_output_.at(i).IsDense() ? " is dense (expected sparse)." - : " is not provided!")); - return g_output_.at(i).values_; - } - const GradientWrapper& GradOut(int i) { - return g_output_.at(i); - } - - // Function to add a gradient pair to map. - void SetDense(const int i, const string& name) { - CAFFE_ENFORCE( - !g_input_.at(i).IsSparse(), - "Input ", - def_.input(i), - " already set to sparse."); - g_input_.at(i).dense_ = name; - } - void SetSparse(const int i, const string& indices, const string& values) { - CAFFE_ENFORCE( - !g_input_.at(i).IsDense(), - "Input ", - def_.input(i), - " already set to dense."); - g_input_.at(i).indices_ = indices; - g_input_.at(i).values_ = values; - } - - /** - * @brief a helper function to allow one to create one single operator - * def, which is usually the case for many simple operators. - */ - template - inline static vector SingleGradientDef(const Args&... args) { - return vector{CreateOperatorDef(args...)}; - } - - public: - /** - * Returns map that returns the parameters that the gradients are for. - */ - static CaffeMap MatchGradsToParams(const OperatorDef& op) { - // NOTE: how to go beyond string-matching? - CaffeMap m; - for (auto& out : op.output()) { - if (IsGradientBlob(out)) { - m[out] = out.substr(0, out.length() - 5); - } - } - return m; - } - - private: - // Utility functions for gradient name computation. We don't expose them - // in order to discourage the use of such names explicitly. - static string GradientName(const string& name) { - return name + "_grad"; - } - - static bool IsGradientBlob(const string& name) { - return name.length() > 5 && name.find("_grad") == name.length() - 5; - } - - static string GradientNameToParam(const string& name) { - CHECK(IsGradientBlob(name)); - return name.substr(0, name.length() - 5); - } - - static string GradientSliceIndices(const string& name) { - return name + "_grad_indices"; - } - - static string GradientSliceValues(const string& name) { - return name + "_grad_values"; - } - - protected: - // We make the member variables protected in case someone wants to write - // a fully custom Get() function. - const OperatorDef& def_; - const vector& g_output_; - vector g_input_; -}; - -/** - * @brief A helper class to indicate that the operator does not need gradient - * computation. - * - * Use the macro NO_GRADIENT to register operators that do not have gradients. - * Note that this is different fron SHOULD_NOT_DO_GRADIENT: the latter means - * that the gradient computation should not flow through it at all, and throws - * an error if it is called. - */ -class NoGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - return vector(); - } -}; - -/** - * @brief A helper class to indicate that the operator should have no gradient. - * - * This is used when the operator definition is designed to not have a gradient. - * Calling a gradient on this operator def will cause Caffe2 to quit. - */ -struct ThrowInTheTowelIfGradientIsCalled : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - GradientOpsMeta Get() override { - CAFFE_ENFORCE( - false, "One should not call gradient for operator ", def_.type(), "."); - } -}; - -/** - * @brief A helper class to indicate that the gradient mechanism is not ready. - * - * This should only be used sparsely when the gradient does exist, but we have - * not implemented it yet and are using this as a lazy excuse. Eventually, a - * gradient operator should be implemented. - */ -struct GradientNotImplementedYet : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - GradientOpsMeta Get() override { - CAFFE_ENFORCE( - false, - "Operator ", - def_.type(), - " should have a gradient but is not implemented yet."); - } -}; - -CAFFE_DECLARE_REGISTRY( - GradientRegistry, - GradientMakerBase, - const OperatorDef&, - const vector&); - -#define REGISTER_GRADIENT(name, ...) \ - CAFFE_REGISTER_CLASS(GradientRegistry, name, __VA_ARGS__) -#define REGISTER_GRADIENT_STR(str_name, ...) \ - CAFFE_REGISTER_TYPED_CLASS(GradientRegistry, str_name, __VA_ARGS__) - -// NO_GRADIENT means that the operator does not need any gradient computation. -#define NO_GRADIENT(name) REGISTER_GRADIENT(name, NoGradient) - -// SHOULD_NOT_DO_GRADIENT means that the operator is not designed to have -// gradient operators. If you attempt to call the gradient, a log fatal will -// occur. -#define SHOULD_NOT_DO_GRADIENT(name) \ - REGISTER_GRADIENT(name, ThrowInTheTowelIfGradientIsCalled) - -#define GRADIENT_NOT_IMPLEMENTED_YET(name) \ - REGISTER_GRADIENT(name, GradientNotImplementedYet) - -/** - * @brief Gets the GradientOpsMeta for the given operator def. - */ -GradientOpsMeta GetGradientForOp( - const OperatorDef& def, - const vector& g_output); - -} // namespace caffe2 - -#endif // CAFFE2_CORE_OPERATOR_GRADIENT_H_ diff --git a/app/src/main/cpp/caffe2/core/operator_schema.h b/app/src/main/cpp/caffe2/core/operator_schema.h deleted file mode 100644 index 478f3f1..0000000 --- a/app/src/main/cpp/caffe2/core/operator_schema.h +++ /dev/null @@ -1,470 +0,0 @@ -#ifndef CAFFE2_CORE_OPERATOR_SCHEMA_H_ -#define CAFFE2_CORE_OPERATOR_SCHEMA_H_ - -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/registry.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -// A const value returned by OpSchema::CalculateOutput() if the number of -// output cannot be determined. -constexpr int kCannotComputeNumOutputs = -1; - -/** - * @brief A class to record the schema of an op. - * - * OpSchema records the common interface of an op specified by its name. This - * is optional for each operator implemented in Caffe2 but is strongly - * recommended. - * - * To register an OpSchema, one can use the macro OPERATOR_SCHEMA(name) and - * then append the various functions in the class. For example, for an op - * that itakes in two inputs, one output, and the first input and output - * could be in-place, can be written as - * - * OPERATOR_SCHEMA(name) - * .NumInputs(2).NumOutputs(1).AllowInplace({{0, 0}}); - */ -class OpSchema { - public: - OpSchema() : file_("unknown"), line_(0) {} - OpSchema(const string& file, const int line) : file_(file), line_(line) {} - - /** - * @brief Returns the file that the op schema is registered from. - */ - inline const string& file() const { - return file_; - } - - /** - * @brief Returns the line in file that the op schema is registered from. - */ - inline int line() const { - return line_; - } - - /** - * @brief Returns the docstring of the op schema. - */ - inline const char* doc() const { - return doc_.empty() ? nullptr : doc_.c_str(); - } - - /** - * @brief Verifies if an operator definition protobuf matches the pattern - * specified in the schema. - */ - bool Verify(const OperatorDef& def) const; - - // Functions to set the property of the operator schemas. - // Sets the number of inputs, either a fixed number or a min and a max. - - /** - * @brief A single input. - */ - OpSchema& NumInputs(int n); - /** - * @brief Input could be in range [min, max], inclusive. - */ - OpSchema& NumInputs(int min, int max); - /** - * @brief Input could be one of the values specified in allowed_input_nums. - */ - OpSchema& NumInputs(set allowed_input_nums); - /** - * @brief Input is checked with a specified function. - */ - OpSchema& NumInputs(std::function func); - - // Sets the number of outputs, either a fixed number, a min and a max, - // or a function that takes in the input number and produces an output - // number. Use only one function in the set below. - /** - * @brief A single output. - */ - OpSchema& NumOutputs(int n); - /** - * @brief Output could be in range [min, max], inclusive. - */ - OpSchema& NumOutputs(int min, int max); - /** - * @brief Output could be one of the values specified in allowed_output_nums. - */ - OpSchema& NumOutputs(set allowed_output_nums); - /** - * @brief Output is checked with a specified function. - */ - OpSchema& NumOutputs(std::function func); - - /** - * @brief Relationship between inputs and outputs is checked with a specified - * function. - */ - OpSchema& NumInputsOutputs(std::function func); - - // Set the function that can calculate the number of output based on the - // number of input. Use only one function in the set below. - /** - * @brief Set the output calculator to a user-defined function. - */ - OpSchema& OutputCalculator(std::function calc); - /** - * @brief Set the number of outputs to be the same as the number of inputs. - */ - OpSchema& SameNumberOfOutput(); - - // Sets the rule to allow optional in-place operation. - OpSchema& AllowInplace(std::function inplace); - OpSchema& AllowInplace(set> inplace); - OpSchema& AllowOneToOneInplace(); - // Sets the rule to enforce in-place opeartion. - OpSchema& EnforceInplace(std::function inplace); - OpSchema& EnforceInplace(set> inplace); - OpSchema& EnforceOneToOneInplace(); - - // Functions to deal with type and shape inference. Basically, this registers - // a function that takes in an OperatorDef and a series of input type and - // shape specified by TensorProto objects (whose data fields are empty), and - // produces a series of output type and shape. - typedef std::function< - vector(const OperatorDef&, const vector&)> - TensorInferenceFunctionType; - /** - * @brief Sets the tensor inference function, which is a std::function object - * defined in operator_schema.h. - */ - OpSchema& TensorInferenceFunction(TensorInferenceFunctionType function); - /** - * @brief Sets the tensor inference function to produce the same output as - * the input. - */ - OpSchema& IdenticalTypeAndShape(); - OpSchema& IdenticalTypeAndShapeOfInput(int idx); - OpSchema& IdenticalTypeAndShapeOfInputDim(int idx, int dim); - OpSchema& ScalarType(::caffe2::TensorProto_DataType dt); - - /** - * @brief A function to allow one to infer the type and shape from the op - * schema. - */ - inline vector InferTensor( - const OperatorDef& def, - const vector input_type_shape) const { - return tensor_inference_function_(def, input_type_shape); - } - - /* - * @brief A struct to store various cost information about - * an operator such as FLOPs and total memory use. - */ - struct Cost { - uint64_t flops; // Floating point operations. - uint64_t bytes_moved; // Total memory used. - }; - /** - * @brief Registers a function that takes in an OperatorDef - * and a series of input shapes and returns the total "cost" - * required to run the operator via struct by value. - */ - typedef std::function< - struct Cost(const OperatorDef&, const vector&)> - CostInferenceFunctionType; - - /** - * @brief Register the Cost inference function. - */ - OpSchema& CostInferenceFunction(CostInferenceFunctionType&& function); - bool HasCostInferenceFunction() const { - return !!cost_inference_function_; - } - inline struct Cost InferCost( - const OperatorDef& def, - const vector& input_tensor_shape) const { - CAFFE_ENFORCE( - cost_inference_function_, "Cost inference function not defined."); - return (*cost_inference_function_)(def, input_tensor_shape); - } - - // Functions to do documentation for the operator schema. - OpSchema& SetDoc(const string& doc); - - struct Argument { - Argument(const char* name, const char* description, bool required) - : name_{name}, description_{description}, required_{required} {} - - const char* name() const { - return name_; - } - - const char* description() const { - return description_; - } - - bool is_required() const { - return required_; - } - - private: - const char* name_; - const char* description_; - const bool required_; - }; - - OpSchema& - Arg(const char* name, const char* description, bool required = false); - -#define DECLARE_STANDARD_ARG(name, str) \ - static const char* Arg_##name; \ - OpSchema& Arg##name(const char* description); - - DECLARE_STANDARD_ARG(IsTest, is_test) - -#undef DECLARE_STANDARD_ARG - - OpSchema& Input(const int n, const char* name, const char* description); - OpSchema& Output(const int n, const char* name, const char* description); - // Calls the passed function with `this` as an argument. Useful for - // adding docs for temlated/macro ops. - OpSchema& FillUsing(std::function populator); - - // Remove from documentation - OpSchema& Private(); - - // This op can pass data across devices - OpSchema& InputsCanCrossDevices(); - - /** - * @brief A function to allow one to get the number of outputs based on the - * number of inputs, if this schema supports it. - */ - int CalculateOutput(int num_input) const; - - int min_input() const { - return min_input_; - } - - int max_input() const { - return max_input_; - } - - int min_output() const { - return min_output_; - } - - int max_output() const { - return max_output_; - } - - bool num_inputs_allowed(int x) const { - return num_inputs_allowed_(x); - } - - bool num_outputs_allowed(int x) const { - return num_outputs_allowed_(x); - } - - bool num_inputs_outputs_allowed(int x, int y) const { - return num_inputs_outputs_allowed_(x, y); - } - - int inf() const { - return std::numeric_limits::max(); - } - - friend std::ostream& operator<<(std::ostream& out, const OpSchema& schema); - - const std::vector& args() const { - return args_; - } - - const std::vector>& input_desc() const { - return input_desc_; - } - const std::vector>& output_desc() const { - return output_desc_; - } - bool private_op() { - return private_; - } - bool inputs_can_cross_devices() const { - return inputs_can_cross_devices_; - } - - /** - * @brief Returns the required device location of inputs and outputs. - */ - using DeviceInferenceFunctionType = std::function< - std::pair, std::vector>( - const OperatorDef& def)>; - - OpSchema& DeviceInferenceFunction(DeviceInferenceFunctionType function); - - /** - * @brief Infer required device location of an op's inputs and outputs - */ - inline std::pair, std::vector> - InferDevice(const OperatorDef& def) const { - return device_inference_function_(def); - } - - private: - string file_; - string doc_; - std::vector args_{}; - std::vector> input_desc_{}; - std::vector> output_desc_{}; - int line_ = 0; - int min_input_ = 0; - int max_input_ = std::numeric_limits::max(); - int min_output_ = 0; - int max_output_ = std::numeric_limits::max(); - bool private_ = false; - bool inputs_can_cross_devices_ = false; - std::function num_inputs_allowed_ = [](int) { return true; }; - std::function num_outputs_allowed_ = [](int) { return true; }; - std::function num_inputs_outputs_allowed_ = [](int, int) { - return true; - }; - std::function calculate_output_; - // In default, any in-place operation is neither allowed nor enforced. - std::function inplace_allowed_ = [](int, int) { - return false; - }; - std::function inplace_enforced_ = [](int, int) { - return false; - }; - TensorInferenceFunctionType tensor_inference_function_ = - [](const OperatorDef& def, const vector&) { - vector out; - for (int i = 0; i < def.output_size(); i++) { - TensorShape ts; - ts.set_unknown_shape(true); - out.push_back(ts); - } - return out; - }; - std::unique_ptr cost_inference_function_ = nullptr; - DeviceInferenceFunctionType device_inference_function_ = - [](const OperatorDef& def) { - auto op_device = - def.has_device_option() ? def.device_option() : DeviceOption(); - vector in_dev(def.input_size(), op_device); - vector out_dev(def.output_size(), op_device); - return std::make_pair(in_dev, out_dev); - }; -}; - -/** - * @brief A registry to hold all the operator schemas. - */ -class OpSchemaRegistry { - public: - static OpSchema& - NewSchema(const string& key, const string& file, const int line) { - auto& m = map(); - if (m.count(key)) { - const auto& schema = m[key]; - std::ios_base::Init init; - std::cerr << "Trying to register schema with name " << key - << " from file " << file << " line " << line - << ", but it is already registered from file " << schema.file() - << " line " << schema.line(); - abort(); - } - m.emplace(std::make_pair(key, OpSchema(file, line))); - return m[key]; - } - - static const OpSchema* Schema(const string& key) { - auto& m = map(); - if (m.count(key)) { - return &m[key]; - } else { - return nullptr; - } - } - - private: - // OpSchemaRegistry should not need to be instantiated. - OpSchemaRegistry() = delete; - - /** - * @brief Returns the underlying string to OpSchema map. - * - * You should not manually manipulate the map object returned. Instead, use - * the macros defined such as OPERATOR_SCHEMA to register your operator - * schema. - * - * We wrap it inside a function to avoid the statia initialization order - * fiasco. - */ - static CaffeMap& map(); -}; - -// Helper function for creating simple tensorproto with dimension and type -template -inline TensorShape CreateTensorShape( - vector dims, - ::caffe2::TensorProto_DataType dt) { - TensorShape ts; - for (int d : dims) { - ts.add_dims(d); - } - ts.set_data_type(dt); - return ts; -} - -// Helper function -inline vector GetDimsVector(const TensorShape& shape) { - vector dims; - for (auto d : shape.dims()) { - dims.push_back(d); - } - return dims; -} - -// Helper function for infer op inputs and outputs device information. -inline std::pair, std::vector> -InferOpInputOutputDevice(const OperatorDef& op) { - auto op_schema = OpSchemaRegistry::Schema(op.type()); - CAFFE_ENFORCE( - op_schema, "Device inference failed. No schema for: ", op.type()); - // TODO(wyiming) : add try catch here. - return op_schema->InferDevice(op); -} - -} // namespace caffe2 - -#ifndef CAFFE2_NO_OPERATOR_SCHEMA - -#define OPERATOR_SCHEMA(name) \ - void CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(){}; \ - static OpSchema* CAFFE_ANONYMOUS_VARIABLE(name) = \ - &OpSchemaRegistry::NewSchema(#name, __FILE__, __LINE__) -#define OPERATOR_SCHEMA_STR(name) \ - static OpSchema* CAFFE_ANONYMOUS_VARIABLE(schema_registration) = \ - &OpSchemaRegistry::NewSchema(name, __FILE__, __LINE__) - -#else // CAFFE2_NO_OPERATOR_SCHEMA - -#define OPERATOR_SCHEMA(name) \ - void CAFFE2_PLEASE_ADD_OPERATOR_SCHEMA_FOR_##name(){}; \ - static OpSchema* CAFFE_ANONYMOUS_VARIABLE(name) = \ - 1 ? nullptr : &OpSchemaRegistry::NewSchema(#name, __FILE__, __LINE__) -#define OPERATOR_SCHEMA_STR(name) \ - static OpSchema* CAFFE_ANONYMOUS_VARIABLE(schema_registration) = \ - 1 ? nullptr : &OpSchemaRegistry::NewSchema(name, __FILE__, __LINE__) - -#endif // CAFFE2_NO_OPERATOR_SCHEMA - -#endif // CAFFE2_CORE_OPERATOR_SCHEMA_H_ diff --git a/app/src/main/cpp/caffe2/core/plan_executor.h b/app/src/main/cpp/caffe2/core/plan_executor.h deleted file mode 100644 index 891e68c..0000000 --- a/app/src/main/cpp/caffe2/core/plan_executor.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#ifndef CAFFE2_MOBILE -#include "caffe2/core/stats.h" -#endif // CAFFE2_MOBILE - -namespace caffe2 { - -class Workspace; -class PlanDef; - -typedef std::function ShouldContinue; - -bool RunPlanOnWorkspace(Workspace* ws, const PlanDef& plan, ShouldContinue); - -#ifndef CAFFE2_MOBILE -struct PlanExecutionTime { - CAFFE_STAT_CTOR(PlanExecutionTime); - CAFFE_EXPORTED_STAT(plan_execution_time_ns); -}; -#endif // CAFFE2_MOBILE -} diff --git a/app/src/main/cpp/caffe2/core/predictor.h b/app/src/main/cpp/caffe2/core/predictor.h deleted file mode 100644 index 4c06883..0000000 --- a/app/src/main/cpp/caffe2/core/predictor.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "caffe2/core/net.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -class Predictor { - public: - using TensorVector = std::vector; - // Runs the `init_net` once, then saves the `run_net` to be executed - // in `::run` - Predictor( - const NetDef& init_net, - const NetDef& run_net, - Workspace* parent = nullptr); - ~Predictor(); - - // Executes `run_net` on the inputs. - // The first `inputs.size()` inputs from run_net::external_inputs - // are shared with the data in `inputs`. - - // Precondition: - // inputs.size() <= run_net_.external_inputs.size() - - // Postcondition: - // outputs->size() == run_net.external_inputs.size() - - // Returns true on success - bool run(const TensorVector& inputs, TensorVector* outputs); - - const NetDef& def() const { - return run_net_; - }; - - Workspace* ws() { - return &ws_; - }; - - private: - NetDef run_net_; - Workspace ws_; -}; -} diff --git a/app/src/main/cpp/caffe2/core/qtensor.h b/app/src/main/cpp/caffe2/core/qtensor.h deleted file mode 100644 index d857cfa..0000000 --- a/app/src/main/cpp/caffe2/core/qtensor.h +++ /dev/null @@ -1,257 +0,0 @@ -#ifndef CAFFE2_CORE_QTENSOR_H_ -#define CAFFE2_CORE_QTENSOR_H_ - -#include -#include -#include -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/context.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/typeid.h" - -namespace caffe2 { - -template -class QTensor { - public: - QTensor() {} - virtual ~QTensor() {} - /** - * @brief Creates a quantized tensor of the given dimension. - * - * Note that the actual data allocation is not going to be carried out until - * the first time mutable_data() is called. - * - * The underlying storage of the quantized tensor interleaves elements - * by bit depth. - * - * Labeled memory for tensor of size 6, precision 3 - * [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] // Least significant Bits - * [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] - * [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ] - * - * In the case of sign bits (see enable_sign argument), an extra bit - * per element is added: - * - * Labeled memory for tensor of size 6, precision 3, sign bit enabled - * [ E1[0] E2[0] E3[0] E4[0] E5[0] E6[0] ] - * [ E1[1] E2[1] E3[1] E4[1] E5[1] E6[1] ] - * [ E1[2] E2[2] E3[2] E4[2] E5[2] E6[2] ] - * [ E1[s] E2[s] E3[s] E4[s] E5[s] E6[s] ] - * Where 's' is 1 if E is negative - * - * The reason for this layout is the ability to efficiently multiply - * many low precision integers as a sum of popcnt(A & B) * 1 << bit. - * Explained here: https://arxiv.org/abs/1606.06160 - */ - explicit QTensor( - const std::vector& dims, - const unsigned char precision, - const bool signbit = false) - : precision_(precision), signed_(signbit) { - Resize(dims); - } - - void Resize(std::vector dim_source) { - if (dims_ != dim_source) { - size_t source_size = std::accumulate( - dim_source.begin(), dim_source.end(), 1, std::multiplies()); - if ((source_size * (precision_ + signed_)) > capacity_) { - data_.reset(); - capacity_ = 0; - } - dims_ = dim_source; - size_ = source_size; - } - } - - void - SetBitAtIndex(const unsigned char bit, const size_t index, const bool value) { - // Get the mutable data at bit depth `bit`. - unsigned char* d = mutable_data(); - - CAFFE_ENFORCE( - bit < precision_ + signed_, - "Attempted to a set a bit that is not allocated."); - CAFFE_ENFORCE(bit * aligned_size() < capacity_); - - auto idx = (aligned_size() * bit) / CHAR_BIT; - d = &d[idx]; - - idx = index / CHAR_BIT; - auto shift = CHAR_BIT - (index % CHAR_BIT) - 1; - - if (value) { - d[idx] |= 1 << shift; - } else { - d[idx] &= ~(1 << shift); - } - } - - bool GetBitAtIndex(const unsigned char bit, const size_t index) const { - // Get the data at bit depth `bit` - const unsigned char* d = data(); - auto idx = (aligned_size() * bit) / CHAR_BIT; - d = &d[idx]; - - idx = index / CHAR_BIT; - auto shift = CHAR_BIT - (index % CHAR_BIT) - 1; - - return d[idx] & (1 << shift); - } - - void SetPrecision(const unsigned char precision) { - precision_ = precision; - data_.reset(); - } - - void SetSigned(const bool make_signed = true) { - signed_ = make_signed; - data_.reset(); - } - - void SetScale(const double scale) { - scale_ = scale; - } - - void SetBias(const double bias) { - bias_ = bias; - } - - unsigned char* mutable_data() { - if (!data_) { - auto ptr_and_deleter = Context::New(nbytes()); - data_.reset( - static_cast(ptr_and_deleter.first), - ptr_and_deleter.second); - capacity_ = nbytes() * CHAR_BIT; - } - CAFFE_ENFORCE(capacity_ == nbytes() * CHAR_BIT); - return data_.get(); - } - - inline const unsigned char* data() const { - return data_.get(); - } - - inline size_t size() const { - return size_; - } - - inline unsigned char alignment() const { - return alignment_; - } - - inline unsigned char precision() const { - return precision_; - } - - inline const vector& dims() const { - return dims_; - } - - inline bool is_signed() const { - return signed_; - } - - /** - * Returns the number of dimensions of the data. - */ - inline int ndim() const { - return dims_.size(); - } - - inline size_t aligned_size() const { - return alignment_ * ((size_ + alignment_ - 1) / alignment_); - } - - inline size_t nbytes() const { - return (aligned_size() * (precision_ + signed_)) / CHAR_BIT; - } - - inline double scale() const { - return scale_; - } - - inline double bias() const { - return bias_; - } - - /** - * Returns the i-th dimension of the qtensor in int. - */ - inline int dim32(const int i) const { - DCHECK_LT(i, dims_.size()) << "Exceeding ndim limit " << dims_.size(); - DCHECK_GE(i, 0) << "Cannot have negative index"; - CAFFE_ENFORCE_LT(dims_[i], std::numeric_limits::max()); - return static_cast(dims_[i]); - } - - /** - * Returns the 'canonical' version of a (usually) user-specified axis, - * allowing for negative indexing (e.g., -1 for the last axis). - * - * @param axis_index the axis index. - * If 0 <= index < ndim(), return index. - * If -ndim <= index <= -1, return (ndim() - (-index)), - * e.g., the last axis index (ndim() - 1) if index == -1, - * the second to last if index == -2, etc. - * Dies on out of range index. - */ - inline int canonical_axis_index(int axis_index) const { - CAFFE_ENFORCE_GE(axis_index, -ndim()); - CAFFE_ENFORCE_LT(axis_index, ndim()); - if (axis_index < 0) { - return axis_index + ndim(); - } - return axis_index; - } - - /** - * Return product of all dimensions starting from K. - */ - inline TIndex size_from_dim(int k) const { - TIndex r = 1; - for (int i = k; i < dims_.size(); ++i) { - r *= dims_[i]; - } - return r; - } - - /** - * Product of all dims up to. - */ - inline TIndex size_to_dim(int k) const { - CAFFE_ENFORCE(k < dims_.size()); - TIndex r = 1; - for (int i = 0; i < k; ++i) { - r *= dims_[i]; - } - return r; - } - - protected: - std::vector dims_; - size_t size_ = 0; - - // Precision in bits. - unsigned char precision_ = CHAR_BIT; - // Bit alignment. - unsigned char alignment_ = CHAR_BIT; - - // Allocated data. - std::shared_ptr data_; - - // value = scale_ * (x + bias_) - double scale_; - double bias_; - bool signed_ = false; - - // Capacity in bits. - size_t capacity_ = 0; -}; - -} // namespace caffe2 -#endif // CAFFE2_CORE_QTENSOR_H_ diff --git a/app/src/main/cpp/caffe2/core/qtensor_serialization.h b/app/src/main/cpp/caffe2/core/qtensor_serialization.h deleted file mode 100644 index 8efac02..0000000 --- a/app/src/main/cpp/caffe2/core/qtensor_serialization.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ -#define CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ - -#include "caffe2/core/blob_serialization.h" -#include "caffe2/core/qtensor.h" - -namespace caffe2 { - -constexpr auto kQTensorBlobQType = "QTensor"; - -template -class QTensorSerializer : public BlobSerializerBase { - public: - QTensorSerializer() : context_() {} - ~QTensorSerializer() {} - /** - * Serializes a Blob. Note that this blob has to contain QTensor. - */ - void Serialize( - const Blob& blob, - const string& name, - SerializationAcceptor acceptor) override; - - private: - Context context_; -}; - -template -class QTensorDeserializer : public BlobDeserializerBase { - public: - void Deserialize(const BlobProto& proto, Blob* blob) override; - void Deserialize(const QTensorProto& proto, QTensor* tensor); -}; - -template -void QTensorSerializer::Serialize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor) { - const auto& qtensor = blob.template Get>(); - BlobProto blob_proto; - blob_proto.set_name(name); - blob_proto.set_type(kQTensorBlobQType); - QTensorProto& proto = *blob_proto.mutable_qtensor(); - proto.set_name(name); - for (int i = 0; i < qtensor.ndim(); ++i) { - proto.add_dims(qtensor.dim32(i)); - } - proto.set_precision(qtensor.precision()); - proto.set_scale(qtensor.scale()); - proto.set_bias(qtensor.bias()); - proto.set_is_signed(qtensor.is_signed()); - detail::CopyToProtoWithCast( - qtensor.nbytes(), qtensor.data(), proto.mutable_data(), &this->context_); - acceptor(name, blob_proto.SerializeAsString()); -} - -template -void QTensorDeserializer::Deserialize( - const BlobProto& blob_proto, - Blob* blob) { - Deserialize(blob_proto.qtensor(), blob->GetMutable>()); -} - -template -void QTensorDeserializer::Deserialize( - const QTensorProto& proto, - QTensor* qtensor) { - Context context{}; - vector dims; - for (const int d : proto.dims()) { - dims.push_back(d); - } - qtensor->Resize(dims); - qtensor->SetPrecision(proto.precision()); - qtensor->SetScale(proto.scale()); - qtensor->SetBias(proto.bias()); - qtensor->SetSigned(proto.is_signed()); - - detail::CopyFromProtoWithCast( - qtensor->nbytes(), proto.data(), qtensor->mutable_data(), &context); -} - -} // namespace caffe2 - -#endif // CAFFE2_CORE_QTENSOR_SERIALIZATION_H_ diff --git a/app/src/main/cpp/caffe2/core/registry.h b/app/src/main/cpp/caffe2/core/registry.h deleted file mode 100644 index 1b0cae7..0000000 --- a/app/src/main/cpp/caffe2/core/registry.h +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Simple registry implementation in Caffe2 that uses static variables to - * register object creators during program initialization time. - */ -#ifndef CAFFE2_CORE_REGISTRY_H_ -#define CAFFE2_CORE_REGISTRY_H_ - -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/typeid.h" - -namespace caffe2 { - -template -inline void PrintOffendingKey(const KeyType& key) { - printf("[key type printing not supported]\n"); -} - -template <> -inline void PrintOffendingKey(const string& key) { - printf("Offending key: %s.\n", key.c_str()); -} - -/** - * @brief A template class that allows one to register classes by keys. - * - * The keys are usually a string specifying the name, but can be anything that - * can be used in a std::map. - * - * You should most likely not use the Registry class explicitly, but use the - * helper macros below to declare specific registries as well as registering - * objects. - */ -template -class Registry { - public: - typedef std::function (Args ...)> Creator; - - Registry() : registry_() {} - - void Register(const SrcType& key, Creator creator) { - // The if statement below is essentially the same as the following line: - // CHECK_EQ(registry_.count(key), 0) << "Key " << key - // << " registered twice."; - // However, CHECK_EQ depends on google logging, and since registration is - // carried out at static initialization time, we do not want to have an - // explicit dependency on glog's initialization function. - std::lock_guard lock(register_mutex_); - if (registry_.count(key) != 0) { - printf("Key already registered.\n"); - PrintOffendingKey(key); - std::exit(1); - } - registry_[key] = creator; - } - - void Register(const SrcType& key, Creator creator, const string& help_msg) { - Register(key, creator); - help_message_[key] = help_msg; - } - - inline bool Has(const SrcType& key) { return (registry_.count(key) != 0); } - - unique_ptr Create(const SrcType& key, Args ... args) { - if (registry_.count(key) == 0) { - // Returns nullptr if the key is not registered. - return nullptr; - } - return registry_[key](args...); - } - - /** - * Returns the keys currently registered as a vector. - */ - vector Keys() { - vector keys; - for (const auto& it : registry_) { - keys.push_back(it.first); - } - return keys; - } - - const CaffeMap& HelpMessage() const { - return help_message_; - } - - const char* HelpMessage(const SrcType& key) const { - auto it = help_message_.find(key); - if (it == help_message_.end()) { - return nullptr; - } - return it->second.c_str(); - } - - private: - CaffeMap registry_; - CaffeMap help_message_; - std::mutex register_mutex_; - - DISABLE_COPY_AND_ASSIGN(Registry); -}; - -template -class Registerer { - public: - Registerer(const SrcType& key, - Registry* registry, - typename Registry::Creator creator, - const string& help_msg="") { - registry->Register(key, creator, help_msg); - } - - template - static unique_ptr DefaultCreator(Args ... args) { - // TODO(jiayq): old versions of NVCC does not handle make_unique well - // so we are forced to use a unique_ptr constructor here. Check if it is - // fine to use make_unique in the future. - // return make_unique(args...); - return std::unique_ptr(new DerivedType(args...)); - } -}; - -/** - * CAFFE_ANONYMOUS_VARIABLE(str) introduces an identifier starting with - * str and ending with a number that varies with the line. - * Pretty much a copy from 'folly/Preprocessor.h' - */ -#define CAFFE_CONCATENATE_IMPL(s1, s2) s1##s2 -#define CAFFE_CONCATENATE(s1, s2) CAFFE_CONCATENATE_IMPL(s1, s2) -#ifdef __COUNTER__ -#define CAFFE_ANONYMOUS_VARIABLE(str) CAFFE_CONCATENATE(str, __COUNTER__) -#else -#define CAFFE_ANONYMOUS_VARIABLE(str) CAFFE_CONCATENATE(str, __LINE__) -#endif - -/** - * CAFFE_DECLARE_TYPED_REGISTRY is a macro that expands to a function - * declaration, as well as creating a convenient typename for its corresponding - * registerer. - */ -#define CAFFE_DECLARE_TYPED_REGISTRY(RegistryName, SrcType, ObjectType, ...) \ - Registry* RegistryName(); \ - typedef Registerer \ - Registerer##RegistryName; - -#define CAFFE_DEFINE_TYPED_REGISTRY(RegistryName, SrcType, ObjectType, ...) \ - Registry* RegistryName() { \ - static Registry* registry = \ - new Registry(); \ - return registry; \ - } - -// Note(Yangqing): The __VA_ARGS__ below allows one to specify a templated -// creator with comma in its templated arguments. -#define CAFFE_REGISTER_TYPED_CREATOR(RegistryName, key, ...) \ - namespace { \ - static Registerer##RegistryName CAFFE_ANONYMOUS_VARIABLE(g_##RegistryName)( \ - key, RegistryName(), __VA_ARGS__); \ - } - -#define CAFFE_REGISTER_TYPED_CLASS(RegistryName, key, ...) \ - namespace { \ - static Registerer##RegistryName CAFFE_ANONYMOUS_VARIABLE(g_##RegistryName)( \ - key, \ - RegistryName(), \ - Registerer##RegistryName::DefaultCreator<__VA_ARGS__>, \ - TypeMeta::Name<__VA_ARGS__>()); \ - } - -// CAFFE_DECLARE_REGISTRY and CAFFE_DEFINE_REGISTRY are hard-wired to use string -// as the key -// type, because that is the most commonly used cases. -#define CAFFE_DECLARE_REGISTRY(RegistryName, ObjectType, ...) \ - CAFFE_DECLARE_TYPED_REGISTRY( \ - RegistryName, std::string, ObjectType, ##__VA_ARGS__) - -#define CAFFE_DEFINE_REGISTRY(RegistryName, ObjectType, ...) \ - CAFFE_DEFINE_TYPED_REGISTRY( \ - RegistryName, std::string, ObjectType, ##__VA_ARGS__) - -// CAFFE_REGISTER_CREATOR and CAFFE_REGISTER_CLASS are hard-wired to use string -// as the key -// type, because that is the most commonly used cases. -#define CAFFE_REGISTER_CREATOR(RegistryName, key, ...) \ - CAFFE_REGISTER_TYPED_CREATOR(RegistryName, #key, __VA_ARGS__) - -#define CAFFE_REGISTER_CLASS(RegistryName, key, ...) \ - CAFFE_REGISTER_TYPED_CLASS(RegistryName, #key, __VA_ARGS__) - -} // namespace caffe2 -#endif // CAFFE2_CORE_REGISTRY_H_ diff --git a/app/src/main/cpp/caffe2/core/scope_guard.h b/app/src/main/cpp/caffe2/core/scope_guard.h deleted file mode 100644 index c0d5e66..0000000 --- a/app/src/main/cpp/caffe2/core/scope_guard.h +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Copyright 2016 Facebook - * @author Tudor Bosman (tudorb@fb.com) - */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace caffe2 { - -// Copied from folly/ScopeGuard.h - -/** - * ScopeGuard is a general implementation of the "Initialization is - * Resource Acquisition" idiom. Basically, it guarantees that a function - * is executed upon leaving the currrent scope unless otherwise told. - * - * The MakeGuard() function is used to create a new ScopeGuard object. - * It can be instantiated with a lambda function, a std::function, - * a functor, or a void(*)() function pointer. - * - * - * Usage example: Add a friend to memory iff it is also added to the db. - * - * void User::addFriend(User& newFriend) { - * // add the friend to memory - * friends_.push_back(&newFriend); - * - * // If the db insertion that follows fails, we should - * // remove it from memory. - * // (You could also declare this as "auto guard = MakeGuard(...)") - * ScopeGuard guard = MakeGuard([&] { friends_.pop_back(); }); - * - * // this will throw an exception upon error, which - * // makes the ScopeGuard execute UserCont::pop_back() - * // once the Guard's destructor is called. - * db_->addFriend(GetName(), newFriend.GetName()); - * - * // an exception was not thrown, so don't execute - * // the Guard. - * guard.dismiss(); - * } - * - * Examine ScopeGuardTest.cpp for some more sample usage. - * - * Stolen from: - * Andrei's and Petru Marginean's CUJ article: - * http://drdobbs.com/184403758 - * and the loki library: - * http://loki-lib.sourceforge.net/index.php?n=Idioms.ScopeGuardPointer - * and triendl.kj article: - * http://www.codeproject.com/KB/cpp/scope_guard.aspx - */ -class ScopeGuardImplBase { - public: - void dismiss() noexcept { - dismissed_ = true; - } - - protected: - ScopeGuardImplBase() noexcept : dismissed_(false) {} - - static ScopeGuardImplBase makeEmptyScopeGuard() noexcept { - return ScopeGuardImplBase{}; - } - - template - static const T& asConst(const T& t) noexcept { - return t; - } - - bool dismissed_; -}; - -template -class ScopeGuardImpl : public ScopeGuardImplBase { - public: - explicit ScopeGuardImpl(FunctionType& fn) noexcept( - std::is_nothrow_copy_constructible::value) - : ScopeGuardImpl( - asConst(fn), - makeFailsafe(std::is_nothrow_copy_constructible{}, - &fn)) {} - - explicit ScopeGuardImpl(const FunctionType& fn) noexcept( - std::is_nothrow_copy_constructible::value) - : ScopeGuardImpl( - fn, - makeFailsafe(std::is_nothrow_copy_constructible{}, - &fn)) {} - - explicit ScopeGuardImpl(FunctionType&& fn) noexcept( - std::is_nothrow_move_constructible::value) - : ScopeGuardImpl( - std::move_if_noexcept(fn), - makeFailsafe(std::is_nothrow_move_constructible{}, - &fn)) {} - - ScopeGuardImpl(ScopeGuardImpl&& other) noexcept( - std::is_nothrow_move_constructible::value) - : function_(std::move_if_noexcept(other.function_)) { - // If the above line attempts a copy and the copy throws, other is - // left owning the cleanup action and will execute it (or not) depending - // on the value of other.dismissed_. The following lines only execute - // if the move/copy succeeded, in which case *this assumes ownership of - // the cleanup action and dismisses other. - dismissed_ = other.dismissed_; - other.dismissed_ = true; - } - - ~ScopeGuardImpl() noexcept { - if (!dismissed_) { - execute(); - } - } - - private: - static ScopeGuardImplBase makeFailsafe(std::true_type, const void*) noexcept { - return makeEmptyScopeGuard(); - } - - template - static auto makeFailsafe(std::false_type, Fn* fn) noexcept - -> ScopeGuardImpl { - return ScopeGuardImpl{std::ref(*fn)}; - } - - template - explicit ScopeGuardImpl(Fn&& fn, ScopeGuardImplBase&& failsafe) - : ScopeGuardImplBase{}, function_(std::forward(fn)) { - failsafe.dismiss(); - } - - void* operator new(std::size_t) = delete; - - void execute() noexcept { function_(); } - - FunctionType function_; -}; - -template -ScopeGuardImpl::type> -MakeGuard(FunctionType&& fn) noexcept( - std::is_nothrow_constructible::type, - FunctionType>::value) { - return ScopeGuardImpl::type>( - std::forward(fn)); -} - -/** - * This is largely unneeded if you just use auto for your guards. - */ -typedef ScopeGuardImplBase&& ScopeGuard; - -} // namespaces diff --git a/app/src/main/cpp/caffe2/core/static_tracepoint.h b/app/src/main/cpp/caffe2/core/static_tracepoint.h deleted file mode 100644 index 5c3d3a1..0000000 --- a/app/src/main/cpp/caffe2/core/static_tracepoint.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2017 Facebook, Inc. - * - * 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 - -#if defined(__ELF__) && (defined(__x86_64__) || defined(__i386__)) -#include - -#define CAFFE_SDT(name, ...) \ - CAFFE_SDT_PROBE_N( \ - caffe2, name, CAFFE_SDT_NARG(0, ##__VA_ARGS__), ##__VA_ARGS__) -#else -#define CAFFE_SDT(name, ...) do {} while(0) -#endif diff --git a/app/src/main/cpp/caffe2/core/static_tracepoint_elfx86.h b/app/src/main/cpp/caffe2/core/static_tracepoint_elfx86.h deleted file mode 100644 index 7752801..0000000 --- a/app/src/main/cpp/caffe2/core/static_tracepoint_elfx86.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2017 Facebook, Inc. - * - * 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 - -// Default constraint for the probe arguments as operands. -#ifndef CAFFE_SDT_ARG_CONSTRAINT -#define CAFFE_SDT_ARG_CONSTRAINT "nor" -#endif - -// Instruction to emit for the probe. -#define CAFFE_SDT_NOP nop - -// Note section properties. -#define CAFFE_SDT_NOTE_NAME "stapsdt" -#define CAFFE_SDT_NOTE_TYPE 3 - -// Size of address depending on platform. -#ifdef __LP64__ -#define CAFFE_SDT_ASM_ADDR .8byte -#else -#define CAFFE_SDT_ASM_ADDR .4byte -#endif - -// Assembler helper Macros. -#define CAFFE_SDT_S(x) #x -#define CAFFE_SDT_ASM_1(x) CAFFE_SDT_S(x) "\n" -#define CAFFE_SDT_ASM_2(a, b) CAFFE_SDT_S(a) "," CAFFE_SDT_S(b) "\n" -#define CAFFE_SDT_ASM_3(a, b, c) CAFFE_SDT_S(a) "," CAFFE_SDT_S(b) "," \ - CAFFE_SDT_S(c) "\n" -#define CAFFE_SDT_ASM_STRING(x) CAFFE_SDT_ASM_1(.asciz CAFFE_SDT_S(x)) - -// Helper to determine the size of an argument. -#define CAFFE_SDT_ISARRAY(x) (__builtin_classify_type(x) == 14) -#define CAFFE_SDT_ARGSIZE(x) (CAFFE_SDT_ISARRAY(x) ? sizeof(void*) : sizeof(x)) - -// Format of each probe arguments as operand. -// Size of the arugment tagged with CAFFE_SDT_Sn, with "n" constraint. -// Value of the argument tagged with CAFFE_SDT_An, with configured constraint. -#define CAFFE_SDT_ARG(n, x) \ - [CAFFE_SDT_S##n] "n" ((size_t)CAFFE_SDT_ARGSIZE(x)), \ - [CAFFE_SDT_A##n] CAFFE_SDT_ARG_CONSTRAINT (x) - -// Templates to append arguments as operands. -#define CAFFE_SDT_OPERANDS_0() [__sdt_dummy] "g" (0) -#define CAFFE_SDT_OPERANDS_1(_1) CAFFE_SDT_ARG(1, _1) -#define CAFFE_SDT_OPERANDS_2(_1, _2) \ - CAFFE_SDT_OPERANDS_1(_1), CAFFE_SDT_ARG(2, _2) -#define CAFFE_SDT_OPERANDS_3(_1, _2, _3) \ - CAFFE_SDT_OPERANDS_2(_1, _2), CAFFE_SDT_ARG(3, _3) -#define CAFFE_SDT_OPERANDS_4(_1, _2, _3, _4) \ - CAFFE_SDT_OPERANDS_3(_1, _2, _3), CAFFE_SDT_ARG(4, _4) -#define CAFFE_SDT_OPERANDS_5(_1, _2, _3, _4, _5) \ - CAFFE_SDT_OPERANDS_4(_1, _2, _3, _4), CAFFE_SDT_ARG(5, _5) -#define CAFFE_SDT_OPERANDS_6(_1, _2, _3, _4, _5, _6) \ - CAFFE_SDT_OPERANDS_5(_1, _2, _3, _4, _5), CAFFE_SDT_ARG(6, _6) -#define CAFFE_SDT_OPERANDS_7(_1, _2, _3, _4, _5, _6, _7) \ - CAFFE_SDT_OPERANDS_6(_1, _2, _3, _4, _5, _6), CAFFE_SDT_ARG(7, _7) -#define CAFFE_SDT_OPERANDS_8(_1, _2, _3, _4, _5, _6, _7, _8) \ - CAFFE_SDT_OPERANDS_7(_1, _2, _3, _4, _5, _6, _7), CAFFE_SDT_ARG(8, _8) - -// Templates to reference the arguments from operands in note section. -#define CAFFE_SDT_ARGFMT(no) %n[CAFFE_SDT_S##no]@%[CAFFE_SDT_A##no] -#define CAFFE_SDT_ARG_TEMPLATE_0 /*No arguments*/ -#define CAFFE_SDT_ARG_TEMPLATE_1 CAFFE_SDT_ARGFMT(1) -#define CAFFE_SDT_ARG_TEMPLATE_2 CAFFE_SDT_ARG_TEMPLATE_1 CAFFE_SDT_ARGFMT(2) -#define CAFFE_SDT_ARG_TEMPLATE_3 CAFFE_SDT_ARG_TEMPLATE_2 CAFFE_SDT_ARGFMT(3) -#define CAFFE_SDT_ARG_TEMPLATE_4 CAFFE_SDT_ARG_TEMPLATE_3 CAFFE_SDT_ARGFMT(4) -#define CAFFE_SDT_ARG_TEMPLATE_5 CAFFE_SDT_ARG_TEMPLATE_4 CAFFE_SDT_ARGFMT(5) -#define CAFFE_SDT_ARG_TEMPLATE_6 CAFFE_SDT_ARG_TEMPLATE_5 CAFFE_SDT_ARGFMT(6) -#define CAFFE_SDT_ARG_TEMPLATE_7 CAFFE_SDT_ARG_TEMPLATE_6 CAFFE_SDT_ARGFMT(7) -#define CAFFE_SDT_ARG_TEMPLATE_8 CAFFE_SDT_ARG_TEMPLATE_7 CAFFE_SDT_ARGFMT(8) - -// Structure of note section for the probe. -#define CAFFE_SDT_NOTE_CONTENT(provider, name, arg_template) \ - CAFFE_SDT_ASM_1(990: CAFFE_SDT_NOP) \ - CAFFE_SDT_ASM_3( .pushsection .note.stapsdt,"","note") \ - CAFFE_SDT_ASM_1( .balign 4) \ - CAFFE_SDT_ASM_3( .4byte 992f-991f, 994f-993f, CAFFE_SDT_NOTE_TYPE) \ - CAFFE_SDT_ASM_1(991: .asciz CAFFE_SDT_NOTE_NAME) \ - CAFFE_SDT_ASM_1(992: .balign 4) \ - CAFFE_SDT_ASM_1(993: CAFFE_SDT_ASM_ADDR 990b) \ - CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*Reserved for Semaphore address*/\ - CAFFE_SDT_ASM_1( CAFFE_SDT_ASM_ADDR 0) /*Reserved for Semaphore name*/ \ - CAFFE_SDT_ASM_STRING(provider) \ - CAFFE_SDT_ASM_STRING(name) \ - CAFFE_SDT_ASM_STRING(arg_template) \ - CAFFE_SDT_ASM_1(994: .balign 4) \ - CAFFE_SDT_ASM_1( .popsection) - -// Main probe Macro. -#define CAFFE_SDT_PROBE(provider, name, n, arglist) \ - __asm__ __volatile__ ( \ - CAFFE_SDT_NOTE_CONTENT(provider, name, CAFFE_SDT_ARG_TEMPLATE_##n) \ - :: CAFFE_SDT_OPERANDS_##n arglist \ - ) \ - -// Helper Macros to handle variadic arguments. -#define CAFFE_SDT_NARG_(_0, _1, _2, _3, _4, _5, _6, _7, _8, N, ...) N -#define CAFFE_SDT_NARG(...) \ - CAFFE_SDT_NARG_(__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0) -#define CAFFE_SDT_PROBE_N(provider, name, N, ...) \ - CAFFE_SDT_PROBE(provider, name, N, (__VA_ARGS__)) diff --git a/app/src/main/cpp/caffe2/core/stats.h b/app/src/main/cpp/caffe2/core/stats.h deleted file mode 100644 index 408c6e5..0000000 --- a/app/src/main/cpp/caffe2/core/stats.h +++ /dev/null @@ -1,294 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include "caffe2/core/logging.h" -#include "caffe2/core/static_tracepoint.h" - -namespace caffe2 { - -class StatValue { - std::atomic v_{0}; - - public: - int64_t increment(int64_t inc) { - return v_ += inc; - } - - int64_t reset(int64_t value = 0) { - return v_.exchange(value); - } - - int64_t get() const { - return v_.load(); - } -}; - -struct ExportedStatValue { - std::string key; - int64_t value; - std::chrono::time_point ts; -}; - -/** - * @brief Holds names and values of counters exported from a StatRegistry. - */ -using ExportedStatList = std::vector; -using ExportedStatMap = std::unordered_map; - -ExportedStatMap toMap(const ExportedStatList& stats); - -/** - * @brief Holds a map of atomic counters keyed by name. - * - * The StatRegistry singleton, accessed through StatRegistry::get(), holds - * counters registered through the macro CAFFE_EXPORTED_STAT. Example of usage: - * - * struct MyCaffeClass { - * MyCaffeClass(const std::string& instanceName): stats_(instanceName) {} - * void run(int numRuns) { - * try { - * CAFFE_EVENT(stats_, num_runs, numRuns); - * tryRun(numRuns); - * CAFFE_EVENT(stats_, num_successes); - * } catch (std::exception& e) { - * CAFFE_EVENT(stats_, num_failures, 1, "arg_to_usdt", e.what()); - * } - * CAFFE_EVENT(stats_, usdt_only, 1, "arg_to_usdt"); - * } - * private: - * struct MyStats { - * CAFFE_STAT_CTOR(MyStats); - * CAFFE_EXPORTED_STAT(num_runs); - * CAFFE_EXPORTED_STAT(num_successes); - * CAFFE_EXPORTED_STAT(num_failures); - * CAFFE_STAT(usdt_only); - * } stats_; - * }; - * - * int main() { - * MyCaffeClass a("first"); - * MyCaffeClass b("second"); - * for (int i = 0; i < 10; ++i) { - * a.run(10); - * b.run(5); - * } - * ExportedStatList finalStats; - * StatRegistry::get().publish(finalStats); - * } - * - * For every new instance of MyCaffeClass, a new counter is created with - * the instance name as prefix. Everytime run() is called, the corresponding - * counter will be incremented by the given value, or 1 if value not provided. - * - * Counter values can then be exported into an ExportedStatList. In the - * example above, considering "tryRun" never throws, `finalStats` will be - * populated as follows: - * - * first/num_runs 100 - * first/num_successes 10 - * first/num_failures 0 - * second/num_runs 50 - * second/num_successes 10 - * second/num_failures 0 - * - * The event usdt_only is not present in ExportedStatList because it is declared - * as CAFFE_STAT, which does not create a counter. - * - * Additionally, for each call to CAFFE_EVENT, a USDT probe is generated. - * The probe will be set up with the following arguments: - * - Probe name: field name (e.g. "num_runs") - * - Arg #0: instance name (e.g. "first", "second") - * - Arg #1: For CAFFE_EXPORTED_STAT, value of the updated counter - * For CAFFE_STAT, -1 since no counter is available - * - Args ...: Arguments passed to CAFFE_EVENT, including update value - * when provided. - * - * It is also possible to create additional StatRegistry instances beyond - * the singleton. These instances are not automatically populated with - * CAFFE_EVENT. Instead, they can be populated from an ExportedStatList - * structure by calling StatRegistry::update(). - * - */ -class StatRegistry { - std::mutex mutex_; - std::unordered_map> stats_; - - public: - /** - * Retrieve the singleton StatRegistry, which gets populated - * through the CAFFE_EVENT macro. - */ - static StatRegistry& get(); - - /** - * Add a new counter with given name. If a counter for this name already - * exists, returns a pointer to it. - */ - StatValue* add(const std::string& name); - - /** - * Populate an ExportedStatList with current counter values. - * If `reset` is true, resets all counters to zero. It is guaranteed that no - * count is lost. - */ - void publish(ExportedStatList& exported, bool reset = false); - - ExportedStatList publish(bool reset = false) { - ExportedStatList stats; - publish(stats, reset); - return stats; - } - - /** - * Update values of counters contained in the given ExportedStatList to - * the values provided, creating counters that don't exist. - */ - void update(const ExportedStatList& data); - - ~StatRegistry(); -}; - -struct Stat { - std::string groupName; - std::string name; - Stat(const std::string& gn, const std::string& n) : groupName(gn), name(n) {} - - template - int64_t increment(Unused...) { - return -1; - } -}; - -class ExportedStat : public Stat { - StatValue* value_; - - public: - ExportedStat(const std::string& gn, const std::string& n) - : Stat(gn, n), value_(StatRegistry::get().add(gn + "/" + n)) {} - - int64_t increment(int64_t value = 1) { - return value_->increment(value); - } - - template - int64_t increment(T value, Unused1, Unused...) { - return increment(value); - } -}; - -class AvgExportedStat : public ExportedStat { - private: - ExportedStat count_; - - public: - AvgExportedStat(const std::string& gn, const std::string& n) - : ExportedStat(gn, n + "/sum"), count_(gn, n + "/count") {} - - int64_t increment(int64_t value = 1) { - count_.increment(); - return ExportedStat::increment(value); - } - - template - int64_t increment(T value, Unused1, Unused...) { - return increment(value); - } -}; - -class DetailedExportedStat : public ExportedStat { - private: - std::vector details_; - - public: - DetailedExportedStat(const std::string& gn, const std::string& n) - : ExportedStat(gn, n) {} - - void setDetails(const std::vector& detailNames) { - details_.clear(); - for (const auto& detailName : detailNames) { - details_.emplace_back(groupName, name + "/" + detailName); - } - } - - template - int64_t increment(T value, size_t detailIndex, Unused...) { - if (detailIndex < details_.size()) { - details_[detailIndex].increment(value); - } - return ExportedStat::increment(value); - } -}; - -namespace detail { - -template -struct _ScopeGuard { - T f_; - std::chrono::high_resolution_clock::time_point start_; - - explicit _ScopeGuard(T f) - : f_(f), start_(std::chrono::high_resolution_clock::now()) {} - ~_ScopeGuard() { - using namespace std::chrono; - auto duration = high_resolution_clock::now() - start_; - int64_t nanos = duration_cast(duration).count(); - f_(nanos); - } - - // Using implicit cast to bool so that it can be used in an 'if' condition - // within CAFFE_DURATION macro below. - /* implicit */ operator bool() { - return true; - } -}; - -template -_ScopeGuard ScopeGuard(T f) { - return _ScopeGuard(f); -} -} - -#define CAFFE_STAT_CTOR(ClassName) \ - ClassName(std::string name) : groupName(name) {} \ - std::string groupName - -#define CAFFE_EXPORTED_STAT(name) \ - ExportedStat name { \ - groupName, #name \ - } - -#define CAFFE_AVG_EXPORTED_STAT(name) \ - AvgExportedStat name { \ - groupName, #name \ - } - -#define CAFFE_DETAILED_EXPORTED_STAT(name) \ - DetailedExportedStat name { \ - groupName, #name \ - } - -#define CAFFE_STAT(name) \ - Stat name { \ - groupName, #name \ - } - -#define CAFFE_EVENT(stats, field, ...) \ - { \ - auto __caffe_event_value_ = stats.field.increment(__VA_ARGS__); \ - CAFFE_SDT( \ - field, \ - stats.field.groupName.c_str(), \ - __caffe_event_value_, \ - ##__VA_ARGS__); \ - } - -#define CAFFE_DURATION(stats, field, ...) \ - if (auto g = detail::ScopeGuard([&](int64_t nanos) { \ - CAFFE_EVENT(stats, field, nanos, ##__VA_ARGS__); \ - })) -} diff --git a/app/src/main/cpp/caffe2/core/tensor.h b/app/src/main/cpp/caffe2/core/tensor.h deleted file mode 100644 index c31676d..0000000 --- a/app/src/main/cpp/caffe2/core/tensor.h +++ /dev/null @@ -1,827 +0,0 @@ -#ifndef CAFFE2_CORE_TENSOR_H_ -#define CAFFE2_CORE_TENSOR_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/flags.h" -#include "caffe2/core/context.h" -#include "caffe2/core/typeid.h" -#include "caffe2/core/logging.h" - -// A global boolean variable to control whether we free memory when a Tensor -// is shrinked to a smaller size. As a result, a Tensor is always going to -// keep the memory allocated for its maximum capacity reshaped to so far. -CAFFE2_DECLARE_bool(caffe2_keep_on_shrink); - -// Since we can have high variance in blob memory allocated across different -// inputs in the same run, we will shrink the blob only if the memory gain -// is larger than this flag in bytes. -CAFFE2_DECLARE_int64(caffe2_max_keep_on_shrink_memory); - -namespace caffe2 { - -/** - * A utility function to convert vector to vector. - */ -inline vector ToVectorTIndex(const std::vector& src) { - return vector(src.begin(), src.end()); -} - -/** - * Return product of all dimensions starting from K - */ -inline TIndex size_from_dim_(int k, vector dims) { - TIndex r = 1; - for (int i = k; i < dims.size(); ++i) { - r *= dims[i]; - } - return r; -} - -// Product of all dims up to -inline TIndex size_to_dim_(int k, vector dims) { - CAFFE_ENFORCE(k < dims.size()); - TIndex r = 1; - for (int i = 0; i < k; ++i) { - r *= dims[i]; - } - return r; -} - -inline int canonical_axis_index_(int axis_index, int ndims) { - CAFFE_ENFORCE_GE(axis_index, -ndims); - CAFFE_ENFORCE_LT(axis_index, ndims); - if (axis_index < 0) { - return axis_index + ndims; - } - return axis_index; -} - -/** - * @brief Tensor is the basic class in Caffe2 that stores a contiguous memory - * with its shape information. - * - * The Tensor class is essentially a wrapper around a device-specific memory - * (the device is specified by the Context template argument), and deals with - * the allocation and de-allocation of such memory. We make a simplified - * assumption that the memory is always contiguous. - */ -template -class Tensor { - public: - /** - * Initializes an empty tensor. - */ - Tensor() {} - - /** - * @brief Creates a tensor of the given dimension. - * - * Note that the actual data allocation is not going to be carried out until - * the first time mutable_data() is called. - */ - explicit Tensor(const vector& dims) { Resize(dims); } - explicit Tensor(const vector& dims) { Resize(dims); } - - /** - * @brief Creates a tensor from a source tensor, copying over the content. - * - * Note that the source tensor can be from a different device context. The - * second argument provides a device context object (either Context or - * SrcContext) that will be responsible for copying the underlying data. - * If you do not wish to pass in a Context object, an equivalent constructor - * function exists that will create an implicit context object for copy, but - * be noted that this will cause a potential performance hit. - */ - template - Tensor(const Tensor& src, ContextForCopy* context) { - CopyFrom(src, context); - } - - /** - * @brief Creates a tensor from a source tensor, copying over the content. - * - * Note that this may have a potential performance hit, since a temporary - * context object will be created for the memory copy. Prefer explicitly - * providing a context for copy if you can. - */ - template - Tensor(const Tensor& src) { - CopyFrom(src); - } - - /** - * @brief Creates a tensor, and fills its contents with the given values. - */ - template - Tensor(const vector& dims, const vector& values, Context* context) - : meta_(TypeMeta::Make()) { - Resize(dims); - CAFFE_ENFORCE_EQ_WITH_CALLER(values.size(), size_); - context->template Copy(size_, values.data(), mutable_data()); - } - - /** - * @brief Creates a scalar tensor, and fills its content with the given value. - */ - template ::value>::type> - Tensor(const T& value, Context* context) { - Resize(vector{}); - context->template Copy(size_, &value, mutable_data()); - } - - /** - * @brief Copies the data from a source tensor, with a contex provided to - * carry out the underlying memcpy operation. - */ - template - void CopyFrom(const Tensor& src, ContextForCopy* context) { - if ((void*)&src == (void*)this) { - return; - } - meta_ = src.meta(); - Resize(src.dims()); - if (size() > 0) { - if (meta_.copy()) { - meta_.copy()(src.raw_data(), raw_mutable_data(), size()); - } else { - context->template CopyBytes( - nbytes(), src.raw_data(), raw_mutable_data()); - } - } - } - - /** - * @brief Copies the data from a source tensor. - * - * Note that this may have a potential performance hit, since a temporary - * context object will be created for the memory copy. Prefer explicitly - * providing a context for copy if you can. - */ - template - inline void CopyFrom(const Tensor& src) { - SrcContext tmp_context; - CopyFrom(src, &tmp_context); - } - - virtual ~Tensor() noexcept {} - - /** - * @brief Extends the outer-most dimension of this tensor by num elements, - * preserving the existing data. - * - * The underlying data may be reallocated in order to accommodate the new - * elements, in which case this tensors' capacity is grown at a factor of - * growthPct. This ensures that Extend runs on an amortized O(1) time - * complexity. - */ - template - void Extend(TIndex num, float growthPct, ContextForCopy* context) { - CAFFE_ENFORCE_GE_WITH_CALLER(dims_.size(), 1); - auto newDims = dims_; - newDims[0] += num; - if (!data_) { - Resize(newDims); - return; - } - auto newSize = std::accumulate( - newDims.begin(), - newDims.end(), - static_cast(1), - std::multiplies()); - if (newSize * meta_.itemsize() <= capacity_) { - dims_ = newDims; - size_ = newSize; - return; - } - auto newCapacity = dims_; - newCapacity[0] = std::max( - newDims[0], std::ceil(dims_[0] * (growthPct + 100) / 100)); - Reserve(newCapacity, context); - dims_ = newDims; - size_ = newSize; - } - - template - void Reserve(const std::vector& newCapacity, ContextForCopy* context) { - auto newSize = std::accumulate( - newCapacity.begin(), - newCapacity.end(), - static_cast(1), - std::multiplies()); - if (newSize * meta_.itemsize() <= capacity_) { - return; - } - auto oldData = std::move(data_); - auto oldSize = size_; - auto oldDims = dims_; - Resize(newCapacity); - auto* newData = raw_mutable_data(meta_); - context->template CopyItems( - meta_, oldSize, oldData.get(), newData); - dims_ = oldDims; - size_ = oldSize; - reserved_ = true; - } - - /** - * @brief Shrinks the outer-most dimension to given size, keeping the data. - * - * This method guarantees that no re-allocations are carried out, which means - * that the extra capacity after the end of the shurnk tensor is maintained. - */ - void Shrink(TIndex outer_dim) { - CAFFE_ENFORCE_WITH_CALLER(dims_.size() >= 1, "Tensor must be at least 1D"); - CAFFE_ENFORCE_WITH_CALLER( - outer_dim <= dims_[0], - "New outer dimension must be smaller than current."); - dims_[0] = outer_dim; - size_ = std::accumulate( - dims_.begin(), - dims_.end(), - static_cast(1), - std::multiplies()); - } - - /** - * @brief Resizes a tensor. - * - * Resize takes in a vector of ints specifying the dimensions of the tensor. - * You can pass in an empty vector to specify that it is a scalar (i.e. - * containing one single item). - * - * The underlying storage may be deleted after calling Resize: if the new - * shape leads to a different number of items in the tensor, the old memory - * is deleted and new memory will be allocated next time you call - * mutable_data(). However, if the shape is different but the total number of - * items is the same, the underlying storage is kept. - */ - template - void Resize(Ts... dim_source) { - bool size_changed = SetDims(dim_source...); - if (size_changed) { - // If needed, we will free the data. the next mutable_data() call - // will create the data storage. - int64_t new_size = size_ * meta_.itemsize(); - bool reset_tensor = false; - if (reserved_) { - // If tensor is reserved then don't claim its memeory unless capacity_ - // is smaller than new size - reset_tensor = capacity_ < new_size; - } else { - reset_tensor = capacity_ < new_size || !FLAGS_caffe2_keep_on_shrink || - capacity_ - new_size > FLAGS_caffe2_max_keep_on_shrink_memory; - } - - if (reset_tensor) { - FreeMemory(); - } - } - } - - /** - * Resize the tensor like the source tensor. Note that this is just a - * sugar wrapper that essentially calls Resize(src_tensor.dims()). - */ - template - inline void ResizeLike(const Tensor& src_tensor) { - // Note: need casting for different context types. - if (static_cast(this) != static_cast(&src_tensor)) { - Resize(src_tensor.dims()); - } - } - - /** - * Resizes the tensor without touching underlying storage. - * This requires the total size of the tensor to remains constant. - */ - inline void Reshape(const vector& dims) { - TIndex new_size = 1; - for (auto d : dims) { - CAFFE_ENFORCE_GE_WITH_CALLER(d, 0); - new_size *= d; - } - CAFFE_ENFORCE_WITH_CALLER( - new_size == size_, - "New size and old size are not equal. You cannot use Reshape, " - "but should use Resize." - // TODO(jiayq): remove the following warning after pending diffs - // stabilize. - " The old caffe2 mixes Reshape and Resize but this behavior has " - "been changed. If you find this error, most likely you will need " - "to change corresponding code from Reshape to Resize."); - dims_ = dims; - } - - inline void Reshape(const vector& dims) { - Reshape(ToVectorTIndex(dims)); - } - - /** - * Release whatever memory the tensor was holding but keep size and type - * information. Subsequent call to mutable_data will trigger new memory - * allocation. - */ - inline void FreeMemory() { - data_.reset(); - capacity_ = 0; - // If reserved is true and we changed tensor memory then it is fine - // to switch it to false, if Resize is called from Reserve and it triggers - // FreeMemory() then reserved_ will be set to true at end of Reserve() - reserved_ = false; - } - - /** - * A utility function to print the debug string for the tensor. Note that this - * is very slow since it involves quite some string operations, so do not use - * it in your performance-critical code. - */ - string DebugString() const { - std::stringstream ss; - ss << "A Tensor of item size " << itemsize() << " and type " - << meta_.name() << " and dimension ("; - for (int d : dims_) { - ss << d << ","; - } - ss << ")."; - return ss.str(); - } - - void swap(Tensor& other) { - std::swap(dims_, other.dims_); - std::swap(size_, other.size_); - std::swap(meta_, other.meta_); - std::swap(data_, other.data_); - std::swap(shares_data_, other.shares_data_); - std::swap(capacity_, other.capacity_); - std::swap(reserved_, other.reserved_); - } - - /** - * @brief Shares the data with another tensor. - * - * To share data between two tensors, the sizes of the two tensors must be - * equal already. The reason we do not implicitly do a Resize to make the two - * tensors have the same shape is that we want to allow tensors of different - * shapes but the same number of items to still be able to share data. This - * allows one to e.g. have a n-dimensional Tensor and a flattened version - * sharing the same underlying storage. - * - * The source tensor should already have its data allocated. - */ - void ShareData(const Tensor& src) { - meta_ = src.meta(); - CAFFE_ENFORCE_EQ_WITH_CALLER( - src.size_, - size_, - "Size mismatch - did you call reshape before sharing the data?"); - // It is possible that the source tensor hasn't called mutable_data() yet, - // in which case ShareData() doesn't make much sense since we don't really - // know what to share yet. - CAFFE_ENFORCE_WITH_CALLER( - src.data_.get() || src.size_ == 0, - "Source tensor has no content and has size > 0"); - // Finally, do sharing. - data_ = src.data_; - capacity_ = src.capacity_; - shares_data_ = true; - } - - /** - * @brief Shares the data with an externally managed pointer. - * - * This is similar to ShareData() but the source is a pointer with an advanced - * deleter option. In default, no deletion takes place, and one needs to make - * sure that the external memory is deallocated only after the tensor finishes - * using it. If a Deleter object is passed in, when this tensor is reallocated - * or freed, the deleter function is going to be called. - */ - template - void ShareExternalPointer(T* src, size_t capacity = 0, Deleter d = nullptr) { - ShareExternalPointer(src, TypeMeta::Make(), capacity, d); - } - - template - void ShareExternalPointer( - void* src, - const TypeMeta& meta, - size_t capacity = 0, - Deleter d = nullptr) { - meta_ = meta; - CAFFE_ENFORCE_WITH_CALLER( - meta_.id(), - "To share with a raw external pointer you need to have meta " - "already set."); - CAFFE_ENFORCE_WITH_CALLER( - size_ >= 0, - "To share data with a raw pointer, you need to set shape first."); - // Check if the deleter is a MemoryDeleter and is a simple nullptr. - if (std::is_same::value && - reinterpret_cast(&d)[0] == nullptr) { - // Use aliasing constructor trick to avoid calling the destructor. - data_ = std::shared_ptr(std::shared_ptr(), src); - } else { - data_.reset(src, d); - } - // Sets capacity. If not specified, we will implicitly assume that - // the capacity is the current size. - if (capacity) { - capacity_ = capacity; - } else { - capacity_ = nbytes(); - } - shares_data_ = true; - } - - bool shares_data() const { - return shares_data_; - } - - /** - * Returns a const raw void* pointer of the underlying storage. mutable_data() - * or raw_mutable_data() must have been called prior to this function call. - */ - inline const void* raw_data() const { - CAFFE_ENFORCE_WITH_CALLER(data_.get() || size_ == 0); - return data_.get(); - } - - /** - * Returns a typed pointer of the underlying storage. mutable_data() or - * raw_mutable_data() must have been called prior to this function call, and - * the data type must be of the correct type. If you want to get a void* - * pointer instead, use raw_data(). - */ - template - inline const T* data() const { - CAFFE_ENFORCE_WITH_CALLER( - data_.get() || size_ == 0, - "The tensor is of non-zero shape, but its data is not allocated yet. " - "Caffe2 uses a lazy allocation, so you will need to call " - "mutable_data() or raw_mutable_data() to actually allocate memory."); - CAFFE_ENFORCE_WITH_CALLER( - IsType(), - "Tensor type mismatch, caller expects elements to be ", - TypeMeta::Name(), - " while tensor contains ", - meta_.name()); - return static_cast(data_.get()); - } - - /** - * Returns a mutable raw pointer of the underlying storage. Since we will need - * to know the type of the data for allocation, a TypeMeta object is passed in - * to specify the necessary information. This is conceptually equivalent of - * calling mutable_data() where the TypeMeta parameter meta is derived from - * the type T. This function differs from mutable_data() in the sense that - * the type T can be specified during runtime via the TypeMeta object. - * - * If the existing data does not match the desired type, it will be deleted - * and a new storage will be created. - */ - inline void* raw_mutable_data(const TypeMeta& meta) { - // For 0-size tensors it's fine to return any pointer (including nullptr) - if (meta_ == meta && (data_.get() || size_ == 0)) { - return data_.get(); - } else { - bool had_special_dtor = meta_.dtor() != nullptr; - meta_ = meta; - CAFFE_ENFORCE_WITH_CALLER( - size_ >= 0, - "Tensor is not initialized. You probably need to call Resize() " - "before calling mutable_data()"); - - // We can reuse the existing buffer if the current data does not have - // a special destructor and the new data doesn't have a special - // constructor. - if (size_ == 0 || - (meta.ctor() == nullptr && !had_special_dtor && - capacity_ >= size_ * meta_.itemsize())) { - return data_.get(); - } - if (meta.ctor()) { - // For types that need placement new, we will call it, as well as - // making sure that when the data is freed, it calls the right - // destruction procedure. - auto size = size_; - auto dtor = meta_.dtor(); - auto ptr_and_deleter = Context::New(size_ * meta_.itemsize()); - auto deleter = ptr_and_deleter.second; - data_.reset( - ptr_and_deleter.first, [size, dtor, deleter](void* ptr) -> void { - dtor(ptr, size); - deleter(ptr); - }); - meta_.ctor()(data_.get(), size_); - } else { - // For fundamental type, new and delete is easier. - auto ptr_and_deleter = Context::New(size_ * meta_.itemsize()); - data_.reset(ptr_and_deleter.first, ptr_and_deleter.second); - } - capacity_ = size_ * meta_.itemsize(); - return data_.get(); - } - } - - /** - * Returns a mutable raw pointer of the underlying storage. This can only be - * used when you know for sure that the underlying storage of the tensor is - * already created via an earlier raw_mutable_data(meta) call or a - * mutable_data() call. - * - * If the existing data does not match the desired type, it will be deleted - * and a new storage will be created. - */ - inline void* raw_mutable_data() { - CAFFE_ENFORCE_WITH_CALLER( - meta_.id() != 0, - "Calling raw_mutable_data() without meta, but the current meta is " - "of unknown type."); - return raw_mutable_data(meta_); - } - - /** - * Returns a typed pointer of the underlying storage. - * - * For fundamental types, we reuse possible existing storage if there - * is sufficient capacity. - */ - template - inline T* mutable_data() { - if ((size_ == 0 || data_.get()) && IsType()) { - return static_cast(data_.get()); - } - return static_cast(raw_mutable_data(TypeMeta::Make())); - } - - - /** - * Returns the number of dimensions of the data. - */ - inline int ndim() const { return dims_.size(); } - /** - * Returns the size (i.e. the number of items) of the tensor. - */ - inline TIndex size() const { return size_; } - /** - * Return the number of bytes each item takes in the tensor. - */ - inline size_t itemsize() const { return meta_.itemsize(); } - /** - * Returns the total number of bytes of the storage. - * - * This is equivalent to calling size() * itemsize(). - */ - inline size_t nbytes() const { return size_ * meta_.itemsize(); } - - inline size_t capacity_nbytes() const { - return capacity_; - } - /** - * Returns the dimensions of the tensor as a vector. - */ - inline const vector& dims() const { return dims_; } - - inline TIndex size_from_dim(int k) const { - return size_from_dim_(k, dims_); - } - - inline TIndex size_to_dim(int k) const { - return size_to_dim_(k, dims_); - } - - /** - * Returns the 'canonical' version of a (usually) user-specified axis, - * allowing for negative indexing (e.g., -1 for the last axis). - * - * @param axis_index the axis index. - * If 0 <= index < ndim(), return index. - * If -ndim <= index <= -1, return (ndim() - (-index)), - * e.g., the last axis index (ndim() - 1) if index == -1, - * the second to last if index == -2, etc. - * Dies on out of range index. - */ - inline int canonical_axis_index(int axis_index) const { - return canonical_axis_index_(axis_index, ndim()); - } - - /** - * Checks if the tensor content is of the given data type. - */ - template - inline bool IsType() const { return meta_.Match(); } - /** - * Returns the TypeMeta object associated with the current data type. - */ - inline const TypeMeta& meta() const { return meta_; } - - /** - * Returns the i-th dimension of the tensor in int. - * - * This function returns an int value instead of TIndex, which depending on - * the typedef could be int64. If you want int64 dim values, make sure you - * call dim() instead. - */ - inline int dim32(const int i) const { - #ifndef NDEBUG - CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit"); - CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index"); - #endif - CAFFE_ENFORCE_LT_WITH_CALLER(dims_[i], std::numeric_limits::max()); - return static_cast(dims_[i]); - } - - /** - * Returns the i-th dimension of the tensor. Note that the passed in index - * must be between 0 (inclusive) and the number of dimensions, otherwise - * this function will produce a fatal message. - */ - inline TIndex dim(const int i) const { - #ifndef NDEBUG - CAFFE_ENFORCE_LT_WITH_CALLER(i, dims_.size(), "Exceeding ndim limit"); - CAFFE_ENFORCE_GE_WITH_CALLER(i, 0, "Cannot have negative dimension index"); - #endif - return dims_[i]; - } - - protected: - vector dims_; - TIndex size_ = -1; - TypeMeta meta_; - std::shared_ptr data_; - bool shares_data_ = false; - size_t capacity_ = 0; - bool reserved_ = false; - // In case of chunk load we store how much data was already loaded - - private: - template < - typename T, - typename = typename std::enable_if::value>::type> - bool SetDims(const vector& src) { - auto old_size = size_; - dims_.resize(src.size()); - TIndex new_size = 1; - for (unsigned int i = 0; i < src.size(); ++i) { - new_size *= src[i]; - dims_[i] = src[i]; - } - size_ = new_size; - return size_ != old_size; - } - - bool SetDims() { - auto old_size = size_; - dims_.resize(0); - size_ = 1; - return size_ != old_size; - } - - // TODO(jiayq): maybe rewrite the following functions with initializer list. - // NVCC does not play well with initializer lists last time, but worth - // another shot. - bool SetDims(const TIndex d0) { - auto old_size = size_; - dims_.resize(1); - dims_[0] = d0; - size_ = d0; - return size_ != old_size; - } - - bool SetDims(const TIndex d0, const TIndex d1) { - auto old_size = size_; - dims_.resize(2); - dims_[0] = d0; - dims_[1] = d1; - size_ = d0 * d1; - return size_ != old_size; - } - - bool SetDims(const TIndex d0, const TIndex d1, const TIndex d2) { - auto old_size = size_; - dims_.resize(3); - dims_[0] = d0; - dims_[1] = d1; - dims_[2] = d2; - size_ = d0 * d1 * d2; - return size_ != old_size; - } - - bool - SetDims(const TIndex d0, const TIndex d1, const TIndex d2, const TIndex d3) { - auto old_size = size_; - dims_.resize(4); - dims_[0] = d0; - dims_[1] = d1; - dims_[2] = d2; - dims_[3] = d3; - size_ = d0 * d1 * d2 * d3; - return size_ != old_size; - } - - // Note(jiayq): possibly a rule-of-three violation, but we explicitly - // discourage the use of = for Tensors. - Tensor& operator=(const Tensor& src) = delete; -}; - -// For simplicity, we will typedef Tensor to TensorCPU. -typedef Tensor TensorCPU; - -constexpr int k_limit_default_ = 1000; - -// Type call registry -typedef TypeMeta (*TypeCall)(const void*); -TypeCall GetTypeCallFunction(CaffeTypeId id); -void RegisterTypeCallFunction(CaffeTypeId id, TypeCall c); - -template -TypeMeta GetTensorType(const void* c) { - const Tensor* tc = static_cast*>(c); - return tc->meta(); -} - -// Shape call registry -typedef vector (*TensorInfoCall)( - const void*, - bool* shares_data, - size_t* capacity, - DeviceOption* device); -TensorInfoCall GetTensorInfoFunction(CaffeTypeId id); -void RegisterTensorInfoFunction(CaffeTypeId id, TensorInfoCall c); - -template -vector GetTensorInfo( - const void* c, - bool* shares_data, - size_t* capacity, - DeviceOption* device) { - const Tensor* tc = static_cast*>(c); - *shares_data = tc->shares_data(); - *capacity = tc->capacity_nbytes(); - device->set_device_type(CPU); - device->set_cuda_gpu_id(0); - return tc->dims(); -} - -class TensorPrinter { - public: - explicit TensorPrinter( - const std::string& tensor_name = "", - const std::string& file_name = "", - int limit = k_limit_default_); - ~TensorPrinter(); - - template - void Print(const Tensor& tensor); - - template - void PrintMeta(const Tensor& tensor); - - string MetaStr(const Tensor& tensor); - - private: - bool to_file_; - int limit_; - std::unique_ptr log_file_; - std::string tensor_name_; -}; - -template -void TensorPrinter::Print(const Tensor& tensor) { - std::stringstream values_stream; - // One most likely doesn't want to print int64-number of items for visual - // inspection, so we cast down to int here. - int total_count = std::min(tensor.size(), TIndex(limit_)); - const T* tensor_data = tensor.template data(); - for (int i = 0; i < total_count - 1; ++i) { - values_stream << tensor_data[i] << ","; - } - // We do not add a comma after the last item. - values_stream << tensor_data[total_count - 1]; - if (to_file_) { - (*log_file_) << MetaStr(tensor) << values_stream.str() << std::endl; - } else { - // Log to console. - LOG(INFO) << MetaStr(tensor) << values_stream.str(); - } -} - -template -void TensorPrinter::PrintMeta(const Tensor& tensor) { - if (to_file_) { - (*log_file_) << MetaStr(tensor) << std::endl; - } else { - LOG(INFO) << MetaStr(tensor); - } -} - -} // namespace caffe2 -#endif // CAFFE2_CORE_TENSOR_H_ diff --git a/app/src/main/cpp/caffe2/core/timer.h b/app/src/main/cpp/caffe2/core/timer.h deleted file mode 100644 index b767da6..0000000 --- a/app/src/main/cpp/caffe2/core/timer.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef CAFFE2_CORE_TIMER_H_ -#define CAFFE2_CORE_TIMER_H_ - -#include - -#include "caffe2/core/common.h" - -namespace caffe2 { - -/** - * @brief A simple timer object for measuring time. - * - * This is a minimal class around a std::chrono::high_resolution_clock that - * serves as a utility class for testing code. - */ -class Timer { - public: - typedef std::chrono::high_resolution_clock clock; - typedef std::chrono::nanoseconds ns; - Timer() { Start(); } - /** - * @brief Starts a timer. - */ - inline void Start() { start_time_ = clock::now(); } - inline float NanoSeconds() { - return std::chrono::duration_cast(clock::now() - start_time_).count(); - } - /** - * @brief Returns the elapsed time in milliseconds. - */ - inline float MilliSeconds() { return NanoSeconds() / 1000000.f; } - /** - * @brief Returns the elapsed time in microseconds. - */ - inline float MicroSeconds() { return NanoSeconds() / 1000.f; } - /** - * @brief Returns the elapsed time in seconds. - */ - inline float Seconds() { return NanoSeconds() / 1000000000.f; } - - protected: - std::chrono::time_point start_time_; - DISABLE_COPY_AND_ASSIGN(Timer); -}; -} - -#endif // CAFFE2_CORE_TIMER_H_ diff --git a/app/src/main/cpp/caffe2/core/transform.h b/app/src/main/cpp/caffe2/core/transform.h deleted file mode 100644 index 63f7e26..0000000 --- a/app/src/main/cpp/caffe2/core/transform.h +++ /dev/null @@ -1,174 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/core/graph.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -/** - * The Transform Base Object - * - * A Transform is an operation which manipulates a Caffe2 NetDef. - * You can consider it as a function: Transform.ApplyTo(NetDef) -> NetDef - * - * A Transform Operation does 4 things: - * 1) Creates a Graph object from a NetDef, which stores connections. - * 2) Pattern Matches on the Graph, to find subgraphs it wants to change. - * 3) Replaces the subgraphs that it's matched with new operators. - * 4) Creates a NetDef from the changed Graph, and returns it. - * - * The effect of a Transform is defined by its 3 protected virtual functions. - * 1) PatternRule determines for an ordered subgraph and a node, whether to - * consider adding the node to the subgraph. - * 2) ValidatorRule determines, for an ordered subgraph, whether it is a - * match. - * 3) ReplaceRule mutates the graph, based on a matched subgraph. - * - * This is the base class for all derived classes to base off. To create your - * own transform, write your implementations for PatternRule, ValidatorRule, and - * ReplaceRule. - */ -class Transform { - public: - Transform() {} - - /** - * Apply a Transform onto a NetDef. - * Returns the transformed NetDef. - */ - NetDef ApplyTo(const NetDef& orig_net_def); - - virtual ~Transform() {} - - /** - * Determines the type of subgraphs that PatternMatch will find. - * - * CONNECTED_SUBGRAPH will only match subgraphs that are connected. - * These subgraphs satisfy that every node of the match is connected to the - * subgraph of the nodes that come before it. - * For example, in the graph (1) --> (2) --> (3) --> (4), - * This is capable of matching the subgraph [2, 3] and [4, 3] - * This is not capable of matching the subgraph [2, 4]. - * - * - * SORTED_WRT_EXECUTION_ORDER will match subgraphs that guarantee - * sorted execution order. - * The nodes don't have to be connected. It is faster than General. - * For example, in the graph (1) --> (2) --> (3) --> (4), - * This is capable of matching the subgraph [2, 4], [3, 4]. - * This is not capable of matching the subgraph [3, 1], [4, 3]. - * - * - * GENERAL can match any subgraph. - * For example, in the graph (1) --> (2) --> (3) --> (4), - * This is capable of matching subgraphs [2, 4], [3, 4], [4, 2, 1]. - * There is no ordered subgraph of G that cannot be matched by this. - */ - enum PatternMatchType { - CONNECTED_SUBGRAPH, - SORTED_WRT_EXECUTION_ORDER, - GENERAL - }; - - /** - * Generates all matches (stored as ordered subgraphs) and returns them. - * - * A match is stored as vector, which is a mapping to OperatorDefs - * in Graph. The order matters. - */ - std::vector> PatternMatch(const transform::Graph& graph); - - /** - * Applies the replace rule onto each of the matches found. - */ - void ReplacePattern( - const std::vector>& matches, - transform::Graph* graph); - - protected: - /** - * The PatternRule essentially answers: - * Given the current subgraph (ordered), should we append the new node at idx? - */ - virtual bool PatternRule( - const transform::Graph& g, - const std::vector& subgraph, - int /*idx*/) { - CAFFE_NOT_IMPLEMENTED; - } - - /** - * The ValidatorRule essentially answers: - * Given a subgraph, can we accept it? - */ - virtual bool ValidatorRule( - const transform::Graph& g, - const std::vector& subgraph) { - CAFFE_NOT_IMPLEMENTED; - } - - /** - * The ReplaceRule actually mutates the graph, and applies the transformation - * upon the subgraph. - */ - virtual bool ReplaceRule( - const std::vector& subgraph, - transform::Graph* g_ptr) { - CAFFE_NOT_IMPLEMENTED; - } - - void SetPatternMatchType(PatternMatchType type) { - pattern_match_type_ = type; - } - - private: - /** - * A helper function for PatternMatch, which keeps track of the best subgraph - * so far. - */ - void PatternMatchHelper( - const transform::Graph& graph, - const std::vector& matched, - std::vector* subgraph_ptr, - std::vector* best_subgraph_ptr); - /** - * Attempts to append each neighbor to the end of the subgraph. - */ - void TryNeighbors( - const transform::Graph& graph, - const std::map>& neighbors, - const std::vector& matched, - std::vector* subgraph_ptr, - std::vector* best_subgraph_ptr); - - PatternMatchType pattern_match_type_ = CONNECTED_SUBGRAPH; -}; - -// Creates a Transform based on a key, which should be defined in registry. -unique_ptr CreateTransform(string key); - -CAFFE_DECLARE_REGISTRY(TransformRegistry, Transform); -#define REGISTER_TRANSFORM(name, ...) \ - CAFFE_REGISTER_CLASS(TransformRegistry, name, __VA_ARGS__) - -// Create a Transform object from registry, -// and immediately apply it to a Netdef. -NetDef ApplyTransform(const string& key, const NetDef& netdef); - -// Create a Transform object from registry, apply it to a NetDef. -// Will only return the transformed net if it is faster than the old net. -// This will run the init net first, will run the two nets warmup_runs times. -// Then, we will take the average time of main_runs runs, and only keep the -// transformed net if it is faster by a factor of improvement_threshold. -NetDef ApplyTransformIfFaster( - const string& key, - const NetDef& netdef, - const NetDef& init_netdef, - const int warmup_runs, - const int main_runs, - const double improvement_threshold); - -} // namespace diff --git a/app/src/main/cpp/caffe2/core/typeid.h b/app/src/main/cpp/caffe2/core/typeid.h deleted file mode 100644 index ee68dd1..0000000 --- a/app/src/main/cpp/caffe2/core/typeid.h +++ /dev/null @@ -1,306 +0,0 @@ -#ifndef CAFFE2_CORE_TYPEID_H_ -#define CAFFE2_CORE_TYPEID_H_ - -#include -#include -#include -#include -#include -#include -#ifdef __GXX_RTTI -#include -#include -#endif - -#include - -#include "caffe2/core/common.h" - -namespace caffe2 { - -typedef intptr_t CaffeTypeId; -std::map& gTypeNames(); -#ifdef __GXX_RTTI -std::set& gRegisteredTypeNames(); -#endif // __GXX_RTTI - -// A utility function to demangle a function name. -string Demangle(const char* name); - -// A utility function to return an exception string by prepending its exception -// type before its what() content. -string GetExceptionString(const std::exception& e); - -std::mutex& gCaffe2TypeRegistrationMutex(); - -template -struct TypeNameRegisterer { - explicit TypeNameRegisterer(CaffeTypeId id) { - std::lock_guard guard(gCaffe2TypeRegistrationMutex()); -#ifdef __GXX_RTTI - string name = Demangle(typeid(T).name()); - gTypeNames()[id] = name; - // If we are in RTTI mode, we will also use this opportunity to do sanity - // check if there are duplicated ids registered for the same type. This - // usually happens when one does not do RTLD_GLOBAL, which is often the - // case in Python. The way we do the check is to make sure that there are - // no duplicated names registered - this could be done by checking the - // uniqueness of names. - if (gRegisteredTypeNames().count(name)) { - std::cerr << "Type name " << name - << " registered twice. This should " - "not happen. Do you have duplicated CAFFE_KNOWN_TYPE?" - << std::endl; - throw std::runtime_error("TypeNameRegisterer error with type " + name); - } - gRegisteredTypeNames().insert(name); -#else // __GXX_RTTI - gTypeNames()[id] = "(RTTI disabled, cannot show name)"; -#endif // __GXX_RTTI - } -}; - -/** - * TypeMeta is a thin class that allows us to store the type of a container such - * as a blob, or the data type of a tensor, with a unique run-time id. It also - * stores some additional data such as the item size and the name of the type - * for run-time inspection. - */ -class TypeMeta { - public: - typedef void (*PlacementNew)(void*, size_t); - typedef void (*TypedCopy)(const void*, void*, size_t); - typedef void (*TypedDestructor)(void*, size_t); - /** Create a dummy TypeMeta object. To create a TypeMeta object for a specific - * type, use TypeMeta::Make(). - */ - TypeMeta() - : id_(0), itemsize_(0), ctor_(nullptr), copy_(nullptr), dtor_(nullptr) {} - - /** - * Copy constructor. - */ - TypeMeta(const TypeMeta& src) - : id_(src.id_), - itemsize_(src.itemsize_), - ctor_(src.ctor_), - copy_(src.copy_), - dtor_(src.dtor_) {} - /** - * Assignment operator. - */ - TypeMeta& operator=(const TypeMeta& src) { - if (this == &src) - return *this; - id_ = src.id_; - itemsize_ = src.itemsize_; - ctor_ = src.ctor_; - copy_ = src.copy_; - dtor_ = src.dtor_; - return *this; - } - - private: - // TypeMeta can only be created by Make, making sure that we do not - // create incorrectly mixed up TypeMeta objects. - TypeMeta( - CaffeTypeId i, - size_t s, - PlacementNew ctor, - TypedCopy copy, - TypedDestructor dtor) - : id_(i), itemsize_(s), ctor_(ctor), copy_(copy), dtor_(dtor) {} - - public: - /** - * Returns the type id. - */ - inline const CaffeTypeId& id() const { - return id_; - } - /** - * Returns the size of the item. - */ - inline const size_t& itemsize() const { - return itemsize_; - } - /** - * Returns the placement new function pointer for individual items. - */ - inline PlacementNew ctor() const { - return ctor_; - } - /** - * Returns the typed copy function pointer for individual iterms. - */ - inline TypedCopy copy() const { - return copy_; - } - /** - * Returns the destructor function pointer for individual items. - */ - inline TypedDestructor dtor() const { - return dtor_; - } - /** - * Returns a printable name for the type. - */ - inline const char* name() const { - auto it = gTypeNames().find(id_); - assert(it != gTypeNames().end()); - return it->second.c_str(); - } - inline bool operator==(const TypeMeta& m) const { - return (id_ == m.id_); - } - inline bool operator!=(const TypeMeta& m) const { - return (id_ != m.id_); - } - - template - inline bool Match() const { - return (id_ == Id()); - } - - // Below are static functions that can be called by passing a specific type. - - /** - * Returns the unique id for the given type T. The id is unique for the type T - * in the sense that for any two different types, their id are different; for - * the same type T, the id remains the same over different calls of the - * function. However, this is not guaranteed over different runs, as the id - * is generated during run-time. Do NOT serialize the id for storage. - */ - template - CAFFE2_EXPORT static CaffeTypeId Id(); - - /** - * Returns the item size of the type. This is equivalent to sizeof(T). - */ - template - static size_t ItemSize() { - return sizeof(T); - } - - /** - * Returns the printable name of the type. - * - * Works for all types, not only the ones registered with CAFFE_KNOWN_TYPE - */ - template - static const char* Name() { -#ifdef __GXX_RTTI - static const string name = Demangle(typeid(T).name()); - return name.c_str(); -#else // __GXX_RTTI - return "(RTTI disabled, cannot show name)"; -#endif // __GXX_RTTI - } - - /** - * Placement new function for the type. - */ - template - static void _Ctor(void* ptr, size_t n) { - T* typed_ptr = static_cast(ptr); - for (int i = 0; i < n; ++i) { - new (typed_ptr + i) T; - } - } - - /** - * Typed copy function for classes. - */ - template - static void _Copy(const void* src, void* dst, size_t n) { - const T* typed_src = static_cast(src); - T* typed_dst = static_cast(dst); - for (int i = 0; i < n; ++i) { - typed_dst[i] = typed_src[i]; - } - } - - /** - * A placeholder function for types that do not allow assignment. - */ - template - static void - _CopyNotAllowed(const void* /*src*/, void* /*dst*/, size_t /*n*/) { - std::cerr << "Type " << Name() << " does not allow assignment."; - // This is an error by design, so we will quit loud. - abort(); - } - - /** - * Destructor for non-fundamental types. - */ - template - static void _Dtor(void* ptr, size_t n) { - T* typed_ptr = static_cast(ptr); - for (int i = 0; i < n; ++i) { - typed_ptr[i].~T(); - } - } - - /** - * Returns a TypeMeta object that corresponds to the typename T. - */ - template - static typename std::enable_if< - std::is_fundamental::value || std::is_pointer::value, - TypeMeta>::type - Make() { - return TypeMeta(Id(), ItemSize(), nullptr, nullptr, nullptr); - } - - template < - typename T, - typename std::enable_if< - !(std::is_fundamental::value || std::is_pointer::value) && - std::is_copy_assignable::value>::type* = nullptr> - static TypeMeta Make() { - return TypeMeta(Id(), ItemSize(), _Ctor, _Copy, _Dtor); - } - - template - static TypeMeta Make( - typename std::enable_if< - !(std::is_fundamental::value || std::is_pointer::value) && - !std::is_copy_assignable::value>::type* = 0) { - return TypeMeta( - Id(), ItemSize(), _Ctor, _CopyNotAllowed, _Dtor); - } - - private: - CaffeTypeId id_; - size_t itemsize_; - PlacementNew ctor_; - TypedCopy copy_; - TypedDestructor dtor_; -}; - -/** - * Register unique id for a type so it can be used in TypeMeta context, e.g. be - * used as a type for Blob or for Tensor elements. - * - * CAFFE_KNOWN_TYPE does explicit instantiation of TypeMeta::Id template - * function and thus needs to be put in a single translation unit (.cpp file) - * for a given type T. Other translation units that use type T as a type of the - * caffe2::Blob or element type of caffe2::Tensor need to depend on the - * translation unit that contains CAFFE_KNOWN_TYPE declaration via regular - * linkage dependencies. - * - * NOTE: the macro needs to be invoked in ::caffe2 namespace - */ -#define CAFFE_KNOWN_TYPE(T) \ - template <> \ - CaffeTypeId TypeMeta::Id() { \ - static bool type_id_bit[1]; \ - static TypeNameRegisterer registerer( \ - reinterpret_cast(type_id_bit)); \ - return reinterpret_cast(type_id_bit); \ - } - -} // namespace caffe2 - -#endif // CAFFE2_CORE_TYPEID_H_ diff --git a/app/src/main/cpp/caffe2/core/types.h b/app/src/main/cpp/caffe2/core/types.h deleted file mode 100644 index 26fff9d..0000000 --- a/app/src/main/cpp/caffe2/core/types.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef CAFFE2_CORE_TYPES_H_ -#define CAFFE2_CORE_TYPES_H_ - -#include -#include -#include - -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/typeid.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -// Storage orders that are often used in the image applications. -enum StorageOrder { - UNKNOWN = 0, - NHWC = 1, - NCHW = 2, -}; - -inline StorageOrder StringToStorageOrder(const string& str) { - if (str == "NHWC" || str == "nhwc") { - return StorageOrder::NHWC; - } else if (str == "NCHW" || str == "nchw") { - return StorageOrder::NCHW; - } else { - LOG(ERROR) << "Unknown storage order string: " << str; - return StorageOrder::UNKNOWN; - } -} - -inline constexpr char NameScopeSeparator() { return '/'; } - -// From TypeMeta to caffe2::DataType protobuffer enum. -TensorProto::DataType TypeMetaToDataType(const TypeMeta& meta); - -// From caffe2::DataType protobuffer enum to TypeMeta -const TypeMeta& DataTypeToTypeMeta(const TensorProto::DataType& dt); - -} // namespace caffe2 - -/////////////////////////////////////////////////////////////////////////////// -// Half float definition. Currently half float operators are mainly on CUDA -// gpus. -// The reason we do not directly use the cuda __half data type is because that -// requires compilation with nvcc. The float16 data type should be compatible -// with the cuda __half data type, but will allow us to refer to the data type -// without the need of cuda. -static_assert(sizeof(unsigned short) == 2, - "Short on this platform is not 16 bit."); -namespace caffe2 { -typedef struct CAFFE2_ALIGNED(2) __f16 { uint16_t x; } float16; -} // namespace caffe2 - -// Make __f16 a fundamental type. -namespace std { -template<> -struct is_fundamental : std::integral_constant { -}; -} // namespace std - -#endif // CAFFE2_CORE_TYPES_H_ diff --git a/app/src/main/cpp/caffe2/core/workspace.h b/app/src/main/cpp/caffe2/core/workspace.h deleted file mode 100644 index e2b829d..0000000 --- a/app/src/main/cpp/caffe2/core/workspace.h +++ /dev/null @@ -1,264 +0,0 @@ -#ifndef CAFFE2_CORE_WORKSPACE_H_ -#define CAFFE2_CORE_WORKSPACE_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/observer.h" - -#ifndef CAFFE2_MOBILE -#error "mobile build state not defined" -#endif - -#include -#include -#include -#include -#include - -#include "caffe2/core/blob.h" -#include "caffe2/core/registry.h" -#include "caffe2/core/net.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/signal_handler.h" -#if CAFFE2_MOBILE -#include "caffe2/utils/threadpool/ThreadPool.h" -#endif // CAFFE2_MOBILE - -CAFFE2_DECLARE_bool(caffe2_print_blob_sizes_at_exit); - -namespace caffe2 { - -class NetBase; - -struct StopOnSignal { - StopOnSignal() - : handler_(std::make_shared( - SignalHandler::Action::STOP, - SignalHandler::Action::STOP)) {} - - StopOnSignal(const StopOnSignal& other) : handler_(other.handler_) {} - - bool operator()(int /*iter*/) { - return handler_->CheckForSignals() != SignalHandler::Action::STOP; - } - - std::shared_ptr handler_; -}; - -/** - * Workspace is a class that holds all the related objects created during - * runtime: (1) all blobs, and (2) all instantiated networks. It is the owner of - * all these objects and deals with the scaffolding logistics. - */ -class Workspace { - public: - typedef std::function ShouldContinue; - typedef CaffeMap > BlobMap; - typedef CaffeMap > NetMap; - /** - * Initializes an empty workspace. - */ - Workspace() : root_folder_("."), shared_(nullptr) {} - - /** - * Initializes an empty workspace with the given root folder. - * - * For any operators that are going to interface with the file system, such - * as load operators, they will write things under this root folder given - * by the workspace. - */ - explicit Workspace(const string& root_folder) - : root_folder_(root_folder), shared_(nullptr) {} - - /** - * Initializes a workspace with a shared workspace. - * - * When we access a Blob, we will first try to access the blob that exists - * in the local workspace, and if not, access the blob that exists in the - * shared workspace. The caller keeps the ownership of the shared workspace - * and is responsible for making sure that its lifetime is longer than the - * created workspace. - */ - explicit Workspace(const Workspace* shared) - : root_folder_("."), shared_(shared) {} - - /** - * Initializes workspace with parent workspace, blob name remapping - * (new name -> parent blob name), no other blobs are inherited from - * parent workspace - */ - Workspace( - const Workspace* shared, - const std::unordered_map& forwarded_blobs) - : root_folder_("."), shared_(nullptr) { - CAFFE_ENFORCE(shared, "Parent workspace must be specified"); - for (const auto& forwarded : forwarded_blobs) { - CAFFE_ENFORCE( - shared->HasBlob(forwarded.second), "Invalid parent workspace blob"); - forwarded_blobs_[forwarded.first] = - std::make_pair(shared, forwarded.second); - } - } - - /** - * Initializes a workspace with a root folder and a shared workspace. - */ - Workspace(const string& root_folder, Workspace* shared) - : root_folder_(root_folder), shared_(shared) {} - - ~Workspace() { - if (FLAGS_caffe2_print_blob_sizes_at_exit) { - PrintBlobSizes(); - } - } - - /** - * Add blob mappings from another workspace - */ - void AddBlobMapping( - const Workspace* parent, - const std::unordered_map& forwarded_blobs); - - /** - * Return list of blobs owned by this Workspace, not including blobs - * shared from parent workspace. - */ - vector LocalBlobs() const; - - /** - * Return a list of blob names. This may be a bit slow since it will involve - * creation of multiple temp variables. For best performance, simply use - * HasBlob() and GetBlob(). - */ - vector Blobs() const; - - /** - * Return the root folder of the workspace. - */ - const string& RootFolder() { return root_folder_; } - /** - * Checks if a blob with the given name is present in the current workspace. - */ - inline bool HasBlob(const string& name) const { - // First, check the local workspace, - // Then, check the forwarding map, then the parent workspace - if (blob_map_.count(name)) { - return true; - } else if (forwarded_blobs_.count(name)) { - const auto parent_ws = forwarded_blobs_.at(name).first; - const auto& parent_name = forwarded_blobs_.at(name).second; - return parent_ws->HasBlob(parent_name); - } else if (shared_) { - return shared_->HasBlob(name); - } - return false; - } - - void PrintBlobSizes(); - - /** - * Creates a blob of the given name. The pointer to the blob is returned, but - * the workspace keeps ownership of the pointer. If a blob of the given name - * already exists, the creation is skipped and the existing blob is returned. - */ - Blob* CreateBlob(const string& name); - /** - * Remove the blob of the given name. Return true if removed and false if - * not exist. - * Will NOT remove from the shared workspace. - */ - bool RemoveBlob(const string& name); - /** - * Gets the blob with the given name as a const pointer. If the blob does not - * exist, a nullptr is returned. - */ - const Blob* GetBlob(const string& name) const; - /** - * Gets the blob with the given name as a mutable pointer. If the blob does - * not exist, a nullptr is returned. - */ - Blob* GetBlob(const string& name); - - /** - * Creates a network with the given NetDef, and returns the pointer to the - * network. If there is anything wrong during the creation of the network, a - * nullptr is returned. The Workspace keeps ownership of the pointer. - * - * If there is already a net created in the workspace with the given name, - * CreateNet will overwrite it if overwrite=true is specified. Otherwise, an - * exception is thrown. - */ - NetBase* CreateNet(const NetDef& net_def, bool overwrite = false); - NetBase* CreateNet( - const std::shared_ptr& net_def, - bool overwrite = false); - /** - * Gets the pointer to a created net. The workspace keeps ownership of the - * network. - */ - NetBase* GetNet(const string& net_name); - /** - * Deletes the instantiated network with the given name. - */ - void DeleteNet(const string& net_name); - /** - * Finds and runs the instantiated network with the given name. If the network - * does not exist or there are errors running the network, the function - * returns false. - */ - bool RunNet(const string& net_name); - - /** - * Returns a list of names of the currently instantiated networks. - */ - vector Nets() const { - vector names; - for (auto& entry : net_map_) { - names.push_back(entry.first); - } - return names; - } - - /** - * Runs a plan that has multiple nets and execution steps. - */ - bool RunPlan(const PlanDef& plan_def, - ShouldContinue should_continue = StopOnSignal{}); - -#if CAFFE2_MOBILE - /* - * Returns a CPU threadpool instace for parallel execution of - * work. The threadpool is created lazily; if no operators use it, - * then no threadpool will be created. - */ - ThreadPool* GetThreadPool(); -#endif - - // RunOperatorOnce and RunNetOnce runs an operator or net once. The difference - // between RunNet and RunNetOnce lies in the fact that RunNet allows you to - // have a persistent net object, while RunNetOnce creates a net and discards - // it on the fly - this may make things like database read and random number - // generators repeat the same thing over multiple calls. - bool RunOperatorOnce(const OperatorDef& op_def); - bool RunNetOnce(const NetDef& net_def); - - public: - std::atomic last_failed_op_net_position; - - private: - BlobMap blob_map_; - NetMap net_map_; - const string root_folder_; - const Workspace* shared_; - std::unordered_map> - forwarded_blobs_; -#if CAFFE2_MOBILE - std::unique_ptr thread_pool_; - std::mutex thread_pool_creation_mutex_; -#endif // CAFFE2_MOBILE - - DISABLE_COPY_AND_ASSIGN(Workspace); -}; - -} // namespace caffe2 - -#endif // CAFFE2_CORE_WORKSPACE_H_ diff --git a/app/src/main/cpp/caffe2/cuda_rtc/common_rtc.h b/app/src/main/cpp/caffe2/cuda_rtc/common_rtc.h deleted file mode 100644 index 80c2ba2..0000000 --- a/app/src/main/cpp/caffe2/cuda_rtc/common_rtc.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef CAFFE2_CUDA_RTC_COMMON_RTC_H_ -#define CAFFE2_CUDA_RTC_COMMON_RTC_H_ - -#include -#include - -#include -#include - -#define NVRTC_CHECK(condition) \ - do { \ - nvrtcResult result = condition; \ - if (result != NVRTC_SUCCESS) { \ - LOG(FATAL) << "Error at: " << __FILE__ << ":" << __LINE__ << ": " \ - << nvrtcGetErrorString(result); \ - } \ - } while(0) - -namespace caffe2 { - -template -class CudaRTCFunction { - public: - CudaRTCFunction() : module_loaded_(false) {} - ~CudaRTCFunction() { - if (module_loaded_) { - CUDA_DRIVERAPI_ENFORCE(cuModuleUnload(module_)); - } - } - - // TODO: this function is nontrivial and since CudaRTCFunction uses CRTP, it - // may potentially increase the binary size. In that case, move common parts - // into a separate function. - template - void Compile(Args... args) { - string src = static_cast(this)->GetSource(args...); - string name = static_cast(this)->KernelName(args...); - VLOG(1) << "function name: " << name; - VLOG(1) << "function src:\n" << src; - // Actually do the compiling. - nvrtcProgram prog; - NVRTC_CHECK(nvrtcCreateProgram( - &prog, src.c_str(), nullptr, 0, nullptr, nullptr)); - // Compile the program. - // TODO(Yangqing): how to find the current gpu architecture instead of hard - // coding it? - const char *nvrtc_opts[] = {"--gpu-architecture=compute_35", - "--use_fast_math"}; - nvrtcResult compile_result = nvrtcCompileProgram( - prog, 2, nvrtc_opts); - if (compile_result != NVRTC_SUCCESS) { - size_t log_size; - NVRTC_CHECK(nvrtcGetProgramLogSize(prog, &log_size)); - vector nvrtc_log(log_size); - NVRTC_CHECK(nvrtcGetProgramLog(prog, nvrtc_log.data())); - LOG(FATAL) << "Compilation failure for nvrtc(" - << nvrtcGetErrorString(compile_result) << "): \n" - << nvrtc_log.data(); - } - size_t ptx_size; - NVRTC_CHECK(nvrtcGetPTXSize(prog, &ptx_size)); - vector nvrtc_ptx(ptx_size); - NVRTC_CHECK(nvrtcGetPTX(prog, nvrtc_ptx.data())); - NVRTC_CHECK(nvrtcDestroyProgram(&prog)); - // After compilation, load the module. - if (module_loaded_) { - CUDA_DRIVERAPI_ENFORCE(cuModuleUnload(module_)); - } - CUDA_DRIVERAPI_ENFORCE( - cuModuleLoadDataEx(&module_, nvrtc_ptx.data(), 0, 0, 0)); - module_loaded_ = true; - CUDA_DRIVERAPI_ENFORCE( - cuModuleGetFunction(&kernel_, module_, name.c_str())); - } - - template - void Launch(unsigned int gx, unsigned int gy, unsigned int gz, - unsigned int bx, unsigned int by, unsigned int bz, - unsigned int shared_mem, cudaStream_t stream, - Args... args) { - CAFFE_ENFORCE( - module_loaded_, "Cannot call Launch before a module is loaded."); - void * args_voidp[] = {&args...}; - CUDA_DRIVERAPI_ENFORCE(cuLaunchKernel( - kernel_, gx, gy, gz, bx, by, bz, shared_mem, stream, args_voidp, 0)); - } - - void LaunchEx(unsigned int gx, unsigned int gy, unsigned int gz, - unsigned int bx, unsigned int by, unsigned int bz, - unsigned int shared_mem, cudaStream_t stream, - void** extra) { - CAFFE_ENFORCE( - module_loaded_, "Cannot call Launch before a module is loaded."); - CUDA_DRIVERAPI_ENFORCE(cuLaunchKernel( - kernel_, gx, gy, gz, bx, by, bz, shared_mem, stream, nullptr, extra)); - } - - private: - bool module_loaded_; - CUmodule module_; - CUfunction kernel_; -}; - -// TODO: this is in no way unique and is just a hack right now. -inline std::string GetUniqueName() { - static constexpr int len = 20; - static const char alpha[] = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - std::stringstream ss; - ss << "_cuda_kernel_"; - for (int i = 0; i < len; ++i) { - ss << alpha[rand() % (sizeof(alpha) - 1)]; - } - return ss.str(); -} - -} // namepsace caffe2 - -#endif // CAFFE2_CUDA_RTC_COMMON_RTC_H_ diff --git a/app/src/main/cpp/caffe2/db/create_db_op.h b/app/src/main/cpp/caffe2/db/create_db_op.h deleted file mode 100644 index c2d6060..0000000 --- a/app/src/main/cpp/caffe2/db/create_db_op.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CAFFE2_DB_CREATE_DB_OP_H_ -#define CAFFE2_DB_CREATE_DB_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/db.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class CreateDBOp final : public Operator { - public: - CreateDBOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - db_type_(OperatorBase::template GetSingleArgument( - "db_type", - "leveldb")), - db_name_(OperatorBase::template GetSingleArgument("db", "")), - num_shards_( - OperatorBase::template GetSingleArgument("num_shards", 1)), - shard_id_( - OperatorBase::template GetSingleArgument("shard_id", 0)) { - CAFFE_ENFORCE_GT(db_name_.size(), 0, "Must specify a db name."); - } - - bool RunOnDevice() final { - OperatorBase::Output(0)->Open( - db_type_, db_name_, num_shards_, shard_id_); - return true; - } - - private: - string db_type_; - string db_name_; - uint32_t num_shards_; - uint32_t shard_id_; - DISABLE_COPY_AND_ASSIGN(CreateDBOp); -}; - -} // namespace caffe2 - -#endif // CAFFE2_DB_CREATE_DB_OP_H_ diff --git a/app/src/main/cpp/caffe2/distributed/file_store_handler.h b/app/src/main/cpp/caffe2/distributed/file_store_handler.h deleted file mode 100644 index a881839..0000000 --- a/app/src/main/cpp/caffe2/distributed/file_store_handler.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#include - -namespace caffe2 { - -class FileStoreHandler : public StoreHandler { - public: - explicit FileStoreHandler(const std::string& path, const std::string& prefix); - virtual ~FileStoreHandler(); - - virtual void set(const std::string& name, const std::string& data) override; - - virtual std::string get(const std::string& name) override; - - virtual int64_t add(const std::string& name, int64_t value) override; - - virtual bool check(const std::vector& names) override; - - virtual void wait( - const std::vector& names, - const std::chrono::milliseconds& timeout = kDefaultTimeout) override; - - protected: - std::string basePath_; - - std::string realPath(const std::string& path); - - std::string tmpPath(const std::string& name); - - std::string objectPath(const std::string& name); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/distributed/file_store_handler_op.h b/app/src/main/cpp/caffe2/distributed/file_store_handler_op.h deleted file mode 100644 index 82aeb34..0000000 --- a/app/src/main/cpp/caffe2/distributed/file_store_handler_op.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include "file_store_handler.h" - -#include - -namespace caffe2 { - -template -class FileStoreHandlerCreateOp final : public Operator { - public: - explicit FileStoreHandlerCreateOp( - const OperatorDef& operator_def, - Workspace* ws) - : Operator(operator_def, ws), - basePath_( - OperatorBase::template GetSingleArgument("path", "")), - prefix_(OperatorBase::template GetSingleArgument( - "prefix", - "")) { - CAFFE_ENFORCE_NE(basePath_, "", "path is a required argument"); - } - - bool RunOnDevice() override { - auto ptr = - std::unique_ptr(new FileStoreHandler(basePath_, prefix_)); - *OperatorBase::Output>(HANDLER) = - std::move(ptr); - return true; - } - - private: - std::string basePath_; - std::string prefix_; - - OUTPUT_TAGS(HANDLER); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/distributed/redis_store_handler.h b/app/src/main/cpp/caffe2/distributed/redis_store_handler.h deleted file mode 100644 index ee208d9..0000000 --- a/app/src/main/cpp/caffe2/distributed/redis_store_handler.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - -extern "C" { -#include -} - -#include - -namespace caffe2 { - -class RedisStoreHandler : public StoreHandler { - public: - explicit RedisStoreHandler(std::string& host, int port, std::string& prefix); - virtual ~RedisStoreHandler(); - - virtual void set(const std::string& name, const std::string& data) override; - - virtual std::string get(const std::string& name) override; - - virtual int64_t add(const std::string& name, int64_t value) override; - - virtual bool check(const std::vector& names) override; - - virtual void wait( - const std::vector& names, - const std::chrono::milliseconds& timeout = kDefaultTimeout) override; - - private: - std::string host_; - int port_; - std::string prefix_; - - redisContext* redis_; - - std::string compoundKey(const std::string& name); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/distributed/redis_store_handler_op.h b/app/src/main/cpp/caffe2/distributed/redis_store_handler_op.h deleted file mode 100644 index 5908fbd..0000000 --- a/app/src/main/cpp/caffe2/distributed/redis_store_handler_op.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -#include "redis_store_handler.h" - -#include - -#include - -namespace caffe2 { - -template -class RedisStoreHandlerCreateOp final : public Operator { - public: - explicit RedisStoreHandlerCreateOp( - const OperatorDef& operator_def, - Workspace* ws) - : Operator(operator_def, ws), - host_( - OperatorBase::template GetSingleArgument("host", "")), - port_(OperatorBase::template GetSingleArgument("port", 0)), - prefix_(OperatorBase::template GetSingleArgument( - "prefix", - "")) { - CAFFE_ENFORCE_NE(host_, "", "host is a required argument"); - CAFFE_ENFORCE_NE(port_, 0, "port is a required argument"); - } - - bool RunOnDevice() override { - auto ptr = std::unique_ptr( - new RedisStoreHandler(host_, port_, prefix_)); - *OperatorBase::Output>(HANDLER) = - std::move(ptr); - return true; - } - - private: - std::string host_; - int port_; - std::string prefix_; - - OUTPUT_TAGS(HANDLER); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/distributed/store_handler.h b/app/src/main/cpp/caffe2/distributed/store_handler.h deleted file mode 100644 index bb16cad..0000000 --- a/app/src/main/cpp/caffe2/distributed/store_handler.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -namespace caffe2 { - -class StoreHandler { - public: - static constexpr std::chrono::milliseconds kDefaultTimeout = - std::chrono::seconds(30); - static constexpr std::chrono::milliseconds kNoTimeout = - std::chrono::milliseconds::zero(); - - virtual ~StoreHandler(); - - /* - * Set data for the key if it doesn't exist. - * If the key exists the data should be the same as the existing key. - */ - virtual void set(const std::string& name, const std::string& data) = 0; - - /* - * Get the data for the key. - * The call should wait until the key is stored with default timeout - * and return data if set else fail. - */ - virtual std::string get(const std::string& name) = 0; - - /* - * Does an atomic add operation on the key and returns the latest updated - * value. - * Note: To access the current value for this counter call with value = 0 - */ - virtual int64_t add(const std::string& name, int64_t value) = 0; - - /* - * Check if a keys exist in the store. - */ - virtual bool check(const std::vector& names) = 0; - - /* - * Wait for Keys to be stored. - */ - virtual void wait( - const std::vector& names, - const std::chrono::milliseconds& timeout = kDefaultTimeout) = 0; -}; - -struct StoreHandlerTimeoutException : public std::runtime_error { - StoreHandlerTimeoutException() = default; - explicit StoreHandlerTimeoutException(const std::string& msg) - : std::runtime_error(msg) {} -}; - -#define STORE_HANDLER_TIMEOUT(...) \ - throw ::caffe2::StoreHandlerTimeoutException( \ - ::caffe2::MakeString("[", __FILE__, ":", __LINE__, "] ", __VA_ARGS__)); -} diff --git a/app/src/main/cpp/caffe2/distributed/store_ops.h b/app/src/main/cpp/caffe2/distributed/store_ops.h deleted file mode 100644 index b0097a3..0000000 --- a/app/src/main/cpp/caffe2/distributed/store_ops.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "store_handler.h" - -#include - -namespace caffe2 { - -class StoreSetOp final : public Operator { - public: - StoreSetOp(const OperatorDef& operator_def, Workspace* ws); - bool RunOnDevice() override; - - private: - std::string blobName_; - - INPUT_TAGS(HANDLER, DATA); -}; - -class StoreGetOp final : public Operator { - public: - StoreGetOp(const OperatorDef& operator_def, Workspace* ws); - bool RunOnDevice() override; - - private: - std::string blobName_; - - INPUT_TAGS(HANDLER); - OUTPUT_TAGS(DATA); -}; - -class StoreAddOp final : public Operator { - public: - StoreAddOp(const OperatorDef& operator_def, Workspace* ws); - bool RunOnDevice() override; - - private: - std::string blobName_; - int addValue_; - - INPUT_TAGS(HANDLER); - OUTPUT_TAGS(VALUE); -}; - -class StoreWaitOp final : public Operator { - public: - StoreWaitOp(const OperatorDef& operator_def, Workspace* ws); - bool RunOnDevice() override; - - private: - std::vector blobNames_; - - INPUT_TAGS(HANDLER); -}; -} diff --git a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_decomposition.h b/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_decomposition.h deleted file mode 100644 index 9b22964..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_decomposition.h +++ /dev/null @@ -1,202 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FULLY_CONNECTED_OP_DECOMPOSITION_H_ -#define CAFFE2_OPERATORS_FULLY_CONNECTED_OP_DECOMPOSITION_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { -/* - * Although a FC_decomp is just like 2 small FC, - * it is better to have it as one op for future analysis. - * And if we have 2 FC with bias, it is not right. - * TODO(wyiming): decompose the layer into 2 matrices - * W(N * K) = U(N * middle) * trans(V(K * middle)) - * */ -// This is Caffe's InnerProductOp, with a name that fits its purpose better. -template -class FullyConnectedOpDecomp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedOpDecomp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~FullyConnectedOpDecomp() {} - - bool RunOnDevice() override { - const auto& X = Input(0); - const auto& U = Input(1); - const auto& V = Input(2); - const auto& b = Input(3); - auto* Y = Output(0); - //auto* buffer_ptr = Output(1); - // Size M * middle; - //auto& multi_buffer_ = *buffer_ptr; - CAFFE_ENFORCE_GE(X.ndim(), 1); - CAFFE_ENFORCE_GE(U.ndim(), 2); - CAFFE_ENFORCE_GE(V.ndim(), 2); - if (X.ndim() > 2 || U.ndim() > 2 || V.ndim() > 2) { - VLOG(1) << "Using legacy support for arbitrary input and weight " - "dimensions."; - } - CAFFE_ENFORCE_EQ(b.ndim(), 1); - // batch size - int M = X.ndim() > 1 ? X.dim32(0) : 1; - // Feature dimension - int K = X.size() / M; - // number of outputs. - int N = U.dim32(0); - int middle = U.dim32(0); - CAFFE_ENFORCE_EQ(K, V.dim32(0)); - CAFFE_ENFORCE_EQ(N, b.dim32(0)); - if (X.ndim() > 1) { - Y->Resize(M, N); - multi_buffer_.Resize(M, middle); - } else { - Y->Resize(N); - multi_buffer_.Resize(middle); - } - // The col buffer is stored in CHW order as well - kernel_dim, and the height - // and width. - // multi_buffer_.Resize(M, middle); - T* multi_buffer_data = multi_buffer_.template mutable_data(); - // X * V * tans(U) - math::Gemm( - CblasNoTrans, CblasNoTrans, M, middle, K, 1, X.template data(), - V.template data(), 0, multi_buffer_data, - &context_); - math::Gemm( - CblasNoTrans, CblasTrans, M, N, middle, 1, multi_buffer_data, - U.template data(), 0, Y->template mutable_data(), - &context_); - // Add bias term - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(M); - math::Set( - M, static_cast(1), bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, CblasNoTrans, M, N, 1, 1, - bias_multiplier_.template data(), b.template data(), 1, - Y->template mutable_data(), &context_); - return true; - } - - protected: - Tensor bias_multiplier_; - Tensor multi_buffer_; -}; - -template -class FullyConnectedDecompGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedDecompGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~FullyConnectedDecompGradientOp() {} - - bool RunOnDevice() override { - const auto& X = Input(0); - const auto& U = Input(1); - const auto& V = Input(2); - const auto& dY = Input(3); - DCHECK_GE(X.ndim(), 1); - DCHECK_GE(U.ndim(), 2); - DCHECK_GE(V.ndim(), 2); - DCHECK_LE(dY.ndim(), 2); - // batch size - int M = X.ndim() > 1 ? X.dim32(0) : 1; - // Feature dimension - int K = X.size() / M; - // number of outputs. - int N = U.dim32(0); - int middle = U.dim32(1); - DCHECK_EQ(K, V.dim32(0)); - if (dY.ndim() > 1) { - DCHECK_EQ(M, dY.dim32(0)); - DCHECK_EQ(N, dY.dim32(1)); - } else { - DCHECK_EQ(X.ndim(), 1); - DCHECK_EQ(N, dY.size()); - } - auto* dU = Output(0); - auto* dV = Output(1); - auto* db = Output(2); - dU->ResizeLike(U); - dV->ResizeLike(V); - db->Resize(N); - - // Compute dU - // first compute X * V - du_buffer_.Resize(N, middle); - T* du_buffer_data = du_buffer_.template mutable_data(); - math::Gemm( - CblasNoTrans, CblasNoTrans, M, middle, K, 1, - X.template data(), V.template data(), - 0, du_buffer_data, - &context_); - math::Gemm( - CblasTrans, CblasNoTrans, N, middle, M, 1, - dY.template data(), du_buffer_data, - 0, dU->template mutable_data(), - &context_); - // Compute dV - // first compute dY * U - dv_buffer_.Resize(M, middle); - T* dv_buffer_data = dv_buffer_.template mutable_data(); - math::Gemm( - CblasNoTrans, CblasNoTrans, M, middle, N, 1, - dY.template data(), U.template data(), - 0, dv_buffer_data, - &context_); - math::Gemm( - CblasTrans, CblasNoTrans, K, middle, M, 1, - dY.template data(), du_buffer_data, - 0, dV->template mutable_data(), - &context_); - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(M); - math::Set( - M, static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - // Compute dB - math::Gemv( - CblasTrans, M, N, 1, dY.template data(), - bias_multiplier_.template data(), 0, - db->template mutable_data(), - &context_); - // Compute dX if necessary. - if (OutputSize() == 4) { - auto* dX = Output(3); - dX->ResizeLike(X); - dx_buffer_.Resize(M, middle); - T* dx_buffer_data = dx_buffer_.template mutable_data(); - math::Gemm( - CblasNoTrans, CblasNoTrans, M, middle, N, 1, - dY.template data(), U.template data(), - 0, dx_buffer_data, - &context_); - math::Gemm( - CblasNoTrans, CblasTrans, M, K, middle, 1, - dx_buffer_data, V.template data(), - 0, dX->template mutable_data(), - &context_); - } - - return true; - } - - protected: - Tensor bias_multiplier_; - Tensor du_buffer_; - Tensor dv_buffer_; - Tensor dx_buffer_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_prune.h b/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_prune.h deleted file mode 100644 index bbc13bd..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_prune.h +++ /dev/null @@ -1,337 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FULLY_CONNECTED_OP_PRUNE_H_ -#define CAFFE2_OPERATORS_FULLY_CONNECTED_OP_PRUNE_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - - namespace { - - template - using Shape = std::array; - - template - const std::vector& shape(Shape vs) { - static thread_local std::vector cache; - cache.resize(vs.size()); - for (auto i = 0; i < vs.size(); ++i) { - cache[i] = vs[i]; - } - return cache; - } - - inline const std::vector& shape(int i) { - return shape<1>(Shape<1>({i})); - } - - inline const std::vector& shape(int i, int j) { - return shape<2>(Shape<2>({i, j})); - } - - template - void MaskMatrix(const T* mask, T* mat, - int M, int N); - - template - void MaskMatrix_Inc(T* mask_seq, T* mat, - int M, int N, int seq_len, T target); - - template - void AggrDW(T* ag_dw, const T* dw, int N, int K, Context* context); - - template - int MatrixCompare_LT(const T* mat, float thres, - T* mask_seq, int M, int N); - - // TODO(wyiming): write an incremental Mask - // Incremental Mask: only give the new mask positions; - // Assuming that weights masked will not be mask again; - // The incremental mask can also be used to update mask matrix; - // But this will include template for bool and float; - template <> - void MaskMatrix( - const float* mask, float* mat, int M, int N) { - int offset = 0; - for (int i = 0; i < M; ++i) { - for (int j = 0; j < N; ++j) { - mat[offset] = mask[offset]? mat[offset] : 0; - offset++; - } - } - } - - template <> - void MaskMatrix_Inc( - float* mask_seq, - float* mat, - int /*M*/, - int /*N*/, - int seq_len, - float target) { - for (int i = 0; i < seq_len; ++i) { - // assume that the mask_seq is smaller than size - // Although it seems that random access gets bad performance, - // we make sure that seq is in order; - mat[static_cast(mask_seq[i])] = target; - } - } - - template <> - void AggrDW( - float* ag_dw, const float* dw, - int N, int K, CPUContext* context) { - math::Add(N*K, dw, ag_dw, ag_dw, context); - } - - template <> - int MatrixCompare_LT( - const float* mat, float thres, - float* mask_seq, int M, int N) { - int seq_len = 0; - int offset = 0; - for (int i = 0 ; i < M; ++i) { - for (int j = 0; j < N; ++j) { - if (mat[offset] != 0 && - (mat[offset] < thres && mat[offset] > -thres)) { - mask_seq[seq_len++] = static_cast(offset); - } - offset++; - } - } - return seq_len; - } - - } - - // This is Caffe's InnerProductOp, with a name that fits its purpose better. - template - class FullyConnectedOpPrune final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedOpPrune(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~FullyConnectedOpPrune() {} - - bool RunOnDevice() override { - const auto& X = Input(0); - const auto& W = Input(1); - const auto& Mask = Input(2); - const auto& b = Input(3); - auto* Y = Output(0); - CAFFE_ENFORCE_GE(X.ndim(), 1); - CAFFE_ENFORCE_GE(W.ndim(), 2); - if (X.ndim() > 2 || W.ndim() > 2) { - VLOG(1) << "Using legacy support for arbitrary input and weight " - "dimensions."; - } - CAFFE_ENFORCE_EQ(b.ndim(), 1); - // batch size - int M = X.ndim() > 1 ? X.dim32(0) : 1; - // Feature dimension - int K = X.size() / M; - // number of outputs. - int N = W.dim32(0); - CAFFE_ENFORCE_EQ(K, W.size() / W.dim32(0)); - CAFFE_ENFORCE_EQ(N, b.dim32(0)); - if (X.ndim() > 1) { - Y->Resize(M, N); - } else { - Y->Resize(N); - } - // W * x - math::Gemm( - CblasNoTrans, CblasTrans, M, N, K, 1, X.template data(), - W.template data(), 0, Y->template mutable_data(), - &context_); - // Add bias term - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, - // reshape and fill it with one. - bias_multiplier_.Resize(M); - math::Set( - M, static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, CblasNoTrans, M, N, 1, 1, - bias_multiplier_.template data(), b.template data(), 1, - Y->template mutable_data(), &context_); - if (OutputSize() == 2){ - auto* Comp_rate = Output(1); - Comp_rate->Resize(vector()); - T* comp_data = Comp_rate->template mutable_data(); - math::Sum( - Mask.size(), Mask.template data(), comp_data, &context_); - math::Scale( - 1, static_cast(1.) / Mask.size(), comp_data, comp_data, - &context_); - } - return true; - } - - protected: - Tensor bias_multiplier_; - }; - - template - class FullyConnectedPruneGradientOp : public Operator { - public: - int iter_offset; - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedPruneGradientOp - (const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { iter_offset = 0; } - ~FullyConnectedPruneGradientOp() {} - - bool RunOnDevice() override { - const auto& X = Input(0); - //const auto& W = Input(1); - auto* W_ptr = Output(2); - auto& W = *W_ptr; - //const auto& Mask = Input(2); - auto* Mask_ptr = Output(3); - auto& Mask = *Mask_ptr; - const auto& dY = Input(3); - //const auto& Ag_dW = Input(4); - auto* Ag_dW_ptr = Output(4); - auto& Ag_dW = *Ag_dW_ptr; - // it is also the Input(5) - auto* mask_seq_auto = Output(5); - // how about get threshold - auto& thres = Input(6); - //TODO(wyiming): check comp_lb is a float - auto& comp_lb = Input(7); - DCHECK_GE(X.ndim(), 1); - DCHECK_GE(W.ndim(), 2); - DCHECK_LE(dY.ndim(), 2); - // batch size - int M = X.ndim() > 1 ? X.dim32(0) : 1; - // Feature dimension - int K = X.size() / M; - // number of outputs. - int N = W.dim32(0); - // TODO(wyiming): add this window_size to workspace? - int window_size = 100; - // TODO(wyiming): this threshold should be - // based on distribution of the layer weight - float thr = 0.01; - DCHECK_EQ(Mask.dim32(0), W.dim32(0)); - DCHECK_EQ(Mask.dim32(1), W.dim32(1)); - DCHECK_EQ(Ag_dW.dim32(0), W.dim32(0)); - DCHECK_EQ(Ag_dW.dim32(1), W.dim32(1)); - DCHECK_EQ(K, W.size() / W.dim32(0)); - if (dY.ndim() > 1) { - DCHECK_EQ(M, dY.dim32(0)); - DCHECK_EQ(N, dY.dim32(1)); - } else { - DCHECK_EQ(X.ndim(), 1); - DCHECK_EQ(N, dY.size()); - } - auto* dW = Output(0); - auto* db = Output(1); - dW->ResizeLike(W); - db->Resize(N); - - // Compute dW - math::Gemm( - CblasTrans, CblasNoTrans, N, K, M, 1, - dY.template data(), X.template data(), - 0, dW->template mutable_data(), - &context_); - - comp_r_buf_.Resize(vector()); - T* comp_data = comp_r_buf_.template mutable_data(); - math::Sum( - Mask.size(), Mask.template data(), comp_data, &context_); - math::Scale( - 1, static_cast(1.) / Mask.size(), comp_data, comp_data, - &context_); - // update W size window - // Notice here we need to maintain state in OP. - // This is new in Caffe2. - // And this is something we might need to discuss in the future. - // at most mask half of the matrix at time - // 1. mask dw with previous mask - MaskMatrix(Mask.template mutable_data(), - dW->template mutable_data(), N, K); - if(*comp_data > *(comp_lb.template data())){ - iter_offset++; - if (iter_offset % window_size == 0) { - // TODO(wyiming):do the prune here; - sum_buffer_.ResizeLike(W); - math::Add(W.size(), - W.template mutable_data(), - Ag_dW.template mutable_data(), - sum_buffer_.template mutable_data(), - &context_); - mask_seq_auto->ResizeLike(W); - T* mask_seq = mask_seq_auto->template mutable_data(); - math::Set(N*K, static_cast(0), - mask_seq_auto->template mutable_data(), &context_); - // 2. find dw below thres but not eq 0 - int seq_len = MatrixCompare_LT( - Ag_dW_ptr->template mutable_data(), - *thres.template data(), mask_seq, N, K); - // 3. use the mask_seq to update W and dw - MaskMatrix_Inc(mask_seq, - dW->template mutable_data(), - N, K, seq_len, 0); - MaskMatrix_Inc(mask_seq, - W.template mutable_data(), - N, K, seq_len, 0); - MaskMatrix_Inc(mask_seq, - Mask.template mutable_data(), - N, K, seq_len, 0); - math::Set(N*K, static_cast(0), - Ag_dW.template mutable_data(), - &context_); - } else { - // add dW to Aggregate dW. - AggrDW( - Ag_dW.template mutable_data(), - dW->template mutable_data(), - N, K, &context_); - } - } - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, - // reshape and fill it with one. - bias_multiplier_.Resize(M); - math::Set( - M, static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - // Compute dB - math::Gemv( - CblasTrans, M, N, 1, dY.template data(), - bias_multiplier_.template data(), 0, - db->template mutable_data(), - &context_); - // Compute dX if necessary. - if (OutputSize() == 7) { - auto* dX = Output(6); - dX->ResizeLike(X); - math::Gemm( - CblasNoTrans, CblasNoTrans, M, K, N, 1, - dY.template data(), W.template data(), - 0, dX->template mutable_data(), - &context_); - } - - return true; - } - - protected: - Tensor bias_multiplier_; - Tensor sum_buffer_; - Tensor comp_r_buf_; - }; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_sparse.h b/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_sparse.h deleted file mode 100644 index 3025298..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/fully_connected_op_sparse.h +++ /dev/null @@ -1,133 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FULLY_CONNECTED_OP_SPARSE_H_ -#define CAFFE2_OPERATORS_FULLY_CONNECTED_OP_SPARSE_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" -#ifdef CAFFE2_USE_MKL -#include -#endif // CAFFE2_USE_MKL - -namespace caffe2 { - -namespace { - -template -using Shape = std::array; - -template -const std::vector& shape(Shape vs) { - static thread_local std::vector cache; - cache.resize(vs.size()); - for (auto i = 0; i < vs.size(); ++i) { - cache[i] = vs[i]; - } - return cache; -} - -inline const std::vector& shape(int i) { - return shape<1>(Shape<1>({i})); -} - -inline const std::vector& shape(int i, int j) { - return shape<2>(Shape<2>({i, j})); -} - -template -void Sparse_mm(const T* acsr, const int* ia, const int* ja, - int m, int k, int n, const T* b, T* c, Context* context); - -template -void trans_mat(const T* o, T* t, int m, int n, Context* context); - -template <> -void trans_mat( - const float* o, - float* t, - int m, - int n, - CPUContext* /*context*/) { - for(int i = 0; i < m; ++i){ - for(int j = 0; j < n; ++j){ - t[j*m+i]=o[i*n+j]; - } - } -} - -// C = A(sparse) * B -// No transpose; -template <> -void Sparse_mm( - const float* acsr, - const int* ia, - const int* ja, - int m, - int k, - int n, - const float* b, - float* c, - CPUContext* /*context*/) { - float alpha = 1.0, beta = 0.; - mkl_scsrmm("N", &m, &n, &k, &alpha, "GLNC", - acsr, ja, ia, ia+1, b, &n, &beta, c, &n); -} - -} - -// This is Caffe's InnerProductOp, with a name that fits its purpose better. -template -class FullyConnectedOp_SPARSE final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedOp_SPARSE(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~FullyConnectedOp_SPARSE() {} - - bool RunOnDevice() override { - const auto& Xt = Input(0); // transposed X - const auto& Wcsr = Input(1); - const auto& iw = Input(2); - const auto& jw = Input(3); - // Notice that we do not need to transpose b - const auto& b = Input(4); - auto* Yt = Output(0); //transposed Y - // here we assume X is k-by-m - CAFFE_ENFORCE_EQ(Xt.ndim(), 2); - CAFFE_ENFORCE_EQ(b.ndim(), 1); - // batch size - int K = Xt.ndim() > 1 ? Xt.dim32(0) : 1; - // Feature dimension - int M = Xt.size() / K; - // number of outputs. - int N = iw.dim32(0)-1; - CAFFE_ENFORCE_EQ(N, b.dim32(0)); - Yt->Resize(shape(N, M)); - - // Y' = W * X'; - Sparse_mm( - Wcsr.template data(), iw.template data(), - jw.template data(), N, K, M, Xt.template data(), - Yt->template mutable_data(), &context_); - // Add bias term - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(shape(M)); - math::Set( - M, static_cast(1), bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, CblasNoTrans, N, M, 1, 1, - b.template data(), bias_multiplier_.template data(), 1, - Yt->template mutable_data(), &context_); - return true; - } - - protected: - Tensor bias_multiplier_; -}; - - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/funhash_op.h b/app/src/main/cpp/caffe2/experiments/operators/funhash_op.h deleted file mode 100644 index 2f607a4..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/funhash_op.h +++ /dev/null @@ -1,222 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FUNHASH_OP_H_ -#define CAFFE2_OPERATORS_FUNHASH_OP_H_ - -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -#define SIGN_MAGIC 0x9e3779b97f4a7c15 -#define INDEX_MAGIC 0xf39cc0605cedc834 - -#define USE_SIGN - -namespace caffe2 { - -template -class FunHashOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FunHashOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_outputs_( - OperatorBase::GetSingleArgument("num_outputs", -1)), - num_segments_( - OperatorBase::GetSingleArgument("num_segments", -1)), - seed_(OperatorBase::GetSingleArgument("seed", 0)) { - CAFFE_ENFORCE( - OperatorBase::HasArgument("num_outputs"), - "Argument `num_outputs` is missing."); - // If alpha is provided, use adaptive hashing parameterized by alpha. - adaptive_ = (InputSize() == 5); - } - - bool RunOnDevice() override { - const auto& val = Input(0); - const auto& key = Input(1); - const auto& seg = Input(2); - const auto& weight = Input(3); - - TIndex num_alpha = 1; - if (adaptive_) { - const auto& alpha = Input(4); - num_alpha = alpha.dim(0); - } - - const auto* seg_data = seg.template data(); - - TIndex num_weight = weight.dim(0); - TIndex num_nz_ent = seg.dim(0); - - TIndex n_segments = num_segments_; - if (num_segments_ == -1) { - for (TIndex i = 0; i < num_nz_ent; ++i) { - if (seg_data[i] > n_segments) { - n_segments = seg_data[i]; - } - } - ++n_segments; - } - - auto* output = Output(0); - output->Resize(n_segments, num_outputs_); - - T* output_data = output->template mutable_data(); - - memset(output_data, 0, sizeof(T) * n_segments * num_outputs_); - - const auto* weight_data = weight.template data(); - const auto* alpha_data = adaptive_ ? Input(4).template data() : 0; - const auto* val_data = val.template data(); - const auto* key_data = key.template data(); - - for (TIndex j = 0; j < num_nz_ent; ++j) { - TIndex cur_seg = seg_data[j]; - TIndex cur_key = key_data[j]; - T cur_val = val_data[j]; - TIndex output_stride = cur_seg * num_outputs_; - for (TIndex i = 0; i < num_outputs_; ++i) { - T sum = 0; - for (TIndex k = 0; k < num_alpha; ++k) { - uint64_t hash; - // The hash function takes as input four integers: - // 1. feature index - // 2. output index - // 3. alpha index - // 4. magic number: SIGN_MAGIC for sign (-1/+1) - // INDEX_MAGIC for weight index - hash_data[0] = cur_key; - hash_data[1] = i; - hash_data[2] = k; - - hash_data[3] = INDEX_MAGIC; - hash = XXH64(hash_data.data(), hash_data.size(), seed_); - TIndex index = hash % num_weight; - - T cur_weight = weight_data[index]; -#ifdef USE_SIGN - hash_data[3] = SIGN_MAGIC; - hash = XXH64(hash_data.data(), hash_data.size(), seed_); - if (hash % 2) { - cur_weight = -cur_weight; - } -#endif // USE_SIGN - - if (adaptive_) { - sum += cur_weight * alpha_data[k]; - } else { - sum += cur_weight; - } - } - output_data[output_stride + i] += sum * cur_val; - } - } - - return true; - } - - protected: - TIndex num_outputs_; - TIndex num_segments_; - uint64_t seed_; - std::array hash_data; - bool adaptive_; -}; - -template -class FunHashGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FunHashGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_outputs_( - OperatorBase::GetSingleArgument("num_outputs", -1)), - seed_(OperatorBase::GetSingleArgument("seed", 0)) { - adaptive_ = (InputSize() == 6); - } - - bool RunOnDevice() override { - const auto& grad_out = Input(0); - const auto& val = Input(1); - const auto& key = Input(2); - const auto& seg = Input(3); - const auto& weight = Input(4); - - TIndex num_alpha = 1; - T* grad_alpha_data = 0; - - if (adaptive_) { - const auto& alpha = Input(5); - num_alpha = alpha.dim(0); - auto* grad_alpha = Output(1); - grad_alpha->ResizeLike(alpha); - grad_alpha_data = grad_alpha->template mutable_data(); - memset(grad_alpha_data, 0, sizeof(T) * num_alpha); - } - - const auto* seg_data = seg.template data(); - - TIndex num_weight = weight.dim(0); - TIndex num_nz_ent = seg.dim(0); - - auto* grad_weight = Output(0); - grad_weight->ResizeLike(weight); - T* grad_weight_data = grad_weight->template mutable_data(); - - const auto* grad_out_data = grad_out.template data(); - const auto* weight_data = weight.template data(); - const auto* alpha_data = adaptive_ ? Input(5).template data() : 0; - const auto* val_data = val.template data(); - const auto* key_data = key.template data(); - - memset(grad_weight_data, 0, sizeof(T) * num_weight); - - for (TIndex j = 0; j < num_nz_ent; ++j) { - TIndex cur_seg = seg_data[j]; - TIndex cur_key = key_data[j]; - T cur_val = val_data[j]; - TIndex grad_out_stride = cur_seg * num_outputs_; - for (TIndex i = 0; i < num_outputs_; ++i) { - T grad_out_scale = grad_out_data[grad_out_stride + i] * cur_val; - for (TIndex k = 0; k < num_alpha; ++k) { - uint64_t hash; - hash_data[0] = cur_key; - hash_data[1] = i; - hash_data[2] = k; - - hash_data[3] = INDEX_MAGIC; - hash = XXH64(hash_data.data(), hash_data.size(), seed_); - TIndex index = hash % num_weight; - - T cur_grad_out_scale = grad_out_scale; -#ifdef USE_SIGN - hash_data[3] = SIGN_MAGIC; - hash = XXH64(hash_data.data(), hash_data.size(), seed_); - if (hash % 2) { - cur_grad_out_scale = -cur_grad_out_scale; - } -#endif // USE_SIGN - - if (adaptive_) { - grad_alpha_data[k] += cur_grad_out_scale * weight_data[index]; - grad_weight_data[index] += alpha_data[k] * cur_grad_out_scale; - } else { - grad_weight_data[index] += cur_grad_out_scale; - } - } - } - } - return true; - } - - protected: - TIndex num_outputs_; - uint64_t seed_; - std::array hash_data; - bool adaptive_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FUNHASH_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/sparse_funhash_op.h b/app/src/main/cpp/caffe2/experiments/operators/sparse_funhash_op.h deleted file mode 100644 index 6741a51..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/sparse_funhash_op.h +++ /dev/null @@ -1,227 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPARSE_FUNHASH_OP_H_ -#define CAFFE2_OPERATORS_SPARSE_FUNHASH_OP_H_ - -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -#define HASH_MAGIC 0x9e3779b97f4a7c15 - -#define USE_SIGN - -namespace caffe2 { - -template -class SparseFunHashOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseFunHashOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_outputs_( - OperatorBase::GetSingleArgument("num_outputs", -1)), - num_segments_( - OperatorBase::GetSingleArgument("num_segments", -1)), - seed_(OperatorBase::GetSingleArgument("seed", 0)) { - CAFFE_ENFORCE( - OperatorBase::HasArgument("num_outputs"), - "Argument `num_outputs` is missing."); - // If alpha is provided, use adaptive hashing parameterized by alpha. - adaptive_ = (InputSize() == 5); - } - - bool RunOnDevice() override { - const auto& val = Input(0); - const auto& key = Input(1); - const auto& seg = Input(2); - const auto& weight = Input(3); - - TIndex num_alpha = 1; - if (adaptive_) { - const auto& alpha = Input(4); - num_alpha = alpha.dim(0); - } - - const auto* seg_data = seg.template data(); - - TIndex num_weight = weight.dim(0); - TIndex num_nz_ent = seg.dim(0); - - TIndex n_segments = num_segments_; - if (num_segments_ == -1) { - for (TIndex i = 0; i < num_nz_ent; ++i) { - if (seg_data[i] > n_segments) { - n_segments = seg_data[i]; - } - } - ++n_segments; - } - - auto* output = Output(0); - output->Resize(n_segments, num_outputs_); - - T* output_data = output->template mutable_data(); - - memset(output_data, 0, sizeof(T) * n_segments * num_outputs_); - - const auto* weight_data = weight.template data(); - const auto* alpha_data = adaptive_ ? Input(4).template data() : 0; - const auto* val_data = val.template data(); - const auto* key_data = key.template data(); - - for (TIndex j = 0; j < num_nz_ent; ++j) { - TIndex cur_seg = seg_data[j]; - TIndex cur_key = key_data[j]; - T cur_val = val_data[j]; - TIndex output_stride = cur_seg * num_outputs_; - for (TIndex i = 0; i < num_outputs_; ++i) { - T sum = 0; - for (TIndex k = 0; k < num_alpha; ++k) { - // The hash function takes as input three integers: - // 1. feature index - // 2. output index - // 3. alpha index - // 4. magic number to improve hashing - hash_data[0] = cur_key; - hash_data[1] = i; - hash_data[2] = k; - hash_data[3] = HASH_MAGIC; - - uint64_t hash = XXH64(hash_data.data(), hash_data.size(), seed_); - -#ifdef USE_SIGN - // Use the least significant bit for sign, the rest for weights. - TIndex index = (hash >> 1) % num_weight; - T cur_weight = weight_data[index]; - if (hash & 1) { - cur_weight = -cur_weight; - } -#else - TIndex index = hash % num_weight; - T cur_weight = weight_data[index]; -#endif - - if (adaptive_) { - sum += cur_weight * alpha_data[k]; - } else { - sum += cur_weight; - } - } - output_data[output_stride + i] += sum * cur_val; - } - } - - return true; - } - - protected: - TIndex num_outputs_; - TIndex num_segments_; - uint64_t seed_; - std::array hash_data; - bool adaptive_; -}; - -template -class SparseFunHashGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseFunHashGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_outputs_( - OperatorBase::GetSingleArgument("num_outputs", -1)), - seed_(OperatorBase::GetSingleArgument("seed", 0)) { - adaptive_ = (InputSize() == 6); - } - - bool RunOnDevice() override { - const auto& grad_out = Input(0); - const auto& val = Input(1); - const auto& key = Input(2); - const auto& seg = Input(3); - const auto& weight = Input(4); - - TIndex num_alpha = 1; - T* grad_alpha_data = 0; - - if (adaptive_) { - const auto& alpha = Input(5); - num_alpha = alpha.dim(0); - auto* grad_alpha = Output(2); - grad_alpha->ResizeLike(alpha); - grad_alpha_data = grad_alpha->template mutable_data(); - memset(grad_alpha_data, 0, sizeof(T) * num_alpha); - } - - const auto* seg_data = seg.template data(); - - TIndex num_weight = weight.dim(0); - TIndex num_nz_ent = seg.dim(0); - - TIndex grad_weight_size = num_nz_ent * num_outputs_ * num_alpha; - auto* grad_weight_val = Output(0); - grad_weight_val->Resize(grad_weight_size); - T* grad_weight_val_data = grad_weight_val->template mutable_data(); - - auto* grad_weight_ind = Output(1); - grad_weight_ind->Resize(grad_weight_size); - auto* grad_weight_ind_data = - grad_weight_ind->template mutable_data(); - - const auto* grad_out_data = grad_out.template data(); - const auto* weight_data = weight.template data(); - const auto* alpha_data = adaptive_ ? Input(5).template data() : 0; - const auto* val_data = val.template data(); - const auto* key_data = key.template data(); - - TIndex w_ind = 0; - for (TIndex j = 0; j < num_nz_ent; ++j) { - TIndex cur_seg = seg_data[j]; - TIndex cur_key = key_data[j]; - T cur_val = val_data[j]; - TIndex grad_out_stride = cur_seg * num_outputs_; - for (TIndex i = 0; i < num_outputs_; ++i) { - T grad_out_scale = grad_out_data[grad_out_stride + i] * cur_val; - for (TIndex k = 0; k < num_alpha; ++k) { - hash_data[0] = cur_key; - hash_data[1] = i; - hash_data[2] = k; - hash_data[3] = HASH_MAGIC; - - uint64_t hash = XXH64(hash_data.data(), hash_data.size(), seed_); - - T cur_grad_out_scale = grad_out_scale; -#ifdef USE_SIGN - TIndex index = (hash >> 1) % num_weight; - if (hash & 1) { - cur_grad_out_scale = -cur_grad_out_scale; - } -#else - TIndex index = hash % num_weight; -#endif - - if (adaptive_) { - grad_alpha_data[k] += cur_grad_out_scale * weight_data[index]; - grad_weight_val_data[w_ind] = alpha_data[k] * cur_grad_out_scale; - } else { - grad_weight_val_data[w_ind] = cur_grad_out_scale; - } - grad_weight_ind_data[w_ind] = index; - ++w_ind; - } - } - } - return true; - } - - protected: - TIndex num_outputs_; - uint64_t seed_; - std::array hash_data; - bool adaptive_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPARSE_FUNHASH_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/sparse_matrix_reshape_op.h b/app/src/main/cpp/caffe2/experiments/operators/sparse_matrix_reshape_op.h deleted file mode 100644 index f533b26..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/sparse_matrix_reshape_op.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPARSE_MATRIX_RESHAPE_H_ -#define CAFFE2_OPERATORS_SPARSE_MATRIX_RESHAPE_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SparseMatrixReshapeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseMatrixReshapeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - CAFFE_ENFORCE( - OperatorBase::HasArgument("old_shape"), - "Argument `old_shape` is missing."); - CAFFE_ENFORCE( - OperatorBase::HasArgument("new_shape"), - "Argument `new_shape` is missing."); - - vector old_shape = - OperatorBase::GetRepeatedArgument("old_shape"); - vector new_shape = - OperatorBase::GetRepeatedArgument("new_shape"); - - CAFFE_ENFORCE( - old_shape.size() == 2, - "Argument `old_shape` must contain exactly two integers."); - CAFFE_ENFORCE( - new_shape.size() == 2, - "Argument `new_shape` must contain exactly two integers."); - - CAFFE_ENFORCE( - old_shape[1] > 0, - "The second dimension in argument `old_shape` must be positive."); - - old_stride_ = old_shape[1]; - - if (old_shape[0] == -1) { - CAFFE_ENFORCE( - new_shape[1] > 0, - "The second dimension in `new_shape` must be positive."); - } else { - CAFFE_ENFORCE( - old_shape[0] > 0, - "The first dimension in `old_shape` must be positive."); - - TIndex matrix_size = old_shape[0] * old_shape[1]; - - if (new_shape[0] == -1) { - CAFFE_ENFORCE( - new_shape[1] > 0, - "Only one dimension in argument `new_shape` can be -1."); - CAFFE_ENFORCE( - matrix_size % new_shape[1] == 0, - "Argument `new_shape` does not agree with `old_shape`."); - } else { - CAFFE_ENFORCE( - new_shape[0] > 0 && (new_shape[1] == -1 || new_shape[1] > 0), - "Dimensions in argument `new_shape` must be positive or -1."); - if (new_shape[1] == -1) { - CAFFE_ENFORCE( - matrix_size % new_shape[0] == 0, - "Argument `new_shape` does not agree with `old_shape`."); - new_shape[1] = matrix_size / new_shape[0]; - } else { - CAFFE_ENFORCE( - new_shape[0] * new_shape[1] == matrix_size, - "Argument `new_shape` does not agree with `old_shape`."); - } - } - } - new_stride_ = new_shape[1]; - } - - bool RunOnDevice() override { - auto& old_col = Input(0); - CAFFE_ENFORCE(old_col.ndim() == 1, "Row index tensor must be 1-D."); - auto& old_row = Input(1); - CAFFE_ENFORCE(old_row.ndim() == 1, "Column index tensor must be 1-D."); - - const auto nnz = old_col.size(); - CAFFE_ENFORCE( - old_row.size() == nnz, - "Column and row tensors must have the same size."); - - auto* new_col = Output(0); - auto* new_row = Output(1); - new_col->Resize(nnz); - new_row->Resize(nnz); - - const auto* old_col_data = old_col.template data(); - const auto* old_row_data = old_row.template data(); - - auto* new_col_data = new_col->template mutable_data(); - auto* new_row_data = new_row->template mutable_data(); - - for (int i = 0; i < nnz; ++i) { - TIndex offset = old_row_data[i] * old_stride_ + old_col_data[i]; - new_row_data[i] = offset / new_stride_; - new_col_data[i] = offset % new_stride_; - } - - return true; - } - - private: - TIndex old_stride_; - TIndex new_stride_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPARSE_MATRIX_RESHAPE_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/tt_contraction_op.h b/app/src/main/cpp/caffe2/experiments/operators/tt_contraction_op.h deleted file mode 100644 index f58b40c..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/tt_contraction_op.h +++ /dev/null @@ -1,150 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TT_CONTRACTION_OP_H_ -#define CAFFE2_OPERATORS_TT_CONTRACTION_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class TTContractionOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTContractionOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - K_(OperatorBase::GetSingleArgument("K", 0)), - M_(OperatorBase::GetSingleArgument("M", 0)), - N_(OperatorBase::GetSingleArgument("N", 0)) { - CAFFE_ENFORCE(OperatorBase::HasArgument("K"), "Argument `K` is missing."); - CAFFE_ENFORCE(OperatorBase::HasArgument("M"), "Argument `M` is missing."); - CAFFE_ENFORCE(OperatorBase::HasArgument("N"), "Argument `N` is missing."); - } - - bool RunOnDevice() override { - const auto& A = Input(0); - const auto& B = Input(1); - auto* C = Output(0); - - CAFFE_ENFORCE(A.ndim() == 2, A.ndim()); - - TIndex A_size = A.size_from_dim(0); - TIndex B_size = B.size_from_dim(0); - - CAFFE_ENFORCE( - K_ * M_ == A_size, - "Argument `K` and `M` do not agree with the size of A."); - - CAFFE_ENFORCE( - B_size % (K_ * N_) == 0, - "Argument `K` and `N` do not agree with the size of B."); - - TIndex D_ = B_size / (K_ * N_); - - TIndex C_size = D_ * M_ * N_; - C->Resize(vector{C_size}); - - TIndex B_stride = K_ * N_; - TIndex C_stride = M_ * N_; - - const T* A_data = A.template data(); - const T* B_data = B.template data(); - T* C_data = C->template mutable_data(); - - for (TIndex B_index = 0; B_index < B_size; B_index += B_stride) { - math::Gemm( - CblasTrans, - CblasNoTrans, - M_, N_, K_, 1, - A_data, - B_data + B_index, - 0, - C_data, - &context_); - C_data += C_stride; - } - - return true; - } - - protected: - TIndex K_; - TIndex M_; - TIndex N_; -}; - -template -class TTContractionGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTContractionGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - K_(OperatorBase::GetSingleArgument("K", 0)), - M_(OperatorBase::GetSingleArgument("M", 0)), - N_(OperatorBase::GetSingleArgument("N", 0)) {} - - bool RunOnDevice() override { - const auto& G = Input(0); - const auto& A = Input(1); - const auto& B = Input(2); - auto* dA = Output(0); - auto* dB = Output(1); - - TIndex G_size = G.size_from_dim(0); - TIndex D_ = G_size / (M_ * N_); - - TIndex dB_size = D_ * K_ * N_; - - dA->Resize(A.dims()); - dB->Resize(B.dims()); - - TIndex B_stride = K_ * N_; - TIndex G_stride = M_ * N_; - - const T* G_data = G.template data(); - const T* A_data = A.template data(); - const T* B_data = B.template data(); - - T* dA_data = dA->template mutable_data(); - T* dB_data = dB->template mutable_data(); - - const T* G_ptr = G_data; - for (TIndex B_index = 0; B_index < dB_size; B_index += B_stride) { - math::Gemm( - CblasNoTrans, - CblasTrans, - K_, M_, N_, 1, - B_data + B_index, - G_ptr, - B_index == 0 ? 0 : 1, - dA_data, - &context_); - G_ptr += G_stride; - } - - G_ptr = G_data; - for (TIndex B_index = 0; B_index < dB_size; B_index += B_stride) { - math::Gemm( - CblasNoTrans, - CblasNoTrans, - K_, N_, M_, 1, - A_data, - G_ptr, - 0, - dB_data + B_index, - &context_); - G_ptr += G_stride; - } - - return true; - } - - protected: - TIndex K_; - TIndex M_; - TIndex N_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TT_CONTRACTION_OP_H_ diff --git a/app/src/main/cpp/caffe2/experiments/operators/tt_pad_op.h b/app/src/main/cpp/caffe2/experiments/operators/tt_pad_op.h deleted file mode 100644 index 220eecc..0000000 --- a/app/src/main/cpp/caffe2/experiments/operators/tt_pad_op.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TT_PAD_OP_H_ -#define CAFFE2_OPERATORS_TT_PAD_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class TTPadOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTPadOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 0)) { - CAFFE_ENFORCE( - OperatorBase::HasArgument("scale"), "Argument `scale` is missing."); - } - - bool RunOnDevice() override { - const auto& X = Input(0); - auto* X_pad = Output(0); - CAFFE_ENFORCE(&X == X_pad); - - CAFFE_ENFORCE(X.ndim() == 2, X.ndim()); - - auto X_dim0 = X.dim(0); - auto X_dim1 = X.dim(1); - - auto* X_orig_dim0 = Output(1); - X_orig_dim0->Resize(1); - *X_orig_dim0->template mutable_data() = X_dim0; - - if (X_dim0 % scale_ != 0) { - TIndex padded_dim0 = (X_dim0 / scale_ + 1) * scale_; - auto dim0_diff = padded_dim0 - X_dim0; - // set growthPct to the upper bound percentage: (100 * scale_ / X_dim0) - X_pad->template Extend(dim0_diff, 100 * scale_ / X_dim0, &context_); - - auto* X_pad_data = X_pad->template mutable_data(); - TIndex X_size = X_dim0 * X_dim1; - memset(X_pad_data + X_size, 0, dim0_diff * X_dim1 * sizeof(T)); - } - - return true; - } - - protected: - TIndex scale_; -}; - -template -class TTPadGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTPadGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - const auto& G = Input(0); - auto* output = Output(0); - CAFFE_ENFORCE(&G == output); - - auto old_dim0 = *Input(1).template data(); - auto new_dim0 = G.dim(0); - auto dim1 = G.dim(1); - - if (old_dim0 < new_dim0) { - output->Shrink(old_dim0); - } - - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TT_PAD_OP_H_ diff --git a/app/src/main/cpp/caffe2/image/image_input_op.h b/app/src/main/cpp/caffe2/image/image_input_op.h deleted file mode 100644 index 5387a11..0000000 --- a/app/src/main/cpp/caffe2/image/image_input_op.h +++ /dev/null @@ -1,1228 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_IMAGE_IMAGE_INPUT_OP_H_ -#define CAFFE2_IMAGE_IMAGE_INPUT_OP_H_ - -#include - -#include -#include - -#include "caffe/proto/caffe.pb.h" -#include "caffe2/core/db.h" -#include "caffe2/utils/cast.h" -#include "caffe2/utils/math.h" -#include "caffe2/utils/thread_pool.h" -#include "caffe2/operators/prefetch_op.h" -#include "caffe2/image/transform_gpu.h" - -namespace caffe2 { - -class CUDAContext; - -template -class ImageInputOp final - : public PrefetchOperator { - // SINGLE_LABEL: single integer label for multi-class classification - // MULTI_LABEL_SPARSE: sparse active label indices for multi-label classification - // MULTI_LABEL_DENSE: dense label embedding vector for label embedding regression - // MULTI_LABEL_WEIGHTED_SPARSE: sparse active label indices with per-label weights - // for multi-label classification - enum LABEL_TYPE { - SINGLE_LABEL = 0, - MULTI_LABEL_SPARSE = 1, - MULTI_LABEL_DENSE = 2, - MULTI_LABEL_WEIGHTED_SPARSE = 3 - }; - - // INCEPTION_STYLE: Random crop with size 8% - 100% image area and aspect - // ratio in [3/4, 4/3]. Reference: GoogleNet paper - enum SCALE_JITTER_TYPE { - NO_SCALE_JITTER = 0, - INCEPTION_STYLE = 1 - // TODO(zyan3): ResNet-style random scale jitter - }; - - public: - using OperatorBase::OutputSize; - using PrefetchOperator::context_; - using PrefetchOperator::prefetch_thread_; - explicit ImageInputOp(const OperatorDef& operator_def, - Workspace* ws); - ~ImageInputOp() { - PrefetchOperator::Finalize(); - } - - bool Prefetch() override; - bool CopyPrefetched() override; - - private: - using BoundingBox = struct { - bool valid; - int ymin; - int xmin; - int height; - int width; - }; - - // Structure to store per-image information - // This can be modified by the DecodeAnd* so needs - // to be privatized per launch. - using PerImageArg = struct { - BoundingBox bounding_params; - }; - - bool GetImageAndLabelAndInfoFromDBValue( - const string& value, cv::Mat* img, PerImageArg& info, int item_id, - std::mt19937* randgen); - void DecodeAndTransform( - const std::string& value, float *image_data, int item_id, - const int channels, std::size_t thread_index); - void DecodeAndTransposeOnly( - const std::string& value, uint8_t *image_data, int item_id, - const int channels, std::size_t thread_index); - - unique_ptr owned_reader_; - const db::DBReader* reader_; - CPUContext cpu_context_; - TensorCPU prefetched_image_; - TensorCPU prefetched_label_; - vector prefetched_additional_outputs_; - Tensor prefetched_image_on_device_; - Tensor prefetched_label_on_device_; - vector> prefetched_additional_outputs_on_device_; - // Default parameters for images - PerImageArg default_arg_; - int batch_size_; - LABEL_TYPE label_type_; - int num_labels_; - - bool color_; - bool color_jitter_; - float img_saturation_; - float img_brightness_; - float img_contrast_; - bool color_lighting_; - float color_lighting_std_; - std::vector> color_lighting_eigvecs_; - std::vector color_lighting_eigvals_; - SCALE_JITTER_TYPE scale_jitter_type_; - int scale_; - // Minsize is similar to scale except that it will only - // force the image to scale up if it is too small. In other words, - // it ensures that both dimensions of the image are at least minsize_ - int minsize_; - bool warp_; - int crop_; - std::vector mean_; - std::vector std_; - Tensor mean_gpu_; - Tensor std_gpu_; - bool mirror_; - bool is_test_; - bool use_caffe_datum_; - bool gpu_transform_; - bool mean_std_copied_ = false; - - // thread pool for parse + decode - int num_decode_threads_; - int additional_inputs_offset_; - int additional_inputs_count_; - std::shared_ptr thread_pool_; - - // Output type for GPU transform path - TensorProto_DataType output_type_; - - // random minsize - vector random_scale_; - bool random_scaling_; - - - // Working variables - std::vector randgen_per_thread_; -}; - -template -ImageInputOp::ImageInputOp( - const OperatorDef& operator_def, - Workspace* ws) - : PrefetchOperator(operator_def, ws), - reader_(nullptr), - prefetched_additional_outputs_(OutputSize() - 2), - prefetched_additional_outputs_on_device_(OutputSize() - 2), - batch_size_( - OperatorBase::template GetSingleArgument("batch_size", 0)), - label_type_(static_cast( - OperatorBase::template GetSingleArgument("label_type", 0))), - num_labels_( - OperatorBase::template GetSingleArgument("num_labels", 0)), - color_(OperatorBase::template GetSingleArgument("color", 1)), - color_jitter_( - OperatorBase::template GetSingleArgument("color_jitter", 0)), - img_saturation_(OperatorBase::template GetSingleArgument( - "img_saturation", - 0.4)), - img_brightness_(OperatorBase::template GetSingleArgument( - "img_brightness", - 0.4)), - img_contrast_( - OperatorBase::template GetSingleArgument("img_contrast", 0.4)), - color_lighting_( - OperatorBase::template GetSingleArgument("color_lighting", 0)), - color_lighting_std_(OperatorBase::template GetSingleArgument( - "color_lighting_std", - 0.1)), - scale_jitter_type_(static_cast( - OperatorBase::template GetSingleArgument( - "scale_jitter_type", - 0))), - scale_(OperatorBase::template GetSingleArgument("scale", -1)), - minsize_(OperatorBase::template GetSingleArgument("minsize", -1)), - warp_(OperatorBase::template GetSingleArgument("warp", 0)), - crop_(OperatorBase::template GetSingleArgument("crop", -1)), - mirror_(OperatorBase::template GetSingleArgument("mirror", 0)), - is_test_(OperatorBase::template GetSingleArgument( - OpSchema::Arg_IsTest, - 0)), - use_caffe_datum_( - OperatorBase::template GetSingleArgument("use_caffe_datum", 0)), - gpu_transform_(OperatorBase::template GetSingleArgument( - "use_gpu_transform", - 0)), - num_decode_threads_( - OperatorBase::template GetSingleArgument("decode_threads", 4)), - thread_pool_(std::make_shared(num_decode_threads_)), - // output type only supported with CUDA and use_gpu_transform for now - output_type_( - cast::GetCastDataType(ArgumentHelper(operator_def), "output_type")), - random_scale_( - OperatorBase::template GetRepeatedArgument("random_scale", {-1,-1})) { - if ((random_scale_[0] == -1) || (random_scale_[1] == -1)) { - random_scaling_ = false; - } else { - random_scaling_ = true; - minsize_ = random_scale_[0]; - } - - mean_ = OperatorBase::template GetRepeatedArgument( - "mean_per_channel", - {OperatorBase::template GetSingleArgument("mean", 0.)}); - - std_ = OperatorBase::template GetRepeatedArgument( - "std_per_channel", - {OperatorBase::template GetSingleArgument("std", 1.)}); - - vector additional_output_sizes = - OperatorBase::template GetRepeatedArgument( - "output_sizes", vector(OutputSize() - 2, 1)); - additional_inputs_count_ = OutputSize() - 2; - - default_arg_.bounding_params = { - false, - OperatorBase::template GetSingleArgument("bounding_ymin", -1), - OperatorBase::template GetSingleArgument("bounding_xmin", -1), - OperatorBase::template GetSingleArgument("bounding_height", -1), - OperatorBase::template GetSingleArgument("bounding_width", -1), - }; - - if (operator_def.input_size() == 0) { - LOG(ERROR) << "You are using an old ImageInputOp format that creates " - "a local db reader. Consider moving to the new style " - "that takes in a DBReader blob instead."; - string db_name = - OperatorBase::template GetSingleArgument("db", ""); - CAFFE_ENFORCE_GT(db_name.size(), 0, "Must specify a db name."); - owned_reader_.reset(new db::DBReader( - OperatorBase::template GetSingleArgument( - "db_type", "leveldb"), - db_name)); - reader_ = owned_reader_.get(); - } - - // hard-coded PCA eigenvectors and eigenvalues, based on RBG channel order - color_lighting_eigvecs_.push_back( - std::vector{-144.7125, 183.396, 102.2295}); - color_lighting_eigvecs_.push_back( - std::vector{-148.104, -1.1475, -207.57}); - color_lighting_eigvecs_.push_back( - std::vector{-148.818, -177.174, 107.1765}); - - color_lighting_eigvals_ = std::vector{0.2175, 0.0188, 0.0045}; - - CAFFE_ENFORCE_GT(batch_size_, 0, "Batch size should be nonnegative."); - if (use_caffe_datum_) { - CAFFE_ENFORCE_EQ(label_type_, SINGLE_LABEL, - "Caffe datum only supports single integer label"); - } - if (label_type_ != SINGLE_LABEL) { - CAFFE_ENFORCE_GT(num_labels_, 0, - "Number of labels must be set for using either sparse label indices or dense label embedding."); - } - if (label_type_ == MULTI_LABEL_WEIGHTED_SPARSE) { - additional_inputs_offset_ = 3; - } else { - additional_inputs_offset_ = 2; - } - CAFFE_ENFORCE((scale_ > 0) != (minsize_ > 0), - "Must provide one and only one of scaling or minsize"); - CAFFE_ENFORCE_GT(crop_, 0, "Must provide the cropping value."); - CAFFE_ENFORCE_GE( - scale_ > 0 ? scale_ : minsize_, - crop_, "The scale/minsize value must be no smaller than the crop value."); - - CAFFE_ENFORCE_EQ( - mean_.size(), - std_.size(), - "The mean and std. dev vectors must be of the same size."); - CAFFE_ENFORCE(mean_.size() == 1 || mean_.size() == 3, - "The mean and std. dev vectors must be of size 1 or 3"); - CAFFE_ENFORCE( - !use_caffe_datum_ || OutputSize() == 2, - "There can only be 2 outputs if the Caffe datum format is used"); - CAFFE_ENFORCE( - additional_output_sizes.size() == OutputSize() - 2, - "If the output sizes are specified, they must be specified for all " - "additional outputs"); - - CAFFE_ENFORCE(random_scale_.size() == 2, - "Must provide [scale_min, scale_max]"); - CAFFE_ENFORCE_GE(random_scale_[1], random_scale_[0], - "random scale must provide a range [min, max]"); - - if (default_arg_.bounding_params.ymin < 0 - || default_arg_.bounding_params.xmin < 0 - || default_arg_.bounding_params.height < 0 - || default_arg_.bounding_params.width < 0) { - default_arg_.bounding_params.valid = false; - } else { - default_arg_.bounding_params.valid = true; - } - - if (mean_.size() == 1) { - // We are going to extend to 3 using the first value - mean_.resize(3, mean_[0]); - std_.resize(3, std_[0]); - } - - LOG(INFO) << "Creating an image input op with the following setting: "; - LOG(INFO) << " Using " << num_decode_threads_ << " CPU threads;"; - if (gpu_transform_) { - LOG(INFO) << " Performing transformation on GPU"; - } - LOG(INFO) << " Outputting in batches of " << batch_size_ << " images;"; - LOG(INFO) << " Treating input image as " - << (color_ ? "color " : "grayscale ") << "image;"; - if (default_arg_.bounding_params.valid) { - LOG(INFO) << " Applying a default bounding box of Y [" - << default_arg_.bounding_params.ymin << "; " - << default_arg_.bounding_params.ymin + - default_arg_.bounding_params.height - << ") x X [" - << default_arg_.bounding_params.xmin << "; " - << default_arg_.bounding_params.xmin + - default_arg_.bounding_params.width - << ")"; - } - if (scale_ > 0 && !random_scaling_) { - LOG(INFO) << " Scaling image to " << scale_ - << (warp_ ? " with " : " without ") << "warping;"; - } else { - if (random_scaling_) { - // randomly set min_size_ for each image - LOG(INFO) << " Randomly scaling shortest side between " - << random_scale_[0] << " and " - << random_scale_[1]; - } else { - // Here, minsize_ > 0 - LOG(INFO) << " Ensuring minimum image size of " << minsize_ - << (warp_ ? " with " : " without ") << "warping;"; - } - } - LOG(INFO) << " " << (is_test_ ? "Central" : "Random") - << " cropping image to " << crop_ - << (mirror_ ? " with " : " without ") << "random mirroring;"; - LOG(INFO) << "Label Type: " << label_type_; - LOG(INFO) << "Num Labels: " << num_labels_; - - auto mit = mean_.begin(); - auto sit = std_.begin(); - - for (int i = 0; - mit != mean_.end() && sit != std_.end(); - ++mit, ++sit, ++i) { - LOG(INFO) << " Default [Channel " << i << "] Subtract mean " << *mit - << " and divide by std " << *sit << "."; - // We actually will use the inverse of std, so inverse it here - *sit = 1.f / *sit; - } - LOG(INFO) << " Outputting images as " - << OperatorBase::template GetSingleArgument("output_type", "unknown") << "."; - - std::mt19937 meta_randgen(time(nullptr)); - for (int i = 0; i < num_decode_threads_; ++i) { - randgen_per_thread_.emplace_back(meta_randgen()); - } - prefetched_image_.Resize( - TIndex(batch_size_), - TIndex(crop_), - TIndex(crop_), - TIndex(color_ ? 3 : 1)); - if (label_type_ != SINGLE_LABEL) { - prefetched_label_.Resize(TIndex(batch_size_), TIndex(num_labels_)); - } else { - prefetched_label_.Resize(vector(1, batch_size_)); - } - - for (int i = 0; i < additional_output_sizes.size(); ++i) { - prefetched_additional_outputs_[i].Resize( - TIndex(batch_size_), TIndex(additional_output_sizes[i])); - } -} - -// Inception-stype scale jittering -template -bool RandomSizedCropping( - cv::Mat* img, - const int crop, - std::mt19937* randgen -) { - cv::Mat scaled_img; - bool inception_scale_jitter = false; - int im_height = img->rows, im_width = img->cols; - int area = im_height * im_width; - std::uniform_real_distribution<> area_dis(0.08, 1.0); - std::uniform_real_distribution<> aspect_ratio_dis(3.0 / 4.0, 4.0 / 3.0); - - cv::Mat cropping; - for (int i = 0; i < 10; ++i) { - int target_area = int(ceil(area_dis(*randgen) * area)); - float aspect_ratio = aspect_ratio_dis(*randgen); - int nh = floor(std::sqrt(((float)target_area / aspect_ratio))); - int nw = floor(std::sqrt(((float)target_area * aspect_ratio))); - if (nh >= 1 && nh <= im_height && nw >=1 && nw <= im_width) { - int height_offset = std::uniform_int_distribution<>( - 0, im_height - nh)(*randgen); - int width_offset = std::uniform_int_distribution<>( - 0,im_width - nw)(*randgen); - cv::Rect ROI(width_offset, height_offset, nw, nh); - cropping = (*img)(ROI); - cv::resize( - cropping, - scaled_img, - cv::Size(crop, crop), - 0, - 0, - cv::INTER_AREA); - *img = scaled_img; - inception_scale_jitter = true; - break; - } - } - return inception_scale_jitter; -} - -template -bool ImageInputOp::GetImageAndLabelAndInfoFromDBValue( - const string& value, - cv::Mat* img, - PerImageArg& info, - int item_id, - std::mt19937* randgen) { - // - // recommend using --caffe2_use_fatal_for_enforce=1 when using ImageInputOp - // as this function runs on a worker thread and the exceptions from - // CAFFE_ENFORCE are silently dropped by the thread worker functions - // - cv::Mat src; - - // Use the default information for images - info = default_arg_; - if (use_caffe_datum_) { - // The input is a caffe datum format. - caffe::Datum datum; - CAFFE_ENFORCE(datum.ParseFromString(value)); - - prefetched_label_.mutable_data()[item_id] = datum.label(); - if (datum.encoded()) { - // encoded image in datum. - src = cv::imdecode( - cv::Mat( - 1, - datum.data().size(), - CV_8UC1, - const_cast(datum.data().data())), - color_ ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); - } else { - // Raw image in datum. - CAFFE_ENFORCE(datum.channels() == 3 || datum.channels() == 1); - - int src_c = datum.channels(); - src.create( - datum.height(), datum.width(), (src_c == 3) ? CV_8UC3 : CV_8UC1); - - if (src_c == 1) { - memcpy(src.ptr(0), datum.data().data(), datum.data().size()); - } else { - // Datum stores things in CHW order, let's do HWC for images to make - // things more consistent with conventional image storage. - for (int c = 0; c < 3; ++c) { - const char* datum_buffer = - datum.data().data() + datum.height() * datum.width() * c; - uchar* ptr = src.ptr(0) + c; - for (int h = 0; h < datum.height(); ++h) { - for (int w = 0; w < datum.width(); ++w) { - *ptr = *(datum_buffer++); - ptr += 3; - } - } - } - } - } - } else { - // The input is a caffe2 format. - TensorProtos protos; - CAFFE_ENFORCE(protos.ParseFromString(value)); - const TensorProto& image_proto = protos.protos(0); - const TensorProto& label_proto = protos.protos(1); - vector additional_output_protos; - int start = additional_inputs_offset_; - int end = start + additional_inputs_count_; - for (int i = start; i < end; ++i) { - additional_output_protos.push_back(protos.protos(i)); - } - - if (protos.protos_size() == end + 1) { - // We have bounding box information - const TensorProto& bounding_proto = protos.protos(end); - DCHECK_EQ(bounding_proto.data_type(), TensorProto::INT32); - DCHECK_EQ(bounding_proto.int32_data_size(), 4); - info.bounding_params.valid = true; - info.bounding_params.ymin = bounding_proto.int32_data(0); - info.bounding_params.xmin = bounding_proto.int32_data(1); - info.bounding_params.height = bounding_proto.int32_data(2); - info.bounding_params.width = bounding_proto.int32_data(3); - } - - if (image_proto.data_type() == TensorProto::STRING) { - // encoded image string. - DCHECK_EQ(image_proto.string_data_size(), 1); - const string& encoded_image_str = image_proto.string_data(0); - int encoded_size = encoded_image_str.size(); - // We use a cv::Mat to wrap the encoded str so we do not need a copy. - src = cv::imdecode( - cv::Mat( - 1, - &encoded_size, - CV_8UC1, - const_cast(encoded_image_str.data())), - color_ ? CV_LOAD_IMAGE_COLOR : CV_LOAD_IMAGE_GRAYSCALE); - } else if (image_proto.data_type() == TensorProto::BYTE) { - // raw image content. - int src_c = (image_proto.dims_size() == 3) ? image_proto.dims(2) : 1; - CAFFE_ENFORCE(src_c == 3 || src_c == 1); - - src.create( - image_proto.dims(0), - image_proto.dims(1), - (src_c == 3) ? CV_8UC3 : CV_8UC1); - memcpy( - src.ptr(0), - image_proto.byte_data().data(), - image_proto.byte_data().size()); - } else { - LOG(FATAL) << "Unknown image data type."; - } - - if (label_proto.data_type() == TensorProto::FLOAT) { - if (label_type_ == SINGLE_LABEL) { - DCHECK_EQ(label_proto.float_data_size(), 1); - prefetched_label_.mutable_data()[item_id] = - label_proto.float_data(0); - } else if (label_type_ == MULTI_LABEL_SPARSE) { - float* label_data = prefetched_label_.mutable_data() + - item_id * num_labels_; - memset(label_data, 0, sizeof(float) * num_labels_); - for (int i = 0; i < label_proto.float_data_size(); ++i) { - label_data[(int)label_proto.float_data(i)] = 1.0; - } - } else if (label_type_ == MULTI_LABEL_WEIGHTED_SPARSE) { - const TensorProto& weight_proto = protos.protos(2); - float* label_data = - prefetched_label_.mutable_data() + item_id * num_labels_; - memset(label_data, 0, sizeof(float) * num_labels_); - for (int i = 0; i < label_proto.float_data_size(); ++i) { - label_data[(int)label_proto.float_data(i)] = - weight_proto.float_data(i); - } - } else if (label_type_ == MULTI_LABEL_DENSE) { - CAFFE_ENFORCE(label_proto.float_data_size() == num_labels_); - float* label_data = prefetched_label_.mutable_data() + - item_id * num_labels_; - for (int i = 0; i < label_proto.float_data_size(); ++i) { - label_data[i] = label_proto.float_data(i); - } - } else { - LOG(ERROR) << "Unknown label type:" << label_type_; - } - } else if (label_proto.data_type() == TensorProto::INT32) { - if (label_type_ == SINGLE_LABEL) { - DCHECK_EQ(label_proto.int32_data_size(), 1); - prefetched_label_.mutable_data()[item_id] = - label_proto.int32_data(0); - } else if (label_type_ == MULTI_LABEL_SPARSE) { - int* label_data = prefetched_label_.mutable_data() + - item_id * num_labels_; - memset(label_data, 0, sizeof(int) * num_labels_); - for (int i = 0; i < label_proto.int32_data_size(); ++i) { - label_data[label_proto.int32_data(i)] = 1; - } - } else if (label_type_ == MULTI_LABEL_WEIGHTED_SPARSE) { - const TensorProto& weight_proto = protos.protos(2); - float* label_data = - prefetched_label_.mutable_data() + item_id * num_labels_; - memset(label_data, 0, sizeof(float) * num_labels_); - for (int i = 0; i < label_proto.int32_data_size(); ++i) { - label_data[label_proto.int32_data(i)] = weight_proto.float_data(i); - } - } else if (label_type_ == MULTI_LABEL_DENSE) { - CAFFE_ENFORCE(label_proto.int32_data_size() == num_labels_); - int* label_data = prefetched_label_.mutable_data() + - item_id * num_labels_; - for (int i = 0; i < label_proto.int32_data_size(); ++i) { - label_data[i] = label_proto.int32_data(i); - } - } else { - LOG(ERROR) << "Unknown label type:" << label_type_; - } - } else { - LOG(FATAL) << "Unsupported label data type."; - } - - for (int i = 0; i < additional_output_protos.size(); ++i) { - auto additional_output_proto = additional_output_protos[i]; - - if (additional_output_proto.data_type() == TensorProto::FLOAT) { - float* additional_output = - prefetched_additional_outputs_[i].template mutable_data() + - item_id * additional_output_proto.float_data_size(); - - for (int j = 0; j < additional_output_proto.float_data_size(); ++j) { - additional_output[j] = additional_output_proto.float_data(j); - } - } else if (additional_output_proto.data_type() == TensorProto::INT32) { - int* additional_output = - prefetched_additional_outputs_[i].template mutable_data() + - item_id * additional_output_proto.int32_data_size(); - - for (int j = 0; j < additional_output_proto.int32_data_size(); ++j) { - additional_output[j] = additional_output_proto.int32_data(j); - } - } else if (additional_output_proto.data_type() == TensorProto::INT64) { - int64_t* additional_output = - prefetched_additional_outputs_[i].template mutable_data() + - item_id * additional_output_proto.int64_data_size(); - - for (int j = 0; j < additional_output_proto.int64_data_size(); ++j) { - additional_output[j] = additional_output_proto.int64_data(j); - } - } - else { - LOG(FATAL) << "Unsupported output type."; - } - } - } - - // - // convert source to the color format requested from Op - // - int out_c = color_ ? 3 : 1; - if (out_c == src.channels()) { - *img = src; - } else { - cv::cvtColor(src, *img, (out_c == 1) ? CV_BGR2GRAY : CV_GRAY2BGR); - } - - // Note(Yangqing): I believe that the mat should be created continuous. - CAFFE_ENFORCE(img->isContinuous()); - - // Sanity check now that we decoded everything - - // Ensure that the bounding box is legit - if (info.bounding_params.valid - && (src.rows < info.bounding_params.ymin + info.bounding_params.height - || src.cols < info.bounding_params.xmin + info.bounding_params.width - )) { - info.bounding_params.valid = false; - } - - // Apply the bounding box if requested - if (info.bounding_params.valid) { - // If we reach here, we know the parameters are sane - cv::Rect bounding_box(info.bounding_params.xmin, info.bounding_params.ymin, - info.bounding_params.width, info.bounding_params.height); - *img = (*img)(bounding_box); - - /* - LOG(INFO) << "Did bounding with ymin:" - << info.bounding_params.ymin << " xmin:" << info.bounding_params.xmin - << " height:" << info.bounding_params.height - << " width:" << info.bounding_params.width << "\n"; - LOG(INFO) << "Bounded matrix: " << img; - */ - } else { - // LOG(INFO) << "No bounding\n"; - } - - cv::Mat scaled_img; - bool inception_scale_jitter = false; - if (scale_jitter_type_ == INCEPTION_STYLE) { - if (!is_test_) { - // Inception-stype scale jittering is only used for training - inception_scale_jitter = RandomSizedCropping(img, crop_, randgen); - // if a random crop is still not found, do simple random cropping later - } - } - - if ((scale_jitter_type_ == NO_SCALE_JITTER) || - (scale_jitter_type_ == INCEPTION_STYLE && !inception_scale_jitter)) { - int scaled_width, scaled_height; - int scale_to_use = scale_ > 0 ? scale_ : minsize_; - - // set the random minsize - if (random_scaling_) { - scale_to_use = std::uniform_int_distribution<>(random_scale_[0], - random_scale_[1])(*randgen); - } - - if (warp_) { - scaled_width = scale_to_use; - scaled_height = scale_to_use; - } else if (img->rows > img->cols) { - scaled_width = scale_to_use; - scaled_height = - static_cast(img->rows) * scale_to_use / img->cols; - } else { - scaled_height = scale_to_use; - scaled_width = - static_cast(img->cols) * scale_to_use / img->rows; - } - if ((scale_ > 0 && - (scaled_height != img->rows || scaled_width != img->cols)) - || (scaled_height > img->rows || scaled_width > img->cols)) { - // We rescale in all cases if we are using scale_ - // but only to make the image bigger if using minsize_ - /* - LOG(INFO) << "Scaling to " << scaled_width << " x " << scaled_height - << " From " << img->cols << " x " << img->rows; - */ - cv::resize( - *img, - scaled_img, - cv::Size(scaled_width, scaled_height), - 0, - 0, - cv::INTER_AREA); - *img = scaled_img; - } - } - // TODO(Yangqing): return false if any error happens. - return true; -} - -// assume HWC order and color channels BGR -template -void Saturation( - float* img, - const int img_size, - const float alpha_rand, - std::mt19937* randgen -) { - float alpha = 1.0f + - std::uniform_real_distribution(-alpha_rand, alpha_rand)(*randgen); - // BGR to Gray scale image: R -> 0.299, G -> 0.587, B -> 0.114 - int p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - float gray_color = img[3 * p] * 0.114f + img[3 * p + 1] * 0.587f + - img[3 * p + 2] * 0.299f; - for (int c = 0; c < 3; ++c) { - img[3 * p + c] = img[3 * p + c] * alpha + gray_color * (1.0f - alpha); - } - p++; - } - } -} - -// assume HWC order and color channels BGR -template -void Brightness( - float* img, - const int img_size, - const float alpha_rand, - std::mt19937* randgen -) { - float alpha = 1.0f + - std::uniform_real_distribution(-alpha_rand, alpha_rand)(*randgen); - int p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - for (int c = 0; c < 3; ++c) { - img[p++] *= alpha; - } - } - } -} - -// assume HWC order and color channels BGR -template -void Contrast( - float* img, - const int img_size, - const float alpha_rand, - std::mt19937* randgen -){ - float gray_mean = 0; - int p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - // BGR to Gray scale image: R -> 0.299, G -> 0.587, B -> 0.114 - gray_mean += img[3 * p] * 0.114f + img[3 * p + 1] * 0.587f + - img[3 * p + 2] * 0.299f; - p++; - } - } - gray_mean /= (img_size * img_size); - - float alpha = 1.0f + - std::uniform_real_distribution(-alpha_rand, alpha_rand)(*randgen); - p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - for (int c = 0; c < 3; ++c) { - img[p] = img[p] * alpha + gray_mean * (1.0f - alpha); - p++; - } - } - } -} - -// assume HWC order and color channels BGR -template -void ColorJitter( - float* img, - const int img_size, - const float saturation, - const float brightness, - const float contrast, - std::mt19937* randgen -) { - std::srand (unsigned(std::time(0))); - std::vector jitter_order{0, 1, 2}; - // obtain a time-based seed: - unsigned seed = std::chrono::system_clock::now().time_since_epoch().count(); - std::shuffle(jitter_order.begin(), jitter_order.end(), - std::default_random_engine(seed)); - - for (int i = 0; i < 3; ++i) { - if (jitter_order[i] == 0) { - Saturation(img, img_size, saturation, randgen); - } else if (jitter_order[i] == 1) { - Brightness(img, img_size, brightness, randgen); - } else { - Contrast(img, img_size, contrast, randgen); - } - } -} - -// assume HWC order and color channels BGR -template -void ColorLighting( - float* img, - const int img_size, - const float alpha_std, - const std::vector>& eigvecs, - const std::vector& eigvals, - std::mt19937* randgen -) { - std::normal_distribution d(0, alpha_std); - std::vector alphas(3); - for (int i = 0; i < 3; ++i) { - alphas[i] = d(*randgen); - } - - std::vector delta_rgb(3, 0.0); - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - delta_rgb[i] += eigvecs[i][j] * eigvals[j] * alphas[j]; - } - } - - int p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - for (int c = 0; c < 3; ++c) { - img[p++] += delta_rgb[2 - c]; - } - } - } - -} - -// assume HWC order and color channels BGR -// mean subtraction and scaling. -template -void ColorNormalization( - float* img, - const int img_size, - const int channels, - const std::vector& mean, - const std::vector& std -) { - int p = 0; - for (int h = 0; h < img_size; ++h) { - for (int w = 0; w < img_size; ++w) { - for (int c = 0; c < channels; ++c) { - img[p] = (img[p] - mean[c]) * std[c]; - p++; - } - } - } -} - -// Factored out image transformation -template -void TransformImage( - const cv::Mat& scaled_img, - const int channels, - float* image_data, - const bool color_jitter, - const float saturation, - const float brightness, - const float contrast, - const bool color_lighting, - const float color_lighting_std, - const std::vector>& color_lighting_eigvecs, - const std::vector& color_lighting_eigvals, - const int crop, - const bool mirror, - const std::vector& mean, - const std::vector& std, - std::mt19937* randgen, - std::bernoulli_distribution* mirror_this_image, - bool is_test = false) { - CAFFE_ENFORCE_GE( - scaled_img.rows, crop, "Image height must be bigger than crop."); - CAFFE_ENFORCE_GE( - scaled_img.cols, crop, "Image width must be bigger than crop."); - - // find the cropped region, and copy it to the destination matrix - int width_offset, height_offset; - if (is_test) { - width_offset = (scaled_img.cols - crop) / 2; - height_offset = (scaled_img.rows - crop) / 2; - } else { - width_offset = - std::uniform_int_distribution<>(0, scaled_img.cols - crop)(*randgen); - height_offset = - std::uniform_int_distribution<>(0, scaled_img.rows - crop)(*randgen); - } - - float* image_data_ptr = image_data; - if (!is_test && mirror && (*mirror_this_image)(*randgen)) { - // Copy mirrored image. - for (int h = height_offset; h < height_offset + crop; ++h) { - for (int w = width_offset + crop - 1; w >= width_offset; --w) { - const uint8_t* cv_data = scaled_img.ptr(h) + w * channels; - for (int c = 0; c < channels; ++c) { - *(image_data_ptr++) = static_cast(cv_data[c]); - } - } - } - } else { - // Copy normally. - for (int h = height_offset; h < height_offset + crop; ++h) { - for (int w = width_offset; w < width_offset + crop; ++w) { - const uint8_t* cv_data = scaled_img.ptr(h) + w * channels; - for (int c = 0; c < channels; ++c) { - *(image_data_ptr++) = static_cast(cv_data[c]); - } - } - } - } - - if (color_jitter && channels == 3 && !is_test) { - ColorJitter(image_data, crop, saturation, brightness, contrast, - randgen); - } - if (color_lighting && channels == 3 && !is_test) { - ColorLighting(image_data, crop, color_lighting_std, - color_lighting_eigvecs, color_lighting_eigvals, randgen); - } - - // Color normalization - // Mean subtraction and scaling. - ColorNormalization(image_data, crop, channels, mean, std); -} - -// Only crop / transose the image -// leave in uint8_t dataType -template -void CropTransposeImage(const cv::Mat& scaled_img, const int channels, - uint8_t *cropped_data, const int crop, - const bool mirror, std::mt19937 *randgen, - std::bernoulli_distribution *mirror_this_image, - bool is_test = false) { - CAFFE_ENFORCE_GE( - scaled_img.rows, crop, "Image height must be bigger than crop."); - CAFFE_ENFORCE_GE( - scaled_img.cols, crop, "Image width must be bigger than crop."); - - // find the cropped region, and copy it to the destination matrix - int width_offset, height_offset; - if (is_test) { - width_offset = (scaled_img.cols - crop) / 2; - height_offset = (scaled_img.rows - crop) / 2; - } else { - width_offset = - std::uniform_int_distribution<>(0, scaled_img.cols - crop)(*randgen); - height_offset = - std::uniform_int_distribution<>(0, scaled_img.rows - crop)(*randgen); - } - - if (mirror && (*mirror_this_image)(*randgen)) { - // Copy mirrored image. - for (int h = height_offset; h < height_offset + crop; ++h) { - for (int w = width_offset + crop - 1; w >= width_offset; --w) { - const uint8_t* cv_data = scaled_img.ptr(h) + w*channels; - for (int c = 0; c < channels; ++c) { - *(cropped_data++) = cv_data[c]; - } - } - } - } else { - // Copy normally. - for (int h = height_offset; h < height_offset + crop; ++h) { - for (int w = width_offset; w < width_offset + crop; ++w) { - const uint8_t* cv_data = scaled_img.ptr(h) + w*channels; - for (int c = 0; c < channels; ++c) { - *(cropped_data++) = cv_data[c]; - } - } - } - } -} - -// Parse datum, decode image, perform transform -// Intended as entry point for binding to thread pool -template -void ImageInputOp::DecodeAndTransform( - const std::string& value, float *image_data, int item_id, - const int channels, std::size_t thread_index) { - - CAFFE_ENFORCE((int)thread_index < num_decode_threads_); - - std::bernoulli_distribution mirror_this_image(0.5f); - std::mt19937* randgen = &(randgen_per_thread_[thread_index]); - - cv::Mat img; - // Decode the image - PerImageArg info; - CHECK(GetImageAndLabelAndInfoFromDBValue(value, &img, info, item_id, - randgen)); - - // Factor out the image transformation - TransformImage(img, channels, image_data, - color_jitter_, img_saturation_, img_brightness_, img_contrast_, - color_lighting_, color_lighting_std_, color_lighting_eigvecs_, - color_lighting_eigvals_, crop_, mirror_, mean_, std_, - randgen, &mirror_this_image, is_test_); -} - -template -void ImageInputOp::DecodeAndTransposeOnly( - const std::string& value, uint8_t *image_data, int item_id, - const int channels, std::size_t thread_index) { - - CAFFE_ENFORCE((int)thread_index < num_decode_threads_); - - std::bernoulli_distribution mirror_this_image(0.5f); - std::mt19937* randgen = &(randgen_per_thread_[thread_index]); - - cv::Mat img; - // Decode the image - PerImageArg info; - CHECK(GetImageAndLabelAndInfoFromDBValue(value, &img, info, item_id, - randgen)); - - // Factor out the image transformation - CropTransposeImage(img, channels, image_data, crop_, mirror_, - randgen, &mirror_this_image, is_test_); -} - - -template -bool ImageInputOp::Prefetch() { - if (!owned_reader_.get()) { - // if we are not owning the reader, we will get the reader pointer from - // input. Otherwise the constructor should have already set the reader - // pointer. - reader_ = &OperatorBase::Input(0); - } - const int channels = color_ ? 3 : 1; - // Call mutable_data() once to allocate the underlying memory. - if (gpu_transform_) { - // we'll transfer up in int8, then convert later - prefetched_image_.mutable_data(); - } else { - prefetched_image_.mutable_data(); - } - - prefetched_label_.mutable_data(); - // Prefetching handled with a thread pool of "decode_threads" threads. - - for (int item_id = 0; item_id < batch_size_; ++item_id) { - std::string key, value; - cv::Mat img; - - // read data - reader_->Read(&key, &value); - - // determine label type based on first item - if( item_id == 0 ) { - if( use_caffe_datum_ ) { - prefetched_label_.mutable_data(); - } else { - TensorProtos protos; - CAFFE_ENFORCE(protos.ParseFromString(value)); - TensorProto_DataType labeldt = protos.protos(1).data_type(); - if( labeldt == TensorProto::INT32 ) { - prefetched_label_.mutable_data(); - } else if ( labeldt == TensorProto::FLOAT) { - prefetched_label_.mutable_data(); - } else { - LOG(FATAL) << "Unsupported label type."; - } - - for (int i = 0; i < additional_inputs_count_; ++i) { - int index = additional_inputs_offset_ + i; - TensorProto additional_output_proto = protos.protos(index); - - if (additional_output_proto.data_type() == TensorProto::FLOAT) { - prefetched_additional_outputs_[i].template mutable_data(); - } else if ( - additional_output_proto.data_type() == TensorProto::INT32) { - prefetched_additional_outputs_[i].template mutable_data(); - } else if ( - additional_output_proto.data_type() == TensorProto::INT64) { - prefetched_additional_outputs_[i].template mutable_data(); - } else { - LOG(FATAL) << "Unsupported output type."; - } - } - } - } - - // launch into thread pool for processing - // TODO: support color jitter and color lighting in gpu_transform - if (gpu_transform_) { - // output of decode will still be int8 - uint8_t* image_data = prefetched_image_.mutable_data() + - crop_ * crop_ * channels * item_id; - thread_pool_->runTaskWithID(std::bind( - &ImageInputOp::DecodeAndTransposeOnly, - this, - std::string(value), - image_data, - item_id, - channels, - std::placeholders::_1)); - } else { - float* image_data = prefetched_image_.mutable_data() + - crop_ * crop_ * channels * item_id; - thread_pool_->runTaskWithID(std::bind( - &ImageInputOp::DecodeAndTransform, - this, - std::string(value), - image_data, - item_id, - channels, - std::placeholders::_1)); - } - } - thread_pool_->waitWorkComplete(); - - // If the context is not CPUContext, we will need to do a copy in the - // prefetch function as well. - if (!std::is_same::value) { - prefetched_image_on_device_.CopyFrom(prefetched_image_, &context_); - prefetched_label_on_device_.CopyFrom(prefetched_label_, &context_); - - for (int i = 0; i < prefetched_additional_outputs_on_device_.size(); ++i) { - prefetched_additional_outputs_on_device_[i].CopyFrom( - prefetched_additional_outputs_[i], &context_); - } - } - return true; -} - -template -bool ImageInputOp::CopyPrefetched() { - auto* image_output = OperatorBase::Output >(0); - auto* label_output = OperatorBase::Output >(1); - vector*> additional_outputs_output; - - for (int i = 2; i < OutputSize(); ++i) { - additional_outputs_output.push_back( - OperatorBase::Output>(i)); - } - - // Note(jiayq): The if statement below should be optimized away by the - // compiler since std::is_same is a constexpr. - if (std::is_same::value) { - image_output->CopyFrom(prefetched_image_, &context_); - label_output->CopyFrom(prefetched_label_, &context_); - - for (int i = 0; i < additional_outputs_output.size(); ++i) { - additional_outputs_output[i]->CopyFrom( - prefetched_additional_outputs_[i], &context_); - } - } else { - // TODO: support color jitter and color lighting in gpu_transform - if (gpu_transform_) { - if (!mean_std_copied_) { - mean_gpu_.Resize(mean_.size()); - std_gpu_.Resize(std_.size()); - - context_.template Copy( - mean_.size(), mean_.data(), mean_gpu_.template mutable_data()); - context_.template Copy( - std_.size(), std_.data(), std_gpu_.template mutable_data()); - mean_std_copied_ = true; - } - // GPU transform kernel allows explicitly setting output type - if (output_type_ == TensorProto_DataType_FLOAT) { - TransformOnGPU(prefetched_image_on_device_, - image_output, mean_gpu_, - std_gpu_, &context_); - } else if (output_type_ == TensorProto_DataType_FLOAT16) { - TransformOnGPU(prefetched_image_on_device_, - image_output, mean_gpu_, - std_gpu_, &context_); - } else { - return false; - } - } else { - image_output->CopyFrom(prefetched_image_on_device_, &context_); - } - label_output->CopyFrom(prefetched_label_on_device_, &context_); - - for (int i = 0; i < additional_outputs_output.size(); ++i) { - additional_outputs_output[i]->CopyFrom( - prefetched_additional_outputs_on_device_[i], &context_); - } - } - return true; -} -} // namespace caffe2 - -#endif // CAFFE2_IMAGE_IMAGE_INPUT_OP_H_ diff --git a/app/src/main/cpp/caffe2/image/transform_gpu.h b/app/src/main/cpp/caffe2/image/transform_gpu.h deleted file mode 100644 index a19b525..0000000 --- a/app/src/main/cpp/caffe2/image/transform_gpu.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CAFFE2_IMAGE_TRANSFORM_GPU_H_ -#define CAFFE2_IMAGE_TRANSFORM_GPU_H_ - -/** - * - * Copyright (c) 2016, NVIDIA CORPORATION, All rights reserved - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - **/ - -#include "caffe2/core/context.h" - -namespace caffe2 { - -template -bool TransformOnGPU(Tensor& X, Tensor* Y, - Tensor& mean, Tensor& std, - Context* context); - -} // namespace caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/mkl/mkl_utils.h b/app/src/main/cpp/caffe2/mkl/mkl_utils.h deleted file mode 100644 index 9514129..0000000 --- a/app/src/main/cpp/caffe2/mkl/mkl_utils.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_UTILS_H_ -#define CAFFE2_UTILS_MKL_UTILS_H_ - -#include "caffe2/core/macros.h" // For caffe2 macros. - -#ifdef CAFFE2_USE_MKL - -#include "caffe2/mkl/utils/mkl_version_check.h" - -// MKLDNN_CHECK should be used in places where exceptions should not be thrown, -// such as in destructors. -#define MKLDNN_CHECK(condition) \ - do { \ - dnnError_t error = condition; \ - CAFFE_ENFORCE_EQ( \ - error, \ - E_SUCCESS, \ - "Error at : ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ", error number: ", \ - error); \ - } while (0) - -#define MKLDNN_SAFE_CALL(condition) \ - do { \ - dnnError_t error = condition; \ - CAFFE_ENFORCE_EQ( \ - error, \ - E_SUCCESS, \ - "Error at : ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ", error number: ", \ - error); \ - } while (0) - -#define CHECK_INPUT_FILTER_DIMS(X, filter, condition) \ - do { \ - if (cached_input_dims_ != X.dims() || \ - cached_filter_dims_ != filter.dims()) { \ - cached_input_dims_ = X.dims(); \ - cached_filter_dims_ = filter.dims(); \ - condition = true; \ - } else { \ - condition = false; \ - } \ - } while (0) - -#define CHECK_INPUT_DIMS(X, condition) \ - do { \ - if (cached_input_dims_ != X.dims()) { \ - cached_input_dims_ = X.dims(); \ - condition = true; \ - } else { \ - condition = false; \ - } \ - } while (0) - -// All caffe2 mkl related headers - -#ifdef CAFFE2_HAS_MKL_DNN -#include "caffe2/mkl/utils/mkl_context.h" -#include "caffe2/mkl/utils/mkl_dnn_cppwrapper.h" -#include "caffe2/mkl/utils/mkl_memory.h" -#include "caffe2/mkl/utils/mkl_operator.h" -#endif // CAFFE2_HAS_MKL_DNN - -#ifdef CAFFE2_HAS_MKL_SGEMM_PACK -#include "caffe2/mkl/utils/sgemm_pack.h" -#endif // CAFFE2_HAS_MKL_SGEMM_PACK - -#endif // CAFFE2_USE_MKL -#endif // CAFFE2_UTILS_MKL_UTILS_H_ diff --git a/app/src/main/cpp/caffe2/mkl/operators/operator_fallback_mkl.h b/app/src/main/cpp/caffe2/mkl/operators/operator_fallback_mkl.h deleted file mode 100644 index cc90bc1..0000000 --- a/app/src/main/cpp/caffe2/mkl/operators/operator_fallback_mkl.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ -#define CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/mkl/mkl_utils.h" -#include "caffe2/proto/caffe2.pb.h" - -#ifdef CAFFE2_HAS_MKL_DNN -namespace caffe2 { -namespace mkl { - -/** - * @brief A templated class to allow one to wrap a CPU operator as an MKL - * operator. - * - * This class can be used when one does not have the MKL implementation ready - * yet for an operator. Essentially, what this op does is to automatically - * deal with data copy for you. Plausibly, this causes a lot of overhead and - * is not optimal, so you should use this operator mostly for quick prototyping - * purpose. - * - * All the input and output of the original operator should be TensorCPU. - * - * Example usage: if you have a class MyMagicOp that is CPU based, and you use - * the registration code - * REGISTER_CPU_OPERATOR(MyMagic, MyMagicOp); - * to register the CPU side, you can create its corresponding MKL operator - * (with performance hits of course) via - * REGISTER_MKL_OPERATOR(MyMagic, - * MKLFallbackOp); - * - * Advanced usage: if you want to have some specific outputs never copied, you - * can use the SkipOutputCopy template argument to do that. For example, if - * MyMagic produces two outputs and the first output is always going to live on - * the CPU, you can do - * REGISTER_MKL_OPERATOR(MyMagic, - * MKLFallbackOp>); - */ -template > -class MKLFallbackOp final : public Operator { - public: - USE_OPERATOR_FUNCTIONS(MKLContext); - MKLFallbackOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) { - CAFFE_ENFORCE_EQ(def.device_option().device_type(), MKLDNN); - OperatorDef base_def_(def); - // base_def_ runs on CPU, so we will set its device option to CPU. - // Copy to allow random_seed to be correctly propagated. - base_def_.mutable_device_option()->CopyFrom(def.device_option()); - base_def_.mutable_device_option()->set_device_type(CPU); - // Set up the symbols for the local workspace. - for (const string& name : def.input()) { - local_input_blobs_.push_back(local_ws_.CreateBlob(name)); - CHECK_NOTNULL(local_input_blobs_.back()); - } - base_op_.reset(new CPUOp(base_def_, &local_ws_)); - for (const string& name : def.output()) { - local_output_blobs_.push_back(local_ws_.GetBlob(name)); - CHECK_NOTNULL(local_output_blobs_.back()); - } - } - - bool RunOnDevice() override { - for (int i = 0; i < InputSize(); ++i) { - if (OperatorBase::InputIsType>(i)) { - OperatorBase::Input>(i).CopyTo( - local_input_blobs_[i]->template GetMutable()); - } else if (OperatorBase::InputIsType>(i)) { - OperatorBase::Input>(i).CopyTo( - local_input_blobs_[i]->template GetMutable()); - } else { - VLOG(1) << "Input " << i << " is not MKLMemory. Skipping copy."; - // Note(jiayq): This removes a const but conceptually - // local_input_blobs will only be used as const blob input for the - // base op so we are still fine. - local_input_blobs_[i]->ShareExternal( - const_cast(OperatorBase::Inputs()[i]->GetRaw()), - OperatorBase::Inputs()[i]->meta()); - } - } - - if (!base_op_->Run()) { - LOG(ERROR) << "Base op run failed in MKLFallbackOp. Def: " - << ProtoDebugString(this->debug_def()); - return false; - } - - for (int i = 0; i < OutputSize(); ++i) { - if (SkipOutputCopy::Contains(i)) { - VLOG(1) << "Copy output: index " << i << " skipped."; - continue; - } - CAFFE_ENFORCE( - local_output_blobs_[i]->template IsType(), - "MKL fallback op currently does not support non-TensorCPU " - "output type who needs copying."); - const auto& src = local_output_blobs_[i]->template Get(); - if (src.template IsType()) { - Blob* dst = OperatorBase::OutputBlob(i); - if (!dst->template IsType>() || - dst->Get>().dims() != src.dims()) { - dst->Reset(new MKLMemory(src.dims())); - } - dst->GetMutable>()->CopyFrom(src); - } else if (src.template IsType()) { - Blob* dst = OperatorBase::OutputBlob(i); - if (!dst->template IsType>() || - dst->Get>().dims() != src.dims()) { - dst->Reset(new MKLMemory(src.dims())); - } - dst->GetMutable>()->CopyFrom(src); - } else { - CAFFE_THROW("MKLMemory only supports float and double."); - } - } - return true; - } - - protected: - Workspace local_ws_; - vector local_input_blobs_; - vector local_output_blobs_; - std::unique_ptr base_op_; -}; -} - -} // namespace caffe2 - -#endif // CAFFE2_HAS_MKL_DNN -#endif // CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ diff --git a/app/src/main/cpp/caffe2/mkl/utils/mkl_context.h b/app/src/main/cpp/caffe2/mkl/utils/mkl_context.h deleted file mode 100644 index 7186ed7..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/mkl_context.h +++ /dev/null @@ -1,112 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_CONTEXT_H_ -#define CAFFE2_UTILS_MKL_CONTEXT_H_ - -#include -#include -#include - -#include "caffe2/core/context.h" - -namespace caffe2 { - -/** - * The MKL Context, which is largely the same as the CPUContext. We instantiate - * this mainly in order to have a first-class MKL device. - * - * Note that although New() and Delete() are implemented, we expect MKLContext - * operators to mainly perform input and output via MKLMemory. As a result, - * most likely MKLContext::New and ::Delete won't be used as often. - */ -class MKLContext final { - public: - MKLContext() : random_seed_(math::randomNumberSeed()) {} - explicit MKLContext(const DeviceOption& option) - : random_seed_( - option.has_random_seed() ? option.random_seed() - : math::randomNumberSeed()) { - CAFFE_ENFORCE_EQ(option.device_type(), MKLDNN); - } - - ~MKLContext() {} - - inline void SwitchToDevice(int /*stream_id*/ = 0) {} - inline void WaitEvent(const Event& ev) { - ev.Wait(MKLDNN, this); - } - inline void Record(Event* ev) const { - CAFFE_ENFORCE(ev, "Event must not be null."); - ev->Record(MKLDNN, this); - } - inline void FinishDeviceComputation() {} - - inline std::mt19937& RandGenerator() { - if (!random_generator_.get()) { - random_generator_.reset(new std::mt19937(random_seed_)); - } - return *random_generator_.get(); - } - - inline static std::pair New(size_t nbytes) { - return GetCPUAllocator()->New(nbytes); - } - - // Two copy functions that deals with cross-device copies. - template - inline void CopyBytes(size_t nbytes, const void* src, void* dst); - - template - inline void Copy(size_t n, const T* src, T* dst) { - if (std::is_fundamental::value) { - CopyBytes( - n * sizeof(T), - static_cast(src), - static_cast(dst)); - } else { - for (int i = 0; i < n; ++i) { - dst[i] = src[i]; - } - } - } - - template - inline void - CopyItems(const TypeMeta& meta, size_t n, const void* src, void* dst) { - if (meta.copy()) { - meta.copy()(src, dst, n); - } else { - CopyBytes(n * meta.itemsize(), src, dst); - } - } - - protected: - // TODO(jiayq): instead of hard-coding a generator, make it more flexible. - int random_seed_{1701}; - std::unique_ptr random_generator_; -}; - -template <> -inline void MKLContext::CopyBytes( - size_t nbytes, - const void* src, - void* dst) { - memcpy(dst, src, nbytes); -} - -template <> -inline void MKLContext::CopyBytes( - size_t nbytes, - const void* src, - void* dst) { - memcpy(dst, src, nbytes); -} - -template <> -inline void MKLContext::CopyBytes( - size_t nbytes, - const void* src, - void* dst) { - memcpy(dst, src, nbytes); -} -} // namespace caffe2 - -#endif // CAFFE2_UTILS_MKL_CONTEXT_H_ diff --git a/app/src/main/cpp/caffe2/mkl/utils/mkl_dnn_cppwrapper.h b/app/src/main/cpp/caffe2/mkl/utils/mkl_dnn_cppwrapper.h deleted file mode 100644 index f775c0f..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/mkl_dnn_cppwrapper.h +++ /dev/null @@ -1,1269 +0,0 @@ -// Do not directl include this file. Include caffe2/mkl/mkl_utils.h instead. -#ifndef CAFFE2_UTILS_MKL_MKL_DNN_CPPWRAPPER_H -#define CAFFE2_UTILS_MKL_MKL_DNN_CPPWRAPPER_H - -#include -#include - -#include - -#define C2_MKL_TEMPLATE_PREFIX \ - template \ - inline -#define C2_MKL_SPEC_PREFIX \ - template <> \ - inline - -namespace caffe2 { -namespace mkl { - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnLayoutCreate( - dnnLayout_t* pLayout, - size_t dimension, - const size_t size[], - const size_t strides[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutCreate( - dnnLayout_t* pLayout, - size_t dimension, - const size_t size[], - const size_t strides[]) { - return dnnLayoutCreate_F32(pLayout, dimension, size, strides); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutCreate( - dnnLayout_t* pLayout, - size_t dimension, - const size_t size[], - const size_t strides[]) { - return dnnLayoutCreate_F64(pLayout, dimension, size, strides); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnLayoutCreateFromPrimitive( - dnnLayout_t* pLayout, - const dnnPrimitive_t primitive, - dnnResourceType_t type); -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutCreateFromPrimitive( - dnnLayout_t* pLayout, - const dnnPrimitive_t primitive, - dnnResourceType_t type) { - return dnnLayoutCreateFromPrimitive_F32(pLayout, primitive, type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutCreateFromPrimitive( - dnnLayout_t* pLayout, - const dnnPrimitive_t primitive, - dnnResourceType_t type) { - return dnnLayoutCreateFromPrimitive_F64(pLayout, primitive, type); -} - -C2_MKL_TEMPLATE_PREFIX size_t dnnLayoutGetMemorySize(const dnnLayout_t layout); -C2_MKL_SPEC_PREFIX size_t -dnnLayoutGetMemorySize(const dnnLayout_t layout) { - return dnnLayoutGetMemorySize_F32(layout); -} -C2_MKL_SPEC_PREFIX size_t -dnnLayoutGetMemorySize(const dnnLayout_t layout) { - return dnnLayoutGetMemorySize_F64(layout); -} - -C2_MKL_TEMPLATE_PREFIX int dnnLayoutCompare( - const dnnLayout_t l1, - const dnnLayout_t l2); -C2_MKL_SPEC_PREFIX int dnnLayoutCompare( - const dnnLayout_t l1, - const dnnLayout_t l2) { - return dnnLayoutCompare_F32(l1, l2); -} -C2_MKL_SPEC_PREFIX int dnnLayoutCompare( - const dnnLayout_t l1, - const dnnLayout_t l2) { - return dnnLayoutCompare_F64(l1, l2); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnAllocateBuffer(void** pPtr, dnnLayout_t layout); -C2_MKL_SPEC_PREFIX dnnError_t -dnnAllocateBuffer(void** pPtr, dnnLayout_t layout) { - return dnnAllocateBuffer_F32(pPtr, layout); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnAllocateBuffer(void** pPtr, dnnLayout_t layout) { - return dnnAllocateBuffer_F64(pPtr, layout); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnReleaseBuffer(void* ptr); -C2_MKL_SPEC_PREFIX dnnError_t dnnReleaseBuffer(void* ptr) { - return dnnReleaseBuffer_F32(ptr); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnReleaseBuffer(void* ptr) { - return dnnReleaseBuffer_F64(ptr); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnLayoutDelete(dnnLayout_t layout); -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutDelete(dnnLayout_t layout) { - return dnnLayoutDelete_F32(layout); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnLayoutDelete(dnnLayout_t layout) { - return dnnLayoutDelete_F64(layout); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnPrimitiveAttributesCreate(dnnPrimitiveAttributes_t* attributes); -C2_MKL_SPEC_PREFIX dnnError_t -dnnPrimitiveAttributesCreate(dnnPrimitiveAttributes_t* attributes) { - return dnnPrimitiveAttributesCreate_F32(attributes); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnPrimitiveAttributesCreate(dnnPrimitiveAttributes_t* attributes) { - return dnnPrimitiveAttributesCreate_F64(attributes); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnPrimitiveAttributesDestroy(dnnPrimitiveAttributes_t attributes); -C2_MKL_SPEC_PREFIX dnnError_t -dnnPrimitiveAttributesDestroy(dnnPrimitiveAttributes_t attributes) { - return dnnPrimitiveAttributesDestroy_F32(attributes); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnPrimitiveAttributesDestroy(dnnPrimitiveAttributes_t attributes) { - return dnnPrimitiveAttributesDestroy_F64(attributes); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnPrimitiveGetAttributes( - dnnPrimitive_t primitive, - dnnPrimitiveAttributes_t* attributes); -C2_MKL_SPEC_PREFIX dnnError_t dnnPrimitiveGetAttributes( - dnnPrimitive_t primitive, - dnnPrimitiveAttributes_t* attributes) { - return dnnPrimitiveGetAttributes_F32(primitive, attributes); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnPrimitiveGetAttributes( - dnnPrimitive_t primitive, - dnnPrimitiveAttributes_t* attributes) { - return dnnPrimitiveGetAttributes_F64(primitive, attributes); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnExecute(dnnPrimitive_t primitive, void* resources[]); -C2_MKL_SPEC_PREFIX dnnError_t -dnnExecute(dnnPrimitive_t primitive, void* resources[]) { - return dnnExecute_F32(primitive, resources); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnExecute(dnnPrimitive_t primitive, void* resources[]) { - return dnnExecute_F64(primitive, resources); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnExecuteAsync(dnnPrimitive_t primitive, void* resources[]); -C2_MKL_SPEC_PREFIX dnnError_t -dnnExecuteAsync(dnnPrimitive_t primitive, void* resources[]) { - return dnnExecuteAsync_F32(primitive, resources); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnExecuteAsync(dnnPrimitive_t primitive, void* resources[]) { - return dnnExecuteAsync_F64(primitive, resources); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnWaitFor(dnnPrimitive_t primitive); -C2_MKL_SPEC_PREFIX dnnError_t dnnWaitFor(dnnPrimitive_t primitive) { - return dnnWaitFor_F32(primitive); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnWaitFor(dnnPrimitive_t primitive) { - return dnnWaitFor_F64(primitive); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnDelete(dnnPrimitive_t primitive); -C2_MKL_SPEC_PREFIX dnnError_t dnnDelete(dnnPrimitive_t primitive) { - return dnnDelete_F32(primitive); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnDelete(dnnPrimitive_t primitive) { - return dnnDelete_F64(primitive); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConversionCreate( - dnnPrimitive_t* pConversion, - const dnnLayout_t from, - const dnnLayout_t to); -C2_MKL_SPEC_PREFIX dnnError_t dnnConversionCreate( - dnnPrimitive_t* pConversion, - const dnnLayout_t from, - const dnnLayout_t to) { - return dnnConversionCreate_F32(pConversion, from, to); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConversionCreate( - dnnPrimitive_t* pConversion, - const dnnLayout_t from, - const dnnLayout_t to) { - return dnnConversionCreate_F64(pConversion, from, to); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t -dnnConversionExecute(dnnPrimitive_t conversion, void* from, void* to); -C2_MKL_SPEC_PREFIX dnnError_t -dnnConversionExecute(dnnPrimitive_t conversion, void* from, void* to) { - return dnnConversionExecute_F32(conversion, from, to); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnConversionExecute(dnnPrimitive_t conversion, void* from, void* to) { - return dnnConversionExecute_F64(conversion, from, to); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateForward_F32( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateForward_F64( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateForwardBias_F32( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateForwardBias_F64( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateBackwardData_F32( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateBackwardData_F64( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateBackwardFilter_F32( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnConvolutionCreateBackwardFilter_F64( - pConvolution, - attributes, - algorithm, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t dstSize[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t dstSize[]) { - return dnnConvolutionCreateBackwardBias_F32( - pConvolution, attributes, algorithm, dimension, dstSize); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t dimension, - const size_t dstSize[]) { - return dnnConvolutionCreateBackwardBias_F64( - pConvolution, attributes, algorithm, dimension, dstSize); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnGroupsConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateForward_F32( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateForward( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateForward_F64( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnGroupsConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateForwardBias_F32( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateForwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateForwardBias_F64( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateBackwardData_F32( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardData( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateBackwardData_F64( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateBackwardFilter_F32( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardFilter( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t srcSize[], - const size_t dstSize[], - const size_t filterSize[], - const size_t convolutionStrides[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnGroupsConvolutionCreateBackwardFilter_F64( - pConvolution, - attributes, - algorithm, - groups, - dimension, - srcSize, - dstSize, - filterSize, - convolutionStrides, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t dstSize[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t dstSize[]) { - return dnnGroupsConvolutionCreateBackwardBias_F32( - pConvolution, attributes, algorithm, groups, dimension, dstSize); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnGroupsConvolutionCreateBackwardBias( - dnnPrimitive_t* pConvolution, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t algorithm, - size_t groups, - size_t dimension, - const size_t dstSize[]) { - return dnnGroupsConvolutionCreateBackwardBias_F64( - pConvolution, attributes, algorithm, groups, dimension, dstSize); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnReLUCreateForward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float negativeSlope); -C2_MKL_SPEC_PREFIX dnnError_t dnnReLUCreateForward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float negativeSlope) { - return dnnReLUCreateForward_F32(pRelu, attributes, dataLayout, negativeSlope); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnReLUCreateForward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float negativeSlope) { - return dnnReLUCreateForward_F64(pRelu, attributes, dataLayout, negativeSlope); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnReLUCreateBackward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - float negativeSlope); -C2_MKL_SPEC_PREFIX dnnError_t dnnReLUCreateBackward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - float negativeSlope) { - return dnnReLUCreateBackward_F32( - pRelu, attributes, diffLayout, dataLayout, negativeSlope); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnReLUCreateBackward( - dnnPrimitive_t* pRelu, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - float negativeSlope) { - return dnnReLUCreateBackward_F64( - pRelu, attributes, diffLayout, dataLayout, negativeSlope); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnLRNCreateForward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k); -C2_MKL_SPEC_PREFIX dnnError_t dnnLRNCreateForward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k) { - return dnnLRNCreateForward_F32( - pLrn, attributes, dataLayout, kernel_size, alpha, beta, k); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnLRNCreateForward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k) { - return dnnLRNCreateForward_F64( - pLrn, attributes, dataLayout, kernel_size, alpha, beta, k); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnLRNCreateBackward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k); -C2_MKL_SPEC_PREFIX dnnError_t dnnLRNCreateBackward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k) { - return dnnLRNCreateBackward_F32( - pLrn, attributes, diffLayout, dataLayout, kernel_size, alpha, beta, k); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnLRNCreateBackward( - dnnPrimitive_t* pLrn, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t diffLayout, - const dnnLayout_t dataLayout, - size_t kernel_size, - float alpha, - float beta, - float k) { - return dnnLRNCreateBackward_F64( - pLrn, attributes, diffLayout, dataLayout, kernel_size, alpha, beta, k); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnPoolingCreateForward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnPoolingCreateForward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnPoolingCreateForward_F32( - pPooling, - attributes, - op, - srcLayout, - kernelSize, - kernelStride, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnPoolingCreateForward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnPoolingCreateForward_F64( - pPooling, - attributes, - op, - srcLayout, - kernelSize, - kernelStride, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnPoolingCreateBackward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type); -C2_MKL_SPEC_PREFIX dnnError_t dnnPoolingCreateBackward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnPoolingCreateBackward_F32( - pPooling, - attributes, - op, - srcLayout, - kernelSize, - kernelStride, - inputOffset, - border_type); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnPoolingCreateBackward( - dnnPrimitive_t* pPooling, - dnnPrimitiveAttributes_t attributes, - dnnAlgorithm_t op, - const dnnLayout_t srcLayout, - const size_t kernelSize[], - const size_t kernelStride[], - const int inputOffset[], - const dnnBorder_t border_type) { - return dnnPoolingCreateBackward_F64( - pPooling, - attributes, - op, - srcLayout, - kernelSize, - kernelStride, - inputOffset, - border_type); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnConcatCreate( - dnnPrimitive_t* pConcat, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnConcatCreate( - dnnPrimitive_t* pConcat, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src[]) { - return dnnConcatCreate_F32(pConcat, attributes, N, src); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnConcatCreate( - dnnPrimitive_t* pConcat, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src[]) { - return dnnConcatCreate_F64(pConcat, attributes, N, src); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnSplitCreate( - dnnPrimitive_t* pSplit, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src, - size_t dst[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnSplitCreate( - dnnPrimitive_t* pSplit, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src, - size_t dst[]) { - return dnnSplitCreate_F32(pSplit, attributes, N, src, dst); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnSplitCreate( - dnnPrimitive_t* pSplit, - dnnPrimitiveAttributes_t attributes, - const size_t N, - dnnLayout_t src, - size_t dst[]) { - return dnnSplitCreate_F64(pSplit, attributes, N, src, dst); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnSumCreate( - dnnPrimitive_t* pSum, - dnnPrimitiveAttributes_t attributes, - const size_t nSummands, - dnnLayout_t layout, - T* coefficients); -C2_MKL_SPEC_PREFIX dnnError_t dnnSumCreate( - dnnPrimitive_t* pSum, - dnnPrimitiveAttributes_t attributes, - const size_t nSummands, - dnnLayout_t layout, - float* coefficients) { - return dnnSumCreate_F32(pSum, attributes, nSummands, layout, coefficients); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnSumCreate( - dnnPrimitive_t* pSum, - dnnPrimitiveAttributes_t attributes, - const size_t nSummands, - dnnLayout_t layout, - double* coefficients) { - return dnnSumCreate_F64(pSum, attributes, nSummands, layout, coefficients); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnBatchNormalizationCreateForward( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps); -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateForward( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateForward_F32( - pBatchNormalization, attributes, dataLayout, eps); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateForward( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateForward_F64( - pBatchNormalization, attributes, dataLayout, eps); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnBatchNormalizationCreateBackwardData( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps); -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateBackwardData( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateBackwardData_F32( - pBatchNormalization, attributes, dataLayout, eps); -} - -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateBackwardData( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateBackwardData_F64( - pBatchNormalization, attributes, dataLayout, eps); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnBatchNormalizationCreateBackwardScaleShift( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps); -C2_MKL_SPEC_PREFIX dnnError_t -dnnBatchNormalizationCreateBackwardScaleShift( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateBackwardScaleShift_F32( - pBatchNormalization, attributes, dataLayout, eps); -} -C2_MKL_SPEC_PREFIX dnnError_t -dnnBatchNormalizationCreateBackwardScaleShift( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps) { - return dnnBatchNormalizationCreateBackwardScaleShift_F64( - pBatchNormalization, attributes, dataLayout, eps); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnBatchNormalizationCreateForward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags); -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateForward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags) { - return dnnBatchNormalizationCreateForward_v2_F32( - pBatchNormalization, attributes, dataLayout, eps, flags); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateForward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags) { - return dnnBatchNormalizationCreateForward_v2_F64( - pBatchNormalization, attributes, dataLayout, eps, flags); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnBatchNormalizationCreateBackward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags); -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateBackward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags) { - return dnnBatchNormalizationCreateBackward_v2_F32( - pBatchNormalization, attributes, dataLayout, eps, flags); -} - -C2_MKL_SPEC_PREFIX dnnError_t dnnBatchNormalizationCreateBackward_v2( - dnnPrimitive_t* pBatchNormalization, - dnnPrimitiveAttributes_t attributes, - const dnnLayout_t dataLayout, - float eps, - unsigned int flags) { - return dnnBatchNormalizationCreateBackward_v2_F64( - pBatchNormalization, attributes, dataLayout, eps, flags); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnInnerProductCreateForward( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels); -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateForward( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateForward_F32( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateForward( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateForward_F64( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnInnerProductCreateForwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels); -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateForwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateForwardBias_F32( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateForwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateForwardBias_F64( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnInnerProductCreateBackwardData( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels); -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardData( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateBackwardData_F32( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardData( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateBackwardData_F64( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnInnerProductCreateBackwardFilter( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels); -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardFilter( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateBackwardFilter_F32( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardFilter( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[], - size_t outputChannels) { - return dnnInnerProductCreateBackwardFilter_F64( - pInnerProduct, attributes, dimensions, srcSize, outputChannels); -} - -C2_MKL_TEMPLATE_PREFIX dnnError_t dnnInnerProductCreateBackwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[]); -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[]) { - return dnnInnerProductCreateBackwardBias_F32( - pInnerProduct, attributes, dimensions, srcSize); -} -C2_MKL_SPEC_PREFIX dnnError_t dnnInnerProductCreateBackwardBias( - dnnPrimitive_t* pInnerProduct, - dnnPrimitiveAttributes_t attributes, - size_t dimensions, - const size_t srcSize[]) { - return dnnInnerProductCreateBackwardBias_F64( - pInnerProduct, attributes, dimensions, srcSize); -} - -} // namespace mkl -} // namespace caffe2 - -// Undef macros to make sure that things are clean. -#undef C2_MKL_TEMPLATE_PREFIX -#undef C2_MKL_SPEC_PREFIX - -#endif // CAFFE2_UTILS_MKL_MKL_DNN_CPPWRAPPER_H diff --git a/app/src/main/cpp/caffe2/mkl/utils/mkl_memory.h b/app/src/main/cpp/caffe2/mkl/utils/mkl_memory.h deleted file mode 100644 index f895444..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/mkl_memory.h +++ /dev/null @@ -1,475 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_MKL_MEMORY_H_ -#define CAFFE2_UTILS_MKL_MKL_MEMORY_H_ - -#include -#include -#include - -#include "caffe2/core/flags.h" // for TIndex -#include "caffe2/core/tensor.h" // for TIndex -#include "caffe2/mkl/utils/mkl_dnn_cppwrapper.h" - -// A global boolean variable that controls the behavior when we call View() on -// an MKLMemory: if it is set true, then the View() function will actually -// change the underlying storage. If it is set false, an implicit copy is -// triggered but the original storage is not affected. -CAFFE2_DECLARE_bool(caffe2_mkl_implicit_layout_change); - -namespace caffe2 { -namespace mkl { - -template -class PrimitiveWrapper { - public: - PrimitiveWrapper() {} - // Creates a primitive wrapper from an existing primitive. The wrapper - // takes over ownership. - explicit PrimitiveWrapper(dnnPrimitive_t primitive) : primitive_(primitive) {} - - template - PrimitiveWrapper(Creator creator, FirstArg&& arg, Args&&... args) { - creator(&primitive_, arg, args...); - } - - ~PrimitiveWrapper() { - if (primitive_) { - MKLDNN_CHECK(dnnDelete(primitive_)); - } - } - - template - void Reset(Creator creator, Args&&... args) { - if (primitive_) { - MKLDNN_SAFE_CALL(dnnDelete(primitive_)); - } - creator(&primitive_, args...); - } - - operator dnnPrimitive_t() const { - return primitive_; - } - - private: - dnnPrimitive_t primitive_ = 0; - DISABLE_COPY_AND_ASSIGN(PrimitiveWrapper); -}; - -template -class LayoutWrapper { - public: - LayoutWrapper() {} - // Create a user layout from a TensorCPU with the given shapes. - explicit LayoutWrapper(const TensorCPU& tensor) { - Reset(tensor); - } - - // Create an internal layout from the primitive and type. - LayoutWrapper(const dnnPrimitive_t primitive, const dnnResourceType_t type) { - Reset(primitive, type); - } - - // Create a user layout from the given dimension, size and strides. - LayoutWrapper( - const size_t dimension, - const size_t size[], - const size_t strides[]) { - Reset(dimension, size, strides); - } - - // Destructs the layout wrapper. - ~LayoutWrapper() { - if (layout_) - MKLDNN_CHECK(dnnLayoutDelete(layout_)); - } - - // Create a user layout from a TensorCPU with the given shapes. - void Reset(const TensorCPU& tensor) { - if (layout_) - MKLDNN_CHECK(dnnLayoutDelete(layout_)); - CAFFE_ENFORCE(tensor.size(), "Cannot reset with an empty tensor."); - size_t dimension = tensor.ndim(); - size_t size[dimension]; - size_t strides[dimension]; - for (int i = 0; i < dimension; ++i) { - size[i] = tensor.dim(dimension - i - 1); - strides[i] = (i == 0) ? 1 : strides[i - 1] * size[i - 1]; - } - MKLDNN_SAFE_CALL(dnnLayoutCreate(&layout_, dimension, size, strides)); - } - - // Create an internal layout from the primitive and type. - void Reset(const dnnPrimitive_t primitive, const dnnResourceType_t type) { - CAFFE_ENFORCE(primitive, "Cannot reset with an unknwon primitive."); - CAFFE_ENFORCE( - type != dnnResourceNumber, - "Cannot reset with an unknown resource number."); - if (layout_) { - MKLDNN_CHECK(dnnLayoutDelete(layout_)); - } - MKLDNN_SAFE_CALL( - dnnLayoutCreateFromPrimitive(&layout_, primitive, type)); - } - - // Create a user layout from the given dimension, size and strides. - void - Reset(const size_t dimension, const size_t size[], const size_t strides[]) { - if (layout_) - MKLDNN_CHECK(dnnLayoutDelete(layout_)); - MKLDNN_SAFE_CALL(dnnLayoutCreate(&layout_, dimension, size, strides)); - } - - operator dnnLayout_t() const { - return layout_; - } - - private: - dnnLayout_t layout_ = 0; - DISABLE_COPY_AND_ASSIGN(LayoutWrapper); -}; - -/** - * @brief A wrapper around an opaque MKL internal resource that has certain - * layouts and convertion primitives set up. - * - * Most of the MKLMemory functions are not thread safe. - */ -template -class MKLMemory { - public: - // Initializes an empty MKLMemory. - MKLMemory() {} - // Initialize an MKLMemory with the given size, strides, dnn - // primitive and type. - MKLMemory( - const size_t dimension, - const size_t size[], - const size_t strides[], - const dnnPrimitive_t primitive = nullptr, - const dnnResourceType_t type = dnnResourceNumber, - bool share_mem_if_possible = false) { - Reset(dimension, size, strides, primitive, type, share_mem_if_possible); - } - - // Initialize an MKLMemory, with the given dimension assuming a C-contiguous - // storage. - template - explicit MKLMemory( - const vector& dims, - const dnnPrimitive_t primitive = nullptr, - const dnnResourceType_t type = dnnResourceNumber, - bool share_mem_if_possible = false) { - Reset(dims, primitive, type, share_mem_if_possible); - } - - // Initialize an MKLMemory with the given size, strides, dnn - // primitive and type. - void Reset( - const size_t dimension, - const size_t size[], - const size_t strides[], - const dnnPrimitive_t primitive = nullptr, - const dnnResourceType_t type = dnnResourceNumber, - bool share_mem_if_possible = false) { - buffer_.reset(); - dims_.resize(dimension); - for (int i = 0; i < dimension; ++i) { - dims_[i] = size[dimension - 1 - i]; - } - user_layout_.Reset(dimension, size, strides); - if (primitive) { - layout_.Reset(primitive, type); - } else { - layout_.Reset(dimension, size, strides); - } - convert_in_.Reset(dnnConversionCreate, user_layout_, layout_); - convert_out_.Reset(dnnConversionCreate, layout_, user_layout_); - share_mem_if_possible_ = share_mem_if_possible; - layout_is_user_layout_ = dnnLayoutCompare(layout_, user_layout_); - VLOG(2) << "layout is user layout? " << layout_is_user_layout_; - if (!share_mem_if_possible_) { - // If we are not going to share memory, we will simply allocate - // memory upfront. - buffer(); - } - } - - // Initialize an MKLMemory, with the given dimension assuming a C-contiguous - // storage. - template - void Reset( - const vector& dims, - const dnnPrimitive_t primitive = nullptr, - const dnnResourceType_t type = dnnResourceNumber, - bool share_mem_if_possible = false) { - buffer_.reset(); - dims_.resize(dims.size()); - for (int i = 0; i < dims.size(); ++i) { - dims_[i] = dims[i]; - } - size_t dimension = dims.size(); - vector size(dimension); - vector strides(dimension); - for (int i = 0; i < dimension; ++i) { - size[i] = dims[dimension - i - 1]; - strides[i] = (i == 0) ? 1 : strides[i - 1] * size[i - 1]; - } - user_layout_.Reset(dims.size(), size.data(), strides.data()); - if (primitive) { - layout_.Reset(primitive, type); - } else { - layout_.Reset(dimension, size.data(), strides.data()); - } - convert_in_.Reset(dnnConversionCreate, user_layout_, layout_); - convert_out_.Reset(dnnConversionCreate, layout_, user_layout_); - share_mem_if_possible_ = share_mem_if_possible; - layout_is_user_layout_ = dnnLayoutCompare(layout_, user_layout_); - VLOG(2) << "layout is user layout? " << layout_is_user_layout_; - if (!share_mem_if_possible_) { - // If we are not going to share memory, we will simply allocate - // memory upfront. - buffer(); - } - } - - // Destructs the MKLMemory. - ~MKLMemory() {} - - void CopyFrom(const void* ptr) { - if (share_mem_if_possible_ && layout_is_user_layout_) { - VLOG(2) << "Sharing underlying memory and skip copy."; - buffer_.reset(const_cast(ptr), [](void*) -> void {}); - } else { - VLOG(2) << "Copying external content."; - MKLDNN_SAFE_CALL(dnnConversionExecute( - convert_in_, const_cast(ptr), buffer())); - } - } - - void CopyFrom(const TensorCPU& tensor) { - CAFFE_ENFORCE_EQ( - tensor.dims(), - dims_, - "Dims does not match the expected dims of the resource."); - CopyFrom(tensor.template data()); - } - - void CopyFrom(const MKLMemory& other) { - if (share_mem_if_possible_ && dnnLayoutCompare(other.layout_, layout_)) { - buffer_ = other.buffer_; - } else { - PrimitiveWrapper convert( - dnnConversionCreate, other.layout_, layout_); - MKLDNN_SAFE_CALL( - dnnConversionExecute(convert, other.buffer_, buffer())); - } - } - - bool ShareFromRaw(const void* ptr) { - if (share_mem_if_possible_ && layout_is_user_layout_) { - buffer_.reset(const_cast(ptr), [](void*) -> void {}); - return true; - } else { - return false; - } - } - - bool ShareFromTensor(const TensorCPU& tensor) { - CAFFE_ENFORCE_EQ( - tensor.dims(), - dims_, - "Dims does not match the expected dims of the resource."); - return ShareFromRaw(tensor.template data()); - } - - bool ShareFrom(const MKLMemory& other) { - if (share_mem_if_possible_ && dnnLayoutCompare(other.layout_, layout_)) { - VLOG(2) << "Sharing underlying memory."; - buffer_ = other.buffer_; - if (!buffer_.get()) { - VLOG(2) << "Warning: the source MKLMemory has no content yet, so the " - "sharing actually has no effect."; - } - return true; - } else { - VLOG(2) << "Not sharing underlying memory."; - return false; - } - } - - void CopyTo(void* ptr) const { - if (buffer_.get() == ptr) { - // This is already mapping to the same memory region. Skip copy. - VLOG(2) << "CopyTo does not need actual copying, as we are sharing " - "memory with the output."; - return; - } - CAFFE_ENFORCE( - buffer_.get(), "Canot copy out from an uninitialized MKLMemory."); - VLOG(2) << "Copy to external memory."; - MKLDNN_SAFE_CALL(dnnConversionExecute(convert_out_, buffer_.get(), ptr)); - } - - void CopyTo(TensorCPU* tensor) const { - if (tensor->size() > 0 && buffer_.get() == tensor->mutable_data()) { - // This is already mapping to the same memory region. Skip copy. - VLOG(2) << "CopyTo does not need actual copying, as we are sharing " - "memory with the output."; - return; - } - tensor->Resize(dims_); - CopyTo(tensor->mutable_data()); - } - - // Copies to another MKL memory. - // - // This function - void CopyTo( - MKLMemory* other, - const dnnPrimitive_t primitive = nullptr, - const dnnResourceType_t type = dnnResourceNumber) { - if (buffer_.get() == other->buffer_.get()) { - VLOG(2) << "CopyTo does not need actual copying, as we are sharing " - "memory with the output."; - // This is already mapping to the same memory region. Skip copy. - return; - } - CAFFE_ENFORCE( - buffer_.get(), "Canot copy out from an uninitialized MKLMemory."); - // TODO(jiayq): if primitive creation is a big overhead and we will be - // consistently copying stuff with fixed src and dst layouts, consider - // making a cache for the primitive below. - VLOG(2) << "CopyTo requires copying. Performing direct copy."; - PrimitiveWrapper convert( - dnnConversionCreate, layout_, other->layout_); - if (dnnPrimitive_t(convert) == nullptr || - dnnConversionExecute(convert, buffer_.get(), other->buffer()) != - E_SUCCESS) { - VLOG(2) << "Direct copy failed, will need to allocate output."; - // If CopyTo directly did not succeed, it could be because the target - // MKLMemory is not having the right layout. In this case we will reset - // the target and then do another copy. - other->Reset(dims_, primitive, type); - PrimitiveWrapper convert2( - dnnConversionCreate, layout_, other->layout_); - MKLDNN_SAFE_CALL( - dnnConversionExecute(convert2, buffer_.get(), other->buffer())); - } - } - - inline void* buffer() { - if (buffer_ == nullptr) { - CAFFE_ENFORCE( - layout_ != nullptr, "Trying to allocate buffer but layout is empty."); - void* allocated = nullptr; - MKLDNN_SAFE_CALL(dnnAllocateBuffer(&allocated, layout_)); - buffer_.reset(allocated, [](void* ptr) -> void { - MKLDNN_CHECK(dnnReleaseBuffer(ptr)); - }); - } - return buffer_.get(); - } - - // MKLDNN does not use const void* even for the inputs, so we will - // have to use void* and rely on the underlying implementation to make - // sure that the buffer is actually not changed. - inline void* buffer() const { - CAFFE_ENFORCE( - buffer_ != nullptr, "Trying to refer to an unallocated buffer."); - return buffer_.get(); - } - - inline const vector& dims() const { - return dims_; - } - - inline const int ndim() const { return dims_.size(); } - - inline int dim32(const int i) const { - CAFFE_ENFORCE_LT(dims_.at(i), std::numeric_limits::max()); - return static_cast(dims_[i]); - } - - /** - * Returns the i-th dimension of the tensor. Note that the passed in index - * must be between 0 (inclusive) and the number of dimensions, otherwise - * this function will produce a fatal message. - */ - inline TIndex dim(const int i) const { - return dims_.at(i); - } - - inline const LayoutWrapper& layout() const { - return layout_; - } - - // Returns a view of the content. We mark this function const, but be noted - // that the returned std::shared_ptr is not const protected - user discretion - // is recommended for correctness. - std::shared_ptr View( - dnnLayout_t layout_wanted, - dnnPrimitive_t primitive, - dnnResourceType_t type) const { - std::lock_guard lock(buffer_lock_); - if (dnnLayoutCompare(layout_wanted, layout_)) { - // If they are the same, return the original content. - VLOG(2) << "Creating a view without the need of copying."; - return std::shared_ptr(buffer_); - } else { - void* temp_buffer; - VLOG(2) << "Creating a view with copying."; - MKLDNN_SAFE_CALL(dnnAllocateBuffer(&temp_buffer, layout_wanted)); - PrimitiveWrapper convert( - dnnConversionCreate, layout_, layout_wanted); - MKLDNN_SAFE_CALL(dnnConversionExecute( - convert, buffer_.get(), temp_buffer)); - if (FLAGS_caffe2_mkl_implicit_layout_change) { - VLOG(2) << "Implicit layout change set. " - "Changing the underlying storage."; - // We will need to call Reset to set up all the member variables. - // This is not thread safe, so we might want to double check if this - // makes sense in actual use cases. - const_cast*>(this)->Reset( - dims_, primitive, type, share_mem_if_possible_); - CAFFE_ENFORCE(dnnLayoutCompare(layout_wanted, layout_), - "You passed in a target layout that is not " - "generated by the given primitive and type."); - buffer_.reset(temp_buffer, [](void* ptr) -> void { - MKLDNN_CHECK(dnnReleaseBuffer(ptr)); - }); - return std::shared_ptr(buffer_); - } else { - return std::shared_ptr(temp_buffer, [](void* ptr) -> void { - MKLDNN_CHECK(dnnReleaseBuffer(ptr)); - }); - } - } - } - - private: - bool share_mem_if_possible_; - bool layout_is_user_layout_; - // The internal buffer in the specific dnn layout. - // It is marked mutable but any modification in a const function should - // be accompanied by the buffer lock, see the View() function. - mutable std::shared_ptr buffer_; - // A mutex to control the access of buffer in the View() function. - mutable std::mutex buffer_lock_; - // The dimensions in the same order as Caffe2 does. This is used to - // interface with C2. - vector dims_; - // The user dnn layout. - LayoutWrapper user_layout_; - // The internal dnn layout. - LayoutWrapper layout_; - // The primitive to use to convert from user layout to internal layout - PrimitiveWrapper convert_in_; - // The primitive to use to convert from internal layout to user layout - PrimitiveWrapper convert_out_; - - DISABLE_COPY_AND_ASSIGN(MKLMemory); -}; - -} // namespace mkl -} // namespace caffe2 - -#endif // CAFFE2_UTILS_MKL_MKL_MEMORY_H_ diff --git a/app/src/main/cpp/caffe2/mkl/utils/mkl_operator.h b/app/src/main/cpp/caffe2/mkl/utils/mkl_operator.h deleted file mode 100644 index 23189fb..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/mkl_operator.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_OPERATOR_H_ -#define CAFFE2_UTILS_MKL_OPERATOR_H_ - -#include "caffe2/core/operator.h" -#include "caffe2/mkl/utils/mkl_dnn_cppwrapper.h" -#include "caffe2/mkl/utils/mkl_memory.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -CAFFE_DECLARE_REGISTRY( - MKLOperatorRegistry, - OperatorBase, - const OperatorDef&, - Workspace*); -#define REGISTER_MKL_OPERATOR_CREATOR(key, ...) \ - CAFFE_REGISTER_CREATOR(MKLOperatorRegistry, key, __VA_ARGS__) -#define REGISTER_MKL_OPERATOR(name, ...) \ - CAFFE_REGISTER_CLASS(MKLOperatorRegistry, name, __VA_ARGS__) -#define REGISTER_MKL_OPERATOR_STR(str_name, ...) \ - CAFFE_REGISTER_TYPED_CLASS(MKLOperatorRegistry, str_name, __VA_ARGS__) - -#define REGISTER_MKL_OPERATOR_WITH_ENGINE(name, engine, ...) \ - CAFFE_REGISTER_CLASS(MKLOperatorRegistry, name##_ENGINE_##engine, __VA_ARGS__) - -namespace mkl { -// MKLOperator is the base scaffolding of the operators that uses MKLDNN. It -// provides a few operators that are useful to MKLDNN specific implementations. -template -class MKLOperator : public OperatorBase { - public: - explicit MKLOperator(const OperatorDef& operator_def, Workspace* ws) - : OperatorBase(operator_def, ws), - context_(operator_def.device_option()) {} - virtual ~MKLOperator() {} - - inline const MKLMemory& Input(int idx) { - return OperatorBase::template Input>(idx); - } - inline MKLMemory* Output(int idx) { - return OperatorBase::template Output>(idx); - } - - // The run function of Operator switches to the device, and then carries out - // the actual computation with RunOnDevice(). You should implement RunOnDevice - // instead of Run(). - bool Run(int /* unused */ /*stream_id*/) final { - // Since MKLDNN does not need to do SwithToDevice and - // FinishDeviceComputation, - // it is always just a re-route to RunOnDevice(). - try { - return RunOnDevice(); - } catch (EnforceNotMet& err) { - err.AppendMessage( - "Error from operator: \n" + ProtoDebugString(debug_def())); - throw; - } - } - - // Waits for a previous event. Note that to properly wait and run - // asynchronously, WaitEvent, RunAsync and Record should all be executed - // on the same CPU thread. - void WaitEvent(const Event& ev) final { - context_.SwitchToDevice(); - context_.WaitEvent(ev); - } - - void Record() final { - context_.SwitchToDevice(); - context_.Record(&event_); - } - - virtual bool RunOnDevice() = 0; - - inline void ExecutePrimitive() { - MKLDNN_SAFE_CALL(mkl::dnnExecute(primitive_, resources_)); - } - - protected: - MKLContext context_; - // The primitive used in the operator. - PrimitiveWrapper primitive_; - // Size cache for all the input sizes. - vector> input_size_cache_; - // An internal MKLMemory buffer. This is usually handy when we have a - // single output from the operator. If your operator has multiple outputs - // then you should allocate your own buffer. - MKLMemory buffer_; - // The resources vector that we will need to use; - void* resources_[dnnResourceNumber]; -}; -} // namespace mkl - -#define USE_MKLOPERATOR_FUNCTIONS(T) \ - USE_OPERATOR_BASE_FUNCTIONS; \ - /* using override */ using MKLOperator::Input; \ - /* using override */ using MKLOperator::Output; \ - /* using override */ using MKLOperator::ExecutePrimitive; \ - /* using override */ using MKLOperator::primitive_; \ - /* using override */ using MKLOperator::input_size_cache_; \ - /* using override */ using MKLOperator::buffer_; \ - /* using override */ using MKLOperator::resources_ - -#define USE_SIMPLE_MKL_CTOR_DTOR(name, T) \ - name(const OperatorDef& operator_def, Workspace* ws) \ - : MKLOperator(operator_def, ws) {} \ - virtual ~name() {} - -} // namespace caffe2 - -#endif // CAFFE2_UTILS_MKL_OPERATOR_H_ diff --git a/app/src/main/cpp/caffe2/mkl/utils/mkl_version_check.h b/app/src/main/cpp/caffe2/mkl/utils/mkl_version_check.h deleted file mode 100644 index 7a125c2..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/mkl_version_check.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_MKL_VERSION_CHECK_H_ -#define CAFFE2_UTILS_MKL_MKL_VERSION_CHECK_H_ -#ifdef CAFFE2_USE_MKL - -#include - -#if INTEL_MKL_VERSION >= 20170000 -#define CAFFE2_HAS_MKL_SGEMM_PACK -#define CAFFE2_HAS_MKL_DNN -#endif // INTEL_MKL_VERSION >= 20170000 - -#endif // CAFFE2_USE_MKL -#endif // CAFFE2_UTILS_MKL_MKL_VERSION_CHECK_H_ diff --git a/app/src/main/cpp/caffe2/mkl/utils/sgemm_pack.h b/app/src/main/cpp/caffe2/mkl/utils/sgemm_pack.h deleted file mode 100644 index 5d45f84..0000000 --- a/app/src/main/cpp/caffe2/mkl/utils/sgemm_pack.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef CAFFE2_UTILS_MKL_SGEMM_PACK_H_ -#define CAFFE2_UTILS_MKL_SGEMM_PACK_H_ - -#include "caffe2/core/logging.h" - -namespace caffe2 { -namespace mkl { -struct MKLPackedMatrix { - CBLAS_IDENTIFIER identifier_; - CBLAS_TRANSPOSE trans_; - int m_; - int n_; - int k_; - float alpha_; - int ld_; - float* data_ = nullptr; - - MKLPackedMatrix( - const CBLAS_IDENTIFIER identifier, - const CBLAS_TRANSPOSE trans, - const int m, - const int n, - const int k, - const float alpha, - const float* src, - const int ld) - : identifier_(identifier), - trans_(trans), - m_(m), - n_(n), - k_(k), - alpha_(alpha), - ld_(ld) { - data_ = cblas_sgemm_alloc(identifier, m, n, k); - CAFFE_ENFORCE(data_, "MKL runtime error: cannot allocate sgemm memory."); - cblas_sgemm_pack( - CblasRowMajor, identifier, trans, m, n, k, alpha, src, ld, data_); - } - - ~MKLPackedMatrix() { - if (data_) { - cblas_sgemm_free(data_); - } - } -}; - -} // namespace mkl -} // namespace caffe2 - -#endif // CAFFE2_UTILS_MKL_SGEMM_PACK_H_ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe.h deleted file mode 100644 index e97d63b..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifdef __cplusplus - -#include -#include -#include "caffe2/core/predictor.h" -#include "caffe2/mobile/contrib/ios/ios_caffe_defines.h" -#include "caffe2/mobile/contrib/ios/ios_caffe_predictor.h" - -extern "C" { - -IOS_CAFFE_EXPORT Caffe2IOSPredictor* MakeCaffe2Predictor(const std::string& init_net_str, - const std::string& predict_net_str, - bool disableMultithreadProcessing, - bool allowMetalOperators, - std::string& errorMessage); -IOS_CAFFE_EXPORT void GenerateStylizedImage(std::vector& originalImage, - const std::string& init_net_str, - const std::string& predict_net_str, - int height, - int width, - std::vector& dataOut); -} - -#endif diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_defines.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_defines.h deleted file mode 100644 index c31e699..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_defines.h +++ /dev/null @@ -1,3 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#define IOS_CAFFE_EXPORT __attribute__((visibility("default"))) diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_predictor.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_predictor.h deleted file mode 100644 index 05c13a1..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/ios_caffe_predictor.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include -#include "caffe2/core/net.h" -#include "caffe2/core/predictor.h" -#include "caffe2/mobile/contrib/ios/ios_caffe_defines.h" - -struct Tensor { - std::vector dims; - uint8_t* data; -}; - -class IOS_CAFFE_EXPORT Caffe2IOSPredictor final { - public: - /** - @allowMetalOperators Allow converting eligible operators to Metal GPU framework accelerated - operators. Setting this flag to true doesn't gaurantee predictor will be using Metal operators; - Client code must check usingMetalOperators flag to determine predictor is using them. - */ - static Caffe2IOSPredictor* NewCaffe2IOSPredictor(const caffe2::NetDef& init_net, - const caffe2::NetDef& predict_net, - bool disableMultithreadProcessing, - bool allowMetalOperators); - void run(const Tensor& inData, Tensor& outData, std::string& errorMessage); - ~Caffe2IOSPredictor(){}; - - const bool usingMetalOperators; - - private: - Caffe2IOSPredictor(const caffe2::NetDef& init_net, - const caffe2::NetDef& predict_net, - bool disableMultithreadProcessing, - bool usingMetalOperators); - caffe2::Predictor predictor_; -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn.h deleted file mode 100644 index f75e9b4..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "caffe2/core/net.h" - -namespace caffe2 { -static constexpr const char* kMPSCNNReadCountArg = "__mpscnn_read_count__"; -static constexpr const char* kMPSCNNOutputIsTempImageArg = "__mpscnn_output_is_temp_img__"; - -// We currently only try to convert a fixed set of operators that handle a subset of a full -// CNN. We also only run when MPSCNN is available, provides a speedup. -// On failure, returns false. On success, returns true, and sets the MPSCNN net in the output -// parameter. - -bool tryConvertToMPSCNN(const NetDef& initNet, const NetDef& predictNet, NetDef* mpscnnPredictNet); - -// Exposed for testing. -NetDef annotateDefWithReadCounts(const NetDef& net); -NetDef rewriteForMetal(const NetDef& net); -NetDef runMPSCNNFusion(const NetDef& net); -void dumpDef(const NetDef& d); -void mpscnnRecordExecutionFinish(); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.h deleted file mode 100644 index 19b4567..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_context.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#import -#import -#import - -#include -#include -#include -#include -#include - -namespace caffe2 { - -struct MPSCNNContext { - public: - id device; - id commandQueue; - id library; - - id getPipelineState(NSString* kernel); - id getSpecializedPipelineState(NSString* kernel, - const std::vector& constants); - - private: - std::mutex pipelineCacheMutex_; - std::unordered_map> pipelineCache_; -}; - -// get the singleton instance. -MPSCNNContext& getMPSCNNContext(); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_graph_mask.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_graph_mask.h deleted file mode 100644 index 7cba876..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_graph_mask.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "caffe2/core/net.h" -#include "mpscnn.h" - -namespace caffe2 { -// We currently only try to convert a fixed set of operators that handle a subset of a full -// CNN. We also only run when MPSCNN is available, provides a speedup. -// On failure, returns false. On success, returns true, and sets the MPSCNN net in the output -// parameter. -// The rewrite function now supports insertion of copies in intermediate ops. -bool tryConvertToMPSCNNIntermediateCopies(const NetDef& initNet, - const NetDef& predictNet, - NetDef* mpscnnPredictNet); -NetDef setSpecialArgs(const NetDef& def); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_kernels.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_kernels.h deleted file mode 100644 index c5ff599..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_kernels.h +++ /dev/null @@ -1,965 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. -// @generated - -static const char* MPSCNN_KERNELS = R"V0G0N( - -// Copyright 2004-present Facebook. All Rights Reserved. - -#include - -using namespace metal; - -constant ushort ushort_arg_0[[function_constant(0)]]; -constant ushort ushort_arg_1[[function_constant(1)]]; -constant ushort ushort_arg_2[[function_constant(2)]]; -constant ushort ushort_arg_3[[function_constant(3)]]; -constant ushort ushort_arg_4[[function_constant(4)]]; -constant ushort ushort_arg_5[[function_constant(5)]]; -constant ushort ushort_arg_6[[function_constant(6)]]; -constant ushort ushort_arg_7[[function_constant(7)]]; -constant ushort ushort_arg_8[[function_constant(8)]]; -constant ushort ushort_arg_9[[function_constant(9)]]; - -inline constexpr ushort divRoundUp(ushort x, ushort y) { return (x + (y - 1)) / y; } - -kernel void affine(constant half4* scale[[buffer(0)]], - constant half4* shift[[buffer(1)]], - texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - const half4 scale_c = scale[gid.z % divRoundUp(C, 4)]; - const half4 shift_c = shift[gid.z % divRoundUp(C, 4)]; - ushort2 gid_(gid.x, gid.y); - const half4 x = in.read(gid_, gid.z); - const half4 y = scale_c * x + shift_c; - out.write(y, gid_, gid.z); -} - -kernel void affine_nonarray(constant half4* scale[[buffer(0)]], - constant half4* shift[[buffer(1)]], - texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort2 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - const half4 scale_c = scale[0]; - const half4 shift_c = shift[0]; - half4 x = in.read(gid); - const half4 y = scale_c * x + shift_c; - out.write(y, gid); -} - -kernel void prelu_nonshared(constant half4* weights[[buffer(0)]], - texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - const ushort S = ushort_arg_1; - const bool channel_shared = S == 1; - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - half4 w = channel_shared ? half4(weights[0][0], weights[0][0], weights[0][0], weights[0][0]) - : weights[gid.z % divRoundUp(C, 4)]; - ushort2 gid_(gid.x, gid.y); - half4 x = in.read(gid_, gid.z); - half4 y = select(x * w, x, x > 0.0h); - out.write(y, gid_, gid.z); -} - -kernel void prelu_nonshared_nonarray(constant half4* weights[[buffer(0)]], - texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort2 gid[[thread_position_in_grid]]) { - // const ushort C = ushort_arg_0; - const ushort S = ushort_arg_1; - const bool channel_shared = S == 1; - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - half4 w = channel_shared ? half4(weights[0][0], weights[0][0], weights[0][0], weights[0][0]) - : weights[0]; - half4 x = in.read(gid); - half4 y = select(x * w, x, x > 0.0h); - out.write(y, gid); -} - -// One block per texture. -// 256 threads per block. -using AccT = float4; - -constant const bool instance_norm_has_prelu = ushort_arg_1 > 0; - -kernel void instance_norm( - constant half4* weights[[buffer(0)]], - constant half4* bias[[buffer(1)]], - constant half4* preluWeights[[ buffer(2), function_constant(instance_norm_has_prelu) ]], - texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]], - ushort tid[[thread_index_in_threadgroup]], - ushort3 tcount[[threads_per_threadgroup]]) { - if (gid.z >= out.get_array_size()) { - return; - } - const ushort C = ushort_arg_0; - const ushort S = ushort_arg_1; - const bool channel_shared = S == 1; - const ushort c = gid.z % divRoundUp(C, 4); - constexpr ushort THREADGROUP_SIZE = 256; - - threadgroup AccT per_thread_state[THREADGROUP_SIZE]; - // Each block handles a single texture. - per_thread_state[tid] = 0; - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - per_thread_state[tid] += static_cast(in.read(ushort2(x, y), gid.z)); - } - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - // 256 -> 32 reduction - if (tid < 32) { - per_thread_state[tid] += per_thread_state[tid + 32] + per_thread_state[tid + 64] + - per_thread_state[tid + 96] + per_thread_state[tid + 128] + - per_thread_state[tid + 160] + per_thread_state[tid + 192] + - per_thread_state[tid + 224]; - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - if (tid == 0) { - AccT sum = 0.0; - for (ushort i = 0; i < 32; ++i) { - sum += per_thread_state[i]; - } - sum /= (in.get_width() * in.get_height()); - per_thread_state[0] = sum; - } - threadgroup_barrier(mem_flags::mem_threadgroup); - // Broadcast to all threads. - const AccT mean = per_thread_state[0]; - - threadgroup_barrier(mem_flags::mem_threadgroup); - - per_thread_state[tid] = 0; - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - AccT delta = static_cast(in.read(ushort2(x, y), gid.z)) - mean; - per_thread_state[tid] += delta * delta; - } - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - // 256 -> 32 reduction - if (tid < 32) { - per_thread_state[tid] += per_thread_state[tid + 32] + per_thread_state[tid + 64] + - per_thread_state[tid + 96] + per_thread_state[tid + 128] + - per_thread_state[tid + 160] + per_thread_state[tid + 192] + - per_thread_state[tid + 224]; - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - if (tid == 0) { - AccT sum = 0.0; - for (ushort i = 0; i < 32; ++i) { - sum += per_thread_state[i]; - } - sum /= (in.get_width() * in.get_height()); - per_thread_state[0] = 1.0 / sqrt(max(sum, AccT(1e-5, 1e-5, 1e-5, 1e-5)) + 1.0e-5); - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - // Broadcast to all threads. - const AccT inv_var = per_thread_state[0]; - - const AccT c_weights = static_cast(weights[c]); - const AccT c_bias = static_cast(bias[c]); - - const AccT scale = inv_var * c_weights; - const AccT shift = c_bias - mean * scale; - - half4 w; - if (instance_norm_has_prelu) { - w = channel_shared ? half4(preluWeights[0][0]) : preluWeights[c]; - } - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - half4 scaled = - static_cast(static_cast(in.read(ushort2(x, y), gid.z)) * scale + shift); - if (instance_norm_has_prelu) { - scaled = select(scaled * w, scaled, scaled > 0.0h); - } - out.write(scaled, ushort2(x, y), gid.z); - } - } -} - -// One block per texture. -// 256 threads per block. -kernel void instance_norm_nonarray( - constant half4* weights[[buffer(0)]], - constant half4* bias[[buffer(1)]], - constant half4* preluWeights[[ buffer(2), function_constant(instance_norm_has_prelu) ]], - texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]], - ushort tid[[thread_index_in_threadgroup]], - ushort3 tcount[[threads_per_threadgroup]]) { - // const ushort C = ushort_arg_0; - const ushort S = ushort_arg_1; - const bool channel_shared = S == 1; - constexpr ushort THREADGROUP_SIZE = 256; - - threadgroup AccT per_thread_state[THREADGROUP_SIZE]; - // Each block handles a single texture. - per_thread_state[tid] = 0; - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - per_thread_state[tid] += static_cast(in.read(ushort2(x, y))); - } - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - // 256 -> 32 reduction - if (tid < 32) { - per_thread_state[tid] += per_thread_state[tid + 32] + per_thread_state[tid + 64] + - per_thread_state[tid + 96] + per_thread_state[tid + 128] + - per_thread_state[tid + 160] + per_thread_state[tid + 192] + - per_thread_state[tid + 224]; - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - if (tid == 0) { - AccT sum = 0.0; - for (ushort i = 0; i < 32; ++i) { - sum += per_thread_state[i]; - } - sum /= (in.get_width() * in.get_height()); - per_thread_state[0] = sum; - } - threadgroup_barrier(mem_flags::mem_threadgroup); - // Broadcast to all threads. - const AccT mean = per_thread_state[0]; - - threadgroup_barrier(mem_flags::mem_threadgroup); - - per_thread_state[tid] = 0; - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - AccT delta = static_cast(in.read(ushort2(x, y))) - mean; - per_thread_state[tid] += delta * delta; - } - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - // 256 -> 32 reduction - if (tid < 32) { - per_thread_state[tid] += per_thread_state[tid + 32] + per_thread_state[tid + 64] + - per_thread_state[tid + 96] + per_thread_state[tid + 128] + - per_thread_state[tid + 160] + per_thread_state[tid + 192] + - per_thread_state[tid + 224]; - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - - if (tid == 0) { - AccT sum = 0.0; - for (ushort i = 0; i < 32; ++i) { - sum += per_thread_state[i]; - } - sum /= (in.get_width() * in.get_height()); - per_thread_state[0] = 1.0 / sqrt(max(sum, AccT(1e-5, 1e-5, 1e-5, 1e-5)) + 1.0e-5); - } - - threadgroup_barrier(mem_flags::mem_threadgroup); - // Broadcast to all threads. - const AccT inv_var = per_thread_state[0]; - - const AccT c_weights = static_cast(weights[0]); - const AccT c_bias = static_cast(bias[0]); - - const AccT scale = inv_var * c_weights; - const AccT shift = c_bias - mean * scale; - - half4 w; - if (instance_norm_has_prelu) { - w = channel_shared ? half4(preluWeights[0][0]) : preluWeights[0]; - } - for (ushort y = gid.y; y < in.get_height(); y += tcount.y) { - for (ushort x = gid.x; x < in.get_width(); x += tcount.x) { - half4 scaled = static_cast(static_cast(in.read(ushort2(x, y))) * scale + shift); - if (instance_norm_has_prelu) { - scaled = select(scaled * w, scaled, scaled > 0.0h); - } - out.write(scaled, ushort2(x, y)); - } - } -} - -kernel void copy_nchw_to_metal(constant float* in[[buffer(0)]], - texture2d_array out[[texture(0)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - const ushort H = ushort_arg_1; - const ushort W = ushort_arg_2; - if (gid.x >= W || gid.y >= H) { - return; - } - - const ushort n = gid.z / divRoundUp(C, 4); - const ushort c = gid.z - n * divRoundUp(C, 4); - - // TODO: are the `else` branches needed? - // TODO: trick the optimizer for case where C == 4? -#define CHW_TO_CHWP4(idx, n, c_, h, w) \ -if ((c_) < C) { \ -trns[idx] = in[n * H * W * C + int(c_) * H * W + int(h) * W + int(w)]; \ -} else { \ -trns[idx] = 0.0h; \ -} - - half4 trns; - CHW_TO_CHWP4(0, n, c * 4 + 0, gid.y, gid.x); - CHW_TO_CHWP4(1, n, c * 4 + 1, gid.y, gid.x); - CHW_TO_CHWP4(2, n, c * 4 + 2, gid.y, gid.x); - CHW_TO_CHWP4(3, n, c * 4 + 3, gid.y, gid.x); -#undef CHW_TO_CHWP4 - - out.write(trns, ushort2(gid.x, gid.y), gid.z); -} - -kernel void copy_nchw_to_metal_nonarray(constant float* in[[buffer(0)]], - texture2d out[[texture(0)]], - ushort2 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - const ushort H = ushort_arg_1; - const ushort W = ushort_arg_2; - - if (gid.x >= W || gid.y >= H) { - return; - } - - half4 trns; - // TODO: are the `else` branches needed? - // TODO: trick the optimizer for case where C % 4 == 0? - -#define CHW_TO_CHWP4(idx, c, h, w) \ -if ((c) < C) { \ -trns[idx] = in[int(c) * H * W + int(h) * W + int(w)]; \ -} else { \ -trns[idx] = 0.0h; \ -} - - CHW_TO_CHWP4(0, 0, gid.y, gid.x); - CHW_TO_CHWP4(1, 1, gid.y, gid.x); - CHW_TO_CHWP4(2, 2, gid.y, gid.x); - CHW_TO_CHWP4(3, 3, gid.y, gid.x); -#undef CHW_TO_CHWP4 - - out.write(trns, ushort2(gid.x, gid.y)); -} - -kernel void copy_metal_to_nchw(texture2d_array in[[texture(0)]], - device float* out[[buffer(0)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - const ushort H = ushort_arg_1; - const ushort W = ushort_arg_2; - - if (gid.x >= W || gid.y >= H) { - return; - } - const ushort n = gid.z / divRoundUp(C, 4); - const ushort c = gid.z - n * divRoundUp(C, 4); - - half4 cs = in.read(ushort2(gid.x, gid.y), gid.z); - -#define CHWP4_TO_CHW(idx, n, c_, h, w) \ -if ((c_) < C) { \ -out[n * H * W * C + int(c_) * H * W + int(h) * W + int(w)] = cs[idx]; \ -} - - CHWP4_TO_CHW(0, n, c * 4 + 0, gid.y, gid.x); - CHWP4_TO_CHW(1, n, c * 4 + 1, gid.y, gid.x); - CHWP4_TO_CHW(2, n, c * 4 + 2, gid.y, gid.x); - CHWP4_TO_CHW(3, n, c * 4 + 3, gid.y, gid.x); -#undef CHWP4_TO_CHW -} - -kernel void copy_metal_to_nchw_nonarray(texture2d in[[texture(0)]], - device float* out[[buffer(0)]], - ushort2 gid[[thread_position_in_grid]]) { - const ushort C = ushort_arg_0; - const ushort H = ushort_arg_1; - const ushort W = ushort_arg_2; - - if (gid.x >= W || gid.y >= H) { - return; - } - - half4 cs = in.read(ushort2(gid.x, gid.y)); - -#define CHWP4_TO_CHW(idx, c, h, w) \ -if ((c) < C) { \ -out[int(c) * H * W + int(h) * W + int(w)] = cs[idx]; \ -} - - CHWP4_TO_CHW(0, 0, gid.y, gid.x); - CHWP4_TO_CHW(1, 1, gid.y, gid.x); - CHWP4_TO_CHW(2, 2, gid.y, gid.x); - CHWP4_TO_CHW(3, 3, gid.y, gid.x); -#undef CHWP4_TO_CHW -} - -kernel void convtranspose_upscale(texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]]) { - // All resolved at compile time. - // Assume symmetric kernel/stride/pad for now. - const ushort kernel_ = ushort_arg_0; - const ushort stride = ushort_arg_1; - const ushort pad = ushort_arg_2; - - half4 zero(0.0h, 0.0h, 0.0h, 0.0h); - - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - const ushort2 gid_ = ushort2(gid.x, gid.y); - if (gid.x < kernel_ - 1 - pad || gid.y < kernel_ - 1 - pad) { - out.write(zero, gid_, gid.z); - return; - } - - if (((gid.x - (kernel_ - 1 - pad)) % stride == 0) && - ((gid.y - (kernel_ - 1 - pad)) % stride == 0)) { - ushort2 in_pos((gid.x - (kernel_ - 1 - pad)) / stride, (gid.y - (kernel_ - 1 - pad)) / stride); - - if (in_pos.x < in.get_width() && in_pos.y < in.get_height()) { - half4 input = in.read(in_pos, gid.z); - out.write(input, gid_, gid.z); - } else { - out.write(zero, gid_, gid.z); - } - } else { - out.write(zero, gid_, gid.z); - } -} - -constant bool has_in_arr = (ushort_arg_7 > 1 || ushort_arg_0 * ushort_arg_1 * ushort_arg_6 > 4); -constant bool has_out_arr = (ushort_arg_7 > 1 || ushort_arg_6 > 4); -constant bool has_in_tex = (!has_in_arr); -constant bool has_out_tex = (!has_out_arr); - -kernel void col2im( - texture2d_array ina[[ texture(0), function_constant(has_in_arr) ]], - texture2d in[[ texture(0), function_constant(has_in_tex) ]], - texture2d_array outa[[ texture(1), function_constant(has_out_arr) ]], - texture2d out[[ texture(1), function_constant(has_out_tex) ]], - constant half4* bias[[buffer(0)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort kernel_h = ushort_arg_0; - const ushort kernel_w = ushort_arg_1; - const ushort stride_h = ushort_arg_2; - const ushort stride_w = ushort_arg_3; - const ushort pad_l = ushort_arg_4; - const ushort pad_t = ushort_arg_5; - const ushort C = ushort_arg_6; - // const int N = ushort_arg_7; - const ushort height_col = ushort_arg_8; //(outa.get_height() + pad + pad - kernel_) / stride + 1; - const ushort width_col = ushort_arg_9; // (outa.get_width() + pad + pad - kernel_) / stride + 1; - - const ushort n = gid.z / divRoundUp(C, 4); - const ushort c = gid.z - n * divRoundUp(C, 4); - - const ushort w = gid.x + pad_l; - const ushort h = gid.y + pad_t; - - // compute the start and end of the output - const ushort w_col_start = (w < kernel_w) ? 0 : (w - kernel_w) / stride_w + 1; - const ushort w_col_end = min(ushort(w / stride_w + 1), ushort(width_col)); - const ushort h_col_start = (h < kernel_h) ? 0 : (h - kernel_h) / stride_h + 1; - const ushort h_col_end = min(ushort(h / stride_h + 1), ushort(height_col)); - - float4 val = static_cast(bias[c]); - for (ushort h_col = h_col_start; h_col < h_col_end; ++h_col) { - for (ushort w_col = w_col_start; w_col < w_col_end; ++w_col) { - const ushort w_k = w - w_col * stride_w; - const ushort h_k = h - h_col * stride_h; - - // layout is essentially: [N][K][K][C][H][W] - // - where the divRoundUp(K * K * C, 4) channels are interleaved as usual. - // Thus, it's actually [N][divRoundUp(K * K * C, 4)][H][W]. - - // If C % 4 is not zero, then we have to play some games via partial indexing. - // TODO: is it worth optimizing this loop via padding in C? - if (C % 4 == 0) { - ushort c_col = n * kernel_h * kernel_w * divRoundUp(C, 4) + - h_k * kernel_w * divRoundUp(C, 4) + w_k * divRoundUp(C, 4) + c; - if (has_in_arr) { - val += static_cast(ina.read(ushort2(w_col, h_col), c_col)); - } - if (has_in_tex) { - val += static_cast(in.read(ushort2(w_col, h_col), c_col)); - } - } else { - half4 components(0, 0, 0, 0); - for (auto i = 0; i < 4; ++i) { - ushort c_col_i = n * divRoundUp(kernel_h * kernel_w * C, 4) * 4 + h_k * kernel_w * C + - w_k * C + c * 4 + i; - ushort c_col_i_z = c_col_i / 4; - ushort c_col_i_off = c_col_i - c_col_i_z * 4; - if (has_in_arr) { - components[i] = ina.read(ushort2(w_col, h_col), c_col_i_z)[c_col_i_off]; - } - if (has_in_tex) { - components[i] = in.read(ushort2(w_col, h_col))[c_col_i_off]; - } - } - val += static_cast(components); - } - } - } - if (has_out_arr) { - outa.write(static_cast(val), ushort2(gid.x, gid.y), gid.z); - } - if (has_out_tex) { - out.write(static_cast(val), ushort2(gid.x, gid.y)); - } -} - -kernel void preprocess_stylizer(device uchar4* in[[buffer(0)]], - constant half* mean[[buffer(1)]], - constant half4* noise[[buffer(2)]], - texture2d out[[texture(0)]], - ushort2 gid[[thread_position_in_grid]]) { - - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - const ushort noise_size = ushort_arg_0; - - half4 mean_half(mean[0], mean[1], mean[2], 0.0h); - uint input_noise_idx = ((uint)out.get_width() * (uint)gid.y + (uint)gid.x) % (noise_size / 4); - const half4 input_noise = noise[input_noise_idx]; - const uint W = out.get_width(); -#define in_at(h, w) in[(uint)(h)*W + (uint)(w)] - uchar4 input = in_at(gid.y, gid.x); -#undef in_at - half4 input_half = static_cast(input); - out.write(input_half - mean_half + input_noise, gid); -} - -kernel void deprocess_stylizer(texture2d in[[texture(0)]], - device uchar4* out[[buffer(0)]], - constant half* mean[[buffer(1)]], - ushort2 gid[[thread_position_in_grid]]) { - if (gid.x >= in.get_width() || gid.y >= in.get_height()) { - return; - } - - half4 value = in.read(gid); - - half4 mean_h(mean[0], mean[1], mean[2], 0.0h); - half4 min_h(0.0h, 0.0h, 0.0h, 255.0h); - half4 max_h(255.0h, 255.0h, 255.0h, 255.0h); - half4 clamped = clamp(value + mean_h, min_h, max_h); - const uint W = in.get_width(); -#define out_at(h, w, v) out[(uint)(h)*W + (uint)(w)] = (v) - out_at(gid.y, gid.x, static_cast(clamped)); -#undef out_at -} - -kernel void reflection_padding_nonarray(texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort2 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - ushort H = in.get_height(); - ushort PH = out.get_height(); - - // Note: we assume symmetric padding on H/W here, which is verified - // in the calling code. - ushort pad_h = (PH - H) / 2; - ushort W = in.get_width(); - ushort PW = out.get_width(); - ushort pad_w = (PW - W) / 2; - - short h = short(gid.y) - short(pad_h); - h = max(h, short(-h)); - h = min(h, short(2 * H - h - 2)); - - short w = short(gid.x) - short(pad_w); - w = max(w, short(-w)); - w = min(w, short(2 * W - w - 2)); - - ushort2 inid(w, h); - out.write(in.read(inid), gid); -} - -kernel void reflection_padding(texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - ushort H = in.get_height(); - ushort PH = out.get_height(); - - // Note: we assume symmetric padding on H/W here, which is verified - // in the calling code. - ushort pad_h = (PH - H) / 2; - ushort W = in.get_width(); - ushort PW = out.get_width(); - ushort pad_w = (PW - W) / 2; - - short h = short(gid.y) - short(pad_h); - h = max(h, short(-h)); - h = min(h, short(2 * H - h - 2)); - - short w = short(gid.x) - short(pad_w); - w = max(w, short(-w)); - w = min(w, short(2 * W - w - 2)); - - ushort2 inid(w, h); - - out.write(in.read(inid, gid.z), ushort2(gid.x, gid.y), gid.z); -} - -kernel void bilinear_upsample(texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort2 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - ushort2 src = gid / 2; - constexpr sampler sampler(address::clamp_to_edge, filter::linear, coord::pixel); - half4 value = in.sample(sampler, static_cast(src)); - out.write(value, gid); -} - -constant bool in0_is_tex = ushort_arg_0 <= 1 && ushort_arg_1 <= 4; -constant bool in0_is_arr = !in0_is_tex; - -kernel void elementwise_mul(texture2d in0[[texture(0), function_constant(in0_is_tex)]], - texture2d_array ina0[[texture(0), function_constant(in0_is_arr)]], - texture2d out[[texture(2), function_constant(in0_is_tex)]], - texture2d_array outa[[texture(2), function_constant(in0_is_arr)]], - constant float* in1[[buffer(1)]], - ushort3 gid[[thread_position_in_grid]]) { - if (in0_is_tex) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - } else { - if (gid.x >= outa.get_width() || gid.y >= outa.get_height()) { - return; - } - } - ushort2 gid_ = ushort2(gid.x, gid.y); - if (in0_is_tex) { - out.write(in0.read(gid_) * in1[0], gid_); - } else { - outa.write(ina0.read(gid_, gid.z) * in1[0], gid_, gid.z); - } -} - -kernel void elementwise_add_nonarray(texture2d in0[[texture(0)]], - texture2d in1[[texture(1)]], - texture2d out[[texture(2)]], - ushort2 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - out.write(in0.read(gid) + in1.read(gid), gid); -} - -kernel void elementwise_add(texture2d_array in0[[texture(0)]], - texture2d_array in1[[texture(1)]], - texture2d_array out[[texture(2)]], - ushort3 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - ushort2 gid_ = ushort2(gid.x, gid.y); - out.write(in0.read(gid_, gid.z) + in1.read(gid_, gid.z), gid_, gid.z); -} - -constant bool has_in0_arg = (ushort_arg_0 > 0); -constant bool has_in1_arg = (ushort_arg_1 > 0); -constant bool has_in2_arg = (ushort_arg_2 > 0); -constant bool has_in3_arg = (ushort_arg_3 > 0); - -constant bool has_in0_tex = (has_in0_arg && ushort_arg_0 <= 4 && ushort_arg_4 <= 1); -constant bool has_in1_tex = (has_in1_arg && ushort_arg_1 <= 4 && ushort_arg_4 <= 1); -constant bool has_in2_tex = (has_in2_arg && ushort_arg_2 <= 4 && ushort_arg_4 <= 1); -constant bool has_in3_tex = (has_in3_arg && ushort_arg_3 <= 4 && ushort_arg_4 <= 1); - -constant bool has_in0_array = (has_in0_arg && !has_in0_tex); -constant bool has_in1_array = (has_in1_arg && !has_in1_tex); -constant bool has_in2_array = (has_in2_arg && !has_in2_tex); -constant bool has_in3_array = (has_in3_arg && !has_in3_tex); - -inline ushort idx_3(ushort z, ushort C0, ushort C1, ushort C2, ushort C3) { - if (z < C0 / 4) { - return 0; - } - if (z < (C0 + C1) / 4) { - return 1; - } - if (z < (C0 + C1 + C2) / 4) { - return 2; - } - return 3; -} - -inline ushort idx_2(ushort z, ushort C0, ushort C1, ushort C2) { - if (z < C0 / 4) { - return 0; - } - if (z < (C0 + C1) / 4) { - return 1; - } - return 2; -} - -inline ushort idx_1(ushort z, ushort C0, ushort C1) { - if (z < C0 / 4) { - return 0; - } else { - return 1; - } -} - -inline ushort idx_0(ushort z, ushort C0) { return 0; } - -// in a texture_array with size C, find the offset for image N at plane c. -inline constexpr ushort z_off(ushort n, ushort c, ushort C) { return n * divRoundUp(C, 4) + c; } - -kernel void concat( - texture2d in0[[ texture(0), function_constant(has_in0_tex) ]], - texture2d in1[[ texture(1), function_constant(has_in1_tex) ]], - texture2d in2[[ texture(2), function_constant(has_in2_tex) ]], - texture2d in3[[ texture(3), function_constant(has_in3_tex) ]], - texture2d_array ina0[[ texture(0), function_constant(has_in0_array) ]], - texture2d_array ina1[[ texture(1), function_constant(has_in1_array) ]], - texture2d_array ina2[[ texture(2), function_constant(has_in2_array) ]], - texture2d_array ina3[[ texture(3), function_constant(has_in3_array) ]], - texture2d_array out[[texture(5)]], - ushort3 gid[[thread_position_in_grid]]) { - if (gid.x >= out.get_width() || gid.y >= out.get_height()) { - return; - } - - const ushort C0 = ushort_arg_0; - const ushort C1 = ushort_arg_1; - const ushort C2 = ushort_arg_2; - const ushort C3 = ushort_arg_3; - const ushort C = C0 + C1 + C2 + C3; - const ushort n = gid.z / divRoundUp(C, 4); - const ushort c = gid.z - n * divRoundUp(C, 4); - - ushort idx = 0; - if (has_in3_arg) { - idx = idx_3(c, C0, C1, C2, C3); - } else if (has_in2_arg) { - idx = idx_2(c, C0, C1, C2); - } else if (has_in1_arg) { - idx = idx_1(c, C0, C1); - } else if (has_in0_arg) { - idx = idx_0(c, C0); - } else { - // never reached. - idx = 0; - } - - ushort2 gid_ = ushort2(gid.x, gid.y); - half4 value; - switch (idx) { - case 0: { - if (has_in0_tex) { - value = in0.read(gid_); - } - if (has_in0_array) { - value = ina0.read(gid_, z_off(n, c, C0)); - } - break; - } - case 1: { - if (has_in1_tex) { - value = in1.read(gid_); - } - if (has_in1_array) { - value = ina1.read(gid_, z_off(n, c - (C0) / 4, C1)); - } - break; - } - case 2: { - if (has_in2_tex) { - value = in2.read(gid_); - } - if (has_in2_array) { - value = ina2.read(gid_, z_off(n, c - (C0 + C1) / 4, C2)); - } - break; - } - case 3: { - if (has_in3_tex) { - value = in3.read(gid_); - } - if (has_in3_array) { - value = ina3.read(gid_, z_off(n, c - (C0 + C1 + C2) / 4, C3)); - } - break; - } - } - out.write(value, gid_, gid.z); -} - -using RoIT = half; -using RoIT4 = half4; -kernel void roi_warp(texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - constant half4* rois[[buffer(0)]], - ushort3 gid[[thread_position_in_grid]]) { - constexpr sampler s2(coord::pixel, address::clamp_to_edge, filter::linear); - - const half spatial_scale = half(ushort_arg_0) / 10000; - const ushort sampling_ratio = ushort_arg_1; - const ushort C = ushort_arg_2; - const ushort pw = gid.x; - const ushort ph = gid.y; - const ushort n = gid.z / divRoundUp(C, 4); - const ushort c = gid.z % divRoundUp(C, 4); - - const RoIT4 roi_scaled = rois[n] * spatial_scale; - const RoIT roi_start_w = roi_scaled[0]; - const RoIT roi_start_h = roi_scaled[1]; - const RoIT roi_end_w = roi_scaled[2]; - const RoIT roi_end_h = roi_scaled[3]; - - // Force malformed ROIs to be 1x1 - const RoIT roi_width = max(roi_end_w - roi_start_w, (RoIT)1.); - const RoIT roi_height = max(roi_end_h - roi_start_h, (RoIT)1.); - - const RoIT bin_size_h = static_cast(roi_height) / static_cast(out.get_height()); - const RoIT bin_size_w = static_cast(roi_width) / static_cast(out.get_width()); - const ushort roi_bin_grid_h = sampling_ratio; - const ushort roi_bin_grid_w = sampling_ratio; - const ushort iy_upper = sampling_ratio; - const ushort ix_upper = sampling_ratio; - - const RoIT count = iy_upper * ix_upper; - - RoIT4 output_val = 0.0; - for (int iy = 0; iy < iy_upper; iy++) { - for (int ix = 0; ix < ix_upper; ix++) { - const RoIT y = - roi_start_h + ph * bin_size_h + iy * bin_size_h / static_cast(roi_bin_grid_h); - const RoIT x = - roi_start_w + pw * bin_size_w + ix * bin_size_w / static_cast(roi_bin_grid_w); - output_val += in.sample(s2, float2(x + 0.5, y + 0.5), c); - } - } - output_val /= count; - out.write(static_cast(output_val), ushort2(gid.x, gid.y), gid.z); -} - -kernel void resize_nearest(texture2d_array in[[texture(0)]], - texture2d_array out[[texture(1)]], - ushort3 gid[[thread_position_in_grid]]) { - const ushort oH = ushort_arg_0; - const ushort oW = ushort_arg_1; - if (gid.x >= oW || gid.y >= oH) { - return; - } - const float height_scale = float(ushort_arg_2) / 10000; - const float width_scale = float(ushort_arg_3) / 10000; - constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::nearest); - const int in_y = (int)(gid.y / height_scale); - const int in_x = (int)(gid.x / width_scale); - out.write(in.sample(s, float2(in_x, in_y), gid.z), ushort2(gid.x, gid.y), gid.z); -} - -kernel void resize_nearest_nonarray(texture2d in[[texture(0)]], - texture2d out[[texture(1)]], - ushort2 gid[[thread_position_in_grid]]) { - const ushort oH = ushort_arg_0; - const ushort oW = ushort_arg_1; - if (gid.x >= oW || gid.y >= oH) { - return; - } - const float height_scale = float(ushort_arg_2) / 10000; - const float width_scale = float(ushort_arg_3) / 10000; - constexpr sampler s(coord::pixel, address::clamp_to_edge, filter::nearest); - const int in_y = (int)(gid.y / height_scale); - const int in_x = (int)(gid.x / width_scale); - out.write(in.sample(s, float2(in_x, in_y)), ushort2(gid.x, gid.y)); -} - -kernel void nms(device uint* mask[[buffer(0)]], - constant float* proposals[[buffer(1)]], - constant int* indices[[buffer(2)]], - ushort2 tgid[[threadgroup_position_in_grid]], - ushort2 tid[[thread_position_in_threadgroup]]) { - const ushort num_proposals = ushort_arg_0; - const ushort threads_per_group = ushort_arg_1; - float nms_thresh = float(ushort_arg_2) / 10000.0; - const ushort global_offset = ushort_arg_3; - const ushort row_start = tgid.y; - const ushort col_start = tgid.x; - const ushort trd_id = tid.x; - - const short row_size = min(short(32), short(num_proposals - row_start * threads_per_group)); - const short col_size = min(short(32), short(num_proposals - col_start * threads_per_group)); - - // mask the bit if the IoU between two proposals exceeds the threshold - if (trd_id < row_size) { - const ushort cur_idx = global_offset + row_start * threads_per_group + trd_id; - const ushort offset = indices[cur_idx] * 4; - const float4 cur_proposal = float4( - proposals[offset], proposals[offset + 1], proposals[offset + 2], proposals[offset + 3]); - uint cur_mask = 0; - ushort group_start = 0; // start index within group - if (row_start == col_start) { - // if in the same group, start from the next - group_start = trd_id + 1; - } - for (ushort i = group_start; i < col_size; i++) { - float4 a = cur_proposal; - ushort idx = indices[global_offset + col_start * threads_per_group + i] * 4; - float4 b = float4(proposals[idx], proposals[idx + 1], proposals[idx + 2], proposals[idx + 3]); - float left = max(a[0], b[0]); - float right = min(a[2], b[2]); - float top = max(a[1], b[1]); - float bottom = min(a[3], b[3]); - float width = max(right - left + 1.0, 0.0); - float height = max(bottom - top + 1.0, 0.0); - float interS = width * height; - float Sa = (a[2] - a[0] + 1.0) * (a[3] - a[1] + 1.0); - float Sb = (b[2] - b[0] + 1.0) * (b[3] - b[1] + 1.0); - float iou = interS / (Sa + Sb - interS); - if (iou - nms_thresh > 0) { - cur_mask |= 1U << i; - } - } - ushort col_blocks = (num_proposals + threads_per_group - 1) / threads_per_group; - mask[cur_idx * col_blocks + col_start] = cur_mask; - } -} - - -)V0G0N"; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.h b/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.h deleted file mode 100644 index 005a312..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ios/mpscnn/mpscnn_test.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#include "caffe2/core/net.h" -#pragma once - -namespace caffe2 { - -void testMPSCNN(); -void compareModels(const NetDef& initNet, NetDef predictNet); -void verifyRewrite(const NetDef& initNet, const NetDef& net, std::vector inputDims); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl.h deleted file mode 100644 index 91f1dc1..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl.h +++ /dev/null @@ -1,1213 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_H -#define __OPENCL_CL_H - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -typedef cl_bitfield cl_command_queue_properties; -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -typedef cl_bitfield cl_mem_migration_flags; -typedef cl_uint cl_image_info; -typedef cl_uint cl_buffer_create_type; -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -typedef cl_uint cl_program_binary_type; -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -typedef cl_uint cl_kernel_arg_info; -typedef cl_uint cl_kernel_arg_address_qualifier; -typedef cl_uint cl_kernel_arg_access_qualifier; -typedef cl_bitfield cl_kernel_arg_type_qualifier; -typedef cl_uint cl_kernel_work_group_info; -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; - - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; - cl_mem buffer; -} cl_image_desc; - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#define CL_INVALID_PROPERTY -64 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 - -/* OpenCL Version */ -#define CL_VERSION_1_0 1 -#define CL_VERSION_1_1 1 -#define CL_VERSION_1_2 1 - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */ -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#define CL_FP_SOFT_FLOAT (1 << 6) -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#define CL_CONTEXT_NUM_DEVICES 0x1083 - -/* cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 - -/* cl_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -// reserved (1 << 6) -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#define CL_UNORM_INT24 0x10DF - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#define CL_PROGRAM_BINARY_TYPE 0x1184 - -/* cl_program_binary_type */ -#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 -#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 -#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 -#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#define CL_KERNEL_ATTRIBUTES 0x1195 - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -/* cl_kernel_arg_type_qualifer */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#define CL_EVENT_CONTEXT 0x11D4 - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 - -/********************************************************************************************************/ - -/* Platform API */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformIDs(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformInfo(cl_platform_id /* platform */, - cl_platform_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Device APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDs(cl_platform_id /* platform */, - cl_device_type /* device_type */, - cl_uint /* num_entries */, - cl_device_id * /* devices */, - cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceInfo(cl_device_id /* device */, - cl_device_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateSubDevices(cl_device_id /* in_device */, - const cl_device_partition_property * /* properties */, - cl_uint /* num_devices */, - cl_device_id * /* out_devices */, - cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -/* Context APIs */ -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(const cl_context_properties * /* properties */, - cl_uint /* num_devices */, - const cl_device_id * /* devices */, - void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContextFromType(const cl_context_properties * /* properties */, - cl_device_type /* device_type */, - void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetContextInfo(cl_context /* context */, - cl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Command Queue APIs */ -extern CL_API_ENTRY cl_command_queue CL_API_CALL -clCreateCommandQueue(cl_context /* context */, - cl_device_id /* device */, - cl_command_queue_properties /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetCommandQueueInfo(cl_command_queue /* command_queue */, - cl_command_queue_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Memory Object APIs */ -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - size_t /* size */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateSubBuffer(cl_mem /* buffer */, - cl_mem_flags /* flags */, - cl_buffer_create_type /* buffer_create_type */, - const void * /* buffer_create_info */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateImage(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - const cl_image_desc * /* image_desc */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSupportedImageFormats(cl_context /* context */, - cl_mem_flags /* flags */, - cl_mem_object_type /* image_type */, - cl_uint /* num_entries */, - cl_image_format * /* image_formats */, - cl_uint * /* num_image_formats */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetMemObjectInfo(cl_mem /* memobj */, - cl_mem_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetImageInfo(cl_mem /* image */, - cl_image_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetMemObjectDestructorCallback( cl_mem /* memobj */, - void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; - -/* Sampler APIs */ -extern CL_API_ENTRY cl_sampler CL_API_CALL -clCreateSampler(cl_context /* context */, - cl_bool /* normalized_coords */, - cl_addressing_mode /* addressing_mode */, - cl_filter_mode /* filter_mode */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSamplerInfo(cl_sampler /* sampler */, - cl_sampler_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Program Object APIs */ -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithSource(cl_context /* context */, - cl_uint /* count */, - const char ** /* strings */, - const size_t * /* lengths */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBinary(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const size_t * /* lengths */, - const unsigned char ** /* binaries */, - cl_int * /* binary_status */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBuiltInKernels(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* kernel_names */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clBuildProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCompileProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_headers */, - const cl_program * /* input_headers */, - const char ** /* header_include_names */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_program CL_API_CALL -clLinkProgram(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_programs */, - const cl_program * /* input_programs */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */, - cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; - - -extern CL_API_ENTRY cl_int CL_API_CALL -clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramInfo(cl_program /* program */, - cl_program_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramBuildInfo(cl_program /* program */, - cl_device_id /* device */, - cl_program_build_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Kernel Object APIs */ -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCreateKernel(cl_program /* program */, - const char * /* kernel_name */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateKernelsInProgram(cl_program /* program */, - cl_uint /* num_kernels */, - cl_kernel * /* kernels */, - cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArg(cl_kernel /* kernel */, - cl_uint /* arg_index */, - size_t /* arg_size */, - const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelInfo(cl_kernel /* kernel */, - cl_kernel_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelArgInfo(cl_kernel /* kernel */, - cl_uint /* arg_indx */, - cl_kernel_arg_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelWorkGroupInfo(cl_kernel /* kernel */, - cl_device_id /* device */, - cl_kernel_work_group_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Event Object APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clWaitForEvents(cl_uint /* num_events */, - const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventInfo(cl_event /* event */, - cl_event_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateUserEvent(cl_context /* context */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetUserEventStatus(cl_event /* event */, - cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetEventCallback( cl_event /* event */, - cl_int /* command_exec_callback_type */, - void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; - -/* Profiling APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventProfilingInfo(cl_event /* event */, - cl_profiling_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Flush and Finish APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -/* Enqueued Commands APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - size_t /* offset */, - size_t /* size */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - size_t /* offset */, - size_t /* size */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - const void * /* pattern */, - size_t /* pattern_size */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - size_t /* src_offset */, - size_t /* dst_offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin */, - const size_t * /* dst_origin */, - const size_t * /* region */, - size_t /* src_row_pitch */, - size_t /* src_slice_pitch */, - size_t /* dst_row_pitch */, - size_t /* dst_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_read */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* row_pitch */, - size_t /* slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_write */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* input_row_pitch */, - size_t /* input_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - const void * /* fill_color */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImage(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_image */, - const size_t * /* src_origin[3] */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin[3] */, - const size_t * /* region[3] */, - size_t /* dst_offset */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_image */, - size_t /* src_offset */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t * /* image_row_pitch */, - size_t * /* image_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueUnmapMemObject(cl_command_queue /* command_queue */, - cl_mem /* memobj */, - void * /* mapped_ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_objects */, - cl_mem_migration_flags /* flags */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNDRangeKernel(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* work_dim */, - const size_t * /* global_work_offset */, - const size_t * /* global_work_size */, - const size_t * /* local_work_size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueTask(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNativeKernel(cl_command_queue /* command_queue */, - void (CL_CALLBACK * /*user_func*/)(void *), - void * /* args */, - size_t /* cb_args */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_list */, - const void ** /* args_mem_loc */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - - -/* Extension function access - * - * Returns the extension function address for the given function name, - * or NULL if a valid function can not be found. The client must - * check to make sure the address is not NULL, before using or - * calling the returned function address. - */ -extern CL_API_ENTRY void * CL_API_CALL -clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, - const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; - - -// Deprecated OpenCL 1.1 APIs -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage2D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_row_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage3D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_depth */, - size_t /* image_row_pitch */, - size_t /* image_slice_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueMarker(cl_command_queue /* command_queue */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueWaitForEvents(cl_command_queue /* command_queue */, - cl_uint /* num_events */, - const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL -clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_H */ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_ext.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_ext.h deleted file mode 100644 index 632cb21..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_ext.h +++ /dev/null @@ -1,251 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ - -/* cl_ext.h contains OpenCL extensions which don't have external */ -/* (OpenGL, D3D) dependencies. */ - -#ifndef __CL_EXT_H -#define __CL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include - #include -#else - #include -#endif - -/* cl_khr_fp16 extension - no extension #define since it has no functions */ -#define CL_DEVICE_HALF_FP_CONFIG 0x1033 - -/* Memory object destruction - * - * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR - * - * Registers a user callback function that will be called when the memory object is deleted and its resources - * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback - * stack associated with memobj. The registered user callback functions are called in the reverse order in - * which they were registered. The user callback functions are called and then the memory object is deleted - * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be - * notified when the memory referenced by host_ptr, specified when the memory object is created and used as - * the storage bits for the memory object, can be reused or freed. - * - * The application may not call CL api's with the cl_mem object passed to the pfn_notify. - * - * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - */ -#define cl_APPLE_SetMemObjectDestructor 1 -cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, - void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/* Context Logging Functions - * - * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). - * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - * - * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger - */ -#define cl_APPLE_ContextLoggingFunctions 1 -extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ -extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ -extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/************************ -* cl_khr_icd extension * -************************/ -#define cl_khr_icd 1 - -/* cl_platform_info */ -#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 - -/* Additional Error Codes */ -#define CL_PLATFORM_NOT_FOUND_KHR -1001 - -extern CL_API_ENTRY cl_int CL_API_CALL -clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( - cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - - -/* Extension: cl_khr_image2D_buffer - * - * This extension allows a 2D image to be created from a cl_mem buffer without a copy. - * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. - * Both the sampler and sampler-less read_image built-in functions are supported for 2D images - * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported - * for 2D images created from a buffer. - * - * When the 2D image from buffer is created, the client must specify the width, - * height, image format (i.e. channel order and channel data type) and optionally the row pitch - * - * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. - * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. - */ - -/************************************* - * cl_khr_initalize_memory extension * - *************************************/ - -#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x200E - - -/************************************** - * cl_khr_terminate_context extension * - **************************************/ - -#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x200F -#define CL_CONTEXT_TERMINATE_KHR 0x2010 - -#define cl_khr_terminate_context 1 -extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - - -/* - * Extension: cl_khr_spir - * - * This extension adds support to create an OpenCL program object from a - * Standard Portable Intermediate Representation (SPIR) instance - */ - -/****************************************** -* cl_nv_device_attribute_query extension * -******************************************/ -/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ -#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 -#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 -#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 -#define CL_DEVICE_WARP_SIZE_NV 0x4003 -#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 -#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 -#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 - - -/********************************* -* cl_amd_device_attribute_query * -*********************************/ -#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 - -#ifdef CL_VERSION_1_1 - /*********************************** - * cl_ext_device_fission extension * - ***********************************/ - #define cl_ext_device_fission 1 - - extern CL_API_ENTRY cl_int CL_API_CALL - clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - extern CL_API_ENTRY cl_int CL_API_CALL - clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef cl_ulong cl_device_partition_property_ext; - extern CL_API_ENTRY cl_int CL_API_CALL - clCreateSubDevicesEXT( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - /* cl_device_partition_property_ext */ - #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 - #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 - #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 - #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 - - /* clDeviceGetInfo selectors */ - #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 - #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 - #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 - #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 - #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 - - /* error codes */ - #define CL_DEVICE_PARTITION_FAILED_EXT -1057 - #define CL_INVALID_PARTITION_COUNT_EXT -1058 - #define CL_INVALID_PARTITION_NAME_EXT -1059 - - /* CL_AFFINITY_DOMAINs */ - #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 - #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 - #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 - #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 - #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 - #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 - - /* cl_device_partition_property_ext list terminators */ - #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) - - - -#endif /* CL_VERSION_1_1 */ - -#ifdef __cplusplus -} -#endif - - -#endif /* __CL_EXT_H */ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl.h deleted file mode 100644 index af2036c..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl.h +++ /dev/null @@ -1,162 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __OPENCL_CL_GL_H -#define __OPENCL_CL_GL_H - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef cl_uint cl_gl_object_type; -typedef cl_uint cl_gl_texture_info; -typedef cl_uint cl_gl_platform_info; -typedef struct __GLsync *cl_GLsync; - -/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ -#define CL_GL_OBJECT_BUFFER 0x2000 -#define CL_GL_OBJECT_TEXTURE2D 0x2001 -#define CL_GL_OBJECT_TEXTURE3D 0x2002 -#define CL_GL_OBJECT_RENDERBUFFER 0x2003 -#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E -#define CL_GL_OBJECT_TEXTURE1D 0x200F -#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 -#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 - -/* cl_gl_texture_info */ -#define CL_GL_TEXTURE_TARGET 0x2004 -#define CL_GL_MIPMAP_LEVEL 0x2005 -#define CL_GL_NUM_SAMPLES 0x2012 - - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* bufobj */, - int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLTexture(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLRenderbuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* renderbuffer */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLObjectInfo(cl_mem /* memobj */, - cl_gl_object_type * /* gl_object_type */, - cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLTextureInfo(cl_mem /* memobj */, - cl_gl_texture_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - - -// Deprecated OpenCL 1.1 APIs -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture2D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture3D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* cl_khr_gl_sharing extension */ - -#define cl_khr_gl_sharing 1 - -typedef cl_uint cl_gl_context_info; - -/* Additional Error Codes */ -#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 - -/* cl_gl_context_info */ -#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 -#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 - -/* Additional cl_context_properties */ -#define CL_GL_CONTEXT_KHR 0x2008 -#define CL_EGL_DISPLAY_KHR 0x2009 -#define CL_GLX_DISPLAY_KHR 0x200A -#define CL_WGL_HDC_KHR 0x200B -#define CL_CGL_SHAREGROUP_KHR 0x200C - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLContextInfoKHR(const cl_context_properties * /* properties */, - cl_gl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_H */ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl_ext.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl_ext.h deleted file mode 100644 index 77d5353..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_gl_ext.h +++ /dev/null @@ -1,69 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ -/* OpenGL dependencies. */ - -#ifndef __OPENCL_CL_GL_EXT_H -#define __OPENCL_CL_GL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include -#else - #include -#endif - -/* - * For each extension, follow this template - * cl_VEN_extname extension */ -/* #define cl_VEN_extname 1 - * ... define new types, if any - * ... define new tokens, if any - * ... define new APIs, if any - * - * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header - * This allows us to avoid having to decide whether to include GL headers or GLES here. - */ - -/* - * cl_khr_gl_event extension - * See section 9.9 in the OpenCL 1.1 spec for more information - */ -#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromGLsyncKHR(cl_context /* context */, - cl_GLsync /* cl_GLsync */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_platform.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_platform.h deleted file mode 100644 index cf2b721..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/cl_platform.h +++ /dev/null @@ -1,1254 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ - -#ifndef __CL_PLATFORM_H -#define __CL_PLATFORM_H - -#ifdef __APPLE__ - /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ - #include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall -#else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK -#endif - -#ifdef __APPLE__ - #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) - #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 - - #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 - #else - #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #endif -#else - #define CL_EXTENSION_WEAK_LINK - #define CL_API_SUFFIX__VERSION_1_0 - #define CL_EXT_SUFFIX__VERSION_1_0 - #define CL_API_SUFFIX__VERSION_1_1 - #define CL_EXT_SUFFIX__VERSION_1_1 - #define CL_API_SUFFIX__VERSION_1_2 - #define CL_EXT_SUFFIX__VERSION_1_2 - - #ifdef __GNUC__ - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif - #elif _WIN32 - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) - #endif - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif -#endif - -#if (defined (_WIN32) && defined(_MSC_VER)) - -/* scalar types */ -typedef signed __int8 cl_char; -typedef unsigned __int8 cl_uchar; -typedef signed __int16 cl_short; -typedef unsigned __int16 cl_ushort; -typedef signed __int32 cl_int; -typedef unsigned __int32 cl_uint; -typedef signed __int64 cl_long; -typedef unsigned __int64 cl_ulong; - -typedef unsigned __int16 cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#define CL_NAN (CL_INFINITY - CL_INFINITY) -#define CL_HUGE_VALF ((cl_float) 1e50) -#define CL_HUGE_VAL ((cl_double) 1e500) -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#else - -#include - -/* scalar types */ -typedef int8_t cl_char; -typedef uint8_t cl_uchar; -typedef int16_t cl_short __attribute__((aligned(2))); -typedef uint16_t cl_ushort __attribute__((aligned(2))); -typedef int32_t cl_int __attribute__((aligned(4))); -typedef uint32_t cl_uint __attribute__((aligned(4))); -typedef int64_t cl_long __attribute__((aligned(8))); -typedef uint64_t cl_ulong __attribute__((aligned(8))); - -typedef uint16_t cl_half __attribute__((aligned(2))); -typedef float cl_float __attribute__((aligned(4))); -typedef double cl_double __attribute__((aligned(8))); - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 0x1.fffffep127f -#define CL_FLT_MIN 0x1.0p-126f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 0x1.fffffffffffffp1023 -#define CL_DBL_MIN 0x1.0p-1022 -#define CL_DBL_EPSILON 0x1.0p-52 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) -#else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) -#endif -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#endif - -#include - -/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ -typedef unsigned int cl_GLuint; -typedef int cl_GLint; -typedef unsigned int cl_GLenum; - -/* - * Vector types - * - * Note: OpenCL requires that all types be naturally aligned. - * This means that vector types must be naturally aligned. - * For example, a vector of four floats must be aligned to - * a 16 byte boundary (calculated as 4 * the natural 4-byte - * alignment of the float). The alignment qualifiers here - * will only function properly if your compiler supports them - * and if you don't actively work to defeat them. For example, - * in order for a cl_float4 to be 16 byte aligned in a struct, - * the start of the struct must itself be 16-byte aligned. - * - * Maintaining proper alignment is the user's responsibility. - */ - -/* Define basic vector types */ -#if defined( __VEC__ ) - #include /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - typedef vector unsigned char __cl_uchar16; - typedef vector signed char __cl_char16; - typedef vector unsigned short __cl_ushort8; - typedef vector signed short __cl_short8; - typedef vector unsigned int __cl_uint4; - typedef vector signed int __cl_int4; - typedef vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 -#endif - -#if defined( __MMX__ ) - #include - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 -#endif - -#if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include - #else - #include - #endif - #if defined( __GNUC__ ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 -#endif - -/* Define alignment keys */ -#if defined( __GNUC__ ) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) -#elif defined( _WIN32) && (_MSC_VER) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) -#else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) -#endif - -/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 -#endif - -/* Define cl_vector types */ - -/* ---- cl_charn ---- */ -typedef union -{ - cl_char CL_ALIGNED(2) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y; }; - __extension__ struct{ cl_char s0, s1; }; - __extension__ struct{ cl_char lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2; -#endif -}cl_char2; - -typedef union -{ - cl_char CL_ALIGNED(4) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3; }; - __extension__ struct{ cl_char2 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[2]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4; -#endif -}cl_char4; - -/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ -typedef cl_char4 cl_char3; - -typedef union -{ - cl_char CL_ALIGNED(8) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_char4 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[4]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[2]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8; -#endif -}cl_char8; - -typedef union -{ - cl_char CL_ALIGNED(16) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_char8 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[8]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[4]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8[2]; -#endif -#if defined( __CL_CHAR16__ ) - __cl_char16 v16; -#endif -}cl_char16; - - -/* ---- cl_ucharn ---- */ -typedef union -{ - cl_uchar CL_ALIGNED(2) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y; }; - __extension__ struct{ cl_uchar s0, s1; }; - __extension__ struct{ cl_uchar lo, hi; }; -#endif -#if defined( __cl_uchar2__) - __cl_uchar2 v2; -#endif -}cl_uchar2; - -typedef union -{ - cl_uchar CL_ALIGNED(4) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3; }; - __extension__ struct{ cl_uchar2 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[2]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4; -#endif -}cl_uchar4; - -/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ -typedef cl_uchar4 cl_uchar3; - -typedef union -{ - cl_uchar CL_ALIGNED(8) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uchar4 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[4]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[2]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8; -#endif -}cl_uchar8; - -typedef union -{ - cl_uchar CL_ALIGNED(16) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uchar8 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[8]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[4]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8[2]; -#endif -#if defined( __CL_UCHAR16__ ) - __cl_uchar16 v16; -#endif -}cl_uchar16; - - -/* ---- cl_shortn ---- */ -typedef union -{ - cl_short CL_ALIGNED(4) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y; }; - __extension__ struct{ cl_short s0, s1; }; - __extension__ struct{ cl_short lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2; -#endif -}cl_short2; - -typedef union -{ - cl_short CL_ALIGNED(8) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3; }; - __extension__ struct{ cl_short2 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[2]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4; -#endif -}cl_short4; - -/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ -typedef cl_short4 cl_short3; - -typedef union -{ - cl_short CL_ALIGNED(16) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_short4 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[4]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[2]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8; -#endif -}cl_short8; - -typedef union -{ - cl_short CL_ALIGNED(32) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_short8 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[8]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[4]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8[2]; -#endif -#if defined( __CL_SHORT16__ ) - __cl_short16 v16; -#endif -}cl_short16; - - -/* ---- cl_ushortn ---- */ -typedef union -{ - cl_ushort CL_ALIGNED(4) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y; }; - __extension__ struct{ cl_ushort s0, s1; }; - __extension__ struct{ cl_ushort lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2; -#endif -}cl_ushort2; - -typedef union -{ - cl_ushort CL_ALIGNED(8) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3; }; - __extension__ struct{ cl_ushort2 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[2]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4; -#endif -}cl_ushort4; - -/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ -typedef cl_ushort4 cl_ushort3; - -typedef union -{ - cl_ushort CL_ALIGNED(16) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ushort4 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[4]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[2]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8; -#endif -}cl_ushort8; - -typedef union -{ - cl_ushort CL_ALIGNED(32) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ushort8 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[8]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[4]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8[2]; -#endif -#if defined( __CL_USHORT16__ ) - __cl_ushort16 v16; -#endif -}cl_ushort16; - -/* ---- cl_intn ---- */ -typedef union -{ - cl_int CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y; }; - __extension__ struct{ cl_int s0, s1; }; - __extension__ struct{ cl_int lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2; -#endif -}cl_int2; - -typedef union -{ - cl_int CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3; }; - __extension__ struct{ cl_int2 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[2]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4; -#endif -}cl_int4; - -/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ -typedef cl_int4 cl_int3; - -typedef union -{ - cl_int CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_int4 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[4]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[2]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8; -#endif -}cl_int8; - -typedef union -{ - cl_int CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_int8 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[8]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[4]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8[2]; -#endif -#if defined( __CL_INT16__ ) - __cl_int16 v16; -#endif -}cl_int16; - - -/* ---- cl_uintn ---- */ -typedef union -{ - cl_uint CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y; }; - __extension__ struct{ cl_uint s0, s1; }; - __extension__ struct{ cl_uint lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2; -#endif -}cl_uint2; - -typedef union -{ - cl_uint CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3; }; - __extension__ struct{ cl_uint2 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[2]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4; -#endif -}cl_uint4; - -/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ -typedef cl_uint4 cl_uint3; - -typedef union -{ - cl_uint CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uint4 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[4]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[2]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8; -#endif -}cl_uint8; - -typedef union -{ - cl_uint CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uint8 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[8]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[4]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8[2]; -#endif -#if defined( __CL_UINT16__ ) - __cl_uint16 v16; -#endif -}cl_uint16; - -/* ---- cl_longn ---- */ -typedef union -{ - cl_long CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y; }; - __extension__ struct{ cl_long s0, s1; }; - __extension__ struct{ cl_long lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2; -#endif -}cl_long2; - -typedef union -{ - cl_long CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3; }; - __extension__ struct{ cl_long2 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[2]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4; -#endif -}cl_long4; - -/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ -typedef cl_long4 cl_long3; - -typedef union -{ - cl_long CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_long4 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[4]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[2]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8; -#endif -}cl_long8; - -typedef union -{ - cl_long CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_long8 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[8]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[4]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8[2]; -#endif -#if defined( __CL_LONG16__ ) - __cl_long16 v16; -#endif -}cl_long16; - - -/* ---- cl_ulongn ---- */ -typedef union -{ - cl_ulong CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y; }; - __extension__ struct{ cl_ulong s0, s1; }; - __extension__ struct{ cl_ulong lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2; -#endif -}cl_ulong2; - -typedef union -{ - cl_ulong CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3; }; - __extension__ struct{ cl_ulong2 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[2]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4; -#endif -}cl_ulong4; - -/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ -typedef cl_ulong4 cl_ulong3; - -typedef union -{ - cl_ulong CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ulong4 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[4]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[2]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8; -#endif -}cl_ulong8; - -typedef union -{ - cl_ulong CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ulong8 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[8]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[4]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8[2]; -#endif -#if defined( __CL_ULONG16__ ) - __cl_ulong16 v16; -#endif -}cl_ulong16; - - -/* --- cl_floatn ---- */ - -typedef union -{ - cl_float CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y; }; - __extension__ struct{ cl_float s0, s1; }; - __extension__ struct{ cl_float lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2; -#endif -}cl_float2; - -typedef union -{ - cl_float CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3; }; - __extension__ struct{ cl_float2 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[2]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4; -#endif -}cl_float4; - -/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ -typedef cl_float4 cl_float3; - -typedef union -{ - cl_float CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_float4 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[4]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[2]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8; -#endif -}cl_float8; - -typedef union -{ - cl_float CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_float8 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[8]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[4]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8[2]; -#endif -#if defined( __CL_FLOAT16__ ) - __cl_float16 v16; -#endif -}cl_float16; - -/* --- cl_doublen ---- */ - -typedef union -{ - cl_double CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y; }; - __extension__ struct{ cl_double s0, s1; }; - __extension__ struct{ cl_double lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2; -#endif -}cl_double2; - -typedef union -{ - cl_double CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3; }; - __extension__ struct{ cl_double2 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[2]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4; -#endif -}cl_double4; - -/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ -typedef cl_double4 cl_double3; - -typedef union -{ - cl_double CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_double4 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[4]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[2]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8; -#endif -}cl_double8; - -typedef union -{ - cl_double CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_double8 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[8]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[4]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8[2]; -#endif -#if defined( __CL_DOUBLE16__ ) - __cl_double16 v16; -#endif -}cl_double16; - -/* Macro to facilitate debugging - * Usage: - * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. - * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" - * Each line thereafter of OpenCL C source must end with: \n\ - * The last line ends in "; - * - * Example: - * - * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ - * kernel void foo( int a, float * b ) \n\ - * { \n\ - * // my comment \n\ - * *b[ get_global_id(0)] = a; \n\ - * } \n\ - * "; - * - * This should correctly set up the line, (column) and file information for your source - * string so you can do source level debugging. - */ -#define __CL_STRINGIFY( _x ) # _x -#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) -#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" - -#ifdef __cplusplus -} -#endif - -#endif /* __CL_PLATFORM_H */ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/opencl.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/opencl.h deleted file mode 100644 index 3f00524..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/CL/opencl.h +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_H -#define __OPENCL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - -#include -#include -#include -#include - -#else - -#include -#include -#include -#include - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_H */ - diff --git a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/libopencl.h b/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/libopencl.h deleted file mode 100644 index 0c37a6b..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/libopencl-stub/include/libopencl.h +++ /dev/null @@ -1,237 +0,0 @@ -#ifndef LIBOPENCL_STUB_H -#define LIBOPENCL_STUB_H - -#include -#include -#include -#include -#include - - -typedef void (*f_pfn_notify)(const char *, const void *, size_t, void *); - -typedef cl_int (*f_clGetPlatformIDs) (cl_uint, cl_platform_id *, cl_uint *); - -typedef cl_int (*f_clGetPlatformInfo) (cl_platform_id, cl_platform_info, size_t, void *, size_t *); - -typedef cl_int (*f_clGetDeviceIDs) (cl_platform_id, cl_device_type, cl_uint, cl_device_id *, cl_uint *); - -typedef cl_int (*f_clGetDeviceInfo) (cl_device_id, cl_device_info, size_t, void *, size_t *); - -typedef cl_int (*f_clCreateSubDevices) (cl_device_id, const cl_device_partition_property *, - cl_uint, cl_device_id *, cl_uint *); - -typedef cl_int (*f_clRetainDevice) (cl_device_id); - -typedef cl_int (*f_clReleaseDevice) (cl_device_id); - -typedef cl_context (*f_clCreateContext) (const cl_context_properties *, cl_uint, const cl_device_id *, - f_pfn_notify, void *, cl_int *); - -typedef cl_context (*f_clCreateContextFromType) (const cl_context_properties *, cl_device_type, - f_pfn_notify, void *, cl_int *); - -typedef cl_int (*f_clRetainContext) (cl_context); - -typedef cl_int (*f_clReleaseContext) (cl_context); - -typedef cl_int (*f_clGetContextInfo) (cl_context, cl_context_info, size_t, void *, size_t *); - -typedef cl_command_queue (*f_clCreateCommandQueue) (cl_context, cl_device_id, cl_command_queue_properties, cl_int *); - -typedef cl_int (*f_clRetainCommandQueue) (cl_command_queue); - -typedef cl_int (*f_clReleaseCommandQueue) (cl_command_queue); - -typedef cl_int (*f_clGetCommandQueueInfo) (cl_command_queue, cl_command_queue_info, size_t, void *, size_t *); - -typedef cl_mem (*f_clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); - -typedef cl_mem (*f_clCreateSubBuffer) (cl_mem, cl_mem_flags, cl_buffer_create_type, const void *, cl_int *); - -typedef cl_mem (*f_clCreateImage) (cl_context, cl_mem_flags, const cl_image_format *, const cl_image_desc *, void *, cl_int *); - -typedef cl_int (*f_clRetainMemObject) (cl_mem); - -typedef cl_int (*f_clReleaseMemObject) (cl_mem); - -typedef cl_int (*f_clGetMemObjectInfo) (cl_mem, cl_mem_info, size_t, void *, size_t *); - -typedef cl_int (*f_clGetImageInfo) (cl_mem, cl_image_info, size_t, void *, size_t *); - -typedef cl_int (*f_clSetMemObjectDestructorCallback) (cl_mem, void (*pfn_notify)( cl_mem memobj, void* user_data), void *); - -typedef cl_int (*f_clGetSupportedImageFormats) (cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, cl_image_format *, cl_uint *); - -typedef cl_sampler (*f_clCreateSampler) (cl_context, cl_bool, cl_addressing_mode, cl_filter_mode, cl_int *); - -typedef cl_int (*f_clRetainSampler) (cl_sampler); - -typedef cl_int (*f_clReleaseSampler) (cl_sampler); - -typedef cl_int (*f_clGetSamplerInfo) (cl_sampler, cl_sampler_info, size_t, void *, size_t *); - -typedef cl_program (*f_clCreateProgramWithSource) (cl_context, cl_uint, const char **, const size_t *, cl_int *); - -typedef cl_program (*f_clCreateProgramWithBinary) (cl_context, cl_uint, const cl_device_id *, - const size_t *, const unsigned char **, cl_int *, cl_int *); - -typedef cl_program (*f_clCreateProgramWithBuiltInKernels) (cl_context, cl_uint, const cl_device_id *, const char *, cl_int *); - -typedef cl_int (*f_clRetainProgram) (cl_program); - -typedef cl_int (*f_clReleaseProgram) (cl_program); - -typedef cl_int (*f_clBuildProgram) (cl_program, cl_uint, const cl_device_id *, const char *, - void (*pfn_notify)(cl_program program, void * user_data), void *); - -typedef cl_int (*f_clCompileProgram) (cl_program, cl_uint, const cl_device_id *, const char *, cl_uint, const cl_program *, - const char **, void (*pfn_notify)(cl_program program, void * user_data), void *); - -typedef cl_program (*f_clLinkProgram) (cl_context, cl_uint, const cl_device_id *, const char *, cl_uint, const cl_program *, - void (*pfn_notify)(cl_program program, void * user_data), void *, cl_int *); - -typedef cl_int (*f_clUnloadPlatformCompiler)(cl_platform_id); - -typedef cl_int (*f_clGetProgramInfo) (cl_program, cl_program_info, size_t, void *, size_t *); - -typedef cl_int (*f_clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); - -typedef cl_kernel (*f_clCreateKernel) (cl_program, const char *, cl_int *); - -typedef cl_int (*f_clCreateKernelsInProgram) (cl_program, cl_uint, cl_kernel *, cl_uint *); - -typedef cl_int (*f_clRetainKernel) (cl_kernel); - -typedef cl_int (*f_clReleaseKernel) (cl_kernel); - -typedef cl_int (*f_clSetKernelArg) (cl_kernel, cl_uint, size_t,const void *); - -typedef cl_int (*f_clGetKernelInfo) (cl_kernel, cl_kernel_info, size_t, void *, size_t *); - -typedef cl_int (*f_clGetKernelArgInfo) (cl_kernel, cl_uint, cl_kernel_arg_info, size_t, void *, size_t *); - -typedef cl_int (*f_clGetKernelWorkGroupInfo) (cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void *, size_t *); - -typedef cl_int (*f_clWaitForEvents) (cl_uint, const cl_event *); - -typedef cl_int (*f_clGetEventInfo) (cl_event, cl_event_info, size_t, void *, size_t *); - -typedef cl_event (*f_clCreateUserEvent) (cl_context, cl_int *); - -typedef cl_int (*f_clRetainEvent) (cl_event); - -typedef cl_int (*f_clReleaseEvent) (cl_event); - -typedef cl_int (*f_clSetUserEventStatus) (cl_event, cl_int); - -typedef cl_int (*f_clSetEventCallback) (cl_event, cl_int, void (*pfn_notify)(cl_event, cl_int, void *), void *); - -typedef cl_int (*f_clGetEventProfilingInfo) (cl_event, cl_profiling_info, size_t, void *, size_t *); - -typedef cl_int (*f_clFlush) (cl_command_queue); - -typedef cl_int (*f_clFinish) (cl_command_queue); - -typedef cl_int (*f_clEnqueueReadBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueReadBufferRect) (cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, - size_t, size_t, size_t, size_t, void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueWriteBuffer) (cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueWriteBufferRect) (cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, - size_t, size_t, size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueFillBuffer) (cl_command_queue, cl_mem, const void *, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueCopyBuffer) (cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueCopyBufferRect) (cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, const size_t *, - size_t, size_t, size_t, size_t, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueReadImage) (cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, - size_t, size_t, void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueWriteImage) (cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, - size_t, size_t, const void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueFillImage) (cl_command_queue, cl_mem, const void *, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueCopyImage) (cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, const size_t *, - cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueCopyImageToBuffer) (cl_command_queue, cl_mem, cl_mem, const size_t *, const size_t *, size_t, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueCopyBufferToImage) (cl_command_queue, cl_mem, cl_mem, size_t, const size_t *, const size_t *, cl_uint, const cl_event *, cl_event *); - -typedef void * (*f_clEnqueueMapBuffer) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, - size_t, cl_uint, const cl_event *, cl_event *, cl_int *); - -typedef void * (*f_clEnqueueMapImage) (cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t *, const size_t *, - size_t *, size_t *, cl_uint, const cl_event *, cl_event *, cl_int *); - -typedef cl_int (*f_clEnqueueUnmapMemObject) (cl_command_queue, cl_mem, void *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueMigrateMemObjects)(cl_command_queue, cl_uint, const cl_mem *, cl_mem_migration_flags, - cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueNDRangeKernel)(cl_command_queue, cl_kernel, cl_uint, const size_t *, const size_t *, - const size_t *, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueTask)(cl_command_queue, cl_kernel, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueNativeKernel)(cl_command_queue, void (*user_func)(void *), void *, size_t, - cl_uint, const cl_mem *, const void **, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueMarkerWithWaitList)(cl_command_queue, cl_uint, const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueBarrierWithWaitList)(cl_command_queue, cl_uint, const cl_event *, cl_event *); - -typedef void * (*f_clGetExtensionFunctionAddressForPlatform)(cl_platform_id, const char *); - -typedef cl_mem (*f_clCreateImage2D)(cl_context, cl_mem_flags,const cl_image_format *, size_t, size_t, - size_t, void *, cl_int *); - -typedef cl_mem (*f_clCreateImage3D)(cl_context, cl_mem_flags, const cl_image_format *, size_t, - size_t, size_t, size_t, size_t, void *, cl_int *); - -typedef cl_int (*f_clEnqueueMarker)(cl_command_queue, cl_event *); - -typedef cl_int(*f_clEnqueueWaitForEvents)(cl_command_queue, cl_uint, const cl_event *); - -typedef cl_int (*f_clEnqueueBarrier)(cl_command_queue); - -typedef cl_int (*f_clUnloadCompiler)(void); - -typedef void * (*f_clGetExtensionFunctionAddress)(const char *); - -typedef cl_mem (*f_clCreateFromGLBuffer) (cl_context, cl_mem_flags, cl_GLuint, int *); - -typedef cl_mem (*f_clCreateFromGLTexture) (cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int *); - -typedef cl_mem (*f_clCreateFromGLRenderbuffer) (cl_context, cl_mem_flags, cl_GLuint, cl_int *); - -typedef cl_int (*f_clGetGLObjectInfo) (cl_mem memobj, cl_gl_object_type *, cl_GLuint *); - -typedef cl_int (*f_clGetGLTextureInfo) (cl_mem, cl_gl_texture_info, size_t, void *, size_t *); - -typedef cl_int (*f_clEnqueueAcquireGLObjects) (cl_command_queue, cl_uint, const cl_mem *, cl_uint, - const cl_event *, cl_event *); - -typedef cl_int (*f_clEnqueueReleaseGLObjects) (cl_command_queue, cl_uint, const cl_mem *, cl_uint, - const cl_event *, cl_event *); - -typedef cl_mem (*f_clCreateFromGLTexture2D) (cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int *); - -typedef cl_mem (*f_clCreateFromGLTexture3D) (cl_context, cl_mem_flags, cl_GLenum, cl_GLint, cl_GLuint, cl_int *); - -//typedef cl_uint cl_gl_context_info; -typedef cl_int (*f_clGetGLContextInfoKHR) (const cl_context_properties *, cl_gl_context_info, size_t, - void *, size_t *); - -// Additional api to reset currently opened opencl shared-object -// Subsequent calls will use newly set environment variables -void stubOpenclReset(); - -#endif // LIBOPENCL_STUB_H diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/AndroidGLContext.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/AndroidGLContext.h deleted file mode 100644 index 4fd58e1..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/AndroidGLContext.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "../core/GLContext.h" -#include "../core/GLTexture.h" -#include - -enum GL_Renderer { Adreno, Mali /*, PowerVR */ }; - -class AndroidGLContext : public GLContext { - private: - EGLContext _eglcontext; - - EGLContext create_opengl_thread_context(); - bool opengl_thread_context_exists(); - bool release_opengl_thread_context(); - - public: - AndroidGLContext(); - ~AndroidGLContext(); - void set_context(); - void reset_context(); - void flush_context(); - void init_gles3(); - GL_Renderer get_platform(); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/arm_neon_support.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/arm_neon_support.h deleted file mode 100644 index eebb972..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/arm_neon_support.h +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include -typedef __fp16 float16_t; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/gl3stub.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/gl3stub.h deleted file mode 100644 index 25e7925..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/android/gl3stub.h +++ /dev/null @@ -1,489 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef __gl3_h_ -#define __gl3_h_ - -/* - * stub gl3.h for dynamic loading, based on: - * gl3.h last updated on $Date: 2013-02-12 14:37:24 -0800 (Tue, 12 Feb 2013) $ - * - * Changes: - * - Added #include - * - Removed duplicate OpenGL ES 2.0 declarations - * - Converted OpenGL ES 3.0 function prototypes to function pointer - * declarations - * - Added gl3stubInit() declaration - */ - -#include -#include - -// clang-format off -#ifdef __cplusplus -extern "C" { -#endif - -/* Call this function before calling any OpenGL ES 3.0 functions. It will - * return GL_TRUE if the OpenGL ES 3.0 was successfully initialized, GL_FALSE - * otherwise. */ -GLboolean gl3stubInit(); - -/*------------------------------------------------------------------------- - * Data type definitions - *-----------------------------------------------------------------------*/ - -/* OpenGL ES 3.0 */ - -typedef unsigned short GLhalf; -#if __ANDROID_API__ <= 19 -typedef khronos_int64_t GLint64; -typedef khronos_uint64_t GLuint64; -typedef struct __GLsync *GLsync; -#endif - -/*------------------------------------------------------------------------- - * Token definitions - *-----------------------------------------------------------------------*/ - -/* OpenGL ES core versions */ -#define GL_ES_VERSION_3_0 1 - -/* OpenGL ES 3.0 */ - -#define GL_READ_BUFFER 0x0C02 -#define GL_UNPACK_ROW_LENGTH 0x0CF2 -#define GL_UNPACK_SKIP_ROWS 0x0CF3 -#define GL_UNPACK_SKIP_PIXELS 0x0CF4 -#define GL_PACK_ROW_LENGTH 0x0D02 -#define GL_PACK_SKIP_ROWS 0x0D03 -#define GL_PACK_SKIP_PIXELS 0x0D04 -#define GL_COLOR 0x1800 -#define GL_DEPTH 0x1801 -#define GL_STENCIL 0x1802 -#define GL_RED 0x1903 -#define GL_RGB8 0x8051 -#define GL_RGBA8 0x8058 -#define GL_RGB10_A2 0x8059 -#define GL_TEXTURE_BINDING_3D 0x806A -#define GL_UNPACK_SKIP_IMAGES 0x806D -#define GL_UNPACK_IMAGE_HEIGHT 0x806E -#define GL_TEXTURE_3D 0x806F -#define GL_TEXTURE_WRAP_R 0x8072 -#define GL_MAX_3D_TEXTURE_SIZE 0x8073 -#define GL_UNSIGNED_INT_2_10_10_10_REV 0x8368 -#define GL_MAX_ELEMENTS_VERTICES 0x80E8 -#define GL_MAX_ELEMENTS_INDICES 0x80E9 -#define GL_TEXTURE_MIN_LOD 0x813A -#define GL_TEXTURE_MAX_LOD 0x813B -#define GL_TEXTURE_BASE_LEVEL 0x813C -#define GL_TEXTURE_MAX_LEVEL 0x813D -#define GL_MIN 0x8007 -#define GL_MAX 0x8008 -#define GL_DEPTH_COMPONENT24 0x81A6 -#define GL_MAX_TEXTURE_LOD_BIAS 0x84FD -#define GL_TEXTURE_COMPARE_MODE 0x884C -#define GL_TEXTURE_COMPARE_FUNC 0x884D -#define GL_CURRENT_QUERY 0x8865 -#define GL_QUERY_RESULT 0x8866 -#define GL_QUERY_RESULT_AVAILABLE 0x8867 -#define GL_BUFFER_MAPPED 0x88BC -#define GL_BUFFER_MAP_POINTER 0x88BD -#define GL_STREAM_READ 0x88E1 -#define GL_STREAM_COPY 0x88E2 -#define GL_STATIC_READ 0x88E5 -#define GL_STATIC_COPY 0x88E6 -#define GL_DYNAMIC_READ 0x88E9 -#define GL_DYNAMIC_COPY 0x88EA -#define GL_MAX_DRAW_BUFFERS 0x8824 -#define GL_DRAW_BUFFER0 0x8825 -#define GL_DRAW_BUFFER1 0x8826 -#define GL_DRAW_BUFFER2 0x8827 -#define GL_DRAW_BUFFER3 0x8828 -#define GL_DRAW_BUFFER4 0x8829 -#define GL_DRAW_BUFFER5 0x882A -#define GL_DRAW_BUFFER6 0x882B -#define GL_DRAW_BUFFER7 0x882C -#define GL_DRAW_BUFFER8 0x882D -#define GL_DRAW_BUFFER9 0x882E -#define GL_DRAW_BUFFER10 0x882F -#define GL_DRAW_BUFFER11 0x8830 -#define GL_DRAW_BUFFER12 0x8831 -#define GL_DRAW_BUFFER13 0x8832 -#define GL_DRAW_BUFFER14 0x8833 -#define GL_DRAW_BUFFER15 0x8834 -#define GL_MAX_FRAGMENT_UNIFORM_COMPONENTS 0x8B49 -#define GL_MAX_VERTEX_UNIFORM_COMPONENTS 0x8B4A -#define GL_SAMPLER_3D 0x8B5F -#define GL_SAMPLER_2D_SHADOW 0x8B62 -#define GL_FRAGMENT_SHADER_DERIVATIVE_HINT 0x8B8B -#define GL_PIXEL_PACK_BUFFER 0x88EB -#define GL_PIXEL_UNPACK_BUFFER 0x88EC -#define GL_PIXEL_PACK_BUFFER_BINDING 0x88ED -#define GL_PIXEL_UNPACK_BUFFER_BINDING 0x88EF -#define GL_FLOAT_MAT2x3 0x8B65 -#define GL_FLOAT_MAT2x4 0x8B66 -#define GL_FLOAT_MAT3x2 0x8B67 -#define GL_FLOAT_MAT3x4 0x8B68 -#define GL_FLOAT_MAT4x2 0x8B69 -#define GL_FLOAT_MAT4x3 0x8B6A -#define GL_SRGB 0x8C40 -#define GL_SRGB8 0x8C41 -#define GL_SRGB8_ALPHA8 0x8C43 -#define GL_COMPARE_REF_TO_TEXTURE 0x884E -#define GL_MAJOR_VERSION 0x821B -#define GL_MINOR_VERSION 0x821C -#define GL_NUM_EXTENSIONS 0x821D -#define GL_RGBA32F 0x8814 -#define GL_RGB32F 0x8815 -#define GL_RGBA16F 0x881A -#define GL_RGB16F 0x881B -#define GL_VERTEX_ATTRIB_ARRAY_INTEGER 0x88FD -#define GL_MAX_ARRAY_TEXTURE_LAYERS 0x88FF -#define GL_MIN_PROGRAM_TEXEL_OFFSET 0x8904 -#define GL_MAX_PROGRAM_TEXEL_OFFSET 0x8905 -#define GL_MAX_VARYING_COMPONENTS 0x8B4B -#define GL_TEXTURE_2D_ARRAY 0x8C1A -#define GL_TEXTURE_BINDING_2D_ARRAY 0x8C1D -#define GL_R11F_G11F_B10F 0x8C3A -#define GL_UNSIGNED_INT_10F_11F_11F_REV 0x8C3B -#define GL_RGB9_E5 0x8C3D -#define GL_UNSIGNED_INT_5_9_9_9_REV 0x8C3E -#define GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH 0x8C76 -#define GL_TRANSFORM_FEEDBACK_BUFFER_MODE 0x8C7F -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS 0x8C80 -#define GL_TRANSFORM_FEEDBACK_VARYINGS 0x8C83 -#define GL_TRANSFORM_FEEDBACK_BUFFER_START 0x8C84 -#define GL_TRANSFORM_FEEDBACK_BUFFER_SIZE 0x8C85 -#define GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN 0x8C88 -#define GL_RASTERIZER_DISCARD 0x8C89 -#define GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS 0x8C8A -#define GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS 0x8C8B -#define GL_INTERLEAVED_ATTRIBS 0x8C8C -#define GL_SEPARATE_ATTRIBS 0x8C8D -#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E -#define GL_TRANSFORM_FEEDBACK_BUFFER_BINDING 0x8C8F -#define GL_RGBA32UI 0x8D70 -#define GL_RGB32UI 0x8D71 -#define GL_RGBA16UI 0x8D76 -#define GL_RGB16UI 0x8D77 -#define GL_RGBA8UI 0x8D7C -#define GL_RGB8UI 0x8D7D -#define GL_RGBA32I 0x8D82 -#define GL_RGB32I 0x8D83 -#define GL_RGBA16I 0x8D88 -#define GL_RGB16I 0x8D89 -#define GL_RGBA8I 0x8D8E -#define GL_RGB8I 0x8D8F -#define GL_RED_INTEGER 0x8D94 -#define GL_RGB_INTEGER 0x8D98 -#define GL_RGBA_INTEGER 0x8D99 -#define GL_SAMPLER_2D_ARRAY 0x8DC1 -#define GL_SAMPLER_2D_ARRAY_SHADOW 0x8DC4 -#define GL_SAMPLER_CUBE_SHADOW 0x8DC5 -#define GL_UNSIGNED_INT_VEC2 0x8DC6 -#define GL_UNSIGNED_INT_VEC3 0x8DC7 -#define GL_UNSIGNED_INT_VEC4 0x8DC8 -#define GL_INT_SAMPLER_2D 0x8DCA -#define GL_INT_SAMPLER_3D 0x8DCB -#define GL_INT_SAMPLER_CUBE 0x8DCC -#define GL_INT_SAMPLER_2D_ARRAY 0x8DCF -#define GL_UNSIGNED_INT_SAMPLER_2D 0x8DD2 -#define GL_UNSIGNED_INT_SAMPLER_3D 0x8DD3 -#define GL_UNSIGNED_INT_SAMPLER_CUBE 0x8DD4 -#define GL_UNSIGNED_INT_SAMPLER_2D_ARRAY 0x8DD7 -#define GL_BUFFER_ACCESS_FLAGS 0x911F -#define GL_BUFFER_MAP_LENGTH 0x9120 -#define GL_BUFFER_MAP_OFFSET 0x9121 -#define GL_DEPTH_COMPONENT32F 0x8CAC -#define GL_DEPTH32F_STENCIL8 0x8CAD -#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8DAD -#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING 0x8210 -#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE 0x8211 -#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE 0x8212 -#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE 0x8213 -#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE 0x8214 -#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE 0x8215 -#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE 0x8216 -#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE 0x8217 -#define GL_FRAMEBUFFER_DEFAULT 0x8218 -#define GL_FRAMEBUFFER_UNDEFINED 0x8219 -#define GL_DEPTH_STENCIL_ATTACHMENT 0x821A -#define GL_DEPTH_STENCIL 0x84F9 -#define GL_UNSIGNED_INT_24_8 0x84FA -#define GL_DEPTH24_STENCIL8 0x88F0 -#define GL_UNSIGNED_NORMALIZED 0x8C17 -#define GL_DRAW_FRAMEBUFFER_BINDING GL_FRAMEBUFFER_BINDING -#define GL_READ_FRAMEBUFFER 0x8CA8 -#define GL_DRAW_FRAMEBUFFER 0x8CA9 -#define GL_READ_FRAMEBUFFER_BINDING 0x8CAA -#define GL_RENDERBUFFER_SAMPLES 0x8CAB -#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER 0x8CD4 -#define GL_MAX_COLOR_ATTACHMENTS 0x8CDF -#define GL_COLOR_ATTACHMENT1 0x8CE1 -#define GL_COLOR_ATTACHMENT2 0x8CE2 -#define GL_COLOR_ATTACHMENT3 0x8CE3 -#define GL_COLOR_ATTACHMENT4 0x8CE4 -#define GL_COLOR_ATTACHMENT5 0x8CE5 -#define GL_COLOR_ATTACHMENT6 0x8CE6 -#define GL_COLOR_ATTACHMENT7 0x8CE7 -#define GL_COLOR_ATTACHMENT8 0x8CE8 -#define GL_COLOR_ATTACHMENT9 0x8CE9 -#define GL_COLOR_ATTACHMENT10 0x8CEA -#define GL_COLOR_ATTACHMENT11 0x8CEB -#define GL_COLOR_ATTACHMENT12 0x8CEC -#define GL_COLOR_ATTACHMENT13 0x8CED -#define GL_COLOR_ATTACHMENT14 0x8CEE -#define GL_COLOR_ATTACHMENT15 0x8CEF -#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE 0x8D56 -#define GL_MAX_SAMPLES 0x8D57 -#define GL_HALF_FLOAT 0x140B -#define GL_MAP_READ_BIT 0x0001 -#define GL_MAP_WRITE_BIT 0x0002 -#define GL_MAP_INVALIDATE_RANGE_BIT 0x0004 -#define GL_MAP_INVALIDATE_BUFFER_BIT 0x0008 -#define GL_MAP_FLUSH_EXPLICIT_BIT 0x0010 -#define GL_MAP_UNSYNCHRONIZED_BIT 0x0020 -#define GL_RG 0x8227 -#define GL_RG_INTEGER 0x8228 -#define GL_R8 0x8229 -#define GL_RG8 0x822B -#define GL_R16F 0x822D -#define GL_R32F 0x822E -#define GL_RG16F 0x822F -#define GL_RG32F 0x8230 -#define GL_R8I 0x8231 -#define GL_R8UI 0x8232 -#define GL_R16I 0x8233 -#define GL_R16UI 0x8234 -#define GL_R32I 0x8235 -#define GL_R32UI 0x8236 -#define GL_RG8I 0x8237 -#define GL_RG8UI 0x8238 -#define GL_RG16I 0x8239 -#define GL_RG16UI 0x823A -#define GL_RG32I 0x823B -#define GL_RG32UI 0x823C -#define GL_VERTEX_ARRAY_BINDING 0x85B5 -#define GL_R8_SNORM 0x8F94 -#define GL_RG8_SNORM 0x8F95 -#define GL_RGB8_SNORM 0x8F96 -#define GL_RGBA8_SNORM 0x8F97 -#define GL_SIGNED_NORMALIZED 0x8F9C -#define GL_PRIMITIVE_RESTART_FIXED_INDEX 0x8D69 -#define GL_COPY_READ_BUFFER 0x8F36 -#define GL_COPY_WRITE_BUFFER 0x8F37 -#define GL_COPY_READ_BUFFER_BINDING GL_COPY_READ_BUFFER -#define GL_COPY_WRITE_BUFFER_BINDING GL_COPY_WRITE_BUFFER -#define GL_UNIFORM_BUFFER 0x8A11 -#define GL_UNIFORM_BUFFER_BINDING 0x8A28 -#define GL_UNIFORM_BUFFER_START 0x8A29 -#define GL_UNIFORM_BUFFER_SIZE 0x8A2A -#define GL_MAX_VERTEX_UNIFORM_BLOCKS 0x8A2B -#define GL_MAX_FRAGMENT_UNIFORM_BLOCKS 0x8A2D -#define GL_MAX_COMBINED_UNIFORM_BLOCKS 0x8A2E -#define GL_MAX_UNIFORM_BUFFER_BINDINGS 0x8A2F -#define GL_MAX_UNIFORM_BLOCK_SIZE 0x8A30 -#define GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS 0x8A31 -#define GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS 0x8A33 -#define GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT 0x8A34 -#define GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH 0x8A35 -#define GL_ACTIVE_UNIFORM_BLOCKS 0x8A36 -#define GL_UNIFORM_TYPE 0x8A37 -#define GL_UNIFORM_SIZE 0x8A38 -#define GL_UNIFORM_NAME_LENGTH 0x8A39 -#define GL_UNIFORM_BLOCK_INDEX 0x8A3A -#define GL_UNIFORM_OFFSET 0x8A3B -#define GL_UNIFORM_ARRAY_STRIDE 0x8A3C -#define GL_UNIFORM_MATRIX_STRIDE 0x8A3D -#define GL_UNIFORM_IS_ROW_MAJOR 0x8A3E -#define GL_UNIFORM_BLOCK_BINDING 0x8A3F -#define GL_UNIFORM_BLOCK_DATA_SIZE 0x8A40 -#define GL_UNIFORM_BLOCK_NAME_LENGTH 0x8A41 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS 0x8A42 -#define GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES 0x8A43 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER 0x8A44 -#define GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER 0x8A46 -#define GL_INVALID_INDEX 0xFFFFFFFFu -#define GL_MAX_VERTEX_OUTPUT_COMPONENTS 0x9122 -#define GL_MAX_FRAGMENT_INPUT_COMPONENTS 0x9125 -#define GL_MAX_SERVER_WAIT_TIMEOUT 0x9111 -#define GL_OBJECT_TYPE 0x9112 -#define GL_SYNC_CONDITION 0x9113 -#define GL_SYNC_STATUS 0x9114 -#define GL_SYNC_FLAGS 0x9115 -#define GL_SYNC_FENCE 0x9116 -#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 -#define GL_UNSIGNALED 0x9118 -#define GL_SIGNALED 0x9119 -#define GL_ALREADY_SIGNALED 0x911A -#define GL_TIMEOUT_EXPIRED 0x911B -#define GL_CONDITION_SATISFIED 0x911C -#define GL_WAIT_FAILED 0x911D -#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 -#define GL_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull -#define GL_VERTEX_ATTRIB_ARRAY_DIVISOR 0x88FE -#define GL_ANY_SAMPLES_PASSED 0x8C2F -#define GL_ANY_SAMPLES_PASSED_CONSERVATIVE 0x8D6A -#define GL_SAMPLER_BINDING 0x8919 -#define GL_RGB10_A2UI 0x906F -#define GL_TEXTURE_SWIZZLE_R 0x8E42 -#define GL_TEXTURE_SWIZZLE_G 0x8E43 -#define GL_TEXTURE_SWIZZLE_B 0x8E44 -#define GL_TEXTURE_SWIZZLE_A 0x8E45 -#define GL_GREEN 0x1904 -#define GL_BLUE 0x1905 -#define GL_INT_2_10_10_10_REV 0x8D9F -#define GL_TRANSFORM_FEEDBACK 0x8E22 -#define GL_TRANSFORM_FEEDBACK_PAUSED 0x8E23 -#define GL_TRANSFORM_FEEDBACK_ACTIVE 0x8E24 -#define GL_TRANSFORM_FEEDBACK_BINDING 0x8E25 -#define GL_PROGRAM_BINARY_RETRIEVABLE_HINT 0x8257 -#define GL_PROGRAM_BINARY_LENGTH 0x8741 -#define GL_NUM_PROGRAM_BINARY_FORMATS 0x87FE -#define GL_PROGRAM_BINARY_FORMATS 0x87FF -#define GL_COMPRESSED_R11_EAC 0x9270 -#define GL_COMPRESSED_SIGNED_R11_EAC 0x9271 -#define GL_COMPRESSED_RG11_EAC 0x9272 -#define GL_COMPRESSED_SIGNED_RG11_EAC 0x9273 -#define GL_COMPRESSED_RGB8_ETC2 0x9274 -#define GL_COMPRESSED_SRGB8_ETC2 0x9275 -#define GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9276 -#define GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 0x9277 -#define GL_COMPRESSED_RGBA8_ETC2_EAC 0x9278 -#define GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC 0x9279 -#define GL_TEXTURE_IMMUTABLE_FORMAT 0x912F -#define GL_MAX_ELEMENT_INDEX 0x8D6B -#define GL_NUM_SAMPLE_COUNTS 0x9380 -#define GL_TEXTURE_IMMUTABLE_LEVELS 0x82DF - -/*------------------------------------------------------------------------- - * Entrypoint definitions - *-----------------------------------------------------------------------*/ - -/* OpenGL ES 3.0 */ - -extern GL_APICALL void (* GL_APIENTRY glReadBuffer) (GLenum mode); -extern GL_APICALL void (* GL_APIENTRY glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid* indices); -extern GL_APICALL void (* GL_APIENTRY glTexImage3D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLenum format, GLenum type, const GLvoid* pixels); -extern GL_APICALL void (* GL_APIENTRY glTexSubImage3D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid* pixels); -extern GL_APICALL void (* GL_APIENTRY glCopyTexSubImage3D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height); -extern GL_APICALL void (* GL_APIENTRY glCompressedTexImage3D) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth, GLint border, GLsizei imageSize, const GLvoid* data); -extern GL_APICALL void (* GL_APIENTRY glCompressedTexSubImage3D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLsizei imageSize, const GLvoid* data); -extern GL_APICALL void (* GL_APIENTRY glGenQueries) (GLsizei n, GLuint* ids); -extern GL_APICALL void (* GL_APIENTRY glDeleteQueries) (GLsizei n, const GLuint* ids); -extern GL_APICALL GLboolean (* GL_APIENTRY glIsQuery) (GLuint id); -extern GL_APICALL void (* GL_APIENTRY glBeginQuery) (GLenum target, GLuint id); -extern GL_APICALL void (* GL_APIENTRY glEndQuery) (GLenum target); -extern GL_APICALL void (* GL_APIENTRY glGetQueryiv) (GLenum target, GLenum pname, GLint* params); -extern GL_APICALL void (* GL_APIENTRY glGetQueryObjectuiv) (GLuint id, GLenum pname, GLuint* params); -extern GL_APICALL GLboolean (* GL_APIENTRY glUnmapBuffer) (GLenum target); -extern GL_APICALL void (* GL_APIENTRY glGetBufferPointerv) (GLenum target, GLenum pname, GLvoid** params); -extern GL_APICALL void (* GL_APIENTRY glDrawBuffers) (GLsizei n, const GLenum* bufs); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix2x3fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix3x2fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix2x4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix4x2fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix3x4fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glUniformMatrix4x3fv) (GLint location, GLsizei count, GLboolean transpose, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glBlitFramebuffer) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter); -extern GL_APICALL void (* GL_APIENTRY glRenderbufferStorageMultisample) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); -extern GL_APICALL void (* GL_APIENTRY glFramebufferTextureLayer) (GLenum target, GLenum attachment, GLuint texture, GLint level, GLint layer); -extern GL_APICALL GLvoid* (* GL_APIENTRY glMapBufferRange) (GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access); -extern GL_APICALL void (* GL_APIENTRY glFlushMappedBufferRange) (GLenum target, GLintptr offset, GLsizeiptr length); -extern GL_APICALL void (* GL_APIENTRY glBindVertexArray) (GLuint array); -extern GL_APICALL void (* GL_APIENTRY glDeleteVertexArrays) (GLsizei n, const GLuint* arrays); -extern GL_APICALL void (* GL_APIENTRY glGenVertexArrays) (GLsizei n, GLuint* arrays); -extern GL_APICALL GLboolean (* GL_APIENTRY glIsVertexArray) (GLuint array); -extern GL_APICALL void (* GL_APIENTRY glGetIntegeri_v) (GLenum target, GLuint index, GLint* data); -extern GL_APICALL void (* GL_APIENTRY glBeginTransformFeedback) (GLenum primitiveMode); -extern GL_APICALL void (* GL_APIENTRY glEndTransformFeedback) (void); -extern GL_APICALL void (* GL_APIENTRY glBindBufferRange) (GLenum target, GLuint index, GLuint buffer, GLintptr offset, GLsizeiptr size); -extern GL_APICALL void (* GL_APIENTRY glBindBufferBase) (GLenum target, GLuint index, GLuint buffer); -extern GL_APICALL void (* GL_APIENTRY glTransformFeedbackVaryings) (GLuint program, GLsizei count, const GLchar* const* varyings, GLenum bufferMode); -extern GL_APICALL void (* GL_APIENTRY glGetTransformFeedbackVarying) (GLuint program, GLuint index, GLsizei bufSize, GLsizei* length, GLsizei* size, GLenum* type, GLchar* name); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribIPointer) (GLuint index, GLint size, GLenum type, GLsizei stride, const GLvoid* pointer); -extern GL_APICALL void (* GL_APIENTRY glGetVertexAttribIiv) (GLuint index, GLenum pname, GLint* params); -extern GL_APICALL void (* GL_APIENTRY glGetVertexAttribIuiv) (GLuint index, GLenum pname, GLuint* params); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribI4i) (GLuint index, GLint x, GLint y, GLint z, GLint w); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribI4ui) (GLuint index, GLuint x, GLuint y, GLuint z, GLuint w); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribI4iv) (GLuint index, const GLint* v); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribI4uiv) (GLuint index, const GLuint* v); -extern GL_APICALL void (* GL_APIENTRY glGetUniformuiv) (GLuint program, GLint location, GLuint* params); -extern GL_APICALL GLint (* GL_APIENTRY glGetFragDataLocation) (GLuint program, const GLchar *name); -extern GL_APICALL void (* GL_APIENTRY glUniform1ui) (GLint location, GLuint v0); -extern GL_APICALL void (* GL_APIENTRY glUniform2ui) (GLint location, GLuint v0, GLuint v1); -extern GL_APICALL void (* GL_APIENTRY glUniform3ui) (GLint location, GLuint v0, GLuint v1, GLuint v2); -extern GL_APICALL void (* GL_APIENTRY glUniform4ui) (GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); -extern GL_APICALL void (* GL_APIENTRY glUniform1uiv) (GLint location, GLsizei count, const GLuint* value); -extern GL_APICALL void (* GL_APIENTRY glUniform2uiv) (GLint location, GLsizei count, const GLuint* value); -extern GL_APICALL void (* GL_APIENTRY glUniform3uiv) (GLint location, GLsizei count, const GLuint* value); -extern GL_APICALL void (* GL_APIENTRY glUniform4uiv) (GLint location, GLsizei count, const GLuint* value); -extern GL_APICALL void (* GL_APIENTRY glClearBufferiv) (GLenum buffer, GLint drawbuffer, const GLint* value); -extern GL_APICALL void (* GL_APIENTRY glClearBufferuiv) (GLenum buffer, GLint drawbuffer, const GLuint* value); -extern GL_APICALL void (* GL_APIENTRY glClearBufferfv) (GLenum buffer, GLint drawbuffer, const GLfloat* value); -extern GL_APICALL void (* GL_APIENTRY glClearBufferfi) (GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil); -extern GL_APICALL const GLubyte* (* GL_APIENTRY glGetStringi) (GLenum name, GLuint index); -extern GL_APICALL void (* GL_APIENTRY glCopyBufferSubData) (GLenum readTarget, GLenum writeTarget, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size); -extern GL_APICALL void (* GL_APIENTRY glGetUniformIndices) (GLuint program, GLsizei uniformCount, const GLchar* const* uniformNames, GLuint* uniformIndices); -extern GL_APICALL void (* GL_APIENTRY glGetActiveUniformsiv) (GLuint program, GLsizei uniformCount, const GLuint* uniformIndices, GLenum pname, GLint* params); -extern GL_APICALL GLuint (* GL_APIENTRY glGetUniformBlockIndex) (GLuint program, const GLchar* uniformBlockName); -extern GL_APICALL void (* GL_APIENTRY glGetActiveUniformBlockiv) (GLuint program, GLuint uniformBlockIndex, GLenum pname, GLint* params); -extern GL_APICALL void (* GL_APIENTRY glGetActiveUniformBlockName) (GLuint program, GLuint uniformBlockIndex, GLsizei bufSize, GLsizei* length, GLchar* uniformBlockName); -extern GL_APICALL void (* GL_APIENTRY glUniformBlockBinding) (GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding); -extern GL_APICALL void (* GL_APIENTRY glDrawArraysInstanced) (GLenum mode, GLint first, GLsizei count, GLsizei instanceCount); -extern GL_APICALL void (* GL_APIENTRY glDrawElementsInstanced) (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices, GLsizei instanceCount); -extern GL_APICALL GLsync (* GL_APIENTRY glFenceSync) (GLenum condition, GLbitfield flags); -extern GL_APICALL GLboolean (* GL_APIENTRY glIsSync) (GLsync sync); -extern GL_APICALL void (* GL_APIENTRY glDeleteSync) (GLsync sync); -extern GL_APICALL GLenum (* GL_APIENTRY glClientWaitSync) (GLsync sync, GLbitfield flags, GLuint64 timeout); -extern GL_APICALL void (* GL_APIENTRY glWaitSync) (GLsync sync, GLbitfield flags, GLuint64 timeout); -extern GL_APICALL void (* GL_APIENTRY glGetInteger64v) (GLenum pname, GLint64* params); -extern GL_APICALL void (* GL_APIENTRY glGetSynciv) (GLsync sync, GLenum pname, GLsizei bufSize, GLsizei* length, GLint* values); -extern GL_APICALL void (* GL_APIENTRY glGetInteger64i_v) (GLenum target, GLuint index, GLint64* data); -extern GL_APICALL void (* GL_APIENTRY glGetBufferParameteri64v) (GLenum target, GLenum pname, GLint64* params); -extern GL_APICALL void (* GL_APIENTRY glGenSamplers) (GLsizei count, GLuint* samplers); -extern GL_APICALL void (* GL_APIENTRY glDeleteSamplers) (GLsizei count, const GLuint* samplers); -extern GL_APICALL GLboolean (* GL_APIENTRY glIsSampler) (GLuint sampler); -extern GL_APICALL void (* GL_APIENTRY glBindSampler) (GLuint unit, GLuint sampler); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameteri) (GLuint sampler, GLenum pname, GLint param); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameteriv) (GLuint sampler, GLenum pname, const GLint* param); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameterf) (GLuint sampler, GLenum pname, GLfloat param); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameterfv) (GLuint sampler, GLenum pname, const GLfloat* param); -extern GL_APICALL void (* GL_APIENTRY glGetSamplerParameteriv) (GLuint sampler, GLenum pname, GLint* params); -extern GL_APICALL void (* GL_APIENTRY glGetSamplerParameterfv) (GLuint sampler, GLenum pname, GLfloat* params); -extern GL_APICALL void (* GL_APIENTRY glVertexAttribDivisor) (GLuint index, GLuint divisor); -extern GL_APICALL void (* GL_APIENTRY glBindTransformFeedback) (GLenum target, GLuint id); -extern GL_APICALL void (* GL_APIENTRY glDeleteTransformFeedbacks) (GLsizei n, const GLuint* ids); -extern GL_APICALL void (* GL_APIENTRY glGenTransformFeedbacks) (GLsizei n, GLuint* ids); -extern GL_APICALL GLboolean (* GL_APIENTRY glIsTransformFeedback) (GLuint id); -extern GL_APICALL void (* GL_APIENTRY glPauseTransformFeedback) (void); -extern GL_APICALL void (* GL_APIENTRY glResumeTransformFeedback) (void); -extern GL_APICALL void (* GL_APIENTRY glGetProgramBinary) (GLuint program, GLsizei bufSize, GLsizei* length, GLenum* binaryFormat, GLvoid* binary); -extern GL_APICALL void (* GL_APIENTRY glProgramBinary) (GLuint program, GLenum binaryFormat, const GLvoid* binary, GLsizei length); -extern GL_APICALL void (* GL_APIENTRY glProgramParameteri) (GLuint program, GLenum pname, GLint value); -extern GL_APICALL void (* GL_APIENTRY glInvalidateFramebuffer) (GLenum target, GLsizei numAttachments, const GLenum* attachments); -extern GL_APICALL void (* GL_APIENTRY glInvalidateSubFramebuffer) (GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height); -extern GL_APICALL void (* GL_APIENTRY glTexStorage2D) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height); -extern GL_APICALL void (* GL_APIENTRY glTexStorage3D) (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth); -extern GL_APICALL void (* GL_APIENTRY glGetInternalformativ) (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params); - -#ifndef GL_EXT_texture_border_clamp -#define GL_EXT_texture_border_clamp 1 -#define GL_TEXTURE_BORDER_COLOR_EXT 0x1004 -#define GL_CLAMP_TO_BORDER_EXT 0x812D -extern GL_APICALL void (* GL_APIENTRY glTexParameterIivEXT) (GLenum target, GLenum pname, const GLint *params); -extern GL_APICALL void (* GL_APIENTRY glTexParameterIuivEXT) (GLenum target, GLenum pname, const GLuint *params); -extern GL_APICALL void (* GL_APIENTRY glGetTexParameterIivEXT) (GLenum target, GLenum pname, GLint *params); -extern GL_APICALL void (* GL_APIENTRY glGetTexParameterIuivEXT) (GLenum target, GLenum pname, GLuint *params); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameterIivEXT) (GLuint sampler, GLenum pname, const GLint *param); -extern GL_APICALL void (* GL_APIENTRY glSamplerParameterIuivEXT) (GLuint sampler, GLenum pname, const GLuint *param); -extern GL_APICALL void (* GL_APIENTRY glGetSamplerParameterIivEXT) (GLuint sampler, GLenum pname, GLint *params); -extern GL_APICALL void (* GL_APIENTRY glGetSamplerParameterIuivEXT) (GLuint sampler, GLenum pname, GLuint *params); -#endif /* GL_EXT_texture_border_clamp */ - -#ifdef __cplusplus -} -#endif -// clang-format on - -#endif diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/DataTransfer.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/DataTransfer.h deleted file mode 100644 index 6579512..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/DataTransfer.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "arm_neon_support.h" - -void interleaveSlice(void* output, - const float* input, - size_t width, - size_t height, - size_t row_stride, - uint16_t input_channels); -void deInterleaveSlice(float* output, - const void* input, - size_t width, - size_t height, - size_t input_stride, - uint32_t output_channels); diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GL.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GL.h deleted file mode 100644 index eaf5f87..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GL.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "caffe2/core/common.h" - -#if CAFFE2_IOS -#include -#include -#elif CAFFE2_ANDROID -#include -#include -#include "caffe2/mobile/contrib/opengl/android/gl3stub.h" -#endif diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLContext.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLContext.h deleted file mode 100644 index 053a92d..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLContext.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "GLTexture.h" -#include "caffe2/core/common.h" -#include - -class GLContext { - private: - static std::unique_ptr _glcontext; - std::function foreignTextureAllocator = - nullptr; - - protected: - bool half_float_supported = true; - - public: - virtual void set_context() = 0; - virtual void reset_context() = 0; - virtual void flush_context() = 0; - virtual ~GLContext(){}; - - static void initGLContext(); - static GLContext* getGLContext(); - static void deleteGLContext(); - - static bool GL_EXT_texture_border_clamp_defined(); - - inline bool halfFloatTextureSupported() { return half_float_supported; } - - void setTextureAllocator( - std::function textureAllocator) { - foreignTextureAllocator = textureAllocator; - } - - std::function getTextureAllocator() { - return foreignTextureAllocator; - } -}; - -bool supportOpenGLES3(bool* hfs = nullptr); - -bool isSupportedDevice(); - -#if CAFFE2_IOS -int iPhoneVersion(); -#endif diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLFilter.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLFilter.h deleted file mode 100644 index cdc3c69..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLFilter.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLContext.h" -#include "GLTexture.h" -#include "arm_neon_support.h" - -#include -#include -#include - -#define BINDING(variableName) (variableName = new binding{#variableName}) -#define ATTRIBUTE(variableName, value) (variableName = new binding{#variableName, value}) - -class GLFilter { - protected: - const std::string kernel_name; - GLuint program = 0; - GLuint frameBuffer = 0; - static constexpr int kMaxUniformBlocks = 12; - struct uniformBlockInfo { - GLuint buffer; - GLint size; - bool initialized; - }; - std::vector> uniformBlock; - bool frame_buffer_initialized = false; - - // glGetError() can be expensive, we should turn error checking off when we're done with debugging - - static constexpr bool check_opengl_errors = false; - - public: - typedef std::vector> replacements_t; - - struct binding { - const std::string name; - GLint location; - }; - - struct texture_attachment { - const GLTexture* texture; - const binding* uniform; - }; - - GLFilter(const std::string kernel_name, - const std::string vertex_shader, - const std::string fragment_shader, - const std::vector uniforms, - const std::vector uniform_blocks = {}, - const std::vector attributes = {}, - const replacements_t& replacements = {}); - - // TODO: The set and reset context need to be commented out for unit testing - ~GLFilter() { - releaseBuffers(); - deleteProgram(); - deleteBindings(); - } - - void throwRuntimeError(std::function error_formatter) const { - std::stringstream errmsg; - errmsg << kernel_name << ": "; - error_formatter(errmsg); - throw std::runtime_error(errmsg.str()); - } - - void checkGLError(std::function error_formatter) const { - if (check_opengl_errors) { - GLenum glError = glGetError(); - if (glError != GL_NO_ERROR) { - throwRuntimeError([&](std::stringstream& errmsg) { - error_formatter(errmsg); - errmsg << ", " << glError; - }); - } - } - } - - template - void attach_uniform_buffer(const binding* block, - GLuint bindingPoint, - std::function loader, - int batch = -1); - - void run(const std::vector& input, - const std::vector& output, - std::function uniforms_initializer, - int width, - int height); - - void releaseBuffers(); - void deleteProgram(); - void deleteBindings(); - - static const char* vertex_shader; - - private: - const std::vector uniforms_; - const std::vector uniform_blocks_; - const std::vector attributes_; - - std::string process_replacements(std::string source, const replacements_t& replacements) const; - - bool createProgram(const GLchar* vertSource, const GLchar* fragSource, GLuint* program) const; - - GLint compileShader(GLenum target, GLsizei count, const GLchar** sources, GLuint* shader) const; - GLint linkProgram(GLuint program) const; - GLint validateProgram(GLuint program) const; -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImage.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImage.h deleted file mode 100644 index 9ba63cd..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImage.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLTexture.h" -#include "caffe2/core/logging.h" - -#include -#include - -template -class GLImage { - public: - const int width; - const int height; - const int channels; - const int data_size; - - const int tile_x; - const int tile_y; - const int texture_width; - const int texture_height; - const int slices; - - const std::vector textures; - - constexpr static int slice_channels = 4; - - static constexpr int channels_to_slices(int channels, int tile_x, int tile_y) { - return ((channels + slice_channels - 1) / slice_channels + tile_x * tile_y - 1) / - (tile_x * tile_y); - } - - static const std::vector allocate_textures( - int slices, std::function texture_loader) { - std::vector textures; - for (int i = 0; i < slices; i++) { - textures.push_back(texture_loader(i)); - } - return textures; - } - - GLImage(int _width, - int _height, - int _channels, - int _tile_x, - int _tile_y, - std::function texture_loader) - : width(_width), - height(_height), - channels(_channels), - data_size(sizeof(T)), - tile_x(_tile_x), - tile_y(_tile_y), - texture_width(_width * _tile_x), - texture_height(_height * _tile_y), - slices(channels_to_slices(_channels, _tile_x, _tile_y)), - textures(allocate_textures(slices, texture_loader)) { - CAFFE_ENFORCE_EQ(slices * tile_x * tile_y, (channels + 3) / 4); - } - - GLImage(int _width, - int _height, - int _channels, - int _tile_x, - int _tile_y, - bool _destroy, - std::function texture_loader) - : width(_width), - height(_height), - channels(_channels), - data_size(sizeof(T)), - tile_x(_tile_x), - tile_y(_tile_y), - texture_width(_width * _tile_x), - texture_height(_height * _tile_y), - slices(channels_to_slices(_channels, _tile_x, _tile_y)), - textures(allocate_textures(slices, texture_loader)) { - CAFFE_ENFORCE_EQ(slices * tile_x * tile_y, (channels + 3) / 4); - } - - GLImage() - : width(0), - height(0), - channels(0), - data_size(sizeof(T)), - tile_x(0), - tile_y(0), - texture_width(0), - texture_height(0), - slices(0){}; - - virtual ~GLImage() { - gl_log(GL_VERBOSE, "deleting GLImage\n"); - for (auto&& texture : textures) { - delete texture; - } - } -}; - -template -class GLImageVector { - private: - std::vector*> images_; - int num_images_ = 0; - int width_ = 0; - int height_ = 0; - int channels_ = 0; - int tile_x_ = 0; - int tile_y_ = 0; - - public: - GLImage* operator[](int index) const { - CAFFE_ENFORCE_LT(index, num_images_, "Out of bounds when accessing GLImageVector"); - return images_[index]; - } - - void push_back(GLImage* image) { - CAFFE_ENFORCE_EQ(image->channels, channels_); - CAFFE_ENFORCE_EQ(image->width, width_); - CAFFE_ENFORCE_EQ(image->height, height_); - CAFFE_ENFORCE_EQ(image->tile_x, tile_x_); - CAFFE_ENFORCE_EQ(image->tile_y, tile_y_); - images_.push_back(image); - CAFFE_ENFORCE_LE(images_.size(), num_images_); - } - - int size() const { return images_.size(); } - int channels() const { return channels_; } - int width() const { return width_; } - int height() const { return height_; } - int tile_x() const { return tile_x_; } - int tile_y() const { return tile_y_; } - int slices() const { return size() > 0 ? images_[0]->slices : 0; } - - GLImageVector(int num_images, int width, int height, int channels, int tile_x = 1, int tile_y = 1) - : num_images_(num_images), - width_(width), - height_(height), - channels_(channels), - tile_x_(tile_x), - tile_y_(tile_y) {} - - GLImageVector() {} - - ~GLImageVector() { - for (int i = 0; i < images_.size(); i++) { - delete images_[i]; - } - } -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImageAllocator.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImageAllocator.h deleted file mode 100644 index 3dd6e98..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLImageAllocator.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLImage.h" -#include "GLPlainTexture.h" - -template -class GLImageAllocator { - public: - static const GLTexture::Type& type; - - GLImageAllocator() { gl_log(GL_VERBOSE, "%s\n", __PRETTY_FUNCTION__); } - - virtual ~GLImageAllocator() { gl_log(GL_VERBOSE, "%s\n", __PRETTY_FUNCTION__); } - - virtual GLImageVector* newImage( - int num_images, int width, int height, int channels, int tile_x, int tile_y, bool is_output); - - virtual GLImageVector* newImage( - int num_images, - int width, - int height, - int channels, - int tile_x, - int tile_y, - std::function textureAllocator); - - virtual GLImageVector* ShareTexture(const GLuint textureID, - int num_images, - int width, - int height, - int channels, - int tile_x = 1, - int tile_y = 1); - - static GLImageAllocator* newGLImageAllocator(); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLLogging.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLLogging.h deleted file mode 100644 index 9f5b5a1..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLLogging.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include -#include - -enum { GL_ERR = -1, GL_LOG = 0, GL_VERBOSE = 1 }; - -static constexpr int GL_LOG_LEVEL = GL_LOG; - -static inline int gl_log(int level, const char* format, ...) { - int r = 0; - if (level <= GL_LOG_LEVEL) { - va_list args; - va_start(args, format); - r = vfprintf(stderr, format, args); - va_end(args); - } - return r; -} diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPBO.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPBO.h deleted file mode 100644 index 6a94dc0..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPBO.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLTexture.h" -#include - -class GLPBO { - GLuint pboId = 0; - GLuint pboSize = 0; - GLuint pboFrameBuffer = 0; - - ~GLPBO(); - - static GLPBO* pboContext; - - public: - void mapTextureData(GLuint _textureId, - GLsizei _width, - GLsizei _height, - GLsizei _stride, - GLsizei _channels, - const GLTexture::Type& type, - std::function process); - - static GLPBO* getContext(); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPlainTexture.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPlainTexture.h deleted file mode 100644 index a0d3f48..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPlainTexture.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLContext.h" -#include "GLTexture.h" - -class GLPlainTexture : public GLTexture { - private: - bool isOwner = true; - - public: - GLPlainTexture(const Type& type, - const void* input, - GLsizei width, - GLsizei height, - bool use_padding = false, - GLint filter = GL_NEAREST, - GLint wrap = GL_CLAMP_TO_EDGE); - - GLPlainTexture(const Type& type, - const GLuint textureID, - GLsizei width, - GLsizei height, - bool use_padding = false, - GLint filter = GL_NEAREST, - GLint wrap = GL_CLAMP_TO_EDGE); - - ~GLPlainTexture() { - if (glIsTexture(_textureId)) { - if (isOwner) { - gl_log(GL_VERBOSE, "~GLPlainTexture() - deleting texture %d\n", _textureId); - glDeleteTextures(1, &_textureId); - } - } else { - gl_log(GL_ERR, "not deleting texture %d\n", _textureId); - } - } - - GLuint name() const { return _textureId; }; - - GLenum target() const { return GL_TEXTURE_2D; }; - - bool flipped() const { return false; }; -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPredictor.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPredictor.h deleted file mode 100644 index c6c7342..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLPredictor.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLImage.h" -#include "caffe2/core/net.h" -#include "caffe2/core/predictor.h" - -namespace caffe2 { -class GLPredictor : public Predictor { - public: - GLPredictor(const NetDef& init_net, - const NetDef& run_net, - bool use_texture_input = false, - Workspace* parent = nullptr); - - template - bool run(std::vector*>& inputs, std::vector*>* outputs); - - ~GLPredictor(); -}; -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLTexture.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLTexture.h deleted file mode 100644 index ca6e304..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/GLTexture.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "GL.h" -#include "GLLogging.h" - -class GLTexture { - public: - struct Type { - const GLenum internalFormat; - const GLenum format; - const GLenum type; - - int dataSize() const { - switch (type) { - case GL_UNSIGNED_INT: - return 4; - case GL_HALF_FLOAT: - return 2; - case GL_UNSIGNED_BYTE: - return 1; - default: - throw std::runtime_error("Unknown Texture Type"); - } - } - - int channels() const { - switch (format) { - case GL_R8: - return 1; - case GL_RG8: - return 2; - // case GL_BGRA: - case GL_RG_INTEGER: - case GL_RGBA: - return 4; - default: - throw std::runtime_error("Unknown Texture Format"); - } - } - }; - - static const Type FP16; - static const Type FP16_COMPAT; - static const Type UI8; - - protected: - const Type& _type; - - const GLsizei _width; - const GLsizei _height; - const GLsizei _stride; - const GLsizei _channels; - const bool _use_padding; - - GLint _filter; - GLint _wrap; - GLuint _textureId; - - public: - GLTexture(const Type& type, - int width, - int height, - int stride, - bool use_padding, - GLint filter, - GLint wrap) - : _type(type), - _width(width), - _height(height), - _stride(stride), - _channels(type.channels()), - _use_padding(use_padding), - _filter(filter), - _wrap(wrap) {} - - GLTexture(const Type& type, int width, int height, bool use_padding, GLint filter, GLint wrap) - : GLTexture(type, - width, - height, - use_padding ? (width + 7) / 8 * 8 : width, - use_padding, - filter, - wrap) {} - - virtual ~GLTexture() {} - virtual GLuint name() const = 0; - virtual GLenum target() const = 0; - virtual bool flipped() const = 0; - - virtual void map_read(std::function process) const; - - virtual void map_load(std::function process) const; - - void loadData(const void* pixels) const; -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/ImageAllocator.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/ImageAllocator.h deleted file mode 100644 index 19375e4..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/ImageAllocator.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "GLImageAllocator.h" - -namespace caffe2 { - -template -class ImageAllocator { - GLImageAllocator* glImageAllocator; - - public: - ImageAllocator() : glImageAllocator(GLImageAllocator::newGLImageAllocator()) {} - - virtual ~ImageAllocator() { delete glImageAllocator; } - - GLImageVector* newImage( - int num_images, int width, int height, int channels, bool is_output = false) { - const int tile_x = 1, tile_y = 1; - return glImageAllocator->newImage( - num_images, width, height, channels, tile_x, tile_y, is_output); - } - - GLImageVector* newImage(int num_images, - int width, - int height, - int channels, - int tile_x, - int tile_y, - bool is_output = false) { - return glImageAllocator->newImage( - num_images, width, height, channels, tile_x, tile_y, is_output); - } - - GLImageVector* newImage( - int num_images, - int width, - int height, - int channels, - int tile_x, - int tile_y, - std::function textureAllocator) { - return glImageAllocator->newImage( - num_images, width, height, channels, tile_x, tile_y, textureAllocator); - } -}; -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/arm_neon_support.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/arm_neon_support.h deleted file mode 100644 index 681662c..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/arm_neon_support.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/common.h" - -#ifdef __ARM_NEON__ -#if CAFFE2_IOS -#include "arm_neon.h" -#elif CAFFE2_ANDROID -#include "caffe2/mobile/contrib/opengl/android/arm_neon_support.h" -#endif -#endif diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/rewrite_net.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/rewrite_net.h deleted file mode 100644 index 36e1436..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/core/rewrite_net.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once -#include "GLPredictor.h" -#include "caffe2/core/predictor.h" - -namespace caffe2 { -bool tryConvertToOpenGL(const NetDef& initNet, - const NetDef& predictNet, - NetDef* glPredictNet, - bool useTextureInput = false, - bool useTiling = false, - bool runFusion = true); - -// Exposed for testing -NetDef rewritePredictNetForOpenGL(const NetDef& predictNet, - bool useTextureInput = false, - bool useTiling = false, - bool runFusion = true); -void dumpDefForOpenGL(const NetDef& net); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLContext.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLContext.h deleted file mode 100644 index 80928ef..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLContext.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "../core/GLContext.h" -#include "../core/GLTexture.h" - -#import - -class IOSGLContext : public GLContext { - void* oglContext; - void* oldContext; - CVOpenGLESTextureCacheRef textureCache; - - public: - IOSGLContext(); - ~IOSGLContext(); - - const GLTexture* createNewTexture(CVPixelBufferRef pixelBuffer, const GLTexture::Type& type); - void set_context(); - void reset_context(); - void flush_context(); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLImageAllocator.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLImageAllocator.h deleted file mode 100644 index 58cca42..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLImageAllocator.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "../core/GLImageAllocator.h" - -#import - -template -class IOSGLImageAllocator : public GLImageAllocator { - static const GLTexture::Type& type; - - std::vector pixelbuffers; - - public: - static const FourCharCode pixelFormat; - - IOSGLImageAllocator() : GLImageAllocator() { gl_log(GL_VERBOSE, "%s\n", __PRETTY_FUNCTION__); } - - ~IOSGLImageAllocator() { - gl_log(GL_VERBOSE, "%s\n", __PRETTY_FUNCTION__); - - for (auto&& pixelbuffer : pixelbuffers) { - CFRelease(pixelbuffer); - } - } - - GLImageVector* newImage(int num_images, - int width, - int height, - int channels, - int tile_x, - int tile_y, - bool useCVPixelBuffer); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLTexture.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLTexture.h deleted file mode 100644 index f1f6559..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/ios/IOSGLTexture.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "../core/GLContext.h" -#include "../core/GLTexture.h" - -#import - -class IOSGLTexture : public GLTexture { - CVOpenGLESTextureRef textureRef; - - IOSGLTexture(const Type& type, - CVOpenGLESTextureCacheRef textureCache, - CVPixelBufferRef sourceImage, - GLint _filter = GL_NEAREST, - GLint _wrap = GL_CLAMP_TO_EDGE); - - friend class IOSGLContext; - - public: - const CVPixelBufferRef sourceImage; - - ~IOSGLTexture() { CFRelease(textureRef); } - - void map_buffer(std::function process) const; - - virtual void map_read(std::function process) const; - - virtual void map_load(std::function process) const; - - GLuint name() const { return CVOpenGLESTextureGetName(textureRef); } - GLenum target() const { return CVOpenGLESTextureGetTarget(textureRef); }; - bool flipped() const { return CVOpenGLESTextureIsFlipped(textureRef); }; - - static CVPixelBufferRef createCVPixelBuffer(OSType pixelType, int32_t width, int32_t height); -}; diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/operators/gl_tiling_utils.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/operators/gl_tiling_utils.h deleted file mode 100644 index 6100af6..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/operators/gl_tiling_utils.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -// pragma once -#include - -namespace { -struct point { - int x; - int y; -}; - -struct tile_descriptor { - point tile_dims; - point tile_size; - int tiles; -}; -} // namespace - -namespace caffe2 { -inline static void squareFactors(int N, int& r1, int& r2) { - int f = sqrt(N); - - if (f * f == N) { - r1 = r2 = f; - } else { - while (N % f != 0) { - f--; - } - r1 = N / f; - r2 = f; - } -} - -inline static void computeOutputTiles(int output_channels, int& output_tile_x, int& output_tile_y) { - squareFactors((output_channels + 3) / 4, output_tile_x, output_tile_y); -} -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/TestGLConvolution.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/TestGLConvolution.h deleted file mode 100644 index ce54f34..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/TestGLConvolution.h +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -void TestGLConvolution(); diff --git a/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/opengl_test.h b/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/opengl_test.h deleted file mode 100644 index ee7bfde..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/opengl/test/opengl_test.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { -void testOpenGL(); -void compareModelsForOpenGL(std::string name, - const NetDef& initNet, - NetDef predictNet, - int width, - int height, - int channel, - std::string input_type, - std::string input_order); - -void compareBatchedToTiledModels(std::string name, - const NetDef& initNet, - NetDef predictNet, - int width, - int height, - int channel, - std::string input_type, - std::string input_order); - -int runModelBenchmarks(caffe2::NetDef& init_net, - caffe2::NetDef& predict_net, - int warm_up_runs, - int main_runs, - int channel, - int height, - int width, - std::string input_type, - std::string input_order, - std::string engine, - bool run_individual = false, - bool use_texture_input = false, - bool use_tiling = false, - bool run_fusion = true); - -typedef enum { - AveragePool, - MaxPool, - Conv, - ConvTranspose, - ConvPRelu, - ConvTransposePRelu, - ConvRelu, - ConvTransposeRelu -} PoolOp; - -void testOpenGLConv(int N, - int C, - int H, - int W, - int K, // output_channels - int kernel_h, - int kernel_w, - int pad, - int stride, - PoolOp poolOp, - float error, - bool random_input = true, - int input_batch_size = 1, - int output_batch_size = 1, - int input_tile_x = 1, - int input_tile_y = 1, - bool tiling = false); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/snpe/snpe_ffi.h b/app/src/main/cpp/caffe2/mobile/contrib/snpe/snpe_ffi.h deleted file mode 100644 index 54c713d..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/snpe/snpe_ffi.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CAFFE2_SNPE_FFI_H_ -#define CAFFE2_SNPE_FFI_H_ - -#include -#include - -namespace caffe2 { - -std::string& gSNPELocation(); - -const char* const snpe_ffi_so = "libsnpe_ffi.so"; - -} - -extern "C" { - -bool snpe_has_gpu(); - -void* snpe_create(const uint8_t* container, size_t size, const char* input_name); - -void snpe_destroy(void* ctx); - -void snpe_get_input_dims(void* ctx, size_t const** dims, size_t* size); - -void snpe_run(void* ctx, - const float* inputData, - size_t inputSize, - size_t const** outputDims, - size_t* outputSize); - -void snpe_copy_output_to(void* ctx, float* outputData); - -} - -#endif // CAFFE2_SNPE_FFI_H_ diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp.h b/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp.h deleted file mode 100644 index bddbf85..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -constexpr size_t k2b1bXBits = 2; - -struct ConvArgs { - int stride_w{1}; - int stride_h{1}; - int pad_l{0}; - int pad_t{0}; - int pad_b{0}; - int pad_r{0}; -}; - -using ParallelFor = std::function)>; - -struct QConvState { - std::vector> XQs; - std::vector> YQs; - std::unique_ptr WQ; - // architecture-dependent whether packing is used. - std::unique_ptr WQPacked; - std::unique_ptr WQN; - std::unique_ptr WQL1Norm; - // Useful for e.g. incomplete tiles - std::unique_ptr scratch; - std::unique_ptr scratchColBuffer; - - std::unique_ptr bias; - - ParallelFor parallelFor{nullptr}; -}; - -void uniformQuantize2b1b(const TensorCPU& X, - const std::vector>& XQ, - float offset, - float inter_center_distance); - -void qpad_zero(const ConvArgs& args, const TensorCPU& X, TensorCPU* Y); - -inline size_t divRoundUp(size_t x, size_t d) { return (x + d - 1) / d; } - -void signQuantize(const TensorCPU& X, TensorCPU* XQ); -void filterNormalization11(const TensorCPU& WQ, TensorCPU* WQN); -void filterNormalizationL1(const TensorCPU& W, TensorCPU* WL1); -std::unique_ptr create2b1bConvState(Workspace* ws, - const TensorCPU& W, - const TensorCPU* b); -void run2b1bConvGeneric(QConvState* state, const ConvArgs& args, const TensorCPU& X, TensorCPU* Y); -void qconv( - const ConvArgs& args, const TensorCPU& X, const TensorCPU& W, const TensorCPU* b, TensorCPU* Y); -void qim2col(const ConvArgs& args, const TensorCPU& XQ, const TensorCPU& WQ, TensorCPU* XQcol); - -void run2b1bUnification(QConvState* state, - size_t N, - size_t C, - const float* WQNVdata, - const float* YQs0Vdata, - const float* YQs1Vdata, - size_t YQstride, - float* Ydata, - size_t Ystride, - const float* bias); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp_neon.h b/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp_neon.h deleted file mode 100644 index 6ec1bd1..0000000 --- a/app/src/main/cpp/caffe2/mobile/contrib/ulp2/ulp_neon.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "ulp.h" - -namespace caffe2 { - -constexpr size_t kGEMMTileSize = 64; -constexpr size_t kGEMMTileDepthBytes = 16; - -bool run2b1bConvNeon(QConvState* state, const ConvArgs& args, const TensorCPU& X, TensorCPU* Y); -} diff --git a/app/src/main/cpp/caffe2/mpi/mpi_common.h b/app/src/main/cpp/caffe2/mpi/mpi_common.h deleted file mode 100644 index 3e1e7a5..0000000 --- a/app/src/main/cpp/caffe2/mpi/mpi_common.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef CAFFE2_MPI_MPI_COMMON_H_ -#define CAFFE2_MPI_MPI_COMMON_H_ - -#include -#include - -#include "caffe2/core/logging.h" - -namespace caffe2 { - -inline void CheckInitializedMPI() { - int flag; - MPI_Initialized(&flag); - CAFFE_ENFORCE(flag, "MPI does not seem to have been initialized."); -} - -template class MPIDataTypeWrapper; - -#define MPI_DATATYPE_WRAPPER(c_type, mpi_type) \ - template<> class MPIDataTypeWrapper { \ - public: \ - inline static MPI_Datatype type() { return mpi_type; } \ - }; - -MPI_DATATYPE_WRAPPER(char, MPI_CHAR) -MPI_DATATYPE_WRAPPER(float, MPI_FLOAT) -MPI_DATATYPE_WRAPPER(double, MPI_DOUBLE) -// Note(Yangqing): as necessary, add more specializations. -#undef MPI_DATATYPE_WRAPPER - -// For all Caffe MPI calls, we will wrap it inside an MPI mutex lock guard. -std::mutex& MPIMutex(); - -#define MPI_CHECK(condition) \ - do { \ - std::lock_guard guard(::caffe2::MPIMutex()); \ - int error = (condition); \ - CAFFE_ENFORCE( \ - error == MPI_SUCCESS, \ - "Caffe2 MPI Error at: ", \ - __FILE__, \ - ":", \ - __LINE__, \ - ": ", \ - error); \ - } while (0) - -/** - * @brief Gets the global MPI communicator used by Caffe2. In default, this - * is MPI_COMM_WORLD unless you call SetGlobalMPIComm(). - */ -MPI_Comm GlobalMPIComm(); - -/** - * @brief Sets the global MPI communicator. Caffe2 takes over the ownership - * of the passed in communicator. - */ -void SetGlobalMPIComm(MPI_Comm new_comm); - -/** - * @brief A helper function to return the size of the given communicator. - */ -int MPICommSize(MPI_Comm comm); - -/** - * @brief A helper function to return the rank of the given communicator. - */ -int MPICommRank(MPI_Comm comm); - -/** - * @brief A simple wrapper over an MPI common world. - */ -class MPICommonWorldWrapper { - public: - /** - * @brief Creates a common world wrapper. - * - * The new common world is created by taking the existing communicator - * passed in as src_comm, and splitting it using the color and the rank - * specified. In default, we will split from Caffe2's global communicator, - * and use color 0 as well as rank implicitly given by src_comm. As a result, - * the default constructor basically creates a comm identical to the source - * comm world. - */ - explicit MPICommonWorldWrapper( - MPI_Comm src_comm = MPI_COMM_NULL, - int color = 0, - int rank = -1) { - if (src_comm == MPI_COMM_NULL) { - src_comm = GlobalMPIComm(); - } - if (rank == -1) { - MPI_CHECK(MPI_Comm_rank(src_comm, &rank)); - } - MPI_CHECK(MPI_Comm_split(src_comm, color, rank, &comm_)); - MPI_CHECK(MPI_Comm_size(comm_, &size_)); - MPI_CHECK(MPI_Comm_rank(comm_, &rank_)); - } - - ~MPICommonWorldWrapper() { - int ret; - MPI_CHECK(MPI_Finalized(&ret)); - if (!ret) { - MPI_Comm_free(&comm_); - } - } - - /** - * @brief Returns the common world held by the wrapper. - */ - inline MPI_Comm comm() const { - return comm_; - } - /** - * @brief Returns the size of the world. - */ - inline int size() const { - return size_; - } - /** - * @brief Returns the rank of this process in the world. - */ - inline int rank() const { - return rank_; - } - - private: - MPI_Comm comm_; - int size_; - int rank_; -}; - -/** - * A function used to perform peer setup so one does not need to use - * mpirun / mpiexec to run the binary. Note that if you use mpirun or mpiexec - * to set up the common world, do not use this function - MPI_Init would have - * already set that up. - * - * This also assumes that you have a common path (like NFS) that multiple - * instances can read from. - * - * Inputs: - * replicas (int): the number of replicas that mpi will run with. - * role (string): the role of this process, "server" or "client". - * job_path (string): a file name that the server will write its port into - * and the clients will read the server's port from. - */ -void MPISetupPeers( - const int replicas, - const string& role, - const string& job_path); -} // namespace caffe2 - -#endif // CAFFE2_MPI_MPI_COMMON_H_ diff --git a/app/src/main/cpp/caffe2/mpi/mpi_ops.h b/app/src/main/cpp/caffe2/mpi/mpi_ops.h deleted file mode 100644 index 108bf45..0000000 --- a/app/src/main/cpp/caffe2/mpi/mpi_ops.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef CAFFE2_MPI_MPI_OPS_H_ -#define CAFFE2_MPI_MPI_OPS_H_ - -#include - -#include "caffe2/core/operator.h" -#include "caffe2/mpi/mpi_common.h" - -namespace caffe2 { - -// TODO(jiayq): if needed, write up the use of color and key with MPI split. -// Currently, the operator simply creates a communicator that has the -// same topology as the Caffe2 global communicator. -template -class MPICreateCommonWorldOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MPICreateCommonWorldOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - OperatorBase::Outputs()[0]->Reset(new MPICommonWorldWrapper()); - return true; - } -}; - -template -class MPIBroadcastOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MPIBroadcastOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - root_(OperatorBase::template GetSingleArgument("root", 0)) {} - ~MPIBroadcastOp() {} - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(0).comm(); - CAFFE_ENFORCE( - OperatorBase::OutputIsType>(0), - "Output is of wrong type."); - auto* output = Output(0); - // Make sure that output is already allocated. - CAFFE_ENFORCE( - output->size() > 0, - "Broadcast op uses in-place operation so the output " - "should be already allocated."); - MPI_CHECK(MPI_Bcast( - output->raw_mutable_data(), - output->nbytes(), - MPIDataTypeWrapper::type(), - root_, - comm)); - return true; - } - - protected: - int root_; -}; - -// MPIReduceOp does Reduce using MPI. Currently, only SUM is supported. -template -class MPIReduceOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MPIReduceOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - root_(OperatorBase::template GetSingleArgument("root", 0)) {} - ~MPIReduceOp() {} - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(0).comm(); - auto& input = Input(1); - auto* output = Output(0); - output->ResizeLike(input); - MPI_CHECK(MPI_Reduce( - const_cast(input.template data()), - output->template mutable_data(), - input.size(), - MPIDataTypeWrapper::type(), - MPI_SUM, - root_, - comm)); - return true; - } - - protected: - int root_; -}; - -// MPIAllgatherOp does MPIAllgather using MPI. -template -class MPIAllgatherOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(MPIAllgatherOp); - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(0).comm(); - auto& input = Input(1); - auto* output = Output(0); - vector output_dims = input.dims(); - output_dims[0] *= OperatorBase::Input(0).size(); - output->Resize(output_dims); - MPI_CHECK(MPI_Allgather( - const_cast(input.template data()), - input.size(), - MPIDataTypeWrapper::type(), - output->template mutable_data(), - input.size(), - MPIDataTypeWrapper::type(), - comm)); - return true; - } -}; - -// MPIAllreduceOp does MPIAllreduce using MPI. Currently, only SUM is supported. -template -class MPIAllreduceOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(MPIAllreduceOp); - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(0).comm(); - auto& input = Input(1); - auto* output = Output(0); - output->ResizeLike(input); - void* source; - if (output->template mutable_data() == input.template data()) { - // We are doing in-place call. Special case handling. - source = MPI_IN_PLACE; - } else { - // Normal allreduce takes the source from the input. - source = const_cast(input.template data()); - } - MPI_CHECK(MPI_Allreduce( - source, - output->template mutable_data(), - input.size(), - MPIDataTypeWrapper::type(), - MPI_SUM, - comm)); - return true; - } -}; - -template -class MPISendTensorOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MPISendTensorOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(int, "dst", dst_, MPI_ANY_SOURCE), - OP_SINGLE_ARG(int, "tag", tag_, MPI_ANY_TAG), - OP_SINGLE_ARG(bool, "raw_buffer", raw_buffer_, false) { - CAFFE_ENFORCE(raw_buffer_, "non-raw-buffer transfer not supported yet."); - CAFFE_ENFORCE( - dst_ != MPI_ANY_SOURCE || def.input_size() == 4, - "You should explicitly specify the to rank either via " - "argument or via input blobs."); - CAFFE_ENFORCE( - tag_ != MPI_ANY_TAG || def.input_size() == 4, - "You should explicitly specify the tag either via " - "argument or via input blobs."); - } - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(COMM).comm(); - auto& input = Input(INPUT); - if (InputSize() == 4) { - dst_ = OperatorBase::Input(DST).template data()[0]; - tag_ = OperatorBase::Input(TAG).template data()[0]; - } - if (raw_buffer_) { - // We need to do a const cast to cope with the fact that, before OpenMPI - // 1.7, MPI_Send expects a non-const pointer although it uses it in a - // const way. - MPI_CHECK(MPI_Send( - const_cast(input.raw_data()), - input.nbytes(), - MPI_CHAR, - dst_, - tag_, - comm)); - } else { - CAFFE_NOT_IMPLEMENTED; - } - return true; - } - - protected: - int dst_; - int tag_; - bool raw_buffer_; - - INPUT_TAGS(COMM, INPUT, DST, TAG); -}; - -template -class MPIReceiveTensorOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MPIReceiveTensorOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(int, "src", src_, MPI_ANY_SOURCE), - OP_SINGLE_ARG(int, "tag", tag_, MPI_ANY_TAG), - OP_SINGLE_ARG(bool, "raw_buffer", raw_buffer_, false) { - CAFFE_ENFORCE(raw_buffer_, "non-raw-buffer transfer not supported yet."); - } - - bool RunOnDevice() override { - MPI_Comm comm = OperatorBase::Input(COMM).comm(); - if (InputSize() == 4) { - src_ = OperatorBase::Input(SRC_IN).template data()[0]; - tag_ = OperatorBase::Input(TAG_IN).template data()[0]; - } - MPI_Status status; - if (raw_buffer_) { - auto* output = Output(OUTPUT); - MPI_CHECK(MPI_Recv( - output->raw_mutable_data(), - output->nbytes(), - MPI_CHAR, - src_, - tag_, - comm, - &status)); - } else { - CAFFE_NOT_IMPLEMENTED; - } - auto* src_out = OperatorBase::Output(SRC_OUT); - src_out->Resize(); - src_out->template mutable_data()[0] = status.MPI_SOURCE; - auto* tag_out = OperatorBase::Output(TAG_OUT); - tag_out->Resize(); - tag_out->template mutable_data()[0] = status.MPI_TAG; - return true; - } - - protected: - int src_; - int tag_; - bool raw_buffer_; - INPUT_TAGS(COMM, INPUT, SRC_IN, TAG_IN); - OUTPUT_TAGS(OUTPUT, SRC_OUT, TAG_OUT); -}; - -} // namespace caffe2 - -#endif // CAFFE2_MPI_MPI_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/accumulate_op.h b/app/src/main/cpp/caffe2/operators/accumulate_op.h deleted file mode 100644 index 20cd4a3..0000000 --- a/app/src/main/cpp/caffe2/operators/accumulate_op.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ACCUMULATE_OP_H_ -#define CAFFE2_OPERATORS_ACCUMULATE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class AccumulateOp final : public Operator { - public: - AccumulateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - gamma_(static_cast( - OperatorBase::template GetSingleArgument("gamma", 1.0))) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - if (output->dims() != input.dims()) { - LOG(INFO) << "Reshaping and initializing output."; - output->ResizeLike(input); - math::Set( - output->size(), 0, output->template mutable_data(), &context_); - } - math::Axpby( - input.size(), - static_cast(1), - input.template data(), - gamma_, - output->template mutable_data(), - &context_); - return true; - } - - protected: - T gamma_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ACCUMULATE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/accuracy_op.h b/app/src/main/cpp/caffe2/operators/accuracy_op.h deleted file mode 100644 index e2dfb95..0000000 --- a/app/src/main/cpp/caffe2/operators/accuracy_op.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ACCURACY_OP_H_ -#define CAFFE2_OPERATORS_ACCURACY_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class AccuracyOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - AccuracyOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - top_k_(OperatorBase::GetSingleArgument("top_k", 1)) {} - - bool RunOnDevice() override; - - protected: - int top_k_; - INPUT_TAGS(PREDICTION, LABEL); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ACCURACY_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/apmeter_op.h b/app/src/main/cpp/caffe2/operators/apmeter_op.h deleted file mode 100644 index 4023e4a..0000000 --- a/app/src/main/cpp/caffe2/operators/apmeter_op.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CAFFE2_MAP_OP_H_ -#define CAFFE2_MAP_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class APMeterOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - APMeterOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - buffer_size_( - OperatorBase::GetSingleArgument("buffer_size", 1000)), - buffer_used_(0) {} - - bool RunOnDevice() override; - - protected: - using BufferDataType = std::pair; - // Buffer the predictions for each class - std::vector> buffers_; - // Capacity of the buffer - int buffer_size_; - // Used buffer - int buffer_used_; - - INPUT_TAGS(PREDICTION, LABEL); - - protected: - // Buffer predictions for N sample and D classes - void - BufferPredictions(const float* Xdata, const int* labelData, int N, int D); -}; - -} // namespace caffe2 - -#endif // CAFFE2_MAP_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/batch_box_cox_op.h b/app/src/main/cpp/caffe2/operators/batch_box_cox_op.h deleted file mode 100644 index 0825321..0000000 --- a/app/src/main/cpp/caffe2/operators/batch_box_cox_op.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CAFFE_OPERATORS_BATCH_BOX_COX_OPS_H_ -#define CAFFE_OPERATORS_BATCH_BOX_COX_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class BatchBoxCoxOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - BatchBoxCoxOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(DATA)); - } - - template - bool DoRunWithType(); - - protected: - INPUT_TAGS(DATA, LAMBDA1, LAMBDA2); -}; - -} // namespace caffe2 - -#endif // CAFFE_OPERATORS_BATCH_BOX_COX_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/batch_gather_ops.h b/app/src/main/cpp/caffe2/operators/batch_gather_ops.h deleted file mode 100644 index f70d6dc..0000000 --- a/app/src/main/cpp/caffe2/operators/batch_gather_ops.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef CAFFE2_OPERATORS_BATCH_GATHER_OPS_H_ -#define CAFFE2_OPERATORS_BATCH_GATHER_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class BatchGatherOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(BatchGatherOp) - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& data = Input(DATA); - auto& indices = Input(INDICES); - auto* output = Output(0); - - CAFFE_ENFORCE_GE(data.ndim(), 2, "DATA should be at least 2-D"); - - vector shape; - shape.push_back(data.dim(0)); - shape.insert(shape.end(), indices.dims().begin(), indices.dims().end()); - shape.insert(shape.end(), data.dims().begin() + 2, data.dims().end()); - output->Resize(shape); - - auto block_size = data.size_from_dim(2); - auto block_bytesize = block_size * data.meta().itemsize(); - auto N = indices.size(); - auto data_batch_bytesize = data.size_from_dim(1) * data.meta().itemsize(); - auto gathered_batch_bytesize = - N * data.size_from_dim(2) * data.meta().itemsize(); - const TInd* idxs = indices.template data(); - auto src_base = static_cast(data.raw_data()); - auto out = static_cast(output->raw_mutable_data(data.meta())); - - for (auto batch = 0; batch < data.dim(0); ++batch) { - for (auto i = 0; i < N; ++i) { - auto idx = idxs[i]; - CAFFE_ENFORCE( - 0 <= idx && idx < data.dim(1), - "INDICES element is out of DATA bounds, id=", - idx, - " data_dim=", - data.dim(1)); - auto src = - src_base + idx * block_bytesize + batch * data_batch_bytesize; - auto dst = out + i * block_bytesize + batch * gathered_batch_bytesize; - context_.template CopyItems( - data.meta(), block_size, src, dst); - } - } - return true; - } - - INPUT_TAGS(DATA, INDICES); -}; - -template -class BatchGatherGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(BatchGatherGradientOp); - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(INDICES)); - } - - template - bool DoRunWithType() { - return DispatchHelper< - TensorTypes2, - TInd>::call(this, Input(DATA)); - } - - template - bool DoRunWithType2() { - auto& data = Input(DATA); - auto& indices = Input(INDICES); - auto& grad = Input(GRAD); - auto* output = Output(0); - - CAFFE_ENFORCE_GE(data.ndim(), 2, "DATA should be at least 2-D"); - CAFFE_ENFORCE_EQ( - data.dim(0), grad.dim(0), "batch sizes should be the same"); - - output->ResizeLike(data); - TData* out_data = output->template mutable_data(); - memset(out_data, 0, output->nbytes()); - - const TData* grad_data = grad.template data(); - - auto block_size = data.size_from_dim(2); - auto N = indices.size(); - auto data_batch_size = data.size_from_dim(1); - auto gathered_batch_size = N * data.size_from_dim(2); - const TInd* idxs = indices.template data(); - - for (auto batch = 0; batch < grad.dim(0); ++batch) { - for (auto i = 0; i < N; ++i) { - auto idx = idxs[i]; - CAFFE_ENFORCE( - 0 <= idx && idx < data.dim(1), - "INDICES element is out of DATA bounds, id=", - idx, - " data_dim=", - data.dim(1)); - math::Add( - block_size, - out_data + idx * block_size + batch * data_batch_size, - grad_data + i * block_size + batch * gathered_batch_size, - out_data + idx * block_size + batch * data_batch_size, - &context_); - } - } - return true; - } - - template - bool DoRunWithOtherType2() { - CAFFE_THROW( - "BatchGatherGradient is not implemented on tensor of type ", - Input(DATA).meta().name(), - "Consider adding it a type in the list DispatchHelper or implementing " - "a generic version (which won't work for duplicated indices though)"); - } - - INPUT_TAGS(DATA, INDICES, GRAD); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_BATCH_GATHER_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/batch_matmul_op.h b/app/src/main/cpp/caffe2/operators/batch_matmul_op.h deleted file mode 100644 index 9b80acb..0000000 --- a/app/src/main/cpp/caffe2/operators/batch_matmul_op.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MATMUL_OP_H_ -#define CAFFE2_OPERATORS_MATMUL_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class BatchMatMulOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - BatchMatMulOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - trans_a_(OperatorBase::GetSingleArgument("trans_a", 0)), - trans_b_(OperatorBase::GetSingleArgument("trans_b", 0)), - use_scratch_(OperatorBase::GetSingleArgument("use_scratch", 0)) { - if (use_scratch_) - scratch_ = std::make_shared >(); - } - ~BatchMatMulOp() {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - const auto& A = Input(0); - const auto& B = Input(1); - auto* Y = Output(0); - - CAFFE_ENFORCE_EQ(A.ndim(), 3); - CAFFE_ENFORCE_EQ(B.ndim(), 3); - CAFFE_ENFORCE_EQ(A.dim32(0), B.dim32(0)); - - int a_dim0, a_dim1, b_dim0, b_dim1; - - if (trans_a_) { - a_dim0 = A.dim32(2); - a_dim1 = A.dim32(1); - } else { - a_dim0 = A.dim32(1); - a_dim1 = A.dim32(2); - } - - if (trans_b_) { - b_dim0 = B.dim32(2); - b_dim1 = B.dim32(1); - } else { - b_dim0 = B.dim32(1); - b_dim1 = B.dim32(2); - } - - // Error checking - CAFFE_ENFORCE( - a_dim1 == b_dim0, - "Dimension mismatch: ", - trans_a_ ? "trans(A): " : "A: ", - a_dim0, - " ", - a_dim1, - trans_b_ ? ", trans(B): " : ", B: ", - b_dim0, - " ", - b_dim1); - - Y->Resize(A.dim(0), a_dim0, b_dim1); - - if (!A.dim(0)) { - Y->template mutable_data(); // create output tensor - return true; - } - - // Y = A * B - math::GemmBatched( - trans_a_ ? CblasTrans : CblasNoTrans, - trans_b_ ? CblasTrans : CblasNoTrans, - A.size(), - A.dim32(0), - B.size(), - B.dim32(0), - a_dim0, // M - b_dim1, // N - a_dim1, // K - 1, - A.template data(), - B.template data(), - 0, - Y->template mutable_data(), - &context_, - use_scratch_ ? scratch_.get() : nullptr); - return true; - } - - protected: - bool trans_a_; - bool trans_b_; - - bool use_scratch_; - std::shared_ptr > scratch_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MATMUL_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/boolean_mask_ops.h b/app/src/main/cpp/caffe2/operators/boolean_mask_ops.h deleted file mode 100644 index 3e3120c..0000000 --- a/app/src/main/cpp/caffe2/operators/boolean_mask_ops.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef BOOLEAN_MASK_OPS_H -#define BOOLEAN_MASK_OPS_H - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/utils/conversions.h" - -namespace caffe2 { - -template -class BooleanMaskOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - BooleanMaskOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override; -}; - -template -class SequenceMaskOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - explicit SequenceMaskOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)), - radius_(OperatorBase::GetSingleArgument("radius", 10)), - grad_(OperatorBase::GetSingleArgument("grad", false)), - fill_val_(OperatorBase::GetSingleArgument( - "fill_val", - -1.0f * std::numeric_limits::infinity())) { - // Mode argument is required - mode_ = GetArgument(operator_def, "mode").s(); - } - - bool RunOnDevice() override; - - template - bool DoRunWithType(); - - private: - int axis_; - int radius_; - std::string mode_; - bool grad_; - float fill_val_; -}; - -} // caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/operators/boolean_unmask_ops.h b/app/src/main/cpp/caffe2/operators/boolean_unmask_ops.h deleted file mode 100644 index 41c6693..0000000 --- a/app/src/main/cpp/caffe2/operators/boolean_unmask_ops.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef BOOLEAN_UNMASK_OPS_H -#define BOOLEAN_UNMASK_OPS_H - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class BooleanUnmaskOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(BooleanUnmaskOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/operators/cast_op.h b/app/src/main/cpp/caffe2/operators/cast_op.h deleted file mode 100644 index 491028c..0000000 --- a/app/src/main/cpp/caffe2/operators/cast_op.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/cast.h" -#include "caffe2/utils/conversions.h" -#include "caffe2/utils/math.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/types.h" - -namespace caffe2 { - -template -class CastOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - CastOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - const ArgumentHelper helper(operator_def); - TensorProto_DataType to = cast::GetCastDataType(helper, "to"); - TensorProto_DataType from = cast::GetCastDataType(helper, "from_type"); - - SetBody(to); - } - - bool RunOnDevice() override { - return (this->*body_)(); - } - - // Allow for Context-specific implementations - void SetBody(TensorProto_DataType to); - - template - bool DoRunWithDstType(); - - template - bool DoRunWithType() { - auto& input = Input(0); - auto* output = Output(0); - output->ResizeLike(input); - const auto* data = input.template data(); - auto* out = output->template mutable_data(); - auto N = input.size(); - for (TIndex i = 0; i < N; ++i) { - out[i] = static_cast(data[i]); - } - return true; - } - - private: - bool (CastOp::*body_)(); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/channel_shuffle_op.h b/app/src/main/cpp/caffe2/operators/channel_shuffle_op.h deleted file mode 100644 index d42c722..0000000 --- a/app/src/main/cpp/caffe2/operators/channel_shuffle_op.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once -#include "caffe2/operators/conv_pool_op_base.h" - -namespace caffe2 { - -template -class ChannelShuffleOp final : public ConvPoolOpBase { - public: - USE_OPERATOR_FUNCTIONS(Context); - ChannelShuffleOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) { - OPERATOR_NEEDS_FEATURE( - this->order_ == StorageOrder::NCHW, - "ChannelShuffleOp only supports NCHW order"); - } - - bool RunOnDeviceWithOrderNCHW() override { - const auto& X = Input(0); - auto* Y = Output(0); - Y->ResizeLike(X); - const auto C = X.dim32(1); - CAFFE_ENFORCE(C % this->group_ == 0, ""); - const auto K = C / this->group_; - const auto S = X.dim32(2) * X.dim32(3); - const auto G = this->group_; - for (auto n = 0; n < X.dim32(0); ++n) { - for (auto g = 0; g < G; ++g) { - // Scatter the group g block (of size KxS) to output channels - // g + 0 * G, g + 1 * G, g + 2 * G, g + G * (K - 1) etc. - math::CopyMatrix( - X.itemsize(), - K, - S, - X.template data() + g * K * S + n * C * S, - S, - Y->template mutable_data() + g * S + n * C * S, - G * S, - &context_); - } - } - return true; - } -}; - -template -class ChannelShuffleGradientOp final : public ConvPoolOpBase { - public: - USE_OPERATOR_FUNCTIONS(Context); - ChannelShuffleGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) { - OPERATOR_NEEDS_FEATURE( - this->order_ == StorageOrder::NCHW, - "ChannelShuffleOp only supports NCHW order"); - } - - bool RunOnDeviceWithOrderNCHW() override { - const auto& dY = Input(0); - auto* dX = Output(0); - dX->ResizeLike(dY); - const auto C = dY.dim32(1); - CAFFE_ENFORCE(C % this->group_ == 0, ""); - const auto K = C / this->group_; - const auto S = dY.dim32(2) * dY.dim32(3); - const auto G = this->group_; - for (auto n = 0; n < dY.dim32(0); ++n) { - for (auto g = 0; g < G; ++g) { - // Gather the group g block (of size KxS) from output channels - // g + 0 * G, g + 1 * G, g + 2 * G, g + G * (K - 1) etc. - math::CopyMatrix( - dY.itemsize(), - K, - S, - dY.template data() + g * S + n * C * S, - G * S, - dX->template mutable_data() + g * K * S + n * C * S, - S, - &context_); - } - } - return true; - } -}; -} diff --git a/app/src/main/cpp/caffe2/operators/clip_op.h b/app/src/main/cpp/caffe2/operators/clip_op.h deleted file mode 100644 index d2d899e..0000000 --- a/app/src/main/cpp/caffe2/operators/clip_op.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CLIP_OP_H_ -#define CAFFE2_OPERATORS_CLIP_OP_H_ - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class ClipOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ClipOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - min_(std::numeric_limits::lowest()), - max_(std::numeric_limits::max()) { - if (HasArgument("min")) { - min_ = static_cast(OperatorBase::GetSingleArgument("min", 0)); - } - if (HasArgument("max")) { - max_ = static_cast(OperatorBase::GetSingleArgument("max", 0)); - } - } - - bool RunOnDevice() override; - - protected: - T min_; - T max_; -}; - -template -class ClipGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ClipGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - min_(std::numeric_limits::lowest()), - max_(std::numeric_limits::max()) { - if (HasArgument("min")) { - min_ = static_cast(OperatorBase::GetSingleArgument("min", 0)); - } - if (HasArgument("max")) { - max_ = static_cast(OperatorBase::GetSingleArgument("max", 0)); - } - } - - bool RunOnDevice() override; - - protected: - T min_; - T max_; - // Input: Y, dY; Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CLIP_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/concat_split_op.h b/app/src/main/cpp/caffe2/operators/concat_split_op.h deleted file mode 100644 index ccc9343..0000000 --- a/app/src/main/cpp/caffe2/operators/concat_split_op.h +++ /dev/null @@ -1,254 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONCAT_SPLIT_OP_H_ -#define CAFFE2_OPERATORS_CONCAT_SPLIT_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/types.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -namespace { -inline int GetDimFromOrderString(const string& str) { - auto order = StringToStorageOrder(str); - switch (order) { - case StorageOrder::NHWC: - return 3; - case StorageOrder::NCHW: - return 1; - default: - CAFFE_THROW("Unsupported storage order: ", str); - return -1; - } -} -} // namespace - -template -class SplitOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SplitOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - split_(OperatorBase::GetRepeatedArgument("split")) { - CAFFE_ENFORCE( - !(OperatorBase::HasArgument("axis") && OperatorBase::HasArgument("order")), - "You shouldn't specify both the dim to split, and the order " - "in the case of 4-D images."); - if (OperatorBase::HasArgument("axis")) { - axis_ = OperatorBase::GetSingleArgument("axis", -1); - // only exists for computing the gradient of a Concat with 'add_axis' - add_axis_ = OperatorBase::GetSingleArgument("add_axis", 0); - } else { - axis_ = GetDimFromOrderString( - OperatorBase::GetSingleArgument("order", "NCHW")); - add_axis_ = 0; - } - CAFFE_ENFORCE_GE(axis_, 0); - } - - bool RunOnDevice() override; - - protected: - int axis_; - int add_axis_; - vector split_; - // Input: X, optionally split - // The split tensor is stored in CPU. -}; - -template -class ConcatOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ConcatOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - CAFFE_ENFORCE( - !(OperatorBase::HasArgument("axis") && OperatorBase::HasArgument("order")), - "You shouldn't specify both the dim to concat, and the order " - "in the case of 4-D images."); - if (OperatorBase::HasArgument("axis")) { - axis_ = OperatorBase::GetSingleArgument("axis", -1); - add_axis_ = OperatorBase::GetSingleArgument("add_axis", 0); - } else { - axis_ = GetDimFromOrderString( - OperatorBase::GetSingleArgument("order", "NCHW")); - add_axis_ = 0; - } - CAFFE_ENFORCE_GE(axis_, 0); - } - - bool RunOnDevice() override; - - protected: - int axis_; - int add_axis_; - // Input: a number of tensors. Output: Y, split - // The split are stored in CPU. -}; - -// Implementations -template -bool SplitOp::RunOnDevice() { - auto& input = Input(0); - CAFFE_ENFORCE_LT(axis_, input.ndim(), "Axis not in input ndim range."); - const int input_channels = input.dim32(axis_); - const int* axis_data; - vector equal_split; - if (InputSize() == 2) { - // We obtain split from the input tensor. - CAFFE_ENFORCE_EQ( - split_.size(), - 0, - "If you set split with an input blob, do not pass in " - "split in the argument."); - auto& split_tensor = OperatorBase::Input(1); - CAFFE_ENFORCE_EQ(split_tensor.size(), OutputSize()); - axis_data = split_tensor.template data(); - } else if (split_.size() == 0) { - CAFFE_ENFORCE_EQ( - input_channels % OutputSize(), - 0, - "If you did not specify split explicitly, the number of " - "input channels should be divisible by the output size."); - equal_split.resize(OutputSize(), input_channels / OutputSize()); - axis_data = equal_split.data(); - } else { - // We obtain split from the parameters. - CAFFE_ENFORCE_EQ( - split_.size(), - OutputSize(), - "The number of splits specified should be equal to the " - "number of outputs."); - axis_data = split_.data(); - } - - CAFFE_ENFORCE_EQ( - add_axis_ ? OutputSize() - : std::accumulate(axis_data, axis_data + OutputSize(), 0), - input_channels, - "Sum of split dimensions do not match: should be ", - input_channels); - vector output_dims(input.dims()); - int before = 1, after = 1; - for (int i = 0; i < axis_; ++i) { - before *= input.dim32(i); - } - for (int i = axis_ + 1; i < input.ndim(); ++i) { - after *= input.dim32(i); - } - if (add_axis_) { - output_dims.erase(output_dims.begin() + axis_); - } - size_t input_offset = 0; - for (int i = 0; i < OutputSize(); ++i) { - auto* output = Output(i); - auto axis_dim = add_axis_ ? 1 : axis_data[i]; - if (!add_axis_) { - output_dims[axis_] = axis_data[i]; - } - output->Resize(output_dims); - math::CopyMatrix( - input.itemsize(), - before, - axis_dim * after, - static_cast(input.raw_data()) + input_offset, - input.dim32(axis_) * after, - output->raw_mutable_data(input.meta()), - axis_dim * after, - &context_); - input_offset += axis_dim * after * input.itemsize(); - } - return true; -} - -template -bool ConcatOp::RunOnDevice() { - auto* output = Output(0); - TensorCPU* split = OperatorBase::Output(1); - split->Resize(vector(1, InputSize())); - int* axis_data = split->template mutable_data(); - auto& input_zero = Input(0); - CAFFE_ENFORCE_LT( - axis_, - input_zero.ndim() + (add_axis_ ? 1 : 0), - "Axis not in input ndim range."); - for (int i = 1; i < InputSize(); ++i) { - CAFFE_ENFORCE( - Input(i).meta() == input_zero.meta(), - "All inputs must have the same type, expected: ", - input_zero.meta().name(), - " but got: ", - Input(i).meta().name(), - " for input: ", - i); - } - - int before = 1, after = 1; - vector output_dims(input_zero.dims()); - for (int i = 0; i < input_zero.ndim(); ++i) { - if (i == axis_ && !add_axis_) { - continue; - } - int dim = input_zero.dim32(i); - if (i < axis_) { - before *= dim; - } else { // i > axis_ || i == axis_ && add_axis_ - after *= dim; - } - // check the input dims are compatible. - for (int j = 1; j < InputSize(); ++j) { - int dim_j = Input(j).dim32(i); - CAFFE_ENFORCE( - dim == dim_j, - "Expect dimension = ", - dim, - " got ", - dim_j, - " at axis = ", - i, - " for input: ", - j, - ". The input tensors can only have different dimensions " - "when arg 'add_axis' = 0 and along the axis = ", - axis_, - " <", - Input(0).dims(), - "> vs <", - Input(j).dims(), - ">."); - } - } - - int output_channels = 0; - for (int i = 0; i < InputSize(); ++i) { - axis_data[i] = add_axis_ ? 1 : Input(i).dim32(axis_); - output_channels += axis_data[i]; - } - if (add_axis_) { - output_dims.insert(output_dims.begin() + axis_, output_channels); - } else { - output_dims[axis_] = output_channels; - } - output->Resize(output_dims); - size_t output_offset = 0; - for (int i = 0; i < InputSize(); ++i) { - auto& input = Input(i); - auto axis_dim = add_axis_ ? 1 : input.dim32(axis_); - math::CopyMatrix( - input.itemsize(), - before, - axis_dim * after, - input.raw_data(), - axis_dim * after, - static_cast(output->raw_mutable_data(input_zero.meta())) + - output_offset, - output_channels * after, - &context_); - output_offset += axis_dim * after * input.itemsize(); - } - return true; -} - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONCAT_SPLIT_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/conditional_op.h b/app/src/main/cpp/caffe2/operators/conditional_op.h deleted file mode 100644 index 9fa53fe..0000000 --- a/app/src/main/cpp/caffe2/operators/conditional_op.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CONDITIONAL_OP_H -#define CONDITIONAL_OP_H - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -template -class ConditionalOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ConditionalOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override; -}; - -} // caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/operators/conv_op.h b/app/src/main/cpp/caffe2/operators/conv_op.h deleted file mode 100644 index 7153b14..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_op.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_OP_H_ -#define CAFFE2_OPERATORS_CONV_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_op_shared.h" -#include "caffe2/operators/conv_pool_op_base.h" - -CAFFE2_DECLARE_bool(caffe2_force_shared_col_buffer); - -namespace caffe2 { - -template -class ConvOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - ConvOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) { - // Since this is the default convolution implementation, we will - // use CAFFE_ENFORCE instead of OPERATOR_NEEDS_FEATURE. - CAFFE_ENFORCE( - group_ == 1 || order_ == StorageOrder::NCHW, - "Group convolution only supports NCHW order right now."); - - // Create shared buffer mutex in the constructor - // to avoid race-condition in DAGNet. - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - createSharedBuffer(ws_); - } - } - ~ConvOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - Tensor col_buffer_; - Tensor bias_multiplier_; - Tensor img_shape_device_; - Tensor col_buffer_shape_device_; - // Input: X, W, b - // Output: Y - INPUT_TAGS(INPUT, FILTER, BIAS); -}; - -template -class ConvGradientOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - ConvGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws), - no_bias_(OperatorBase::GetSingleArgument("no_bias", 0)) { - CAFFE_ENFORCE( - !(no_bias_ && OutputSize() == 3), - "If bias is not present, you should not have 3 grad output."); - CAFFE_ENFORCE( - group_ == 1 || order_ == StorageOrder::NCHW, - "Group convolution only supports NCHW order right now."); - } - ~ConvGradientOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - Tensor col_buffer_; - Tensor bias_multiplier_; - Tensor img_shape_device_; - Tensor col_buffer_shape_device_; - bool no_bias_; - // input: X, W, dY - // output: dW, db, and optionally dX - INPUT_TAGS(INPUT, FILTER, OUTPUT_GRAD); - OUTPUT_TAGS(FILTER_GRAD, BIAS_OR_INPUT_GRAD, INPUT_GRAD); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_op_cache_cudnn.h b/app/src/main/cpp/caffe2/operators/conv_op_cache_cudnn.h deleted file mode 100644 index d02a84f..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_op_cache_cudnn.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_OP_CACHE_H_ -#define CAFFE2_OPERATORS_CONV_OP_CACHE_H_ - -#include -#include -#include - -#include "caffe2/core/logging.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { -template -class AlgorithmsCache { - public: - T getAlgorithm( - const std::vector& bottom, - const std::vector& desc, - std::function generatingFunc); - - private: - std::unordered_map hash_; -}; - -template -T AlgorithmsCache::getAlgorithm( - const std::vector& vec1, - const std::vector& vec2, - std::function generatingFunc) { - int64_t seed = 0; - std::hash hashFn; - for (const auto num : vec1) { - // Copied from boost::hash_combine. - // Adding 1 to differentiate between first and second vector. - seed ^= hashFn(num) + 0x9e3779b9 + (seed << 6) + (seed >> 2) + 1; - } - - for (const auto num : vec2) { - // Copied from boost::hash_combine. - seed ^= hashFn(num) + 0x9e3779b9 + (seed << 6) + (seed >> 2); - } - - if (seed == 0) { - return generatingFunc(); - } - - if (hash_.find(seed) == hash_.end()) { - T value = generatingFunc(); - hash_[seed] = value; - } - - return hash_[seed]; -} -} -#endif diff --git a/app/src/main/cpp/caffe2/operators/conv_op_impl.h b/app/src/main/cpp/caffe2/operators/conv_op_impl.h deleted file mode 100644 index 93a5fb6..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_op_impl.h +++ /dev/null @@ -1,709 +0,0 @@ -// conv_op_impl.h is the templated implementation of the conv_op.h file. -#ifndef CAFFE2_OPERATORS_CONV_OP_IMPL_H_ -#define CAFFE2_OPERATORS_CONV_OP_IMPL_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/flags.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_op.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -bool ConvOp::RunOnDeviceWithOrderNCHW() { - const Tensor& X = Input(INPUT); - auto& filter = Input(FILTER); - Tensor* Y = Output(0); - const int N = X.dim32(0), C = X.dim32(1); - CAFFE_ENFORCE_EQ(X.ndim(), filter.ndim()); - const int M = filter.dim32(0); - CAFFE_ENFORCE( - C == filter.dim32(1) * group_, - "Convolution op: input channels does not match: # of input channels ", - C, - " is not equal to kernel channels * group:", - filter.dim32(1), - "*", - group_); - CAFFE_ENFORCE( - M % group_ == 0, - "The number of output channels is not divisible by group."); - - int kernel_dims_size = 1; - for (int i = 0; i < kernel_.size(); ++i) { - CAFFE_ENFORCE(filter.dim32(i + 2) == kernel_[i]); - kernel_dims_size *= kernel_[i]; - } - - ConvPoolOpBase::SetOutputSize(X, Y, filter.dim32(0)); - - const vector input_dims = GetDims(X); - const vector output_dims = GetDims(*Y); - const int input_image_size = this->GetDimsSize(X); - const int output_image_size = this->GetDimsSize(*Y); - - vector img_shape; - img_shape.assign(X.dims().begin() + 1, X.dims().end()); - - vector buffer_shape; - buffer_shape.push_back(C / group_ * kernel_dims_size); - buffer_shape.insert( - buffer_shape.end(), output_dims.begin(), output_dims.end()); - - if (kernel_.size() != 2 && img_shape_device_.size() != img_shape.size()) { - img_shape_device_.Resize(img_shape.size()); - context_.template Copy( - img_shape.size(), - img_shape.data(), - img_shape_device_.template mutable_data()); - } - - if (kernel_.size() != 2 && - col_buffer_shape_device_.size() != buffer_shape.size()) { - col_buffer_shape_device_.Resize(buffer_shape.size()); - context_.template Copy( - buffer_shape.size(), - buffer_shape.data(), - col_buffer_shape_device_.template mutable_data()); - } - - const int col_buffer_size = - (C / group_) * kernel_dims_size * output_image_size; - - // The dimension of each kernel - const int kernel_dim = C / group_ * kernel_dims_size; - // The offset corresponding to a single input image, and a single output - // image. - const int input_offset = C / group_ * input_image_size; - const int output_offset = Y->size() / Y->dim32(0) / group_; - const int filter_offset = filter.size() / group_; - - // The col buffer is stored in CHW order as well - kernel_dim, and the height - // and width. - const T* Xdata = X.template data(); - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(bias.ndim() == 1); - CAFFE_ENFORCE(bias.dim32(0) == M); - if (bias_multiplier_.size() != output_image_size) { - // If the helper bias multiplier is not image size, reshape and fill it - // with - // one. - bias_multiplier_.Resize(vector(1, output_image_size)); - math::Set( - output_image_size, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - } - T* Ydata = Y->template mutable_data(); - - auto f = [&](Tensor* col_buffer) { - col_buffer->Resize(buffer_shape); - T* col_buffer_data = col_buffer->template mutable_data(); - // Im2col, followed by gemm. - for (int image_id = 0; image_id < N; ++image_id) { - for (int group_id = 0; group_id < group_; ++group_id) { - if (kernel_.size() == 2) { - math::Im2col( - Xdata + group_id * input_offset, - C / group_, - input_dims[0], - input_dims[1], - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - col_buffer_data, - &context_); - } else { - math::Im2colNd( - Xdata + group_id * input_offset, - img_shape_device_.template data(), - col_buffer_shape_device_.template data(), - C * input_image_size, - col_buffer_size, - kernel_device_.template data(), - stride_device_.template data(), - dilation_device_.template data(), - pads_device_.template data(), - kernel_.size(), - col_buffer_data, - &context_); - } - // Weight term - math::Gemm( - CblasNoTrans, - CblasNoTrans, - M / group_, - output_image_size, - kernel_dim, - 1, - filter.template data() + group_id * filter_offset, - col_buffer_data, - 0, - Ydata + group_id * output_offset, - &context_); - } - if (InputSize() == 3) { - // Bias term can be carried out outside the group definition - // to be efficient. - auto* bias_data = Input(BIAS).template data(); - math::Gemm( - CblasNoTrans, - CblasNoTrans, - M, - output_image_size, - 1, - 1, - bias_data, - bias_multiplier_.template data(), - 1, - Ydata, - &context_); - } - Xdata += input_offset * group_; - Ydata += output_offset * group_; - } - }; - - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - runWithSharedBuffer(ws_, f); - } else { - f(&col_buffer_); - } - return true; -} - -// The implementations. -template -bool ConvOp::RunOnDeviceWithOrderNHWC() { - const Tensor& X = Input(INPUT); - auto& filter = Input(FILTER); - Tensor* Y = Output(0); - const int N = X.dim32(0), H = X.dim32(1), W = X.dim32(2), C = X.dim32(3); - - CAFFE_ENFORCE_EQ( - kernel_.size(), - 2, - "Only 2d convolution is supported for NHWC storage type"); - - CAFFE_ENFORCE(X.ndim(), filter.ndim()); - const int M = filter.dim32(0); - CAFFE_ENFORCE(filter.dim32(1) == kernel_h()); - CAFFE_ENFORCE(filter.dim32(2) == kernel_w()); - CAFFE_ENFORCE(filter.dim32(3) == C); - - ConvPoolOpBase::SetOutputSize(X, Y, filter.dim32(0)); - // The dimension of each kernel - const int kernel_dim = kernel_h() * kernel_w() * C; - // The offset corresponding to a single input image, and a single output - // image. - const int input_offset = H * W * C; - const int output_offset = Y->size() / Y->dim32(0); - // The output image size is the spatial size of the output. - const int output_image_size = Y->dim32(1) * Y->dim32(2); - // The col buffer is stored in HWC order as well - kernel_dim, and the height - // and width. - const T* Xdata = X.template data(); - T* Ydata = Y->template mutable_data(); - // Specialized path for 1 by 1 convolution with stride 1, pad 0 - we - // can skip im2col. - if (kernel_dim == C && Y->dim32(1) == X.dim32(1) && - Y->dim32(2) == X.dim32(2) && stride_h() == 1 && stride_w() == 1 && - pad_t() == 0 && pad_b() == 0 && pad_l() == 0 && pad_r() == 0) { - math::Gemm( - CblasNoTrans, - CblasTrans, - N * H * W, - M, - C, - 1, - Xdata, - filter.template data(), - 0, - Ydata, - &context_); - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(1 == bias.ndim()); - CAFFE_ENFORCE(bias.dim32(0) == M); - if (bias_multiplier_.size() != N * H * W) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(vector(1, N * H * W)); - math::Set( - N * H * W, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, - CblasNoTrans, - N * H * W, - M, - 1, - 1, - bias_multiplier_.template data(), - bias.template data(), - 1, - Ydata, - &context_); - } - } else { - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(1 == bias.ndim()); - CAFFE_ENFORCE(bias.dim32(0) == M); - if (bias_multiplier_.size() != output_image_size) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(vector(1, output_image_size)); - math::Set( - output_image_size, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - } - auto f = [&](Tensor* col_buffer) { - col_buffer->Resize( - vector{Y->dim32(1), Y->dim32(2), kernel_h(), kernel_w(), C}); - T* col_buffer_data = col_buffer->template mutable_data(); - // Im2col, followed by gemm. - for (int image_id = 0; image_id < N; ++image_id) { - math::Im2col( - Xdata, - C, - H, - W, - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - col_buffer_data, - &context_); - // Weight term - math::Gemm( - CblasNoTrans, - CblasTrans, - output_image_size, - M, - kernel_dim, - 1, - col_buffer_data, - filter.template data(), - 0, - Ydata, - &context_); - if (InputSize() == 3) { - // Bias term - math::Gemm( - CblasNoTrans, - CblasNoTrans, - output_image_size, - M, - 1, - 1, - bias_multiplier_.template data(), - Input(BIAS).template data(), - 1, - Ydata, - &context_); - } - Xdata += input_offset; - Ydata += output_offset; - } - }; - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - runWithSharedBuffer(ws_, f); - } else { - f(&col_buffer_); - } - } - return true; -} - -template -bool ConvGradientOp::RunOnDeviceWithOrderNCHW() { - auto& X = Input(INPUT); - auto& filter = Input(FILTER); - auto& dY = Input(OUTPUT_GRAD); - auto* dfilter = Output(FILTER_GRAD); - const int N = X.dim32(0), C = X.dim32(1); - - const vector input_dims = this->GetDims(X); - const int input_image_size = this->GetDimsSize(X); - - const vector output_dims = this->GetDims(dY); - // The output image size is the spatial size of the output. - const int output_image_size = this->GetDimsSize(dY); - - ConvPoolOpBase::ComputePads(input_dims); - CAFFE_ENFORCE_EQ(X.ndim(), filter.ndim()); - const int M = filter.dim32(0); - CAFFE_ENFORCE(filter.dim32(1) * group_ == C); - - int kernel_dims_size = 1; - for (int i = 0; i < kernel_.size(); ++i) { - CAFFE_ENFORCE(filter.dim32(i + 2) == kernel_[i]); - kernel_dims_size *= kernel_[i]; - } - - CAFFE_ENFORCE(M % group_ == 0); - dfilter->ResizeLike(filter); - // The dimension of each kernel - const int kernel_dim = C / group_ * kernel_dims_size; - // The offset corresponding to a single input image, and a single output - // image. - const int input_offset = C / group_ * input_image_size; - const int output_offset = dY.size() / dY.dim32(0) / group_; - const int filter_offset = filter.size() / group_; - // The col buffer is stored in CHW order as well - kernel_dim, and the height - // and width. - - vector img_shape; - img_shape.assign(X.dims().begin() + 1, X.dims().end()); - vector col_buffer_shape; - col_buffer_shape.push_back(C / group_ * kernel_dims_size); - col_buffer_shape.insert( - col_buffer_shape.end(), output_dims.begin(), output_dims.end()); - col_buffer_.Resize(col_buffer_shape); - - if (kernel_.size() != 2 && img_shape_device_.size() != img_shape.size()) { - img_shape_device_.Resize(img_shape.size()); - context_.template Copy( - img_shape.size(), - img_shape.data(), - img_shape_device_.template mutable_data()); - } - - const int col_buffer_size = - (C / group_) * kernel_dims_size * output_image_size; - - if (kernel_.size() != 2 && - col_buffer_shape_device_.size() != col_buffer_shape.size()) { - col_buffer_shape_device_.Resize(col_buffer_shape.size()); - context_.template Copy( - col_buffer_shape.size(), - col_buffer_shape.data(), - col_buffer_shape_device_.template mutable_data()); - } - - const T* Xdata = X.template data(); - const T* filter_data = filter.template data(); - const T* dYdata = dY.template data(); - T* col_buffer_data = col_buffer_.template mutable_data(); - T* dfilter_data = dfilter->template mutable_data(); - - // Pre-setting the gradients to zero. - math::Set(dfilter->size(), 0, dfilter_data, &context_); - - T* dbias_data = nullptr; - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - dbias->Resize(M); - if (bias_multiplier_.size() != output_image_size) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(vector(1, output_image_size)); - math::Set( - output_image_size, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - dbias_data = dbias->template mutable_data(); - math::Set(dbias->size(), 0, dbias_data, &context_); - } - - for (int image_id = 0; image_id < N; ++image_id) { - for (int group_id = 0; group_id < group_; ++group_id) { - // When we compute the gradient with respect to the filters, we need to do - // im2col to allow gemm-type computation. - if (kernel_.size() == 2) { - math::Im2col( - Xdata + group_id * input_offset, - C / group_, - input_dims[0], - input_dims[1], - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - col_buffer_data, - &context_); - } else { - math::Im2colNd( - Xdata + group_id * input_offset, - img_shape_device_.template data(), - col_buffer_shape_device_.template data(), - C * input_image_size, - col_buffer_size, - kernel_device_.template data(), - stride_device_.template data(), - dilation_device_.template data(), - pads_device_.template data(), - kernel_.size(), - col_buffer_data, - &context_); - } - // Gradient with respect to filter. - math::Gemm( - CblasNoTrans, - CblasTrans, - M / group_, - kernel_dim, - output_image_size, - 1, - dYdata + group_id * output_offset, - col_buffer_data, - 1, - dfilter_data + group_id * filter_offset, - &context_); - } - if (!no_bias_) { - // Gradient with respect to bias can be computed independent from group. - math::Gemv( - CblasNoTrans, - M, - output_image_size, - 1, - dYdata, - bias_multiplier_.template data(), - 1, - dbias_data, - &context_); - } - Xdata += input_offset * group_; - dYdata += output_offset * group_; - } - if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) { - // Compute the gradient w.r.t. the input. - auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD); - dX->ResizeLike(X); - T* dXdata = dX->template mutable_data(); - dYdata = dY.template data(); - for (int image_id = 0; image_id < N; ++image_id) { - for (int group_id = 0; group_id < group_; ++group_id) { - // Compute gradient into col_buffer. - math::Gemm( - CblasTrans, - CblasNoTrans, - kernel_dim, - output_image_size, - M / group_, - 1, - filter_data + group_id * filter_offset, - dYdata, - 0, - col_buffer_data, - &context_); - if (kernel_.size() == 2) { - math::Col2im( - col_buffer_data, - C / group_, - input_dims[0], - input_dims[1], - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - dXdata, - &context_); - } else { - math::Col2imNd( - col_buffer_data, - img_shape_device_.template data(), - col_buffer_shape_device_.template data(), - C * input_image_size, - col_buffer_size, - kernel_device_.template data(), - stride_device_.template data(), - dilation_device_.template data(), - pads_device_.template data(), - kernel_.size(), - dXdata, - &context_); - } - dXdata += input_offset; - dYdata += output_offset; - } - } - } - return true; -} - -template -bool ConvGradientOp::RunOnDeviceWithOrderNHWC() { - auto& X = Input(INPUT); - auto& filter = Input(FILTER); - auto& dY = Input(OUTPUT_GRAD); - auto* dfilter = Output(FILTER_GRAD); - - const int N = X.dim32(0), H = X.dim32(1), W = X.dim32(2), C = X.dim32(3); - ConvPoolOpBase::ComputePads({H, W}); - CAFFE_ENFORCE(4 == filter.ndim()); - const int M = filter.dim32(0); - CAFFE_ENFORCE(filter.dim32(1) == kernel_h()); - CAFFE_ENFORCE(filter.dim32(2) == kernel_w()); - CAFFE_ENFORCE(filter.dim32(3) == C); - dfilter->ResizeLike(filter); - - // The dimension of each kernel - const int kernel_dim = kernel_h() * kernel_w() * C; - // The offset corresponding to a single input image, and a single output - // image. - const int input_offset = H * W * C; - const int output_offset = dY.size() / dY.dim32(0); - // The output image size is the spatial size of the output. - const int output_image_size = dY.dim32(1) * dY.dim32(2); - // The col buffer is stored in CHW order as well - kernel_dim, and the height - // and width. - col_buffer_.Resize(output_image_size, kernel_dim); - - const T* Xdata = X.template data(); - const T* const filter_data = filter.template data(); - const T* const dYdata = dY.template data(); - T* col_buffer_data = col_buffer_.template mutable_data(); - T* dfilter_data = dfilter->template mutable_data(); - - // Pre-setting the gradients to zero. - math::Set(dfilter->size(), 0, dfilter_data, &context_); - - T* dbias_data = nullptr; - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - dbias->Resize(M); - dbias_data = dbias->template mutable_data(); - math::Set(dbias->size(), 0, dbias_data, &context_); - if (bias_multiplier_.size() != output_image_size) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(vector(1, output_image_size)); - math::Set( - output_image_size, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - } - - for (int image_id = 0; image_id < N; ++image_id) { - // When we compute the gradient with respect to the filters, we need to do - // im2col to allow gemm-type computation. - math::Im2col( - Xdata, - C, - H, - W, - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - col_buffer_data, - &context_); - // Gradient with respect to filter. - math::Gemm( - CblasTrans, - CblasNoTrans, - M, - kernel_dim, - output_image_size, - 1, - dYdata + output_offset * image_id, - col_buffer_data, - 1, - dfilter_data, - &context_); - if (!no_bias_) { - // Gradient with respect to bias - math::Gemv( - CblasTrans, - output_image_size, - M, - 1, - dYdata + output_offset * image_id, - bias_multiplier_.template data(), - 1, - dbias_data, - &context_); - } - Xdata += input_offset; - } - - if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) { - // Compute the gradient w.r.t. the input. - auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD); - dX->ResizeLike(X); - T* dXdata = dX->template mutable_data(); - for (int image_id = 0; image_id < N; ++image_id) { - // Compute gradient into col_buffer. - math::Gemm( - CblasNoTrans, - CblasNoTrans, - output_image_size, - kernel_dim, - M, - 1, - dYdata + output_offset * image_id, - filter_data, - 0, - col_buffer_data, - &context_); - math::Col2im( - col_buffer_data, - C, - H, - W, - kernel_h(), - kernel_w(), - dilation_h(), - dilation_w(), - pad_t(), - pad_l(), - pad_b(), - pad_r(), - stride_h(), - stride_w(), - dXdata, - &context_); - dXdata += input_offset; - } - } - return true; -} -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_OP_IMPL_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_op_shared.h b/app/src/main/cpp/caffe2/operators/conv_op_shared.h deleted file mode 100644 index 18f7aa8..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_op_shared.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_OP_SHARED_H_ -#define CAFFE2_OPERATORS_CONV_OP_SHARED_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" - -namespace caffe2 { - -/** - * Creates a mutex and shared buffer in the workspace. - * Not thread-safe, must be called from the constructor. - */ -template -void createSharedBuffer(Workspace* ws); - -/** - * Thread-safe, can be invoked from RunOnDevice() to serialize - * access to shared buffer. - */ -template -void runWithSharedBuffer( - Workspace* ws, - std::function* buffer)> f); -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_OP_SHARED_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_pool_op_base.h b/app/src/main/cpp/caffe2/operators/conv_pool_op_base.h deleted file mode 100644 index e0c7c9e..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_pool_op_base.h +++ /dev/null @@ -1,684 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_POOL_OP_BASE_H_ -#define CAFFE2_OPERATORS_CONV_POOL_OP_BASE_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/proto/caffe2_legacy.pb.h" -#include "caffe2/utils/math.h" - -// This macro is here just to allow us to experiment with padding values that -// determines, when we have an odd number of pads, which side gets the one -// additional pad value, the head side, or the tail side. Setting it to false -// will enable the TensorFlow behavior, and setting it to true will enable -// a behavior more consistent with Caffe and CuDNN. -// This only affects the case when you set legacy pad to VALID or SAME. The -// behavior inherits from the early designs of Google's CNN implementation, -// where padding values are implicitly calculated instead of explicitly -// specified. This is still the case with TensorFlow. Many frameworks have -// followed a slightly different approach of explicitly giving padding values, -// in which case the value of this constant value does not matter. -const bool CAFFE2_PAD_HEAD_MORE = false; - -namespace caffe2 { - -template -class ConvPoolOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ConvPoolOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - legacy_pad_( - static_cast(OperatorBase::GetSingleArgument( - "legacy_pad", - LegacyPadding::NOTSET))), - global_pooling_( - OperatorBase::GetSingleArgument("global_pooling", 0)), - kernel_(OperatorBase::GetRepeatedArgument("kernels")), - dilation_(OperatorBase::GetRepeatedArgument("dilations")), - stride_(OperatorBase::GetRepeatedArgument("strides")), - pads_(OperatorBase::GetRepeatedArgument("pads")), - group_(OperatorBase::GetSingleArgument("group", 1)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - shared_buffer_( - OperatorBase::GetSingleArgument("shared_buffer", 0)), - ws_(ws) { - // For the padding, they should either be the legacy padding strategy - // (VALID or SAME), or an explicit, non-negative value. - if (legacy_pad_ == LegacyPadding::VALID || - legacy_pad_ == LegacyPadding::SAME) { - CAFFE_ENFORCE( - !OperatorBase::HasArgument("pads"), - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - } - - // Get old arguments values. - if (OperatorBase::HasArgument("kernel")) { - kernel_.resize(2, OperatorBase::GetSingleArgument("kernel", 0)); - } else if ( - OperatorBase::HasArgument("kernel_h") && - OperatorBase::HasArgument("kernel_w")) { - kernel_.push_back(OperatorBase::GetSingleArgument("kernel_h", 0)); - kernel_.push_back(OperatorBase::GetSingleArgument("kernel_w", 0)); - } - - if (OperatorBase::HasArgument("stride")) { - stride_.resize(2, OperatorBase::GetSingleArgument("stride", 0)); - } else if ( - OperatorBase::HasArgument("stride_h") && - OperatorBase::HasArgument("stride_w")) { - stride_.push_back(OperatorBase::GetSingleArgument("stride_h", 0)); - stride_.push_back(OperatorBase::GetSingleArgument("stride_w", 0)); - } - - if (OperatorBase::HasArgument("dilation")) { - dilation_.resize(2, OperatorBase::GetSingleArgument("dilation", 0)); - } else if ( - OperatorBase::HasArgument("dilation_h") && - OperatorBase::HasArgument("dilation_w")) { - dilation_.push_back( - OperatorBase::GetSingleArgument("dilation_h", 0)); - dilation_.push_back( - OperatorBase::GetSingleArgument("dilation_w", 0)); - } - - if (OperatorBase::HasArgument("pad")) { - CAFFE_ENFORCE( - legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME, - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - pads_.resize(4, OperatorBase::GetSingleArgument("pad", 0)); - } else if ( - OperatorBase::HasArgument("pad_t") && - OperatorBase::HasArgument("pad_l") && - OperatorBase::HasArgument("pad_b") && - OperatorBase::HasArgument("pad_r")) { - CAFFE_ENFORCE( - legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME, - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - pads_.push_back(OperatorBase::GetSingleArgument("pad_t", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_l", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_b", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_r", 0)); - } - - // Fill default values. - if (kernel_.size() == 0) { - kernel_.assign({0, 0}); - } - - if (stride_.size() == 0) { - stride_.resize(kernel_.size(), 1); - } - - if (pads_.size() == 0) { - pads_.resize(kernel_.size() * 2, 0); - } - - if (dilation_.size() == 0) { - dilation_.resize(kernel_.size(), 1); - } - - CAFFE_ENFORCE_EQ(stride_.size(), kernel_.size()); - CAFFE_ENFORCE_EQ(dilation_.size(), kernel_.size()); - - if (legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME) { - CAFFE_ENFORCE_EQ(pads_.size(), 2 * kernel_.size()); - } - - if (global_pooling_) { - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE( - pads_[2 * dim] == 0 && pads_[2 * dim + 1] == 0 && - dilation_[dim] == 1 && stride_[dim] == 1, - "If global_pooling is set dilation and stride shouldn't be set."); - } - } - - AllocateAndCopy(kernel_, kernel_device_); - AllocateAndCopy(stride_, stride_device_); - AllocateAndCopy(dilation_, dilation_device_); - AllocateAndCopy(pads_, pads_device_); - - // Check kernel only if we are doing conv or pooling. The reason is that a - // few other ops, like PadImage, are also using this base class. We really - // need to clean this up. - if (operator_def.name().find("Conv") == 0 || - operator_def.name().find("Pool") != std::string::npos) { - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE_GE(pads_[dim], 0); - CAFFE_ENFORCE_GE(pads_[kernel_.size() + dim], 0); - CAFFE_ENFORCE( - kernel_[dim], - "If you are doing convolution or pooling, you will need to set " - "explicitly the kernel size."); - } - } - - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE_GE(kernel_[dim], 0); - CAFFE_ENFORCE_GE(dilation_[dim], 0); - CAFFE_ENFORCE_GE(stride_[dim], 0); - } - - if (group_ != 1) { - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE_EQ( - dilation_[dim], - 1, - "When group is used, dilation should not be set at the same time."); - } - } - } - - // Returns the input image dimensions for the current storage order type. - vector GetDims(const Tensor& input) { - vector dims; - switch (order_) { - case StorageOrder::NCHW: - dims.assign(input.dims().begin() + 2, input.dims().end()); - break; - case StorageOrder::NHWC: - dims.assign(input.dims().begin() + 1, input.dims().end() - 1); - break; - default: - CAFFE_THROW("Unknown storage order : ", order_); - } - return dims; - } - - // Returns the size of the input image for the current storage type. - int GetDimsSize(const Tensor& input) { - int size = 0; - switch (order_) { - case StorageOrder::NCHW: - size = std::accumulate( - input.dims().begin() + 2, - input.dims().end(), - 1, - std::multiplies()); - break; - case StorageOrder::NHWC: - size = std::accumulate( - input.dims().begin() + 1, - input.dims().end() - 1, - 1, - std::multiplies()); - break; - default: - CAFFE_THROW("Unknown storage order : ", order_); - } - return size; - } - - // Sets the output size. The output channel is manually provided since - // it may not be identical to the input channels. - // This function can be used in the forward functions to obtain the output - // sizes. - // Note(jiayq): the templatization of this function is mainly to help - // implementations that do not use first-class Tensor objects, such as the - // MKL operator. One can still call this function with dummy - // Tensor objects in order to obtain the sizes. - template - void SetOutputSize( - const Tensor& input, - Tensor* output, - int output_channel) { - CAFFE_ENFORCE(input.size() > 0); - vector output_dims; - int N = input.dim32(0); - bool channel_first; - InferOutputSize( - input.dims(), - output_channel, - order_, - global_pooling_, - legacy_pad_, - N, - kernel_, - output_dims, - dilation_, - stride_, - pads_, - channel_first); - - if (channel_first) { - output_dims.insert(output_dims.begin(), {N, output_channel}); - } else { - output_dims.insert(output_dims.begin(), N); - output_dims.push_back(output_channel); - } - output->Resize(output_dims); - } - - // Helper function that is also called from OperatorSchema. Modified - // kernel parameters and output output_dims and channel_first. - static inline void InferOutputSize( - vector input_dims, - int /*output_channel*/, - StorageOrder order, - bool global_pooling, - LegacyPadding legacy_pad, - int /*N*/, - vector& kernel, - vector& output_dims, - vector dilation, - vector stride, - vector pads, - bool& channel_first) { - channel_first = false; // initialized to suppress compiler warning. - vector dims; - switch (order) { - case StorageOrder::NHWC: - channel_first = false; - dims.assign(input_dims.begin() + 1, input_dims.end() - 1); - break; - case StorageOrder::NCHW: - // Old Caffe order. - channel_first = true; - dims.assign(input_dims.begin() + 2, input_dims.end()); - break; - default: - CAFFE_THROW("Unknown Storage order: ", order); - } - - if (global_pooling) { - kernel.assign(dims.begin(), dims.end()); - output_dims.assign(dims.size(), 1); - } else { - for (int dim = 0; dim < dims.size(); ++dim) { - int dim_size = 0; - ComputeSizeAndPad( - dims[dim], - stride[dim], - kernel[dim], - dilation[dim], - legacy_pad, - &pads[dim], - &pads[dims.size() + dim], - &dim_size); - output_dims.push_back(dim_size); - } - } - - } - - // ComputePads could be used in backward functions to figure out the padding - // values for the given input. - void ComputePads(const vector& dims) { - if (global_pooling_) { - kernel_ = dims; - } else if (legacy_pad_ != LegacyPadding::NOTSET) { - int output_unused; - for (int dim = 0; dim < dims.size(); ++dim) { - ComputeSizeAndPad( - dims[dim], - stride_[dim], - kernel_[dim], - dilation_[dim], - legacy_pad_, - &pads_[dim], - &pads_[dims.size() + dim], - &output_unused); - } - } - } - - bool RunOnDevice() override { - if (!global_pooling_) { - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE_GT(kernel_[dim], 0); - } - } - switch (order_) { - case StorageOrder::NHWC: - // VLOG(2) << "Running NHWC"; - return RunOnDeviceWithOrderNHWC(); - case StorageOrder::NCHW: - // VLOG(2) << "Running NCHW"; - return RunOnDeviceWithOrderNCHW(); - default: - CAFFE_THROW("Unknown Storage order: ", order_); - } - } - - // The actual function that does the computation, if the different - // storage order leads to different implementations. - virtual bool RunOnDeviceWithOrderNHWC() { - CAFFE_NOT_IMPLEMENTED; - } - virtual bool RunOnDeviceWithOrderNCHW() { - CAFFE_NOT_IMPLEMENTED; - } - - static struct OpSchema::Cost CostInferenceForConv( - const OperatorDef& def, - const vector& inputs) { - struct OpSchema::Cost c; - const TensorShape X = inputs[0]; - const TensorShape W = inputs[1]; - - ArgumentHelper helper(def); - const auto order = - StringToStorageOrder(helper.GetSingleArgument("order", "NCHW")); - - unsigned long long X_h; - unsigned long long X_w; - unsigned long long kernel_h; - unsigned long long kernel_w; - unsigned long long in_channels; - unsigned long long out_channels; - if (order == StorageOrder::NHWC) { - X_h = X.dims(1); - X_w = X.dims(2); - kernel_h = W.dims(1); - kernel_w = W.dims(2); - in_channels = W.dims(3); - out_channels = W.dims(0); - } else { - X_h = X.dims(2); - X_w = X.dims(3); - kernel_h = W.dims(2); - kernel_w = W.dims(3); - in_channels = W.dims(1); - out_channels = W.dims(0); - } - c.flops = (X_h - kernel_h + 1) * (X_w - kernel_w + 1) * kernel_w * - kernel_h * in_channels * out_channels * 2; - return c; - } - - static vector TensorInferenceForSchema( - const OperatorDef& def, - const vector& in, - int output_channel) { - ArgumentHelper helper(def); - CAFFE_ENFORCE_GT(in.size(), 0); - CAFFE_ENFORCE_GT(in[0].dims_size(), 0); - int N = in[0].dims(0); - bool channel_first; - - vector pads = helper.GetRepeatedArgument("pads"); - vector kernel = helper.GetRepeatedArgument("kernels"); - vector strides = helper.GetRepeatedArgument("strides"); - vector dilations = helper.GetRepeatedArgument("dilation"); - - if (helper.HasArgument("pad")) { - pads.resize(4, helper.GetSingleArgument("pad", 0)); - } else if ( - helper.HasArgument("pad_t") && helper.HasArgument("pad_l") && - helper.HasArgument("pad_b") && helper.HasArgument("pad_r")) { - pads.push_back(helper.GetSingleArgument("pad_t", 0)); - pads.push_back(helper.GetSingleArgument("pad_l", 0)); - pads.push_back(helper.GetSingleArgument("pad_b", 0)); - pads.push_back(helper.GetSingleArgument("pad_r", 0)); - } - - if (helper.HasArgument("kernel")) { - kernel.resize(2, helper.GetSingleArgument("kernel", 1)); - } else if ( - helper.HasArgument("kernel_h") && helper.HasArgument("kernel_w")) { - kernel.push_back(helper.GetSingleArgument("kernel_h", 1)); - kernel.push_back(helper.GetSingleArgument("kernel_w", 1)); - } - - if (helper.HasArgument("stride")) { - strides.resize(2, helper.GetSingleArgument("stride", 1)); - } else if ( - helper.HasArgument("stride_h") && helper.HasArgument("stride_w")) { - strides.push_back(helper.GetSingleArgument("stride_h", 1)); - strides.push_back(helper.GetSingleArgument("stride_w", 1)); - } - - if (helper.HasArgument("dilation")) { - strides.resize(2, helper.GetSingleArgument("dilation", 1)); - } else if ( - helper.HasArgument("dilation_h") && helper.HasArgument("dilation_w")) { - strides.push_back(helper.GetSingleArgument("dilation_h", 1)); - strides.push_back(helper.GetSingleArgument("dilation_w", 1)); - } - - auto check_and_set_default_value = []( - vector& vec, int size, int value) { - if (vec.size() == 0) { - vec.resize(size, value); - } - }; - - check_and_set_default_value(pads, 4, 0); - check_and_set_default_value(kernel, 2, 1); - check_and_set_default_value(strides, 2, 1); - check_and_set_default_value(dilations, 2, 1); - - vector output_dims; - ConvPoolOpBase::InferOutputSize( - GetDimsVector(in[0]), - output_channel, - StringToStorageOrder(helper.GetSingleArgument("order", "NCHW")), - helper.GetSingleArgument("global_pooling", 0), - static_cast( - helper.GetSingleArgument("legacy_pad", LegacyPadding::NOTSET)), - N, - kernel, - output_dims, - dilations, - strides, - pads, - channel_first); - vector out(1); - if (channel_first) { - output_dims.insert(output_dims.begin(), {N, output_channel}); - } else { - output_dims.push_back(output_channel); - output_dims.insert(output_dims.begin(), N); - } - - out[0] = CreateTensorShape(output_dims, TensorProto::FLOAT); - return out; - } - - static vector TensorInferenceForConv( - const OperatorDef& def, - const vector& in) { - return TensorInferenceForSchema(def, in, in[1].dims(0)); - } - - static vector TensorInferenceForPool( - const OperatorDef& def, - const vector& in) { - ArgumentHelper helper(def); - auto order = - StringToStorageOrder(helper.GetSingleArgument("order", "NCHW")); - int num_channels = - (order == StorageOrder::NCHW ? in[0].dims(1) : in[0].dims(3)); - return TensorInferenceForSchema(def, in, num_channels); - } - - virtual ~ConvPoolOpBase() {} - -protected: - LegacyPadding legacy_pad_; - bool global_pooling_; - vector kernel_; - vector dilation_; - vector stride_; - vector pads_; - - // We need the above parameters to be available for the devices. - Tensor kernel_device_; - Tensor dilation_device_; - Tensor stride_device_; - Tensor pads_device_; - - int group_; - StorageOrder order_; - bool shared_buffer_; - Workspace* ws_; - - static inline void ComputeSizeAndPad( - const int in_size, - const int stride, - const int kernel, - const int dilation, - LegacyPadding legacy_pad, - int* pad_head, - int* pad_tail, - int* out_size) { - const int dkernel = dilation * (kernel - 1) + 1; - switch (legacy_pad) { - case LegacyPadding::NOTSET: - // We will just use the direct padding head and tail values, but we - // will verify that they are non-negative. - CAFFE_ENFORCE_GE(in_size + *pad_head + *pad_tail, dkernel); - *out_size = static_cast( - static_cast(in_size + *pad_head + *pad_tail - dkernel) / - stride + - 1); - break; - case LegacyPadding::VALID: - *pad_head = 0; - *pad_tail = 0; - *out_size = (in_size - dkernel) / stride + 1; - break; - case LegacyPadding::SAME: { - CAFFE_ENFORCE( - 1 == dilation, "Dilation not supported for legacy padding."); - int legacy_target_size = (in_size + stride - 1) / stride; - int pad_needed = (legacy_target_size - 1) * stride + kernel - in_size; - if (CAFFE2_PAD_HEAD_MORE) { - *pad_head = (pad_needed + 1) / 2; - } else { - *pad_head = pad_needed / 2; - } - *pad_tail = pad_needed - *pad_head; - *out_size = (in_size + pad_needed - dkernel) / stride + 1; - break; - } - case LegacyPadding::CAFFE_LEGACY_POOLING: - // This is in order to adapt Caffe's pooling padding case. In this case, - // we will only use pad_head and will compute pad_tail to match the - // old caffe pooling strategy. Also see caffe2_legacy.proto for more - // details. - CAFFE_ENFORCE_GE(*pad_head, 0); - // Here, notice that caffe casts UP while caffe2 casts DOWN for the - // output size computation. - *out_size = std::ceil( - static_cast(in_size + *pad_head * 2 - kernel) / stride + 1); - // If we have padding, caffe also ensures that the last pooling starts - // strictly inside the image (instead of at the padding); otherwise clip - // the last. - if (*pad_head > 0 && (*out_size - 1) * stride >= in_size + *pad_head) { - --*out_size; - } - // Now, compare the output size with the standard Caffe2 output size. - // The - // caffe2 standard output size should always be no larger than the - // output - // size of caffe. - int standard_out_size = static_cast( - static_cast(in_size + *pad_head * 2 - kernel) / stride + 1); - CAFFE_ENFORCE_GE( - *out_size, - standard_out_size, - "This should never happen. If this happens, double check the logic " - "above."); - if (*out_size > standard_out_size) { - LOG(WARNING) - << "You are hitting a case where Caffe's legacy padding calculation " - "is hit. This leads to inefficient and sometimes incorrect " - "results. We are keeping this behavior for backward compatibility" - ", but you are strongly recommended to move away from it."; - } - *pad_tail = *pad_head + stride * (*out_size - standard_out_size); - break; - } - } - - // Accessors for 2D conv params. - - inline int pad_t() const { - return pads_[0]; - } - - inline int pad_l() const { - return pads_[1]; - } - - inline int pad_b() const { - return pads_[2]; - } - - inline int pad_r() const { - return pads_[3]; - } - - inline int kernel_h() const { - return kernel_[0]; - } - - inline int kernel_w() const { - return kernel_[1]; - } - - inline int stride_h() const { - return stride_[0]; - } - - inline int stride_w() const { - return stride_[1]; - } - - inline int dilation_h() const { - return dilation_[0]; - } - - inline int dilation_w() const { - return dilation_[1]; - } - - private: - inline void AllocateAndCopy(const vector& vec, Tensor& tensor) { - tensor.Resize(vec.size()); - context_.template Copy( - vec.size(), vec.data(), tensor.template mutable_data()); - } - -#define USE_CONV_POOL_BASE_FUNCTIONS(Context) \ - USE_OPERATOR_FUNCTIONS(Context); \ - using ConvPoolOpBase::pads_; \ - using ConvPoolOpBase::pads_device_; \ - using ConvPoolOpBase::pad_t; \ - using ConvPoolOpBase::pad_l; \ - using ConvPoolOpBase::pad_b; \ - using ConvPoolOpBase::pad_r; \ - using ConvPoolOpBase::legacy_pad_; \ - using ConvPoolOpBase::global_pooling_; \ - using ConvPoolOpBase::kernel_; \ - using ConvPoolOpBase::kernel_device_; \ - using ConvPoolOpBase::kernel_h; \ - using ConvPoolOpBase::kernel_w; \ - using ConvPoolOpBase::dilation_; \ - using ConvPoolOpBase::dilation_device_; \ - using ConvPoolOpBase::dilation_h; \ - using ConvPoolOpBase::dilation_w; \ - using ConvPoolOpBase::stride_; \ - using ConvPoolOpBase::stride_device_; \ - using ConvPoolOpBase::stride_h; \ - using ConvPoolOpBase::stride_w; \ - using ConvPoolOpBase::group_; \ - using ConvPoolOpBase::order_; \ - using ConvPoolOpBase::shared_buffer_; \ - using ConvPoolOpBase::GetDims; \ - using ConvPoolOpBase::GetDimsSize; \ - using ConvPoolOpBase::ws_ -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_POOL_OP_BASE_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_transpose_op.h b/app/src/main/cpp/caffe2/operators/conv_transpose_op.h deleted file mode 100644 index 6dcdbb8..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_transpose_op.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_ -#define CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_transpose_unpool_op_base.h" - -namespace caffe2 { - -template -class ConvTransposeOp final : public ConvTransposeUnpoolBase { - public: - USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context); - ConvTransposeOp(const OperatorDef& operator_def, Workspace* ws) - : ConvTransposeUnpoolBase(operator_def, ws) {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - Tensor col_buffer_; - Tensor bias_multiplier_; - // Input: X, W, b - // Output: Y - INPUT_TAGS(INPUT, FILTER, BIAS); -}; - -template -class ConvTransposeGradientOp final : public ConvTransposeUnpoolBase { - public: - USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context); - ConvTransposeGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvTransposeUnpoolBase(operator_def, ws), - no_bias_(OperatorBase::GetSingleArgument("no_bias", false)) { - CAFFE_ENFORCE( - !(no_bias_ && OutputSize() == 3), - "If bias is not present, you should not have 3 grad output."); - } - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - Tensor col_buffer_; - Tensor bias_multiplier_; - const bool no_bias_; - // input: X, W, dY - // output: dW, optionally db and dX - INPUT_TAGS(INPUT, FILTER, OUTPUT_GRAD); - OUTPUT_TAGS(FILTER_GRAD, BIAS_OR_INPUT_GRAD, INPUT_GRAD); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_transpose_op_impl.h b/app/src/main/cpp/caffe2/operators/conv_transpose_op_impl.h deleted file mode 100644 index e12c328..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_transpose_op_impl.h +++ /dev/null @@ -1,554 +0,0 @@ -// conv_transpose_op_impl.h is the templated implementation of the -// conv_transpose_op.h file. -#ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_IMPL_H_ -#define CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_IMPL_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_op_shared.h" -#include "caffe2/operators/conv_transpose_op.h" -#include "caffe2/operators/conv_transpose_unpool_op_base.h" -#include "caffe2/utils/math.h" - -CAFFE2_DECLARE_bool(caffe2_force_shared_col_buffer); - -namespace caffe2 { - -template -bool ConvTransposeOp::RunOnDeviceWithOrderNCHW() { - const Tensor& X = Input(INPUT); - auto& filter = Input(FILTER); - Tensor* Y = Output(0); - const int N = X.dim32(0), M = X.dim32(1), H = X.dim32(2), W = X.dim32(3); - CAFFE_ENFORCE(filter.ndim() == 4, "filter must be 4D tensor"); - CAFFE_ENFORCE( - filter.dim32(0) == M, - "filter number must be equal to input channel number"); - const int C = filter.dim32(1); - CAFFE_ENFORCE( - filter.dim32(2) == this->kernel_h(), - "filter height must be equal to kernel height"); - CAFFE_ENFORCE( - filter.dim32(3) == this->kernel_w(), - "filter width must be equal to kernel width"); - ConvTransposeUnpoolBase::SetOutputSize(X, Y, C); - - const int kernel_dim = C * this->kernel_h() * this->kernel_w(); - const int input_image_size = H * W; - const int output_image_size = Y->dim32(2) * Y->dim32(3); - -#ifndef __ARM_NEON__ - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(bias.ndim() == 1, "bias must be 1D tensor"); - CAFFE_ENFORCE( - bias.dim32(0) == C, - "bias dimension must be equal to output channel number"); - if (bias_multiplier_.size() != output_image_size) { - bias_multiplier_.Resize(vector(1, output_image_size)); - T* bm_data = bias_multiplier_.template mutable_data(); - math::Set( - output_image_size, - static_cast(1), - bm_data, - &context_); - } - } -#endif // !__ARM_NEON__ - - const T* Xdata = X.template data(); - const T* filter_data = filter.template data(); - T* Ydata = Y->template mutable_data(); - - auto f = [&](Tensor* col_buffer) { - col_buffer->Resize( - vector{C, this->kernel_h(), this->kernel_w(), H, W}); - T* col_buffer_data = col_buffer->template mutable_data(); - for (auto image_id = 0; image_id < N; ++image_id) { - // Weight term - math::Gemm( - CblasTrans, - CblasNoTrans, - kernel_dim, - input_image_size, - M, - 1, - filter_data, - Xdata, - 0, - col_buffer_data, - &context_); - - // Col2im - math::Col2im( - col_buffer_data, - C, - Y->dim32(2), - Y->dim32(3), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - Ydata, - &context_); - - // Bias term - if (InputSize() == 3) { - const T* bias_data = Input(BIAS).template data(); -#ifndef __ARM_NEON__ - const T* bm_data = bias_multiplier_.template data(); - math::Gemm( - CblasNoTrans, - CblasNoTrans, - C, - output_image_size, - 1, - 1, - bias_data, - bm_data, - 1, - Ydata, - &context_); -#else - math::BiasCHW( - bias_data, - C, - output_image_size, - Ydata, - &context_); -#endif // !__ARM_NEON__ - } - - Xdata += M * H * W; - Ydata += Y->size() / Y->dim32(0); - } - }; - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - runWithSharedBuffer(ws_, f); - } else { - f(&col_buffer_); - } - return true; -} - -template -bool ConvTransposeOp::RunOnDeviceWithOrderNHWC() { - const Tensor& X = Input(INPUT); - auto& filter = Input(FILTER); - Tensor* Y = Output(0); - const auto N = X.dim32(0), H = X.dim32(1), W = X.dim32(2), M = X.dim32(3); - CAFFE_ENFORCE(filter.ndim() == 4, "filter must be 4D tensor"); - CAFFE_ENFORCE( - filter.dim32(0) == M, - "filter number must be equal to input channel number"); - CAFFE_ENFORCE( - filter.dim32(1) == this->kernel_h(), - "filter height must be equal to kernel height"); - CAFFE_ENFORCE( - filter.dim32(2) == this->kernel_w(), - "filter width must be equal to kernel width"); - const int C = filter.dim32(3); - ConvTransposeUnpoolBase::SetOutputSize(X, Y, C); - - const auto kernel_dim = C * this->kernel_h() * this->kernel_w(); - const auto input_image_size = H * W; - const auto output_image_size = Y->dim32(1) * Y->dim32(2); - - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(bias.ndim() == 1, "bias must be 1D tensor"); - CAFFE_ENFORCE( - bias.dim32(0) == C, - "bias dimension must be equal to output channel number"); - if (bias_multiplier_.size() != output_image_size) { - bias_multiplier_.Resize(vector(1, output_image_size)); - T* bm_data = bias_multiplier_.template mutable_data(); - math::Set( - output_image_size, - static_cast(1), - bm_data, - &context_); - } - } - const T* Xdata = X.template data(); - const T* filter_data = filter.template data(); - T* Ydata = Y->template mutable_data(); - - auto f = [&](Tensor* /*col_buffer*/) { - col_buffer_.Resize( - vector{H, W, this->kernel_h(), this->kernel_w(), C}); - T* col_buffer_data = col_buffer_.template mutable_data(); - for (auto image_id = 0; image_id < N; ++image_id) { - // Weight term - math::Gemm( - CblasNoTrans, - CblasNoTrans, - input_image_size, - kernel_dim, - M, - 1, - Xdata, - filter_data, - 0, - col_buffer_data, - &context_); - // Col2im - math::Col2im( - col_buffer_data, - C, - Y->dim32(1), - Y->dim32(2), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - Ydata, - &context_); - // Bias term - if (InputSize() == 3) { - const T* bm_data = bias_multiplier_.template data(); - const T* bias_data = Input(BIAS).template data(); - math::Gemm( - CblasNoTrans, - CblasNoTrans, - output_image_size, - C, - 1, - 1, - bm_data, - bias_data, - 1, - Ydata, - &context_); - } - Xdata += M * H * W; - Ydata += Y->size() / Y->dim32(0); - } - }; - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - runWithSharedBuffer(ws_, f); - } else { - f(&col_buffer_); - } - return true; -} - -template -bool ConvTransposeGradientOp::RunOnDeviceWithOrderNCHW() { - auto& X = Input(INPUT); - auto& filter = Input(FILTER); - auto& dY = Input(OUTPUT_GRAD); - auto* dfilter = Output(FILTER_GRAD); - const int N = X.dim32(0), M = X.dim32(1), H = X.dim32(2), W = X.dim32(3); - // We only handle LegacyPadding::NOTSET case and ignore cases of - // LegacyPadding::VALID and LegacyPadding::SAME - // Thus, we don't need to manually compute padding values - // We simply use the values from the user - CAFFE_ENFORCE(filter.ndim() == 4); - const int C = filter.dim32(1); - CAFFE_ENFORCE( - filter.dim32(2) == this->kernel_h(), - "filter height must be equal to kernel height"); - CAFFE_ENFORCE( - filter.dim32(3) == this->kernel_w(), - "filter width must be equal to kernel width"); - dfilter->ResizeLike(filter); - - const int kernel_dim = C * this->kernel_h() * this->kernel_w(); - const int output_image_size = dY.dim32(2) * dY.dim32(3); - // The col buffer is stored in CHW order as well - col_buffer_.Resize( - vector{C, this->kernel_h(), this->kernel_w(), H, W}); - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - dbias->Resize(C); - if (bias_multiplier_.size() != output_image_size) { - bias_multiplier_.Resize(1, output_image_size); - T* bm_data = bias_multiplier_.template mutable_data(); - math::Set( - output_image_size, - static_cast(1), - bm_data, - &context_); - } - } - T* col_buffer_data = col_buffer_.template mutable_data(); - const T* Xdata = X.template data(); - const T* filter_data = filter.template data(); - const T* dYdata = dY.template data(); - T* dfilter_data = dfilter->template mutable_data(); - // Pre-setting the gradients to zero - math::Set(dfilter->size(), 0, dfilter_data, &context_); - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - T* dbias_data = dbias->template mutable_data(); - math::Set(dbias->size(), 0, dbias_data, &context_); - } - for (auto image_id = 0; image_id < N; ++image_id) { - // gradient w.r.t. filters. Im2col followed by Gemm - // Im2col. - math::Im2col( - dYdata, - C, - dY.dim32(2), - dY.dim32(3), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - col_buffer_data, - &context_); - // Gemm - math::Gemm( - CblasNoTrans, - CblasTrans, - M, - kernel_dim, - H * W, - 1, - Xdata, - col_buffer_data, - 1, - dfilter_data, - &context_); - // gradient w.r.t. bias - if (!no_bias_) { - const T* bm_data = bias_multiplier_.template data(); - T* input_grad_data = Output(BIAS_OR_INPUT_GRAD)->template mutable_data(); - math::Gemm( - CblasNoTrans, - CblasNoTrans, - C, - 1, - output_image_size, - 1, - dYdata, - bm_data, - 1, - input_grad_data, - &context_); - } - dYdata += dY.size() / dY.dim32(0); - Xdata += X.size() / X.dim32(0); - } - if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) { - // Compute gradients w.r.t. the input - // Since we have changed dYdata in the above loop, we will need to reset. - dYdata = dY.template data(); - auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD); - dX->ResizeLike(X); - T* dXdata = dX->template mutable_data(); - for (auto image_id = 0; image_id < N; ++image_id) { - // Im2col. - // TODO(zyan3): Probably duplicate work as in gradient computation - // w.r.t filters - math::Im2col( - dYdata, - C, - dY.dim32(2), - dY.dim32(3), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - col_buffer_data, - &context_); - // Gemm - math::Gemm( - CblasNoTrans, - CblasNoTrans, - M, - H * W, - kernel_dim, - 1, - filter_data, - col_buffer_data, - 0, - dXdata, - &context_); - dYdata += dY.size() / dY.dim32(0); - dXdata += X.size() / X.dim32(0); - } - } - return true; -} - -template -bool ConvTransposeGradientOp::RunOnDeviceWithOrderNHWC() { - auto& X = Input(INPUT); - auto& filter = Input(FILTER); - auto& dY = Input(OUTPUT_GRAD); - auto* dfilter = Output(FILTER_GRAD); - const int N = X.dim32(0), H = X.dim32(1), W = X.dim32(2), M = X.dim32(3); - // We only handle LegacyPadding::NOTSET case and ignore cases of - // LegacyPadding::VALID and LegacyPadding::SAME - // Thus, we don't need to manually compute padding values - // We simply use the values from the user - CAFFE_ENFORCE(filter.ndim() == 4, "filter must be 4D tensor"); - CAFFE_ENFORCE( - filter.dim32(1) == this->kernel_h(), - "filter height must be equal to kernel height"); - CAFFE_ENFORCE( - filter.dim32(2) == this->kernel_w(), - "filter width must be equal to kernel width"); - const int C = filter.dim32(3); - dfilter->ResizeLike(filter); - - const int kernel_dim = C * this->kernel_h() * this->kernel_w(); - const int output_image_size = dY.dim32(1) * dY.dim32(2); - // The col buffer is stored in HWC order as well - col_buffer_.Resize( - vector{H, W, this->kernel_h(), this->kernel_w(), C}); - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - dbias->Resize(C); - if (bias_multiplier_.size() != output_image_size) { - bias_multiplier_.Resize(1, output_image_size); - T* bm_data = bias_multiplier_.template mutable_data(); - math::Set( - output_image_size, - static_cast(1), - bm_data, - &context_); - } - } - T* col_buffer_data = col_buffer_.template mutable_data(); - const T* Xdata = X.template data(); - const T* filter_data = filter.template data(); - const T* dYdata = dY.template data(); - T* dfilter_data = dfilter->template mutable_data(); - // Pre-setting the gradients to zero - math::Set(dfilter->size(), 0, dfilter_data, &context_); - if (!no_bias_) { - auto* dbias = Output(BIAS_OR_INPUT_GRAD); - T* dbias_data = dbias->template mutable_data(); - math::Set(dbias->size(), 0, dbias_data, &context_); - } - for (auto image_id = 0; image_id < N; ++image_id) { - // gradient w.r.t. filters. Im2col followed by Gemm - // Im2col. - math::Im2col( - dYdata, - C, - dY.dim32(1), - dY.dim32(2), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - col_buffer_data, - &context_); - // Gemm - math::Gemm( - CblasTrans, - CblasNoTrans, - M, - kernel_dim, - H * W, - 1, - Xdata, - col_buffer_data, - 1, - dfilter_data, - &context_); - // gradients w.r.t. bias - if (!no_bias_) { - const T* bm_data = bias_multiplier_.template data(); - T* input_grad_data = Output(BIAS_OR_INPUT_GRAD)->template mutable_data(); - math::Gemm( - CblasTrans, - CblasNoTrans, - C, - 1, - output_image_size, - 1, - dYdata, - bm_data, - 1, - input_grad_data, - &context_); - } - dYdata += dY.size() / dY.dim32(0); - Xdata += X.size() / X.dim32(0); - } - if (OutputSize() == 3 || (no_bias_ && (OutputSize() == 2))) { - // Compute gradients w.r.t. the input - // Since we have changed dYdata in the above loop, we will need to reset. - dYdata = dY.template data(); - auto* dX = Output(no_bias_ ? BIAS_OR_INPUT_GRAD : INPUT_GRAD); - dX->ResizeLike(X); - T* dXdata = dX->template mutable_data(); - for (auto image_id = 0; image_id < N; ++image_id) { - // Im2col. - // TODO(zyan3): Probably duplicate work as in gradient computation - // w.r.t filters - math::Im2col( - dYdata, - C, - dY.dim32(1), - dY.dim32(2), - this->kernel_h(), - this->kernel_w(), - 1, - 1, - this->pad_t(), - this->pad_l(), - this->pad_b(), - this->pad_r(), - this->stride_h(), - this->stride_w(), - col_buffer_data, - &context_); - // Gemm - math::Gemm( - CblasNoTrans, - CblasTrans, - H * W, - M, - kernel_dim, - 1, - col_buffer_data, - filter_data, - 0, - dXdata, - &context_); - dYdata += dY.size() / dY.dim32(0); - dXdata += X.size() / X.dim32(0); - } - } - return true; -} - -} // namespace caffe2 -#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_OP_IMPL_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile.h b/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile.h deleted file mode 100644 index ddfe365..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_ -#define CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_ - -#include "caffe2/core/common.h" - -#ifndef CAFFE2_MOBILE -#error "mobile build state not defined" -#endif - -#if CAFFE2_MOBILE - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_transpose_unpool_op_base.h" - -namespace caffe2 { - -template -class ConvTransposeMobileOp final : public ConvTransposeUnpoolBase { - public: - USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context); - ConvTransposeMobileOp(const OperatorDef& operator_def, Workspace* ws) - : ConvTransposeUnpoolBase(operator_def, ws) { - OPERATOR_NEEDS_FEATURE(order_ == StorageOrder::NCHW, "Only NCHW order is supported right now."); - OPERATOR_NEEDS_FEATURE( - this->pad_l() == 0, "operator does not handle row width padding"); - OPERATOR_NEEDS_FEATURE( - this->pad_r() == 0, "operator does not handle row width padding"); - OPERATOR_NEEDS_FEATURE(this->stride_w() <= 4, "stride width must be <= 4"); - } - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - // We store a numThreasds per-worker tiles of Y, and numThreads per-worker threadBuffer for the - // gemm output, laid out in that order. - TensorCPU threadBuffer_; - - // Input: X, W, b - // Output: Y - INPUT_TAGS(INPUT, FILTER, BIAS); -}; - -} // namespace caffe2 - -#endif // CAFFE2_MOBILE - -#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile_impl.h b/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile_impl.h deleted file mode 100644 index 2514fd1..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_transpose_op_mobile_impl.h +++ /dev/null @@ -1,698 +0,0 @@ -// conv_transpose_op_impl.h is the templated implementation of the -// conv_transpose_op.h file. -#ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_ -#define CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_ - -#include "caffe2/core/common.h" - -#ifndef CAFFE2_MOBILE -#error "mobile build state not defined" -#endif - -#if CAFFE2_MOBILE - -#include "caffe2/core/logging.h" -#include "caffe2/operators/conv_op_shared.h" -#include "caffe2/operators/conv_transpose_op_mobile.h" -#include "caffe2/utils/cpu_neon.h" -#include "caffe2/utils/fixed_divisor.h" -#include "caffe2/utils/math.h" - -CAFFE2_DECLARE_bool(caffe2_force_shared_col_buffer); - -namespace caffe2 { - -template -void runTileContiguous( - int tileId, - int N, - int M, - int H, - int W, - int outputH, - int outputW, - int C, - int kernelH, - int kernelW, - int strideH, - int strideW, - int padT, - const T* filterData, - const T* Xdata, - T* colBufferData, - T* Ydata, - Context* context) { - // The tile size is exactly the length of a single row - int tileSize = W; - - auto kernelDataSize = C * kernelH * kernelW; - auto currentTileStart = tileSize * tileId; - - // gemm tile - math::GemmEx( - CblasTrans, - CblasNoTrans, - kernelDataSize, - tileSize, - M, - 1, - filterData, - kernelDataSize, - Xdata + currentTileStart, - H * W, - 0, - colBufferData, - tileSize, - context); - - // col2im tile - // We assume that there is no padding in the columns (padL and padR - // == 0). - // FIXME: it is actually possible for us to handle padding, figure - // out how to adjust the bounds - - // We write into Y in a de-interleaved fashion; in other words, - // every column (mod strideW) == 0 together in one block, - // every column (mod strideW) == 1 in another, - // ... and so on. - int colBlockSize = (W + kernelW / strideW); - int numColBlocks = strideW; - - for (int c = 0; c < kernelDataSize; ++c) { - int w_offset = c % kernelW; - int h_offset = (c / kernelW) % kernelH; - int c_im = c / kernelH / kernelW; - - // Each row is a separate tile that we handle. First determine the - // row into which we are writing the output. - // We can properly handle padding for the rows. - int rowY = tileId * strideH - padT + h_offset; - - // If this row is out of bounds, then skip it - if (!math::is_a_ge_zero_and_a_lt_b(rowY, outputH)) { - continue; - } - - // FIXME: we don't actually handle a dynamic padL > 0 - constexpr int kPadL = 0; - int colOffsetStart = -kPadL + w_offset; - int colBlockY = colOffsetStart % strideW; - - // However, within a block we may not start writing at offset - // 0. The offset at which we begin writing is determined by - // colOffsetStart - int colWithinBlockOffsetY = colOffsetStart / strideW; - - // So, this is where we begin reading/writing in Y - int colY = colBlockY * colBlockSize + colWithinBlockOffsetY; - - // This is the complete offset into Y from the start - // Each row has strideW blocks of size colBlockSize - int offsetY = rowY * colBlockSize * numColBlocks + colY; - - T* colBufferPointer = colBufferData + c * tileSize; - T* yPointer = - Ydata + c_im * outputH * (colBlockSize * numColBlocks) + offsetY; - - int b = 0; -#ifdef __ARM_NEON__ - // We vectorize the loop within the row - { - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)) * 4; - int limit = (tileSize / kUnroll) * kUnroll; - - for (; b < limit; b += kUnroll) { - float32x4_t cb0 = vld1q_f32(colBufferPointer + 0); - float32x4_t cb1 = vld1q_f32(colBufferPointer + 4); - float32x4_t cb2 = vld1q_f32(colBufferPointer + 8); - float32x4_t cb3 = vld1q_f32(colBufferPointer + 12); - - float32x4_t y0 = vld1q_f32(yPointer + 0); - float32x4_t y1 = vld1q_f32(yPointer + 4); - float32x4_t y2 = vld1q_f32(yPointer + 8); - float32x4_t y3 = vld1q_f32(yPointer + 12); - - y0 = vaddq_f32(y0, cb0); - y1 = vaddq_f32(y1, cb1); - y2 = vaddq_f32(y2, cb2); - y3 = vaddq_f32(y3, cb3); - - vst1q_f32(yPointer + 0, y0); - vst1q_f32(yPointer + 4, y1); - vst1q_f32(yPointer + 8, y2); - vst1q_f32(yPointer + 12, y3); - - colBufferPointer += kUnroll; - yPointer += kUnroll; - } - } - - { - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)); - int limit = (tileSize / kUnroll) * kUnroll; - - for (; b < limit; b += kUnroll) { - float32x4_t cb0 = vld1q_f32(colBufferPointer); - float32x4_t y0 = vld1q_f32(yPointer); - - y0 = vaddq_f32(y0, cb0); - - vst1q_f32(yPointer, y0); - - colBufferPointer += kUnroll; - yPointer += kUnroll; - } - } -#endif - - // Handle un-vectorizable epilogue - for (; b < tileSize; ++b) { - *yPointer += *colBufferPointer; - ++yPointer; - ++colBufferPointer; - } - } -} - -template -struct StoreInterleaved {}; - -template <> -struct StoreInterleaved { -#ifdef __ARM_NEON__ - inline static void store(float* p, float32x4_t v[1]) { - vst1q_f32(p, v[0]); - } -#endif - - inline static void store(float* p, float v[1]) { - p[0] = v[0]; - } -}; - -template <> -struct StoreInterleaved { -#ifdef __ARM_NEON__ - inline static void store(float* p, float32x4_t v[2]) { - float32x4x2_t x = {{v[0], v[1]}}; - vst2q_f32(p, x); - } -#endif - - inline static void store(float* p, float v[2]) { - p[0] = v[0]; - p[1] = v[1]; - } -}; - -template <> -struct StoreInterleaved { -#ifdef __ARM_NEON__ - inline static void store(float* p, float32x4_t v[3]) { - float32x4x3_t x = {{v[0], v[1], v[2]}}; - vst3q_f32(p, x); - } -#endif - - inline static void store(float* p, float v[3]) { - p[0] = v[0]; - p[1] = v[1]; - p[2] = v[2]; - } -}; - -template <> -struct StoreInterleaved { -#ifdef __ARM_NEON__ - inline static void store(float* p, float32x4_t v[4]) { - float32x4x4_t x = {{v[0], v[1], v[2], v[3]}}; - vst4q_f32(p, x); - } -#endif - - inline static void store(float* p, float v[4]) { - p[0] = v[0]; - p[1] = v[1]; - p[2] = v[2]; - p[3] = v[3]; - } -}; - -template -void reinterleaveRows( - const float* src, - const float* bias, - int c, - int h, - float* dst, - int outputC, - int outputH, - int outputW, - int inputW, - int kernelW, - int strideW, - int adjH) { - // Each row in src is of the form: - // [w mod strideW == 0 elements]...[w mod strideW == strideW - 1 - // elements] - // We need to re-interleave the values and write them in the output - int colBlockSize = inputW + kernelW / kStrideW; - int noAdjOutputW = (inputW - 1) * kStrideW + kernelW; - - int point = c * outputH + h; - src += point * colBlockSize * kStrideW; - dst += point * outputW; - - float b = bias ? bias[c] : 0; -#ifdef __ARM_NEON__ - float32x4_t biasV = vdupq_n_f32(b); -#endif - - int w = 0; -#ifdef __ARM_NEON__ - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)) * 2; - int limit = ((inputW - 1) / kUnroll) * kUnroll; - - for (; w < limit; w += kUnroll) { - // We need to interleave in terms of kStrideW units - float32x4_t v0[kStrideW]; - float32x4_t v1[kStrideW]; - - for (int i = 0; i < kStrideW; ++i) { - v0[i] = vld1q_f32(src + i * colBlockSize); - v1[i] = vld1q_f32(src + i * colBlockSize + 4); - } - - // add per-channel bias - for (int i = 0; i < kStrideW; ++i) { - v0[i] = vaddq_f32(v0[i], biasV); - v1[i] = vaddq_f32(v1[i], biasV); - } - - // Write interleaved into the output - StoreInterleaved::store(dst + 0 * kStrideW, v0); - StoreInterleaved::store(dst + 4 * kStrideW, v1); - - src += kUnroll; - dst += kUnroll * kStrideW; - } -#endif - - // Handle non-vectorizable remainder - for (; w < inputW - 1; ++w) { - float v[kStrideW]; - - for (int i = 0; i < kStrideW; ++i) { - v[i] = src[i * colBlockSize]; - } - - // add per-channel bias - for (int i = 0; i < kStrideW; ++i) { - v[i] += b; - } - - // Write interleaved into the output - StoreInterleaved::store(dst, v); - - src += 1; - dst += kStrideW; - } - - // We have handled 0 .. (inputW - 1) * stride inclusive so far. - // Handle the remainder - int outputPoint = (inputW - 1) * kStrideW; - int block = 0; - - // Output width may include adjustment into which we don't - // write; ignore it - while (outputPoint < noAdjOutputW) { - float v = src[block * colBlockSize]; - dst[0] = v + b; - ++outputPoint; - dst += 1; - - ++block; - if (block >= kStrideW) { - block = 0; - src += 1; - } - } - - // Remainder of the buffer comprised of just the `adj` must have - // bias added - for (; outputPoint < outputW; ++outputPoint) { - dst[0] = b; - dst += 1; - } -} - -template -void reinterleaveMultithreaded( - const T* y0, - const T* bias_data, - T* y, - int outputC, - int outputH, - int outputW, - int inputW, - int kernelW, - int strideW, - int adjH, - ThreadPool* pool) { - // # channels times height - size_t totalTiles = (size_t)outputC * outputH; - FixedDivisor divOutputH(outputH); - -#define REINTERLEAVE(N) \ - do { \ - reinterleaveRows( \ - y0, \ - bias_data, \ - c, \ - h, \ - y, \ - outputC, \ - outputH, \ - outputW, \ - inputW, \ - kernelW, \ - strideW, \ - adjH); \ - } while (false) - - std::function fnReinterleave = [&](int threadId, - size_t tileId) { - int h; - int c; - divOutputH.divMod((int)tileId, c, h); - - REINTERLEAVE(N); - }; - -#undef REINTERLEAVE - - pool->run(fnReinterleave, totalTiles); -} - -#ifdef __ARM_NEON__ -template -struct SumMultiple { - static void sumInto(float* acc, float** toSum, size_t size); -}; - -template <> -struct SumMultiple<1> { - static void sumInto(float* acc, float** toSum, size_t size) { - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)); - int limit = (size / kUnroll) * kUnroll; - - auto toSum0 = toSum[0]; - - size_t i = 0; - for (; i < limit; i += kUnroll) { - float32x4_t v0 = vld1q_f32_aligned(acc + i); - float32x4_t v1 = vld1q_f32_aligned(toSum0 + i); - - v0 = vaddq_f32(v0, v1); - - vst1q_f32_aligned(acc + i, v0); - } - - for (; i < size; ++i) { - float v0 = acc[i]; - float v1 = toSum0[i]; - - v0 += v1; - - acc[i] = v0; - } - } -}; - -template <> -struct SumMultiple<2> { - static void sumInto(float* acc, float** toSum, size_t size) { - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)); - int limit = (size / kUnroll) * kUnroll; - - auto toSum0 = toSum[0]; - auto toSum1 = toSum[1]; - - size_t i = 0; - for (; i < limit; i += kUnroll) { - float32x4_t v0 = vld1q_f32_aligned(acc + i); - float32x4_t v1 = vld1q_f32_aligned(toSum0 + i); - float32x4_t v2 = vld1q_f32_aligned(toSum1 + i); - - v0 = vaddq_f32(v0, v1); - v0 = vaddq_f32(v0, v2); - - vst1q_f32_aligned(acc + i, v0); - } - - for (; i < size; ++i) { - float v0 = acc[i]; - float v1 = toSum0[i]; - float v2 = toSum1[i]; - - v0 += v1; - v0 += v2; - - acc[i] = v0; - } - } -}; - -template <> -struct SumMultiple<3> { - static void sumInto(float* acc, float** toSum, size_t size) { - constexpr int kUnroll = (sizeof(float32x4_t) / sizeof(float)); - int limit = (size / kUnroll) * kUnroll; - - auto toSum0 = toSum[0]; - auto toSum1 = toSum[1]; - auto toSum2 = toSum[2]; - - size_t i = 0; - for (; i < limit; i += kUnroll) { - float32x4_t v0 = vld1q_f32_aligned(acc + i); - float32x4_t v1 = vld1q_f32_aligned(toSum0 + i); - float32x4_t v2 = vld1q_f32_aligned(toSum1 + i); - float32x4_t v3 = vld1q_f32_aligned(toSum2 + i); - - v0 = vaddq_f32(v0, v1); - v2 = vaddq_f32(v2, v3); - v0 = vaddq_f32(v0, v2); - - vst1q_f32_aligned(acc + i, v0); - } - - for (; i < size; ++i) { - float v0 = acc[i]; - float v1 = toSum0[i]; - float v2 = toSum1[i]; - float v3 = toSum2[i]; - - v0 += v1; - v2 += v3; - v0 += v2; - - acc[i] = v0; - } - } -}; -#endif - -// Performs acc[i] += sum_j toSum_j[i] pointwise -void sumInto(float* acc, std::vector& toSum, size_t size) { -#ifdef __ARM_NEON__ - if (toSum.size() == 1) { - SumMultiple<1>::sumInto(acc, toSum.data(), size); - return; - } else if (toSum.size() == 2) { - SumMultiple<2>::sumInto(acc, toSum.data(), size); - return; - } else if (toSum.size() == 3) { - SumMultiple<3>::sumInto(acc, toSum.data(), size); - return; - } -#endif - - // Otherwise, use fallback implementation - EigenVectorArrayMap accT(acc, size); - - for (auto p : toSum) { - accT += ConstEigenVectorArrayMap(p, size); - } -} - -template -bool ConvTransposeMobileOp::RunOnDeviceWithOrderNCHW() { - const Tensor& X = Input(INPUT); - auto& filter = Input(FILTER); - Tensor* Y = Output(0); - const int N = X.dim32(0), M = X.dim32(1), H = X.dim32(2), W = X.dim32(3); - CAFFE_ENFORCE(filter.ndim() == 4, "filter must be 4D tensor"); - CAFFE_ENFORCE( - filter.dim32(0) == M, - "filter number must be equal to input channel number"); - const int C = filter.dim32(1); - CAFFE_ENFORCE( - filter.dim32(2) == this->kernel_h(), - "filter height must be equal to kernel height"); - CAFFE_ENFORCE( - filter.dim32(3) == this->kernel_w(), - "filter width must be equal to kernel width"); - if (InputSize() == 3) { - auto& bias = Input(BIAS); - CAFFE_ENFORCE(bias.ndim() == 1, "bias must be 1D tensor"); - CAFFE_ENFORCE( - bias.dim32(0) == C, - "bias dimension must be equal to output channel number"); - } - - ConvTransposeUnpoolBase::SetOutputSize(X, Y, C); - - const int outputH = Y->dim32(2); - const int outputW = Y->dim32(3); - const int outputPlaneSize = outputH * outputW; - const int outputBatchElementSize = Y->dim32(1) * outputPlaneSize; - - auto Xdata = X.template data(); - auto Ydata = Y->template mutable_data(); - - auto pool = ws_->GetThreadPool(); - auto numThreads = pool->getNumThreads(); - - // Initialize per-thread buffers for output - // The main thread will write directly into the output Y, we just - // need buffers for the worker threads - size_t colBlockSize = W + this->kernel_w() / this->stride_w(); - size_t threadYBufferSize = C * outputH * colBlockSize * this->stride_w(); - // Require 16 byte alignment, so 4-element alignment as these are floats. - size_t threadYBufferSizeAligned = - ((C * outputH * colBlockSize * this->stride_w() + 3) / 4) * 4; - size_t threadColBufferSize = C * this->kernel_h() * this->kernel_w() * W; - - // Work around GCC 4.9 bug when this is declared inside the inner lambda. - auto runLocalTile = [&](TensorCPU* threadBuffer, - int threadId, - size_t tileId) { - auto localYData = threadBuffer->template mutable_data() + - threadId * threadYBufferSizeAligned; - - auto localColBufferData = threadBuffer->template mutable_data() + - numThreads * threadYBufferSizeAligned + threadId * threadColBufferSize; - - runTileContiguous( - tileId, - N, - M, - H, - W, - outputH, - outputW, - C, - this->kernel_h(), - this->kernel_w(), - this->stride_h(), - this->stride_w(), - this->pad_t(), - filter.template data(), - Xdata, - localColBufferData, - localYData, - &context_); - }; - - auto f = [&](Tensor* threadBuffer) { - threadBuffer->Resize( - numThreads * threadYBufferSizeAligned + - numThreads * threadColBufferSize); - // Group together thread buffers for accumulation - std::vector toSum(numThreads - 1); - for (int i = 1; i < numThreads; ++i) { - toSum[i - 1] = threadBuffer->template mutable_data() + - i * threadYBufferSizeAligned; - } - - for (auto image_id = 0; image_id < N; ++image_id) { - // Each time through, we have to reset all per-thread output - // buffers, since the output buffer is only per-batch element - // The column buffers are overwritten by the matrix multiplication - // each time, so we need not clear them out each round - math::Set( - numThreads * threadYBufferSizeAligned, - 0, - threadBuffer->template mutable_data(), - &context_); - - // Run tiled gemm and col2im in our threadpool; all of these tiles - // are guaranteed to be full tiles - // Each tile handles a single row of the input - pool->run( - [&](int threadId, int tileId) { - runLocalTile(threadBuffer, threadId, tileId); - }, - H); - - // We need to accumulate the per-thread results into the output - // Y; the first worker thread (main thread) already produced its - // results in Y - sumInto( - threadBuffer->template mutable_data(), toSum, threadYBufferSize); - -// y0 now contains the final output, but it is in deinterleaved -// form. We have to re-interleave it to produce the final form in Y -// This operation also handles adding the per-channel bias. -#define REINTERLEAVE(N) \ - do { \ - reinterleaveMultithreaded( \ - threadBuffer->template mutable_data(), \ - InputSize() == 3 ? Input(BIAS).template data() : nullptr, \ - Ydata, \ - Y->dim32(1), \ - Y->dim32(2), \ - Y->dim32(3), \ - W, \ - this->kernel_w(), \ - this->stride_w(), \ - this->adj_h(), \ - pool); \ - } while (false) - - if (this->stride_w() == 1) { - REINTERLEAVE(1); - } else if (this->stride_w() == 2) { - REINTERLEAVE(2); - } else if (this->stride_w() == 3) { - REINTERLEAVE(3); - } else if (this->stride_w() == 4) { - REINTERLEAVE(4); - } - -#undef REINTERLEAVE - - Xdata += M * H * W; - Ydata += Y->size() / Y->dim32(0); - } - }; - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - runWithSharedBuffer(ws_, f); - } else { - f(&threadBuffer_); - } - - return true; -} - -template -bool ConvTransposeMobileOp::RunOnDeviceWithOrderNHWC() { - CAFFE_THROW("Not implemented."); -} - -} // namespace caffe2 - -#endif // CAFFE2_MOBILE - -#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_MOBILE_OP_IMPL_H_ diff --git a/app/src/main/cpp/caffe2/operators/conv_transpose_unpool_op_base.h b/app/src/main/cpp/caffe2/operators/conv_transpose_unpool_op_base.h deleted file mode 100644 index bf2708d..0000000 --- a/app/src/main/cpp/caffe2/operators/conv_transpose_unpool_op_base.h +++ /dev/null @@ -1,307 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CONV_TRANSPOSE_UNPOOL_OP_BASE_H_ -#define CAFFE2_OPERATORS_CONV_TRANSPOSE_UNPOOL_OP_BASE_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_op_shared.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/proto/caffe2_legacy.pb.h" -#include "caffe2/utils/math.h" - -CAFFE2_DECLARE_bool(caffe2_force_shared_col_buffer); - -namespace caffe2 { - -template -class ConvTransposeUnpoolBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ConvTransposeUnpoolBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - legacy_pad_( - static_cast(OperatorBase::GetSingleArgument( - "legacy_pad", - LegacyPadding::NOTSET))), - kernel_(OperatorBase::GetRepeatedArgument("kernels")), - stride_(OperatorBase::GetRepeatedArgument("strides")), - pads_(OperatorBase::GetRepeatedArgument("pads")), - adj_(OperatorBase::GetRepeatedArgument("adjs")), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - shared_buffer_( - OperatorBase::GetSingleArgument("shared_buffer", 0)), - ws_(ws) { - // For the padding, they should either be the legacy padding strategy - // (VALID or SAME), or an explicit, non-negative value. - if (legacy_pad_ == LegacyPadding::VALID || - legacy_pad_ == LegacyPadding::SAME) { - CAFFE_ENFORCE( - !OperatorBase::HasArgument("pads"), - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - } - // Get old arguments values. - if (OperatorBase::HasArgument("kernel")) { - kernel_.resize(2, OperatorBase::GetSingleArgument("kernel", 0)); - } else if ( - OperatorBase::HasArgument("kernel_h") && - OperatorBase::HasArgument("kernel_w")) { - kernel_.push_back(OperatorBase::GetSingleArgument("kernel_h", 0)); - kernel_.push_back(OperatorBase::GetSingleArgument("kernel_w", 0)); - } - - if (OperatorBase::HasArgument("stride")) { - stride_.resize(2, OperatorBase::GetSingleArgument("stride", 0)); - } else if ( - OperatorBase::HasArgument("stride_h") && - OperatorBase::HasArgument("stride_w")) { - stride_.push_back(OperatorBase::GetSingleArgument("stride_h", 0)); - stride_.push_back(OperatorBase::GetSingleArgument("stride_w", 0)); - } - - if (OperatorBase::HasArgument("adj")) { - adj_.resize(2, OperatorBase::GetSingleArgument("adj", 0)); - } else if ( - OperatorBase::HasArgument("adj_h") && - OperatorBase::HasArgument("adj_w")) { - adj_.push_back(OperatorBase::GetSingleArgument("adj_h", 0)); - adj_.push_back(OperatorBase::GetSingleArgument("adj_w", 0)); - } - - if (OperatorBase::HasArgument("pad")) { - CAFFE_ENFORCE( - legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME, - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - pads_.resize(4, OperatorBase::GetSingleArgument("pad", 0)); - } else if ( - OperatorBase::HasArgument("pad_t") && - OperatorBase::HasArgument("pad_l") && - OperatorBase::HasArgument("pad_b") && - OperatorBase::HasArgument("pad_r")) { - CAFFE_ENFORCE( - legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME, - "If you use legacy padding VALID or SAME, you should not specify " - "any specific padding values."); - pads_.push_back(OperatorBase::GetSingleArgument("pad_t", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_l", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_b", 0)); - pads_.push_back(OperatorBase::GetSingleArgument("pad_r", 0)); - } - - // Fill default values. - if (kernel_.size() == 0) { - kernel_.assign({0, 0}); - } - - if (stride_.size() == 0) { - stride_.resize(kernel_.size(), 1); - } - - if (pads_.size() == 0) { - pads_.resize(kernel_.size() * 2, 0); - } - - if (adj_.size() == 0) { - adj_.resize(kernel_.size(), 0); - } - - CAFFE_ENFORCE_EQ(stride_.size(), kernel_.size()); - CAFFE_ENFORCE_EQ(adj_.size(), kernel_.size()); - - if (legacy_pad_ != LegacyPadding::VALID && - legacy_pad_ != LegacyPadding::SAME) { - CAFFE_ENFORCE_EQ(pads_.size(), 2 * kernel_.size()); - } - - for (int dim = 0; dim < kernel_.size(); ++dim) { - CAFFE_ENFORCE_GT(kernel_[dim], 0); - CAFFE_ENFORCE_GT(stride_[dim], 0); - CAFFE_ENFORCE_GE(adj_[dim], 0); - CAFFE_ENFORCE_LE(adj_[dim], stride_[dim]); - } - - // Create shared buffer mutex in the constructor - // to avoid race-condition in DAGNet. - if (FLAGS_caffe2_force_shared_col_buffer || shared_buffer_) { - createSharedBuffer(ws_); - } - } - // Sets the output size. The output channel is manually specified. - void SetOutputSize( - const Tensor& input, - Tensor* output, - int output_channel) { - CAFFE_ENFORCE(4 == input.ndim()); - CAFFE_ENFORCE(input.size() > 0); - int N = input.dim32(0); - bool channel_first = false; // initialized to suppress compiler warning. - int H = 0, W = 0; // initialized to suppress compiler warning. - int M = 0; - switch (order_) { - case StorageOrder::NHWC: - channel_first = false; - H = input.dim32(1); - W = input.dim32(2); - M = input.dim32(3); - break; - case StorageOrder::NCHW: - channel_first = true; - M = input.dim32(1); - H = input.dim32(2); - W = input.dim32(3); - break; - default: - LOG(FATAL) << "Unknown Storage order: " << order_; - } - int output_height = 0, output_width = 0; - ComputeSizeAndPad( - H, - stride_[0], - kernel_[0], - adj_[0], - &pads_[0], - &pads_[2], - &output_height); - ComputeSizeAndPad( - W, - stride_[1], - kernel_[1], - adj_[1], - &pads_[1], - &pads_[3], - &output_width); - if (channel_first) { - output->Resize(N, output_channel, output_height, output_width); - } else { - output->Resize(N, output_height, output_width, output_channel); - } - VLOG(2) << "In: N " << N << " M " << M << " H " << H << " W " << W; - VLOG(2) << "Out: output_channel " << output_channel << " H " - << output_height << " W " << output_width; - } - - bool RunOnDevice() override { - switch (order_) { - case StorageOrder::NHWC: - return RunOnDeviceWithOrderNHWC(); - case StorageOrder::NCHW: - return RunOnDeviceWithOrderNCHW(); - default: - LOG(FATAL) << "Unknown storage order: " << order_; - } - // To suppress old compiler warnings - return true; - } - - virtual bool RunOnDeviceWithOrderNCHW() { - CAFFE_THROW("Not implemented"); - } - - virtual bool RunOnDeviceWithOrderNHWC() { - CAFFE_THROW("Not implemented"); - } - - virtual ~ConvTransposeUnpoolBase() {} - - private: - LegacyPadding legacy_pad_; - int pad_; - - protected: - vector kernel_; - vector stride_; - vector pads_; - vector adj_; - StorageOrder order_; - bool shared_buffer_; - Workspace* ws_; - - // Accessors for 2D conv params. - - inline int pad_t() const { - return pads_[0]; - } - - inline int pad_l() const { - return pads_[1]; - } - - inline int pad_b() const { - return pads_[2]; - } - - inline int pad_r() const { - return pads_[3]; - } - - inline int kernel_h() const { - return kernel_[0]; - } - - inline int kernel_w() const { - return kernel_[1]; - } - - inline int stride_h() const { - return stride_[0]; - } - - inline int stride_w() const { - return stride_[1]; - } - - inline int adj_h() const { - return adj_[0]; - } - - inline int adj_w() const { - return adj_[1]; - } - - inline void ComputeSizeAndPad( - const int in_size, - const int stride, - const int kernel, - const int adj, - int* pad_head, - int* pad_tail, - int* out_size) { - switch (legacy_pad_) { - case LegacyPadding::NOTSET: - CAFFE_ENFORCE(*pad_head >= 0); - CAFFE_ENFORCE(*pad_tail >= 0); - *out_size = - (in_size - 1) * stride + kernel + adj - *pad_head - *pad_tail; - break; - // We handle cases of LegacyPadding::VALID and LegacyPadding::SAME - // the same way - case LegacyPadding::VALID: - case LegacyPadding::SAME: - *pad_head = 0; - *pad_tail = 0; - *out_size = (in_size - 1) * stride + kernel + adj; - break; - case LegacyPadding::CAFFE_LEGACY_POOLING: - LOG(FATAL) << "CAFFE_LEGACY_POOLING is no longer supported."; - break; - } - } -}; - -#define USE_CONV_TRANSPOSE_UNPOOL_BASE_FUNCTIONS(Context) \ - USE_OPERATOR_FUNCTIONS(Context); \ - using ConvTransposeUnpoolBase::kernel_; \ - using ConvTransposeUnpoolBase::stride_; \ - using ConvTransposeUnpoolBase::pads_; \ - using ConvTransposeUnpoolBase::adj_; \ - using ConvTransposeUnpoolBase::order_; \ - using ConvTransposeUnpoolBase::shared_buffer_; \ - using ConvTransposeUnpoolBase::ws_ - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CONV_TRANSPOSE_UNPOOL_OP_BASE_H_ diff --git a/app/src/main/cpp/caffe2/operators/cosine_embedding_criterion_op.h b/app/src/main/cpp/caffe2/operators/cosine_embedding_criterion_op.h deleted file mode 100644 index 0d9599d..0000000 --- a/app/src/main/cpp/caffe2/operators/cosine_embedding_criterion_op.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CAFFE2_OPERATORS_COSINE_EMBEDDING_CRITERION_OP_H_ -#define CAFFE2_OPERATORS_COSINE_EMBEDDING_CRITERION_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class CosineEmbeddingCriterionOp final : public Operator { - public: - CosineEmbeddingCriterionOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(float, "margin", margin_, 0.0) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float margin_; -}; - -template -class CosineEmbeddingCriterionGradientOp final : public Operator { - public: - CosineEmbeddingCriterionGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(float, "margin", margin_, 0.0) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float margin_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_COSINE_EMBEDDING_CRITERION_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/counter_ops.h b/app/src/main/cpp/caffe2/operators/counter_ops.h deleted file mode 100644 index 3b7bf7d..0000000 --- a/app/src/main/cpp/caffe2/operators/counter_ops.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef CAFFE2_OPERATORS_COUNTER_OPS_H -#define CAFFE2_OPERATORS_COUNTER_OPS_H - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { -template -class Counter { - public: - explicit Counter(T count) : count_(count) {} - bool countDown() { - if (count_-- > 0) { - return false; - } - return true; - } - - T countUp() { - return count_++; - } - - T retrieve() const { - return count_.load(); - } - - T checkIfDone() const { - return (count_.load() <= 0); - } - - T reset(T init_count) { - return count_.exchange(init_count); - } - - private: - std::atomic count_; -}; - -// TODO(jiayq): deprecate these ops & consolidate them with IterOp/AtomicIterOp - -template -class CreateCounterOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CreateCounterOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - init_count_(OperatorBase::GetSingleArgument("init_count", 0)) { - CAFFE_ENFORCE_LE(0, init_count_, "negative init_count is not permitted."); - } - - bool RunOnDevice() override { - *OperatorBase::Output>>(0) = - std::unique_ptr>(new Counter(init_count_)); - return true; - } - - private: - T init_count_ = 0; -}; - -template -class ResetCounterOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ResetCounterOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - init_count_(OperatorBase::GetSingleArgument("init_count", 0)) { - CAFFE_ENFORCE_LE(0, init_count_, "negative init_count is not permitted."); - } - - bool RunOnDevice() override { - auto& counterPtr = OperatorBase::Input>>(0); - auto previous = counterPtr->reset(init_count_); - if (OutputSize() == 1) { - auto* output = OperatorBase::Output(0); - output->Resize(); - *output->template mutable_data() = previous; - } - return true; - } - - private: - T init_count_; -}; - -// Will always use TensorCPU regardless the Context -template -class CountDownOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CountDownOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& counterPtr = OperatorBase::Input>>(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = counterPtr->countDown(); - return true; - } -}; - -// Will always use TensorCPU regardless the Context -template -class CheckCounterDoneOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CheckCounterDoneOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& counterPtr = OperatorBase::Input>>(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = counterPtr->checkIfDone(); - return true; - } -}; - -// Will always use TensorCPU regardless the Context -template -class CountUpOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CountUpOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& counterPtr = OperatorBase::Input>>(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = counterPtr->countUp(); - return true; - } -}; - -// Will always use TensorCPU regardless the Context -template -class RetrieveCountOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RetrieveCountOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& counterPtr = OperatorBase::Input>>(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = counterPtr->retrieve(); - return true; - } -}; - -} // namespace caffe2 -#endif // CAFFE2_OPERATORS_COUNTER_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/create_scope_op.h b/app/src/main/cpp/caffe2/operators/create_scope_op.h deleted file mode 100644 index 8a432ac..0000000 --- a/app/src/main/cpp/caffe2/operators/create_scope_op.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CREATE_SCOPE_OP_H_ -#define CAFFE2_OPERATORS_CREATE_SCOPE_OP_H_ - -#include -#include -#include -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/proto/caffe2.pb.h" - -CAFFE2_DECLARE_bool(caffe2_workspace_stack_debug); - -namespace caffe2 { -namespace detail { - -/* - * Keeps track of forward and backward gradient workspaces in stack, - * reuses previously created workspaces, non-thread safe - */ -class WorkspaceStack { - public: - explicit WorkspaceStack() : parent_ws_(nullptr), top_(-1) {} - - std::shared_ptr pushForwardWorkspace( - Workspace* parent_ws, - const std::unordered_map& blob_bindings) { - checkStack(); - if (FLAGS_caffe2_workspace_stack_debug) { - if (parent_ws_) { - CAFFE_ENFORCE_EQ(parent_ws_, parent_ws, "Parent workspace mismatch"); - } else { - parent_ws_ = parent_ws; - } - if (!blob_bindings_.empty()) { - checkBindingsMatch(blob_bindings_, blob_bindings); - } else { - blob_bindings_ = blob_bindings; - } - } - - if (top_ == workspaces_.size() - 1) { - workspaces_.push_back( - std::make_shared(parent_ws, blob_bindings)); - } - return workspaces_[++top_]; - } - - std::shared_ptr popGradientWorkspace( - Workspace* parent_ws, - const std::unordered_map& grad_blob_bindings) { - checkStack(); - if (FLAGS_caffe2_workspace_stack_debug) { - if (parent_ws_) { - CAFFE_ENFORCE_EQ(parent_ws_, parent_ws, "Parent workspace mismatch"); - } else { - parent_ws_ = parent_ws; - } - if (!grad_blob_bindings_.empty()) { - checkBindingsMatch(grad_blob_bindings_, grad_blob_bindings); - } else { - grad_blob_bindings_ = grad_blob_bindings; - } - } - - if (top_ < 0) { - return nullptr; - } - auto& grad_workspace = workspaces_[top_]; - grad_workspace->AddBlobMapping(parent_ws, grad_blob_bindings); - --top_; - return grad_workspace; - } - - void clear() { - checkStack(); - top_ = -1; - } - - private: - void checkStack() const { - CAFFE_ENFORCE_GT( - (int)workspaces_.size(), top_, "Corrupted workspaces stack"); - } - - void checkBindingsMatch( - const std::unordered_map& bindings, - const std::unordered_map& test_bindings) const { - CAFFE_ENFORCE_EQ( - bindings.size(), test_bindings.size(), "Blob bindings mismatch"); - for (const auto& blob_binding : bindings) { - CAFFE_ENFORCE( - test_bindings.count(blob_binding.first), "Blob bindings mismatch"); - CAFFE_ENFORCE_EQ( - test_bindings.at(blob_binding.first), - blob_binding.second, - "Blob bindings mismatch"); - } - } - - std::unordered_map blob_bindings_; - std::unordered_map grad_blob_bindings_; - Workspace* parent_ws_; - int top_; - std::vector> workspaces_; -}; -} - -template -class CreateScopeOp final : public Operator { - public: - CreateScopeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CREATE_SCOPE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/cross_entropy_op.h b/app/src/main/cpp/caffe2/operators/cross_entropy_op.h deleted file mode 100644 index 2fba127..0000000 --- a/app/src/main/cpp/caffe2/operators/cross_entropy_op.h +++ /dev/null @@ -1,115 +0,0 @@ -#ifndef CAFFE2_OPERATORS_CROSS_ENTROPY_OP_H_ -#define CAFFE2_OPERATORS_CROSS_ENTROPY_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class LabelCrossEntropyOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(LabelCrossEntropyOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - static constexpr T kLOG_THRESHOLD() { - return static_cast(1e-20); - } - // Input: X, label - // Output: Y -}; - -template -class LabelCrossEntropyGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(LabelCrossEntropyGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - // Input: X, label, dY - // Ouptut: dX. There is no gradient with respect to the label. - static constexpr T kLOG_THRESHOLD() { - return static_cast(1e-20); - } -}; - -// Hacky: turns a vector of probabilities into a 2-column matrix with -// complimentary probabilities for binary classification -template -class MakeTwoClassOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(MakeTwoClassOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - // Input: X - // Output: Y = vstack(1-X, X) -}; - -template -class MakeTwoClassGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(MakeTwoClassGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - // Input: dY - // Ouptut: dX -}; - -template -class SigmoidCrossEntropyWithLogitsOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(SigmoidCrossEntropyWithLogitsOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; -}; - -template -class SigmoidCrossEntropyWithLogitsGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(SigmoidCrossEntropyWithLogitsGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; -}; - -template -class CrossEntropyOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(CrossEntropyOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - // Input: X, label - // Output: Y - static constexpr T kLOG_THRESHOLD() { - return static_cast(1e-20); - } -}; - -template -class CrossEntropyGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(CrossEntropyGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - // Input: X, label, dY - // Ouptut: dX. There is no gradient with respect to the label. - static constexpr T kLOG_THRESHOLD() { - return static_cast(1e-20); - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_CROSS_ENTROPY_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/dataset_ops.h b/app/src/main/cpp/caffe2/operators/dataset_ops.h deleted file mode 100644 index 98bf672..0000000 --- a/app/src/main/cpp/caffe2/operators/dataset_ops.h +++ /dev/null @@ -1,199 +0,0 @@ -#ifndef CAFFE2_OPERATORS_DATASET_OPS_H_ -#define CAFFE2_OPERATORS_DATASET_OPS_H_ - -#include -#include -#include -#include -#include "caffe2/core/blob.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { -namespace dataset_ops { - -// used for lengths tensors in the dataset -using TLength = int32_t; -// used for all internal dataset operations (offsets, sizes to read, etc.) -using TOffset = int64_t; - -/** - * Provides functionality to iterate across a list of tensors where some - * of those tensors represent lengths in a hierarchical structure. - */ -class TreeIterator { - public: - struct FieldDesc { - int id; - int lengthFieldId = -1; - std::string name; - }; - - explicit TreeIterator(const std::vector& fields); - - void advance( - const std::vector& lengths, - std::vector& offsets, - std::vector& sizes, - std::vector& limits, - TOffset num); - - // Corresponds to the number of fields that have "length" as its last name - int numLengthFields() const { - return lengthFieldIds_.size(); - } - - // Corresponds to the number of length fields + 1 (for the top-level domain) - int numOffsetFields() const { - return numLengthFields() + 1; - } - - // Get lengthField description for the given field - const FieldDesc* lengthFieldFor(const FieldDesc& desc) { - return (desc.lengthFieldId == -1) - ? nullptr - : &fields_.at(lengthFieldIds_.at(desc.lengthFieldId)); - } - - // Get lengthField description for the given lengthFieldId, where - // 0 <= lengthFieldId < numLengthFields() - const FieldDesc& lengthField(int lengthFieldId) { - return fields_.at(lengthFieldIds_.at(lengthFieldId)); - } - - // Returns the index into the 'offset' vector for the given field. - int offsetFieldIdFor(const FieldDesc& fieldDesc) { - return fieldDesc.lengthFieldId + 1; - } - - // Returns the field description for all fields. - const std::vector& fields() { - return fields_; - } - - const std::vector& lengthFieldIds() const { - return lengthFieldIds_; - } - - private: - // Description of each field - std::vector fields_; - // Index into fields_ above for the fields that are lengths. - std::vector lengthFieldIds_; -}; - -class TreeCursor { - public: - explicit TreeCursor(const TreeIterator& iterator) : it(iterator) {} - std::vector offsets; - std::mutex mutex_; - TreeIterator it; -}; - -/** - * Simple wrapper class allowing an easy traversal of the tensors representing - * the hirerarchical structure. - */ -class TreeWalker { - public: - TreeWalker(const vector& inputs, TreeCursor& cursor); - - // Returns the number of records in a dataset - inline TOffset size() const { - return limits_.at(0); - } - - void advance(); - - private: - inline const TensorCPU& input(int32_t idx) const { - return inputs_[idx]->Get(); - } - - // TODO: Change to fieldDesc - inline const TreeIterator::FieldDesc& field(int idx) const { - return cursor_.it.fields().at(idx); - } - - inline int lengthIdx(int fieldId) const { - return field(fieldId).lengthFieldId + 1; - } - - inline TOffset offset(int fieldId) const { - return prevOffsets_[lengthIdx(fieldId)]; - } - - std::vector fieldDim(int fieldId) const; - - void* fieldPtr(int fieldId) const; - - public: - // Simple Proxy class to expose nicer API for field access - class Field { - public: - Field(TreeWalker& walker, int fieldId) - : walker_(walker), fieldId_(fieldId) {} - - inline std::vector dim() const { - return walker_.fieldDim(fieldId_); - } - - inline TIndex size() const { - TIndex size = 1; - for (const auto d : dim()) { - size *= d; - } - return size; - } - - inline const TypeMeta& meta() const { - return walker_.input(fieldId_).meta(); - } - - inline void* ptr() const { - return walker_.fieldPtr(fieldId_); - } - - int fieldId() const { - return fieldId_; - } - - inline TOffset offset() const { - return walker_.offset(fieldId_); - } - - private: - const TreeWalker& walker_; - const int fieldId_; - }; - - // Notice that a reference is returned. If advance() is called the fields will - // be updated to represent the new state. - inline const std::vector& fields() const { - return fields_; - } - - private: - void gatherLengthData(); - - void gatherSizeLimits(); - - const vector& inputs_; - TreeCursor& cursor_; - std::vector fields_; - - std::vector lengths_; - std::vector limits_; - std::vector sizes_; - std::vector offsets_; - std::vector prevOffsets_; -}; - -using SharedTensorVectorPtr = std::shared_ptr>; - -template -using TensorVectorPtr = std::unique_ptr>>; - -} // dataset_ops -} // caffe2 - -#endif // CAFFE2_OPERATORS_DATASET_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/distance_op.h b/app/src/main/cpp/caffe2/operators/distance_op.h deleted file mode 100644 index aad57e9..0000000 --- a/app/src/main/cpp/caffe2/operators/distance_op.h +++ /dev/null @@ -1,285 +0,0 @@ -#ifndef CAFFE2_OPERATORS_DISTANCE_OP_H_ -#define CAFFE2_OPERATORS_DISTANCE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SquaredL2DistanceOp : public Operator { - public: - SquaredL2DistanceOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - // Input: X, Y; Output: Distance -}; - -template -class SquaredL2DistanceGradientOp final : public Operator { - public: - SquaredL2DistanceGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& X = Input(0); - auto& Y = Input(1); - auto& dDistance = Input(2); - auto* dX = Output(0); - auto* dY = Output(1); - int N = X.ndim() > 0 ? X.dim32(0) : 1; - int D = N > 0 ? X.size() / N : 0; - CAFFE_ENFORCE(X.ndim() == Y.ndim()); - for (int i = 0; i < X.ndim(); ++i) { - CAFFE_ENFORCE(X.dim32(i) == Y.dim32(i)); - } - CAFFE_ENFORCE(dDistance.ndim() == 1); - CAFFE_ENFORCE(dDistance.dim32(0) == N); - dX->ResizeLike(X); - dY->ResizeLike(Y); - math::Sub( - X.size(), - X.template data(), - Y.template data(), - dX->template mutable_data(), - &context_); - for (int i = 0; i < N; ++i) { - math::Scale( - D, - dDistance.template data() + i, - dX->template data() + i * D, - dX->template mutable_data() + i * D, - &context_); - } - // The gradient of the other side is basically the negative. - math::Scale( - X.size(), - -1, - dX->template data(), - dY->template mutable_data(), - &context_); - return true; - } - - protected: - // Input: X, Y, dDistance; Output: dX, dY -}; - -template -class L1DistanceOp : public Operator { - public: - L1DistanceOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - // Input: X, Y; Output: Distance -}; - -template -class L1DistanceGradientOp : public Operator { - public: - L1DistanceGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - // Input: X, Y, dDistance; Output: dX, dY -}; - -template -class DotProductOp : public Operator { - public: - DotProductOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - INPUT_TAGS(X_IN, Y_IN); - OUTPUT_TAGS(DOT_OUT); -}; - -template -class DotProductGradientOp final : public Operator { - public: - DotProductGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - INPUT_TAGS(X_IN, Y_IN, DER_DOT_IN); - OUTPUT_TAGS(DER_X_OUT, DER_Y_OUT); -}; - -template -class DotProductWithPaddingOp : public Operator { - public: - DotProductWithPaddingOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - pad_value_(OperatorBase::GetSingleArgument("pad_value", 0.0)), - replicate_(OperatorBase::GetSingleArgument("replicate", false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float pad_value_; - bool replicate_; - INPUT_TAGS(X_IN, Y_IN); - OUTPUT_TAGS(DOT_OUT); -}; - -template -class CosineSimilarityOp : public Operator { - public: - CosineSimilarityOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - INPUT_TAGS(X_IN, Y_IN); - OUTPUT_TAGS(COS_OUT); - - private: - Tensor aux_; -}; - -template -class CosineSimilarityGradientOp final : public Operator { - public: - CosineSimilarityGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - INPUT_TAGS(X_IN, Y_IN, DER_COS_IN); - OUTPUT_TAGS(DER_X_OUT, DER_Y_OUT); - - private: - Tensor aux_; -}; - -template -class DotProductWithPaddingGradientOp final : public Operator { - public: - DotProductWithPaddingGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - pad_value_(OperatorBase::GetSingleArgument("pad_value", 0.0)), - replicate_(OperatorBase::GetSingleArgument("replicate", false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& X = Input(X_IN); - auto& Y = Input(Y_IN); - auto& dDot = Input(DER_DOT_IN); - auto* dX = Output(DER_X_OUT); - auto* dY = Output(DER_Y_OUT); - int N, D, DX, DY, restD; - if (X.size() > 0) { - N = X.ndim() > 0 ? X.dim32(0) : 1; - DX = X.size() / N; - DY = Y.size() / N; - } else { - N = 0; - DX = 0; - DY = 0; - } - CAFFE_ENFORCE(!replicate_ || DX % DY == 0 || DY % DX == 0); - D = std::min(DX, DY); - restD = std::max(DX, DY) - D; - CAFFE_ENFORCE_EQ(X.ndim(), Y.ndim()); - CAFFE_ENFORCE_EQ(X.dim32(0), Y.dim32(0)); - CAFFE_ENFORCE_EQ(dDot.ndim(), 1); - CAFFE_ENFORCE_EQ(dDot.dim32(0), N); - dX->ResizeLike(X); - dY->ResizeLike(Y); - - const auto* X_data = X.template data(); - const auto* Y_data = Y.template data(); - const auto* dDot_data = dDot.template data(); - auto* dX_data = dX->template mutable_data(); - auto* dY_data = dY->template mutable_data(); - for (int i = 0; i < N; ++i) { // TODO: multithreading - auto offsetX = i * DX; - auto offsetY = i * DY; - if (replicate_) { - // L_ for longer vector and S_ for shorter vector - const T *L_data, *S_data; - T *dL_data, *dS_data; - int DL, DS; - if (DX > DY) { - L_data = X_data + offsetX; - S_data = Y_data + offsetY; - dL_data = dX_data + offsetX; - dS_data = dY_data + offsetY; - DL = DX; - DS = DY; - } else { - L_data = Y_data + offsetY; - S_data = X_data + offsetX; - dL_data = dY_data + offsetY; - dS_data = dX_data + offsetX; - DL = DY; - DS = DX; - } - - // TODO: get rid of temp memory use - std::vector tmp_data(DS); - math::Set(DS, 0.0, dS_data, &context_); - for (int j = 0; j < DL / DS; j++) { - math::Scale( - DS, dDot_data[i], S_data, dL_data + j * DS, &context_); - math::Scale( - DS, dDot_data[i], L_data + j * DS, tmp_data.data(), &context_); - math::Axpy(DS, 1.0, tmp_data.data(), dS_data, &context_); - } - } else { - math::Scale( - D, dDot_data[i], X_data + offsetX, dY_data + offsetY, &context_); - math::Scale( - D, dDot_data[i], Y_data + offsetY, dX_data + offsetX, &context_); - } - - if (!replicate_ && DX != DY) { - T* rest_data; - if (DX > DY) { - rest_data = dX_data + offsetX + D; - } else { - rest_data = dY_data + offsetY + D; - } - auto pad_gradient = dDot_data[i] * pad_value_; - math::Set(restD, pad_gradient, rest_data, &context_); - } - } - - return true; - } - - protected: - float pad_value_; - bool replicate_; - INPUT_TAGS(X_IN, Y_IN, DER_DOT_IN); - OUTPUT_TAGS(DER_X_OUT, DER_Y_OUT); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_DISTANCE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/do_op.h b/app/src/main/cpp/caffe2/operators/do_op.h deleted file mode 100644 index fa0ac87..0000000 --- a/app/src/main/cpp/caffe2/operators/do_op.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef CAFFE2_OPERATORS_DO_OP_H_ -#define CAFFE2_OPERATORS_DO_OP_H_ - -#include -#include -#include -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -template -class DoOp final : public Operator { - public: - DoOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), parent_ws_(ws) { - CAFFE_ENFORCE( - this->template HasSingleArgumentOfType("net"), - "net must be specified in Do operator"); - net_def_ = this->template GetSingleArgument("net", NetDef()); - is_gradient_op_ = operator_def.is_gradient_op(); - - const auto& inner_blobs = - this->template GetRepeatedArgument("inner_blobs"); - const auto& outer_blobs_idx = - this->template GetRepeatedArgument("outer_blobs_idx"); - CAFFE_ENFORCE_EQ( - inner_blobs.size(), - outer_blobs_idx.size(), - "Invalid blob bindings: different inner/outer blobs lengths"); - - const auto& outer_blob_names = checkAndGetOuterNames(operator_def); - std::unordered_set used_outer_names; - for (size_t blob_idx = 0; blob_idx < inner_blobs.size(); ++blob_idx) { - CAFFE_ENFORCE( - !blob_bindings_.count(inner_blobs[blob_idx]), - "Invalid blob bindings: redefinition of inner blob " + - inner_blobs[blob_idx]); - CAFFE_ENFORCE( - outer_blobs_idx[blob_idx] >= 0 && - outer_blobs_idx[blob_idx] < outer_blob_names.size(), - "Invalid blob bindings: outer blob index (" + - caffe2::to_string(outer_blobs_idx[blob_idx]) + ", inner name: " + - inner_blobs[blob_idx] + ") is out of bounds [0, " + - caffe2::to_string(outer_blob_names.size() - 1) + "]"); - const auto& outer_name = outer_blob_names[outer_blobs_idx[blob_idx]]; - CAFFE_ENFORCE( - !used_outer_names.count(outer_name), - "Reusage of outer name: " + outer_name); - used_outer_names.insert(outer_name); - blob_bindings_[inner_blobs[blob_idx]] = outer_name; - } - std::unordered_set all_outer_names( - outer_blob_names.begin(), outer_blob_names.end()); - CAFFE_ENFORCE_EQ( - used_outer_names.size(), - all_outer_names.size(), - "Not all outer names are used in blob bindings"); - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - private: - // returns vector of input blob names followed by output blob names in - // operator definition order; ensures that input (output) names are unique, - // checks number of input (output) blobs - std::vector checkAndGetOuterNames( - const OperatorDef& operator_def) const { - auto input_names = getInputBlobNames(operator_def); - CAFFE_ENFORCE(!input_names.empty(), "Expected at least one input blob"); - std::string input_ws_blob = input_names.back(); // copy - // removing blob that holds pointer op workspace - input_names.pop_back(); - - std::unordered_set all_input_names( - input_names.begin(), input_names.end()); - CAFFE_ENFORCE_EQ( - input_names.size(), all_input_names.size(), "Duplicate input blobs"); - - auto output_names = getOutputBlobNames(operator_def); - CAFFE_ENFORCE(!output_names.empty(), "Expected at least one output blob"); - const auto& output_ws_blob = output_names.back(); - CAFFE_ENFORCE_EQ( - input_ws_blob, - output_ws_blob, - "Expected same input/output workspace blob"); - // remove blob that holds pointer to op workspace - output_names.pop_back(); - - std::unordered_set all_output_names( - output_names.begin(), output_names.end()); - CAFFE_ENFORCE_EQ( - output_names.size(), all_output_names.size(), "Duplicate output blobs"); - - std::vector outer_blob_names; - outer_blob_names.reserve(input_names.size() + output_names.size()); - outer_blob_names.insert( - outer_blob_names.end(), input_names.begin(), input_names.end()); - outer_blob_names.insert( - outer_blob_names.end(), output_names.begin(), output_names.end()); - return outer_blob_names; - } - - std::vector getInputBlobNames( - const OperatorDef& operator_def) const { - std::vector names; - names.reserve(operator_def.input_size()); - for (auto idx = 0; idx < operator_def.input_size(); ++idx) { - names.push_back(operator_def.input(idx)); - } - return names; - } - - std::vector getOutputBlobNames( - const OperatorDef& operator_def) const { - std::vector names; - names.reserve(operator_def.output_size()); - for (auto idx = 0; idx < operator_def.output_size(); ++idx) { - names.push_back(operator_def.output(idx)); - } - return names; - } - - std::unordered_map blob_bindings_; - bool is_gradient_op_; - NetDef net_def_; - Workspace* parent_ws_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_DO_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/dropout_op.h b/app/src/main/cpp/caffe2/operators/dropout_op.h deleted file mode 100644 index f368886..0000000 --- a/app/src/main/cpp/caffe2/operators/dropout_op.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef CAFFE2_OPERATORS_DROPOUT_OP_H_ -#define CAFFE2_OPERATORS_DROPOUT_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class DropoutOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - DropoutOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ratio_(OperatorBase::GetSingleArgument("ratio", 0.5)), - is_test_( - OperatorBase::GetSingleArgument(OpSchema::Arg_IsTest, 0)) { - CAFFE_ENFORCE_GE(ratio_, 0); - CAFFE_ENFORCE_LT(ratio_, 1); - } - - bool RunOnDevice() override; - - protected: - float ratio_; - bool is_test_; - // Input: X; Output: Y, mask. -}; - -template -class DropoutGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - DropoutGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ratio_(OperatorBase::GetSingleArgument("ratio", 0.5)), - is_test_( - OperatorBase::GetSingleArgument(OpSchema::Arg_IsTest, 0)) { - CAFFE_ENFORCE_GE(ratio_, 0); - CAFFE_ENFORCE_LT(ratio_, 1); - } - - bool RunOnDevice() override; - - protected: - float ratio_; - bool is_test_; - // Input: dY, mask; Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_DROPOUT_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/elementwise_linear_op.h b/app/src/main/cpp/caffe2/operators/elementwise_linear_op.h deleted file mode 100644 index f2811aa..0000000 --- a/app/src/main/cpp/caffe2/operators/elementwise_linear_op.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ELEMENTWISE_LINEAR_OP_H_ -#define CAFFE2_OPERATORS_ELEMENTWISE_LINEAR_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { -template -class ElementwiseLinearOp final : public Operator { - public: - ElementwiseLinearOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - int axis_; -}; - -template -class ElementwiseLinearGradientOp final : public Operator { - public: - ElementwiseLinearGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - int axis_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ELEMENTWISE_LINEAR_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/elementwise_logical_ops.h b/app/src/main/cpp/caffe2/operators/elementwise_logical_ops.h deleted file mode 100644 index 90ec047..0000000 --- a/app/src/main/cpp/caffe2/operators/elementwise_logical_ops.h +++ /dev/null @@ -1,172 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ELEMENTWISE_LOGICAL_OPS_H_ -#define CAFFE2_OPERATORS_ELEMENTWISE_LOGICAL_OPS_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/elementwise_op.h" - -#include - -namespace caffe2 { - -template -class WhereOp final : public Operator { - public: - USE_OPERATOR_FUNCTIONS(Context); - USE_DISPATCH_HELPER; - - WhereOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(bool, "broadcast_on_rows", enable_broadcast_, 0) {} - - bool RunOnDevice() override { - return DispatchHelper< - TensorTypes>:: - call(this, Input(1)); - } - - template - bool DoRunWithType() { - auto& select = Input(0); - auto& left = Input(1); - auto& right = Input(2); - auto* output = Output(0); - if (enable_broadcast_) { - CAFFE_ENFORCE_EQ(select.ndim(), 1); - CAFFE_ENFORCE_EQ(select.dim(0), right.dim(0)); - CAFFE_ENFORCE_EQ(left.dims(), right.dims()); - } else { - CAFFE_ENFORCE_EQ(select.dims(), left.dims()); - CAFFE_ENFORCE_EQ(select.dims(), right.dims()); - } - output->ResizeLike(left); - - const bool* select_data = select.template data(); - const T* left_data = left.template data(); - const T* right_data = right.template data(); - T* output_data = output->template mutable_data(); - - if (enable_broadcast_) { - size_t block_size = left.size_from_dim(1); - for (int i = 0; i < select.size(); i++) { - size_t offset = i * block_size; - if (select_data[i]) { - context_.template CopyItems( - output->meta(), - block_size, - left_data + offset, - output_data + offset); - } else { - context_.template CopyItems( - output->meta(), - block_size, - right_data + offset, - output_data + offset); - } - } - } else { - for (int i = 0; i < select.size(); ++i) { - output_data[i] = select_data[i] ? left_data[i] : right_data[i]; - } - } - return true; - } - - private: - bool enable_broadcast_; -}; - -class IsMemberOfValueHolder { - std::unordered_set int32_values_; - std::unordered_set int64_values_; - std::unordered_set bool_values_; - std::unordered_set string_values_; - bool has_values_ = false; - - public: - template - std::unordered_set& get(); - - template - void set(const std::vector& args) { - has_values_ = true; - auto& values = get(); - values.insert(args.begin(), args.end()); - } - - bool has_values() { - return has_values_; - } -}; - -template -class IsMemberOfOp final : public Operator { - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - - static constexpr const char* VALUE_TAG = "value"; - - public: - using TestableTypes = TensorTypes; - - IsMemberOfOp(const OperatorDef& op, Workspace* ws) - : Operator(op, ws) { - auto dtype = - static_cast(OperatorBase::GetSingleArgument( - "dtype", TensorProto_DataType_UNDEFINED)); - switch (dtype) { - case TensorProto_DataType_INT32: - values_.set(OperatorBase::GetRepeatedArgument(VALUE_TAG)); - break; - case TensorProto_DataType_INT64: - values_.set(OperatorBase::GetRepeatedArgument(VALUE_TAG)); - break; - case TensorProto_DataType_BOOL: - values_.set(OperatorBase::GetRepeatedArgument(VALUE_TAG)); - break; - case TensorProto_DataType_STRING: - values_.set(OperatorBase::GetRepeatedArgument(VALUE_TAG)); - break; - case TensorProto_DataType_UNDEFINED: - // If dtype is not provided, values_ will be filled the first time that - // DoRunWithType is called. - break; - default: - CAFFE_THROW("Unexpected 'dtype' argument value: ", dtype); - } - } - virtual ~IsMemberOfOp() noexcept {} - - bool RunOnDevice() override { - return DispatchHelper< - TensorTypes>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - auto* output = Output(0); - output->ResizeLike(input); - - if (!values_.has_values()) { - values_.set(OperatorBase::GetRepeatedArgument(VALUE_TAG)); - } - const auto& values = values_.get(); - - const T* input_data = input.template data(); - bool* output_data = output->template mutable_data(); - for (int i = 0; i < input.size(); ++i) { - output_data[i] = values.find(input_data[i]) != values.end(); - } - return true; - } - - protected: - IsMemberOfValueHolder values_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ELEMENTWISE_LOGICAL_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/elementwise_op.h b/app/src/main/cpp/caffe2/operators/elementwise_op.h deleted file mode 100644 index 84b9c44..0000000 --- a/app/src/main/cpp/caffe2/operators/elementwise_op.h +++ /dev/null @@ -1,404 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ELEMENTWISE_OP_H_ -#define CAFFE2_OPERATORS_ELEMENTWISE_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -using NumericTypes = TensorTypes; -using IntTypes = TensorTypes; -using BoolTypes = TensorTypes; - -struct SameTypeAsInput { - template - using type = T; -}; - -template -struct FixedType { - template - using type = R; -}; - -template < - typename InputTypes, - class Context, - class Functor, - class TypeMap = SameTypeAsInput> -class UnaryElementwiseWithArgsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - UnaryElementwiseWithArgsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), functor_(*this) {} - - bool RunOnDevice() override { - return DispatchHelper::call(this, Input(0)); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - auto* output = Output(0); - output->ResizeLike(input); - using R = typename TypeMap::template type; - functor_( - input.size(), - input.template data(), - output->template mutable_data(), - &context_); - return true; - } - - private: - Functor functor_; -}; - -/** - * WithDefaultConstructor is a functor that can be used as the functor of an - * UnaryElementwiseWithArgsOp. It simply forwards the operator() call into - * another functor that doesn't accept arguments in its constructor. - */ -template -struct WithDefaultConstructor { - explicit WithDefaultConstructor(OperatorBase& /*op*/) {} - - template - void operator()(int n, const In* in, Out* out, Context* c) { - Functor()(n, in, out, c); - } -}; - -/** - * UnaryElementwiseOp is a wrapper around UnaryElementwiseWithArgsOp, with the - * difference that it takes a functor with default constructor, e.g. that does - * not need to take into consideration any arguments during operator creation. - */ -template < - typename InputTypes, - class Context, - class Functor, - class OutputType = SameTypeAsInput> -using UnaryElementwiseOp = UnaryElementwiseWithArgsOp< - InputTypes, - Context, - WithDefaultConstructor, - OutputType>; - -/** - * Performs a binary operation (e.g. +, - or /) with optional broadcast support. - * - * Functor specifies actual operation to be performed. - * - * If AllowBroadcast=false tensors has to be of exactly the same shape. - * - * If AllowBroadcast=true it support limited broadcasting of the right-hand-side - * argument to match the shape of left-hand-side argument. Only suffix matching - * is supported for now, 1-dim expansion doesn't work yet. More precisely - * tensors A and B can be operated on iff - * `shape(A)[-len(shape(B)):] == * shape(B)` - */ -template < - typename InputTypes, - class Context, - class Functor, - class TypeMap = SameTypeAsInput> -class BinaryElementwiseOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - BinaryElementwiseOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(bool, "broadcast", enable_broadcast_, 0), - OP_SINGLE_ARG(int, "axis", axis_, -1), - OP_SINGLE_ARG(string, "axis_str", axis_str_, ""), - OP_SINGLE_ARG(string, "order", order_, "NCHW"), - functor_() { - // Figure out the correct axis to use. - if (enable_broadcast_) { - if (axis_ != -1) { - // Get axis from an explicit axis argument. - CAFFE_ENFORCE_EQ( - axis_str_.size(), - 0, - "Args axis and axis_str cannot be used simultaneously."); - } else if (axis_str_.size()) { - // Get the axis index semantically. - CAFFE_ENFORCE_EQ( - axis_str_.size(), 1, "Unsupported axis string", axis_str_); - size_t semantic_axis_ = order_.find(axis_str_); - CAFFE_ENFORCE_NE( - semantic_axis_, - string::npos, - "Unrecognizable axis string ", - axis_str_, - " from order string ", - order_); - axis_ = semantic_axis_; - } - } else { - CAFFE_ENFORCE( - axis_ == -1 && axis_str_.size() == 0, - "Do not specify axis or axis_str if broadcast is not enabled."); - } - } - - bool RunOnDevice() override { - return DispatchHelper::call(this, Input(0)); - } - - template - bool DoRunWithType() { - const auto& A = Input(0); - const auto& B = Input(1); - auto* C = Output(0); - CAFFE_ENFORCE( - &B != C || !enable_broadcast_, - "In-place is allowed only with the first tensor when broadcasting"); - C->ResizeLike(A); - const T* Adata = A.template data(); - const T* Bdata = B.template data(); - auto* Cdata = - C->template mutable_data>(); - if (!enable_broadcast_) { - CAFFE_ENFORCE_EQ( - A.dims(), - B.dims(), - "Dimension mismatch - did you forget to set broadcast=1?"); - functor_.template Run(A.size(), Adata, Bdata, Cdata, &context_); - } else if (B.size() == 1) { - functor_.template Run(A.size(), Adata, Bdata, Cdata, &context_); - } else { - CAFFE_ENFORCE_GT( - A.ndim(), - B.ndim(), - "If you are doing broadcasting, input1 should have " - "a smaller number of dimensions."); - const int axis = (axis_ == -1 ? A.ndim() - B.ndim() : axis_); - CAFFE_ENFORCE( - axis >= 0 && axis < A.ndim(), - "Broadcast axis should be in the range of the number " - "of dimensions of the first input."); - size_t pre = 1, n = 1, post = 1; - for (int i = 0; i < axis; ++i) { - pre *= A.dim(i); - } - for (int i = 0; i < B.ndim(); ++i) { - CAFFE_ENFORCE_EQ( - A.dim(i + axis), B.dim(i), "Broadcast dimension mismatch."); - n *= B.dim(i); - } - for (int i = axis + B.ndim(); i < A.ndim(); ++i) { - post *= A.dim(i); - } - if (post == 1) { - functor_.RunWithBroadcast(Adata, Bdata, Cdata, pre, n, &context_); - } else { - functor_.RunWithBroadcast2( - Adata, Bdata, Cdata, pre, n, post, &context_); - } - } - return true; - } - - private: - bool enable_broadcast_; - int axis_; - string axis_str_; - string order_; - Functor functor_; -}; - -template -struct WithoutBroadcast { - template - inline void Run(size_t n, const T* a, const T* b, R* out, Context* c) { - if (b_is_scalar) { - CAFFE_THROW("Broadcast not supported."); - } else { - Functor().Run(n, a, b, out, c); - } - } - template - inline void RunWithBroadcast( - const T* /*a*/, - const T* /*b*/, - R* /*out*/, - size_t /*pre*/, - size_t /*n*/, - Context*) { - CAFFE_NOT_IMPLEMENTED; - } - template - inline void RunWithBroadcast2( - const T* /*a*/, - const T* /*b*/, - R* /*out*/, - size_t /*pre*/, - size_t /*n*/, - size_t /*post*/, - Context*) { - CAFFE_NOT_IMPLEMENTED; - } -}; - -// Gradient operator for elementwise division. -template -class DivGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(DivGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; -}; - -namespace SRLHelper { - -template -void sum2one(const T* a, T* y, size_t n); - -template -void RunWithBroadcastFront(const T* a, T* y, size_t pre, size_t n, CPUContext*); - -template -void RunWithBroadcastBack(const T* a, T* y, size_t post, size_t n, CPUContext*); - -template -void RunWithBroadcast2( - const T* a, - T* y, - size_t pre, - size_t n, - size_t post, - CPUContext*); - -} // namespace SRLHelper - -// Sum reduction operator that is used for computing the gradient in cases -// where the forward op is in broadcast mode. -template -class SumReduceLikeOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SumReduceLikeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(int, "axis", axis_, -1), - OP_SINGLE_ARG(string, "axis_str", axis_str_, ""), - OP_SINGLE_ARG(string, "order", order_, "NCHW") { - if (axis_ != -1) { - // Get axis from an explicit axis argument. - CAFFE_ENFORCE_EQ( - axis_str_.size(), - 0, - "Args axis and axis_str cannot be used simultaneously."); - } else if (axis_str_.size()) { - // Get the axis index semantically. - CAFFE_ENFORCE_EQ( - axis_str_.size(), 1, "Unsupported axis string", axis_str_); - size_t semantic_axis = order_.find(axis_str_); - CAFFE_ENFORCE_NE( - semantic_axis, - string::npos, - "Unrecognizable axis string ", - axis_str_, - " from order string ", - order_); - axis_ = semantic_axis; - } - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType(); - - private: - int axis_; - string axis_str_; - string order_; - Tensor ones_; - Tensor sum_buffer_; -}; - -template -bool DivGradientOp::RunOnDevice() { - auto& Y = Input(0); - auto& Z = Input(1); - auto& dZ = Input(2); - auto* dX = Output(0); - auto* dY = Output(1); - CAFFE_ENFORCE_GT(Y.size(), 0); - CAFFE_ENFORCE_GT(Z.size(), 0); - dX->ResizeLike(Y); - dY->ResizeLike(Y); - - const float* Ydata = Y.template data(); - const float* Zdata = Z.template data(); - const float* dZdata = dZ.template data(); - float* dXdata = dX->template mutable_data(); - float* dYdata = dY->template mutable_data(); - - ElementWiseDivide(context_, Y.size(), dXdata, dYdata, dZdata, Ydata, Zdata); - return true; -} - -// For arithmetic operators, Eigen provides a good way to vectorize even -// when broadcasting. -#define EIGEN_FUNCTOR(name, eigen_op, input_type, output_type) \ - struct Eigen##name##Functor { \ - template \ - inline void Run(size_t n, const T* a, const T* b, R* out, CPUContext*) { \ - if (b_is_scalar) { \ - EigenVectorArrayMap(out, n) = \ - eigen_op((ConstEigenVectorArrayMap(a, n)), (b[0])); \ - } else { \ - EigenVectorArrayMap(out, n) = eigen_op( \ - (ConstEigenVectorArrayMap(a, n)), \ - (ConstEigenVectorArrayMap(b, n))); \ - } \ - } \ - template \ - void RunWithBroadcast( \ - const T* a, \ - const T* b, \ - R* out, \ - size_t pre, \ - size_t n, \ - CPUContext*) { \ - EigenArrayMap(out, n, pre) = eigen_op( \ - (ConstEigenArrayMap(a, n, pre).colwise()), \ - (ConstEigenVectorArrayMap(b, n))); \ - } \ - template \ - void RunWithBroadcast2( \ - const T* a, \ - const T* b, \ - R* out, \ - size_t pre, \ - size_t n, \ - size_t post, \ - CPUContext*) { \ - for (int i = 0; i < pre; ++i) { \ - EigenArrayMap(out + i * n * post, post, n) = eigen_op( \ - (ConstEigenArrayMap(a + i * n * post, post, n).rowwise()), \ - (Eigen::Map>(b, n))); \ - } \ - } \ - }; \ - REGISTER_CPU_OPERATOR( \ - name, \ - BinaryElementwiseOp< \ - input_type, \ - CPUContext, \ - Eigen##name##Functor, \ - output_type>) - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ELEMENTWISE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/elementwise_op_test.h b/app/src/main/cpp/caffe2/operators/elementwise_op_test.h deleted file mode 100644 index c4f7429..0000000 --- a/app/src/main/cpp/caffe2/operators/elementwise_op_test.h +++ /dev/null @@ -1,248 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ELEMENTWISE_OP_TEST_H_ -#define CAFFE2_OPERATORS_ELEMENTWISE_OP_TEST_H_ - -#include -#include -#include - -#include "caffe2/operators/elementwise_op.h" -#include - -template -void CopyVector(const int N, const T* x, T* y); - -template -void FillTensor( - caffe2::Workspace* ws, - const std::string& name, - const std::vector& shape, - const std::vector& values) { - auto* blob = ws->CreateBlob(name); - auto* tensor = blob->GetMutable>(); - tensor->Resize(shape); - auto* mutable_data = tensor->template mutable_data(); - const O_Type* data = reinterpret_cast(values.data()); - CopyVector(values.size(), data, mutable_data); -} - -template -caffe2::OperatorDef CreateOperatorDef() { - caffe2::OperatorDef def; - return def; -} - -template -caffe2::OperatorDef DefineOperator(const std::string& op_type) { - caffe2::OperatorDef def = CreateOperatorDef(); - def.set_name("test"); - def.set_type(op_type); - def.add_input("X"); - def.add_input("Y"); - def.add_output("Z"); - return def; -} - -template -void elementwiseAnd() { - const int N = 4; - const int M = 2; - caffe2::Workspace ws; - auto def = DefineOperator("And"); - { // equal size - FillTensor( - &ws, "X", {N}, {true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), N); - std::vector result{true, false, false, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } - { // broadcast - auto* arg = def.add_arg(); - arg->set_name("broadcast"); - arg->set_i(1); - FillTensor( - &ws, "X", {M, N}, {true, false, true, false, true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), M * N); - std::vector result{ - true, false, false, false, true, false, false, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } -} - -template -void elementwiseOr() { - const int N = 4; - const int M = 2; - caffe2::Workspace ws; - auto def = DefineOperator("Or"); - { // equal size - FillTensor( - &ws, "X", {N}, {true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), N); - std::vector result{true, true, true, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } - { // broadcast - auto* arg = def.add_arg(); - arg->set_name("broadcast"); - arg->set_i(1); - FillTensor( - &ws, "X", {M, N}, {true, false, true, false, true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), M * N); - std::vector result{true, true, true, false, true, true, true, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } -} - -template -void elementwiseXor() { - const int N = 4; - const int M = 2; - caffe2::Workspace ws; - auto def = DefineOperator("Xor"); - { // equal size - FillTensor( - &ws, "X", {N}, {true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), N); - std::vector result{false, true, true, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } - { // broadcast - auto* arg = def.add_arg(); - arg->set_name("broadcast"); - arg->set_i(1); - FillTensor( - &ws, "X", {M, N}, {true, false, true, false, true, false, true, false}); - FillTensor( - &ws, "Y", {N}, {true, true, false, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), M * N); - std::vector result{ - false, true, true, false, false, true, true, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } -} - -template -void elementwiseNot() { - const int N = 2; - caffe2::Workspace ws; - caffe2::OperatorDef def = CreateOperatorDef(); - def.set_name("test"); - def.set_type("Not"); - def.add_input("X"); - def.add_output("Y"); - FillTensor(&ws, "X", {N}, {true, false}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Y"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Y(blob->Get>()); - EXPECT_EQ(Y.size(), N); - std::vector result{false, true}; - for (size_t i = 0; i < Y.size(); ++i) { - EXPECT_EQ(Y.template data()[i], result[i]); - } -} - -template -void elementwiseEQ() { - const int N = 4; - const int M = 2; - caffe2::Workspace ws; - auto def = DefineOperator("EQ"); - { // equal size - FillTensor(&ws, "X", {N}, {1, 100, 5, -10}); - FillTensor(&ws, "Y", {N}, {0, 100, 4, -10}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), N); - std::vector result{false, true, false, true}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } - { // broadcast - auto* arg = def.add_arg(); - arg->set_name("broadcast"); - arg->set_i(1); - FillTensor( - &ws, "X", {M, N}, {1, 100, 5, -10, 3, 6, -1000, 33}); - FillTensor(&ws, "Y", {N}, {1, 6, -1000, -10}); - std::unique_ptr op(caffe2::CreateOperator(def, &ws)); - EXPECT_NE(nullptr, op.get()); - EXPECT_TRUE(op->Run()); - auto* blob = ws.GetBlob("Z"); - EXPECT_NE(nullptr, blob); - caffe2::TensorCPU Z(blob->Get>()); - EXPECT_EQ(Z.size(), M * N); - std::vector result{ - true, false, false, true, false, true, true, false}; - for (size_t i = 0; i < Z.size(); ++i) { - EXPECT_EQ(Z.template data()[i], result[i]); - } - } -} - -#endif // CAFFE2_OPERATORS_ELEMENTWISE_OP_TEST_H_ diff --git a/app/src/main/cpp/caffe2/operators/elu_op.h b/app/src/main/cpp/caffe2/operators/elu_op.h deleted file mode 100644 index 0f2e7e7..0000000 --- a/app/src/main/cpp/caffe2/operators/elu_op.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class EluOp final : public Operator { - public: - EluOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - alpha_(OperatorBase::GetSingleArgument("alpha", 1.0)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T alpha_; -}; - -template -class EluGradientOp final : public Operator { - public: - EluGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - alpha_(OperatorBase::GetSingleArgument("alpha", 1.0)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T alpha_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/feed_blob_op.h b/app/src/main/cpp/caffe2/operators/feed_blob_op.h deleted file mode 100644 index 4121214..0000000 --- a/app/src/main/cpp/caffe2/operators/feed_blob_op.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FEED_BLOB_OP_H_ -#define CAFFE2_OPERATORS_FEED_BLOB_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class FeedBlobOp : public Operator { - public: - FeedBlobOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) { - CAFFE_ENFORCE( - OperatorBase::HasSingleArgumentOfType("value"), - "value argument must exist and be passed as a string"); - value_ = OperatorBase::GetSingleArgument("value", ""); - } - - bool RunOnDevice() override { - *OperatorBase::Output(0) = value_; - return true; - } - - private: - std::string value_; -}; - -} // namespace caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/operators/filler_op.h b/app/src/main/cpp/caffe2/operators/filler_op.h deleted file mode 100644 index d17bd0e..0000000 --- a/app/src/main/cpp/caffe2/operators/filler_op.h +++ /dev/null @@ -1,540 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FILLER_OP_H_ -#define CAFFE2_OPERATORS_FILLER_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// FillerOp takes in either zero or one input. -// -// If the number of input is 1, the shape will be identical to that of the input -// at run time with optional additional dimensions appended at the end as -// specified by "extra_shape" argument. In that case the "shape" parameter -// should not be set. -// -// If the number of inputs is 0, the full shape must be provided via "shape" -// argument -template -class FillerOp : public Operator { - public: - FillerOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - shape_(ToVectorTIndex(OperatorBase::GetRepeatedArgument("shape"))), - extra_shape_(ToVectorTIndex( - OperatorBase::GetRepeatedArgument("extra_shape"))), - input_as_shape_( - OperatorBase::GetSingleArgument("input_as_shape", false)) { - if (InputSize()) { - if (shape_.size() != 0) { - CAFFE_THROW( - "Cannot set the shape argument and pass in an input at " - "the same time"); - } - } else { - if (!extra_shape_.empty()) { - CAFFE_THROW("Cannot set extra_shape when there is no input"); - } - if (input_as_shape_) { - CAFFE_THROW("An input must be given if input_as_shape is true"); - } - if (shape_.size() == 0 && - OperatorBase::HasSingleArgumentOfType("shape")) { - CAFFE_THROW("Fill 'shape' argument was a scalar, list expected"); - } - } - } - - virtual ~FillerOp() {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto* output = Operator::Output(0); - if (InputSize()) { - auto shape = vector{}; - if (input_as_shape_) { - // Shape input must be in CPU context - auto& input = OperatorBase::Input>(0); - CAFFE_ENFORCE_EQ( - input.ndim(), - 1, - "When input_as_shape is true, the input must be a 1D tensor of " - "data type TIndex"); - auto* shape_data = input.template data(); - shape.insert(shape.end(), shape_data, shape_data + input.dim32(0)); - } else { - auto& input = Input(0); - shape.insert(shape.end(), input.dims().begin(), input.dims().end()); - } - shape.insert(shape.end(), extra_shape_.begin(), extra_shape_.end()); - output->Resize(shape); - } else { - output->Resize(shape_); - } - return Fill(output); - } - - virtual bool Fill(Tensor* output) = 0; - - protected: - vector shape_; - vector extra_shape_; - bool input_as_shape_; -}; - -template -class UniformFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - UniformFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws), - min_(OperatorBase::template GetSingleArgument("min", 0)), - max_(OperatorBase::template GetSingleArgument("max", 1)) { - if (InputSize() == 3) { - CAFFE_ENFORCE( - !OperatorBase::HasSingleArgumentOfType("min"), - "Cannot set both min arg and min input blob"); - CAFFE_ENFORCE( - !OperatorBase::HasSingleArgumentOfType("max"), - "Cannot set both max arg and max input blob"); - } else { - CAFFE_ENFORCE_LT( - min_, max_, "Max value should be bigger than min value."); - } - } - - bool Fill(Tensor* output) override { - T min = min_; - T max = max_; - if (InputSize() == 3) { - CAFFE_ENFORCE_EQ(1, Input(1).size(), "min blob must be scalar"); - CAFFE_ENFORCE_EQ(1, Input(2).size(), "max blob must be scalar"); - min = *Input(1).template data(); - max = *Input(2).template data(); - if (min > max) { - auto shape = output->dims(); - shape[0] = 0; - output->Resize(shape); - output->template mutable_data(); - return true; - } - } - math::RandUniform( - output->size(), - min, - max, - output->template mutable_data(), - &context_); - return true; - } - - private: - T min_; - T max_; -}; - -template -class UniqueUniformFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - UniqueUniformFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) { - TensorProto_DataType dtype = - static_cast(OperatorBase::GetSingleArgument( - "dtype", TensorProto_DataType_INT32)); - - switch (dtype) { - case TensorProto_DataType_INT32: - CheckRange(); - body_ = &UniqueUniformFillOp::FillWithType; - break; - case TensorProto_DataType_INT64: - CheckRange(); - body_ = &UniqueUniformFillOp::FillWithType; - break; - case TensorProto_DataType_UNDEFINED: - CAFFE_THROW( - "UniqueUniformFill op cannot have undefined 'dtype' argument"); - // break; - default: - CAFFE_THROW("Unexpected 'dtype' argument value: ", dtype); - } - } - - bool Fill(Tensor* output) override { - return (this->*body_)(output); - } - - private: - template - void CheckRange() { - CAFFE_ENFORCE(OperatorBase::HasSingleArgumentOfType("min")); - CAFFE_ENFORCE(OperatorBase::HasSingleArgumentOfType("max")); - CAFFE_ENFORCE_LT( - OperatorBase::GetSingleArgument("min", 0), - OperatorBase::GetSingleArgument("max", 0), - "Max value should be bigger than min value."); - } - - template - bool FillWithType(Tensor* output) { - T min = OperatorBase::GetSingleArgument("min", 0); - T max = OperatorBase::GetSingleArgument("max", 0); - - const T* avoid_data = nullptr; - size_t avoid_size = 0; - if (InputSize() >= 2) { - auto& avoid = Input(1); - avoid_data = avoid.template data(); - avoid_size = avoid.size(); - } - math::RandUniformUnique( - output->size(), - min, - max, - output->template mutable_data(), - avoid_size, - avoid_data, - &context_); - return true; - } - - bool (UniqueUniformFillOp::*body_)(Tensor* output); -}; - -template -class ConstantFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ConstantFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) { - TensorProto_DataType dtype = - static_cast(OperatorBase::GetSingleArgument( - "dtype", TensorProto_DataType_FLOAT)); - - if (!OperatorBase::HasArgument("dtype") && - OperatorBase::HasArgument("value")) { - // If 'dtype' is not provided, infer type based on the type of 'value' - // Currently, single argument contains either float, int64 or bytes - if (OperatorBase::HasSingleArgumentOfType("value")) { - dtype = TensorProto_DataType_FLOAT; - } else if (OperatorBase::HasSingleArgumentOfType("value")) { - dtype = TensorProto_DataType_INT64; - } else { - CAFFE_THROW("Argument 'value' is of unexpected type"); - } - VLOG(1) << "Argument 'dtype' is not provided. Assume the data type is " - << "the same as that of argument 'value': " << dtype; - } - - switch (dtype) { - case TensorProto_DataType_FLOAT: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_DOUBLE: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_BOOL: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_INT8: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_INT16: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_INT32: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_INT64: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_UINT8: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_UINT16: - body_ = &ConstantFillOp::FillWithType; - break; - case TensorProto_DataType_STRING: - body_ = &ConstantFillOp::FillWithString; - break; - case TensorProto_DataType_UNDEFINED: - CAFFE_THROW("ConstantFill op cannot have undefined 'dtype' argument"); - // break; - default: - CAFFE_THROW("Unexpected 'dtype' argument value: ", dtype); - } - } - - bool Fill(Tensor* output) override { - return (this->*body_)(output); - } - - template - bool FillWithType(Tensor* output) { - T value = OperatorBase::GetSingleArgument("value", 0); - auto* data = output->template mutable_data(); - if (output->size()) { - math::Set(output->size(), value, data, &context_); - } - return true; - } - - bool FillWithString(Tensor* output) { - auto value = OperatorBase::GetSingleArgument("value", ""); - auto* data = output->template mutable_data(); - for (int i = 0; i < output->size(); ++i) { - data[i] = value; - } - return true; - } - - private: - bool (ConstantFillOp::*body_)(Tensor* output); -}; - -template -class DiagonalFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - DiagonalFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) { - TensorProto_DataType dtype = - static_cast(OperatorBase::GetSingleArgument( - "dtype", TensorProto_DataType_FLOAT)); - - if (!OperatorBase::HasArgument("dtype") && - OperatorBase::HasArgument("value")) { - // If 'dtype' is not provided, infer type based on the type of 'value' - // Currently, single argument contains either float, int64 or bytes - if (OperatorBase::HasSingleArgumentOfType("value")) { - dtype = TensorProto_DataType_FLOAT; - } else if (OperatorBase::HasSingleArgumentOfType("value")) { - dtype = TensorProto_DataType_INT64; - } else { - CAFFE_THROW("Argument 'value' is of unexpected type"); - } - VLOG(1) << "Argument 'dtype' is not provided. Assume the data type is " - << "the same as that of argument 'value': " << dtype; - } - - switch (dtype) { - case TensorProto_DataType_FLOAT: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_DOUBLE: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_BOOL: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_INT8: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_INT16: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_INT32: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_INT64: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_UINT8: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_UINT16: - body_ = &DiagonalFillOp::FillWithType; - break; - case TensorProto_DataType_UNDEFINED: - CAFFE_THROW("Cannot have undefined 'dtype' argument"); - default: - CAFFE_THROW("Unexpected 'dtype' argument value: ", dtype); - } - } - - bool Fill(Tensor* output) override { - return (this->*body_)(output); - } - - template - bool FillWithType(Tensor* output); - - private: - void VerifyOutputShape(Tensor* output) { - CAFFE_ENFORCE(output->ndim() >= 2, "Input shape must be >= 2D"); - } - - TIndex GetStepSize(Tensor* output) { - TIndex step; - if (output->ndim() == 2) { - step = output->dim(1) + 1; - } else { - TIndex prev_i = output->dim(0); - for (auto i : output->dims()) { - if (i != prev_i) { - CAFFE_THROW("All dimensions of input must be of equal length"); - } - } - vector cumprod(output->ndim()); - auto dims = output->dims(); - std::partial_sum( - dims.begin(), - dims.end() - 1, - cumprod.begin(), - std::multiplies()); - step = 1 + - std::accumulate( - cumprod.begin(), cumprod.end(), static_cast(0)); - VLOG(0) << step; - } - return step; - } - - bool (DiagonalFillOp::*body_)(Tensor* output); -}; - -template -class GaussianFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - GaussianFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws), - mean_(OperatorBase::template GetSingleArgument("mean", 0)), - std_(OperatorBase::template GetSingleArgument("std", 1)) { - DCHECK_GT(std_, 0) << "Standard deviation should be nonnegative."; - } - - bool Fill(Tensor* output) override { - math::RandGaussian( - output->size(), - mean_, - std_, - output->template mutable_data(), - &context_); - return true; - } - - private: - T mean_; - T std_; -}; - -template -class XavierFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - XavierFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) {} - - bool Fill(Tensor* output) override { - const int fan_in = output->size() / output->dim32(0); - T scale = std::sqrt(T(3) / fan_in); - math::RandUniform( - output->size(), - -scale, - scale, - output->template mutable_data(), - &context_); - return true; - } -}; - -template -class MSRAFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MSRAFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) {} - - bool Fill(Tensor* output) override { - const int fan_out = output->size() / output->dim32(1); - T scale = std::sqrt(T(2) / fan_out); - math::RandGaussian( - output->size(), - 0.0, - scale, - output->template mutable_data(), - &context_); - return true; - } -}; - -// This is mostly used just as a debugging purpose stuff: it fills a tensor -// sequentially with values 0, 1, 2..., which can then be used to check e.g. -// reshape operations by allowing one to read the indices more easily. -template -class RangeFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RangeFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) {} - - bool Fill(Tensor* output) override; -}; - -template -class LengthsRangeFillOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsRangeFillOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - auto* input_data = input.template data(); - - CAFFE_ENFORCE_EQ(input.ndim(), 1, "Input must be a vector."); - - auto len_sum = std::accumulate(input_data, input_data + input.size(), 0); - - output->Resize(len_sum); - auto* output_data = output->template mutable_data(); - - int32_t offset = 0; - for (int i = 0; i < input.size(); ++i) { - auto len = input_data[i]; - auto start = output_data + offset; - std::iota( - start, - start + len, - 0); // make the third argument the arg of this operator - offset += len; - } - return true; - } -}; - -inline std::vector FillerTensorInference( - const OperatorDef& def, - const vector& in) { - vector out(1); - ArgumentHelper helper(def); - out[0].set_data_type(static_cast( - helper.GetSingleArgument("dtype", TensorProto_DataType_FLOAT))); - - if (in.size()) { - // TODO - bool input_as_shape = - helper.GetSingleArgument("input_as_shape", false); - if (input_as_shape) { - out[0].set_unknown_shape(true); - return out; - } - for (int d : in[0].dims()) { - out[0].add_dims(d); - } - } else { - auto shape = helper.GetRepeatedArgument("shape"); - for (int d : shape) { - out[0].add_dims(d); - } - } - return out; -} - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FILLER_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/find_duplicate_elements_op.h b/app/src/main/cpp/caffe2/operators/find_duplicate_elements_op.h deleted file mode 100644 index 3dd89db..0000000 --- a/app/src/main/cpp/caffe2/operators/find_duplicate_elements_op.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H -#define CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H - -#include -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -template -class FindDuplicateElementsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(FindDuplicateElementsOp); - USE_DISPATCH_HELPER; - - bool RunOnDevice() override { - return DispatchHelper>:: - call(this, Input(0)); - } - - template - bool DoRunWithType() { - const auto& data = Input(0); - CAFFE_ENFORCE(data.ndim() == 1, "data should be 1-D."); - - const auto* data_ptr = data.template data(); - std::unordered_map dict; - std::vector dupIndices; - // i is the index of unique elements, j is the index of all elements - for (int64_t i = 0, j = 0; j < data.dims()[0]; ++i, ++j) { - bool retVal = dict.insert({data_ptr[j], i}).second; - if (!retVal) { - --i; - dupIndices.push_back(j); - } - } - - const auto dupSize = dupIndices.size(); - auto* output = Output(0); - output->Resize(dupSize); - auto* out_ptr = output->template mutable_data(); - for (int64_t i = 0; i < dupSize; ++i) { - out_ptr[i] = dupIndices[i]; - } - - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FIND_DUPLICATE_ELEMENTS_OP_H diff --git a/app/src/main/cpp/caffe2/operators/find_op.h b/app/src/main/cpp/caffe2/operators/find_op.h deleted file mode 100644 index 8ba28a8..0000000 --- a/app/src/main/cpp/caffe2/operators/find_op.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FIND_OP_H_ -#define CAFFE2_OPERATORS_FIND_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -#include - -namespace caffe2 { - -template -class FindOp final : public Operator { - public: - FindOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - missing_value_( - OperatorBase::GetSingleArgument("missing_value", -1)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - - bool RunOnDevice() { - return DispatchHelper>::call(this, Input(0)); - } - - protected: - template - bool DoRunWithType() { - auto& idx = Input(0); - auto& needles = Input(1); - auto* res_indices = Output(0); - res_indices->ResizeLike(needles); - - const T* idx_data = idx.template data(); - const T* needles_data = needles.template data(); - T* res_data = res_indices->template mutable_data(); - auto idx_size = idx.size(); - - // Use an arbitrary cut-off for when to use brute-force - // search. For larger needle sizes we first put the - // index into a map - if (needles.size() < 16) { - // Brute force O(nm) - for (int i = 0; i < needles.size(); i++) { - T x = needles_data[i]; - T res = static_cast(missing_value_); - for (int j = idx_size - 1; j >= 0; j--) { - if (idx_data[j] == x) { - res = j; - break; - } - } - res_data[i] = res; - } - } else { - // O(n + m) - std::unordered_map idx_map; - for (int j = 0; j < idx_size; j++) { - idx_map[idx_data[j]] = j; - } - for (int i = 0; i < needles.size(); i++) { - T x = needles_data[i]; - auto it = idx_map.find(x); - res_data[i] = (it == idx_map.end() ? missing_value_ : it->second); - } - } - - return true; - } - - protected: - int missing_value_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FIND_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/free_op.h b/app/src/main/cpp/caffe2/operators/free_op.h deleted file mode 100644 index 7fc38ae..0000000 --- a/app/src/main/cpp/caffe2/operators/free_op.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FREE_OP_H_ -#define CAFFE2_OPERATORS_FREE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// FreeOp frees the content of the output blob. We allow it to take in input -// blobs purely for the reason that it can "wait" on the input blobs to be -// produced by some of the earlier operators before a free is called. -template -class FreeOp : public Operator { - public: - FreeOp(const OperatorDef& def, Workspace* ws) : Operator(def, ws) {} - - bool RunOnDevice() override { - for (Blob* output : OperatorBase::Outputs()) { - output->Reset(); - } - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FREE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/fully_connected_op.h b/app/src/main/cpp/caffe2/operators/fully_connected_op.h deleted file mode 100644 index 8bd972f..0000000 --- a/app/src/main/cpp/caffe2/operators/fully_connected_op.h +++ /dev/null @@ -1,270 +0,0 @@ -#ifndef CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ -#define CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/conversions.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// This is Caffe's InnerProductOp, with a name that fits its purpose better. -template -class FullyConnectedOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)), - axis_w_(OperatorBase::GetSingleArgument("axis_w", 1)) {} - ~FullyConnectedOp() {} - - template < - typename T_X, - typename T_W, - typename T_B, - typename T_Y, - typename MATH> - bool DoRunWithType() { - const auto& X = Input(0); - const auto& W = Input(1); - const auto& b = Input(2); - auto* Y = Output(0); - CAFFE_ENFORCE(b.ndim() == 1, b.ndim()); - // batch size - const auto canonical_axis = X.canonical_axis_index(axis_); - const auto M = X.size_to_dim(canonical_axis); - const auto K = X.size_from_dim(canonical_axis); - const auto canonical_axis_w = W.canonical_axis_index(axis_w_); - const int N = W.size_to_dim(canonical_axis_w); - - auto dimErrorString = [&]() { - return MakeString( - "Dimension mismatch: ", - "X: ", - X.dims(), - ", W: ", - W.dims(), - ", b: ", - b.dims(), - ", axis: ", - axis_, - ", M: ", - M, - ", N: ", - N, - ", K: ", - K); - }; - - // Error checking - CAFFE_ENFORCE(M == X.size() / K, dimErrorString()); - CAFFE_ENFORCE(K == W.size() / N, dimErrorString()); - CAFFE_ENFORCE(N == b.dim32(0), dimErrorString()); - CAFFE_ENFORCE(N == b.size(), dimErrorString()); - - Y_shape_cache_ = X.dims(); - // This is an invariant of canonical_axis, so we can DCHECK. - DCHECK_LE(canonical_axis + 1, Y_shape_cache_.size()); - Y_shape_cache_.resize(canonical_axis + 1); - Y_shape_cache_[canonical_axis] = N; - Y->Resize(Y_shape_cache_); - CAFFE_ENFORCE(M * N == Y->size(), dimErrorString()); - - if (X.size() == 0) { - // skip the rest of the computation if X is empty - Y->template mutable_data(); - return true; - } - - // W * x - math::Gemm( - CblasNoTrans, - CblasTrans, - M, - N, - K, - 1, - X.template data(), - W.template data(), - 0, - Y->template mutable_data(), - &context_); - // Add bias term - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(M); - math::Set( - M, - convert::To(1), - bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, - CblasNoTrans, - M, - N, - 1, - 1, - bias_multiplier_.template data(), - b.template data(), - 1, - Y->template mutable_data(), - &context_); - return true; - } - - bool RunOnDevice() override { - return DoRunWithType< - float, // X - float, // W - float, // B - float, // Y - float>(); // Math - } - - protected: - size_t axis_{1}; - size_t axis_w_{1}; - // A local vector to cache the output shape so we don't need to recreate - // a vector object every time we run Run(). - vector Y_shape_cache_; - Tensor bias_multiplier_; -}; - -template -class FullyConnectedGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FullyConnectedGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)), - axis_w_(OperatorBase::GetSingleArgument("axis_w", 1)) {} - ~FullyConnectedGradientOp() {} - - template < - typename T_X, - typename T_W, - typename T_DY, - typename T_B, - typename T_DX, - typename T_DW, - typename T_DB, - typename MATH> - bool DoRunWithType() { - const auto& X = Input(0); - const auto& W = Input(1); - const auto& dY = Input(2); - // batch size - const auto canonical_axis = X.canonical_axis_index(axis_); - const int M = X.size_to_dim(canonical_axis); - const int K = X.size_from_dim(canonical_axis); - const auto canonical_axis_w = W.canonical_axis_index(axis_w_); - const int N = W.size_to_dim(canonical_axis_w); - CAFFE_ENFORCE(M * K == X.size()); - CAFFE_ENFORCE(K * N == W.size()); - - auto* dW = Output(0); - auto* db = Output(1); - dW->ResizeLike(W); - db->Resize(N); - - if (X.size() == 0) { - // generate a zero blob for db and dW when X is empty - math::Set( - db->size(), - convert::To(0), - db->template mutable_data(), - &context_); - math::Set( - dW->size(), - convert::To(0), - dW->template mutable_data(), - &context_); - - if (OutputSize() == 3) { - auto* dX = Output(2); - dX->ResizeLike(X); - dX->template mutable_data(); - } - - return true; - } - - // Compute dW - math::Gemm( - CblasTrans, - CblasNoTrans, - N, - K, - M, - convert::To(1), - dY.template data(), - X.template data(), - convert::To(0), - dW->template mutable_data(), - &context_); - if (bias_multiplier_.size() != M) { - // If the helper bias multiplier is not M, reshape and fill it - // with one. - bias_multiplier_.Resize(M); - math::Set( - M, - convert::To(1), - bias_multiplier_.template mutable_data(), - &context_); - } - // Compute dB - math::Gemv( - CblasTrans, - M, - N, - convert::To(1), - dY.template data(), - bias_multiplier_.template data(), - convert::To(0), - db->template mutable_data(), - &context_); - - // Compute dX - if (OutputSize() == 3) { - auto* dX = Output(2); - dX->ResizeLike(X); - math::Gemm( - CblasNoTrans, - CblasNoTrans, - M, - K, - N, - convert::To(1), - dY.template data(), - W.template data(), - convert::To(0), - dX->template mutable_data(), - &context_); - } - return true; - } - - bool RunOnDevice() override { - return DoRunWithType< - float, // X - float, // W - float, // dY - float, // B - float, // dX - float, // dW - float, // dB - float>(); // Math - } - - protected: - size_t axis_{1}; - size_t axis_w_{1}; - Tensor bias_multiplier_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_FULLY_CONNECTED_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/given_tensor_fill_op.h b/app/src/main/cpp/caffe2/operators/given_tensor_fill_op.h deleted file mode 100644 index 5994ad7..0000000 --- a/app/src/main/cpp/caffe2/operators/given_tensor_fill_op.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/filler_op.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class GivenTensorFillOp final : public FillerOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - GivenTensorFillOp(const OperatorDef& operator_def, Workspace* ws) - : FillerOp(operator_def, ws) { - auto source_values = - OperatorBase::template GetRepeatedArgument("values"); - values_.Resize(source_values.size()); - T* values_data = values_.template mutable_data(); - for (int i = 0; i < source_values.size(); i++) { - values_data[i] = static_cast(source_values[i]); - } - } - - bool Fill(Tensor* output) override { - DCHECK_EQ(output->size(), values_.size()) - << "output size: " << output->size() - << " given size: " << values_.size(); - auto* data = output->template mutable_data(); - const T* values_data = values_.template data(); - if (output->size()) { - context_.template Copy( - output->size(), values_data, data); - } - return true; - } - - private: - TensorCPU values_; -}; -} diff --git a/app/src/main/cpp/caffe2/operators/gru_unit_op.h b/app/src/main/cpp/caffe2/operators/gru_unit_op.h deleted file mode 100644 index 34c25bc..0000000 --- a/app/src/main/cpp/caffe2/operators/gru_unit_op.h +++ /dev/null @@ -1,216 +0,0 @@ -#ifndef CAFFE2_OPERATORS_GRU_UNIT_OP_H_ -#define CAFFE2_OPERATORS_GRU_UNIT_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { -namespace detail { - -template -inline T sigmoid(T x) { - return 1.0f / (1.0f + exp(-x)); -} - -template -inline T host_tanh(T x) { - return 2.0f * sigmoid(2.0f * x) - 1.0f; -} - -template -void GRUUnit( - int N, - int D, - int t, - const T* H_prev, - const T* X, - const int32_t* seqLengths, - bool drop_states, - T* H, - Context* /*context*/) { - for (int n = 0; n < N; ++n) { - const bool valid = t < seqLengths[n]; - - for (int d = 0; d < D; ++d) { - if (!valid) { - if (drop_states) { - H[d] = 0; - } else { - H[d] = H_prev[d]; - } - } else { - const T update = X[1 * D + d]; - const T output = X[2 * D + d]; - T sigmoid_update = sigmoid(update); - H[d] = H_prev[d] * sigmoid_update + - host_tanh(output) * (1.0f - sigmoid_update); - } - } - - H_prev += D; - X += 3 * D; - H += D; - } -} - -template -void GRUUnitGradient( - int N, - int D, - int t, - const T* H_prev, - const T* X, - const int32_t* seqLengths, - const T* H, - const T* H_diff, - bool drop_states, - T* H_prev_diff, - T* X_diff, - Context* /*context*/) { - for (int n = 0; n < N; ++n) { - const bool valid = t < seqLengths[n]; - - for (int d = 0; d < D; ++d) { - T* h_prev_diff = H_prev_diff + d; - T* reset_diff = X_diff + 0 * D + d; - T* update_diff = X_diff + 1 * D + d; - T* output_diff = X_diff + 2 * D + d; - - if (!valid) { - if (drop_states) { - *h_prev_diff = 0; - } else { - *h_prev_diff = H_diff[d]; - } - *reset_diff = 0; - *update_diff = 0; - *output_diff = 0; - } else { - // Calculate Gate Outputs - const T u = sigmoid(X[1 * D + d]); - const T o = host_tanh(X[2 * D + d]); - - *h_prev_diff = H_diff[d] * u; - *reset_diff = 0; // 0 contribution to gradient from this operation - *update_diff = (H_diff[d] * H_prev[d] - H_diff[d] * o) * u * (1.0f - u); - *output_diff = H_diff[d] * (1.0f - u) * (1.0f - o * o); - } - } - - H_prev += D; - X += 3 * D; - H += D; - H_diff += D; - X_diff += 3 * D; - H_prev_diff += D; - } -} - -} // namespace detail - -template -class GRUUnitOp : public Operator { - public: - GRUUnitOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - drop_states_(OperatorBase::template GetSingleArgument( - "drop_states", - false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - // Extract N - const auto N = Input(HIDDEN_T_M_1).dim(1); - - // Gates: 1xNxG - const auto G = Input(GATES).dim(2); - const auto D = Input(HIDDEN_T_M_1).dim(2); - - CAFFE_ENFORCE_EQ(3 * D, G); - const auto* H_prev = Input(HIDDEN_T_M_1).template data(); - const auto* X = Input(GATES).template data(); - CAFFE_ENFORCE_EQ(Input(SEQ_LENGTHS).size(), N); - const auto* seqLengths = Input(SEQ_LENGTHS).template data(); - const auto t = OperatorBase::Input>(TIMESTEP) - .template data()[0]; - Output(HIDDEN_T)->ResizeLike(Input(HIDDEN_T_M_1)); - auto* H = Output(HIDDEN_T)->template mutable_data(); - - detail::GRUUnit( - N, D, t, H_prev, X, seqLengths, drop_states_, H, &context_); - return true; - } - - protected: - INPUT_TAGS(HIDDEN_T_M_1, GATES, SEQ_LENGTHS, TIMESTEP); - OUTPUT_TAGS(HIDDEN_T); - - private: - bool drop_states_; -}; - -template -class GRUUnitGradientOp : public Operator { - public: - GRUUnitGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - drop_states_(OperatorBase::template GetSingleArgument( - "drop_states", - false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - // Extract N - const auto N = Input(HIDDEN_T_M_1).dim(1); - - // Gates: 1xNxG - const auto G = Input(GATES).dim(2); - const auto D = Input(HIDDEN_T_M_1).dim(2); - - CAFFE_ENFORCE_EQ(3 * D, G); - const auto* H_prev = Input(HIDDEN_T_M_1).template data(); - const auto* X = Input(GATES).template data(); - const auto t = OperatorBase::Input>(TIMESTEP) - .template data()[0]; - const auto* H = Input(HIDDEN_T).template data(); - const auto* H_diff = Input(HIDDEN_T_GRAD).template data(); - const auto* seqLengths = Input(SEQ_LENGTHS).template data(); - Output(HIDDEN_T_M_1_GRAD)->ResizeLike(Input(HIDDEN_T_M_1)); - auto* H_prev_diff = Output(HIDDEN_T_M_1_GRAD)->template mutable_data(); - Output(GATES_GRAD)->ResizeLike(Input(GATES)); - auto* X_diff = Output(GATES_GRAD)->template mutable_data(); - - detail::GRUUnitGradient( - N, - D, - t, - H_prev, - X, - seqLengths, - H, - H_diff, - drop_states_, - H_prev_diff, - X_diff, - &context_); - return true; - } - - protected: - INPUT_TAGS( - HIDDEN_T_M_1, - GATES, - SEQ_LENGTHS, - TIMESTEP, - HIDDEN_T, - HIDDEN_T_GRAD, ); - OUTPUT_TAGS(HIDDEN_T_M_1_GRAD, GATES_GRAD); - - private: - bool drop_states_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_GRU_UNIT_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/h_softmax_op.h b/app/src/main/cpp/caffe2/operators/h_softmax_op.h deleted file mode 100644 index 176bae8..0000000 --- a/app/src/main/cpp/caffe2/operators/h_softmax_op.h +++ /dev/null @@ -1,175 +0,0 @@ -#ifndef CAFFE2_OPERATORS_H_SOFTMAX_OP_H_ -#define CAFFE2_OPERATORS_H_SOFTMAX_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/proto/hsm.pb.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class HSoftmaxOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - HSoftmaxOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - HierarchyProto hierarchy; - CAFFE_ENFORCE(hierarchy.ParseFromString( - OperatorBase::GetSingleArgument("hierarchy", ""))); - for (const auto& path : hierarchy.paths()) { - hierarchy_all_map_.emplace(path.word_id(), path); - } - } - - protected: - std::unordered_map hierarchy_all_map_; - Tensor scale_; - Tensor sum_multiplier_; - Tensor bias_multiplier_; - static constexpr T kLOG_THRESHOLD() { - return 1e-20; - } - static std::unordered_map getHierarchyForLabels( - int M, - const int* labels, - const std::unordered_map& hierarchy_all_map) { - std::unordered_map hierarchy_map; - std::set label_set = std::set(labels, labels + M); - for (const auto& label : label_set) { - auto search = hierarchy_all_map.find(label); - CAFFE_ENFORCE(search != hierarchy_all_map.end(), "incorrect label."); - hierarchy_map.emplace(search->first, search->second); - } - return hierarchy_map; - } - int getIntermediateOutputSize( - const int* labels, - int M, - std::unordered_map& hierarchy) const { - int size = 0; - for (int label = 0; label < M; ++label) { - int word_id = labels[label]; - const auto& path = hierarchy[word_id]; - size += std::accumulate( - path.path_nodes().begin(), - path.path_nodes().end(), - 0, - // Output of FC + Output of Softmax - [](int sz, PathNodeProto node) { - return sz + 2 * node.length(); - }); - } - return size; - } -}; - -template -class HSoftmaxOp : public HSoftmaxOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using HSoftmaxOpBase::HSoftmaxOpBase; - - bool RunOnDevice() override; - - protected: - float RunForwardSingle( - const float* X, - const float* W, - const float* b, - int target, - float* output, - const float* bias_multiplier, - int w_length, - int K, - int& output_offset); -}; - -template -class HSoftmaxGradientOp final : public HSoftmaxOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using HSoftmaxOpBase::HSoftmaxOpBase; - bool RunOnDevice() override; - - private: - void RunBackwardSingle( - const float* X, - const float* dY, - const float* W, - int target, - const float* int_output, - float* dX, - float* dW, - float* db, - float* dOutput, - int dim_in, - int w_length, - int& output_offset); -}; - -template -class HSoftmaxSearchOp final : public HSoftmaxOp { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - HSoftmaxSearchOp(const OperatorDef& operator_def, Workspace* ws) - : HSoftmaxOp(operator_def, ws), - top_n_(OperatorBase::GetSingleArgument("topN", 5)), - beam_(OperatorBase::GetSingleArgument("beam", 0.01)) { - CAFFE_ENFORCE(tree_.ParseFromString( - OperatorBase::GetSingleArgument("tree", ""))); - } - bool RunOnDevice() override; - - private: - int top_n_; - float beam_; - TreeProto tree_; - bool pruning( - const float* X, - int sample, - int K, - const float* W, - const float* b, - const NodeProto& src_node, - NodeProto& dst_node, - float parent_score, - float beam); - bool extractNodes( - const NodeProto& node, - std::vector>& info); -}; - -template -class HuffmanTreeHierarchyOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - HuffmanTreeHierarchyOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_classes_(OperatorBase::GetSingleArgument("num_classes", -1)) {} - bool RunOnDevice() override; - - private: - // Internal huffman tree data. - struct Node { - Node(T l, int count) - : label(l), count(count), left_ch_index(-1), right_ch_index(-1) {} - T label; - int count; - int left_ch_index; - int right_ch_index; - }; - - struct NodeComparator { - bool operator()(const Node& node_a, const Node& node_b) { - return node_a.count > node_b.count; - } - }; - - int num_classes_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SOFTMAX_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/half_float_ops.h b/app/src/main/cpp/caffe2/operators/half_float_ops.h deleted file mode 100644 index f65720b..0000000 --- a/app/src/main/cpp/caffe2/operators/half_float_ops.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef CAFFE2_OPERATORS_HALF_FLOAT_OPS_H_ -#define CAFFE2_OPERATORS_HALF_FLOAT_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class FloatToHalfOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(FloatToHalfOp); - - bool RunOnDevice() override; -}; - -template -class HalfToFloatOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(HalfToFloatOp); - - bool RunOnDevice() override; -}; - -class Float16ConstantFillOp : public Operator { - public: - Float16ConstantFillOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - shape_( - ToVectorTIndex(OperatorBase::GetRepeatedArgument("shape"))) {} - - USE_OPERATOR_FUNCTIONS(CPUContext); - virtual ~Float16ConstantFillOp() {} - - bool RunOnDevice() override; - - private: - vector shape_; -}; - -inline std::vector Float16FillerTensorInference( - const OperatorDef& def, - const vector& in) { - vector out(1); - ArgumentHelper helper(def); - out[0].set_data_type(static_cast( - helper.GetSingleArgument("dtype", TensorProto_DataType_FLOAT))); - auto shape = helper.GetRepeatedArgument("shape"); - for (int d : shape) { - out[0].add_dims(d); - } - return out; -} - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_HALF_FLOAT_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/if_op.h b/app/src/main/cpp/caffe2/operators/if_op.h deleted file mode 100644 index 401db28..0000000 --- a/app/src/main/cpp/caffe2/operators/if_op.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CAFFE2_OPERATORS_IF_OP_H_ -#define CAFFE2_OPERATORS_IF_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class IfOp final : public Operator { - public: - IfOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - CAFFE_ENFORCE( - this->template HasSingleArgumentOfType("then_net"), - "then_net must be specified in If operator"); - auto then_net_def = - this->template GetSingleArgument("then_net", NetDef()); - then_net_ = CreateNet(then_net_def, ws); - CAFFE_ENFORCE(then_net_, "Failed to initialize then subnet"); - - if (this->template HasSingleArgumentOfType("else_net")) { - auto else_net_def = - this->template GetSingleArgument("else_net", NetDef()); - else_net_ = CreateNet(else_net_def, ws); - CAFFE_ENFORCE(else_net_, "Failed to initialize else subnet"); - } - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - private: - std::unique_ptr then_net_; - std::unique_ptr else_net_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_IF_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/im2col_op.h b/app/src/main/cpp/caffe2/operators/im2col_op.h deleted file mode 100644 index f89131e..0000000 --- a/app/src/main/cpp/caffe2/operators/im2col_op.h +++ /dev/null @@ -1,292 +0,0 @@ -#ifndef CAFFE2_OPERATORS_IM2COL_OP_H_ -#define CAFFE2_OPERATORS_IM2COL_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class Im2ColOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - Im2ColOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - pad_(OperatorBase::GetSingleArgument("pad", 0)), - kernel_h_(OperatorBase::GetSingleArgument( - "kernel_h", - OperatorBase::GetSingleArgument("kernel", 0))), - kernel_w_(OperatorBase::GetSingleArgument( - "kernel_w", - OperatorBase::GetSingleArgument("kernel", 0))), - dilation_h_(OperatorBase::GetSingleArgument( - "dilation_h", - OperatorBase::GetSingleArgument("dilation", 1))), - dilation_w_(OperatorBase::GetSingleArgument( - "dilation_w", - OperatorBase::GetSingleArgument("dilation", 1))), - stride_h_(OperatorBase::GetSingleArgument( - "stride_h", - OperatorBase::GetSingleArgument("stride", 1))), - stride_w_(OperatorBase::GetSingleArgument( - "stride_w", - OperatorBase::GetSingleArgument("stride", 1))), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(kernel_h_ > 0); - CAFFE_ENFORCE(kernel_w_ > 0); - CAFFE_ENFORCE(dilation_h_ > 0); - CAFFE_ENFORCE(dilation_w_ > 0); - CAFFE_ENFORCE(stride_h_ > 0); - CAFFE_ENFORCE(stride_w_ > 0); - CAFFE_ENFORCE(pad_ >= 0); - } - - bool RunOnDevice() override { - auto& X = Input(0); - auto* Y = Output(0); - CAFFE_ENFORCE(4 == X.ndim()); - - int N = 0, C = 0, H = 0, W = 0; - switch (order_) { - case StorageOrder::NCHW: - N = X.dim32(0); - C = X.dim32(1); - H = X.dim32(2); - W = X.dim32(3); - break; - case StorageOrder::NHWC: - N = X.dim32(0); - H = X.dim32(1); - W = X.dim32(2); - C = X.dim32(3); - break; - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - - const int dkernel_h = dilation_h_ * (kernel_h_ - 1) + 1; - const int dkernel_w = dilation_w_ * (kernel_w_ - 1) + 1; - CAFFE_ENFORCE(H >= dkernel_h); - CAFFE_ENFORCE(W >= dkernel_w); - const int out_h = (H + 2 * pad_ - dkernel_h) / stride_h_ + 1; - const int out_w = (W + 2 * pad_ - dkernel_w) / stride_w_ + 1; - - switch (order_) { - case StorageOrder::NCHW: { - Y->Resize( - std::vector{N, C * kernel_h_ * kernel_w_, out_h, out_w}); - - const size_t dx = X.size() / N; - const size_t dy = Y->size() / N; - for (int n = 0; n < N; ++n) { - const auto* xdata = X.template data() + (n * dx); - auto* ydata = Y->template mutable_data() + (n * dy); - math::Im2col( - xdata, - C, - H, - W, - kernel_h_, - kernel_w_, - dilation_h_, - dilation_w_, - pad_, - pad_, - pad_, - pad_, - stride_h_, - stride_w_, - ydata, - &context_); - } - }; break; - case StorageOrder::NHWC: { - Y->Resize( - std::vector{N, out_h, out_w, kernel_h_ * kernel_w_ * C}); - - const size_t dx = X.size() / N; - const size_t dy = Y->size() / N; - for (int n = 0; n < N; ++n) { - const auto* xdata = X.template data() + (n * dx); - auto* ydata = Y->template mutable_data() + (n * dy); - math::Im2col( - xdata, - C, - H, - W, - kernel_h_, - kernel_w_, - dilation_h_, - dilation_w_, - pad_, - pad_, - pad_, - pad_, - stride_h_, - stride_w_, - ydata, - &context_); - } - }; break; - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - - return true; - } - - private: - int pad_; - int kernel_h_; - int kernel_w_; - int dilation_h_; - int dilation_w_; - int stride_h_; - int stride_w_; - StorageOrder order_; -}; - -template -class Col2ImOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - Col2ImOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - pad_(OperatorBase::GetSingleArgument("pad", 0)), - kernel_h_(OperatorBase::GetSingleArgument( - "kernel_h", - OperatorBase::GetSingleArgument("kernel", 0))), - kernel_w_(OperatorBase::GetSingleArgument( - "kernel_w", - OperatorBase::GetSingleArgument("kernel", 0))), - dilation_h_(OperatorBase::GetSingleArgument( - "dilation_h", - OperatorBase::GetSingleArgument("dilation", 1))), - dilation_w_(OperatorBase::GetSingleArgument( - "dilation_w", - OperatorBase::GetSingleArgument("dilation", 1))), - stride_h_(OperatorBase::GetSingleArgument( - "stride_h", - OperatorBase::GetSingleArgument("stride", 1))), - stride_w_(OperatorBase::GetSingleArgument( - "stride_w", - OperatorBase::GetSingleArgument("stride", 1))), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(kernel_h_ > 0); - CAFFE_ENFORCE(kernel_w_ > 0); - CAFFE_ENFORCE(dilation_h_ > 0); - CAFFE_ENFORCE(dilation_w_ > 0); - CAFFE_ENFORCE(stride_h_ > 0); - CAFFE_ENFORCE(stride_w_ > 0); - CAFFE_ENFORCE(pad_ >= 0); - } - - bool RunOnDevice() override { - auto& X = Input(0); - auto& Z = Input(1); - auto* Y = Output(0); - Y->ResizeLike(Z); - CAFFE_ENFORCE(4 == Y->ndim()); - - int N = 0, C = 0, H = 0, W = 0; - switch (order_) { - case StorageOrder::NCHW: - N = Y->dim32(0); - C = Y->dim32(1); - H = Y->dim32(2); - W = Y->dim32(3); - break; - case StorageOrder::NHWC: - N = Y->dim32(0); - H = Y->dim32(1); - W = Y->dim32(2); - C = Y->dim32(3); - break; - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - - const int dkernel_h = dilation_h_ * (kernel_h_ - 1) + 1; - const int dkernel_w = dilation_w_ * (kernel_w_ - 1) + 1; - CAFFE_ENFORCE(H >= dkernel_h); - CAFFE_ENFORCE(W >= dkernel_w); - const int out_h = (H + 2 * pad_ - dkernel_h) / stride_h_ + 1; - const int out_w = (W + 2 * pad_ - dkernel_w) / stride_w_ + 1; - CAFFE_ENFORCE(X.size() == N * kernel_h_ * kernel_w_ * C * out_h * out_w); - - const size_t dx = X.size() / N; - const size_t dy = Y->size() / N; - - // could template-specialize this, but it's test code... - switch (order_) { - case StorageOrder::NCHW: { - for (int n = 0; n < N; ++n) { - const auto* xdata = X.template data() + (n * dx); - auto* ydata = Y->template mutable_data() + (n * dy); - math::Col2im( - xdata, - C, - H, - W, - kernel_h_, - kernel_w_, - dilation_h_, - dilation_w_, - pad_, - pad_, - pad_, - pad_, - stride_h_, - stride_w_, - ydata, - &context_); - } - }; break; - case StorageOrder::NHWC: { - for (int n = 0; n < N; ++n) { - const auto* xdata = X.template data() + (n * dx); - auto* ydata = Y->template mutable_data() + (n * dy); - math::Col2im( - xdata, - C, - H, - W, - kernel_h_, - kernel_w_, - dilation_h_, - dilation_w_, - pad_, - pad_, - pad_, - pad_, - stride_h_, - stride_w_, - ydata, - &context_); - } - }; break; - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - - return true; - } - - private: - int pad_; - int kernel_h_; - int kernel_w_; - int dilation_h_; - int dilation_w_; - int stride_h_; - int stride_w_; - StorageOrder order_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_IM2COL_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/index_hash_ops.h b/app/src/main/cpp/caffe2/operators/index_hash_ops.h deleted file mode 100644 index f81fb2e..0000000 --- a/app/src/main/cpp/caffe2/operators/index_hash_ops.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef CAFFE2_OPERATORS_INDEX_HASH_OPS_H_ -#define CAFFE2_OPERATORS_INDEX_HASH_OPS_H_ - -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class IndexHashOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - IndexHashOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - seed_(OperatorBase::GetSingleArgument("seed", 0)), - modulo_(OperatorBase::GetSingleArgument("modulo", 0)) { - CAFFE_ENFORCE_GT(modulo_, 0, "MODULO should be > 0"); - } - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& indices = Input(INDICES); - auto* hashed_indices = Output(HASHED_INDICES); - hashed_indices->ResizeLike(indices); - - CAFFE_ENFORCE_GE( - static_cast(std::numeric_limits::max()), - modulo_, - "MODULO shouldn't be larger than the numeric limit of the indices"); - - auto N = indices.size(); - auto* indices_data = indices.template data(); - auto* hashed_indices_data = hashed_indices->template mutable_data(); - - for (auto i = 0; i < N; i++) { - hashed_indices_data[i] = hash(indices_data[i]); - } - - return true; - } - - protected: - template - T hash(T id) { - int8_t* bytes = (int8_t*)&id; - T hashed = seed_ * 0xDEADBEEF; - for (int i = 0; i < sizeof(T) / sizeof(int8_t); i++) { - hashed = hashed * 65537 + bytes[i]; - } - hashed = (modulo_ + hashed % modulo_) % modulo_; - return hashed; - } - - private: - INPUT_TAGS(INDICES); - OUTPUT_TAGS(HASHED_INDICES); - - int64_t seed_; - int64_t modulo_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_INDEX_HASH_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/instance_norm_op.h b/app/src/main/cpp/caffe2/operators/instance_norm_op.h deleted file mode 100644 index 7bbe84d..0000000 --- a/app/src/main/cpp/caffe2/operators/instance_norm_op.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CAFFE2_OPERATORS_INSTANCE_NORM_OP_H_ -#define CAFFE2_OPERATORS_INSTANCE_NORM_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class InstanceNormOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - InstanceNormOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(epsilon_ >= 0, "Must pass a nonnegative epsilon."); - } - ~InstanceNormOp() {} - - bool RunOnDevice() { - switch (order_) { - case StorageOrder::NHWC: - return RunOnDeviceWithOrderNHWC(); - case StorageOrder::NCHW: - return RunOnDeviceWithOrderNCHW(); - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - } - - bool RunOnDeviceWithOrderNHWC(); - bool RunOnDeviceWithOrderNCHW(); - - protected: - // parameters - T epsilon_; - StorageOrder order_; - - // temp results that get passed to the gradient, but are otherwise stored here - Tensor mean_; - Tensor inv_stdev_; - - INPUT_TAGS(INPUT, SCALE, BIAS); - OUTPUT_TAGS(OUTPUT, MEAN, INV_STDEV); -}; - -template -class InstanceNormGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - InstanceNormGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(epsilon_ >= 0, "Must pass a nonnegative epsilon."); - } - ~InstanceNormGradientOp() {} - - bool RunOnDevice() { - switch (order_) { - case StorageOrder::NHWC: - return RunOnDeviceWithOrderNHWC(); - case StorageOrder::NCHW: - return RunOnDeviceWithOrderNCHW(); - default: - CAFFE_THROW("Unknown storage order: ", order_); - } - } - - bool RunOnDeviceWithOrderNHWC(); - bool RunOnDeviceWithOrderNCHW(); - - protected: - // parameters - T epsilon_; - StorageOrder order_; - - // temp results that could get passed through to this gradient, but if not, - // are stored here - Tensor mean_; - Tensor inv_stdev_; - - INPUT_TAGS(INPUT, SCALE, BIAS, OUTPUT_GRAD, MEAN, INV_STDEV); - OUTPUT_TAGS(INPUT_GRAD, SCALE_GRAD, BIAS_GRAD); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_INSTANCE_NORM_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/layer_norm_op.h b/app/src/main/cpp/caffe2/operators/layer_norm_op.h deleted file mode 100644 index 24604e3..0000000 --- a/app/src/main/cpp/caffe2/operators/layer_norm_op.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LAYER_NORM_OP_H -#define CAFFE2_OPERATORS_LAYER_NORM_OP_H - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class LayerNormOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LayerNormOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - ~LayerNormOp() {} - - template - bool DoRunWithType(); - - bool RunOnDevice() override { - return DoRunWithType(); - } - - protected: - int axis_; - float epsilon_; - - Tensor scratch_; - Tensor seg_indices_; -}; - -template -class LayerNormGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LayerNormGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 0.001)) {} - ~LayerNormGradientOp() {} - - template - bool DoRunWithType(); - - bool RunOnDevice() override { - return DoRunWithType(); - } - - protected: - int axis_; - float epsilon_; - - Tensor scratch_; - Tensor gscratch_; - Tensor seg_indices_; - Tensor dstdev_; - Tensor dmean_; -}; - -} // namespace caffe2 - -#endif /* CAFFE2_OPERATORS_LAYER_NORM_OP_H */ diff --git a/app/src/main/cpp/caffe2/operators/leaky_relu_op.h b/app/src/main/cpp/caffe2/operators/leaky_relu_op.h deleted file mode 100644 index 32b41d7..0000000 --- a/app/src/main/cpp/caffe2/operators/leaky_relu_op.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class LeakyReluOp : public Operator { - public: - LeakyReluOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), alpha_(0) { - if (HasArgument("alpha")) { - alpha_ = - static_cast(OperatorBase::GetSingleArgument("alpha", 0)); - } - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T alpha_; -}; - -template -class LeakyReluGradientOp final : public Operator { - public: - LeakyReluGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), alpha_(0) { - if (HasArgument("alpha")) { - alpha_ = - static_cast(OperatorBase::GetSingleArgument("alpha", 0)); - } - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T alpha_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/lengths_reducer_ops.h b/app/src/main/cpp/caffe2/operators/lengths_reducer_ops.h deleted file mode 100644 index fc9295a..0000000 --- a/app/src/main/cpp/caffe2/operators/lengths_reducer_ops.h +++ /dev/null @@ -1,100 +0,0 @@ -#pragma once -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/perfkernels/embedding_lookup.h" - -namespace caffe2 { - -// A templated class that implements SparseLengths[Sum,WeightedSum,Mean]. -template < - typename T, // output type - class InputTypes, // supported input types, such as TensorTypes - bool USE_WEIGHT = 0, // Whether it is SparseLengthsWeightedSum - bool USE_MEAN = 0 // Whether this is SparseLengthsMean - > -class CPUSparseLengthsReductionOp : public Operator { - public: - USE_OPERATOR_FUNCTIONS(CPUContext); - CPUSparseLengthsReductionOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - static_assert( - !(USE_WEIGHT & USE_MEAN), "Cannot both specify weight and mean."); - } - - ~CPUSparseLengthsReductionOp() {} - - // Currently, we support float and float16 inputs for input data type, and - // int32_t and int64_t for the index type. - - bool RunOnDevice() override { - return DispatchHelper::call(this, Input(DATA)); - } - - template - bool DoRunWithType() { - return DispatchHelper, InputType>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType2() { - auto& dataInput = Input(DATA); - auto& indicesInput = Input(INDICES); - auto& lengthsInput = Input(LENGTHS); - - CAFFE_ENFORCE_EQ(1, indicesInput.ndim(), "INDICES must be a vector"); - CAFFE_ENFORCE_EQ(1, lengthsInput.ndim(), "LENGTHS must be a vector"); - const TIndex N = dataInput.dim(0); - const int D = dataInput.size_from_dim(1); - const TIndex M = lengthsInput.dim(0); - const TIndex indices_size = indicesInput.size(); - - auto* output = Output(0); - auto shape = dataInput.dims(); - shape[0] = M; - output->Resize(shape); - T* out_data = output->template mutable_data(); - - const InputType* in_data = dataInput.template data(); - const IndexType* indices = indicesInput.template data(); - const int* lengths = lengthsInput.template data(); - const T* in_weight = nullptr; - - if (USE_WEIGHT) { // static if - auto& weightInput = Input(WEIGHT); - CAFFE_ENFORCE_EQ(1, weightInput.ndim(), "WEIGHT must be a vector"); - CAFFE_ENFORCE_EQ( - weightInput.size(), - indices_size, - "Weight should have the same length as indices."); - in_weight = weightInput.template data(); - } - - // delegate work to perfkernel that branches based on architecture - EmbeddingLookup( - D, - M, - indices_size, - N, - in_data, - indices, - lengths, - in_weight, - nullptr, // scale_bias field is only used in SparseLengths8BitsRowwiseOp - USE_MEAN, - out_data); - return true; - } - - private: - enum { - DATA = 0, // Data input. - WEIGHT = 1, // Weight input used in SparseLengthsWeightedSum - INDICES = 1 + USE_WEIGHT, // 1 in SparseLengths[Sum,Mean] and - // 2 in SparseLengthsWeightedSum - LENGTHS = 2 + USE_WEIGHT, // 2 in SparseLengths[Sum, Mean], - // 3 in SparseLengthsWeightedSum - }; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/lengths_reducer_rowwise_8bit_ops.h b/app/src/main/cpp/caffe2/operators/lengths_reducer_rowwise_8bit_ops.h deleted file mode 100644 index 5c1a596..0000000 --- a/app/src/main/cpp/caffe2/operators/lengths_reducer_rowwise_8bit_ops.h +++ /dev/null @@ -1,186 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_LENGTHS_REDUCER_ROWWISE_8bits_OP_H_ -#define CAFFE2_OPERATORS_LENGTHS_REDUCER_ROWWISE_8bits_OP_H_ -// SparseLengthsSum8bits - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/reducer_functors.h" -#include "caffe2/perfkernels/embedding_lookup.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -namespace { -const float kEqualityThreshold = 1e-10; -} - -template < - class Context, - bool USE_WEIGHTS = 0, - bool USE_MEAN = 0, - class OutDataT = float> -class SparseLengths8BitsRowwiseOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(SparseLengths8BitsRowwiseOp); - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& dataInput = Input(DATA); - auto& lengthsInput = Input(LENGTHS); - auto* output = Output(0); - auto* scale_bias = Input(SCALE_BIAS).template data(); - CAFFE_ENFORCE_EQ(1, lengthsInput.ndim(), "LENGTHS must be a vector"); - const TIndex outputSize = lengthsInput.dim(0); - - auto& indicesInput = Input(INDICES); - CAFFE_ENFORCE_EQ( - 2, Input(SCALE_BIAS).ndim(), "scale_bias has to be matrix"); - CAFFE_ENFORCE_EQ( - dataInput.dim(0), - Input(SCALE_BIAS).dim(0), - "scale_bias must have the same first dim as data"); - CAFFE_ENFORCE_EQ( - 2, - Input(SCALE_BIAS).dim(1), - "the second dim of scale_bias has to be equal to 2"); - CAFFE_ENFORCE_EQ(1, indicesInput.ndim(), "INDICES must be a vector"); - const IndexType* indices = indicesInput.template data(); - TIndex dataToReduceSize = indicesInput.dim(0); - - const int* lengths = lengthsInput.template data(); - vector shape = dataInput.dims(); - shape[0] = outputSize; - output->Resize(shape); - const float* w = nullptr; - if (USE_WEIGHTS) { - w = Input(WEIGHTS).template data(); - } - TIndex in_block_size = dataInput.size_from_dim(1); - OutDataT* out = output->template mutable_data(); - const uint8_t* input_data = dataInput.template data(); - - // delegate work to perfkernel that branches based on architecture - const TIndex indices_size = indicesInput.size(); - const TIndex N = dataInput.dim(0); - EmbeddingLookup( - in_block_size, - outputSize, - indices_size, - N, // embeding table length - input_data, - indices, - lengths, - w, - scale_bias, - USE_MEAN, - out); - - return true; - } - - enum { - DATA = 0, - WEIGHTS = 1, - INDICES = 1 + USE_WEIGHTS, - LENGTHS = 2 + USE_WEIGHTS, - SCALE_BIAS = 3 + USE_WEIGHTS - }; -}; - -template -class FloatToRowwiseQuantized8BitsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(FloatToRowwiseQuantized8BitsOp); - bool RunOnDevice() override { - auto& input = Input(DATA_FLOAT); - auto* output = Output(DATA_UINT8); - auto* scale_bias = Output(SCALE_BIAS); - auto* input_data = input.template data(); - output->ResizeLike(input); - vector scale_bias_dims = {input.dim(0), 2}; - scale_bias->Resize(scale_bias_dims); - auto* output_data = output->template mutable_data(); - float* scale_bias_data = scale_bias->template mutable_data(); - size_t n_blocks = input.dim(0); - size_t block_size = input.size_from_dim(1); - for (size_t i = 0; i < n_blocks; ++i) { - ConstEigenVectorArrayMap input_row( - input_data + i * block_size, block_size); - EigenVectorArrayMap output_row( - output_data + i * block_size, block_size); - auto min_element = input_row.minCoeff(); - auto max_element = input_row.maxCoeff(); - if (max_element - min_element < kEqualityThreshold) { - scale_bias_data[2 * i] = 1.0f; - scale_bias_data[2 * i + 1] = min_element; - memset(output_data + i * block_size, 0, block_size); - } else { - scale_bias_data[2 * i] = (max_element - min_element) / 255.0f; - scale_bias_data[2 * i + 1] = min_element; - const float inv_scale = 1.0f / scale_bias_data[2 * i]; - output_row = ((input_row - scale_bias_data[2 * i + 1]) * inv_scale) - .round() - .template cast(); - } - } - return true; - } - - private: - INPUT_TAGS(DATA_FLOAT); - OUTPUT_TAGS(DATA_UINT8, SCALE_BIAS); -}; - -template -class Rowwise8BitQuantizedToFloatOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(Rowwise8BitQuantizedToFloatOp); - bool RunOnDevice() override { - auto& input = Input(DATA_UINT8); - auto& scale_bias = Input(SCALE_BIAS); - auto* output = Output(DATA_FLOAT); - CAFFE_ENFORCE_EQ(2, scale_bias.ndim(), "scale_bias has to be matrix"); - CAFFE_ENFORCE_EQ( - input.dim(0), - scale_bias.dim(0), - "scale_bias must have the same first dim as data"); - CAFFE_ENFORCE_EQ( - 2, - scale_bias.dim(1), - "the second dim of scale_bias has to be equal to 2"); - output->ResizeLike(input); - auto* input_data = input.template data(); - auto* scale_bias_data = scale_bias.template data(); - - auto* output_data = output->template mutable_data(); - size_t block_size = input.size_from_dim(1); - size_t n_blocks = input.dim(0); - - for (size_t i = 0; i < n_blocks; ++i) { - ConstEigenVectorArrayMap input_row( - input_data + i * block_size, block_size); - EigenVectorArrayMap output_row( - output_data + i * block_size, block_size); - output_row = input_row.template cast() * scale_bias_data[2 * i] + - scale_bias_data[2 * i + 1]; - } - return true; - } - - private: - INPUT_TAGS(DATA_UINT8, SCALE_BIAS); - OUTPUT_TAGS(DATA_FLOAT); -}; -} -#endif // CAFFE2_OPERATORS_LENGTHS_REDUCER_ROWWISE_8bits_H_ diff --git a/app/src/main/cpp/caffe2/operators/lengths_tile_op.h b/app/src/main/cpp/caffe2/operators/lengths_tile_op.h deleted file mode 100644 index 7c3bd11..0000000 --- a/app/src/main/cpp/caffe2/operators/lengths_tile_op.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LENGTHS_TILE_OP_H_ -#define CAFFE2_OPERATORS_LENGTHS_TILE_OP_H_ - -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class LengthsTileOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsTileOp); - - bool RunOnDevice() override { - auto& data = Input(DATA); - auto& lengths = Input(LENGTHS); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(lengths.ndim(), 1, "LENGTHS must be 1-D"); - CAFFE_ENFORCE_GE(data.ndim(), 1, "DATA should be at least 1-D"); - CAFFE_ENFORCE_EQ(lengths.size(), data.dim(0)); - - auto* lengths_data = lengths.template data(); - int32_t total_length = 0; - math::Sum( - lengths.size(), lengths_data, &total_length, &context_); - - auto shape = data.dims(); - shape[0] = total_length; - output->Resize(shape); - - auto block_size = data.size_from_dim(1); - auto block_bytesize = data.size_from_dim(1) * data.meta().itemsize(); - auto N = lengths.size(); - - auto src = static_cast(data.raw_data()); - auto out = static_cast(output->raw_mutable_data(data.meta())); - - for (TIndex i = 0; i < N; ++i) { - auto length = lengths_data[i]; - CAFFE_ENFORCE_GE(length, 0); - for (int32_t j = 0; j < length; ++j) { - context_.template CopyItems( - data.meta(), block_size, src, out); - out += block_bytesize; - } - src += block_bytesize; - } - return true; - } - - INPUT_TAGS(DATA, LENGTHS); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LENGTHS_TILE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/lengths_top_k_op.h b/app/src/main/cpp/caffe2/operators/lengths_top_k_op.h deleted file mode 100644 index ff960c9..0000000 --- a/app/src/main/cpp/caffe2/operators/lengths_top_k_op.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_ -#define CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { -template -class LengthsTopKOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - LengthsTopKOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), OP_SINGLE_ARG(int, "k", k_, -1) { - CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1"); - } - - bool RunOnDevice() override; - - protected: - int k_; - INPUT_TAGS(X_IN, Y_IN); - OUTPUT_TAGS(TOPK_VALUES_OUT, TOPK_INDICES_OUT); -}; - -template -class LengthsTopKGradientOp : public Operator { - public: - LengthsTopKGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), OP_SINGLE_ARG(int, "k", k_, -1) { - CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1"); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - int k_; - INPUT_TAGS(LENGTH_IN, INDICES_IN, DER_TOPK_IN); - OUTPUT_TAGS(DER_X_OUT); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/load_save_op.h b/app/src/main/cpp/caffe2/operators/load_save_op.h deleted file mode 100644 index 986ecc9..0000000 --- a/app/src/main/cpp/caffe2/operators/load_save_op.h +++ /dev/null @@ -1,506 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LOAD_SAVE_OP_H_ -#define CAFFE2_OPERATORS_LOAD_SAVE_OP_H_ - -#include -#include -#include - -#include "caffe2/core/blob_serialization.h" -#include "caffe2/core/context.h" -#include "caffe2/core/db.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -namespace { -struct BlobState { - int64_t total_size; - int64_t current_size; - bool is_tensor; - std::set seen_chunks_ids; - - explicit BlobState( - int64_t total_size = 0, - int64_t current_size = 0, - bool is_tensor = false) - : total_size(total_size), - current_size(current_size), - is_tensor(is_tensor) {} -}; -} // namespace - -using db::Cursor; -using db::DB; -using db::Transaction; - -template -class DBExistsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - DBExistsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - absolute_path_( - OperatorBase::GetSingleArgument("absolute_path", false)), - db_name_(OperatorBase::GetSingleArgument("db_name", "")), - db_type_(OperatorBase::GetSingleArgument("db_type", "")) {} - - bool RunOnDevice() override { - string full_db_name = - absolute_path_ ? db_name_ : (ws_->RootFolder() + "/" + db_name_); - auto* output = Output(0); - output->Resize(); - bool* exists = output->template mutable_data(); - - *exists = caffe2::db::DBExists(db_type_, full_db_name); - return true; - } - - private: - Workspace* ws_; - bool absolute_path_; - std::string db_name_; - std::string db_type_; -}; - -template -class LoadOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LoadOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - absolute_path_( - OperatorBase::GetSingleArgument("absolute_path", false)), - add_prefix_(OperatorBase::GetSingleArgument("add_prefix", "")), - strip_prefix_( - OperatorBase::GetSingleArgument("strip_prefix", "")), - db_name_(OperatorBase::GetSingleArgument("db", "")), - db_type_(OperatorBase::GetSingleArgument("db_type", "")), - keep_device_(OperatorBase::GetSingleArgument("keep_device", 0)), - load_all_(OperatorBase::GetSingleArgument("load_all", 0)), - allow_incomplete_( - OperatorBase::GetSingleArgument("allow_incomplete", false)), - blob_names_(OperatorBase::GetRepeatedArgument( - "source_blob_names")) { - if (InputSize() == 0) { - CAFFE_ENFORCE_GT(db_name_.size(), 0, "Must specify a db name."); - CAFFE_ENFORCE_GT(db_type_.size(), 0, "Must specify a db type."); - } - CAFFE_ENFORCE(blob_names_.empty() || blob_names_.size() == OutputSize(), - "Number of output blobs and source_blob_names mismatch."); - CAFFE_ENFORCE(blob_names_.empty() || strip_prefix_.empty(), - "strip_prefix and source_blob_names are mutually exclusive."); - CAFFE_ENFORCE(blob_names_.empty() || !load_all_, - "cannot load_all_ while using source_blob_names."); - if (!load_all_) { - // blob_names_ will be filled with ''source blob names'' in file/db - // if argument source_blob_names is not given, then blob_names_ is - // inferred from operator output - if(blob_names_.empty()) { - for (const string& name : operator_def.output()) { - blob_names_.push_back(name); - } - } - int idx = 0; - std::set name_set; - for (const string& name : blob_names_) { - CAFFE_ENFORCE(name_set.insert(name).second, - "Duplicated source blob name: ", name); - output_indices_[name] = idx++; - } - } - } - - void SetCurrentDevice(BlobProto* proto); - - bool RunOnDevice() override { - if (InputSize() == 1) { - const db::DBReader& reader = OperatorBase::Input(0); - extract(reader.cursor()); - } else { - string full_db_name = - absolute_path_ ? db_name_ : (ws_->RootFolder() + "/" + db_name_); - std::unique_ptr in_db( - caffe2::db::CreateDB(db_type_, full_db_name, caffe2::db::READ)); - CAFFE_ENFORCE(in_db.get(), "Cannot open db: ", db_name_); - std::unique_ptr cursor(in_db->NewCursor()); - extract(cursor.get()); - } - - return true; - } - - private: - void extract(Cursor* cursor) { - if (load_all_) { - extractAll(cursor); - } else { - extractFrom(cursor, OperatorBase::Outputs()); - } - } - - void extractAll(Cursor* cursor) { - CAFFE_ENFORCE(cursor, "cursor is not valid"); - std::unordered_map blob_states; - int loaded_blobs = 0; - for (; cursor->Valid(); cursor->Next()) { - const auto key = buildBlobNameFromDbKey(cursor->key()); - BlobProto proto; - CAFFE_ENFORCE( - proto.ParseFromString(cursor->value()), "Couldn't parse Proto"); - if (!keep_device_) { - // If we are not keeping the device as the one specified in the - // proto, we will set the current device. - SetCurrentDevice(&proto); - } - - Blob* blob = ws_->CreateBlob(key); - ProcessBlob(blob, proto, &blob_states, key, &loaded_blobs); - } - - VLOG(1) << "Loaded " << loaded_blobs << " from db"; - validateBlobStates(blob_states); - } - - void extractFrom(Cursor* cursor, const vector& outputs) { - CAFFE_ENFORCE(cursor); - std::unordered_map blob_states; - int loaded_blobs = 0; - for (; cursor->Valid(); cursor->Next()) { - const auto key = buildBlobNameFromDbKey(cursor->key()); - if (!output_indices_.count(key)) { - VLOG(1) << "Key " << key << " not used. Skipping."; - } else { - VLOG(2) << "Deserializing blob " << key; - BlobProto proto; - CAFFE_ENFORCE(proto.ParseFromString(cursor->value())); - if (!keep_device_) { - // If we are not keeping the device as the one specified in the - // proto, we will set the current device. - SetCurrentDevice(&proto); - } - auto blobIndex = output_indices_[key]; - Blob* blob = outputs.at(blobIndex); - ProcessBlob(blob, proto, &blob_states, key, &loaded_blobs); - - if (loaded_blobs == OutputSize()) { - VLOG(1) << "Read all required blobs"; - break; - } - } - } - - validateBlobStates(blob_states); - VLOG(1) << "Fully loaded " << blob_states.size() << " blobs"; - - if (loaded_blobs != OutputSize()) { - if (allow_incomplete_ && loaded_blobs < OutputSize()) { - VLOG(1) << "Loaded " << loaded_blobs << " blobs out of " << OutputSize() - << " blobs from db."; - return; - } - for (const string& output_name : this->debug_def().output()) { - if (blob_states.count(output_name) == 0) { - LOG(ERROR) << "Failed to load blob: " << output_name; - } - } - CAFFE_THROW( - "Expected to load ", - OutputSize(), - " blobs, got ", - loaded_blobs, - " only.\n"); - } - } - - string buildBlobNameFromDbKey(const string& dbKey) { - string key = dbKey.substr(0, dbKey.find(kChunkIdSeparator)); - if (!strip_prefix_.empty()) { - auto match_pos = key.find(strip_prefix_); - if (match_pos != string::npos) { - key = key.substr(match_pos + strip_prefix_.size()); - } - } - key = add_prefix_ + key; - return key; - } - - private: - // We are tracking sizes of already read tensor parts while reading data - // chunks. This way we can make sure that all chunks were loaded in the end. - void ProcessBlob( - Blob* blob, - const BlobProto& proto, - std::unordered_map* blob_states_ptr, - const string& key, - int* loaded_blobs) { - auto& blob_states = *blob_states_ptr; - if (blob_states.count(key) == 0) { - // We reset the blob so that any existing content is destroyed. This - // is to guaranee correct device placement: if we are deserializing - // into a TensorCUDA, without explicit Reset we might be loading data - // into an existing TensorCUDA that has pre-allocated memory on a - // different GPU. - blob->Reset(); - } - blob->Deserialize(proto); - if (proto.has_content_num_chunks()) { - if (!blob_states.count(key)) { - blob_states[key] = BlobState(proto.content_num_chunks()); - } - CAFFE_ENFORCE( - blob_states[key] - .seen_chunks_ids.insert(proto.content_chunk_id()) - .second, - "Chunk with the same id has occured twice for: ", - key); - CAFFE_ENFORCE( - proto.content_chunk_id() >= 0 && - proto.content_chunk_id() < blob_states[key].total_size, - "Chunk id has to be not less than 0 and " - "less than content_num_chunks for key: ", - key); - blob_states[key].current_size++; - CAFFE_ENFORCE( - !blob_states[key].is_tensor, - "Proto with content_chunks can not store tensor: ", - key); - CAFFE_ENFORCE( - blob_states[key].current_size <= blob_states[key].total_size, - "Found an extra part for an already filled blob: ", - key); - if (blob_states[key].current_size == blob_states[key].total_size) { - (*loaded_blobs)++; - } - return; - } - if (!proto.has_tensor()) { - // If blob is divided into chunks the field content_chunks has to be set, - // otherwise only tensors can be seen multiple times as chunks. - CAFFE_ENFORCE(blob_states.count(key) == 0, "Blob duplicated: ", key); - blob_states[key] = BlobState(); - (*loaded_blobs)++; - return; - } - CAFFE_ENFORCE(proto.has_tensor()); - if (blob_states.count(key)) { - CAFFE_ENFORCE(blob_states[key].is_tensor, "Must be tensor ", key); - CAFFE_ENFORCE( - blob_states[key].current_size < blob_states[key].total_size, - "Found an extra part for an already filled tensor: ", - key); - CAFFE_ENFORCE( - proto.tensor().has_segment(), - "Partial tensor must have a segment: ", - key); - blob_states[key].current_size += - proto.tensor().segment().end() - proto.tensor().segment().begin(); - CAFFE_ENFORCE( - blob_states[key].current_size <= blob_states[key].total_size, - "Tensor parts are bigger than target size for tensor: ", - key); - } else { - const auto& dims = proto.tensor().dims(); - int64_t total_size = 1; - for (const auto& dim : dims) { - total_size *= dim; - } - auto current_size = total_size; - if (proto.tensor().has_segment()) { - current_size = - proto.tensor().segment().end() - proto.tensor().segment().begin(); - } - blob_states[key] = - BlobState(total_size, current_size, true /* is_tensor */); - } - - if (blob_states[key].current_size == blob_states[key].total_size) { - (*loaded_blobs)++; - } - } - - void validateBlobStates( - const std::unordered_map& blob_states) { - for (const auto& iter : blob_states) { - const BlobState& blob_state = iter.second; - CAFFE_ENFORCE( - blob_state.current_size == blob_state.total_size, - "Data size mismatch for blob ", - iter.first, - ". Expected: ", - blob_state.total_size, - " Read: ", - blob_state.current_size); - } - } - - Workspace* ws_; - bool absolute_path_; - string add_prefix_; - string strip_prefix_; - string db_name_; - string db_type_; - bool keep_device_; - bool load_all_; - bool allow_incomplete_; - std::map output_indices_; - std::vector blob_names_; -}; - -template -class SaveOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SaveOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - absolute_path_( - OperatorBase::GetSingleArgument("absolute_path", false)), - strip_prefix_( - OperatorBase::GetSingleArgument("strip_prefix", "")), - db_name_(OperatorBase::GetSingleArgument("db", "")), - db_type_(OperatorBase::GetSingleArgument("db_type", "")), - blob_names_( - OperatorBase::GetRepeatedArgument("blob_name_overrides")) { - CAFFE_ENFORCE_GT(db_name_.size(), 0, "Must specify a db name."); - CAFFE_ENFORCE_GT(db_type_.size(), 0, "Must specify a db type."); - CAFFE_ENFORCE( - blob_names_.empty() || - blob_names_.size() == OperatorBase::Inputs().size(), - "Number of blobs and blob_name_overrides mismatch."); - CAFFE_ENFORCE( - blob_names_.empty() || strip_prefix_.empty(), - "strip_prefix and blob_name_overrides are mutually exclusive."); - - if (blob_names_.empty()) { - std::set input_names; - blob_names_.resize(OperatorBase::Inputs().size()); - for (int i = 0; i < blob_names_.size(); ++i) { - std::string name; - if (strip_prefix_.empty()) { - name = operator_def.input(i); - } else { - auto match_pos = operator_def.input(i).find(strip_prefix_); - if (match_pos == string::npos) { - name = operator_def.input(i); - } else { - name = operator_def.input(i).substr( - match_pos + strip_prefix_.size(), string::npos); - } - } - CAFFE_ENFORCE( - input_names.insert(name).second, "Duplicated input: ", name); - blob_names_[i] = name; - } - } - } - - bool RunOnDevice() override { - string full_db_name = - absolute_path_ ? db_name_ : (ws_->RootFolder() + "/" + db_name_); - std::unique_ptr out_db( - caffe2::db::CreateDB(db_type_, full_db_name, caffe2::db::NEW)); - CAFFE_ENFORCE(out_db.get(), "Cannot open db for writing: ", full_db_name); - - BlobSerializerBase::SerializationAcceptor acceptor = [&]( - const std::string& blobName, const std::string& data) { - // transaction should take care of locking - VLOG(2) << "Sending " << blobName << " blob's data of size " - << data.size() << " to db"; - auto transaction = out_db->NewTransaction(); - transaction->Put(blobName, data); - transaction->Commit(); - }; - - const vector& inputs = OperatorBase::Inputs(); - for (int i = 0; i < inputs.size(); ++i) { - inputs[i]->Serialize(blob_names_[i], acceptor); - } - out_db->Close(); - return true; - } - - private: - Workspace* ws_; - bool absolute_path_; - string strip_prefix_; - string db_name_; - string db_type_; - std::vector blob_names_; -}; - -template -string FormatString(const string& pattern, Ts... values) { - // Note(Yangqing): We believe that 1024 is enough, but who are we to assert - // that? - // As a result, if things go wrong, we'll just throw the towel and quit loud. - // Yeah, I know that there is snprintf, but it is not present in *some* - // platforms unfortunately. - char buffer[1024]; - int written = sprintf(buffer, pattern.c_str(), values...); - if (written < 0 || written + 1 > 1024) { - LOG(FATAL) << "FormatString fails: total bytes written " << written; - } - return string(buffer); - /* - * The following is the snprintf version that is safe; enable it one day? - unsigned int required = - std::snprintf(nullptr, 0, pattern.c_str(), values...) + 1; - char bytes[required]; - std::snprintf(bytes, required, pattern.c_str(), values...); - return string(bytes); - */ -} - -// CheckpointOp is a wrapper over a SaveFloatTensorOp that basically allows -// flexible naming over iterations. -// The file pattern in db_name should be a format string that can be passed into -// sprintf with an int argument specifying the current iteration. An example: -// "/path/to/my/checkpoint/checkpoint_at_%d.pb" -template -class CheckpointOp final : public Operator { - public: - CheckpointOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - db_pattern_(OperatorBase::GetSingleArgument("db", "")), - every_(OperatorBase::GetSingleArgument("every", 1)), - ws_(ws), - save_op_def_(operator_def) { - CAFFE_ENFORCE_GT( - db_pattern_.size(), 0, "Must specify a checkpoint file pattern."); - CAFFE_ENFORCE_GT(every_, 0, "Checkpoint interval should be positive."); - if (every_ == 1) { - // Just issue a warning, but it's totally legal so we don't do anything. - LOG(WARNING) << "It seems that we are checkpointting every iteration. " - << "Is that intended?"; - } - save_op_def_.set_type("Save"); - } - - bool RunOnDevice() override { - int64_t iter = - OperatorBase::Input(0).template data()[0]; - if (iter % every_ == 0) { - GetMutableArgument("db", true, &save_op_def_) - ->set_s(FormatString(db_pattern_, iter)); - SaveOp sub_op(save_op_def_, ws_); - return sub_op.Run(); - } else { - return true; - } - } - - private: - string db_pattern_; - int every_; - Workspace* ws_; - OperatorDef save_op_def_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LOAD_SAVE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/local_response_normalization_op.h b/app/src/main/cpp/caffe2/operators/local_response_normalization_op.h deleted file mode 100644 index 79f388c..0000000 --- a/app/src/main/cpp/caffe2/operators/local_response_normalization_op.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LOCAL_RESPONSE_NORMALIZATION_OP_H_ -#define CAFFE2_OPERATORS_LOCAL_RESPONSE_NORMALIZATION_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class LRNOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LRNOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - size_(OperatorBase::GetSingleArgument("size", 0)), - alpha_(OperatorBase::GetSingleArgument("alpha", 0)), - beta_(OperatorBase::GetSingleArgument("beta", 0)), - bias_(OperatorBase::GetSingleArgument("bias", 1)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - pre_pad_((size_ - 1) / 2) { - DCHECK_GT(size_, 0); - DCHECK_EQ(size_ % 2, 1); - DCHECK_GT(alpha_, 0); - DCHECK_GT(beta_, 0); - } - - bool RunOnDevice() override { - switch (order_) { - case StorageOrder::NHWC: - return RunOnDeviceWithOrderNHWC(); - case StorageOrder::NCHW: - return RunOnDeviceWithOrderNCHW(); - default: - LOG(FATAL) << "Unknown storage order: " << order_; - } - // To suppress old compiler warnings - return true; - } - - virtual bool RunOnDeviceWithOrderNCHW() = 0; - virtual bool RunOnDeviceWithOrderNHWC() = 0; - - protected: - const int size_; - const float alpha_; - const float beta_; - const float bias_; - const StorageOrder order_; - const int pre_pad_; - // Input: X; Output: Y, scale. -}; - -template -class LRNOp final : public LRNOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LRNOp(const OperatorDef& operator_def, Workspace* ws) - : LRNOpBase(operator_def, ws) {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - protected: - // Input: X; Output: Y, scale. - OUTPUT_TAGS(OUTPUT, SCALE); - Tensor* scale_ = nullptr; - Tensor local_scale_tensor_; -}; - -template -class LRNGradientOp final : public LRNOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LRNGradientOp(const OperatorDef& operator_def, Workspace* ws) - : LRNOpBase(operator_def, ws) {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - protected: - // Input: X, Y, scale, dY; Output: dX - INPUT_TAGS(INPUT, OUTPUT, SCALE, OUTPUT_GRAD); - Tensor* scale_ = nullptr; - Tensor local_scale_tensor_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LOCAL_RESPONSE_NORMALIZATION_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/loss_op.h b/app/src/main/cpp/caffe2/operators/loss_op.h deleted file mode 100644 index aa61a89..0000000 --- a/app/src/main/cpp/caffe2/operators/loss_op.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LOSS_OP_H_ -#define CAFFE2_OPERATORS_LOSS_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/reduction_ops.h" -#include "caffe2/operators/utility_ops.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// AveragedLoss takes in the input and produces the output loss value as -// the average of the input. -template -class AveragedLoss final : public SumElementsOp { - public: - AveragedLoss(const OperatorDef& operator_def, Workspace* ws) - : SumElementsOp(operator_def, ws, true) {} - ~AveragedLoss() {} -}; - -template -class AveragedLossGradient final : public SumElementsGradientOp { - public: - AveragedLossGradient(const OperatorDef& operator_def, Workspace* ws) - : SumElementsGradientOp(operator_def, ws, true) {} - ~AveragedLossGradient() {} -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LOSS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/lpnorm_op.h b/app/src/main/cpp/caffe2/operators/lpnorm_op.h deleted file mode 100644 index d8f46a7..0000000 --- a/app/src/main/cpp/caffe2/operators/lpnorm_op.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LPNORM_OP_H_ -#define CAFFE2_OPERATORS_LPNORM_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class LpNormOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LpNormOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - p_(OperatorBase::GetSingleArgument("p", 2)) { - CAFFE_ENFORCE(p_ == 1 || p_ == 2, "p should be either 1 or 2."); - } - - bool RunOnDevice() override; - - protected: - int p_; - INPUT_TAGS(X_IN); - OUTPUT_TAGS(OUT); - // Input: X; Output: Norm -}; - -template -class LpNormGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LpNormGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - p_(OperatorBase::GetSingleArgument("p", 2)) { - CAFFE_ENFORCE(p_ == 1 || p_ == 2, "p should be either 1 or 2."); - } - - bool RunOnDevice() override; - - protected: - int p_; - INPUT_TAGS(X_IN, DER_NORM_IN); - OUTPUT_TAGS(DER_X_OUT); - // Input: X, dNorm; Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LPNORM_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/lstm_unit_op.h b/app/src/main/cpp/caffe2/operators/lstm_unit_op.h deleted file mode 100644 index 2315569..0000000 --- a/app/src/main/cpp/caffe2/operators/lstm_unit_op.h +++ /dev/null @@ -1,287 +0,0 @@ -#ifndef CAFFE2_OPERATORS_LSTM_UNIT_OP_H_ -#define CAFFE2_OPERATORS_LSTM_UNIT_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/conversions.h" - -namespace caffe2 { -namespace detail { -template -inline T sigmoid(T x) { - return 1. / (1. + exp(-x)); -} - -template -inline T host_tanh(T x) { - return 2. * sigmoid(2. * x) - 1.; -} - -template -void LSTMUnit( - int N, - int D, - int t, - const T* H_prev, - const T* C_prev, - const T* X, - const int32_t* seqLengths, - bool drop_states, - T* C, - T* H, - const float forget_bias, - Context* /*context*/) { - for (int n = 0; n < N; ++n) { - const bool valid = t < seqLengths[n]; - - for (int d = 0; d < D; ++d) { - if (!valid) { - if (drop_states) { - H[d] = 0; - C[d] = 0; - } else { - H[d] = H_prev[d]; - C[d] = C_prev[d]; - } - } else { - const T i = sigmoid(X[d]); - const T f = sigmoid(X[1 * D + d] + convert::To(forget_bias)); - const T o = sigmoid(X[2 * D + d]); - const T g = host_tanh(X[3 * D + d]); - const T c_prev = C_prev[d]; - const T c = f * c_prev + i * g; - C[d] = c; - const T host_tanh_c = host_tanh(c); - H[d] = o * host_tanh_c; - } - } - H_prev += D; - C_prev += D; - X += 4 * D; - C += D; - H += D; - } -} - -template -void LSTMUnitGradient( - int N, - int D, - int t, - const T* C_prev, - const T* X, - const int32_t* seqLengths, - const T* C, - const T* H, - const T* C_diff, - const T* H_diff, - bool drop_states, - T* H_prev_diff, - T* C_prev_diff, - T* X_diff, - const float forget_bias, - Context* /*context*/) { - for (int n = 0; n < N; ++n) { - const bool valid = t < seqLengths[n]; - - for (int d = 0; d < D; ++d) { - T* c_prev_diff = C_prev_diff + d; - T* h_prev_diff = H_prev_diff + d; - T* i_diff = X_diff + d; - T* f_diff = X_diff + 1 * D + d; - T* o_diff = X_diff + 2 * D + d; - T* g_diff = X_diff + 3 * D + d; - - if (!valid) { - if (drop_states) { - *h_prev_diff = 0; - *c_prev_diff = 0; - } else { - *h_prev_diff = H_diff[d]; - *c_prev_diff = C_diff[d]; - } - *i_diff = 0; - *f_diff = 0; - *o_diff = 0; - *g_diff = 0; - } else { - const T i = sigmoid(X[d]); - const T f = sigmoid(X[1 * D + d] + convert::To(forget_bias)); - const T o = sigmoid(X[2 * D + d]); - const T g = host_tanh(X[3 * D + d]); - const T c_prev = C_prev[d]; - const T c = C[d]; - const T host_tanh_c = host_tanh(c); - const T c_term_diff = C_diff[d] + H_diff[d] * o * (1 - host_tanh_c * host_tanh_c); - *c_prev_diff = c_term_diff * f; - *h_prev_diff = 0; // not used in 'valid' case - *i_diff = c_term_diff * g * i * (1 - i); - *f_diff = c_term_diff * c_prev * f * (1 - f); - *o_diff = H_diff[d] * host_tanh_c * o * (1 - o); - *g_diff = c_term_diff * i * (1 - g * g); - } - } - C_prev += D; - X += 4 * D; - C += D; - H += D; - C_diff += D; - H_diff += D; - X_diff += 4 * D; - H_prev_diff += D; - C_prev_diff += D; - } -} -} // namespace detail - -template -class LSTMUnitOp : public Operator { - public: - LSTMUnitOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - forget_bias_( - static_cast(OperatorBase::template GetSingleArgument( - "forget_bias", - 0.0))), - drop_states_(OperatorBase::template GetSingleArgument( - "drop_states", - false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - - template - bool DoRunWithType() { - // Extract N - const auto N = Input(CELL_T_M_1).dim(1); - - // Gates: 1xNxG - const auto G = Input(GATES).dim(2); - const auto D = Input(CELL_T_M_1).dim(2); - - CAFFE_ENFORCE_EQ(4 * D, G); - const auto* H_prev = Input(HIDDEN_T_M_1).template data(); - const auto* C_prev = Input(CELL_T_M_1).template data(); - const auto* X = Input(GATES).template data(); - CAFFE_ENFORCE_EQ(Input(SEQ_LENGTHS).size(), N); - const auto* seqLengths = Input(SEQ_LENGTHS).template data(); - const auto t = OperatorBase::Input>(TIMESTEP) - .template data()[0]; - Output(CELL_T)->ResizeLike(Input(CELL_T_M_1)); - auto* C = Output(CELL_T)->template mutable_data(); - Output(HIDDEN_T)->ResizeLike(Input(CELL_T_M_1)); - auto* H = Output(HIDDEN_T)->template mutable_data(); - detail::LSTMUnit( - N, - D, - t, - H_prev, - C_prev, - X, - seqLengths, - drop_states_, - C, - H, - forget_bias_, - &context_); - return true; - } - - bool RunOnDevice() override { - return DoRunWithType(); - } - - protected: - INPUT_TAGS(HIDDEN_T_M_1, CELL_T_M_1, GATES, SEQ_LENGTHS, TIMESTEP); - OUTPUT_TAGS(HIDDEN_T, CELL_T); - - float forget_bias_; - - private: - bool drop_states_; -}; - -template -class LSTMUnitGradientOp : public Operator { - public: - LSTMUnitGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - forget_bias_( - static_cast(OperatorBase::template GetSingleArgument( - "forget_bias", - 0.0))), - drop_states_(OperatorBase::template GetSingleArgument( - "drop_states", - false)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - template - bool DoRunWithType() { - // Extract N - const auto N = Input(CELL_T_M_1).dim(1); - - // Gates: 1xNxG - const auto G = Input(GATES).dim(2); - const auto D = Input(CELL_T_M_1).dim(2); - - CAFFE_ENFORCE_EQ(4 * D, G); - const auto* C_prev = Input(CELL_T_M_1).template data(); - const auto* X = Input(GATES).template data(); - const auto t = OperatorBase::Input>(TIMESTEP) - .template data()[0]; - const auto* C = Input(CELL_T).template data(); - const auto* H = Input(HIDDEN_T).template data(); - const auto* C_diff = Input(CELL_T_GRAD).template data(); - const auto* H_diff = Input(HIDDEN_T_GRAD).template data(); - const auto* seqLengths = Input(SEQ_LENGTHS).template data(); - Output(HIDDEN_T_M_1_GRAD)->ResizeLike(Input(HIDDEN_T_M_1)); - auto* H_prev_diff = Output(HIDDEN_T_M_1_GRAD)->template mutable_data(); - Output(CELL_T_M_1_GRAD)->ResizeLike(Input(CELL_T_M_1)); - auto* C_prev_diff = Output(CELL_T_M_1_GRAD)->template mutable_data(); - Output(GATES_GRAD)->ResizeLike(Input(GATES)); - auto* X_diff = Output(GATES_GRAD)->template mutable_data(); - - detail::LSTMUnitGradient( - N, - D, - t, - C_prev, - X, - seqLengths, - C, - H, - C_diff, - H_diff, - drop_states_, - H_prev_diff, - C_prev_diff, - X_diff, - forget_bias_, - &context_); - return true; - } - - bool RunOnDevice() override { - return DoRunWithType(); - } - - protected: - INPUT_TAGS( - HIDDEN_T_M_1, - CELL_T_M_1, - GATES, - SEQ_LENGTHS, - TIMESTEP, - HIDDEN_T, - CELL_T, - HIDDEN_T_GRAD, - CELL_T_GRAD, ); - OUTPUT_TAGS(HIDDEN_T_M_1_GRAD, CELL_T_M_1_GRAD, GATES_GRAD); - - float forget_bias_; - - private: - bool drop_states_; -}; -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_LSTM_UNIT_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/map_ops.h b/app/src/main/cpp/caffe2/operators/map_ops.h deleted file mode 100644 index 8d1a18f..0000000 --- a/app/src/main/cpp/caffe2/operators/map_ops.h +++ /dev/null @@ -1,258 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MAP_OPS_H_ -#define CAFFE2_OPERATORS_MAP_OPS_H_ - -#include -#include -#include -#include -#include -#include -#include - -#include "caffe2/core/blob_serialization.h" -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -struct TypeNameTraits { - static constexpr const char* name = "unknown"; -}; - -template <> -struct TypeNameTraits { - static constexpr const char* name = "int64_t"; -}; - -template <> -struct TypeNameTraits { - static constexpr const char* name = "int32_t"; -}; - -template -struct MapTypeTraits { - using MapType = std::unordered_map; - static string MapTypeName() { - return string("(std::unordered_map<") + TypeNameTraits::name + ", " + - TypeNameTraits::name + ">)"; - } -}; - -using MapType64To64 = MapTypeTraits::MapType; -using MapType64To32 = MapTypeTraits::MapType; -using MapType32To32 = MapTypeTraits::MapType; -using MapType32To64 = MapTypeTraits::MapType; - -template -class CreateMapOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - CreateMapOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~CreateMapOp() {} - - bool RunOnDevice() override { - TensorProto::DataType key_dtype = - static_cast(OperatorBase::GetSingleArgument( - "key_dtype", TensorProto_DataType_INT32)); - - return DispatchHelper>::call( - this, DataTypeToTypeMeta(key_dtype)); - } - - template - bool DoRunWithType() { - TensorProto::DataType value_dtype = - static_cast(OperatorBase::GetSingleArgument( - "value_dtype", TensorProto_DataType_INT32)); - - return DispatchHelper< - TensorTypes2, - KEY_T>::call(this, DataTypeToTypeMeta(value_dtype)); - } - - template - bool DoRunWithType2() { - // clear to make sure the map is empty - OperatorBase::Output::MapType>(MAP) - ->clear(); - return true; - } - - template - bool DoRunWithOtherType2() { - TensorProto::DataType value_dtype = - static_cast(OperatorBase::GetSingleArgument( - "value_dtype", TensorProto_DataType_INT32)); - - CAFFE_THROW( - "CreateMap is not implemented on value tensor of type ", - DataTypeToTypeMeta(value_dtype).name(), - "Consider adding it a type in the list DispatchHelper"); - } - - OUTPUT_TAGS(MAP); -}; - -template -class KeyValueToMapOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - KeyValueToMapOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~KeyValueToMapOp() {} - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(KEYS)); - } - - template - bool DoRunWithType() { - return DispatchHelper< - TensorTypes2, - KEY_T>::call(this, Input(VALUES)); - } - - template - bool DoRunWithType2() { - using MapType = typename MapTypeTraits::MapType; - const auto& key_input = Input(KEYS); - const auto& value_input = Input(VALUES); - - CAFFE_ENFORCE_EQ(key_input.size(), value_input.size()); - - auto* key_data = key_input.template data(); - auto* value_data = value_input.template data(); - - auto* map_data = OperatorBase::Output(MAP); - - for (int i = 0; i < key_input.size(); ++i) { - map_data->emplace(key_data[i], value_data[i]); - } - - return true; - } - - template - bool DoRunWithOtherType2() { - CAFFE_THROW( - "KeyValueToMap is not implemented on value tensor of type ", - Input(VALUES).meta().name(), - "Consider adding it a type in the list DispatchHelper"); - } - - INPUT_TAGS(KEYS, VALUES); - OUTPUT_TAGS(MAP); -}; - -template -class MapToKeyValueOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MapToKeyValueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~MapToKeyValueOp() {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, OperatorBase::InputBlob(MAP)); - } - - template - bool DoRunWithType() { - using key_type = typename MAP_T::key_type; - using mapped_type = typename MAP_T::mapped_type; - auto& map_data = OperatorBase::Input(MAP); - auto* key_output = Output(KEYS); - auto* value_output = Output(VALUES); - key_output->Resize(map_data.size()); - value_output->Resize(map_data.size()); - auto* key_data = key_output->template mutable_data(); - auto* value_data = value_output->template mutable_data(); - - for (const auto& it : map_data) { - *key_data = it.first; - *value_data = it.second; - key_data++; - value_data++; - } - - return true; - } - - INPUT_TAGS(MAP); - OUTPUT_TAGS(KEYS, VALUES); -}; - -template -class MapSerializer : public BlobSerializerBase { - public: - using MapType = typename MapTypeTraits::MapType; - - void Serialize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor) override { - CAFFE_ENFORCE(blob.IsType()); - const MapType& map_data = blob.template Get(); - TIndex sz = map_data.size(); - Tensor key_tensor; - key_tensor.Resize(sz); - Tensor value_tensor; - value_tensor.Resize(sz); - auto* key_data = key_tensor.mutable_data(); - auto* value_data = value_tensor.mutable_data(); - for (const auto& it : map_data) { - *key_data = it.first; - *value_data = it.second; - key_data++; - value_data++; - } - - TensorProtos tensor_protos; - TensorSerializer ser; - ser.Serialize( - key_tensor, name, tensor_protos.add_protos(), 0, key_tensor.size()); - ser.Serialize( - value_tensor, name, tensor_protos.add_protos(), 0, value_tensor.size()); - - BlobProto blob_proto; - blob_proto.set_name(name); - blob_proto.set_type(MapTypeTraits::MapTypeName()); - blob_proto.set_content(tensor_protos.SerializeAsString()); - acceptor(name, blob_proto.SerializeAsString()); - } -}; - -template -class MapDeserializer : public BlobDeserializerBase { - public: - using MapType = typename MapTypeTraits::MapType; - - void Deserialize(const BlobProto& proto, Blob* blob) override { - TensorProtos tensor_protos; - CAFFE_ENFORCE( - tensor_protos.ParseFromString(proto.content()), - "Fail to parse TensorProtos"); - TensorDeserializer deser; - Tensor key_tensor, value_tensor; - deser.Deserialize(tensor_protos.protos(0), &key_tensor); - deser.Deserialize(tensor_protos.protos(1), &value_tensor); - auto* key_data = key_tensor.data(); - auto* value_data = value_tensor.data(); - - auto* map_ptr = blob->template GetMutable(); - for (int i = 0; i < key_tensor.size(); ++i) { - map_ptr->emplace(key_data[i], value_data[i]); - } - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MAP_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/margin_ranking_criterion_op.h b/app/src/main/cpp/caffe2/operators/margin_ranking_criterion_op.h deleted file mode 100644 index 933db52..0000000 --- a/app/src/main/cpp/caffe2/operators/margin_ranking_criterion_op.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MARGIN_RANKING_CRITERION_OP_H_ -#define CAFFE2_OPERATORS_MARGIN_RANKING_CRITERION_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class MarginRankingCriterionOp final : public Operator { - public: - MarginRankingCriterionOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(float, "margin", margin_, 1.0) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float margin_; -}; - -template -class MarginRankingCriterionGradientOp final : public Operator { - public: - MarginRankingCriterionGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - OP_SINGLE_ARG(float, "margin", margin_, 1.0) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float margin_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MARGIN_RANKING_CRITERION_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/math_ops.h b/app/src/main/cpp/caffe2/operators/math_ops.h deleted file mode 100644 index bc7386e..0000000 --- a/app/src/main/cpp/caffe2/operators/math_ops.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MATH_OP_H_ -#define CAFFE2_OPERATORS_MATH_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/operators/elementwise_op.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -struct PowFunctor { - explicit PowFunctor(OperatorBase& op) { - exponent_ = op.GetSingleArgument("exponent", 0); - } - - template - inline void - operator()(const int n, const T* x, T* y, Context* device_context) { - math::Powx(n, x, exponent_, y, device_context); - } - - float exponent_; -}; -} - -#endif diff --git a/app/src/main/cpp/caffe2/operators/matmul_op.h b/app/src/main/cpp/caffe2/operators/matmul_op.h deleted file mode 100644 index 106d8e8..0000000 --- a/app/src/main/cpp/caffe2/operators/matmul_op.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MATMUL_OP_H_ -#define CAFFE2_OPERATORS_MATMUL_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class MatMulOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MatMulOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - trans_a_(OperatorBase::GetSingleArgument("trans_a", 0)), - trans_b_(OperatorBase::GetSingleArgument("trans_b", 0)) {} - ~MatMulOp() {} - - bool RunOnDevice() override { - const auto& A = Input(0); - const auto& B = Input(1); - auto* Y = Output(0); - - CAFFE_ENFORCE(A.ndim() == 2, A.ndim()); - CAFFE_ENFORCE(B.ndim() == 2, B.ndim()); - - int a_dim0, a_dim1, b_dim0, b_dim1; - - if (trans_a_) { - a_dim0 = A.dim32(1); - a_dim1 = A.dim32(0); - } else { - a_dim0 = A.dim32(0); - a_dim1 = A.dim32(1); - } - - if (trans_b_) { - b_dim0 = B.dim32(1); - b_dim1 = B.dim32(0); - } else { - b_dim0 = B.dim32(0); - b_dim1 = B.dim32(1); - } - - auto dimErrorString = [&]() { - return MakeString( - "Dimension mismatch: ", - trans_a_ ? "trans(A): " : "A: ", - a_dim0, - " ", - a_dim1, - trans_b_ ? ", trans(B): " : ", B: ", - b_dim0, - " ", - b_dim1); - }; - // Error checking - CAFFE_ENFORCE(a_dim1 == b_dim0, dimErrorString()); - - Y_shape_cache_[0] = a_dim0; - Y_shape_cache_[1] = b_dim1; - Y->Resize(Y_shape_cache_); - CAFFE_ENFORCE(a_dim0 * b_dim1 == Y->size(), dimErrorString()); - - // Y = A * B - math::Gemm( - trans_a_ ? CblasTrans : CblasNoTrans, - trans_b_ ? CblasTrans : CblasNoTrans, - a_dim0, - b_dim1, - a_dim1, - 1, - A.template data(), - B.template data(), - 0, - Y->template mutable_data(), - &context_); - return true; - } - - protected: - // A local vector to cache the output shape so we don't need to recreate - // a vector object every time we run Run(). - vector Y_shape_cache_{0, 0}; - bool trans_a_; - bool trans_b_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MATMUL_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/max_pool_with_index.h b/app/src/main/cpp/caffe2/operators/max_pool_with_index.h deleted file mode 100644 index 64337dc..0000000 --- a/app/src/main/cpp/caffe2/operators/max_pool_with_index.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MAX_POOL_WITH_INDEX_H_ -#define CAFFE2_OPERATORS_MAX_POOL_WITH_INDEX_H_ - -#include -#include "caffe2/core/context.h" -#include "caffe2/core/context_gpu.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/operators/pool_op.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -class MaxPoolWithIndexOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(CUDAContext); - MaxPoolWithIndexOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) {} - ~MaxPoolWithIndexOp() {} - - template - bool DoRunWithType(); - - bool RunOnDevice() override; - - // Input: X - // Output: Y, mask -}; - -class MaxPoolWithIndexGradientOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(CUDAContext); - MaxPoolWithIndexGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) {} - ~MaxPoolWithIndexGradientOp() {} - - template - bool DoRunWithType(); - - bool RunOnDevice() override; - - // Input: X, dY, mask - // Output: dX -}; - -}; // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MAX_POOL_WITH_INDEX_H_ diff --git a/app/src/main/cpp/caffe2/operators/merge_id_lists_op.h b/app/src/main/cpp/caffe2/operators/merge_id_lists_op.h deleted file mode 100644 index 9858b98..0000000 --- a/app/src/main/cpp/caffe2/operators/merge_id_lists_op.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MERGE_ID_LISTS_OP_H_ -#define CAFFE2_OPERATORS_MERGE_ID_LISTS_OP_H_ - -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class MergeIdListsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(MergeIdListsOp); - - template - bool DoRunWithType() { - auto& first_lengths = Input(0); - CAFFE_ENFORCE_EQ(first_lengths.ndim(), 1, "LENGTHS should be 1-D"); - const auto batch_size = first_lengths.size(); - - auto* out_lengths = Output(0); - out_lengths->ResizeLike(first_lengths); - - auto* out_lengths_data = out_lengths->template mutable_data(); - - /** - * Loop to figure out how much space to reserve for output - * and perform checks. - */ - auto M = 0; - for (size_t i = 0; i < InputSize(); i += 2) { - auto& lengths = Input(i); - CAFFE_ENFORCE_EQ(lengths.ndim(), 1, "LENGTHS should be 1-D"); - CAFFE_ENFORCE_EQ(lengths.size(), batch_size, "LENGTHS should be equal"); - auto& values = Input(i + 1); - CAFFE_ENFORCE_EQ(values.ndim(), 1, "VALUES should be 1-D"); - M += values.size(); - } - - auto* out_values = Output(1); - out_values->Resize(M); - - T* out_values_data = out_values->template mutable_data(); - auto pos = 0; - - // TODO(badri): Use unordered_set if performance is an issue - std::set deduped; - std::vector offsets(InputSize(), 0); - for (auto sample = 0; sample < batch_size; sample++) { - for (size_t i = 0; i < InputSize(); i += 2) { - auto& lengths = Input(i); - const auto* lengths_data = lengths.template data(); - - auto& values = Input(i + 1); - const T* values_data = values.template data(); - const auto length = lengths_data[sample]; - - for (auto j = offsets[i]; j < offsets[i] + length; j++) { - deduped.insert(values_data[j]); - } - offsets[i] += length; - } - for (auto val : deduped) { - out_values_data[pos++] = val; - } - out_lengths_data[sample] = deduped.size(); - deduped.clear(); - } - out_values->Resize(pos); - return true; - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(1)); - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MERGE_ID_LISTS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/multi_class_accuracy_op.h b/app/src/main/cpp/caffe2/operators/multi_class_accuracy_op.h deleted file mode 100644 index 5710f5a..0000000 --- a/app/src/main/cpp/caffe2/operators/multi_class_accuracy_op.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef CAFFE2_OPERATORS_MULTI_CLASS_ACCURACY_OP_H_ -#define CAFFE2_OPERATORS_MULTI_CLASS_ACCURACY_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class MultiClassAccuracyOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(MultiClassAccuracyOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - INPUT_TAGS(PREDICTION, LABEL); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_MULTI_CLASS_ACCURACY_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/no_default_engine_op.h b/app/src/main/cpp/caffe2/operators/no_default_engine_op.h deleted file mode 100644 index c148094..0000000 --- a/app/src/main/cpp/caffe2/operators/no_default_engine_op.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CAFFE2_OPERATORS_NO_DEFAULT_ENGINE_OP_H_ -#define CAFFE2_OPERATORS_NO_DEFAULT_ENGINE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -/** - * A helper class to denote that an op does not have a default engine. - * - * NoDefaultEngineOp is a helper class that one can use to denote that a - * specific operator is not intended to be called without an explicit engine - * given. This is the case for e.g. the communication operators where one has - * to specify a backend (like MPI or ZEROMQ). - */ -template -class NoDefaultEngineOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(NoDefaultEngineOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - CAFFE_THROW( - "The operator ", - this->debug_def().type(), - " does not have a default engine implementation. Please " - "specify an engine explicitly for this operator."); - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_NO_DEFAULT_ENGINE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/normalize_op.h b/app/src/main/cpp/caffe2/operators/normalize_op.h deleted file mode 100644 index dc5fc7e..0000000 --- a/app/src/main/cpp/caffe2/operators/normalize_op.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef CAFFE2_OPERATORS_NORMALIZE_OP_H_ -#define CAFFE2_OPERATORS_NORMALIZE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class NormalizeOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - NormalizeOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - - bool RunOnDevice() override { - const auto& x = Input(0); - auto* y = Output(0); - const auto* xData = x.template data(); - y->ResizeLike(x); - auto* yData = y->template mutable_data(); - - const auto canonical_axis = x.canonical_axis_index( - OperatorBase::GetSingleArgument("axis", -1)); - const int m = x.dim32(canonical_axis); - const int n = x.size() / m; - const int sf = x.size_from_dim(canonical_axis + 1); - DoNormalize(xData, yData, m, n, sf); - return true; - } - - private: - void - DoNormalize(const T* xData, T* yData, const int m, const int n, const int sf); -}; - -template -class NormalizeGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - NormalizeGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) {} - - bool RunOnDevice() override { - const auto& x = Input(0); - const auto& gOut = Input(GRAD_OUT); - auto* gIn = Output(GRAD_IN); - gIn->ResizeLike(gOut); - - const auto* xData = x.template data(); - const auto* gOutData = gOut.template data(); - auto* gInData = gIn->template mutable_data(); - - const auto canonical_axis = x.canonical_axis_index( - OperatorBase::GetSingleArgument("axis", -1)); - const int m = x.dim32(canonical_axis); - const int n = x.size() / m; - const int sf = x.size_from_dim(canonical_axis + 1); - DoNormalize(xData, gOutData, gInData, m, n, sf); - return true; - } - - private: - void DoNormalize( - const T* xData, - const T* gOutData, - T* gInData, - const int m, - const int n, - const int sf); - - INPUT_TAGS(INPUT, GRAD_OUT); - OUTPUT_TAGS(GRAD_IN); -}; - -template -class NormalizeL1Op final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(NormalizeL1Op) - - bool RunOnDevice() override { - const auto& x = Input(0); - auto* y = Output(0); - const auto* xData = x.template data(); - y->ResizeLike(x); - auto* yData = y->template mutable_data(); - - const auto canonical_axis = x.canonical_axis_index( - OperatorBase::GetSingleArgument("axis", -1)); - const int m = x.dim32(canonical_axis); - const int n = x.size() / m; - const int sf = x.size_from_dim(canonical_axis + 1); - DoNormalize(xData, yData, m, n, sf); - return true; - } - - private: - void - DoNormalize(const T* xData, T* yData, const int m, const int n, const int sf); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_NORMALIZE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/one_hot_ops.h b/app/src/main/cpp/caffe2/operators/one_hot_ops.h deleted file mode 100644 index d8c4c79..0000000 --- a/app/src/main/cpp/caffe2/operators/one_hot_ops.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef CAFFE_OPERATORS_ONE_HOT_OPS_H_ -#define CAFFE_OPERATORS_ONE_HOT_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class OneHotOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - OneHotOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& indices = Input(0); - CAFFE_ENFORCE_EQ( - indices.ndim(), - 1, - "indices input must be 1D tensor of data type TIndex"); - - // Index size input must be in CPU context - auto& index_size_tensor = OperatorBase::Input>(1); - CAFFE_ENFORCE_EQ( - index_size_tensor.size(), - 1, - "index_size_tensor input must be scalar of data type TIndex"); - - auto batch_size = indices.size(); - auto index_size = *index_size_tensor.template data(); - auto one_hots = Output(0); - one_hots->Resize(batch_size, index_size); - auto output_size = one_hots->size(); - if (output_size == 0) { - return true; - } - - DoOneHotOp(batch_size, index_size, indices, one_hots); - return true; - } - - protected: - void DoOneHotOp( - TIndex batch_size, - TIndex index_size, - const Tensor& indices, - Tensor* output); -}; - -template -class BatchOneHotOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - BatchOneHotOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(X)); - } - - template - bool DoRunWithType(); - - protected: - INPUT_TAGS(X, LENS, VALS); - OUTPUT_TAGS(ONE_HOT); -}; - -} // namespace caffe2 - -#endif // CAFFE_OPERATORS_ONE_HOT_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/operator_fallback_gpu.h b/app/src/main/cpp/caffe2/operators/operator_fallback_gpu.h deleted file mode 100644 index 62d9cdb..0000000 --- a/app/src/main/cpp/caffe2/operators/operator_fallback_gpu.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ -#define CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ - -#include "caffe2/core/common.h" -#include "caffe2/core/context.h" -#include "caffe2/core/context_gpu.h" -#include "caffe2/core/operator.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -/** - * @brief A templated class to allow one to wrap a CPU operator as a CUDA - * operator. - * - * This class can be used when one does not have the CUDA implementation ready - * yet for an operator. Essentially, what this op does is to automatically - * deal with data copy for you. Plausibly, this causes a lot of overhead and - * is not optimal, so you should use this operator mostly for quick prototyping - * purpose. - * - * All the input and output of the original operator should be TensorCPU. - * - * Example usage: if you have a class MyMagicOp that is CPU based, and you use - * the registration code - * REGISTER_CPU_OPERATOR(MyMagic, MyMagicOp); - * to register the CPU side, you can create its corresponding GPU operator - * (with performance hits of course) via - * REGISTER_CUDA_OPERATOR(MyMagic, - * GPUFallbackOp); - * - * Advanced usage: if you want to have some specific outputs never copied, you - * can use the SkipOutputCopy template argument to do that. For example, if - * MyMagic produces two outputs and the first output is always going to live on - * the CPU, you can do - * REGISTER_CUDA_OPERATOR(MyMagic, - * GPUFallbackOp>); - */ -template > -class GPUFallbackOp final : public Operator { - public: - USE_OPERATOR_FUNCTIONS(CUDAContext); - GPUFallbackOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws) { - CAFFE_ENFORCE_EQ(def.device_option().device_type(), CUDA); - OperatorDef base_def_(def); - // base_def_ runs on CPU, so we will set its device option to CPU. - base_def_.clear_device_option(); - base_def_.mutable_device_option()->set_device_type(CPU); - // Set up the symbols for the local workspace. - for (const string& name : def.input()) { - local_input_blobs_.push_back(local_ws_.CreateBlob(name)); - CHECK_NOTNULL(local_input_blobs_.back()); - } - base_op_.reset(new CPUOp(base_def_, &local_ws_)); - for (const string& name : def.output()) { - local_output_blobs_.push_back(local_ws_.GetBlob(name)); - CHECK_NOTNULL(local_output_blobs_.back()); - } - } - - bool RunOnDevice() override { - bool need_sync = false; - for (int i = 0; i < InputSize(); ++i) { - if (OperatorBase::InputIsType(i)) { - local_input_blobs_[i]->template GetMutable()->CopyFrom( - Input(i), &context_); - need_sync = true; - } else { - VLOG(1) << "Input " << i << " is not TensorCUDA. Skipping copy."; - // Note(jiayq): This removes a const but conceptually - // local_input_blobs will only be used as const blob input for the - // base op so we are still fine. - local_input_blobs_[i]->ShareExternal( - const_cast(OperatorBase::Inputs()[i]->GetRaw()), - OperatorBase::Inputs()[i]->meta()); - } - } - - // Sync to make sure copies are done. - if (need_sync) { - context_.FinishDeviceComputation(); - } - - if (!base_op_->Run()) { - LOG(ERROR) << "Base op run failed in GPUFallbackOp. Def: " - << ProtoDebugString(this->debug_def()); - return false; - } - for (int i = 0; i < OutputSize(); ++i) { - if (SkipOutputCopy::Contains(i)) { - VLOG(1) << "Copy output: index " << i << " skipped."; - continue; - } - CAFFE_ENFORCE( - local_output_blobs_[i]->template IsType(), - "GPU fallback op currently does not support non-TensorCPU " - "output type who needs copying."); - Output(i)->CopyFrom( - local_output_blobs_[i]->template Get(), &context_); - } - return true; - } - - protected: - Workspace local_ws_; - vector local_input_blobs_; - vector local_output_blobs_; - std::unique_ptr base_op_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_OPERATOR_FALLBACK_H_ diff --git a/app/src/main/cpp/caffe2/operators/order_switch_ops.h b/app/src/main/cpp/caffe2/operators/order_switch_ops.h deleted file mode 100644 index b8420d6..0000000 --- a/app/src/main/cpp/caffe2/operators/order_switch_ops.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ORDER_SWITCH_OPS_H_ -#define CAFFE2_OPERATORS_ORDER_SWITCH_OPS_H_ - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// Note(Yangqing): I think it is possible to do a more general swapaxes operator -// but I am a little afraid of going down that general path. Only implementing -// the two actually needed ones here. - -template -class NHWC2NCHWOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(NHWC2NCHWOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: -}; - -template -class NCHW2NHWCOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(NCHW2NHWCOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ORDER_SWITCH_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/pack_rnn_sequence_op.h b/app/src/main/cpp/caffe2/operators/pack_rnn_sequence_op.h deleted file mode 100644 index c2fcb7d..0000000 --- a/app/src/main/cpp/caffe2/operators/pack_rnn_sequence_op.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PACK_RNN_SEQUENCE_OP_H_ -#define CAFFE2_OPERATORS_PACK_RNN_SEQUENCE_OP_H_ - -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class PackRNNSequenceOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - PackRNNSequenceOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(0)); - } - - template - bool DoRunWithType() { - // The value is copied from the sequence to the pack - // if Forward is true, and vice versa - int dim_offset = Forward ? 1 : 2; - auto& values = Input(0); - CAFFE_ENFORCE_GT(values.ndim(), dim_offset); - - // block_size is the size for each individual feature - TIndex block_size = values.size_from_dim(dim_offset); - auto values_vec = values.template data(); - - auto& lengths = Input(LENGTHS); - CAFFE_ENFORCE_EQ(lengths.ndim(), 1); - const auto cols = lengths.size(); - const int32_t* lengths_vec = lengths.template data(); - // the total number of rows is defined as the max number from lengths - // if when the lengths is empty, we set rows = 0 to support zero lengths - const auto rows = - cols ? *std::max_element(lengths_vec, lengths_vec + cols) : 0; - CAFFE_ENFORCE_GE(rows, 0); - int length_sum = 0; - if (cols > 0) { - math::Sum(cols, lengths_vec, &length_sum, &context_); - } - - vector shape; - // the output shape is rows * cols for the pack, - // or length_sum for the sequence - if (Forward) { - shape.push_back(rows); - shape.push_back(cols); - } else { - shape.push_back(length_sum); - } - // insert the dim for the feature - shape.insert( - shape.end(), values.dims().begin() + dim_offset, values.dims().end()); - - auto* output = Output(OUTPUTVALUE); - output->Resize(shape); - - auto output_data = output->template mutable_data(); - // initialize output_data with zero, as it is the default value for padding - // when certain length is smaller than rows - math::Set(output->size(), 0, output_data, &context_); - - int32_t offset = 0; - for (int c = 0; c < cols; c++) { - for (int r = 0; r < lengths_vec[c]; r++) { - auto input_offset = Forward ? (offset + r) : (r * cols + c); - auto output_offset = Forward ? (r * cols + c) : (offset + r); - context_.template CopyItems( - values.meta(), - block_size, - values_vec + input_offset * block_size, - output_data + output_offset * block_size); - } - offset += lengths_vec[c]; - } - return true; - } - - private: - INPUT_TAGS(INPUTVALUE, LENGTHS); - OUTPUT_TAGS(OUTPUTVALUE); -}; -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PACK_RNN_SEQUENCE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/pack_segments.h b/app/src/main/cpp/caffe2/operators/pack_segments.h deleted file mode 100644 index 720ba99..0000000 --- a/app/src/main/cpp/caffe2/operators/pack_segments.h +++ /dev/null @@ -1,154 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PACK_SEGMENTS_H_ -#define CAFFE2_OPERATORS_PACK_SEGMENTS_H_ - -#include -#include -#include -#include -#include -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class PackSegmentsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - // USE_SIMPLE_CTOR_DTOR(PackSegmentsOp) - USE_DISPATCH_HELPER; - - PackSegmentsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - pad_minf_(OperatorBase::GetSingleArgument("pad_minf", false)) { - if (pad_minf_) { - padding_ = -1.0 * std::numeric_limits::infinity(); - } else { - padding_ = 0; - } - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(LENGTHS)); - } - - template - bool DoRunWithType() { - const auto& data = Input(DATA); - const auto& lengths = Input(LENGTHS); - auto* output = Output(0); - - CAFFE_ENFORCE(data.ndim() >= 1, "DATA should be at least 1-D"); - CAFFE_ENFORCE(lengths.ndim() == 1, "LENGTH should be 1-D"); - - // Find the length of the longest sequence. - const T* l = lengths.template data(); - T max_length = 0; - for (T i = 0; i < lengths.dim(0); ++i) { - max_length = std::max(max_length, l[i]); - } - - auto shape = data.dims(); // Shape of output is batch_size x max_len x ... - shape[0] = max_length; - shape.insert(shape.begin(), lengths.size()); - output->Resize(shape); - // create output tensor - auto* out = static_cast(output->raw_mutable_data(data.meta())); - - if (!data.dim(0)) { - // Return empty output (with the proper shape) - return true; - } - - // Do padding - if (output->template IsType()) { - math::Set( - output->size(), - padding_, - output->template mutable_data(), - &context_); - } - - int block_size = data.size() / data.dim(0); - int block_bytesize = data.nbytes() / data.dim(0); - const auto* d = static_cast(data.raw_data()); - int start = 0; - for (int i = 0; i < lengths.dim(0); ++i) { - context_.template CopyItems( - data.meta(), - l[i] * block_size, - d + block_bytesize * start, - out + block_bytesize * max_length * i); - start += l[i]; - } - - return true; - } - - INPUT_TAGS(LENGTHS, DATA); - - private: - bool pad_minf_; - float padding_; -}; - -template -class UnpackSegmentsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(UnpackSegmentsOp) - USE_DISPATCH_HELPER; - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(LENGTHS)); - } - - template - bool DoRunWithType() { - const auto& data = Input(DATA); - const auto& lengths = Input(LENGTHS); - auto* output = Output(0); - - CAFFE_ENFORCE(data.ndim() >= 2, "DATA should be at least 2-D"); - CAFFE_ENFORCE(lengths.ndim() == 1, "LENGTH should be 1-D"); - - const T* l = lengths.template data(); - - T max_length = 0; - for (T i = 0; i < lengths.dim(0); ++i) { - max_length = std::max(max_length, l[i]); - } - T total_l = std::accumulate(l, l + lengths.dim(0), 0); - - auto shape = data.dims(); - CAFFE_ENFORCE( - shape[0] == lengths.dim(0), "LENGTH should match DATA in dimension 0"); - shape.erase(shape.begin()); - shape[0] = total_l; - output->Resize(shape); - // create output tensor - auto* out = static_cast(output->raw_mutable_data(data.meta())); - if (!(data.dim(0) * data.dim(1))) { - return true; - } - int block_size = data.size() / (data.dim(0) * data.dim(1)); - int block_bytesize = data.nbytes() / (data.dim(0) * data.dim(1)); - const auto* d = static_cast(data.raw_data()); - int start = 0; - for (int i = 0; i < lengths.dim(0); ++i) { - context_.template CopyItems( - data.meta(), - l[i] * block_size, - d + block_bytesize * data.dim(1) * i, - out + block_bytesize * start); - start += l[i]; - } - return true; - } - - INPUT_TAGS(LENGTHS, DATA); -}; - -} // namspace caffe2 -#endif // CAFFE2_OPERATORS_PACK_SEGMENTS_H_ diff --git a/app/src/main/cpp/caffe2/operators/pad_op.h b/app/src/main/cpp/caffe2/operators/pad_op.h deleted file mode 100644 index 5ab4f37..0000000 --- a/app/src/main/cpp/caffe2/operators/pad_op.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PAD_OP_H_ -#define CAFFE2_OPERATORS_PAD_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// Padding mode similar to numpy. -enum class PadMode { - CONSTANT = 0, // pad constant values, with string "constant" - REFLECT = 1, // pads with reflect values, with string "reflect" - EDGE = 2, // pads with the edge values, with string "edge" -}; - -PadMode StringToPadMode(const string&); - -template -class PadImageOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - PadImageOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws), - mode_(StringToPadMode( - OperatorBase::GetSingleArgument("mode", "constant"))), - value_(static_cast( - OperatorBase::GetSingleArgument("value", 0.0))) { - CAFFE_ENFORCE( - legacy_pad_ == LegacyPadding::NOTSET, - "Padding layer only supports explicit pad values."); - CAFFE_ENFORCE( - dilation_h() == 1 && dilation_w() == 1, - "Pooling op does not support dilation right now."); - CAFFE_ENFORCE( - stride_h() == 1 && stride_w() == 1, - "Pooling op does not support stride right now."); - // Pad op does not use kernel sizes, so we set it to 1 for computing the - // output size. - kernel_.assign(pads_.size() / 2, 1); - } - ~PadImageOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - static std::vector PadTensorInference( - const OperatorDef& def, - const vector& in); - - private: - PadMode mode_; - T value_; - - // Input: X - // Output: Y -}; - -template -class PadImageGradientOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - PadImageGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws), - mode_(StringToPadMode( - OperatorBase::GetSingleArgument("mode", "constant"))) { - CAFFE_ENFORCE( - legacy_pad_ == LegacyPadding::NOTSET, - "Padding layer only supports explicit pad values."); - CAFFE_ENFORCE( - dilation_h() == 1 && dilation_w() == 1, - "Pooling op does not support dilation right now."); - // Pad op does not use kernel sizes, so we set it to 1 for computing the - // output size. - kernel_.assign(pads_.size() / 2, 1); - } - ~PadImageGradientOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - private: - PadMode mode_; - // Input: dY - // Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PAD_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/partition_ops.h b/app/src/main/cpp/caffe2/operators/partition_ops.h deleted file mode 100644 index 563a026..0000000 --- a/app/src/main/cpp/caffe2/operators/partition_ops.h +++ /dev/null @@ -1,297 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PARTITION_OPS_H_ -#define CAFFE2_OPERATORS_PARTITION_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -static inline int moduloPartition(Index key, int numPartitions) { - int shard = key % numPartitions; - // equivalent to `if (shard < 0) shard += partitions;` - shard += numPartitions & (shard >> (sizeof(int) * 8 - 1)); - return shard; -} - -class GatherByKeyOp : public Operator { - public: - USE_DISPATCH_HELPER; - USE_OPERATOR_FUNCTIONS(CPUContext); - GatherByKeyOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - private: - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - private: - template - bool DoRunWithType() { - const auto numPartitions = InputSize() - 1; - CAFFE_ENFORCE_GE(numPartitions, 1); - const auto& keysTensor = Input(0); - const auto* keysData = keysTensor.template data(); - const auto& keysShape = Input(0).dims(); - CAFFE_ENFORCE_EQ( - keysShape.size(), 1, "Only 1D keys tensor supported currently."); - - // 1. Shape and type consistency checks - const auto& in0Shape = Input(1).dims(); - CAFFE_ENFORCE_GE(in0Shape.size(), 1); - - vector outShape(keysShape); - outShape.insert(outShape.end(), in0Shape.begin() + 1, in0Shape.end()); - - CAFFE_ENFORCE_GE(outShape.size(), 1); - auto totalSize = in0Shape[0]; - auto meta = Input(1).meta(); - for (int i = 2; i < InputSize(); ++i) { - const auto& input = Input(i); - CAFFE_ENFORCE(meta == input.meta()); - CAFFE_ENFORCE_GE(input.ndim(), 1); - CAFFE_ENFORCE(std::equal( - outShape.begin() + keysShape.size(), - outShape.end(), - input.dims().begin() + 1)); - totalSize += input.dim(0); - } - CAFFE_ENFORCE_EQ(keysTensor.size(), totalSize); - - auto* outTensor = Output(0); - outTensor->Resize(outShape); - auto* outData = static_cast(outTensor->raw_mutable_data(meta)); - const auto blockSize = outTensor->size_from_dim(1); - - inputDatas_.resize(numPartitions); - for (int i = 0; i < numPartitions; ++i) { - inputDatas_[i] = static_cast(Input(i + 1).raw_data()); - } - inStartOffsets_.assign(numPartitions, 0); - Index outStartOffset = 0; - int currentShard = -1; - - // 2. copy from inputs into output based on shard for each input key - const auto numEntries = keysTensor.size(); - for (int64_t i = 0; i <= numEntries; ++i) { - auto newShard = - i < numEntries ? moduloPartition(keysData[i], numPartitions) : -1; - if (newShard != currentShard) { - if (currentShard != -1) { - auto inStartOffset = inStartOffsets_[currentShard]; - auto numItems = i - outStartOffset; - context_.template CopyItems( - meta, - numItems * blockSize, - inputDatas_[currentShard] + - inStartOffset * blockSize * meta.itemsize(), - outData + outStartOffset * blockSize * meta.itemsize()); - inStartOffsets_[currentShard] += numItems; - } - currentShard = newShard; - outStartOffset = i; - } - } - - return true; - } - - std::vector inputDatas_; - std::vector inStartOffsets_; -}; - -class PartitionOpBase : public Operator { - public: - USE_OPERATOR_FUNCTIONS(CPUContext); - - PartitionOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(int, "pack_first_input", pack_first_input_, 0) {} - - protected: - template - void ApplyPartition(bool skipFirstArgument) { - CAFFE_ENFORCE_EQ( - OutputSize() % InputSize(), - 0, - "Output number must be a multiple of input number"); - int partitions = OutputSize() / InputSize(); - int inputSize = InputSize(); - int mainInputIndex = skipFirstArgument; - CAFFE_ENFORCE_GT(partitions, 0, "Invalid number of partitions"); - - auto& main_input = Input(mainInputIndex); - TIndex size = main_input.size(); - const Index* data = main_input.template data(); - counts_.assign(partitions, 0); - for (TIndex p = 0; p < size; p++) { - int shard = moduloPartition(data[p], partitions); - ++counts_[shard]; - } - - raw_datas_.resize(inputSize); - block_sizes_.resize(inputSize); - metas_.resize(inputSize); - out_datas_.resize(OutputSize()); - for (int i = mainInputIndex; i < inputSize; ++i) { - auto& input = Input(i); - if (i > mainInputIndex) { - CAFFE_ENFORCE_GE( - input.ndim(), - main_input.ndim(), - "Prefix of extra input's shape must match main input's shape, ", - "input: ", - i); - for (int j = 0; j < main_input.ndim(); ++j) { - CAFFE_ENFORCE_GE( - input.dim(j), - main_input.dim(j), - "Prefix of extra input's shape must match main input's shape, ", - "input: ", - i, - ", dim ", - j); - } - } - raw_datas_[i] = input.raw_data(); - block_sizes_[i] = input.size_from_dim(main_input.ndim()); - metas_[i] = input.meta(); - // shape = partition_size + suffix of input dims - vector shape( - input.dims().begin() + main_input.ndim() - 1, input.dims().end()); - for (int j = 0; j < partitions; ++j) { - int out_idx = i + j * inputSize; - auto output = Output(out_idx); - shape[0] = counts_[j]; - output->Resize(shape); - out_datas_[out_idx] = output->raw_mutable_data(input.meta()); - } - } - - counts_.assign(partitions, 0); - for (TIndex p = 0; p < size; p++) { - int shard = moduloPartition(data[p], partitions); - TIndex idx = counts_[shard]++; - - // special case first input - static_cast(out_datas_[shard * inputSize + mainInputIndex])[idx] = - pack_first_input_ ? ((data[p] - shard) / partitions) : data[p]; - - int baseIndex = shard * inputSize; - for (int i = mainInputIndex + 1; i < inputSize; ++i) { - auto bs = block_sizes_[i]; - auto meta = metas_[i]; - // special case for small bs? - context_.template CopyItems( - meta, - bs, - static_cast(raw_datas_[i]) + p * bs * meta.itemsize(), - static_cast(out_datas_[baseIndex + i]) + - idx * bs * meta.itemsize()); - } - } - } - - bool pack_first_input_; - - // use member fields to reuse memory - vector counts_; - vector block_sizes_; - vector metas_; - vector raw_datas_; - vector out_datas_; -}; - -class PartitionOp : public PartitionOpBase { - public: - USE_DISPATCH_HELPER; - - PartitionOp(const OperatorDef& operator_def, Workspace* ws) - : PartitionOpBase(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - private: - template - bool DoRunWithType() { - ApplyPartition(false /* skipFirstArgument */); - return true; - } - - DISABLE_COPY_AND_ASSIGN(PartitionOp); -}; - -class LengthsPartitionOp : public PartitionOpBase { - public: - USE_DISPATCH_HELPER; - - LengthsPartitionOp(const OperatorDef& operator_def, Workspace* ws) - : PartitionOpBase(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(1)); - } - - private: - template - bool DoRunWithType() { - CAFFE_ENFORCE( - OutputSize() % InputSize() == 0, - "Output number must be a multiple of input number"); - int partitions = OutputSize() / InputSize(); - CAFFE_ENFORCE_GT(partitions, 0, "Invalid number of partitions"); - CAFFE_ENFORCE_EQ( - Input(1).ndim(), - 1, - "Only 1-D tensors supported as a partitioning tensor for sharding"); - - // Apply sharding to all parameters except lengths - ApplyPartition(true /* skipFirstArgument */); - - // Compute lengths after sharding - auto& main_input = Input(1); - TIndex size = main_input.size(); - const Index* data = main_input.template data(); - - auto& length_input = Input(0); - TIndex elements = length_input.size(); - const int32_t* lengths_data = length_input.template data(); - out_length_.resize(partitions); - for (int i = 0; i < partitions; ++i) { - auto& output = *Output(i * InputSize()); - output.Resize(elements); - out_length_[i] = output.template mutable_data(); - } - - int total_length = 0; - for (int i = 0; i < elements; ++i) { - total_length += lengths_data[i]; - } - CAFFE_ENFORCE( - total_length == size, - "Total length is not matching to the number of elements"); - - int index = 0; - for (int i = 0; i < elements; ++i) { - for (int j = 0; j < partitions; ++j) { - out_length_[j][i] = 0; - } - for (int j = 0; j < lengths_data[i]; ++j, ++index) { - int shard = moduloPartition(data[index], partitions); - ++out_length_[shard][i]; - } - } - return true; - } - - DISABLE_COPY_AND_ASSIGN(LengthsPartitionOp); - - vector out_length_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PARTITION_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/perplexity_op.h b/app/src/main/cpp/caffe2/operators/perplexity_op.h deleted file mode 100644 index 4fda547..0000000 --- a/app/src/main/cpp/caffe2/operators/perplexity_op.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PERPLEXITY_OP_H_ -#define CAFFE2_OPERATORS_PERPLEXITY_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class PerplexityOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(PerplexityOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PERPLEXITY_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/piecewise_linear_transform_op.h b/app/src/main/cpp/caffe2/operators/piecewise_linear_transform_op.h deleted file mode 100644 index 701acb8..0000000 --- a/app/src/main/cpp/caffe2/operators/piecewise_linear_transform_op.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PIECEWISE_LINEAR_TRANSFORM_OP_H_ -#define CAFFE2_OPERATORS_PIECEWISE_LINEAR_TRANSFORM_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class PiecewiseLinearTransformOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - PiecewiseLinearTransformOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - binary_ = OperatorBase::GetSingleArgument("binary", false); - - // Retrieve transform params (i.e., the linear functions). - bounds_from_arg_ = OperatorBase::GetRepeatedArgument("bounds"); - slopes_from_arg_ = OperatorBase::GetRepeatedArgument("slopes"); - intercepts_from_arg_ = OperatorBase::GetRepeatedArgument("intercepts"); - transform_param_from_arg_ = CheckTransParamFromArg(); - } - - bool RunOnDevice() override { - return binary_ ? TransformBinary() : TransformGeneral(); - } - - private: - // num_func_per_group is the number of pieces of linear functions of - // each group. - // num_group: The number of groups of linear functions. Each group is for - // transforming one column of predictions. - void InferNumFunctionsPerGroup( - const TIndex num_bounds, - const TIndex num_slopes, - const TIndex num_intercepts, - TIndex* num_func_per_group, - TIndex* num_group) { - CAFFE_ENFORCE_EQ(num_slopes, num_intercepts); - - // This is based on the facts: - // 1. in each group, the num of bounds minus the num of slopes is 1; - // 2. each group has the same number of pieces. - *num_group = num_bounds - num_slopes; - CAFFE_ENFORCE_GT(*num_group, 0); - if (binary_) { - CAFFE_ENFORCE_EQ(*num_group, 1); - } - *num_func_per_group = num_slopes / *num_group; - CAFFE_ENFORCE_GT(*num_func_per_group, 0); - CAFFE_ENFORCE_EQ(num_slopes % *num_group, 0); - } - - bool CheckBoundsSorted( - const T* bounds, - const TIndex num_bounds_per_group, - const TIndex num_group) { - const T* start = bounds; - for (TIndex i = 0; i < num_group; i++) { - if (!std::is_sorted(start, start + num_bounds_per_group)) { - return false; - } - start += num_bounds_per_group; - } - return true; - } - - // Returns true if the transform params from arg are valid. - // Otherwise, we will assume the transform params will pass from Input blobs. - bool CheckTransParamFromArg() { - int good_param = 0; - good_param += bounds_from_arg_.size() > 0; - good_param += slopes_from_arg_.size() > 0; - good_param += intercepts_from_arg_.size() > 0; - CAFFE_ENFORCE( - good_param == 0 || good_param == 3, - "bounds, slopes, intercepts must be all set or all not set"); - if (good_param == 3) { - TIndex num_func_per_group; - TIndex num_group; - InferNumFunctionsPerGroup( - bounds_from_arg_.size(), - slopes_from_arg_.size(), - intercepts_from_arg_.size(), - &num_func_per_group, - &num_group); - CAFFE_ENFORCE( - CheckBoundsSorted( - bounds_from_arg_.data(), num_func_per_group + 1, num_group), - "bounds must be sorted for each group"); - } - - return good_param == 3; - } - - void setUpTensors(TIndex& num_func_per_group, TIndex& num_group, TIndex M); - - void GetTransParamData( - const T** bounds, - const T** slopes, - const T** intercepts, - TIndex* num_func_per_group, - TIndex* num_group) { - TIndex num_bounds; - TIndex num_slopes; - TIndex num_intercepts; - - if (transform_param_from_arg_) { - CAFFE_ENFORCE_EQ(InputSize(), 1); - *bounds = bounds_from_arg_.data(); - *slopes = slopes_from_arg_.data(); - *intercepts = intercepts_from_arg_.data(); - num_bounds = bounds_from_arg_.size(); - num_slopes = slopes_from_arg_.size(); - num_intercepts = intercepts_from_arg_.size(); - } else { - CAFFE_ENFORCE_EQ(InputSize(), 4); - auto& bounds_input = Input(BOUNDS); - auto& slopes_input = Input(SLOPES); - auto& intercepts_input = Input(INTERCEPTS); - *bounds = bounds_input.template data(); - *slopes = slopes_input.template data(); - *intercepts = intercepts_input.template data(); - num_bounds = bounds_input.size(); - num_slopes = slopes_input.size(); - num_intercepts = intercepts_input.size(); - } - InferNumFunctionsPerGroup( - num_bounds, num_slopes, num_intercepts, num_func_per_group, num_group); - } - - bool TransformGeneral() { - auto& X = Input(0); - auto* Y = Output(0); - CAFFE_ENFORCE_EQ(X.ndim(), 2); - TIndex N = X.dim32(0); - TIndex M = X.dim32(1); - Y->ResizeLike(X); - const auto* Xdata = X.template data(); - T* Ydata = Y->template mutable_data(); - - const T* bounds; - const T* slopes; - const T* intercepts; - TIndex num_func_per_group; - TIndex num_group; - GetTransParamData( - &bounds, &slopes, &intercepts, &num_func_per_group, &num_group); - CAFFE_ENFORCE_EQ(num_group, M); - - for (TIndex j = 0; j < M; ++j) { - const T* bounds_group = bounds + j * (num_func_per_group + 1); - const T* slopes_group = slopes + j * num_func_per_group; - const T* intercepts_group = intercepts + j * num_func_per_group; - for (TIndex i = 0; i < N; ++i) { - Ydata[i * M + j] = PiecewiseLinearTransform( - Xdata[i * M + j], - bounds_group, - slopes_group, - intercepts_group, - num_func_per_group); - } - } - return true; - } - - bool TransformBinary() { - auto& X = Input(PREDICTIONS); - auto* Y = Output(0); - CAFFE_ENFORCE(X.ndim() == 1 || X.ndim() == 2); - TIndex N = X.dim32(0); - TIndex M = X.ndim() == 2 ? X.dim32(1) : 1; - CAFFE_ENFORCE( - M == 1 || M == 2, - "If binary is set to true, the input must be Nx2 or Nx1 tensor"); - Y->ResizeLike(X); - const auto* Xdata = X.template data(); - T* Ydata = Y->template mutable_data(); - - const T* bounds; - const T* slopes; - const T* intercepts; - TIndex num_func_per_group; - TIndex num_group; - GetTransParamData( - &bounds, &slopes, &intercepts, &num_func_per_group, &num_group); - CAFFE_ENFORCE_EQ(num_group, 1); - - if (M == 1) { - for (TIndex i = 0; i < N; ++i) { - Ydata[i] = PiecewiseLinearTransform( - Xdata[i], bounds, slopes, intercepts, num_func_per_group); - } - } else { - for (TIndex i = 0; i < N; ++i) { - Ydata[i * M + 1] = PiecewiseLinearTransform( - Xdata[i * M + 1], bounds, slopes, intercepts, num_func_per_group); - Ydata[i * M] = 1.0f - Ydata[i * M + 1]; - } - } - - return true; - } - - T PiecewiseLinearTransform( - const T x, - const T* bounds, - const T* slopes, - const T* intercepts, - const TIndex num_func_per_group) { - T y = 0; - // deal with samples out of bounds - // make it the same as the upper/lower bound value - if (x <= bounds[0]) { - y = slopes[0] * bounds[0] + intercepts[0]; - } else if (x >= bounds[num_func_per_group]) { - y = slopes[num_func_per_group - 1] * bounds[num_func_per_group] + - intercepts[num_func_per_group - 1]; - } else { - auto low_bound = - std::lower_bound(bounds, bounds + num_func_per_group + 1, x); - int bounds_idx = low_bound - bounds - 1; - // compute the piecewise linear transformation as Y - y = slopes[bounds_idx] * x + intercepts[bounds_idx]; - } - return y; - } - - private: - bool binary_; - vector bounds_from_arg_; - vector slopes_from_arg_; - vector intercepts_from_arg_; - - Tensor bounds_device_; - Tensor intercepts_device_; - Tensor slopes_device_; - bool gpu_copied_ = false; - - // If true, the piecewise linear functions are passed through args, - // otherwise, they are passed through Input blobs. - bool transform_param_from_arg_; - - INPUT_TAGS(PREDICTIONS, BOUNDS, SLOPES, INTERCEPTS); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PIECEWISE_LINEAR_TRANSFORM_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/pool_op.h b/app/src/main/cpp/caffe2/operators/pool_op.h deleted file mode 100644 index fa77492..0000000 --- a/app/src/main/cpp/caffe2/operators/pool_op.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef CAFFE2_OPERATORS_POOL_OP_H_ -#define CAFFE2_OPERATORS_POOL_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/conv_pool_op_base.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class PoolOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - PoolOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) { - for (int i = 0; i < kernel_.size(); ++i) { - CAFFE_ENFORCE( - dilation_[i] == 1, "Pooling op does not support dilation right now."); - } - if (!global_pooling_) { - for (int i = 0; i < kernel_.size(); ++i) { - CAFFE_ENFORCE( - pads_[i] < kernel_[i] && pads_[i + kernel_.size()] < kernel_[i], - "Pad should be smaller than kernel."); - } - } - } - ~PoolOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - // Input: X - // Output: Y -}; - -template -class PoolGradientOp final : public ConvPoolOpBase { - public: - USE_CONV_POOL_BASE_FUNCTIONS(Context); - PoolGradientOp(const OperatorDef& operator_def, Workspace* ws) - : ConvPoolOpBase(operator_def, ws) {} - ~PoolGradientOp() {} - - bool RunOnDeviceWithOrderNCHW() override; - bool RunOnDeviceWithOrderNHWC() override; - - // Input: X, Y, dY - // Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_POOL_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/prefetch_op.h b/app/src/main/cpp/caffe2/operators/prefetch_op.h deleted file mode 100644 index 01b5451..0000000 --- a/app/src/main/cpp/caffe2/operators/prefetch_op.h +++ /dev/null @@ -1,132 +0,0 @@ -#ifndef CAFFE2_OPERATORS_PREFETCH_OP_H_ -#define CAFFE2_OPERATORS_PREFETCH_OP_H_ - -#include -#include -#include // NOLINT - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// PrefetchOperator is an operator that prefetches the next batch. It should -// almost always be used to read things from disk, so I am setting the input to -// zero blobs. -// -// For any operator that is derived from PrefetchOperator, it should -// explicitly call the Finalize() function in its destructor, so that the -// prefetching thread is properly destructed. - -// Note: We inherit from OperatorBase since we control the -// synchronization properties of this operator ourselves (we inform -// the waiting producer after we synchronize). This is a special-case -// - you should generally inherit from Operator directly. -template -class PrefetchOperator : public OperatorBase { - public: - PrefetchOperator(const OperatorDef& operator_def, Workspace* ws) - : OperatorBase(operator_def, ws), - context_(operator_def.device_option()), - prefetched_(false), - prefetch_success_(true), - finalize_(false) { - context_.SwitchToDevice(0); - } - - virtual ~PrefetchOperator() noexcept { - CHECK(finalize_ || !prefetch_thread_.get()) << - "YOU MADE A PROGRAMING ERROR: derived class of PrefetchOperator " - "should call Finalize() in its destructor so the prefetching " - "thread is joined. "; - } - - void Finalize() { - if (prefetch_thread_.get()) { - { - std::unique_lock lock(prefetch_access_mutex_); - while (!prefetched_) - consumer_.wait(lock); - finalize_ = true; - prefetched_ = false; - } - producer_.notify_one(); - prefetch_thread_->join(); - prefetch_thread_.reset(); - } else { - // If we never initialized the prefetch thread, just set - // finalize anyway. - finalize_ = true; - } - } - - bool Run(int /* unused */ /*stream_id*/) override { - // Note(jiayq): We only start the prefetch_thread at the Run() function - // instead of in the constructor, because the prefetch_thread needs to start - // after all derived classes' constructors finish. - if (!prefetch_thread_) { - prefetch_thread_.reset( - new std::thread([this] { this->PrefetchWorker(); })); - } - context_.SwitchToDevice(0); - std::unique_lock lock(prefetch_access_mutex_); - while (!prefetched_) - consumer_.wait(lock); - if (!prefetch_success_) { - LOG(ERROR) << "Prefetching failed."; - return false; - } - if (!CopyPrefetched()) { - LOG(ERROR) << "Error when copying prefetched data."; - return false; - } - prefetched_ = false; - context_.FinishDeviceComputation(); - producer_.notify_one(); - return true; - } - - void PrefetchWorker() { - context_.SwitchToDevice(); - std::unique_lock lock(prefetch_access_mutex_); - while (prefetched_) - producer_.wait(lock); - while (!finalize_) { - // We will need to run a FinishDeviceComputation() call because the - // prefetcher thread and the main thread are potentially using different - // streams (like on GPU). - try { - prefetch_success_ = Prefetch(); - context_.FinishDeviceComputation(); - } catch (const std::exception& e) { - // TODO: propagate exception_ptr to the caller side - LOG(ERROR) << "Prefetching error " << e.what(); - prefetch_success_ = false; - } - prefetched_ = true; - consumer_.notify_one(); - while (prefetched_) - producer_.wait(lock); - } - } - - // You will need to implement this instead of the Run function. - virtual bool Prefetch() = 0; - virtual bool CopyPrefetched() = 0; - - protected: - Context context_; - std::mutex prefetch_access_mutex_; - std::condition_variable producer_, consumer_; - // prefetched_ is used to tell the operator that it is done. - std::atomic prefetched_; - // prefetch_success_ is used to see if prefetching failed or not. - std::atomic prefetch_success_; - // finalize_ is used to tell the prefetcher to quit. - std::atomic finalize_; - unique_ptr prefetch_thread_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PREFETCH_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/prelu_op.h b/app/src/main/cpp/caffe2/operators/prelu_op.h deleted file mode 100644 index 54e1afa..0000000 --- a/app/src/main/cpp/caffe2/operators/prelu_op.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class PReluOp final : public Operator { - public: - PReluOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - StorageOrder order_; -}; - -template -class PReluGradientOp final : public Operator { - public: - PReluGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - StorageOrder order_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/prepend_dim_op.h b/app/src/main/cpp/caffe2/operators/prepend_dim_op.h deleted file mode 100644 index 6eb864e..0000000 --- a/app/src/main/cpp/caffe2/operators/prepend_dim_op.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_PREPEND_DIM_OP_H_ -#define CAFFE2_OPERATORS_PREPEND_DIM_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class PrependDimOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - PrependDimOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - dim_size_(OperatorBase::GetSingleArgument("dim_size", 0)) { - CAFFE_ENFORCE_GT( - dim_size_, 0, "Argument dim_size must be greater than zero."); - } - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - - CAFFE_ENFORCE(input.ndim() > 0, "Input must be at least 1D."); - CAFFE_ENFORCE( - input.dim(0) % dim_size_ == 0, - "First dimension must be multiple of prepend_dim."); - - vector actual_new_shape(input.ndim() + 1); - actual_new_shape[0] = dim_size_; - actual_new_shape[1] = input.dim(0) / dim_size_; - for (int i = 1; i < input.dims().size(); ++i) { - actual_new_shape[i + 1] = input.dim(i); - } - output->Resize(actual_new_shape); - - if (output != &input) { - // If we are not doing in-place computation, a copy is needed. - context_.template CopyBytes( - input.nbytes(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - } - return true; - } - - private: - int64_t dim_size_; -}; - -template -class MergeDimOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MergeDimOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - - CAFFE_ENFORCE(input.ndim() > 1, "Input must be at least 2D."); - - vector actual_new_shape(input.ndim() - 1); - actual_new_shape[0] = input.dim(0) * input.dim(1); - for (int i = 1; i < input.dims().size() - 1; ++i) { - actual_new_shape[i] = input.dim(i + 1); - } - output->Resize(actual_new_shape); - - if (output != &input) { - // If we are not doing in-place computation, a copy is needed. - context_.template CopyBytes( - input.nbytes(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - } - return true; - } - - private: - int64_t dim_size_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_PREPEND_DIM_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/rank_loss_op.h b/app/src/main/cpp/caffe2/operators/rank_loss_op.h deleted file mode 100644 index 420428a..0000000 --- a/app/src/main/cpp/caffe2/operators/rank_loss_op.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// support multiple batches of sessions -template -class PairWiseLossOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(PairWiseLossOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - private: - INPUT_TAGS(XVALUE, LABEL, LENGTHS); - OUTPUT_TAGS(YVALUE); -}; - -template -class PairWiseLossGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(PairWiseLossGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - private: - INPUT_TAGS(XVALUE, LABEL, DYVALUE, LENGTHS); - OUTPUT_TAGS(DXVALUE); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/recurrent_network_blob_fetcher_op.h b/app/src/main/cpp/caffe2/operators/recurrent_network_blob_fetcher_op.h deleted file mode 100644 index d627a94..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_network_blob_fetcher_op.h +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RECURRENT_BLOB_FETCHER_OP_H_ -#define CAFFE2_OPERATORS_RECURRENT_BLOB_FETCHER_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/operators/recurrent_network_op.h" -#include "google/protobuf/text_format.h" - -#include - -namespace caffe2 { - -template -class RecurrentNetworkBlobFetcherOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - RecurrentNetworkBlobFetcherOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - prefix_ = OperatorBase::GetSingleArgument("prefix", "rnn"); - ws_ = ws; - } - - bool RunOnDevice() override { - const detail::ScratchWorkspaces& scratch = - OperatorBase::Input(0); - const std::vector>& stepWorkspaces = - scratch.stepWorkspaces; - - std::vector blob_names_vector = {}; - - for (TIndex i = 0; i < stepWorkspaces.size(); i++) { - Workspace* currentStepWorkspace = stepWorkspaces[i].get(); - std::vector blob_names = currentStepWorkspace->LocalBlobs(); - - for (auto& blob_name : blob_names) { - const Blob* currentBlob = currentStepWorkspace->GetBlob(blob_name); - const auto& currentTensor = currentBlob->Get>(); - - std::string newBlobName = - prefix_ + std::string("_") + blob_name + caffe2::to_string(i); - blob_names_vector.push_back(newBlobName); - - ws_->CreateBlob(newBlobName) - ->template GetMutable() - ->ResizeLike(currentTensor); - - auto* newTensor = - ws_->GetBlob(newBlobName)->template GetMutable>(); - newTensor->template CopyFrom(currentTensor); - } - } - - auto* output = Output(0); - output->Resize(blob_names_vector.size()); - std::copy( - blob_names_vector.begin(), - blob_names_vector.end(), - output->template mutable_data()); - - return true; - } - - private: - std::string prefix_; - Workspace* ws_; -}; -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECURRENT_BLOB_FETCHER_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/recurrent_network_executor.h b/app/src/main/cpp/caffe2/operators/recurrent_network_executor.h deleted file mode 100644 index d5d543f..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_network_executor.h +++ /dev/null @@ -1,424 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_H_ -#define CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_H_ - -#include -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/timer.h" -#include "caffe2/operators/recurrent_network_executor_incl.h" - -namespace caffe2 { - -class RecurrentNetworkExecutorBase { - protected: - explicit RecurrentNetworkExecutorBase( - const NetDef& step_net_def, - std::map& recurrent_input_map, - std::string timestep_blob) - : step_net_def_(step_net_def), - recurrent_input_map_(recurrent_input_map), - timestep_blob_(timestep_blob) { - for (int i = 0; i < step_net_def_.op_size(); i++) { - op_deps_.push_back(op_deps(i)); - } - } - - public: - virtual ~RecurrentNetworkExecutorBase() {} - - virtual bool Run(int T) = 0; - - virtual bool RunBackwards(int T) = 0; - - /** - * Callers must call this before running an execution that contains - * timestep t. On first call, this will initialize the data structures - * for the given timestep. For subsequent calls, this has no cost. - */ - void EnsureTimestepInitialized(int t, Workspace* ws) { - if (timestep_ops_template_.size() == 0) { - CalculateInternalDependencies(); - } - if (timestep_ops_.size() <= t || - (timestep_ops_.size() > t && timestep_ops_[t].size() == 0)) { - for (int j = timestep_ops_.size(); j < t + 1; j++) { - timestep_ops_.push_back(std::vector()); - } - - // Create a specific timestep blob for this timestep. This is to - // avoid conflicting timestep blobs when reusing workspaces, as with - // the forward-only mode. - std::string this_timestep_blob = - timestep_blob_ + "_rnnexec_t" + caffe2::to_string(t); - ws->CreateBlob(this_timestep_blob)->template GetMutable()->Resize(1); - auto b = ws->GetBlob(this_timestep_blob); - CAFFE_ENFORCE(b); - b->template GetMutable() - ->template mutable_data()[0] = t; - - // Copy the operators from template - for (auto& template_rnn_op : timestep_ops_template_) { - auto& rnn_op = template_rnn_op; - OperatorDef op_copy = step_net_def_.op(rnn_op.order); - - // Rename timestep references to use the timestep specific timestep blob - for (int i = 0; i < op_copy.input_size(); i++) { - if (op_copy.input(i) == timestep_blob_) { - op_copy.set_input(i, this_timestep_blob); - } - } - CAFFE_ENFORCE(!HasOutput(op_copy, timestep_blob_), - "Timestep cannot be output of an op: ", timestep_blob_, - " op=" + ProtoDebugString(op_copy)); - - rnn_op.op = CreateOperator(op_copy, ws); - timestep_ops_[t].emplace_back(rnn_op); - } - } - } - - void SetMaxParallelTimesteps(int p) { - max_parallel_timesteps_ = p; - } - - private: - // Utility method to check if any of the op inputs or control inputs - // contain given blob 'input' - bool has_input(std::string x, int opidx) { - for (auto& inp : step_net_def_.op(opidx).input()) { - if (inp == x) { - return true; - } - } - for (auto& inp : step_net_def_.op(opidx).control_input()) { - if (inp == x) { - return true; - } - } - return false; - } - - // Return all outbound dependencies of an op. Special case for - // rnn dependencies, that are set in recurent_network_op. - std::vector op_deps(int i) { - std::vector outs; - auto& opdef = step_net_def_.op(i); - for (string o : opdef.output()) { - outs.push_back(o); - }; - for (auto& arg : opdef.arg()) { - if (arg.name().find("rnn_dependency") == 0) { - outs.push_back(arg.s()); - } - } - return outs; - } - - /** - * Calculate dependencies of this op, for the ops following it in this - * timestep and also for the next timestep. Removes redundant dependencies. - */ - void infer_dependencies( - int start_i, - std::set outputs, - std::vector& rnn_ops, - std::set* dep_ops) { - std::set frontier = outputs; - std::set already_accounted_deps; - int num_ops = step_net_def_.op_size(); - for (int j = 0; j < num_ops - 1 && !outputs.empty(); j++) { - int i = (start_i + j) % num_ops; - if (rnn_ops[i].link_op && this->ignoreLinkDependencies()) { - continue; - } - for (auto& outp : frontier) { - if (has_input(outp, i)) { - if (outputs.find(outp) != outputs.end()) { - if (already_accounted_deps.find(i) == - already_accounted_deps.end()) { - dep_ops->insert(i); - } - - // Now we can take the deps of this ops and not - // add them anymore - for (int odep : rnn_ops[i].dependencies) { - already_accounted_deps.insert(odep); - } - } - for (string& dep_out : op_deps_[i]) { - auto oit = outputs.find(dep_out); - if (oit != outputs.end()) { - // This op produces output of the orignal op, so the dependency - // passed through that op - outputs.erase(oit); - } - frontier.insert(dep_out); - } - } - } - } - } - - /** - * Add dependencies to ops in the next timestep that would write an op - * that this op has as an input or output. This is special for RNNs, - * since we can have ops running in different timesteps concurrently. - * Also, we need to check ops that output a blob that is input of - * of the op in question. - */ - void add_race_conflict_dependencies( - int opidx, - std::vector& rnn_ops, - std::set* dep_ops) { - - for (int i = 0; i < rnn_ops.size(); i++) { - if (i == opidx) { - continue; - } - if (rnn_ops[i].link_op && this->ignoreLinkDependencies()) { - continue; - } - for (auto& dep_blob : op_deps_[i]) { - for (auto& inp : step_net_def_.op(opidx).input()) { - if (inp == dep_blob) { - dep_ops->insert(i); - break; - } - } - if (i < opidx) { - for (auto& outp : step_net_def_.op(opidx).output()) { - if (outp == dep_blob) { - dep_ops->insert(i); - break; - } - } - } - } - } - } - - - - void CalculateInternalDependencies() { - /** - * Calculate the dependencies between ops inside timestep and across - * timestep. These are store in timestep_ops_ vector that is copied - * for each timestep. - */ - for (int i = 0; i < step_net_def_.op_size(); i++) { - timestep_ops_template_.push_back(RNNNetOperator(step_net_def_.op(i), i)); - } - - // Then see which outputs appear as inputs, and those are - // the internal blobs. - for (auto& rnn_op : timestep_ops_template_) { - set dep_outputs; - for (auto& outp : op_deps_[rnn_op.order]) { - dep_outputs.insert(outp); - } - - // Add recurrent dependencies as 'outputs' for this op - for (auto& outp : dep_outputs) { - auto rit = recurrent_input_map_.find(outp); - if (rit != recurrent_input_map_.end()) { - dep_outputs.insert(rit->second); - } else { - dep_outputs.insert(outp); - } - } - - // Compute dependencies of this op. - if (!rnn_op.link_op || !this->ignoreLinkDependencies()) { - std::set dependent_ops; - infer_dependencies( - rnn_op.order + 1, - dep_outputs, - timestep_ops_template_, - &dependent_ops); - - // Race conditions arise when operator writes a blob that is - // being read by another. - if (!this->ignoreLinkDependencies()) { - add_race_conflict_dependencies( - rnn_op.order, timestep_ops_template_, &dependent_ops); - } - - for (int i : dependent_ops) { - rnn_op.dependencies.push_back(i); - } - - // Sort in ascending order of dependency distance. If op - // j > i, then distance is j - i. But if j < i, then distance - // from i to j passes the timestep boundary and is j + num ops - i. - std::sort( - rnn_op.dependencies.begin(), - rnn_op.dependencies.end(), - [&](const int& a, const int& b) { - if (a < rnn_op.order && b < rnn_op.order) { - return a < b; - } - if (a >= rnn_op.order && b >= rnn_op.order) { - return a < b; - } - if (a >= rnn_op.order && b < rnn_op.order) { - return true; - } - return false; - }); - } - } - - // Update dependency counts - for (auto& rnn_op : timestep_ops_template_) { - for (int i : rnn_op.dependencies) { - timestep_ops_template_[i].num_dynamic_inputs++; - - if (i > rnn_op.order) { - timestep_ops_template_[i].frontier = false; - } else { - timestep_ops_template_[i].num_recurrent_inputs++; - } - } - } - - // Find ops that have no recurrent inputs, and bind them - // to the last op of the timestep. If there is only one op - // in the step net, then it will depend on itself. Note that - // we do not increase the dynamic input counter. - for (auto& rnn_op : timestep_ops_template_) { - if (rnn_op.num_dynamic_inputs == 0 && rnn_op.num_recurrent_inputs == 0) { - if (rnn_op.link_op && this->ignoreLinkDependencies()) { - continue; - } - timestep_ops_template_.back().dependencies.push_back(rnn_op.order); - } - } - - // compute parents - for (auto& rnn_op : timestep_ops_template_) { - for (int dep : rnn_op.dependencies) { - timestep_ops_template_[dep].parents.push_back(rnn_op.order); - } - } - - AnalyzeOps(); - } - - -protected: - /** - * For debug purposes - */ - void PrintInfo(int t) { - auto& rnn_ops = timestep_ops_[t]; - - LOG(INFO) << "Timestep: " << t; - for (auto& rnn_op : rnn_ops) { - auto& op = rnn_op.op; - LOG(INFO) << "Operator " << rnn_op.order << ": " << op->type() - << " dep inputs:" << rnn_op.num_dynamic_inputs - << " rec inputs:" << rnn_op.num_recurrent_inputs - << " frontier: " << rnn_op.frontier; - for (auto& inp : rnn_op.op->debug_def().input()) { - LOG(INFO) << " ---- input: " << inp; - } - for (auto& outp : rnn_op.op->debug_def().output()) { - LOG(INFO) << " ---- output: " << outp; - } - for (auto j : rnn_op.dependencies) { - LOG(INFO) << " dep: " << j << ": " << rnn_ops[j].op->type(); - } - for (auto j : rnn_op.parents) { - LOG(INFO) << " parent: " << j << ": " << rnn_ops[j].op->type(); - } - } - - LOG(INFO) << "recurrent_inputs:" << recurrent_input_map_; - - for (auto& rnn_op : rnn_ops) { - LOG(INFO) << "Operator " << rnn_op.order; - LOG(INFO) << ProtoDebugString(rnn_op.op->debug_def()); - } - } - - protected: - - virtual void AnalyzeOps() {} - - virtual bool ignoreLinkDependencies() = 0; - - std::vector> timestep_ops_; - std::vector op_ptrs_; - - std::vector timestep_ops_template_; - - NetDef step_net_def_; - std::vector> op_deps_; - std::map recurrent_input_map_; - std::string timestep_blob_; - - int max_parallel_timesteps_ = -1; -}; - -template -std::unique_ptr createRNNExecutor( - const NetDef& step_net_def, - std::map& recurrent_input_map, - std::string timestep_blob, - ArgumentHelper rnn_args); - -class ThreadedRecurrentNetworkExecutor : public RecurrentNetworkExecutorBase { - public: - ThreadedRecurrentNetworkExecutor( - const NetDef& step_net_def, - std::map& recurrent_input_map, - std::string timestep_blob) - : RecurrentNetworkExecutorBase(step_net_def, recurrent_input_map, timestep_blob), - failed_(false) {} - - ~ThreadedRecurrentNetworkExecutor() { - job_queue_.NoMoreJobs(); - VLOG(1) << "Joining workers."; - for (auto& worker : workers_) { - worker.join(); - } - } - - bool Run(int T) override; - - bool RunBackwards(int T) override; - - bool ignoreLinkDependencies() override { - return false; - } - - void setNumThreads(int n) { - num_threads_ = n; - } - - private: - void _ExecRange(int from, int to); - - void _Exec(); - - void WorkerFunction(); - - void RunOp(OpJob job, int thread_id); - - SimpleQueue job_queue_; - std::atomic countdown_; - std::atomic failed_; - std::atomic finished_timesteps_; - int num_ops_; - std::mutex countdown_mtx_; - std::condition_variable cv_; - std::vector workers_; - int num_threads_ = 4; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_H_ diff --git a/app/src/main/cpp/caffe2/operators/recurrent_network_executor_gpu.h b/app/src/main/cpp/caffe2/operators/recurrent_network_executor_gpu.h deleted file mode 100644 index ae7ccbd..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_network_executor_gpu.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_GPU_EXECUTOR_H_ -#define CAFFE2_OPERATORS_RECURRENT_NETWORK_GPU_EXECUTOR_H_ - -#include "caffe2/core/context_gpu.h" -#include "caffe2/operators/recurrent_network_executor.h" - - -#include - -namespace caffe2 { - -class CUDARecurrentNetworkExecutor : public RecurrentNetworkExecutorBase { - public: - CUDARecurrentNetworkExecutor( - const NetDef& step_net_def, - std::map& recurrent_input_map, - std::string timestep_blob) - : RecurrentNetworkExecutorBase(step_net_def, recurrent_input_map, timestep_blob) {} - - ~CUDARecurrentNetworkExecutor(); - - protected: - bool Run(int T) override; - - bool RunBackwards(int T) override; - - bool ignoreLinkDependencies() override { - return true; - } - - void AnalyzeOps() override { - /** - * Check if there is an op that only depends on ops from previous - * timestep, and that ops is not the last op. Then we can start computation - * in subsequent timesteps before the whole previous timestep has finished. - * If there is no parallelism, we can avoid overhead of event-based - * dependency management. - */ - has_timestep_parallelism_ = false; - for (auto& rnn_op : timestep_ops_template_) { - int i = rnn_op.order; - if (rnn_op.parents.size() >= 1 && i < timestep_ops_template_.size() - 1) { - bool only_recurrent_deps = std::all_of( - rnn_op.parents.begin(), - rnn_op.parents.end(), [&](const int &parent) { - return parent > i; - } - ); - if (only_recurrent_deps) { - VLOG(1) << "Timestep parallel op: " << ProtoDebugString(step_net_def_.op(i)); - has_timestep_parallelism_ = true; - - for (int dep : rnn_op.parents) { - if (dep == timestep_ops_template_.size() - 1) { - // This op depends on the last op of the previous iteration, - // so it will block any parallelism - has_timestep_parallelism_ = false; - break; - } - } - break; - } - } - } - LOG(INFO) << "Analyzed ops for timestep parallelism: " << has_timestep_parallelism_; - } - - public: - - void setMaxStreams(int n) { - max_cuda_streams_ = n; - } - - private: - void _ExecRange(int from, int to); - - std::vector events_; - bool has_timestep_parallelism_ = false; - int max_cuda_streams_ = 2; -}; -} -#endif diff --git a/app/src/main/cpp/caffe2/operators/recurrent_network_executor_incl.h b/app/src/main/cpp/caffe2/operators/recurrent_network_executor_incl.h deleted file mode 100644 index 9bcabf6..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_network_executor_incl.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_ -#define CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_INCL_H_ - -#include -#include "caffe2/core/operator.h" - -namespace caffe2 { - -struct RNNNetOperator { - // Operator - int order; - std::shared_ptr op = nullptr; - bool link_op; - - // Bookkeeping - int num_dynamic_inputs = 0; - int num_recurrent_inputs = 0; - - // Dependencies - std::atomic proc_inputs; - std::vector dependencies; - std::vector parents; - bool frontier = true; - - explicit RNNNetOperator(const OperatorDef& def, int order) : order(order) { - proc_inputs = 0; - link_op = def.type() == "rnn_internal_apply_link"; - } - - RNNNetOperator(const RNNNetOperator& x) { - order = x.order; - op = x.op; - link_op = x.link_op; - num_dynamic_inputs = x.num_dynamic_inputs; - num_recurrent_inputs = x.num_recurrent_inputs; - proc_inputs = 0; - dependencies = x.dependencies; - parents = x.parents; - frontier = x.frontier; - } -}; - -struct OpJob { - int timestep; - int op_idx; - int T; - int direction; - int stream_id = -1; // only used by gpu version - OpJob() {} - OpJob(int _timestep, int _op_idx, int _T, int _direction) - : timestep(_timestep), op_idx(_op_idx), T(_T), direction(_direction) { - CHECK(direction == 1 || direction == -1); - CHECK(timestep >= 0 && timestep < _T); - } - - inline bool backward() { - return direction == -1; - } - inline bool forward() { - return direction == 1; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECURRENT_NETWORK_EXECUTOR_H_ diff --git a/app/src/main/cpp/caffe2/operators/recurrent_network_op.h b/app/src/main/cpp/caffe2/operators/recurrent_network_op.h deleted file mode 100644 index 8002d69..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_network_op.h +++ /dev/null @@ -1,921 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RECURRENT_NETWORK_OP_H_ -#define CAFFE2_OPERATORS_RECURRENT_NETWORK_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/operators/recurrent_network_executor.h" -#include "google/protobuf/text_format.h" -#include "caffe2/utils/conversions.h" - -CAFFE2_DECLARE_bool(caffe2_rnn_executor); - -namespace caffe2 { -namespace detail { - -struct Param { - std::string param; - std::string grad; - std::string cellGradient; -}; - -struct RecurrentInput { - std::string state; - std::string input; -}; - -struct RecurrentGradient { - std::string param; - std::string grad; - std::string externalGrad; - std::string lastExternalGrad; - int32_t offset; -}; - -struct OffsetAlias { - std::string src; - std::string dst; - int32_t offset{0}; -}; - -struct Link { - std::string internal; - std::string external; - int32_t offset{0}; - int32_t window{1}; -}; - -struct ScratchWorkspaces { - std::vector> stepWorkspaces; - std::shared_ptr sharedBlobsWs = nullptr; -}; - -inline void UpdateTimestepBlob(Workspace* ws, std::string blob_name, int t) { - ws->CreateBlob(blob_name)->template GetMutable()->Resize(1); - auto timestepBlob = ws->GetBlob(blob_name); - CAFFE_ENFORCE(timestepBlob); - timestepBlob->template GetMutable() - ->template mutable_data()[0] = t; -} - -std::map GetRecurrentMapping( - const std::vector& links, bool backward); - -template -void applyOffsetAlias( - const OffsetAlias& oc, - Workspace* ws, - Context* /*context*/) { - VLOG(1) << "Aliasing: " << oc.src << " to: " << oc.dst - << " at offset: " << oc.offset; - auto srcBlob = ws->GetBlob(oc.src); - CAFFE_ENFORCE(srcBlob); - auto* src = srcBlob->template GetMutable>(); - auto* dst = ws->GetBlob(oc.dst)->template GetMutable>(); - auto timestep = src->size() / src->dim(0); - auto dims = src->dims(); - const int32_t startDstTimestep = - oc.offset >= 0 ? oc.offset : src->dim(0) + oc.offset; - const int32_t numDstTimesteps = src->dim(0) - startDstTimestep; - CAFFE_ENFORCE( - numDstTimesteps >= 1, "Invalid number of timesteps: ", numDstTimesteps); - dims[0] = numDstTimesteps; - dst->Resize(dims); - CAFFE_ENFORCE(timestep == dst->size() / numDstTimesteps, "Invalid offset"); - dst->ShareExternalPointer( - src->template mutable_data() + startDstTimestep * timestep, - dst->size()); -} - -template -void repeatCopy( - size_t repeat_n, - size_t n, - const T* src, - T* dst, - Context* context) { - for (int i = 0; i < repeat_n; ++i) { - context->template Copy(n, src, dst + i * n); - } -} - -/** - * Copy external input to the step net into the first item of - * (T + 1) X batch_size X input_size tensor - */ -template -void initializeRecurrentInput( - const RecurrentInput& rc, - int32_t seqLen, - int32_t batchSize, - Workspace* ws, - Context* context) { - auto stateBlob = ws->GetBlob(rc.state); - CAFFE_ENFORCE(stateBlob); - auto* state = stateBlob->template GetMutable>(); - - auto inputBlob = ws->GetBlob(rc.input); - CAFFE_ENFORCE(inputBlob); - const auto& input = inputBlob->template Get>(); - CAFFE_ENFORCE_GE(input.ndim(), 1, rc.input); - CAFFE_ENFORCE_LE(input.ndim(), 3, rc.input); - - const auto stateSize = input.dim(input.ndim() - 1); - // Sometimes we want to provide more than one initial step. - // For example, if we do a convolution op in step net - // and need a sufficient left padding around the input. - // This could be used together with links where window != 1. - auto initialStateLength = 1; - if (input.ndim() == 3) { - initialStateLength = input.dim(0); - } - // States at [0, ..., (T + initialStateLength - 1)] (inclusive) - state->Resize(seqLen + initialStateLength, batchSize, stateSize); - - if (input.ndim() >= 2) { - CAFFE_ENFORCE_EQ(input.dim(input.ndim() - 2), batchSize, rc.input); - context->template Copy( - batchSize * stateSize * initialStateLength, - input.template data(), - state->template mutable_data()); - } else { - // Usually, the initial state is the same for all inputs in the batch. - // So the op conveniently accepts 1-D input and copies it batchSize times. - repeatCopy( - batchSize, - stateSize, - input.template data(), - state->template mutable_data(), - context); - } -} - -void PrependOps(std::vector ops, NetDef* netdef); - -void AddApplyLinkOps( - const vector& links, - std::string timestep, - const DeviceOption& device_option, - NetDef* netdef); - -void extractLinks( - OperatorBase* op, - const std::string& internalArg, - const std::string& externalArg, - const std::string& offsetArg, - const std::string& windowArg, - std::vector* links); -} // namespace detail - -template -class RecurrentNetworkOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RecurrentNetworkOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - sharedWs_(ws), - enable_rnn_executor_(OperatorBase::template GetSingleArgument( - "enable_rnn_executor", - false)), - timestep_(OperatorBase::template GetSingleArgument( - "timestep", - "timestep")) { - CAFFE_ENFORCE(ws); - const auto stepNet = - OperatorBase::GetSingleArgument("step_net", ""); - CAFFE_ENFORCE( - google::protobuf::TextFormat::ParseFromString(stepNet, &stepNetDef_), - "Invalid netdef"); - - recurrentInputs_ = constructRecurrentInputs(operator_def, sharedWs_); - links_ = constructLinks(); - aliases_ = constructAliases(); - - stepNetDef_.add_external_input(timestep_); - detail::AddApplyLinkOps( - links_, timestep_, operator_def.device_option(), &stepNetDef_); - - if (FLAGS_caffe2_rnn_executor && enable_rnn_executor_) { - VLOG(1) << "Use RecurrentNetworkExecutor"; - auto recurrent_map = detail::GetRecurrentMapping(links_, false /* backward */); - rnnExecutor_ = - createRNNExecutor( - stepNetDef_, - recurrent_map, - timestep_, - ArgumentHelper(operator_def)); - } else { - // Fix for legacy models that pass "rnn" type net - if (stepNetDef_.type() == "rnn") { - stepNetDef_.set_type("async_simple"); - } - CAFFE_ENFORCE(stepNetDef_.type() != "async_dag"); - } - } - - std::vector constructRecurrentInputs( - const OperatorDef& operator_def, - Workspace* sharedWs) { - const auto states = - OperatorBase::GetRepeatedArgument("recurrent_states"); - const auto inputs = - OperatorBase::GetRepeatedArgument("initial_recurrent_state_ids"); - CAFFE_ENFORCE_EQ(states.size(), inputs.size(), "states/inputs mismatch"); - std::vector ris; - for (auto i = 0; i < states.size(); ++i) { - // States need to be "global" (since they are shared between - // forward and backward). - sharedWs->CreateBlob(states[i]); - - detail::RecurrentInput ri; - ri.state = states[i]; - ri.input = operator_def.input(inputs[i]); - ris.push_back(ri); - } - return ris; - } - - std::vector constructAliases() { - const auto& src = - OperatorBase::GetRepeatedArgument("alias_src"); - const auto& dst = - OperatorBase::GetRepeatedArgument("alias_dst"); - const auto& offset = - OperatorBase::GetRepeatedArgument("alias_offset"); - CAFFE_ENFORCE( - src.size() == offset.size(), "alias_src/alias_offset mismatch"); - CAFFE_ENFORCE( - dst.size() == offset.size(), "alias_dst/alias_offset mismatch"); - std::vector aliases; - for (auto i = 0; i < src.size(); ++i) { - detail::OffsetAlias oc; - oc.src = src[i]; - oc.dst = dst[i]; - oc.offset = offset[i]; - aliases.push_back(oc); - } - return aliases; - } - - /** - * Some blobs can be marked as to be recomputed on backward pass. - * For those blobs, we do not want to allocate on each step workspace, - * but we instead store that blob in the shared workspace so all - * steps can use the same buffer on forward pass. - */ - void initializeBlobsToRecomputeOnBackward(Workspace* sharedBlobsWs) { - std::vector v; - const auto& blobs = OperatorBase::GetRepeatedArgument( - "recompute_blobs_on_backward", v); - for (const auto& b : blobs) { - // Note: if the blob already was created, this is a no-op. - sharedBlobsWs->CreateBlob(b); - } - } - - std::vector constructLinks() { - std::vector links; - detail::extractLinks( - this, - "link_internal", - "link_external", - "link_offset", - "link_window", - &links); - return links; - } - - template - bool DoRunWithType() { - const auto seqLen = Input(0).dim32(0); - const auto batchSize = Input(0).dim32(1); - for (const auto& ri : recurrentInputs_) { - detail::initializeRecurrentInput( - ri, seqLen, batchSize, sharedWs_, &context_); - } - - // If we don't have a backward step net, this operator is forward_only - // and we can avoid creating multiple workspaces. - - bool has_backward_pass = - OperatorBase::GetSingleArgument("backward_step_net", "") != ""; - - // With backward pass: we need to create workspace for each timestep - detail::ScratchWorkspaces* scratch = - OperatorBase::Output(OutputSize() - 1); - std::vector>& stepWorkspaces = - scratch->stepWorkspaces; - std::shared_ptr& sharedBlobsWs = scratch->sharedBlobsWs; - if (!sharedBlobsWs) { - sharedBlobsWs = std::make_shared(sharedWs_); - } - - // Caller can decide that some of the forward activations - // are recomputed on backward pass. Then those activations do not - // have to be stored in step workspaces but can be shared. - initializeBlobsToRecomputeOnBackward(sharedBlobsWs.get()); - - if (has_backward_pass && seqLen > stepWorkspaces.size()) { - stepWorkspaces.resize(seqLen); - } - - // In forward-only mode, we cycle over workspaces. This limits the amount - // of parallelism over timesteps that the RNNExecutor provides. So with - // RNN executor we use more workspaces to get better perf. - int num_workspaces_on_fwd_only = rnnExecutor_ ? 4 : 2; - - if (!has_backward_pass && stepWorkspaces.size() < num_workspaces_on_fwd_only) { - // Use alternating stepWorkspaces when forward_only=True. - // Note that the step workspaces can be shared by other ops, thus - // we cannot shrink it to 2 if there are more than 2 step workspaces. - stepWorkspaces.resize(num_workspaces_on_fwd_only); - } - - for (auto t = 0; t < seqLen; ++t) { - auto& currentStepWorkspace = - (has_backward_pass ? stepWorkspaces[t] : - stepWorkspaces[t % num_workspaces_on_fwd_only]); - if (!currentStepWorkspace) { - currentStepWorkspace = std::make_shared(sharedBlobsWs.get()); - } - - if (rnnExecutor_) { - if (!has_backward_pass) { - // Need to limit timestep parallelism because we cycle over workspaces - rnnExecutor_->SetMaxParallelTimesteps(num_workspaces_on_fwd_only); - } - rnnExecutor_->EnsureTimestepInitialized(t, currentStepWorkspace.get()); - } else { - // Use plain Caffe2 nets - detail::UpdateTimestepBlob(currentStepWorkspace.get(), timestep_, t); - auto* stepNet = currentStepWorkspace->GetNet(stepNetDef_.name()); - if (stepNet == nullptr) { - stepNet = currentStepWorkspace->CreateNet(stepNetDef_); - } - CAFFE_ENFORCE(stepNet, "Step Net construction failure"); - // Since we have a SimpleNet, there are no races here. - stepNet->RunAsync(); - } - } - - if (rnnExecutor_) { - rnnExecutor_->Run(seqLen); - } - - for (const auto& alias : aliases_) { - detail::applyOffsetAlias(alias, sharedWs_, &context_); - } - - return true; - } - - bool RunOnDevice() { - return DoRunWithType(); - } - - protected: - NetDef stepNetDef_; - Workspace* sharedWs_; - bool enable_rnn_executor_; - std::unique_ptr rnnExecutor_; - - std::vector links_; - std::vector aliases_; - std::vector recurrentInputs_; - std::string timestep_; -}; - -template -class RecurrentNetworkGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RecurrentNetworkGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - sharedWs_(ws), - enable_rnn_executor_(OperatorBase::template GetSingleArgument( - "enable_rnn_executor", - false)), - timestep_(OperatorBase::template GetSingleArgument( - "timestep", - "timestep")), - gradInputs_(OperatorBase::template GetRepeatedArgument( - "outputs_with_grads")) { - CAFFE_ENFORCE(ws); - const auto stepNet = - OperatorBase::GetSingleArgument("backward_step_net", ""); - - if (stepNetDef_.type() == "rnn") { - stepNetDef_.set_type("simple"); - } - - CAFFE_ENFORCE( - google::protobuf::TextFormat::ParseFromString(stepNet, &stepNetDef_)); - - links_ = constructLinks(); - params_ = constructParams(operator_def); - recurrentGradients_ = constructRecurrentGradients(operator_def); - recurrentInputIds_ = OperatorBase::template GetRepeatedArgument( - "initial_recurrent_state_ids"); - - /* Add operators to the backward step net to handle accumulation of - gradients over timesteps - */ - stepNetDef_.add_external_input(timestep_); - - AddGradientInputAccumulationOps(operator_def); - detail::AddApplyLinkOps( - links_, timestep_, operator_def.device_option(), &stepNetDef_); - AddParamGradientAccumulationOps(operator_def); - - if (FLAGS_caffe2_rnn_executor && enable_rnn_executor_) { - InitializeExecutor(operator_def); - } - } - - // Renaming maps (generated by memonger.py) - std::string remappedName(std::string blob_name) { - return OperatorBase::template GetSingleArgument( - blob_name + ".rename", blob_name); - } - - detail::Link remappedLink(const detail::Link& link) { - detail::Link renamed_link = link; - renamed_link.internal = remappedName(link.internal); - renamed_link.external = remappedName(link.external); - return renamed_link; - } - - void renameOpInputOutput(std::string from_name, std::string to_name) { - for (int j = 0; j < stepNetDef_.op_size(); j++) { - auto* op = stepNetDef_.mutable_op(j); - for (int i = 0; i < op->input_size(); i++) { - if (op->input(i) == from_name) { - op->set_input(i, to_name); - } - } - for (int i = 0; i < op->output_size(); i++) { - if (op->output(i) == from_name) { - op->set_output(i, to_name); - } - } - } - } - - std::vector constructParams(const OperatorDef& operator_def) { - std::vector params; - const auto& param = OperatorBase::GetRepeatedArgument("param"); - const auto& param_grads = - OperatorBase::GetRepeatedArgument("param_grads"); - CAFFE_ENFORCE( - param_grads.empty() || param_grads.size() == param.size(), - param.size(), - " != ", - param_grads.size()); - for (int i = 0; i < param.size(); ++i) { - detail::Param p; - // Forward inputs come after [outputs_with_grads] gradient inputs - p.param = operator_def.input(param[i] + gradInputs_.size()); - // See GetRecurrentNetworkGradient to understand offseting here - p.grad = operator_def.output(i + numSequences_); - - std::string grad_blob = - param_grads.empty() ? p.grad : remappedName(param_grads[i]); - p.cellGradient = grad_blob + "_tmpstep"; - params.push_back(p); - - renameOpInputOutput(grad_blob, p.cellGradient); - } - return params; - } - - std::vector constructRecurrentGradients( - const OperatorDef& operator_def) { - std::vector rgs; - const auto& recurrent = - OperatorBase::GetRepeatedArgument("recurrent_states"); - const auto& alias_src = - OperatorBase::GetRepeatedArgument("alias_src"); - const auto& offset = - OperatorBase::GetRepeatedArgument("alias_offset"); - - for (auto i = 0; i < recurrent.size(); ++i) { - detail::RecurrentGradient rg; - rg.param = recurrent[i]; - rg.grad = remappedName(recurrent[i] + "_grad"); - - for (int j = 0; j < alias_src.size(); ++j) { - if (alias_src[j] != recurrent[i]) { - continue; - } - int idx = -1; - for (int k = 0; k < gradInputs_.size(); ++k) { - if (gradInputs_[k] == j) { - idx = k; - } - } - if (idx == -1) { - continue; - } - - CAFFE_ENFORCE(offset[j] == 1 || offset[j] == -1); - if (offset[j] == 1) { - rg.externalGrad = operator_def.input(idx); - } else if (offset[j] == -1) { - rg.lastExternalGrad = operator_def.input(idx); - } - } - rg.offset = 1; - rgs.push_back(rg); - } - return rgs; - } - - std::vector constructLinks() { - std::vector links; - detail::extractLinks( - this, - "link_internal", - "link_external", - "link_offset", - "link_window", - &links); - detail::extractLinks( - this, - "backward_link_internal", - "backward_link_external", - "backward_link_offset", - "", - &links); - for (int i = 0; i < links.size(); i++) { - links[i] = remappedLink(links[i]); - } - return links; - } - - void InitializeExecutor(const OperatorDef& operator_def) { - VLOG(1) << "Use RecurrentNetworkExecutor for backward"; - auto recurrent_map = detail::GetRecurrentMapping(links_, true /* backward */); - rnnExecutor_ = createRNNExecutor( - stepNetDef_, recurrent_map, timestep_, ArgumentHelper(operator_def)); - } - - void AddGradientInputAccumulationOps(const OperatorDef& operator_def) { - /** - * Add ops to the step net to accumulate input gradients. - */ - std::vector ops; - for (const auto& rg : recurrentGradients_) { - if (rg.externalGrad.empty()) { - continue; - } - VLOG(1) << "Accumulating into: " << rg.grad << " from " << rg.externalGrad - << ", offset: " << rg.offset; - - OperatorDef opdef; - opdef.set_type("rnn_internal_accumulate_gradient_input"); - opdef.add_input(timestep_); - opdef.add_input(rg.externalGrad); - opdef.add_input(rg.grad); - opdef.add_output(rg.grad); - - // Add also the linked blobs to outputs, to ensure correct - // chaining. - for (auto& l : links_) { - if (rg.grad == l.external) { - Argument* dep_arg = opdef.add_arg(); - dep_arg->set_name("rnn_dependency." + l.internal); - dep_arg->set_s(l.internal); - } - } - - opdef.mutable_device_option()->CopyFrom(operator_def.device_option()); - - Argument* offset_arg = opdef.add_arg(); - offset_arg->set_name("offset"); - offset_arg->set_i(rg.offset); - ops.push_back(opdef); - - stepNetDef_.add_external_input(rg.externalGrad); - stepNetDef_.add_external_input(rg.grad); - } - detail::PrependOps(ops, &stepNetDef_); - } - - void AddParamGradientAccumulationOps(const OperatorDef& operator_def) { - // If a user passes in param_grads mapping, we can copy dirrectly - // form a blob where backward cell net written data to. - // This becomes handy in a case where gradient from the cell net - // is an internal blob of the backward cell. This happens, for example, - // when SumOp is the first op of the cell - for (const auto& param : params_) { - OperatorDef opdef; - opdef.set_type("Sum"); - opdef.add_input(param.grad); - opdef.add_input(param.cellGradient); - opdef.add_output(param.grad); - opdef.mutable_device_option()->CopyFrom(operator_def.device_option()); - stepNetDef_.add_op()->CopyFrom(opdef); - stepNetDef_.add_external_input(param.grad); - } - } - - void CreateSharedBlobs( - const std::shared_ptr& step0Ws, - Workspace* sharedBlobsWs) { - /** - * Create all output blobs created by ops of the backward step net, they - * can be shared. - */ - for (auto& op : stepNetDef_.op()) { - for (const string& outp : op.output()) { - if (!step0Ws->HasBlob(outp)) { - sharedBlobsWs->CreateBlob(outp); - } - } - } - } - - template - bool DoRunWithType() { - const auto seqLen = Input(gradInputs_.size()).dim32(0); - VLOG(1) << "seqLen: " << seqLen; - - const detail::ScratchWorkspaces& scratch = - OperatorBase::Input(InputSize() - 1); - const std::vector>& stepWorkspaces = - scratch.stepWorkspaces; - CAFFE_ENFORCE_GE(stepWorkspaces.size(), seqLen); - Workspace& sharedBlobsWs = *scratch.sharedBlobsWs.get(); - - const auto batchSize = Input(0).dim32(1); - for (auto& param : params_) { - auto pBlob = sharedWs_->GetBlob(param.param); - CAFFE_ENFORCE(pBlob); - const auto& p = pBlob->template Get>(); - - auto gBlob = sharedWs_->GetBlob(param.grad); - CAFFE_ENFORCE(gBlob); - auto* g = gBlob->template GetMutable>(); - g->ResizeLike(p); - math::Set( - g->size(), - convert::To(0.0), - g->template mutable_data(), - &context_); - } - - for (auto& rg : recurrentGradients_) { - auto pBlob = sharedWs_->GetBlob(rg.param); - CAFFE_ENFORCE(pBlob); - const auto& p = pBlob->template Get>(); - - auto gBlob = sharedWs_->CreateBlob(rg.grad); - CAFFE_ENFORCE(gBlob); - auto* g = gBlob->template GetMutable>(); - g->ResizeLike(p); - CAFFE_ENFORCE_EQ(g->ndim(), 3); - const auto timestep = g->size() / g->dim(0); - // Fill the last timestep with zeros for the gradient - math::Set( - timestep, - convert::To(0.0), - g->template mutable_data() + (g->dim(0) - 1) * timestep, - &context_); - } - - // This code assumes that there are several inputs - // sequences. Actually it is not supported by the rest of the code, - // and numSequences_ is a constant, equal to 1. - for (int i = 0; i < numSequences_; ++i) { - // Offseting as the first gradInputs_.size() inputs of the op - // are from GO. Then all I(0..N). - const int gradientInputIndex = i + gradInputs_.size(); - const auto& inputName = this->debug_def().input(gradientInputIndex); - auto gradientName = remappedName(inputName + "_grad"); - VLOG(1) << "Initializing gradient for input " << gradientInputIndex - << " (" << inputName << ") " - << " as blob " << gradientName - << ". Size: " << Input(gradientInputIndex).size(); - auto pGradientBlob = sharedWs_->GetBlob(gradientName); - CAFFE_ENFORCE(pGradientBlob); - auto* g = pGradientBlob->template GetMutable>(); - g->ResizeLike(Input(gradientInputIndex)); - g->template mutable_data(); - } - - auto accumulateFinalInputGradients = [&]() { - for (const auto& rg : recurrentGradients_) { - if (rg.lastExternalGrad.empty()) { - continue; - } - VLOG(1) << "Accumulating into: " << rg.grad << " from " - << rg.lastExternalGrad << " for final time step (sep. blob)"; - auto gBlob = sharedWs_->GetBlob(rg.grad); - CAFFE_ENFORCE(gBlob); - auto* g = gBlob->template GetMutable>(); - - auto oglastBlob = sharedWs_->GetBlob(rg.lastExternalGrad); - CAFFE_ENFORCE(oglastBlob); - const auto& oglast = oglastBlob->template Get>(); - CAFFE_ENFORCE_EQ(g->dim(1), oglast.dim(1)); - CAFFE_ENFORCE_EQ(g->dim(2), oglast.dim(2)); - - const auto t = g->dim(0) - 1; - const auto timestep_size = g->size() / g->dim(0); - CAFFE_ENFORCE_EQ(timestep_size, oglast.size()); - T* g_data_with_offset = - g->template mutable_data() + t * timestep_size; - math::Add( - timestep_size, - oglast.template data(), - g_data_with_offset, - g_data_with_offset, - &context_); - } - }; - - accumulateFinalInputGradients(); - - // Create shared blobs for blobs that can be shared between - // all timesteps. - if (stepWorkspaces.size() > 0) { - CreateSharedBlobs(stepWorkspaces[0], &sharedBlobsWs); - } - for (int32_t t = seqLen - 1; t >= 0; --t) { - if (rnnExecutor_) { - rnnExecutor_->EnsureTimestepInitialized(t, stepWorkspaces[t].get()); - } else { - auto* stepNet = stepWorkspaces[t].get()->GetNet(stepNetDef_.name()); - if (stepNet == nullptr) { - stepNet = stepWorkspaces[t].get()->CreateNet(stepNetDef_); - } - CAFFE_ENFORCE(stepNet); - stepNet->RunAsync(); - } - } - - if (rnnExecutor_) { - rnnExecutor_->RunBackwards(seqLen); - } - - CAFFE_ENFORCE_EQ(recurrentInputIds_.size(), recurrentGradients_.size()); - for (int i = 0; i < recurrentInputIds_.size(); ++i) { - // See GetRecurrentNetworkGradient to understand offseting here - // Outputs of the gradient are inputs of the forward pass. - // So we need to offset on all inputs that go before recurrent - // initial ones - auto outputIdx = i + params_.size() + numSequences_; - // because first gradInputs_.size() inputs are from GO - int inputId = recurrentInputIds_[i] + gradInputs_.size(); - VLOG(1) << "Resetting output " << this->debug_def().output(outputIdx) - << " like input " << this->debug_def().input(inputId); - Output(outputIdx)->ResizeLike(Input(inputId)); - T* output_data = Output(outputIdx)->template mutable_data(); - auto pBlob = sharedWs_->GetBlob(recurrentGradients_[i].grad); - CAFFE_ENFORCE(pBlob); - auto* p = pBlob->template GetMutable>(); - - if (Input(inputId).ndim() >= 2) { - // Gradient states blob should live. And if it gets changed by the - // backward pass, then output should be changed as well. Thus it should - // be okay to share data here - Output(outputIdx)->template ShareExternalPointer( - p->template mutable_data()); - } else { - // We need to do a bunch of Adds any way. So lets not worry about - // copy / share data here. One way to speed this up could be a kernel - // which sums up several tensors together instead of going 1 by 1 - const auto recurrentStateSize = Input(inputId).dim32(0); - - math::Set( - recurrentStateSize, - convert::To(0.0), - output_data, - &context_); - - math::AddStripedBatch( - recurrentStateSize, - p->template data(), - output_data, - recurrentStateSize, - batchSize, - &context_); - } - } - - return true; - } - - bool RunOnDevice() { - return DoRunWithType(); - } - - protected: - NetDef stepNetDef_; - Workspace* sharedWs_; - bool enable_rnn_executor_; - std::unique_ptr rnnExecutor_; - std::vector links_; - std::vector params_; - std::vector recurrentGradients_; - std::string timestep_; - // For now we support only one input sequence - const int numSequences_{1}; - std::vector recurrentInputIds_; - std::vector gradInputs_; -}; - -template -class AccumulateInputGradientOp : public Operator { - public: - AccumulateInputGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - offset_(OperatorBase::GetSingleArgument("offset", -1)) { - CAFFE_ENFORCE(offset_ >= 0, "Offset not set"); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - template - bool DoRunWithType() { - const auto t = - OperatorBase::Input>(0).template data()[0]; - auto& og = Input(1); - auto* g = Output(0); - - T* g_data = g->template mutable_data(); - const auto timestep_size = g->size() / g->dim(0); - - CAFFE_ENFORCE( - (t + offset_) * timestep_size + timestep_size <= g->size(), - "Accumulation destination address over bounds"); - CAFFE_ENFORCE( - t * timestep_size + timestep_size <= og.size(), - "Accumulation source address out of bounds"); - - math::Add( - timestep_size, - og.template data() + t * timestep_size, - g_data + (t + offset_) * timestep_size, - g_data + (t + offset_) * timestep_size, - &context_); - return true; - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(1)); - } - - private: - int offset_; -}; - -template -class RNNApplyLinkOp : public Operator { - public: - RNNApplyLinkOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - offset_(OperatorBase::GetSingleArgument("offset", -1)), - window_(OperatorBase::GetSingleArgument("window", -1)) { - CAFFE_ENFORCE(offset_ >= 0, "offset not set"); - CAFFE_ENFORCE(window_ >= 0, "window not set"); - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - template - bool DoRunWithType() { - // Both internal and external appear as both input and output to enforce - // correct dependency computation. - const auto t = - OperatorBase::Input>(0).template data()[0]; - auto& external = Input(1); - - auto* internal_out = Output(0); - auto* external_out = Output(1); - - CAFFE_ENFORCE_GT(external.size(), 0); - const TIndex externalTimestepSize = external.size() / external.dim(0); - auto* externalData = external_out->template mutable_data() + - (t + offset_) * externalTimestepSize; - auto internalDims = external_out->dims(); - internalDims[0] = window_; - - internal_out->Resize(internalDims); - internal_out->ShareExternalPointer( - externalData, externalTimestepSize * window_); - return true; - } - - bool RunOnDevice() override { - return DoRunWithType(); - } - - private: - int offset_; - int window_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECURRENT_NETWORK_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/recurrent_op_cudnn.h b/app/src/main/cpp/caffe2/operators/recurrent_op_cudnn.h deleted file mode 100644 index d820845..0000000 --- a/app/src/main/cpp/caffe2/operators/recurrent_op_cudnn.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RECURRENT_OP_CUDNN_H_ -#define CAFFE2_OPERATORS_RECURRENT_OP_CUDNN_H_ - -#include "caffe2/core/common_cudnn.h" -#include "caffe2/core/context.h" -#include "caffe2/core/context_gpu.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { -namespace detail { - -template -class TensorDescriptors { - public: - TensorDescriptors( - size_t n, - const std::vector& dim, - const std::vector& stride); - ~TensorDescriptors(); - const cudnnTensorDescriptor_t* descs() const { - return descs_.data(); - } - - private: - std::vector descs_; -}; - -} // namespace detail - -template -class RecurrentBaseOp : public Operator { - public: - USE_OPERATOR_FUNCTIONS(CUDAContext); - RecurrentBaseOp(const OperatorDef& operator_def, Workspace* ws); - virtual ~RecurrentBaseOp(); - - protected: - void initialize( - const Tensor& input, - Tensor* dropoutStates = nullptr, - // If passed, reshapes to the appropriate size - Tensor* output = nullptr, - Tensor* hiddenOutput = nullptr, - Tensor* cellOutput = nullptr); - - CuDNNWrapper cudnn_wrapper_; - cudnnDropoutDescriptor_t dropoutDesc_; - cudnnRNNDescriptor_t rnnDesc_; - cudnnFilterDescriptor_t wDesc_; - cudnnTensorDescriptor_t hxDesc_; - cudnnTensorDescriptor_t cxDesc_; - cudnnTensorDescriptor_t hyDesc_; - cudnnTensorDescriptor_t cyDesc_; - - std::unique_ptr> xDesc_; - std::unique_ptr> yDesc_; - - std::vector cachedInputDims_; - size_t reserveNbytes_; - size_t cudnnWsNbytes_; - - private: -}; - -#define USE_RECURRENT_BASE_FUNCTIONS \ - USE_OPERATOR_FUNCTIONS(CUDAContext); \ - using RecurrentBaseOp::cudnn_wrapper_; \ - using RecurrentBaseOp::dropoutDesc_; \ - using RecurrentBaseOp::rnnDesc_; \ - using RecurrentBaseOp::wDesc_; \ - using RecurrentBaseOp::hxDesc_; \ - using RecurrentBaseOp::cxDesc_; \ - using RecurrentBaseOp::hyDesc_; \ - using RecurrentBaseOp::cyDesc_; \ - using RecurrentBaseOp::xDesc_; \ - using RecurrentBaseOp::yDesc_; \ - using RecurrentBaseOp::cachedInputDims_; \ - using RecurrentBaseOp::reserveNbytes_; \ - using RecurrentBaseOp::cudnnWsNbytes_; \ - using RecurrentBaseOp::initialize; - -template -class RecurrentOp : public RecurrentBaseOp { - public: - USE_RECURRENT_BASE_FUNCTIONS - RecurrentOp(const OperatorDef& operator_def, Workspace* ws) - : RecurrentBaseOp(operator_def, ws) {} - - bool RunOnDevice() override; - - protected: - INPUT_TAGS(INPUT, HIDDEN_INPUT, CELL_INPUT, WEIGHT); - OUTPUT_TAGS(OUTPUT, HIDDEN_OUTPUT, CELL_OUTPUT, RNN_SCRATCH, DROPOUT_STATES); -}; - -enum RecurrentParamOpMode { SET_PARAM, GET_PARAM }; - -template -class RecurrentParamAccessOp : public RecurrentBaseOp { - public: - USE_RECURRENT_BASE_FUNCTIONS - RecurrentParamAccessOp(const OperatorDef& operator_def, Workspace* ws) - : RecurrentBaseOp(operator_def, ws) {} - - bool RunOnDevice() override; -}; - -template -class RecurrentGradientOp : public RecurrentBaseOp { - public: - USE_RECURRENT_BASE_FUNCTIONS - RecurrentGradientOp(const OperatorDef& operator_def, Workspace* ws) - : RecurrentBaseOp(operator_def, ws) {} - - bool RunOnDevice() override; - - protected: - INPUT_TAGS( - INPUT, - HIDDEN_INPUT, - CELL_INPUT, - WEIGHT, - RNN_SCRATCH, - OUTPUT, - GRAD_OUTPUT, - GRAD_HIDDEN_OUTPUT, - GRAD_CELL_OUTPUT); - OUTPUT_TAGS( - GRAD_INPUT, - GRAD_HIDDEN_INPUT, - GRAD_CELL_INPUT, - GRAD_WEIGHT, - DROPOUT_STATES, - RNN_SCRATCH_OUT); -}; - - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECURRENT_OP_CUDNN_H_ diff --git a/app/src/main/cpp/caffe2/operators/reducer_functors.h b/app/src/main/cpp/caffe2/operators/reducer_functors.h deleted file mode 100644 index e6308af..0000000 --- a/app/src/main/cpp/caffe2/operators/reducer_functors.h +++ /dev/null @@ -1,842 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_RECUDER_FUNCTORS_H_ -#define CAFFE2_OPERATORS_RECUDER_FUNCTORS_H_ - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/tensor.h" -#include "caffe2/utils/math.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -//////////////////////////////////////////////////////////////////////////////// -// Range reducers: can leverage that input segment is continuous and provide -// special implementation -//////////////////////////////////////////////////////////////////////////////// - -// Put forward and backward in the same template? -template -class SumRangeReducer; -template -class SumRangeReducerGradient; - -template -class SumRangeReducer { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* in, - T* out, - CPUContext* /*context*/) { - // do we need to go through wrapper in math.h? - EigenVectorMap out_vec(out, block_size); - out_vec = ConstEigenMatrixMap(in, block_size, blocks).rowwise().sum(); - } -}; - -template -class SumRangeReducerGradient { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* segment_grad, - T* data_grad, - const T* /*data_in*/, // unused - const T* /*data_out*/, // unused - Context* context) { - // do we have some op that does it smartly with minimum number of memcpy? - for (TIndex i = 0; i < blocks; ++i) { - context->template Copy( - block_size, segment_grad, data_grad + block_size * i); - } - } -}; - -struct SumRangeReducerDef { - template - using Reducer = SumRangeReducer; - template - using ReducerGradient = SumRangeReducerGradient; - static constexpr const char* name = "Sum"; - static constexpr const char* doc = - "Summation is done element-wise across slices of the input tensor and " - "doesn't change the shape of the individual blocks."; -}; - -// Put forward and backward in the same template? -template -class LogSumExpRangeReducer; -template -class LogSumExpRangeReducerGradient; - -template -class LogSumExpRangeReducer { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* in, - T* out, - CPUContext* /*context*/) { - for (int j = 0; j < block_size; ++j) { - T max_value = std::numeric_limits::lowest(); - for (int i = 0; i < blocks; ++i) { - max_value = std::max(max_value, in[i * block_size + j]); - } - T scaled_exp_sum = 0; - for (int i = 0; i < blocks; ++i) { - scaled_exp_sum += std::exp(in[i * block_size + j] - max_value); - } - *(out++) = std::log(scaled_exp_sum) + max_value; - } - } - T r{1}; -}; - -template -class LogSumExpRangeReducerGradient { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* segment_grad, // GO - T* data_grad, // GI - const T* data_in, // I - const T* data_out, // O - Context* /*context*/) { - for (int j = 0; j < block_size; ++j) { - const T out_grad = *(segment_grad++); - const T offset = *(data_out++); - for (int i = 0; i < blocks; ++i) { - auto idx = i * block_size + j; - data_grad[idx] = out_grad * std::exp(data_in[idx] - offset); - } - } - } -}; - -struct LogSumExpRangeReducerDef { - template - using Reducer = LogSumExpRangeReducer; - template - using ReducerGradient = LogSumExpRangeReducerGradient; - static constexpr const char* name = "LogSumExp"; - static constexpr const char* doc = - "LogSumExp computes the element-wise log of the sum of exponentials of " - "input slices. Operation doesn't change the shape of individual blocks."; -}; - -template -class LogMeanExpRangeReducer; -template -class LogMeanExpRangeReducerGradient; - -template -class LogMeanExpRangeReducer { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* in, - T* out, - CPUContext* /*context*/) { - for (int j = 0; j < block_size; ++j) { - T max_value = std::numeric_limits::lowest(); - for (int i = 0; i < blocks; ++i) { - max_value = std::max(max_value, in[i * block_size + j]); - } - T scaled_exp_sum = 0; - for (int i = 0; i < blocks; ++i) { - scaled_exp_sum += std::exp(in[i * block_size + j] - max_value); - } - scaled_exp_sum /= blocks; - *(out++) = std::log(scaled_exp_sum) + max_value; - } - } -}; - -template -class LogMeanExpRangeReducerGradient { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* segment_grad, // GO - T* data_grad, // GI - const T* data_in, // I - const T* data_out, // O - Context* /*context*/) { - for (int j = 0; j < block_size; ++j) { - const T out_grad = *(segment_grad++); - const T offset = *(data_out++); - for (int i = 0; i < blocks; ++i) { - auto idx = i * block_size + j; - data_grad[idx] = out_grad * std::exp(data_in[idx] - offset) / blocks; - } - } - } -}; - -struct LogMeanExpRangeReducerDef { - template - using Reducer = LogMeanExpRangeReducer; - template - using ReducerGradient = LogMeanExpRangeReducerGradient; - static constexpr const char* name = "LogMeanExp"; - static constexpr const char* doc = - "LogMeanExp computes the element-wise log of the mean of exponentials of " - "input slices. Operation doesn't change the shape of individual blocks."; -}; - -template -class MeanRangeReducer; -template -class MeanRangeReducerGradient; - -template -class MeanRangeReducer { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* in, - T* out, - CPUContext* /*context*/) { - for (int j = 0; j < block_size; ++j) { - T avg_value = 0; - for (int i = 0; i < blocks; ++i) { - avg_value += in[i * block_size + j] / blocks; - } - *(out++) = avg_value; - } - } -}; - -template -class MeanRangeReducerGradient { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* segment_grad, // GO - T* data_grad, // GI - const T* /*data_in*/, // I - const T* /*data_out*/, // O - Context* /*context*/) { - const auto in_grad = 1.0 / blocks; - for (int j = 0; j < block_size; ++j) { - const T out_grad = *(segment_grad++); - for (int i = 0; i < blocks; ++i) { - auto idx = i * block_size + j; - data_grad[idx] = out_grad * in_grad; - } - } - } -}; - -struct MeanRangeReducerDef { - template - using Reducer = MeanRangeReducer; - template - using ReducerGradient = MeanRangeReducerGradient; - static constexpr const char* name = "Mean"; - static constexpr const char* doc = - "Mean computation is done element-wise, so that each element of the " - "output slice corresponds to the average value of the respective " - "elements in the input slices. Operation doesn't change the shape of " - "individual blocks."; -}; - -template -class MaxRangeReducer; -template -class MaxRangeReducerGradient; - -template -class MaxRangeReducer { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* in, - T* out, - CPUContext* /*context*/) { - for (int j = 0; j < block_size; ++j) { - T max_value = std::numeric_limits::lowest(); - for (int i = 0; i < blocks; ++i) { - max_value = std::max(max_value, in[i * block_size + j]); - } - *(out++) = max_value; - } - } -}; - -template -class MaxRangeReducerGradient { - public: - void operator()( - const TIndex block_size, - const TIndex blocks, - const T* segment_grad, // GO - T* data_grad, // GI - const T* data_in, // I - const T* data_out, // O - Context* /*context*/) { - std::memset( - static_cast(data_grad), 0, blocks * block_size * sizeof(T)); - for (int j = 0; j < block_size; ++j) { - const T out_grad = *(segment_grad++); - const T out = data_out[j]; - for (int i = 0; i < blocks; ++i) { - auto idx = i * block_size + j; - if (out == data_in[idx]) { - data_grad[idx] = out_grad; - } - } - } - } -}; - -struct MaxRangeReducerDef { - template - using Reducer = MaxRangeReducer; - template - using ReducerGradient = MaxRangeReducerGradient; - static constexpr const char* name = "Max"; - static constexpr const char* doc = - "Max computation is done element-wise, so that each element of the " - "output slice corresponds to the max value of the respective " - "elements in the input slices. Operation doesn't change the shape of " - "individual blocks. This implementation imitates torch nn.Max operator. " - "If the maximum value occurs more than once, the operator will return " - "the first occurence of value. When computing the gradient using the " - "backward propagation, the gradient input corresponding to the first " - "occurence of the maximum value will be used."; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Incremental reducers: consume elements one by one -//////////////////////////////////////////////////////////////////////////////// - -// Base implementation, everything can be overwritten -class BaseReducer { - public: - static constexpr int kInputCount = 1; - - struct Meta { - TIndex block_size; - vector block_shape; - bool first_dim; - - explicit Meta(bool first = true) : first_dim(first) {} - - void computeMeta(const std::vector& dims, int skip_dims) { - first_dim ? block_shape.assign(dims.begin() + skip_dims, dims.end()) - : block_shape.assign(dims.begin(), dims.end() - skip_dims); - block_size = first_dim ? size_from_dim_(skip_dims, dims) - : size_from_dim_(dims.size() - skip_dims, dims); - } - - void - observeInput(int input, const Tensor& value, int skip_dims) { - DCHECK_EQ(0, input); - auto& dims = value.dims(); - computeMeta(dims, skip_dims); - } - - void appendOutputShape(vector* output_shape) { - output_shape->insert( - output_shape->end(), block_shape.begin(), block_shape.end()); - } - - vector getOutputShape(const TensorShape& in, int skip_dims) { - vector dims(in.dims().begin(), in.dims().end()); - computeMeta(dims, skip_dims); - return block_shape; - } - }; - - template - void finish(const Meta& /*meta*/, CPUContext* /*context*/) {} -}; - -class BaseReducerGradient { - public: - // which of the original inputs are required for gradient computation - static constexpr std::array originalInputs() { - return std::array(); - } - - static constexpr bool computeLength() { - return false; - } - - static int numAuxInputsWithGrads(const OperatorDef& /*def*/) { - return 0; - } - - static bool requiresDataInput(const OperatorDef& /*def*/) { - return false; - } - - // True if the backward op requires the output of the forward op. - static bool requiresForwardOutput() { - return false; - } - - struct Meta { - TIndex block_size; - vector block_shape; - bool first_dim; - - Meta( - const Tensor& out_grad, - int skip_dims, - bool first_dim = true) - : first_dim(first_dim) { - auto& dims = out_grad.dims(); - first_dim ? block_shape.assign(dims.begin() + skip_dims, dims.end()) - : block_shape.assign(dims.begin(), dims.end() - skip_dims); - block_size = first_dim - ? out_grad.size_from_dim(skip_dims) - : out_grad.size_from_dim(out_grad.ndim() - skip_dims); - } - - void observeOriginalInput( - int /*original_input*/, - const Tensor& /*value*/, - Tensor* /*input_grad*/, // optional grad to populate - int /*skip_dims*/) {} - - void appendGradShape(vector* output_shape) { - output_shape->insert( - output_shape->end(), block_shape.begin(), block_shape.end()); - } - }; -}; - -// Put forward and backward in the same template? -template -class SumReducer; -template -class SumReducerGradient; - -template -class SumReducer : public BaseReducer { - public: - using FixedDispatch = FixedValues<1>; - - SumReducer(const Meta& meta, T* out, CPUContext* /*context*/) - : current_size_(0), out_(out) { - // add a wrapper in Context for it - if (meta.first_dim) { - memset(out, 0, sizeof(T) * meta.block_size); - } - } - template - void process( - const Meta& meta, - const T* in, - TIndex /*offset*/, - CPUContext* context) { - if (meta.first_dim) { - math::AxpyFixedSize( - meta.block_size, 1, in, out_, context); - } else { - math::Sum( - meta.block_size, in, out_ + current_size_++, context); - } - } - - private: - int current_size_; - T* out_; -}; - -template -class SumReducerGradient : public BaseReducerGradient { - public: - using FixedDispatch = FixedValues<1>; - - SumReducerGradient( - const Meta& /*meta*/, - const T* s_grad, - CPUContext* /*context*/) - : s_grad_(s_grad) {} - - template - void fillGrad( - const Meta& meta, - T* data_grad, - TIndex offset, - Context* context, - const int length) { - if (FixedSize == 1) { // static if - *data_grad = *s_grad_; - } else if (meta.first_dim) { - context->template Copy( - meta.block_size, s_grad_, data_grad); - } else { - math::Set(length, s_grad_[offset], data_grad, context); - } - } - - private: - const T* s_grad_; -}; - -struct SumReducerDef { - template - using Reducer = SumReducer; - template - using ReducerGradient = SumReducerGradient; - static constexpr const char* name = "Sum"; - static constexpr const char* doc = - "Summation is done element-wise across slices of the input tensor and " - "doesn't change the shape of the individual blocks."; - static void PopulateSchema(OpSchema& /*schema*/) {} -}; - -// Put forward and backward in the same template? -template -class WeightedSumReducer; -template -class WeightedSumReducerGradient; - -template -class WeightedSumReducer : public BaseReducer { - public: - static constexpr int kInputCount = 2; - - using FixedDispatch = FixedValues<1>; - - struct Meta : BaseReducer::Meta { - const T* scalars; - - bool first_dim; - - explicit Meta(bool first = true) : first_dim(first) {} - - void - observeInput(int input, const Tensor& value, int skip_dims) { - if (input == 1) { - CAFFE_ENFORCE_EQ( - skip_dims, value.ndim(), "SCALARS mustn't have extra dimensions"); - scalars = value.data(); - return; - } - BaseReducer::Meta::observeInput(input, value, skip_dims); - } - }; - - WeightedSumReducer(const Meta& meta, T* out, CPUContext* /*context*/) - : out_(out) { - // do we have a wrapper for it? - memset(out, 0, sizeof(T) * meta.block_size); - } - template - void - process(const Meta& meta, const T* in, TIndex offset, CPUContext* context) { - CAFFE_ENFORCE( - meta.first_dim, - "WeightedSumReducer implemented only for " - "front dimensions reduction"); - math::AxpyFixedSize( - meta.block_size, meta.scalars[offset], in, out_, context); - } - - private: - T* out_; -}; - -template -class WeightedSumReducerGradient : public BaseReducerGradient { - public: - // which of the original inputs are required for gradient computation - static constexpr std::array originalInputs() { - return {1}; - } - - static int numAuxInputsWithGrads(const OperatorDef& def) { - return GetFlagArgument(def, "grad_on_weights"); - } - - static bool requiresDataInput(const OperatorDef& def) { - return numAuxInputsWithGrads(def) > 0; - } - - using FixedDispatch = FixedValues<1>; - - struct Meta : public BaseReducerGradient::Meta { - const T* scalars; - T* scalars_grad; - - using BaseReducerGradient::Meta::Meta; - - void observeOriginalInput( - int original_input, - const Tensor& value, - Tensor* input_grad, // optional grad to populate - int /*skip_dims*/) { - CAFFE_ENFORCE_EQ(1, original_input); - scalars = value.data(); - if (input_grad) { - input_grad->ResizeLike(value); - scalars_grad = input_grad->mutable_data(); - } - } - }; - - WeightedSumReducerGradient( - const Meta& /*meta*/, - const T* s_grad, - CPUContext* /*context*/) - : s_grad_(s_grad) {} - - template - void fillGrad( - const Meta& meta, - T* data_grad, - TIndex offset, - Context* context, - const int /*length*/) { - math::ScaleFixedSize( - meta.block_size, meta.scalars[offset], s_grad_, data_grad, context); - } - - // Special version which is called with the main input too, used only if - // additional input grad is requested - template - void fillGradWithMainInput( - const Meta& meta, - const T* data, - T* data_grad, - TIndex offset, - Context* context, - const int /*length*/) { - math::ScaleFixedSize( - meta.block_size, meta.scalars[offset], s_grad_, data_grad, context); - math::Dot( - meta.block_size, s_grad_, data, meta.scalars_grad + offset, context); - } - - private: - const T* s_grad_; -}; - -struct WeightedSumReducerDef { - template - using Reducer = WeightedSumReducer; - template - using ReducerGradient = WeightedSumReducerGradient; - static constexpr const char* name = "WeightedSum"; - static constexpr const char* doc = - "Input slices are first scaled by SCALARS and then summed element-wise. " - "It doesn't change the shape of the individual blocks."; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor for the summation"); - schema.Input( - 1, - "SCALARS", - "Scalar multipliers for the input slices. Must be a vector with the " - "length matching the first dimension of DATA"); - schema.Arg( - "grad_on_weights", - "Produce also gradient for `weights`. For now it's only supported in " - "`Lengths`-based operators"); - } -}; - -template -class MeanReducer; -template -class MeanReducerGradient; - -template -class MeanReducer : public BaseReducer { - public: - using FixedDispatch = FixedValues<1>; - - MeanReducer(const Meta& meta, T* out, CPUContext* /*context*/) - : out_(out), current_size_(0) { - if (meta.first_dim) { - memset(out, 0, sizeof(T) * meta.block_size); - } - } - - template - void process( - const Meta& meta, - const T* in, - TIndex /*offset*/, - CPUContext* context) { - if (meta.first_dim) { - math::AxpyFixedSize( - meta.block_size, 1, in, out_, context); - } else { - math::Sum( - meta.block_size, in, out_ + current_size_, context); - } - current_size_++; - } - - template - void finish(const Meta& meta, CPUContext* context) { - if (meta.first_dim) { - if (current_size_ > 0) { - math::ScaleFixedSize( - meta.block_size, 1.0 / current_size_, out_, out_, context); - } - } else { - math::ScaleFixedSize( - current_size_, 1.0 / meta.block_size, out_, out_, context); - } - } - - private: - T* out_; - int current_size_; -}; - -template -class MeanReducerGradient : public BaseReducerGradient { - public: - static constexpr bool computeLength() { - return true; - } - - using FixedDispatch = FixedValues<1>; - - MeanReducerGradient( - const Meta& /*meta*/, - const T* s_grad, - CPUContext* /*context*/) - : s_grad_(s_grad) {} - - template - void fillGrad( - const Meta& meta, - T* data_grad, - TIndex offset, - Context* context, - const int length) { - CAFFE_ENFORCE_GT(length, 0, "Segment length must be > 0"); - if (meta.first_dim) { - math::ScaleFixedSize( - meta.block_size, 1.0 / length, s_grad_, data_grad, context); - } else { - math::Set( - length, s_grad_[offset] * 1.0f / length, data_grad, context); - } - } - - private: - const T* s_grad_; -}; - -struct MeanReducerDef { - template - using Reducer = MeanReducer; - template - using ReducerGradient = MeanReducerGradient; - static constexpr const char* name = "Mean"; - static constexpr const char* doc = - "Mean computes the element-wise mean of the input slices. " - "Operation doesn't change the shape of the individual blocks."; - static void PopulateSchema(OpSchema& /*schema*/) {} -}; - -template -class MaxReducer; -template -class MaxReducerGradient; - -template -class MaxReducer : public BaseReducer { - public: - using FixedDispatch = FixedValues<1>; - - MaxReducer(const Meta& meta, T* out, CPUContext* /*context*/) - : out_(out), current_size_(0) {} - - template - void process( - const Meta& meta, - const T* in, - TIndex /*offset*/, - CPUContext* context) { - CAFFE_ENFORCE( - meta.first_dim, - "MaxReducer implemented only for front dimensions reduction"); - if (current_size_ > 0) { - EigenVectorMap output_vec(out_, meta.block_size); - output_vec = - output_vec.cwiseMax(ConstEigenVectorMap(in, meta.block_size)); - } else { - memcpy(out_, in, sizeof(T) * meta.block_size); - } - ++current_size_; - } - - private: - T* out_; - int current_size_; -}; - -template -class MaxReducerGradient : public BaseReducerGradient { - public: - static bool requiresDataInput(const OperatorDef& /*def*/) { - return true; - } - - static bool requiresForwardOutput() { - return true; - } - - using FixedDispatch = FixedValues<1>; - - MaxReducerGradient( - const Meta& /*meta*/, - const T* s_grad, - CPUContext* /*context*/) - : s_grad_(s_grad) {} - - template - void fillGradWithMainInputAndForwardOutput( - const Meta& meta, - const T* data, - T* data_grad, - const T* forward_output, - TIndex /*offset*/, - Context* /*context*/, - const int /*length*/) { - for (TIndex i = 0; i < meta.block_size; ++i) { - data_grad[i] = data[i] == forward_output[i] ? s_grad_[i] : 0; - } - } - - private: - const T* s_grad_; -}; - -struct MaxReducerDef { - template - using Reducer = MaxReducer; - template - using ReducerGradient = MaxReducerGradient; - static constexpr const char* name = "Max"; - static constexpr const char* doc = - "Max computes the element-wise max of the input slices. " - "Operation doesn't change the shape of the individual blocks."; - static void PopulateSchema(OpSchema& /*schema*/) {} -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RECUDER_FUNCTORS_H_ diff --git a/app/src/main/cpp/caffe2/operators/reduction_front_back_ops.h b/app/src/main/cpp/caffe2/operators/reduction_front_back_ops.h deleted file mode 100644 index 50b1e9d..0000000 --- a/app/src/main/cpp/caffe2/operators/reduction_front_back_ops.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef CAFFE2_OPERATORS_REDUCTION_FRONT_BACK_OPS_H_ -#define CAFFE2_OPERATORS_REDUCTION_FRONT_BACK_OPS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class MaxReduceDimsOp final : public Operator { - public: - MaxReduceDimsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_reduce_dims_( - OperatorBase::GetSingleArgument("num_reduce_dim", 1)) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() { - auto& X = Input(0); - auto* Y = Output(0); - - const int rows = FIRSTDIMS ? X.size_to_dim(num_reduce_dims_) - : X.size_to_dim(X.ndim() - num_reduce_dims_); - const int cols = FIRSTDIMS ? X.size_from_dim(num_reduce_dims_) - : X.size_from_dim(X.ndim() - num_reduce_dims_); - - vector output_shape; - int start_index = FIRSTDIMS ? num_reduce_dims_ : 0; - int end_index = - FIRSTDIMS ? X.dims().size() : X.dims().size() - num_reduce_dims_; - - for (int i = start_index; i < end_index; ++i) { - output_shape.push_back(X.dims()[i]); - } - Y->Resize(output_shape); - - if (cols == 0 || rows == 0) { - return true; - } - - const float* data = X.template data(); - float* out_data = Y->template mutable_data(); - Compute(rows, cols, data, out_data); - return true; - } - - protected: - void Compute(int rows, int cols, const float* data, float* out_data); - - int num_reduce_dims_; -}; - -template -class MaxReduceDimsGradientOp final : public Operator { - public: - MaxReduceDimsGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - num_reduce_dims_( - OperatorBase::GetSingleArgument("num_reduce_dim", 1)) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& dY = Input(0); - auto& X = Input(1); - auto& Y = Input(2); - auto* dX = Output(0); - - dX->ResizeLike(X); - const int rows = FIRSTDIMS ? X.size_to_dim(num_reduce_dims_) - : X.size_to_dim(X.ndim() - num_reduce_dims_); - const int cols = FIRSTDIMS ? X.size_from_dim(num_reduce_dims_) - : X.size_from_dim(X.ndim() - num_reduce_dims_); - - const float* dYdata = dY.template data(); - const float* Xdata = X.template data(); - const float* Ydata = Y.template data(); - - float* dXdata = dX->template mutable_data(); - Compute(rows, cols, dYdata, Xdata, Ydata, dXdata); - return true; - } - - protected: - void Compute( - int rows, - int cols, - const float* dYdata, - const float* Xdata, - const float* Ydata, - float* dXdata); - - int num_reduce_dims_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_REDUCTION_FRONT_BACK_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/reduction_ops.h b/app/src/main/cpp/caffe2/operators/reduction_ops.h deleted file mode 100644 index b0bceef..0000000 --- a/app/src/main/cpp/caffe2/operators/reduction_ops.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef CAFFE2_OPERATORS_REDUCTION_OPS_H_ -#define CAFFE2_OPERATORS_REDUCTION_OPS_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SumElementsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - SumElementsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - average_(OperatorBase::GetSingleArgument("average", false)) {} - SumElementsOp(const OperatorDef& operator_def, Workspace* ws, bool average) - : Operator(operator_def, ws), average_(average) {} - ~SumElementsOp() {} - - bool RunOnDevice() override -// TODO: T21635002 fix float-divide-by-zero undefined behavior -#if defined(__has_feature) -#if __has_feature(__address_sanitizer__) - __attribute__((__no_sanitize__("float-divide-by-zero"))) -#endif -#endif - { - auto& X = Input(0); - auto* sum = Output(0); - sum->Resize(vector()); - T* data = sum->template mutable_data(); - math::Sum( - X.size(), X.template data(), data, &context_, &scratch_); - if (average_) { - math::Scale( - 1, - static_cast(1.) / X.size(), - sum->template data(), - data, - &context_); - } - return true; - } - - private: - bool average_; - Tensor scratch_; -}; - -template -class SumElementsGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - SumElementsGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - average_(OperatorBase::GetSingleArgument("average", false)) {} - SumElementsGradientOp( - const OperatorDef& operator_def, - Workspace* ws, - bool average) - : Operator(operator_def, ws), average_(average) {} - ~SumElementsGradientOp() {} - - bool RunOnDevice() override; - - private: - bool average_; -}; - -template -class SumSqrElementsOp : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(SumSqrElementsOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - bool average = OperatorBase::GetSingleArgument("average", false); - auto& X = Input(0); - auto* sum = Output(0); - sum->Resize(vector()); - math::SumSqr( - X.size(), - X.template data(), - sum->template mutable_data(), - &context_, - &scratch_); - if (average) { - math::Scale( - 1, - float(1.) / X.size(), - sum->template data(), - sum->template mutable_data(), - &context_); - } - return true; - } - - private: - Tensor scratch_; -}; - -template -class MaxReductionOp : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(MaxReductionOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& X = Input(0); - CAFFE_ENFORCE_EQ(X.ndim(), 3); - - const int batch_size = X.dim32(0); - const int M = X.dim32(1); - const int N = X.dim32(2); - - auto* Y = Output(0); - ROWWISE ? Y->Resize(batch_size, M) : Y->Resize(batch_size, N); - - if (ROWWISE) { - math::RowwiseMax( - batch_size * M, - N, - X.template data(), - Y->template mutable_data(), - &context_); - } else { - const int input_size = N * M; - for (int i = 0; i < batch_size; ++i) { - math::ColwiseMax( - M, - N, - X.template data() + i * input_size, - Y->template mutable_data() + i * N, - &context_); - } - } - return true; - } -}; - -template -class MaxReductionGradientOp : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(MaxReductionGradientOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif diff --git a/app/src/main/cpp/caffe2/operators/relu_op.h b/app/src/main/cpp/caffe2/operators/relu_op.h deleted file mode 100644 index 2b29b9b..0000000 --- a/app/src/main/cpp/caffe2/operators/relu_op.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RELU_OP_H_ -#define CAFFE2_OPERATORS_RELU_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class ReluOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(ReluOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: -}; - -template -class ReluGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(ReluGradientOp); - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - // Input: Y, dY; Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RELU_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/remove_data_blocks_op.h b/app/src/main/cpp/caffe2/operators/remove_data_blocks_op.h deleted file mode 100644 index 9530242..0000000 --- a/app/src/main/cpp/caffe2/operators/remove_data_blocks_op.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_ -#define CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_ - -#include -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class RemoveDataBlocksOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(RemoveDataBlocksOp); - USE_DISPATCH_HELPER; - - bool RunOnDevice() override { - if (Input(INDICES).dims()[0] == 0) { - Output(0)->CopyFrom(Input(0)); - return true; - } else { - return DispatchHelper>::call(this, Input(INDICES)); - } - } - - template - bool DoRunWithType() { - const auto& data = Input(DATA); - const auto& indices = Input(INDICES); - CAFFE_ENFORCE(data.ndim() > 0, "DATA should be at leat 1-D."); - CAFFE_ENFORCE(indices.ndim() == 1, "INDICES should be 1-D."); - - const auto outer_size = data.dims()[0]; - const auto block_size = data.size_from_dim(1); - const auto block_size_bytes = block_size * data.meta().itemsize(); - auto indices_size = indices.dims()[0]; - const char* data_ptr = (char*)data.raw_data(); - const auto* ind_ptr = indices.template data(); - - std::vector ind_vec; - for (int64_t i = 0; i < indices_size; i++) { - ind_vec.push_back(ind_ptr[i]); - } - std::sort(ind_vec.begin(), ind_vec.end()); - CAFFE_ENFORCE(ind_vec[0] >= 0, "The min index should be larger than zero."); - CAFFE_ENFORCE( - ind_vec[indices_size - 1] < outer_size, - "The max index should be smaller than the data outer size."); - // removes duplicate indices - ind_vec.erase(std::unique(ind_vec.begin(), ind_vec.end()), ind_vec.end()); - indices_size = ind_vec.size(); - - auto* output = Output(0); - auto shape = data.dims(); - shape[0] -= indices_size; - output->Resize(shape); - char* out_ptr = (char*)output->raw_mutable_data(data.meta()); - - ind_vec.insert(ind_vec.begin(), -1); - int64_t ind_vec_size = ind_vec.size(); - for (auto i = 0; i < ind_vec_size; i++) { - int64_t interval_start = ind_vec[i] + 1; - int64_t interval_end = - (i == ind_vec_size - 1) ? outer_size : ind_vec[i + 1]; - auto num_items = interval_end - interval_start; - context_.template CopyItems( - data.meta(), - num_items * block_size, - data_ptr + block_size_bytes * interval_start, - out_ptr); - out_ptr += block_size_bytes * num_items; - } - - return true; - } - - private: - INPUT_TAGS(DATA, INDICES); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_REMOVE_DATA_BLOCKS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/replace_nan_op.h b/app/src/main/cpp/caffe2/operators/replace_nan_op.h deleted file mode 100644 index dd6ac38..0000000 --- a/app/src/main/cpp/caffe2/operators/replace_nan_op.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef CAFFE_OPERATORS_REPLACE_NAN_OP_H_ -#define CAFFE_OPERATORS_REPLACE_NAN_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class ReplaceNaNOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ReplaceNaNOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - T value = OperatorBase::GetSingleArgument("value", 0); - - auto& input = Input(0); - auto* output = Output(0); - output->ResizeLike(input); - - const T* input_data = input.template data(); - T* output_data = output->template mutable_data(); - for (TIndex i = 0; i < input.size(); i++) { - if (std::isnan(input_data[i])) { - output_data[i] = value; - } else { - output_data[i] = input_data[i]; - } - } - - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE_OPERATORS_REPLACE_NAN_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/reshape_op.h b/app/src/main/cpp/caffe2/operators/reshape_op.h deleted file mode 100644 index 151a9e3..0000000 --- a/app/src/main/cpp/caffe2/operators/reshape_op.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef CAFFE2_OPERATORS_RESHAPE_OP_H_ -#define CAFFE2_OPERATORS_RESHAPE_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// Takes a shape and data tensor and reshapes it -template -class ReshapeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ReshapeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - new_shape_(OperatorBase::GetRepeatedArgument("shape")) {} - - bool RunOnDevice() override { - if (InputSize() == 2) { - return DispatchHelper>::call(this, Input(1)); - } - CAFFE_ENFORCE( - OperatorBase::HasArgument("shape"), "Argument `shape` is missing."); - return this->template DoRunWithType(); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - - vector actual_new_shape = new_shape_; - if (InputSize() == 2) { - CAFFE_ENFORCE( - !OperatorBase::HasArgument("shape"), - "New shape is specified by the input blob, do not pass in " - "the argument `shape`."); - - auto& shape = Input(1); - CAFFE_ENFORCE(shape.ndim() == 1, "Shape should be 1-D"); - - const T* shape_data = shape.template data(); - - // Bit awkward, but needed so works on both CPU and CUDA contexts - std::vector tmpv(shape.size()); - context_.template CopyBytes( - shape.size() * sizeof(T), shape_data, &tmpv[0]); - actual_new_shape.assign(tmpv.begin(), tmpv.begin() + shape.size()); - } - - // Copy over the dimensions for those that are specified zero. - for (int i = 0; i < actual_new_shape.size(); ++i) { - if (actual_new_shape[i] == 0) { - actual_new_shape[i] = input.dim(i); - } - } - - // Checks if the new shape is valid and fills in the missing dimension - // specified by -1. - // NOTE: At most one dimension can be -1. - auto total_size = input.size_from_dim(0); - T size = 1; - int unknown_idx = -1; - for (int i = 0; i < actual_new_shape.size(); ++i) { - const auto dim = actual_new_shape[i]; - if (dim == -1) { - CAFFE_ENFORCE( - unknown_idx == -1, - "Argument `shape` has more than one missing dimension."); - unknown_idx = i; - } else { - size *= dim; - } - } - - if (unknown_idx != -1) { - CAFFE_ENFORCE( - total_size % size == 0, - "Argument `shape` does not agree with the input data.", - " (", - total_size, - " vs ", - size, - ")"); - actual_new_shape[unknown_idx] = total_size / size; - } else { - CAFFE_ENFORCE_EQ( - total_size, - size, - "Argument `shape` does not agree with the input data.", - " (", - total_size, - " != ", - size, - ")"); - } - - // Write the original shape to the second output. - auto* old_shape = Output(1); - old_shape->Resize(input.ndim()); - T* old_shape_data = old_shape->template mutable_data(); - for (int i = 0; i < input.ndim(); ++i) { - math::Set(1, input.dim(i), old_shape_data + i, &context_); - } - - auto* output = Output(0); - output->Resize(actual_new_shape); - if (output != &input) { - // If we are not doing in-place computation, a copy is needed. - context_.template CopyBytes( - input.nbytes(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - } - - return true; - } - - private: - vector new_shape_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RESHAPE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/resize_op.h b/app/src/main/cpp/caffe2/operators/resize_op.h deleted file mode 100644 index 42f9937..0000000 --- a/app/src/main/cpp/caffe2/operators/resize_op.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class ResizeNearestOp final : public Operator { - public: - ResizeNearestOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), width_scale_(1), height_scale_(1) { - if (HasArgument("width_scale")) { - width_scale_ = static_cast( - OperatorBase::GetSingleArgument("width_scale", 1)); - } - if (HasArgument("height_scale")) { - height_scale_ = static_cast( - OperatorBase::GetSingleArgument("height_scale", 1)); - } - CAFFE_ENFORCE_GT(width_scale_, 0); - CAFFE_ENFORCE_GT(height_scale_, 0); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T width_scale_; - T height_scale_; -}; - -template -class ResizeNearestGradientOp final : public Operator { - public: - ResizeNearestGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), width_scale_(1), height_scale_(1) { - width_scale_ = static_cast( - OperatorBase::GetSingleArgument("width_scale", 1)); - height_scale_ = static_cast( - OperatorBase::GetSingleArgument("height_scale", 1)); - CAFFE_ENFORCE_GT(width_scale_, 0); - CAFFE_ENFORCE_GT(height_scale_, 0); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - T width_scale_; - T height_scale_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/reverse_packed_segs_op.h b/app/src/main/cpp/caffe2/operators/reverse_packed_segs_op.h deleted file mode 100644 index f2f1122..0000000 --- a/app/src/main/cpp/caffe2/operators/reverse_packed_segs_op.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef CAFFE2_OPERATORS_REVERSE_PACKED_SEGS_OP_H_ -#define CAFFE2_OPERATORS_REVERSE_PACKED_SEGS_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class ReversePackedSegsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ReversePackedSegsOp); - USE_DISPATCH_HELPER; - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(DATA)); - } - - template - bool DoRunWithType() { - if (Input(LENGTHS).template IsType()) { - DoRunWithLengthType(); - } else { - DoRunWithLengthType(); - } - return true; - } - - private: - INPUT_TAGS(DATA, LENGTHS); - - template - void DoRunWithLengthType() { - const auto& data = Input(DATA); - const auto& lengths = Input(LENGTHS); - - CAFFE_ENFORCE( - data.ndim() == 3, - "DATA should be 3-D tensor "); - CAFFE_ENFORCE(lengths.ndim() == 1, "LENGTH should be 1-D"); - - auto* output = Output(0); - const auto& shape = data.dims(); - output->Resize(shape); - - const auto& max_length = data.dims()[0]; - const auto& batch_size = data.dims()[1]; - const auto& block_size = data.dims()[2]; - CAFFE_ENFORCE( - lengths.dims()[0] == batch_size, - "lenths size should be" - " equal to batch size"); - - const T* data_ptr = data.template data(); - const LengthType* lengths_ptr = lengths.template data(); - - vector lengths_host(batch_size); - context_.template Copy( - batch_size, lengths_ptr, &lengths_host[0]); - context_.FinishDeviceComputation(); - - T* rev_data_ptr = output->template mutable_data(); - for (TIndex i = 0; i < batch_size; i++) { - const auto& seg_length = lengths_host[i]; - CAFFE_ENFORCE_LE(seg_length, max_length); - TIndex j = 0; - for (; j < seg_length; j++) { - const T* data_block_ptr = data_ptr + (j * batch_size + i) * block_size; - T* rev_data_block_ptr = - rev_data_ptr + ((seg_length - 1 - j) * batch_size + i) * block_size; - context_.template Copy( - block_size, data_block_ptr, rev_data_block_ptr); - } - for (; j < max_length; j++) { - const T* data_block_ptr = data_ptr + (j * batch_size + i) * block_size; - T* rev_data_block_ptr = - rev_data_ptr + (j * batch_size + i) * block_size; - context_.template Copy( - block_size, data_block_ptr, rev_data_block_ptr); - } - } - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_REVERSE_PACKED_SEGS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/rmac_regions_op.h b/app/src/main/cpp/caffe2/operators/rmac_regions_op.h deleted file mode 100644 index bb71f2e..0000000 --- a/app/src/main/cpp/caffe2/operators/rmac_regions_op.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#ifndef CAFFE2_OPERATORS_RMAC_REGIONS_OP_H -#define CAFFE2_OPERATORS_RMAC_REGIONS_OP_H - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class RMACRegionsOp final : public Operator { - public: - RMACRegionsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - scales_(OperatorBase::GetSingleArgument("scales", 3)), - overlap_(OperatorBase::GetSingleArgument("overlap", 0.4)) {} - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - int scales_; - float overlap_; - Tensor num_rois_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_RMAC_REGIONS_OP_H diff --git a/app/src/main/cpp/caffe2/operators/roi_pool_op.h b/app/src/main/cpp/caffe2/operators/roi_pool_op.h deleted file mode 100644 index 7be379d..0000000 --- a/app/src/main/cpp/caffe2/operators/roi_pool_op.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef ROI_POOL_OP_H_ -#define ROI_POOL_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class RoIPoolOp final : public Operator { - public: - RoIPoolOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - is_test_(OperatorBase::GetSingleArgument(OpSchema::Arg_IsTest, 0)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - pooled_height_(OperatorBase::GetSingleArgument("pooled_h", 1)), - pooled_width_(OperatorBase::GetSingleArgument("pooled_w", 1)), - spatial_scale_( - OperatorBase::GetSingleArgument("spatial_scale", 1.)) { - CAFFE_ENFORCE( - (is_test_ && OutputSize() == 1) || (!is_test_ && OutputSize() == 2), - "Output size mismatch."); - CAFFE_ENFORCE_GT(spatial_scale_, 0); - CAFFE_ENFORCE_GT(pooled_height_, 0); - CAFFE_ENFORCE_GT(pooled_width_, 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - bool is_test_; - StorageOrder order_; - int pooled_height_; - int pooled_width_; - float spatial_scale_; -}; - -template -class RoIPoolGradientOp final : public Operator { - public: - RoIPoolGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - spatial_scale_( - OperatorBase::GetSingleArgument("spatial_scale", 1.)), - pooled_height_(OperatorBase::GetSingleArgument("pooled_h", 1)), - pooled_width_(OperatorBase::GetSingleArgument("pooled_w", 1)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE_GT(spatial_scale_, 0); - CAFFE_ENFORCE_GT(pooled_height_, 0); - CAFFE_ENFORCE_GT(pooled_width_, 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - CAFFE_NOT_IMPLEMENTED; - } - - protected: - float spatial_scale_; - int pooled_height_; - int pooled_width_; - StorageOrder order_; -}; - -} // namespace caffe2 - -#endif // ROI_POOL_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/rowmul_op.h b/app/src/main/cpp/caffe2/operators/rowmul_op.h deleted file mode 100644 index cf82044..0000000 --- a/app/src/main/cpp/caffe2/operators/rowmul_op.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef CAFFE2_OPERATORS_ROW_MUL_H_ -#define CAFFE2_OPERATORS_ROW_MUL_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// A hacky version of Mul with broadcast -// RowMul([mat, w], [output]) -template -class RowMulOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(RowMulOp); - - bool RunOnDevice() override { - auto& mat = Input(0); - auto& w = Input(1); - auto* output = Output(0); - - output->ResizeLike(mat); - T* output_data = output->template mutable_data(); - const T* mat_data = mat.template data(); - const T* w_data = w.template data(); - - // Dimension checking - CAFFE_ENFORCE_EQ( - w.size(), - mat.dim32(0), - "Length of w should be equal to the first dim of mat"); - - auto block_size = mat.size_from_dim(1); - for (int i = 0; i < w.size(); i++) { - size_t offset = i * block_size; - for (int j = 0; j < block_size; j++) { - output_data[offset + j] = mat_data[offset + j] * w_data[i]; - } - } - - return true; - } -}; - -// A hacky version -template -class ReduceTailSumOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ReduceTailSumOp); - - bool RunOnDevice() override { - auto& mat = Input(0); - auto* output = Output(0); - - int N = mat.dim32(0); - int block_size = mat.size_from_dim(1); - - output->Resize(N); - T* output_data = output->template mutable_data(); - const T* mat_data = mat.template data(); - - for (int i = 0; i < N; i++) { - output_data[i] = 0; - size_t offset = i * block_size; - for (int j = 0; j < block_size; j++) { - output_data[i] += mat_data[offset + j]; - } - } - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_ROW_MUL_H_ diff --git a/app/src/main/cpp/caffe2/operators/scale_op.h b/app/src/main/cpp/caffe2/operators/scale_op.h deleted file mode 100644 index b8632ea..0000000 --- a/app/src/main/cpp/caffe2/operators/scale_op.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SCALE_OP_H_ -#define CAFFE2_OPERATORS_SCALE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class ScaleOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ScaleOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 1.0)) {} - - template - bool DoRunWithType() { - auto& X = Input(0); - auto* Y = Output(0); - Y->ResizeLike(X); - math::Scale( - X.size(), - scale_, - X.template data(), - Y->template mutable_data(), - &context_); - return true; - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - protected: - float scale_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SCALE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/segment_reduction_op.h b/app/src/main/cpp/caffe2/operators/segment_reduction_op.h deleted file mode 100644 index 65bda40..0000000 --- a/app/src/main/cpp/caffe2/operators/segment_reduction_op.h +++ /dev/null @@ -1,2043 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SEGMENT_REDUCTION_OP_H_ -#define CAFFE2_OPERATORS_SEGMENT_REDUCTION_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/operators/reducer_functors.h" - -namespace caffe2 { - -template -class BaseInputAccessor { - public: - BaseInputAccessor() {} - - bool observeInput(const Tensor& dataInput) { - data_ = dataInput.raw_data(); - return dataInput.template IsType(); - } - - inline const TData* - getBlockPtr(TIndex in_block_size, TIndex idx, TIndex /* blocks */ = 1) { - return static_cast(data_) + in_block_size * idx; - } - - protected: - const void* data_ = nullptr; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Range reducer ops: leverage that input segment is continuous and allow -// reducer functors to do something special -// Note: for now there are no real use cases for it yet :) -// Also, doesn't support additional arguments for now -//////////////////////////////////////////////////////////////////////////////// - -/** - * Base implementation for segment reduction op that leverages continuity of the - * data - * - * Assumes that segments are sorted and there are no skip indices - */ -template < - typename T, - typename SIndex, - class Context, - class RangeReducer, - class InputAccessor = BaseInputAccessor> -class AbstractSortedSegmentRangeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractSortedSegmentRangeOp); - - bool RunOnDevice() override { - auto& dataInput = Input(DATA); - auto& segment_ids = Input(SEGMENT_IDS); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - auto N = segment_ids.dim(0); - CAFFE_ENFORCE_EQ( - N, - dataInput.dim(0), - "SEGMENT_IDS must have the same length as outer dimension of DATA"); - - OPERATOR_NEEDS_FEATURE( - inputAccessor_.observeInput(dataInput), - "Unsupported input type: ", - dataInput.meta().name(), - "."); - - const SIndex* s_ids = segment_ids.template data(); - - const SIndex K = N > 0 ? s_ids[N - 1] + 1 : 0; - auto shape = dataInput.dims(); - shape[0] = K; - output->Resize(shape); - - T* out = output->template mutable_data(); - - if (N == 0) { - return true; - } - - TIndex block_size = dataInput.size() / N; - - // Assume the segments are sorted and there are no gaps - CAFFE_ENFORCE_EQ(0, s_ids[0], "Indices must be sorted and not have gaps"); - for (TIndex i = 0; i < N;) { - TIndex start = i; - for (++i; i < N && s_ids[start] == s_ids[i]; ++i) - ; - - RangeReducer()( - block_size, - i - start, - inputAccessor_.getBlockPtr(block_size, start, i - start), - out + block_size * s_ids[start], - &context_); - - // check correctness of the next segment - if (i < N) { - CAFFE_ENFORCE_EQ( - s_ids[start] + 1, - s_ids[i], - "Indices must be sorted and not have gaps"); - } - } - return true; - } - - static constexpr int kNumInputs = 2; - INPUT_TAGS(DATA, SEGMENT_IDS); - - private: - InputAccessor inputAccessor_; -}; - -template < - typename T, - typename SIndex, - class Context, - class RangeReducerGradient> -class AbstractSortedSegmentRangeGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractSortedSegmentRangeGradientOp); - - bool RunOnDevice() override { - // TODO(azzolini): avoid using input/output if not used by a particular op - auto& data_in = Input(DATA_IN); - auto& data_out = Input(DATA_OUT); - auto& segment_grads = Input(SEGMENT_GRADS); - auto& segment_ids = Input(SEGMENT_IDS); - auto* data_grads = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - TIndex N = segment_ids.dim(0); - - const SIndex* s_ids = segment_ids.template data(); - const T* s_grads = segment_grads.template data(); - const T* d_in = data_in.template data(); - const T* d_out = data_out.template data(); - - auto shape = segment_grads.dims(); - shape[0] = N; - data_grads->Resize(shape); - - const SIndex K = segment_grads.dim(0); - T* out = data_grads->template mutable_data(); - - if (N == 0) { - return true; - } - - TIndex block_size = segment_grads.size_from_dim(1); - - // Assume the segments are sorted and there are no gaps - CAFFE_ENFORCE_EQ(0, s_ids[0], "Indices must be sorted and not have gaps"); - // repeat the check from forward op - CAFFE_ENFORCE_EQ( - K - 1, s_ids[N - 1], "Indices must be sorted and not have gaps"); - for (TIndex i = 0; i < N;) { - TIndex start = i; - for (++i; i < N && s_ids[start] == s_ids[i]; ++i) - ; - - auto expanded_idx = block_size * start; - auto reduced_idx = block_size * s_ids[start]; - RangeReducerGradient()( - block_size, - i - start, - s_grads + reduced_idx, - out + expanded_idx, - d_in + expanded_idx, - d_out + reduced_idx, - &context_); - - // check correctness of the next segment - if (i < N) { - CAFFE_ENFORCE_EQ( - s_ids[start] + 1, - s_ids[i], - "Indices must be sorted and not have gaps"); - } - } - return true; - } - - static constexpr int kNumInputs = 4; - INPUT_TAGS(DATA_IN, DATA_OUT, SEGMENT_GRADS, SEGMENT_IDS); -}; - -template -struct AbstractSortedSegmentRangeDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "SortedSegmentRange"; - static constexpr const char* doc = R"DOC( -Applies '{op}' to each segment of input tensor. In order to allow for more -efficient implementation of '{op}', the input segments have to be contiguous -and non-empty. - -SEGMENT_IDS is a vector that maps each of the first dimension slices of the -DATA to a particular group (segment). Values belonging to the same segment are -aggregated together. - -The first dimension of the output is equal to the number of input segments, -i.e. `SEGMENT_IDS[-1]+1`. Other dimensions are inherited from the input tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor to be aggregated"); - schema.Input( - 1, - "SEGMENT_IDS", - "Vector with the same length as the first dimension of DATA " - "and values in the range 0..K-1 and in increasing order that " - "maps each slice of DATA to one of the segments"); - schema.Output( - 0, - "OUTPUT", - "Aggregated tensor with the first dimension of K and the " - "other dimentsions inherited from DATA"); - } - using ForwardOp = AbstractSortedSegmentRangeOp< - T, - SIndex, - Context, - typename ReducerDef::template Reducer>; - using BackwardOp = AbstractSortedSegmentRangeGradientOp< - T, - SIndex, - Context, - typename ReducerDef::template ReducerGradient>; - struct GetGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - return SingleGradientDef( - string(basename) + ReducerDef::name + "Gradient", - "", - vector{I(0), O(0), GO(0), I(1)}, - // no gradient on segment_ids! - vector{GI(0)}); - } - }; -}; - -//////////////////////////////////////////////////////////////////////////////// -// Incremental reducer ops: assume that reducer consumes pieces of data one by -// one. Also, supports additional arguments passed to reducer, e.g. scalers for -// weighted sum. -// -// Note: in current implementation additional inputs are considered auxiliary -// constants and have limitations: -// - there is no gradient computation for auxiliary inputs -// - auxiliary inputs aren't affected by fused embedding lookup in operations -// like sparse_sorted_segment -//////////////////////////////////////////////////////////////////////////////// - -/** - * @brief Simple non-segmented reduction over the first few dimensions of the - * tensor - * - * Inputs: - * 0: DATA - input embedding to do lookups in - * 1..P: AUX_ARG_ - optional additional arguments to be passed to the - * reducer - * - * Args: - * num_reduce_dim (default 1) - the number of dims in front of the tensor to - * reduce - * - * Output: - * Tensor without the first `num_dim` dimensions of DATA - */ -template < - typename T, - class Context, - class Reducer, - bool FirstDim, - class InputAccessor = BaseInputAccessor> -class AbstractReduceFrontOrBackOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - AbstractReduceFrontOrBackOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(int, "num_reduce_dim", num_reduce_dims_, 1) {} - - bool RunOnDevice() override { - auto& data = Input(0); - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex in_block_size = FirstDim - ? data.size_from_dim(num_reduce_dims_) - : data.size_to_dim(data.ndim() - num_reduce_dims_); - return DispatchHelper::call( - this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& data = Input(0); - auto* output = Output(0); - - CAFFE_ENFORCE_LE(num_reduce_dims_, data.ndim()); - - typename Reducer::Meta ctx(FirstDim); - ctx.observeInput(0, data, num_reduce_dims_); - for (int i = 1; i < Reducer::kInputCount; ++i) { - auto& aux_in = Input(i); - ctx.observeInput(i, aux_in, num_reduce_dims_); - } - - OPERATOR_NEEDS_FEATURE( - inputAccessor_.observeInput(data), - "Unsupported input type: ", - data.meta().name(), - "."); - - vector shape; - ctx.appendOutputShape(&shape); - output->Resize(shape); - - T* out = output->template mutable_data(); - - const int block_size = FirstDim - ? data.size_from_dim(num_reduce_dims_) - : data.size_from_dim(data.ndim() - num_reduce_dims_); - - const int num_blocks = block_size > 0 ? data.size() / block_size : 0; - - Reducer r(ctx, out, &context_); - for (TIndex i = 0; i < num_blocks; ++i) { - r.template process( - ctx, inputAccessor_.getBlockPtr(block_size, i), i, &context_); - } - r.template finish(ctx, &context_); - return true; - } - - static constexpr int kNumInputs = Reducer::kInputCount; - - private: - int num_reduce_dims_; - InputAccessor inputAccessor_; -}; - -template < - typename T, - class Context, - class ReducerGradient, - bool FirstDim = true> -class AbstractReduceFrontOrBackGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - AbstractReduceFrontOrBackGradientOp( - const OperatorDef& operator_def, - Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(int, "num_reduce_dim", num_reduce_dims_, 1) {} - - bool RunOnDevice() override { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex grad_block_size = Input(REDUCTION_GRAD).size(); - return DispatchHelper::call( - this, grad_block_size); - } - - template - bool DoRunWithValue() { - auto& reduction_grad = Input(REDUCTION_GRAD); - auto& source_shape = OperatorBase::Input(SOURCE_SHAPE); - - auto* data_grads = Output(0); - - typename ReducerGradient::Meta ctx(reduction_grad, 0, FirstDim); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - auto& aux_in = Input(i); - ctx.observeOriginalInput( - ReducerGradient::originalInputs()[i], - aux_in, - nullptr, /*no grad*/ - num_reduce_dims_); - } - - const T* r_grad = reduction_grad.template data(); - - CAFFE_ENFORCE_LE(num_reduce_dims_, source_shape.size()); - - vector shape( - source_shape.template data(), - source_shape.template data() + source_shape.size()); - - data_grads->Resize(shape); - - TIndex block_size = FirstDim - ? data_grads->size_from_dim(num_reduce_dims_) - : data_grads->size_from_dim(data_grads->ndim() - num_reduce_dims_); - TIndex block_num = block_size > 0 ? data_grads->size() / block_size : 0; - - T* out = data_grads->template mutable_data(); - - ReducerGradient r(ctx, r_grad, &context_); - for (TIndex i = 0; i < block_num; ++i) { - r.template fillGrad( - ctx, - out + block_size * i, - i, - &context_, - FirstDim ? block_num : block_size); - } - return true; - } - - static constexpr int kNumInputs = - ReducerGradient::originalInputs().size() + 2; - enum _InputTags { - REDUCTION_GRAD = ReducerGradient::originalInputs().size(), - SOURCE_SHAPE - }; - - private: - int num_reduce_dims_; -}; - -template -struct AbstractReduceFrontDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "ReduceFront"; - static constexpr const char* doc = R"DOC( -Reduces the input tensor along the first dimension of the input tensor by -applying '{op}'. This op acts in a similar way to SortedSegment{op} and -UnsortedSegment{op} but as if all input slices belong to a single segment. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input( - 0, "DATA", "Input tensor to be reduced on the first dimension"); - schema.TensorInferenceFunction([](const OperatorDef& def, - const vector& in) { - CAFFE_ENFORCE_EQ(1, in.size()); - ArgumentHelper helper(def); - int num_reduce_dims = helper.GetSingleArgument("num_reduce_dim", 1); - typename ReducerDef::template Reducer::Meta ctx(true); - vector out_dims = ctx.getOutputShape(in[0], num_reduce_dims); - return vector{ - CreateTensorShape(out_dims, in[0].data_type())}; - }); - ReducerDef::PopulateSchema(schema); - } - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractReduceFrontOrBackOp< - T, - Context, - typename ReducerDef::template Reducer, - true>; - using BackwardOp = - AbstractReduceFrontOrBackGradientOp; - struct GetGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - // Have utility function generating these names? - string tmp_dims = "_" + O(0) + "_dims"; - - vector grad_ins; - for (const int i : ReducerGradient::originalInputs()) { - grad_ins.push_back(I(i)); - } - grad_ins.push_back(GO(0)); - grad_ins.push_back(tmp_dims); - - vector args; - if (ArgumentHelper::HasArgument(def_, "num_reduce_dim")) { - args.push_back(GetArgument(def_, "num_reduce_dim")); - } - // FIXME: pass in num_reduce_dims?! - return vector{ - CreateOperatorDef( - "Shape", "", vector{I(0)}, vector{tmp_dims}), - CreateOperatorDef( - string(basename) + ReducerDef::name + "Gradient", - "", - grad_ins, - // no gradient on auxiliary inputs for now - vector{GI(0)}), - }; - } - }; -}; - -template -struct AbstractReduceBackDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "ReduceBack"; - static constexpr const char* doc = R"DOC( -Reduces the input tensor along the last dimension of the input tensor by -applying '{op}'. This op acts in a similar way to SortedSegment{op} and -UnsortedSegment{op} but as if all input slices belong to a single segment. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input( - 0, "DATA", "Input tensor to be reduced on the first dimension"); - schema.TensorInferenceFunction([](const OperatorDef& def, - const vector& in) { - CAFFE_ENFORCE_EQ(1, in.size()); - ArgumentHelper helper(def); - int num_reduce_dims = helper.GetSingleArgument("num_reduce_dim", 1); - typename ReducerDef::template Reducer::Meta ctx(false); - vector out_dims = ctx.getOutputShape(in[0], num_reduce_dims); - return vector{ - CreateTensorShape(out_dims, in[0].data_type())}; - }); - ReducerDef::PopulateSchema(schema); - } - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractReduceFrontOrBackOp< - T, - Context, - typename ReducerDef::template Reducer, - false>; - using BackwardOp = - AbstractReduceFrontOrBackGradientOp; - struct GetGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - // Have utility function generating these names? - string tmp_dims = "_" + O(0) + "_dims"; - - vector grad_ins; - for (const int i : ReducerGradient::originalInputs()) { - grad_ins.push_back(I(i)); - } - grad_ins.push_back(GO(0)); - grad_ins.push_back(tmp_dims); - - vector args; - if (ArgumentHelper::HasArgument(def_, "num_reduce_dim")) { - args.push_back(GetArgument(def_, "num_reduce_dim")); - } - // FIXME: pass in num_reduce_dims?! - return vector{ - CreateOperatorDef( - "Shape", "", vector{I(0)}, vector{tmp_dims}), - CreateOperatorDef( - string(basename) + ReducerDef::name + "Gradient", - "", - grad_ins, - // no gradient on auxiliary inputs for now - vector{GI(0)}), - }; - } - }; -}; - -/** - * @brief Segment reduction op with optional fused embedding lookup - * - * Base implementation for SortedSegmentXXX and SparseSortedSegmentXXX depending - * on SparseFused static argument. - * - * Inputs: - * 0: DATA - input embedding to do lookups in - * 1..P: AUX_ARG_ - optional additional arguments to be passed to the - * reducer, should have the same first dimension as - * SEGMENT_IDS (e.g. scalars in WeightedSum) - * # if SparseFused == true: - * P+1: INDICES - 1-D vector with indices to look up in DATA. Should have the - * same dimension as SEGMENT_IDS - * # P+1 if SparseFused == false: - * P+1 or P+2: SEGMENT_IDS - sorted segment ids 1-D vector - * - * Output: - * Tensor with first dimension of K, where K is the max segment id + 1. Rest - * of dimensions are decided by reducer but usually are the same size as extra - * dimensions of DATA - */ -template < - typename T, - typename SIndex, - class Context, - class Reducer, - bool SparseFused = true, - class InputAccessor = BaseInputAccessor> -class AbstractSortedSegmentOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractSortedSegmentOp); - - bool RunOnDevice() override { - if (SparseFused) { - return DispatchHelper>::call( - this, Input(INDICES)); - } else { - // type doesn't matter - return DoRunWithType(); - } - } - - template - bool DoRunWithType() { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex in_block_size = Input(0).size_from_dim(1); - return DispatchHelper::call( - this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& dataInput = Input(0); - auto& segment_ids = Input(SEGMENT_IDS); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - TIndex N = segment_ids.dim(0); - const TIndex M = dataInput.dim(0); - - const IndexType* idxs; - if (SparseFused) { // static if - auto& indices = Input(INDICES); - CAFFE_ENFORCE_EQ(1, indices.ndim(), "INDICES must be a vector"); - CAFFE_ENFORCE_EQ( - N, - indices.dim(0), - "SEGMENT_IDS must have the same length as INDICES"); - idxs = indices.template data(); - } else { - CAFFE_ENFORCE_EQ( - N, M, "DATA must have the same first dimension as SEGMENT_IDS"); - } - - // It would probably look nicer with varargs templates but it's too much - // metaprogramming - typename Reducer::Meta ctx; - ctx.observeInput(0, dataInput, 1); - for (int i = 1; i < Reducer::kInputCount; ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE_EQ( - N, - aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeInput(i, aux_in, 1); - } - - OPERATOR_NEEDS_FEATURE( - inputAccessor_.observeInput(dataInput), - "Unsupported input type: ", - dataInput.meta().name(), - "."); - - const SIndex* s_ids = segment_ids.template data(); - - const SIndex K = N > 0 ? s_ids[N - 1] + 1 : 0; - vector shape; - shape.push_back(K); - ctx.appendOutputShape(&shape); - output->Resize(shape); - - T* out = output->template mutable_data(); - if (N == 0) { - return true; - } - TIndex in_block_size = dataInput.size_from_dim(1); - TIndex out_block_size = output->size_from_dim(1); - - // Assume the segments are sorted and there are no gaps - CAFFE_ENFORCE_EQ(0, s_ids[0], "Indices must be sorted and not have gaps"); - for (TIndex i = 0; i < N;) { - TIndex start = i; - - Reducer r(ctx, out + out_block_size * s_ids[start], &context_); - for (; i < N && s_ids[start] == s_ids[i]; ++i) { - IndexType idx; - if (SparseFused) { // static if - CAFFE_ENFORCE( - 0 <= idxs[i] && idxs[i] < M, - "Index out of bounds: ", - idxs[i], - ", range 0 to ", - M); - idx = idxs[i]; - } else { - idx = i; - } - r.template process( - ctx, inputAccessor_.getBlockPtr(in_block_size, idx), i, &context_); - } - - r.template finish(ctx, &context_); - // check correctness of the next segment - if (i < N) { - CAFFE_ENFORCE_EQ( - s_ids[start] + 1, - s_ids[i], - "Indices must be sorted and not have gaps"); - } - } - return true; - } - - enum { - INDICES = Reducer::kInputCount, - SEGMENT_IDS = Reducer::kInputCount + (SparseFused ? 1 : 0) - }; - static constexpr int kSelfInputs = SparseFused ? 2 : 1; - static constexpr int kNumInputs = Reducer::kInputCount + kSelfInputs; - - private: - InputAccessor inputAccessor_; -}; - -// Gradient actually doesn't depend on whether sparse lookup is fused or not -template -class AbstractSortedSegmentGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractSortedSegmentGradientOp); - - bool RunOnDevice() override { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex grad_block_size = Input(SEGMENT_GRADS).size_from_dim(1); - return DispatchHelper::call( - this, grad_block_size); - } - - template - bool DoRunWithValue() { - auto& segment_grads = Input(SEGMENT_GRADS); - auto& segment_ids = Input(SEGMENT_IDS); - auto* data_grads = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - TIndex N = segment_ids.dim(0); - - typename ReducerGradient::Meta ctx(segment_grads, 1); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE_EQ( - N, - aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeOriginalInput( - ReducerGradient::originalInputs()[i], aux_in, nullptr /*no grad*/, 1); - } - - const SIndex* s_ids = segment_ids.template data(); - const T* s_grads = segment_grads.template data(); - - vector shape; - shape.push_back(N); - ctx.appendGradShape(&shape); - data_grads->Resize(shape); - - TIndex d_block_size = data_grads->size_from_dim(1); - const SIndex K = segment_grads.dim(0); - TIndex s_block_size = segment_grads.size_from_dim(1); - T* out = data_grads->template mutable_data(); - - if (N == 0) { - return true; - } - - // Assume the segments are sorted and there are no gaps - CAFFE_ENFORCE_EQ(0, s_ids[0], "Indices must be sorted and not have gaps"); - // repeat the check from forward op - CAFFE_ENFORCE_EQ( - K - 1, s_ids[N - 1], "Indices must be sorted and not have gaps"); - for (TIndex i = 0; i < N;) { - TIndex start = i; - TIndex end = start; - - if (ReducerGradient::computeLength()) { - for (; end < N && s_ids[start] == s_ids[end]; ++end) { - } - } - - ReducerGradient r(ctx, s_grads + s_block_size * s_ids[start], &context_); - for (; i < N && s_ids[start] == s_ids[i]; ++i) { - r.template fillGrad( - ctx, out + d_block_size * i, i, &context_, end - start); - } - - // check correctness of the next segment - if (i < N) { - CAFFE_ENFORCE_EQ( - s_ids[start] + 1, - s_ids[i], - "Indices must be sorted and not have gaps"); - } - } - return true; - } - - // Input layout: - // orig_arg1, orig_arg2, ..., orig_argN, SEGMENT_GRADS, SEGMENT_IDS - // orig_argXs represent original op's inputs and will be passed to the reducer - // directly - static constexpr int kNumInputs = - ReducerGradient::originalInputs().size() + 2; - enum _InputTags { - SEGMENT_GRADS = ReducerGradient::originalInputs().size(), - SEGMENT_IDS - }; -}; - -// base implementation of sorted/unsorted sparse/non-sparse gradient computation -template < - typename ForwardOp, - typename ReducerDef, - typename ReducerGradient, - bool Sorted, - bool SparseFused> -struct SegmentOpGetGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - CAFFE_ENFORCE( - !ReducerGradient::requiresDataInput(Def()), - "grads on aux inputs are not yet implemented for Segment operators."); - vector grad_ins; - for (const int i : ReducerGradient::originalInputs()) { - grad_ins.push_back(I(i)); - } - grad_ins.push_back(GO(0)); - grad_ins.push_back(I(ForwardOp::SEGMENT_IDS)); - vector r{CreateOperatorDef( - string(Sorted ? "SortedSegment" : "UnsortedSegment") + - ReducerDef::name + "Gradient", - "", - grad_ins, - // no gradient on segment_ids or auxiliary inputs for now - vector{SparseFused ? GI_V(0) : GI(0)})}; - if (SparseFused) { - SetSparse(0, I(ForwardOp::INDICES), GI_V(0)); - } - return r; - } -}; - -template -struct AbstractSortedSegmentDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "SortedSegment"; - static constexpr const char* doc = R"DOC( -Applies '{op}' to each segment of input tensor. Segments need to be sorted and -contiguous. See also UnsortedSegment{op} that doesn't have this requirement. - -SEGMENT_IDS is a vector that maps each of the first dimension slices of the -DATA to a particular group (segment). Values belonging to the same segment are -aggregated together. - -The first dimension of the output is equal to the number of input segments, -i.e. `SEGMENT_IDS[-1]+1`. Other dimensions are inherited from the input tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "SEGMENT_IDS", - "Vector with the same length as the first dimension of DATA " - "and values in the range 0..K-1 and in increasing order that " - "maps each slice of DATA to one of the segments"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of K " - "(the number of segments)."); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractSortedSegmentOp; - using BackwardOp = - AbstractSortedSegmentGradientOp; - using GetGradient = SegmentOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - true /*Sorted*/, - false /*SparseFused*/>; -}; - -template -struct AbstractSparseSortedSegmentDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "SparseSortedSegment"; - static constexpr const char* doc = R"DOC( -Pulls in slices of the input tensor, groups them into segments and applies -'{op}' to each segment. Segments need to be sorted and contiguous. See also -SparseUnsortedSegment{op} that doesn't have this requirement. - -This op is basically Gather and SortedSegment{op} fused together. - -INDICES should contain integers in range 0..N-1 where N is the first dimension -of DATA. INDICES represent which slices of DATA need to be pulled in. - -SEGMENT_IDS is a vector that maps each referenced slice of the DATA to a -particular group (segment). Values belonging to the same segment are aggregated -together. SEGMENT_IDS should have the same dimension as INDICES. - -The first dimension of the output is equal to the number of input segments, -i.e. `SEGMENT_IDS[-1]+1`. Other dimensions are inherited from the input tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "INDICES", - "Integer vector containing indices of the first dimension of DATA for " - "the slices that are being aggregated"); - schema.Input( - Reducer::kInputCount + 1, - "SEGMENT_IDS", - "Vector with the same length as INDICES and values in the range " - "0..K-1 and in increasing order that maps each slice of DATA referenced" - " by INDICES to one of the segments"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of K " - "(the number of segments)."); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractSortedSegmentOp; - // TODO(dzhulgakov): we're registering the same class twice here, - // consider avoiding op duplication here - using BackwardOp = - AbstractSortedSegmentGradientOp; - using GetGradient = SegmentOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - true /*Sorted*/, - true /*SparseFused*/>; -}; - -/** - * @brief Unsorted segment reduction op with optional fused embedding lookup - * - * Base implementation for UnsortedSegmentXXX and UnsparseSortedSegmentXXX - * depending on SparseFused static argument. - * - * Unlike the sorted version it allows to have "gaps" in segment ids. - * - * Inputs: - * 0: DATA - input embedding to do lookups in - * 1..P: AUX_ARG_ - optional additional arguments to be passed to the - * reducer, should have the same first dimension as - * SEGMENT_IDS (e.g. scalars in WeightedSum) - * # if SparseFused == true: - * P+1: INDICES - 1-D vector with indices to look up in DATA. Should have the - * same dimension as SEGMENT_IDS - * # P+1 if SparseFused == false: - * P+1 or P+2: SEGMENT_IDS - unsorted segment ids 1-D vector - * - * Args: - * num_segments - allows to override the dimension of the output. If not set - * it would be inferred from segment_ids tensor. - * - * - * Output: - * Tensor with first dimension of K, where K is the max segment id + 1. Rest - * of dimensions are decided by reducer but usually are the same size as extra - * dimensions of DATA - */ -template < - typename T, - typename SIndex, - class Context, - class Reducer, - bool SparseFused = true, - class InputAccessor = BaseInputAccessor> -class AbstractUnsortedSegmentOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - AbstractUnsortedSegmentOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - OP_SINGLE_ARG(int, "num_segments", num_segments_, -1) {} - - bool RunOnDevice() override { - if (SparseFused) { - return DispatchHelper>::call( - this, Input(INDICES)); - } else { - // type doesn't matter - return DoRunWithType(); - } - } - - template - bool DoRunWithType() { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex in_block_size = Input(0).size_from_dim(1); - return DispatchHelper::call( - this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& data = Input(0); - auto& segment_ids = Input(SEGMENT_IDS); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - TIndex N = segment_ids.dim(0); - const TIndex M = data.dim(0); - - const IndexType* idxs; - if (SparseFused) { // static if - auto& indices = Input(INDICES); - CAFFE_ENFORCE_EQ(1, indices.ndim(), "INDICES must be a vector"); - CAFFE_ENFORCE_EQ( - N, - indices.dim(0), - "SEGMENT_IDS must have the same length as INDICES"); - idxs = indices.template data(); - } else { - CAFFE_ENFORCE_EQ( - N, M, "DATA must have the same first dimension as SEGMENT_IDS"); - } - - // It would probably look nicer with varargs templates but it's too much - // metaprogramming - typename Reducer::Meta ctx; - ctx.observeInput(0, data, 1); - for (int i = 1; i < Reducer::kInputCount; ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE_EQ( - N, - aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeInput(i, aux_in, 1); - } - - const SIndex* s_ids = segment_ids.template data(); - OPERATOR_NEEDS_FEATURE( - inputAccessor_.observeInput(data), - "Unsupported input type: ", - data.meta().name(), - "."); - - // determine the number of segments - SIndex K; - if (num_segments_ != -1) { - K = num_segments_; - } else { - K = 0; - for (TIndex i = 0; i < N; ++i) { - K = std::max(K, s_ids[i] + 1); - } - } - - vector shape; - shape.push_back(K); - ctx.appendOutputShape(&shape); - output->Resize(shape); - - TIndex in_block_size = data.size_from_dim(1); - TIndex out_block_size = output->size_from_dim(1); - T* out = output->template mutable_data(); - - reducers_.clear(); - reducers_.reserve(K); - for (TIndex i = 0; i < K; ++i) { - reducers_.emplace_back(ctx, out + out_block_size * i, &context_); - } - - for (TIndex i = 0; i < N; ++i) { - auto s_id = s_ids[i]; - CAFFE_ENFORCE( - 0 <= s_id && s_id < K, - "Segment id out of range: ", - s_id, - ", range 0 to ", - K); - IndexType idx; - if (SparseFused) { // static if - CAFFE_ENFORCE( - 0 <= idxs[i] && idxs[i] < M, - "Index out of bounds: ", - idxs[i], - ", range 0 to ", - M); - idx = idxs[i]; - } else { - idx = i; - } - reducers_[s_id].template process( - ctx, inputAccessor_.getBlockPtr(in_block_size, idx), i, &context_); - } - - for (TIndex i = 0; i < K; ++i) { - reducers_[i].template finish(ctx, &context_); - } - // call reducers destructors (if there is any) - reducers_.clear(); - return true; - } - - enum { - INDICES = Reducer::kInputCount, - SEGMENT_IDS = Reducer::kInputCount + (SparseFused ? 1 : 0) - }; - static constexpr int kSelfInputs = SparseFused ? 2 : 1; - static constexpr int kNumInputs = Reducer::kInputCount + kSelfInputs; - - private: - TIndex num_segments_; - // member field to reuse memory - vector reducers_; - InputAccessor inputAccessor_; -}; - -// Gradient actually doesn't depend on whether sparse lookup is fused or not -template -class AbstractUnsortedSegmentGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractUnsortedSegmentGradientOp); - - bool RunOnDevice() override { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex grad_block_size = Input(SEGMENT_GRADS).size_from_dim(1); - return DispatchHelper::call( - this, grad_block_size); - } - - template - bool DoRunWithValue() { - auto& segment_grads = Input(SEGMENT_GRADS); - auto& segment_ids = Input(SEGMENT_IDS); - auto* data_grads = Output(0); - - CAFFE_ENFORCE_EQ(1, segment_ids.ndim(), "SEGMENT_IDS must be a vector"); - TIndex N = segment_ids.dim(0); - - typename ReducerGradient::Meta ctx(segment_grads, 1); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE_EQ( - N, - aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeOriginalInput( - ReducerGradient::originalInputs()[i], aux_in, nullptr /*no grad*/, 1); - } - - const SIndex* s_ids = segment_ids.template data(); - const T* s_grads = segment_grads.template data(); - - vector shape; - shape.push_back(N); - ctx.appendGradShape(&shape); - data_grads->Resize(shape); - - TIndex d_block_size = data_grads->size_from_dim(1); - const SIndex K = segment_grads.dim(0); - TIndex s_block_size = segment_grads.size_from_dim(1); - T* out = data_grads->template mutable_data(); - - if (ReducerGradient::computeLength()) { - segment_length_.resize(K, 0); - for (int i = 0; i < N; ++i) { - auto s_id = s_ids[i]; - CAFFE_ENFORCE( - 0 <= s_id && s_id < K, - "Segment id out of range: ", - s_id, - ", range 0 to ", - K); - segment_length_[s_ids[i]]++; - } - } - - reducers_.clear(); - reducers_.reserve(K); - for (SIndex i = 0; i < K; ++i) { - reducers_.emplace_back(ctx, s_grads + s_block_size * i, &context_); - } - - for (TIndex i = 0; i < N; ++i) { - auto s_id = s_ids[i]; - if (ReducerGradient::computeLength()) { - reducers_[s_id].template fillGrad( - ctx, out + d_block_size * i, i, &context_, segment_length_[s_id]); - } else { - reducers_[s_id].template fillGrad( - ctx, out + d_block_size * i, i, &context_, 0); - } - } - // call reducers destructors (if there is any) - reducers_.clear(); - return true; - } - - // Input layout: - // orig_arg1, orig_arg2, ..., orig_argN, SEGMENT_GRADS, SEGMENT_IDS - // orig_argXs represent original op's inputs and will be passed to the reducer - // directly - static constexpr int kNumInputs = - ReducerGradient::originalInputs().size() + 2; - enum _InputTags { - SEGMENT_GRADS = ReducerGradient::originalInputs().size(), - SEGMENT_IDS - }; - - private: - // member field to reuse memory - vector reducers_; - vector segment_length_; -}; - -template -struct AbstractUnsortedSegmentDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "UnsortedSegment"; - static constexpr const char* doc = R"DOC( -Applies '{op}' to each segment of input tensor. Segments ids can appear in -arbitrary order (unlike in SortedSegment{op}). - -SEGMENT_IDS is a vector that maps each of the first dimension slices of the -DATA to a particular group (segment). Values belonging to the same segment are -aggregated together. - -If `num_segments` argument is passed it would be used as a first dimension for -the output. Otherwise, it'd be dynamically calculated from as the max value of -SEGMENT_IDS plus one. Other output dimensions are inherited from the input -tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Arg( - "num_segments", - "Optional int argument specifying the number of output segments and " - "thus the first dimension of the output"); - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "SEGMENT_IDS", - "Integer vector with the same length as the first dimension of DATA " - "that maps each slice of DATA to one of the segments"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of equal to the " - "number of segments."); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractUnsortedSegmentOp< - T, - SIndex, - Context, - typename ReducerDef::template Reducer, - false>; - using BackwardOp = - AbstractUnsortedSegmentGradientOp; - using GetGradient = SegmentOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - false /*Sorted*/, - false /*SparseFused*/>; -}; - -template -struct AbstractSparseUnsortedSegmentDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "SparseUnsortedSegment"; - static constexpr const char* doc = R"DOC( -Pulls in slices of the input tensor, groups them into segments and applies -'{op}' to each segment. Segments ids can appear in arbitrary order (unlike in -SparseSortedSegment{op}). - -This op is basically Gather and UnsortedSegment{op} fused together. - -INDICES should contain integers in range 0..N-1 where N is the first dimension -of DATA. INDICES represent which slices of DATA need to be pulled in. - -SEGMENT_IDS is a vector that maps each referenced slice of the DATA to a -particular group (segment). Values belonging to the same segment are aggregated -together. SEGMENT_IDS should have the same dimension as INDICES. - -If `num_segments` argument is passed it would be used as a first dimension for -the output. Otherwise, it'd be dynamically calculated from as the max value of -SEGMENT_IDS plus one. Other output dimensions are inherited from the input -tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "INDICES", - "Integer vector containing indices of the first dimension of DATA for " - "the slices that are being aggregated"); - schema.Input( - Reducer::kInputCount + 1, - "SEGMENT_IDS", - "Integer vector with the same length as INDICES that maps each slice " - "of DATA referenced by INDICES to one of the segments"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of equal to the " - "number of segments."); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractUnsortedSegmentOp; - // TODO(dzhulgakov): we're registering the same class twice here, - // consider avoiding op duplication here - using BackwardOp = - AbstractUnsortedSegmentGradientOp; - using GetGradient = SegmentOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - false /*Sorted*/, - true /*SparseFused*/>; -}; - -/** - * @brief Segment reduction op with optional fused embedding lookup - * - * Base implementation for LengthsXXX and SparseLengthsXXX depending - * on SparseFused static argument. - * - * Inputs: - * 0: DATA - input embedding to do lookups in - * 1..P: AUX_ARG_ - optional additional arguments to be passed to the - * reducer, should have the same first dimension as - * LENGTHS (e.g. scalars in WeightedSum) - * # if SparseFused == true: - * P+1: INDICES - 1-D vector with indices to look up in DATA. Should have the - * same dimension as LENGTHS - * # P+1 if SparseFused == false: - * P+1 or P+2: LENGTHS - lengths on indecies vector - * - * Output: - * Tensor with first dimension of K, where K = len(LENGTHS). Rest - * of dimensions are decided by reducer but usually are the same size as extra - * dimensions of DATA - */ -// TODO(dzhulgakov): for now it's implemented with incremental reducers because -// of fused sparse support. But using "lengths" representation actually implies -// continuous segments and thus range reducers can be used for non-sparse -// version. - -template < - typename TData, - typename TLengths, - class Context, - class Reducer, - bool SparseFused = true, - class InputAccessor = BaseInputAccessor> -class AbstractLengthsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractLengthsOp); - - bool RunOnDevice() override { - if (SparseFused) { - return DispatchHelper>::call( - this, Input(INDICES)); - } else { - // type doesn't matter - return DoRunWithType(); - } - } - - template - bool DoRunWithType() { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex in_block_size = Input(0).size_from_dim(1); - return DispatchHelper::call( - this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& dataInput = Input(0); - auto& lengthsInput = Input(LENGTHS); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(1, lengthsInput.ndim(), "LENGTHS must be a vector"); - const TIndex dataSize = dataInput.dim(0); - // Either first dim the data or how much we pull in indexies from it - TIndex dataToReduceSize; - const TIndex outputSize = lengthsInput.dim(0); - - const IndexType* indices; - if (SparseFused) { // static if - auto& indicesInput = Input(INDICES); - CAFFE_ENFORCE_EQ(1, indicesInput.ndim(), "INDICES must be a vector"); - indices = indicesInput.template data(); - dataToReduceSize = indicesInput.dim(0); - } else { - dataToReduceSize = dataSize; - } - - typename Reducer::Meta ctx; - ctx.observeInput(0, dataInput, 1); - for (int i = 1; i < Reducer::kInputCount; ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE( - dataToReduceSize == aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeInput(i, aux_in, 1); - } - - const TLengths* lengths = lengthsInput.template data(); - - OPERATOR_NEEDS_FEATURE( - inputAccessor_.observeInput(dataInput), - "Unsupported input type: ", - dataInput.meta().name(), - "."); - - vector shape{outputSize}; - ctx.appendOutputShape(&shape); - output->Resize(shape); - - TIndex in_block_size = dataInput.size_from_dim(1); - TIndex out_block_size = output->size_from_dim(1); - TData* out = output->template mutable_data(); - - TIndex dataIndex = 0; - for (TIndex rangeIndex = 0; rangeIndex < outputSize; ++rangeIndex) { - Reducer reducer(ctx, out + out_block_size * rangeIndex, &context_); - for (TIndex start = dataIndex; dataIndex < start + lengths[rangeIndex]; - ++dataIndex) { - IndexType idx; - if (SparseFused) { // static if - idx = indices[dataIndex]; - CAFFE_ENFORCE( - 0 <= idx && idx < dataSize, - "Index ", - dataIndex, - " is out of bounds: ", - idx, - ", range 0 to ", - dataSize); - } else { - idx = dataIndex; - CAFFE_ENFORCE( - idx < dataSize, - "Range ", - rangeIndex, - " of length ", - lengths[rangeIndex], - " is out of bound ", - dataSize); - } - - const TData* input = inputAccessor_.getBlockPtr(in_block_size, idx); - reducer.template process(ctx, input, dataIndex, &context_); - } - reducer.template finish(ctx, &context_); - } - CAFFE_ENFORCE( - dataIndex == dataToReduceSize, dataIndex, " != ", dataToReduceSize); - - return true; - } - - enum { - INDICES = Reducer::kInputCount, - LENGTHS = Reducer::kInputCount + (SparseFused ? 1 : 0) - }; - static constexpr int kSelfInputs = SparseFused ? 2 : 1; - static constexpr int kNumInputs = Reducer::kInputCount + kSelfInputs; - - private: - InputAccessor inputAccessor_; -}; - -/* - * Some notice: - * 1. Gradient actually doesn't depend on whether sparse lookup is fused or not - * 2. INDICES are not used in CPU version, but they are needed in async CUDA - * version. So we register 3 input version for CPU as gradient op for - * GPU/CPU convert. We then register 2 input version for CPU for backward - * compatibility with older nets. - */ -template < - typename T, - typename TLengths, - class Context, - class ReducerGradient, - bool GradientNeedIndices = false> -class AbstractLengthsGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractLengthsGradientOp); - - bool RunOnDevice() override { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex gradBlockSize = Input(SEGMENT_GRADS).size_from_dim(1); - return DispatchHelper::call( - this, gradBlockSize); - } - - template - bool DoRunWithValue() { - auto& segmentGradsInput = Input(SEGMENT_GRADS); - auto& lengthsInput = Input(LENGTHS); - auto* dataGradsOutput = Output(0); - - CAFFE_ENFORCE(lengthsInput.ndim() == 1, "LENGTHS must be a vector"); - TIndex reducedDataSize = 0; - TIndex numSegments = lengthsInput.dim(0); - CAFFE_ENFORCE(segmentGradsInput.ndim() > 0); - CAFFE_ENFORCE(numSegments == segmentGradsInput.dim(0)); - const TLengths* lengths = lengthsInput.template data(); - for (TIndex i = 0; i < numSegments; ++i) { - reducedDataSize += lengths[i]; - } - - typename ReducerGradient::Meta ctx(segmentGradsInput, 1); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - auto& aux_in = Input(i); - CAFFE_ENFORCE_EQ( - reducedDataSize, - aux_in.dim(0), - "Input ", - i, - " must have the same first dim as SEGMENT_IDS"); - ctx.observeOriginalInput( - ReducerGradient::originalInputs()[i], aux_in, nullptr /*no grad*/, 1); - } - - const T* segmentGrads = segmentGradsInput.template data(); - - vector shape; - shape.push_back(reducedDataSize); - ctx.appendGradShape(&shape); - dataGradsOutput->Resize(shape); - - TIndex dataGradsBlockSize = dataGradsOutput->size_from_dim(1); - TIndex segmentBlockSize = segmentGradsInput.size_from_dim(1); - T* dataGrads = dataGradsOutput->template mutable_data(); - - TIndex dataIndex = 0; - for (TIndex rangeIndex = 0; rangeIndex < numSegments; ++rangeIndex) { - ReducerGradient reducer( - ctx, segmentGrads + segmentBlockSize * rangeIndex, &context_); - for (TIndex start = dataIndex; dataIndex < start + lengths[rangeIndex]; - ++dataIndex) { - reducer.template fillGrad( - ctx, - dataGrads + dataGradsBlockSize * dataIndex, - dataIndex, - &context_, - lengths[rangeIndex]); - } - } - CAFFE_ENFORCE( - dataIndex == reducedDataSize, dataIndex, " != ", reducedDataSize); - return true; - } - - // Input layout: - // orig_arg1, orig_arg2, ..., orig_argN, SEGMENT_GRADS, SEGMENT_IDS - // orig_argXs represent original op's inputs and will be passed to the reducer - // directly - static constexpr int kNumInputs = ReducerGradient::originalInputs().size() + - 2 + (GradientNeedIndices ? 1 : 0); - enum _InputTags { - SEGMENT_GRADS = ReducerGradient::originalInputs().size(), - LENGTHS, - INDICES - }; -}; - -// Version of gradient that requires the main input and thus needs to receive -// length, indices and other stuff -template < - typename T, - typename TLengths, - class Context, - class ReducerGradient, - bool SparseFused = true, - bool GradientNeedIndices = false> -class AbstractLengthsWithMainInputGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractLengthsWithMainInputGradientOp); - - bool RunOnDevice() override { - if (SparseFused) { - return DispatchHelper>::call( - this, Input(INDICES)); - } else { - // type doesn't matter - return DoRunWithType(); - } - } - - template - bool DoRunWithType() { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class - TIndex in_block_size = Input(SEGMENT_GRADS).size_from_dim(1); - return DispatchHelper:: - call(this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& dataInput = Input(DATA_INPUT); - auto& segmentGradsInput = Input(SEGMENT_GRADS); - auto& lengthsInput = Input(LENGTHS); - auto* dataGradsOutput = Output(0); - - CAFFE_ENFORCE(lengthsInput.ndim() == 1, "LENGTHS must be a vector"); - TIndex numSegments = lengthsInput.dim(0); - CAFFE_ENFORCE(segmentGradsInput.ndim() > 0); - CAFFE_ENFORCE(numSegments == segmentGradsInput.dim(0)); - const TLengths* lengths = lengthsInput.template data(); - - typename ReducerGradient::Meta ctx(segmentGradsInput, 1); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - int aux_num = ReducerGradient::originalInputs()[i]; - auto& aux_in = Input(i); - auto* aux_grad = aux_num < OutputSize() ? Output(aux_num) : nullptr; - ctx.observeOriginalInput(aux_num, aux_in, aux_grad, 1); - } - - // Either first dim the data or how much we pull in indexies from it - TIndex dataToReduceSize; - const IndexType* indices = nullptr; - if (SparseFused) { // static if - auto& indicesInput = Input(INDICES); - indices = indicesInput.template data(); - dataToReduceSize = indicesInput.dim(0); - } else { - dataToReduceSize = dataInput.dim(0); - } - - const T* segmentGrads = segmentGradsInput.template data(); - - vector shape; - shape.push_back(dataToReduceSize); - ctx.appendGradShape(&shape); - dataGradsOutput->Resize(shape); - - TIndex dataGradsBlockSize = dataGradsOutput->size_from_dim(1); - TIndex segmentBlockSize = segmentGradsInput.size_from_dim(1); - T* dataGrads = dataGradsOutput->template mutable_data(); - - const T* data = dataInput.template data(); - - TIndex dataIndex = 0; - for (TIndex rangeIndex = 0; rangeIndex < numSegments; ++rangeIndex) { - ReducerGradient reducer( - ctx, segmentGrads + segmentBlockSize * rangeIndex, &context_); - for (TIndex start = dataIndex; dataIndex < start + lengths[rangeIndex]; - ++dataIndex) { - IndexType data_pos; - // No range checking, should've been verified in forward pass - if (SparseFused) { // static if - data_pos = indices[dataIndex]; - } else { - data_pos = dataIndex; - } - reducer.template fillGradWithMainInput( - ctx, - data + dataGradsBlockSize * data_pos, - dataGrads + dataGradsBlockSize * dataIndex, - dataIndex, - &context_, - lengths[rangeIndex]); - } - } - return true; - } - - // Input layout: - // orig_arg1, orig_arg2, ..., orig_argN, DATA_INPUT, SEGMENT_GRADS, - // SEGMENT_LEGNTHS, [INDICES] - // orig_argXs represent original op's inputs and will be passed to the reducer - // directly - static constexpr int kNumInputs = ReducerGradient::originalInputs().size() + - 3 + (SparseFused ? 1 : 0) + (GradientNeedIndices ? 1 : 0); - enum _InputTags { - SEGMENT_GRADS = ReducerGradient::originalInputs().size(), - LENGTHS, - DATA_INPUT, - INDICES, - }; -}; - -// Version of gradient that requires the main input as well as the output of the -// forward op. -template -class AbstractLengthsWithMainInputAndForwardOutputGradientOp - : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AbstractLengthsWithMainInputAndForwardOutputGradientOp); - - bool RunOnDevice() override { - // If more complicated fixed size logic becomes necessary, it can be moved - // to the reducer class. - TIndex in_block_size = Input(SEGMENT_GRADS).size_from_dim(1); - return DispatchHelper::call( - this, in_block_size); - } - - template - bool DoRunWithValue() { - auto& dataInput = Input(DATA_INPUT); - auto& segmentGradsInput = Input(SEGMENT_GRADS); - auto& lengthsInput = Input(LENGTHS); - auto& forwardOutputInput = Input(FORWARD_OUTPUT); - auto* dataGradsOutput = Output(0); - - CAFFE_ENFORCE(lengthsInput.ndim() == 1, "LENGTHS must be a vector"); - TIndex numSegments = lengthsInput.dim(0); - CAFFE_ENFORCE(segmentGradsInput.ndim() > 0); - CAFFE_ENFORCE(numSegments == segmentGradsInput.dim(0)); - const TLengths* lengths = lengthsInput.template data(); - - typename ReducerGradient::Meta ctx(segmentGradsInput, 1); - for (int i = 0; i < ReducerGradient::originalInputs().size(); ++i) { - int aux_num = ReducerGradient::originalInputs()[i]; - auto& aux_in = Input(i); - auto* aux_grad = aux_num < OutputSize() ? Output(aux_num) : nullptr; - ctx.observeOriginalInput(aux_num, aux_in, aux_grad, 1); - } - - CAFFE_ENFORCE(forwardOutputInput.ndim() > 0); - CAFFE_ENFORCE(numSegments == forwardOutputInput.dim(0)); - const T* forwardOutput = forwardOutputInput.template data(); - - TIndex dataToReduceSize = dataInput.dim(0); - - const T* segmentGrads = segmentGradsInput.template data(); - - vector shape; - shape.push_back(dataToReduceSize); - ctx.appendGradShape(&shape); - dataGradsOutput->Resize(shape); - - TIndex dataGradsBlockSize = dataGradsOutput->size_from_dim(1); - TIndex segmentBlockSize = segmentGradsInput.size_from_dim(1); - T* dataGrads = dataGradsOutput->template mutable_data(); - - const T* data = dataInput.template data(); - - TIndex dataIndex = 0; - for (TIndex rangeIndex = 0; rangeIndex < numSegments; ++rangeIndex) { - ReducerGradient reducer( - ctx, segmentGrads + segmentBlockSize * rangeIndex, &context_); - for (TIndex start = dataIndex; dataIndex < start + lengths[rangeIndex]; - ++dataIndex) { - // No range checking, should've been verified in forward pass - reducer.template fillGradWithMainInputAndForwardOutput( - ctx, - data + dataGradsBlockSize * dataIndex, - dataGrads + dataGradsBlockSize * dataIndex, - forwardOutput + segmentBlockSize * rangeIndex, - dataIndex, - &context_, - lengths[rangeIndex]); - } - } - return true; - } - - // Input layout: - // orig_arg1, orig_arg2, ..., orig_argN, FORWARD_OUTPUT, DATA_INPUT, - // SEGMENT_GRADS, SEGMENT_LEGNTHS - // orig_argXs represent original op's inputs and will be passed to the reducer - // directly - static constexpr int kNumInputs = - ReducerGradient::originalInputs().size() + 4; - enum _InputTags { - FORWARD_OUTPUT = ReducerGradient::originalInputs().size(), - SEGMENT_GRADS, - LENGTHS, - DATA_INPUT, - }; -}; - -// base implementation of sparse/non-sparse gradient computation -template < - typename ForwardOp, - typename ReducerDef, - typename ReducerGradient, - bool SparseFused, - bool GradientNeedIndices = false> -struct LengthsOpGetGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - vector GetGradientDefs() override { - vector grad_ins; - string suffix = "Gradient"; - for (const int i : ReducerGradient::originalInputs()) { - grad_ins.push_back(I(i)); - } - if (ReducerGradient::requiresForwardOutput()) { - grad_ins.push_back(O(0)); - CAFFE_ENFORCE( - !SparseFused, - "Forward pass output not yet supported as input for backward pass " - "for SparseLengthsXXX operators"); - suffix = "AndForwardOutput" + suffix; - } - grad_ins.push_back(GO(0)); - grad_ins.push_back(I(ForwardOp::LENGTHS)); - bool indices_pushed = false; - if (ReducerGradient::requiresDataInput(Def())) { - grad_ins.push_back(I(0)); - if (SparseFused) { - grad_ins.push_back(I(ForwardOp::INDICES)); - indices_pushed = true; - } - suffix = "WithMainInput" + suffix; - } - if (GradientNeedIndices && !indices_pushed) { - if (SparseFused) { - grad_ins.push_back(I(ForwardOp::INDICES)); - } else { - // Hacky: using Input as Indices, remove this after we have specialized - // cuda LengthsIndicesInGradientSumGradient - grad_ins.push_back(I(0)); - } - } - vector grad_outs; - grad_outs.push_back({SparseFused ? GI_V(0) : GI(0)}); - int aux_grads = ReducerGradient::numAuxInputsWithGrads(Def()); - for (int i = 1; i <= aux_grads; ++i) { - grad_outs.push_back(GI(i)); - } - vector r{CreateOperatorDef( - string(SparseFused ? "SparseLengths" : "Lengths") + - string(GradientNeedIndices ? "IndicesInGradient" : "") + - ReducerDef::name + suffix, - "", - grad_ins, - grad_outs)}; - if (SparseFused) { - SetSparse(0, I(ForwardOp::INDICES), GI_V(0)); - } - return r; - } -}; - -template < - typename T, - typename SIndex, - typename Context, - typename ReducerDef, - bool GradientNeedIndices = false> -struct AbstractLengthsDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "Lengths"; - static constexpr const char* doc = R"DOC( -Applies '{op}' to each segment of the input tensor. Segments are defined -by their LENGTHS. - -LENGTHS is a vector that maps each of the first dimension slices of the -DATA to a particular group (segment). Values belonging to the same segment are -aggregated together. - -For example LENGTHS = [2, 1] stands for segments DATA[0..1] and DATA[2] - -The first dimension of the output is equal to the number of input segments, -i.e. `len(LENGTHS)`. Other dimensions are inherited from the input tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "LENGTHS", - "Vector with the same sum of elements as the first dimension of DATA"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of len(LENGTHS) "); - schema.TensorInferenceFunction( - [](const OperatorDef& def, const vector& in) { - vector out(0); - TensorShape output; - for (int d : in[Reducer::kInputCount].dims()) { - output.add_dims(d); - } - for (int j = 1; j < in[0].dims_size(); j++) { - output.add_dims(in[0].dims(j)); - } - output.set_data_type(in[0].data_type()); - out.push_back(output); - return out; - }); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractLengthsOp; - using BackwardOp = - AbstractLengthsGradientOp; - using WithMainInputBackwardOp = AbstractLengthsWithMainInputGradientOp< - T, - SIndex, - Context, - ReducerGradient, - false>; - using WithMainInputAndForwardOutputBackwardOp = - AbstractLengthsWithMainInputAndForwardOutputGradientOp< - T, - SIndex, - Context, - ReducerGradient>; - using GetGradient = LengthsOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - false /*SparseFused*/, - GradientNeedIndices>; -}; - -template < - typename T, - typename SIndex, - typename Context, - typename ReducerDef, - bool GradientNeedIndices = false> -struct AbstractSparseLengthsDef { - using OpDef = ReducerDef; - static constexpr const char* basename = "SparseLengths"; - static constexpr const char* doc = R"DOC( -Pulls in slices of the input tensor, groups them into segments and applies -'{op}' to each segment. Segments are defined by their LENGTHS. - -This op is basically Gather and Lengths{op} fused together. - -INDICES should contain integers in range 0..N-1 where N is the first dimension -of DATA. INDICES represent which slices of DATA need to be pulled in. - -LENGTHS is a vector that defines slice sizes by first dimention of DATA. Values -belonging to the same segment are aggregated together. sum(LENGTHS) has -to match INDICES size. - -The first dimension of the output is equal to the number of input segment, -i.e. `len(LENGTHS)`. Other dimensions are inherited from the input tensor. - -{op_doc} - )DOC"; - static void PopulateSchema(OpSchema& schema) { - schema.Input(0, "DATA", "Input tensor, slices of which are aggregated."); - schema.Input( - Reducer::kInputCount, - "INDICES", - "Integer vector containing indices of the first dimension of DATA for " - "the slices that are being aggregated"); - schema.Input( - Reducer::kInputCount + 1, - "LENGTHS", - "Non negative vector with sum of elements equal to INDICES length"); - schema.Output( - 0, - "OUTPUT", - "Aggregated output tensor. Has the first dimension of K " - "(the number of segments)."); - ReducerDef::PopulateSchema(schema); - } - using Reducer = typename ReducerDef::template Reducer; - using ReducerGradient = - typename ReducerDef::template ReducerGradient; - using ForwardOp = AbstractLengthsOp; - // TODO(dzhulgakov): we're registering the same class twice here, - // consider avoiding op duplication here - // Note: registering 2 input version for now because of naming in the macro, - // will register 3 input version alone - /* INDICES are not used in CPU version, but they are needed in async CUDA - * version. So we register 3 input version for CPU as gradient op for - * GPU/CPU convert. We then register 2 input version for CPU for backward - * compatibility with older nets. - */ - using BackwardOp = AbstractLengthsGradientOp< - T, - SIndex, - Context, - ReducerGradient, - false /*GradientNeedIndices*/>; - using WithMainInputBackwardOp = AbstractLengthsWithMainInputGradientOp< - T, - SIndex, - Context, - ReducerGradient>; - // Will return 3 input version. This is aliging new CPU/GPU nets. - using GetGradient = LengthsOpGetGradient< - ForwardOp, - ReducerDef, - ReducerGradient, - true /*SparseFused*/, - GradientNeedIndices>; -}; -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SEGMENT_REDUCTION_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/sequence_ops.h b/app/src/main/cpp/caffe2/operators/sequence_ops.h deleted file mode 100644 index 95fbfbb..0000000 --- a/app/src/main/cpp/caffe2/operators/sequence_ops.h +++ /dev/null @@ -1,129 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SEQUENCE_OPS_H_ -#define CAFFE2_OPERATORS_SEQUENCE_OPS_H_ - -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -template -class GatherPaddingOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - GatherPaddingOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - startPaddingWidth_( - OperatorBase::GetSingleArgument("padding_width", 1)), - endPaddingWidth_( - OperatorBase::GetSingleArgument("end_padding_width", -1)) { - CAFFE_ENFORCE_GE(startPaddingWidth_, 0); - if (endPaddingWidth_ < 0) { - endPaddingWidth_ = startPaddingWidth_; - } - } - - bool RunOnDevice() override { - if (startPaddingWidth_ == 0 && endPaddingWidth_ == 0) { - Output(0)->Resize(std::vector(0)); - if (OutputSize() == 2) { - Output(1)->Resize(std::vector(0)); - } - return true; - } - return DispatchHelper>::call( - this, Input(0)); - } - - template - bool DoRunWithType(); - - private: - int startPaddingWidth_; - int endPaddingWidth_; -}; - -template -class RemovePaddingOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RemovePaddingOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - startPaddingWidth_( - OperatorBase::GetSingleArgument("padding_width", 1)), - endPaddingWidth_( - OperatorBase::GetSingleArgument("end_padding_width", -1)) { - CAFFE_ENFORCE_GE(startPaddingWidth_, 0); - if (endPaddingWidth_ < 0) { - endPaddingWidth_ = startPaddingWidth_; - } - } - - bool RunOnDevice() override { - if (startPaddingWidth_ == 0 && endPaddingWidth_ == 0) { - Output(0)->CopyFrom(Input(0), &context_); - if (OutputSize() == 2) { - Output(1)->CopyFrom(Input(1), &context_); - } - return true; - } - return DispatchHelper>::call( - this, Input(0)); - } - - template - bool DoRunWithType(); - - private: - int startPaddingWidth_; - int endPaddingWidth_; -}; - -template -class AddPaddingOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - AddPaddingOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - startPaddingWidth_( - OperatorBase::GetSingleArgument("padding_width", 1)), - endPaddingWidth_( - OperatorBase::GetSingleArgument("end_padding_width", -1)) { - CAFFE_ENFORCE_GE(startPaddingWidth_, 0); - if (endPaddingWidth_ < 0) { - endPaddingWidth_ = startPaddingWidth_; - } - } - - bool RunOnDevice() override { - if (startPaddingWidth_ == 0 && endPaddingWidth_ == 0) { - Output(0)->CopyFrom(Input(0), &context_); - if (OutputSize() == 2) { - Output(1)->CopyFrom(Input(1), &context_); - } - return true; - } - return DispatchHelper>::call( - this, Input(0)); - } - - template - bool DoRunWithType(); - - private: - int startPaddingWidth_; - int endPaddingWidth_; -}; - -template -class PadEmptySamplesOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - PadEmptySamplesOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SEQUENCE_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/shape_op.h b/app/src/main/cpp/caffe2/operators/shape_op.h deleted file mode 100644 index a7eb92a..0000000 --- a/app/src/main/cpp/caffe2/operators/shape_op.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// RecordShapeOp records the shape of the input tensor to a vector of int. You -// mostly don't need this operator explicitly, and it is mostly used in the -// autodiff process. -template -class ShapeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ShapeOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = OperatorBase::Output>(0); - output->Resize(input.ndim()); - TIndex* output_data = output->template mutable_data(); - context_.template CopyBytes( - input.ndim() * sizeof(TIndex), input.dims().data(), output_data); - return true; - } -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/sinusoid_position_encoding_op.h b/app/src/main/cpp/caffe2/operators/sinusoid_position_encoding_op.h deleted file mode 100644 index 69c8ea8..0000000 --- a/app/src/main/cpp/caffe2/operators/sinusoid_position_encoding_op.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SINUSOID_POSITION_ENCODING_OP_H_ -#define CAFFE2_OPERATORS_SINUSOID_POSITION_ENCODING_OP_H_ - -#ifdef _MSC_VER -#define _USE_MATH_DEFINES -#endif // _MSC_VER -#include - -#include "caffe2/core/operator.h" - -#include "Eigen/Core" - -namespace caffe2 { - -template -class SinusoidPositionEncodingOp : public Operator { - public: - SinusoidPositionEncodingOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - embedding_size_(OperatorBase::template GetSingleArgument( - "embedding_size", - 100)), - alpha_(OperatorBase::template GetSingleArgument("alpha", 10000)), - amplitude_( - OperatorBase::template GetSingleArgument("amplitude", 1)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(0)); - } - - template - bool DoRunWithType() { - auto& positions = Input(0); - auto* output = Output(0); - - CAFFE_ENFORCE_EQ(positions.ndim(), 2, "POSITIONS should be a 2-D tensor"); - - auto shape = positions.dims(); - shape.push_back(embedding_size_); - output->Resize(shape); - - int M = shape[0]; - int K = shape[1]; - const Index* idxs = positions.template data(); - float* out = output->template mutable_data(); - - float log_alpha = std::log(alpha_); - float max_alpha_pow = - ((float)embedding_size_ - 1.0f) / (float)embedding_size_; - - for (int i = 0; i < M; ++i) { - float pos = (float)idxs[i * K]; - - // Compute the embedding for position i, example 0 first - float* row = &out[i * K * embedding_size_]; - Eigen::Map row_map(row, embedding_size_, 1); - auto row_array = row_map.array(); - - float log_pos = std::log(pos); - row_array.setLinSpaced( - embedding_size_, log_pos, log_pos - log_alpha * max_alpha_pow); - row_array = row_array.exp().eval(); - // row_array[k] == pos / alpha^(k / embedding_size) - - // Phase shift so that alternating elements are cosines - for (int k = 1; k < embedding_size_; k += 2) { - row[k] += (float)M_PI_2; - } - row_array = amplitude_ * row_array.sin().eval(); - - // Copy the embedding to position i in the other examples - for (int j = 1; j < K; ++j) { - int base = i * K * embedding_size_; - std::copy( - &out[base], - &out[base + embedding_size_], - &out[base + j * embedding_size_]); - } - } - return true; - } - - protected: - int embedding_size_; - float alpha_; - float amplitude_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SINUSOID_POSITION_ENCODING_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/slice_op.h b/app/src/main/cpp/caffe2/operators/slice_op.h deleted file mode 100644 index 0b47669..0000000 --- a/app/src/main/cpp/caffe2/operators/slice_op.h +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -namespace { - -template -bool SliceImpl( - Tensor* output, - const Tensor& data, - const Tensor& starts, - const Tensor& ends, - Context* context, - Tensor* gdata = nullptr, - const Tensor* go = nullptr) { - bool backward = output == nullptr; - - auto* starts_data = starts.template data(); - auto* ends_data = ends.template data(); - - CAFFE_ENFORCE_EQ(starts.ndim(), 1); - CAFFE_ENFORCE_EQ(ends.ndim(), 1); - CAFFE_ENFORCE_GE(data.ndim(), starts.size()); - CAFFE_ENFORCE_EQ(starts.size(), ends.size()); - - std::vector starts_idx(data.ndim()); - std::vector ends_idx(data.ndim()); - std::vector dst_sizes(data.ndim()); - - for (int i = 0; i < data.ndim(); ++i) { - if (i >= starts.size()) { - starts_idx[i] = 0; - ends_idx[i] = data.dims()[i]; - continue; - } - if (data.dims()[i] > 0) { - auto start = starts_data[i]; - auto end = ends_data[i]; - if (start < 0) { - start = data.dims()[i] + 1 + start; - } - if (end < 0) { - end = data.dims()[i] + 1 + end; - } - CAFFE_ENFORCE_GE(start, 0); - CAFFE_ENFORCE_GE(end, 0); - CAFFE_ENFORCE_LT(start, data.dims()[i]); - CAFFE_ENFORCE_LE(end, data.dims()[i]); - CAFFE_ENFORCE_GE(end, start); - starts_idx[i] = start; - ends_idx[i] = end; - dst_sizes[i] = end - start; - } else { - starts_idx[i] = 0; - ends_idx[i] = 0; - dst_sizes[i] = 0; - } - } - - if (data.size() <= 0) { - // When the input is empty, we do not need to do copy. - if (!backward) { - output->Resize(dst_sizes); - output->raw_mutable_data(data.meta()); - } - return true; - } - // for now only supports slicing in 1 dimension - int dim = -1; - for (int i = 0; i < data.ndim(); ++i) { - if (starts_idx[i] > 0 || ends_idx[i] < data.dims()[i]) { - CAFFE_ENFORCE_EQ( - dim, -1, "Currently only possible to slice in 1 dimension."); - dim = i; - } - } - if (dim == -1) { - if (!backward) { - output->CopyFrom(data, context); - } else { - gdata->CopyFrom(*go, context); - } - return true; - } - size_t unit = std::accumulate( - data.dims().begin() + dim + 1, - data.dims().end(), - 1, - std::multiplies()); - size_t num_blocks = std::accumulate( - data.dims().begin(), - data.dims().begin() + dim, - 1, - std::multiplies()); - if (!backward) { - output->Resize(dst_sizes); - } else { - gdata->ResizeLike(data); - } - - size_t itemsize = data.meta().itemsize(); - - if (!backward) { - char* src_bytes = (char*)data.raw_data(); - char* dst_bytes = (char*)output->raw_mutable_data(data.meta()); - - size_t src_nbytes = data.nbytes(); - size_t dst_nbytes = output->nbytes(); - - size_t src_block_size = unit * data.dims()[dim]; - size_t dst_block_size = unit * (ends_idx[dim] - starts_idx[dim]); - size_t src_offset = unit * starts_idx[dim]; - - if (num_blocks == 0 || dst_block_size == 0) { - return true; - } - - size_t src_block_size_bytes = itemsize * src_block_size; - size_t dst_block_size_bytes = itemsize * dst_block_size; - - char* src_offset_bytes = src_bytes + itemsize * src_offset; - char* dst_offset_bytes = dst_bytes; - for (int i = 0; i < num_blocks; ++i) { - char* local_src_offset_bytes = - src_offset_bytes + i * src_block_size_bytes; - char* local_dst_offset_bytes = - dst_offset_bytes + i * dst_block_size_bytes; - DCHECK_LE( - static_cast(local_src_offset_bytes + dst_block_size_bytes), - static_cast(src_bytes + src_nbytes)); - DCHECK_LE( - static_cast(local_dst_offset_bytes + dst_block_size_bytes), - static_cast(dst_bytes + dst_nbytes)); - context->template CopyItems( - data.meta(), - dst_block_size, - (void*)local_src_offset_bytes, - (void*)local_dst_offset_bytes); - } - } else { - char* src_bytes = (char*)go->raw_data(); - char* dst_bytes = (char*)gdata->raw_mutable_data(go->meta()); - - size_t src_nbytes = go->nbytes(); - size_t dst_nbytes = gdata->nbytes(); - - size_t src_block_size = unit * (ends_idx[dim] - starts_idx[dim]); - size_t dst_block_size = unit * data.dims()[dim]; - size_t dst_offset = unit * starts_idx[dim]; - - if (num_blocks == 0 || dst_block_size == 0) { - return true; - } - - size_t src_block_size_bytes = itemsize * src_block_size; - size_t dst_block_size_bytes = itemsize * dst_block_size; - - char* src_offset_bytes = src_bytes; - char* dst_offset_bytes = dst_bytes + itemsize * dst_offset; - // Zero out gradient blob before copy since we copy in fewer items than - // there is space for - math::Set(dst_nbytes, 0, dst_bytes, context); - - // If output tensor is empty, just return zeroed gradient tensor - if (!src_bytes) { - return true; - } - - for (int i = 0; i < num_blocks; ++i) { - char* local_src_offset_bytes = - src_offset_bytes + i * src_block_size_bytes; - char* local_dst_offset_bytes = - dst_offset_bytes + i * dst_block_size_bytes; - DCHECK_LE( - local_src_offset_bytes + src_block_size_bytes, - src_bytes + src_nbytes); - DCHECK_LE( - local_dst_offset_bytes + src_block_size_bytes, - dst_bytes + dst_nbytes); - context->template CopyItems( - go->meta(), - src_block_size, - (void*)local_src_offset_bytes, - (void*)local_dst_offset_bytes); - } - } - return true; -} - -} // namespace - -template -class SliceOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SliceOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - starts_(OperatorBase::GetRepeatedArgument("starts")), - ends_(OperatorBase::GetRepeatedArgument("ends")), - statically_inited_(false) {} - - bool RunOnDevice() override { - auto* output = Output(0); - auto& data = Input(0); - - if (InputSize() > 1) { - starts_host_.template CopyFrom(Input(1)); - ends_host_.template CopyFrom(Input(2)); - } else { - if (!statically_inited_) { - CAFFE_ENFORCE(HasArgument("starts")); - CAFFE_ENFORCE(HasArgument("ends")); - CAFFE_ENFORCE_EQ(starts_.size(), ends_.size()); - - starts_host_.Resize(starts_.size()); - ends_host_.Resize(ends_.size()); - - memcpy( - starts_host_.template mutable_data(), - starts_.data(), - sizeof(SIndex) * starts_.size()); - memcpy( - ends_host_.template mutable_data(), - ends_.data(), - sizeof(SIndex) * ends_.size()); - statically_inited_ = true; - } - } - - return SliceImpl( - output, data, starts_host_, ends_host_, &context_); - } - - DISABLE_COPY_AND_ASSIGN(SliceOp); - - private: - std::vector starts_; - std::vector ends_; - bool statically_inited_; - TensorCPU starts_host_; - TensorCPU ends_host_; -}; - -template -class SliceGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SliceGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - starts_(OperatorBase::GetRepeatedArgument("starts")), - ends_(OperatorBase::GetRepeatedArgument("ends")), - statically_inited_(false) {} - - bool RunOnDevice() override { - auto* gdata = Output(0); - auto& data = Input(0); - - if (InputSize() == 4) { - starts_host_.template CopyFrom(Input(1)); - ends_host_.template CopyFrom(Input(2)); - - auto& go = Input(3); - - return SliceImpl( - nullptr, data, starts_host_, ends_host_, &context_, gdata, &go); - } else { - if (!statically_inited_) { - CAFFE_ENFORCE(HasArgument("starts")); - CAFFE_ENFORCE(HasArgument("ends")); - CAFFE_ENFORCE_EQ(starts_.size(), ends_.size()); - - starts_host_.Resize(starts_.size()); - ends_host_.Resize(ends_.size()); - - memcpy( - starts_host_.template mutable_data(), - starts_.data(), - sizeof(SIndex) * starts_.size()); - memcpy( - ends_host_.template mutable_data(), - ends_.data(), - sizeof(SIndex) * ends_.size()); - - statically_inited_ = true; - } - auto& go = Input(1); - - return SliceImpl( - nullptr, data, starts_host_, ends_host_, &context_, gdata, &go); - } - } - - DISABLE_COPY_AND_ASSIGN(SliceGradientOp); - - private: - std::vector starts_; - std::vector ends_; - bool statically_inited_; - TensorCPU starts_host_; - TensorCPU ends_host_; -}; -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/operators/softmax_op.h b/app/src/main/cpp/caffe2/operators/softmax_op.h deleted file mode 100644 index 9073a0e..0000000 --- a/app/src/main/cpp/caffe2/operators/softmax_op.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SOFTMAX_OP_H_ -#define CAFFE2_OPERATORS_SOFTMAX_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SoftmaxOp final : public Operator { - public: - SoftmaxOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - int axis_; - Tensor scale_; - Tensor rowmax_; - Tensor sum_multiplier_; -}; - -template -class SoftmaxGradientOp final : public Operator { - public: - SoftmaxGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axis_(OperatorBase::GetSingleArgument("axis", 1)) {} - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - protected: - int axis_; - Tensor scale_; - Tensor sum_multiplier_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SOFTMAX_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/softmax_shared.h b/app/src/main/cpp/caffe2/operators/softmax_shared.h deleted file mode 100644 index 60c2bd0..0000000 --- a/app/src/main/cpp/caffe2/operators/softmax_shared.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SOFTMAX_SHARED_H_ -#define CAFFE2_OPERATORS_SOFTMAX_SHARED_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -void SoftmaxCPU( - CPUContext& context, - const int N, - const int D, - const float* Xdata, - float* Ydata, - float* scale, - const float* sum_multiplier, - bool logarithmic, - float* rowmax); -} // namespace caffe2 - -#endif // #define CAFFE2_OPERATORS_SOFTMAX_SHARED_H_ diff --git a/app/src/main/cpp/caffe2/operators/softmax_with_loss_op.h b/app/src/main/cpp/caffe2/operators/softmax_with_loss_op.h deleted file mode 100644 index 27e6db2..0000000 --- a/app/src/main/cpp/caffe2/operators/softmax_with_loss_op.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef SOFTMAX_WITH_LOSS_OP_H_ -#define SOFTMAX_WITH_LOSS_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SoftmaxWithLossOp final : public Operator { - public: - SoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 1.)), - label_prob_mode_(OperatorBase::GetSingleArgument("label_prob", 0)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - axis_(OperatorBase::GetSingleArgument("axis", 1)) { - CAFFE_ENFORCE(scale_ >= 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float scale_; - int label_prob_mode_; - StorageOrder order_; - int axis_; - - Tensor losses_; // Per example loss - Tensor rowmax_; // per example row max - Tensor weights_; // unignored weights - Tensor sum_multiplier_; // Vector of ones for summing via dot prod - Tensor total_weight_ptr_; - Tensor scratch_; -}; - -template -class SoftmaxWithLossGradientOp final : public Operator { - public: - SoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 1.)), - label_prob_mode_(OperatorBase::GetSingleArgument("label_prob", 0)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - only_loss_(OperatorBase::GetSingleArgument("only_loss", false)), - axis_(OperatorBase::GetSingleArgument("axis", 1)) { - CAFFE_ENFORCE(scale_ >= 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float scale_; - int label_prob_mode_; - Tensor sum_multiplier_; - Tensor weights_; // unignored weights - Tensor total_weight_ptr_; - StorageOrder order_; - bool only_loss_; - int axis_; - Tensor scratch_; -}; - -} // namespace caffe2 - -#endif // SOFTMAX_WITH_LOSS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/softplus_op.h b/app/src/main/cpp/caffe2/operators/softplus_op.h deleted file mode 100644 index 38559ef..0000000 --- a/app/src/main/cpp/caffe2/operators/softplus_op.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SOFTPLUS_OP_H_ -#define CAFFE2_OPERATORS_SOFTPLUS_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class SoftplusOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(SoftplusOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: -}; - -template -class SoftplusGradientOp final : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(SoftplusGradientOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - // Input: Y, dY; Output: dX -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SOFTPLUS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/space_batch_op.h b/app/src/main/cpp/caffe2/operators/space_batch_op.h deleted file mode 100644 index 4f42dc0..0000000 --- a/app/src/main/cpp/caffe2/operators/space_batch_op.h +++ /dev/null @@ -1,208 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPACE_BATCH_OP_H_ -#define CAFFE2_OPERATORS_SPACE_BATCH_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -void spaceToBatch( - const Tensor& input, - int pad_t, - int pad_l, - int block_size, - Tensor* output, - Context* /*context*/) { - CAFFE_ENFORCE(input.ndim() == 4); - CAFFE_ENFORCE(output->ndim() == 4); - - const int output_batch = output->dim32(0); - const int output_depth = output->dim32(1); - const int output_height = output->dim32(2); - const int output_width = output->dim32(3); - - const int input_batch = input.dim32(0); - const int input_depth = input.dim32(1); - const int input_height = input.dim32(2); - const int input_width = input.dim32(3); - - for (int out_b = 0; out_b < output_batch; ++out_b) { - const int in_b = out_b % input_batch; - const int offset_w = (out_b / input_batch) % block_size; - const int offset_h = (out_b / input_batch) / block_size; - for (int d = 0; d < input_depth; ++d) { - for (int out_h = 0; out_h < output_height; ++out_h) { - const int in_h = out_h * block_size + offset_h - pad_t; - for (int out_w = 0; out_w < output_width; ++out_w) { - const int in_w = out_w * block_size + offset_w - pad_l; - const auto output_offset = - ((out_b * output_depth + d) * output_height + out_h) * - output_width + - out_w; - const auto input_offset = - ((in_b * input_depth + d) * input_height + in_h) * input_width + - in_w; - if (in_h >= 0 && in_w >= 0 && in_h < input_height && - in_w < input_width) { - output->template mutable_data()[output_offset] = - input.template data()[input_offset]; - } else { - output->template mutable_data()[output_offset] = 0.0; - } - } - } - } - } -} - -template -void batchToSpace( - const Tensor& input, - int pad_t, - int pad_l, - int block_size, - Tensor* output, - Context* /*context*/) { - CAFFE_ENFORCE(input.ndim() == 4); - CAFFE_ENFORCE(output->ndim() == 4); - - const int output_batch = output->dim32(0); - const int output_depth = output->dim32(1); - const int output_height = output->dim32(2); - const int output_width = output->dim32(3); - - const int input_batch = input.dim32(0); - const int input_depth = input.dim32(1); - const int input_height = input.dim32(2); - const int input_width = input.dim32(3); - - CAFFE_ENFORCE(input_depth == output_depth); - for (int in_b = 0; in_b < input_batch; ++in_b) { - const int out_b = in_b % output_batch; - const int offset_w = (in_b / output_batch) % block_size; - const int offset_h = (in_b / output_batch) / block_size; - for (int d = 0; d < input_depth; ++d) { - for (int in_h = 0; in_h < input_height; ++in_h) { - const int out_h = in_h * block_size + offset_h - pad_t; - for (int in_w = 0; in_w < input_width; ++in_w) { - const int out_w = in_w * block_size + offset_w - pad_l; - if (out_h >= 0 && out_w >= 0 && out_h < output_height && - out_w < output_width) { - const auto output_offset = - ((out_b * output_depth + d) * output_height + out_h) * - output_width + - out_w; - const auto input_offset = - ((in_b * input_depth + d) * input_height + in_h) * input_width + - in_w; - output->template mutable_data()[output_offset] = - input.template data()[input_offset]; - } - } - } - } - } -} - -template -class SpaceBatchOpBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SpaceBatchOpBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - pad_(OperatorBase::GetSingleArgument("pad", 0)), - pad_t_(OperatorBase::GetSingleArgument("pad_t", pad_)), - pad_l_(OperatorBase::GetSingleArgument("pad", pad_)), - pad_b_(OperatorBase::GetSingleArgument("pad", pad_)), - pad_r_(OperatorBase::GetSingleArgument("pad", pad_)), - block_size_(OperatorBase::GetSingleArgument("block_size", 2)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(order_ == StorageOrder::NCHW); - } - - protected: - int pad_; - int pad_t_; - int pad_l_; - int pad_b_; - int pad_r_; - int block_size_; - StorageOrder order_; -}; - -template -class SpaceToBatchOp final : public SpaceBatchOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using SpaceBatchOpBase::SpaceBatchOpBase; - - bool RunOnDevice() override { - const auto& input = Input(0); - auto* output = Output(0); - const int batch = input.dim32(0); - const int depth = input.dim32(1); - const int height = this->pad_b_ + this->pad_t_ + input.dim32(2); - const int width = this->pad_l_ + this->pad_r_ + input.dim32(3); - CAFFE_ENFORCE( - height % this->block_size_ == 0, - "Height: ", - height, - ", block size: ", - this->block_size_); - CAFFE_ENFORCE(width % this->block_size_ == 0); - - const int output_batch = batch * this->block_size_ * this->block_size_; - const int output_height = height / this->block_size_; - const int output_width = width / this->block_size_; - Output(0)->Resize(output_batch, depth, output_height, output_width); - - spaceToBatch( - input, - this->pad_t_, - this->pad_l_, - this->block_size_, - output, - &context_); - - return true; - } -}; - -template -class BatchToSpaceOp final : public SpaceBatchOpBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using SpaceBatchOpBase::SpaceBatchOpBase; - - bool RunOnDevice() override { - const auto& input = Input(0); - auto* output = Output(0); - const int batch = input.dim32(0); - const int depth = input.dim32(1); - const int height = input.dim32(2); - const int width = input.dim32(3); - - const int output_batch = batch / this->block_size_ / this->block_size_; - const int output_height = - height * this->block_size_ - this->pad_b_ - this->pad_t_; - const int output_width = - width * this->block_size_ - this->pad_l_ - this->pad_r_; - Output(0)->Resize(output_batch, depth, output_height, output_width); - batchToSpace( - input, - this->pad_t_, - this->pad_l_, - this->block_size_, - output, - &context_); - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPACE_BATCH_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/sparse_to_dense_mask_op.h b/app/src/main/cpp/caffe2/operators/sparse_to_dense_mask_op.h deleted file mode 100644 index ccedc5e..0000000 --- a/app/src/main/cpp/caffe2/operators/sparse_to_dense_mask_op.h +++ /dev/null @@ -1,278 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPARSE_TO_DENSE_MASK_OP_H_ -#define CAFFE2_OPERATORS_SPARSE_TO_DENSE_MASK_OP_H_ - -#include -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/tensor.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SparseToDenseMaskBase : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskBase(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - std::vector mask = - OperatorBase::template GetRepeatedArgument("mask"); - featuresCount_ = mask.size(); - CAFFE_ENFORCE(!mask.empty(), "mask can't be empty"); - auto biggest = *std::max_element(mask.begin(), mask.end()); - dense_.assign(std::min(kMaxDenseSize, biggest + 1), -1); - for (int i = 0; i < mask.size(); i++) { - int id = mask[i]; - CAFFE_ENFORCE_GE(id, 0, "Only positive IDs are allowed."); - if (id >= kMaxDenseSize) { - CAFFE_ENFORCE(sparse_.count(id) == 0, "Duplicated id: ", id); - sparse_[id] = i; - } else { - CAFFE_ENFORCE(dense_[id] == -1, "Duplicated id: ", id); - dense_[id] = i; - } - } - } - - protected: - const int kMaxDenseSize = 1024 * 128; - - std::unordered_map sparse_; - std::vector dense_; - int featuresCount_; - - inline int getFeatureIdx(int id) const { - if (id >= kMaxDenseSize) { - const auto& iter = sparse_.find(id); - if (iter == sparse_.end()) { - return -1; - } else { - return iter->second; - } - } else { - return (id >= dense_.size()) ? -1 : dense_[id]; - } - } -}; - -template -class SparseToDenseMaskOp : public SparseToDenseMaskBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskOp(const OperatorDef& operator_def, Workspace* ws) - : SparseToDenseMaskBase(operator_def, ws) { - returnPresenceMask_ = OperatorBase::template GetSingleArgument( - "return_presence_mask", false); - } - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& sparse_indices = Input(INDICES); - CAFFE_ENFORCE_EQ(sparse_indices.ndim(), 1); - auto& sparse_values = Input(VALUES); - CAFFE_ENFORCE_GE(sparse_values.ndim(), 1); - CAFFE_ENFORCE_EQ(sparse_indices.size(), sparse_values.dim(0)); - auto& default_value = Input(DEFAULT); - CAFFE_ENFORCE_EQ(default_value.ndim() + 1, sparse_values.ndim()); - CAFFE_ENFORCE_EQ(default_value.size(), sparse_values.size_from_dim(1)); - CAFFE_ENFORCE(sparse_values.meta() == default_value.meta()); - - const TInd* sparse_indices_vec = sparse_indices.template data(); - const char* sparse_values_vec = - static_cast(sparse_values.raw_data()); - const void* default_val = default_value.raw_data(); - - TIndex block_size = default_value.size(); - size_t block_nbytes = default_value.nbytes(); - - const int cols = this->featuresCount_; - int rows = -1; - int32_t sparse_indices_length = sparse_indices.dim32(0); - const int32_t* lengths_vec = nullptr; - auto* output = Output(OUTPUTVALUE); - Tensor* presence_mask = nullptr; - if (returnPresenceMask_) { - presence_mask = Output(PRESENCEMASK); - } - vector shape; - if (InputSize() == 4) { - auto& lengths = Input(LENGTHS); - CAFFE_ENFORCE_EQ(lengths.ndim(), 1); - lengths_vec = lengths.template data(); - rows = lengths.dim32(0); - } - if (rows == -1) { - // if the LENGTHS is not set, the output will be a vector - rows = 1; - lengths_vec = &sparse_indices_length; - } else { - shape.push_back(rows); - } - shape.push_back(cols); - if (returnPresenceMask_) { - presence_mask->Resize(shape); - } - shape.insert( - shape.end(), default_value.dims().begin(), default_value.dims().end()); - output->Resize(shape); - - // init - // TODO: consider unrolling CopyItems to make elemental types copy faster - char* output_data = - static_cast(output->raw_mutable_data(sparse_values.meta())); - for (int i = 0; i < cols * rows; i++) { - context_.template CopyItems( - default_value.meta(), - block_size, - default_val, - output_data + i * block_nbytes); - } - bool* presence_mask_data = nullptr; - if (returnPresenceMask_) { - presence_mask_data = presence_mask->template mutable_data(); - math::Set( - rows * cols, false, presence_mask_data, &context_); - } - - CAFFE_ENFORCE( - (ConstEigenVectorArrayMap( - sparse_indices_vec, sparse_indices_length) < - std::numeric_limits::max()) - .all() && - (ConstEigenVectorArrayMap( - sparse_indices_vec, sparse_indices_length) >= 0) - .all(), - "All indices must be representable as non-negative int32_t numbers"); - - int32_t offset = 0; - for (int r = 0; r < rows; r++) { - for (int c = 0; c < lengths_vec[r]; c++) { - int idx = this->getFeatureIdx(sparse_indices_vec[offset + c]); - if (idx != -1) { - context_.template CopyItems( - sparse_values.meta(), - block_size, - sparse_values_vec + (offset + c) * block_nbytes, - output_data + (r * cols + idx) * block_nbytes); - if (returnPresenceMask_) { - presence_mask_data[r * cols + idx] = true; - } - } - } - offset += lengths_vec[r]; - } - - return true; - } - - private: - bool returnPresenceMask_; - - INPUT_TAGS(INDICES, VALUES, DEFAULT, LENGTHS); - OUTPUT_TAGS(OUTPUTVALUE, PRESENCEMASK); -}; - -template -class SparseToDenseMaskGradientOp : public SparseToDenseMaskBase { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseToDenseMaskGradientOp(const OperatorDef& operator_def, Workspace* ws) - : SparseToDenseMaskBase(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& sparse_indices = Input(INDICES); - CAFFE_ENFORCE_EQ(sparse_indices.ndim(), 1); - auto& gradient_output = Input(GOUTPUT); - - TIndex block_size = gradient_output.size_from_dim(1); - size_t block_nbytes = gradient_output.itemsize() * block_size; - - const int cols = this->featuresCount_; - int rows = -1; - int iter_offset = 1; - int32_t default_length = sparse_indices.dim32(0); - const int32_t* lengths_vec = nullptr; - auto* output = Output(GVALUES); - vector shape; - if (InputSize() > LENGTHS) { - // if the LENGTHS is set, the gradient_output has dim: - // lengths * mask.size() * feature_dim - auto& lengths = Input(LENGTHS); - lengths_vec = lengths.template data(); - rows = lengths.dim32(0); - CAFFE_ENFORCE_EQ(lengths.ndim(), 1); - CAFFE_ENFORCE_GE(gradient_output.ndim(), 2); - CAFFE_ENFORCE_EQ(gradient_output.dim(0), rows); - CAFFE_ENFORCE_EQ(gradient_output.dim(1), cols); - block_nbytes /= gradient_output.dim(1); - block_size /= gradient_output.dim(1); - iter_offset += 1; - } - if (rows == -1) { - // if the LENGTHS is not set, the gradient_output has dim: - // mask.size() * feature_dim - rows = 1; - lengths_vec = &default_length; - CAFFE_ENFORCE_GE(gradient_output.ndim(), 1); - CAFFE_ENFORCE_EQ(gradient_output.dim(0), cols); - } - shape.push_back(default_length); - // insert feature_dim - shape.insert( - shape.end(), - gradient_output.dims().begin() + iter_offset, - gradient_output.dims().end()); - output->Resize(shape); - - const TInd* sparse_indices_vec = sparse_indices.template data(); - const char* gradient_output_vec = - static_cast(gradient_output.raw_data()); - - char* output_data = - static_cast(output->raw_mutable_data(gradient_output.meta())); - math::Set( - default_length * gradient_output.itemsize(), 0, output_data, &context_); - - int32_t offset = 0; - // SparseToDenseMask is not injective; gradient_used records - // if the gradient is used for other input value from the same row - vector gradient_used(cols, false); - for (int r = 0; r < rows; r++) { - std::fill(gradient_used.begin(), gradient_used.end(), false); - for (int c = lengths_vec[r] - 1; c >= 0; c--) { - int idx = this->getFeatureIdx(sparse_indices_vec[offset + c]); - if (idx != -1 && !gradient_used[idx]) { - gradient_used[idx] = true; - context_.template CopyItems( - gradient_output.meta(), - block_size, - gradient_output_vec + (r * cols + idx) * block_nbytes, - output_data + (offset + c) * block_nbytes); - } - } - offset += lengths_vec[r]; - } - return true; - } - - private: - INPUT_TAGS(INDICES, GOUTPUT, LENGTHS); - OUTPUT_TAGS(GVALUES); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPARSE_TO_DENSE_MASK_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/sparse_to_dense_op.h b/app/src/main/cpp/caffe2/operators/sparse_to_dense_op.h deleted file mode 100644 index 7fbfa38..0000000 --- a/app/src/main/cpp/caffe2/operators/sparse_to_dense_op.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPARSE_TO_DENSE_OP_H_ -#define CAFFE2_OPERATORS_SPARSE_TO_DENSE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SparseToDenseOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - - SparseToDenseOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - output_first_dim_( - OperatorBase::GetSingleArgument("output_first_dim", 0)) {} - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(INDICES)); - } - - private: - template - int GetOutputFirstDim( - const TInd* sparse_indices_vec, - const int32_t sparse_indices_len) { - if (output_first_dim_ > 0) { - CAFFE_ENFORCE_EQ(InputSize(), 2); - return output_first_dim_; - } - if (InputSize() == 3) { - auto& data_to_infer_dim = Input(DATA_TO_INFER_DIM); - CAFFE_ENFORCE_GE(data_to_infer_dim.ndim(), 1); - return data_to_infer_dim.dim32(0); - } - if (sparse_indices_len <= 0) { - return 0; - } - - // Awkward way to get the max element to make it work with both CUDA - // and CPU. - max_element_.Resize(1); - TInd* max_element_ptr = max_element_.template mutable_data(); - math::ReduceMax(sparse_indices_len, sparse_indices_vec, max_element_ptr, - &scratch_, &context_); - max_element_host_.CopyFrom(max_element_); - return 1 + max_element_host_.template data()[0]; - } - - template - bool DoRunWithType() { - return DispatchHelper< - TensorTypes2< - float, - int32_t, - int64_t, - GenericTensorImplementation>, - TInd>::call(this, Input(VALUES)); - } - - template - bool DoRunWithType2() { - auto& sparse_indices = Input(INDICES); - CAFFE_ENFORCE_EQ(sparse_indices.ndim(), 1); - auto& sparse_values = Input(VALUES); - CAFFE_ENFORCE_GE(sparse_values.ndim(), 1); - CAFFE_ENFORCE_EQ(sparse_indices.size(), sparse_values.dim(0)); - - const TInd* sparse_indices_vec = sparse_indices.template data(); - const int32_t sparse_indices_len = sparse_indices.dim32(0); - const int output_first_dim = - GetOutputFirstDim(sparse_indices_vec, sparse_indices_len); - - auto shape = sparse_values.dims(); - shape[0] = output_first_dim; - auto* output = Output(0); - output->Resize(shape); - - TData* output_data = output->template mutable_data(); - memset(output_data, 0, output->nbytes()); - const auto block_nitems = sparse_values.size_from_dim(1); - const TData* sparse_values_vec = sparse_values.template data(); - - for (int32_t i = 0; i < sparse_indices_len; i++) { - const TInd idx = sparse_indices_vec[i]; - CAFFE_ENFORCE_GE(idx, 0); - CAFFE_ENFORCE_LT(idx, output_first_dim); - math::Add( - block_nitems, - output_data + idx * block_nitems, - sparse_values_vec + i * block_nitems, - output_data + idx * block_nitems, - &context_); - } - return true; - } - - template - bool DoRunWithOtherType2() { - CAFFE_THROW( - "SparseToDense is not implemented on tensor of type ", - Input(VALUES).meta().name(), - "Consider adding it a type in the list DispatchHelper or implementing " - "a generic version (which won't work for duplicated indices though)"); - } - - private: - int output_first_dim_; - Tensor scratch_; - Tensor max_element_host_; - Tensor max_element_; - - INPUT_TAGS(INDICES, VALUES, DATA_TO_INFER_DIM); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPARSE_TO_DENSE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/spatial_batch_norm_op.h b/app/src/main/cpp/caffe2/operators/spatial_batch_norm_op.h deleted file mode 100644 index 87600ef..0000000 --- a/app/src/main/cpp/caffe2/operators/spatial_batch_norm_op.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SPATIAL_BATCH_NORM_OP_H_ -#define CAFFE2_OPERATORS_SPATIAL_BATCH_NORM_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SpatialBNOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SpatialBNOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - is_test_(OperatorBase::GetSingleArgument(OpSchema::Arg_IsTest, 0)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5)), - momentum_(OperatorBase::GetSingleArgument("momentum", 0.9)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - // TODO(jiayq): update the input and output size checks. - CAFFE_ENFORCE( - (is_test_ && OutputSize() == 1) || (!is_test_ && OutputSize() == 5)); - CAFFE_ENFORCE_GT(epsilon_, 0); - CAFFE_ENFORCE_GE(momentum_, 0); - CAFFE_ENFORCE_LE(momentum_, 1); - } - ~SpatialBNOp() {} - - bool RunOnDevice() override { - return true; - } - - protected: - bool is_test_; - double epsilon_; - double momentum_; - StorageOrder order_; - INPUT_TAGS(INPUT, SCALE, BIAS, EST_MEAN, EST_VAR); - OUTPUT_TAGS(OUTPUT, RUNNING_MEAN, RUNNING_VAR, SAVED_MEAN, SAVED_INV_VAR); -}; - -template -class SpatialBNGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SpatialBNGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - is_test_(OperatorBase::GetSingleArgument(OpSchema::Arg_IsTest, 0)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(InputSize() == 5); - CAFFE_ENFORCE(OutputSize() == 3); - } - ~SpatialBNGradientOp() {} - - bool RunOnDevice() override { - return true; - } - - protected: - bool is_test_; - double epsilon_; - StorageOrder order_; - - INPUT_TAGS(INPUT, SCALE, OUTPUT_GRAD, SAVED_MEAN, SAVED_INV_VAR); - OUTPUT_TAGS(INPUT_GRAD, SCALE_GRAD, BIAS_GRAD); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SPATIAL_BATCH_NORM_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/spatial_softmax_with_loss_op.h b/app/src/main/cpp/caffe2/operators/spatial_softmax_with_loss_op.h deleted file mode 100644 index d466063..0000000 --- a/app/src/main/cpp/caffe2/operators/spatial_softmax_with_loss_op.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef SPATIAL_SOFTMAX_WITH_LOSS_OP_H_ -#define SPATIAL_SOFTMAX_WITH_LOSS_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SpatialSoftmaxWithLossOp final : public Operator { - public: - SpatialSoftmaxWithLossOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 1.)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))) { - CAFFE_ENFORCE(scale_ >= 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float scale_; - StorageOrder order_; - - Tensor losses_; // Per example loss - Tensor rowmax_; // per example row max - Tensor weights_; // unignored weights - Tensor sum_multiplier_; // Vector of ones for summing via dot prod - Tensor total_weight_ptr_; - Tensor scratch_; -}; - -template -class SpatialSoftmaxWithLossGradientOp final : public Operator { - public: - SpatialSoftmaxWithLossGradientOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - scale_(OperatorBase::GetSingleArgument("scale", 1.)), - order_(StringToStorageOrder( - OperatorBase::GetSingleArgument("order", "NCHW"))), - only_loss_(OperatorBase::GetSingleArgument("only_loss", false)) { - CAFFE_ENFORCE(scale_ >= 0); - CAFFE_ENFORCE_EQ( - order_, StorageOrder::NCHW, "Only NCHW order is supported right now."); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override; - - protected: - float scale_; - Tensor sum_multiplier_; - Tensor weights_; // unignored weights - Tensor total_weight_ptr_; - StorageOrder order_; - bool only_loss_; - Tensor scratch_; -}; - -} // namespace caffe2 - -#endif // SOFTMAX_WITH_LOSS_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/square_root_divide_op.h b/app/src/main/cpp/caffe2/operators/square_root_divide_op.h deleted file mode 100644 index dce63a8..0000000 --- a/app/src/main/cpp/caffe2/operators/square_root_divide_op.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SQUARE_ROOT_DIVIDE_OP_H_ -#define CAFFE2_OPERATORS_SQUARE_ROOT_DIVIDE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class SquareRootDivideOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - - SquareRootDivideOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(DATA)); - } - - private: - template - bool DoRunWithType() { - return DispatchHelper, TData>::call( - this, Input(SCALE)); - } - - template - bool DoRunWithType2() { - auto& data = Input(DATA); - auto& scale = Input(SCALE); - auto* Y = Output(0); - Y->ResizeLike(data); - size_t batchSize = data.dim(0); - size_t exampleSize = data.size_from_dim(1); - CAFFE_ENFORCE(batchSize == scale.dim(0), batchSize, " != ", scale.dim(0)); - auto* scalePtr = scale.template data(); - auto* dataPtr = data.template data(); - auto* yPtr = Y->template mutable_data(); - for (auto i = 0; i < batchSize; ++i) { - auto scale = scalePtr[i]; - CAFFE_ENFORCE(scale >= 0, scale, " < 0"); - auto multiplier = scale == 0 ? 1.0 : 1 / std::sqrt(scale); - math::Scale( - exampleSize, - multiplier, - dataPtr + i * exampleSize, - yPtr + i * exampleSize, - &context_); - } - return true; - } - - INPUT_TAGS(DATA, SCALE); -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SQUARE_ROOT_DIVIDE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/stop_gradient.h b/app/src/main/cpp/caffe2/operators/stop_gradient.h deleted file mode 100644 index e05cd11..0000000 --- a/app/src/main/cpp/caffe2/operators/stop_gradient.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef CAFFE2_OPERATORS_STOP_GRADIENT_H_ -#define CAFFE2_OPERATORS_STOP_GRADIENT_H_ - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class StopGradientOp : public Operator { - public: - USE_SIMPLE_CTOR_DTOR(StopGradientOp) - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override { - const auto& in = Input(0); - auto* out = Output(0); - if (out != &in) { - out->CopyFrom(in, &context_); - } - return true; - } -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_STOP_GRADIENT_H_ diff --git a/app/src/main/cpp/caffe2/operators/string_ops.h b/app/src/main/cpp/caffe2/operators/string_ops.h deleted file mode 100644 index 17011fe..0000000 --- a/app/src/main/cpp/caffe2/operators/string_ops.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef CAFFE2_OPERATORS_STRING_OPS_H_ -#define CAFFE2_OPERATORS_STRING_OPS_H_ - -#include "caffe2/core/operator.h" -#include "caffe2/operators/elementwise_op.h" - -namespace caffe2 { - -/** - * ForEach is a unary functor that forwards each element of the input array - * into the elementwise Functor provided, and gathers the results of each - * call into the resulting array. Use it as an adaptor if you want to create - * a UnaryElementwiseOp that acts on each element of the tensor per function - * call -- this is resonable for complex types where vectorization wouldn't - * be much of a gain, performance-wise. - */ -template -struct ForEach { - explicit ForEach(OperatorBase& op) : functor(op) {} - - template - void operator()(int n, const In* in, Out* out, Context* /*c*/) { - for (int i = 0; i < n; ++i) { - out[i] = functor(in[i]); - } - } - Functor functor; -}; - -template > -using StringElementwiseOp = UnaryElementwiseWithArgsOp< - TensorTypes, - CPUContext, - ForEach, - TypeMap>; - -template -class StringJoinOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - StringJoinOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - delimiter_( - OperatorBase::GetSingleArgument("delimiter", ",")), - axis_(OperatorBase::GetSingleArgument("axis", 0)) { - CAFFE_ENFORCE(axis_ == 0 || axis_ == 1); - } - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType(); - - protected: - std::string delimiter_; - int axis_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_STRING_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/summarize_op.h b/app/src/main/cpp/caffe2/operators/summarize_op.h deleted file mode 100644 index dddac5c..0000000 --- a/app/src/main/cpp/caffe2/operators/summarize_op.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef CAFFE2_OPERATORS_SUMMARIZE_OP_H_ -#define CAFFE2_OPERATORS_SUMMARIZE_OP_H_ - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -constexpr char kSummaryzeOpExtension[] = ".summary"; - -template -class SummarizeOp final : public Operator { - public: - SummarizeOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - to_file_(OperatorBase::GetSingleArgument("to_file", 0)) { - if (to_file_) { - // We will output to file instead of printing on screen. - const string& target_folder = ws->RootFolder(); - // We will write each individual tensor to its individual file. - // Also, since the namescope is currently represented by "/", we will - // need to replace it with a symbol that does not conflict with the - // folder separator in Linux. - string proper_name = def.input(0); - std::replace(proper_name.begin(), proper_name.end(), '/', '#'); - log_file_.reset(new std::ofstream( - target_folder + "/" + proper_name + kSummaryzeOpExtension, - std::ofstream::out | std::ofstream::trunc)); - CAFFE_ENFORCE( - log_file_->good(), - "Failed to open summarize file for tensor ", - def.input(0), - ". rdstate() = ", - log_file_->rdstate()); - } - } - ~SummarizeOp() { - if (to_file_) - log_file_->close(); - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - static constexpr int MIN_IDX = 0; - static constexpr int MAX_IDX = 1; - static constexpr int MEAN_IDX = 2; - static constexpr int STD_IDX = 3; - - static constexpr int NUM_STATS = 4; - - protected: - bool to_file_; - std::unique_ptr log_file_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_SUMMARIZE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/tensor_protos_db_input.h b/app/src/main/cpp/caffe2/operators/tensor_protos_db_input.h deleted file mode 100644 index e9e55b8..0000000 --- a/app/src/main/cpp/caffe2/operators/tensor_protos_db_input.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TENSOR_PROTOS_DB_INPUT_H_ -#define CAFFE2_OPERATORS_TENSOR_PROTOS_DB_INPUT_H_ - -#include -#include - -#include "caffe2/core/db.h" -#include "caffe2/operators/prefetch_op.h" - -namespace caffe2 { - -template -class TensorProtosDBInput final : public PrefetchOperator { - public: - using OperatorBase::OutputSize; - using PrefetchOperator::prefetch_thread_; - explicit TensorProtosDBInput(const OperatorDef& operator_def, Workspace* ws); - ~TensorProtosDBInput() { - PrefetchOperator::Finalize(); - } - - bool Prefetch() override; - bool CopyPrefetched() override; - - private: - // Prefetch will always just happen on the CPU side. - vector prefetched_blobs_; - int batch_size_; - bool shape_inferred_ = false; - string key_; - string value_; -}; - -template -TensorProtosDBInput::TensorProtosDBInput( - const OperatorDef& operator_def, - Workspace* ws) - : PrefetchOperator(operator_def, ws), - prefetched_blobs_(operator_def.output_size()), - batch_size_( - OperatorBase::template GetSingleArgument("batch_size", 0)) {} - -template -bool TensorProtosDBInput::Prefetch() { - const db::DBReader& reader = OperatorBase::Input(0); - TensorDeserializer deserializer; - if (batch_size_ == 0) { - // We do not need to construct a batch. As a result, we will simply - // deserialize everything into the target prefetched blob. - reader.Read(&key_, &value_); - TensorProtos protos; - CAFFE_ENFORCE(protos.ParseFromString(value_)); - CAFFE_ENFORCE(protos.protos_size() == OutputSize()); - for (int i = 0; i < protos.protos_size(); ++i) { - if (protos.protos(i).has_device_detail()) { - protos.mutable_protos(i)->clear_device_detail(); - } - deserializer.Deserialize( - protos.protos(i), - prefetched_blobs_[i].template GetMutable()); - } - } else { - vector temp_tensors(OutputSize()); - for (int item_id = 0; item_id < batch_size_; ++item_id) { - reader.Read(&key_, &value_); - TensorProtos protos; - CAFFE_ENFORCE(protos.ParseFromString(value_)); - CAFFE_ENFORCE(protos.protos_size() == OutputSize()); - if (!shape_inferred_) { - // First, set the shape of all the blobs. - for (int i = 0; i < protos.protos_size(); ++i) { - vector dims( - protos.protos(i).dims().begin(), protos.protos(i).dims().end()); - dims.insert(dims.begin(), batch_size_); - prefetched_blobs_[i].template GetMutable()->Resize(dims); - } - } - for (int i = 0; i < protos.protos_size(); ++i) { - TensorCPU* dst = prefetched_blobs_[i].template GetMutable(); - TensorCPU& src = temp_tensors[i]; - if (protos.protos(i).has_device_detail()) { - protos.mutable_protos(i)->clear_device_detail(); - } - deserializer.Deserialize(protos.protos(i), &src); - DCHECK_EQ(src.size() * batch_size_, dst->size()); - this->context_.template CopyItems( - src.meta(), - src.size(), - src.raw_data(), - static_cast(dst->raw_mutable_data(src.meta())) + - src.nbytes() * item_id); - } - } - } - return true; -} - -template -bool TensorProtosDBInput::CopyPrefetched() { - for (int i = 0; i < OutputSize(); ++i) { - OperatorBase::Output>(i)->CopyFrom( - prefetched_blobs_[i].template Get(), &this->context_); - } - return true; -} - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TENSOR_PROTOS_DB_INPUT_H_ diff --git a/app/src/main/cpp/caffe2/operators/text_file_reader_utils.h b/app/src/main/cpp/caffe2/operators/text_file_reader_utils.h deleted file mode 100644 index 73bbbb8..0000000 --- a/app/src/main/cpp/caffe2/operators/text_file_reader_utils.h +++ /dev/null @@ -1,122 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TEXT_FILE_READER_UTILS_H -#define CAFFE2_OPERATORS_TEXT_FILE_READER_UTILS_H - -#include -#include -#include - -#include "caffe2/core/common.h" - -namespace caffe2 { - -struct Token { - int startDelimId; - const char* start; - const char* end; -}; - -class TokenizedString { - // holder for strings that have been modified - std::vector> modifiedStrings_; - std::vector tokens_; - int lastDelim_; - - public: - const std::vector& tokens() const { - return tokens_; - } - const int lastDelim() const { - return lastDelim_; - } - friend class Tokenizer; -}; - -class Tokenizer { - private: - int startDelimId_; - // state of the tokenizer - std::string leftover_; - // if we need to skip the first characters of the next batch because - // e.g. an escape char that was the last character of the last batch. - int toBeSkipped_; - int delimTable_[256]; - const char escape_; - - public: - Tokenizer(const std::vector& delimiters, char escape); - void reset(); - void next(char* start, char* end, TokenizedString& tokenized); -}; - -struct CharRange { - char* start; - char* end; -}; - -struct StringProvider { - virtual void operator()(CharRange&) = 0; - virtual void reset() = 0; - virtual ~StringProvider() {} -}; - -class BufferedTokenizer { - public: - BufferedTokenizer(const Tokenizer& t, StringProvider* p, int numPasses = 1) - : provider_(p), tokenizer_(t), tokenIndex_(0), numPasses_(numPasses) {} - - bool next(Token& token) { - CharRange range; - while (tokenIndex_ >= tokenized_.tokens().size()) { - range.start = nullptr; - while (range.start == nullptr && pass_ < numPasses_) { - (*provider_)(range); - if (range.start == nullptr) { - ++pass_; - if (pass_ < numPasses_) { - provider_->reset(); - tokenizer_.reset(); - } - } - } - if (range.start == nullptr) { - return false; - } - tokenizer_.next(range.start, range.end, tokenized_); - tokenIndex_ = 0; - } - token = tokenized_.tokens()[tokenIndex_++]; - return true; - }; - - int endDelim() const { - if (tokenIndex_ + 1 < tokenized_.tokens().size()) { - return tokenized_.tokens()[tokenIndex_ + 1].startDelimId; - } - return tokenized_.lastDelim(); - } - - private: - StringProvider* provider_; - Tokenizer tokenizer_; - TokenizedString tokenized_; - int tokenIndex_; - int numPasses_; - int pass_{0}; -}; - -class FileReader : public StringProvider { - public: - explicit FileReader(const std::string& path, size_t bufferSize = 65536); - ~FileReader(); - void operator()(CharRange& range) override; - void reset() override; - - private: - const size_t bufferSize_; - int fd_; - std::unique_ptr buffer_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TEXT_FILE_READER_UTILS_H diff --git a/app/src/main/cpp/caffe2/operators/tile_op.h b/app/src/main/cpp/caffe2/operators/tile_op.h deleted file mode 100644 index 046aaa5..0000000 --- a/app/src/main/cpp/caffe2/operators/tile_op.h +++ /dev/null @@ -1,256 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TILE_OP_H_ -#define CAFFE2_OPERATORS_TILE_OP_H_ - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -// Copy a Blob n times along a specified axis. -template -class TileOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TileOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - tiles_(OperatorBase::GetSingleArgument("tiles", 1)), - axis_(OperatorBase::GetSingleArgument("axis", 0)) {} - ~TileOp() {} - - bool RunOnDevice() override { - const auto& input = Input(0); - std::array temp_params = {{tiles_, axis_}}; - if (InputSize() > 1) { - // We potentially have tiles and/or axis specified as inputs - // as well. We will check for them in that order. In other words: - // InputSize() == 2: tiles is specified - // InputSize() == 3: tiles is specified and axis. - // Anything specified as input will override the arguments - CAFFE_ENFORCE( - Input(1).ndim() == 1 && Input(1).size() == 1, - "Input `tiles` should be a vector of size 1."); - - const auto& input1 = Input(1); - context_.template CopyItems( - input1.meta(), - 1, - static_cast(input1.raw_data()), - &(temp_params[0])); - - if (InputSize() > 2) { - CAFFE_ENFORCE( - Input(2).ndim() == 1 && Input(2).size() == 1, - "Input `axis` should be a vector of size 1."); - - const auto& input2 = Input(2); - context_.template CopyItems( - input2.meta(), - 1, - static_cast(input2.raw_data()), - &(temp_params[1])); - } else { - CAFFE_ENFORCE( - OperatorBase::HasArgument("axis"), - "Argument `axis` is missing and was not specified as input."); - } - } else { - CAFFE_ENFORCE( - OperatorBase::HasArgument("tiles"), - "Argument `tiles` is missing and was not specified as input."); - CAFFE_ENFORCE( - OperatorBase::HasArgument("axis"), - "Argument `axis` is missing and was not specified as input."); - } - - tiles_ = temp_params[0]; - axis_ = temp_params[1]; - - auto* output = Output(0); - const auto axis = input.canonical_axis_index(axis_); - - // reshape output to be input tiled along the axis - vector output_dims(input.dims()); - output_dims[axis_] = output_dims[axis_] * tiles_; - output->Resize(output_dims); - - // size up to (and not including) axis - const auto outer_dim = input.size_to_dim(axis); - // size from axis up - const auto inner_dim = input.size_from_dim(axis); - - /** - * How this works: - * Imagine a 2D tensor (matrix) of size 3x10, tiled 2 times. - * - Tiling along axis 0 (row) means copying the entire 3x10 Matrix 2 - * times. outer_dim = 0, inner_dim = 30. - * - Tiling along axis 1 (column) means copying each row 2 times, then - * proceed to the next row, until the end. outer_dim = 3, inner_dim = 10. - */ - const char* input_data = static_cast(input.raw_data()); - char* output_data = - static_cast(output->raw_mutable_data(input.meta())); - - DoTile( - input.meta(), - input.itemsize(), - outer_dim, - inner_dim, - input_data, - output_data); - - return true; - } - - private: - void DoTile( - const TypeMeta& meta, - int item_size, - int outer_dim, - int inner_dim, - const char* input_data, - char* output_data) { - for (auto i = 0; i < outer_dim; ++i) { - for (auto t = 0; t < tiles_; ++t) { - context_.template CopyItems( - meta, inner_dim, input_data, output_data); - output_data += inner_dim * item_size; - } - input_data += inner_dim * item_size; - } - } - - int32_t tiles_; - int32_t axis_; -}; - -template -class TileGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TileGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - tiles_(OperatorBase::GetSingleArgument("tiles", 1)), - axis_(OperatorBase::GetSingleArgument("axis", 0)) {} - ~TileGradientOp() {} - - bool RunOnDevice() override { - std::array temp_params = {{tiles_, axis_}}; - if (InputSize() > 1) { - // We potentially have tiles and/or axis specified as inputs - // as well. We will check for them in that order. In other words: - // InputSize() == 2: tiles is specified - // InputSize() == 3: tiles is specified and axis. - // Anything specified as input will override the arguments - CAFFE_ENFORCE( - Input(1).ndim() == 1 && Input(1).size() == 1, - "Input `tiles` should be a vector of size 1."); - - const auto& input1 = Input(1); - context_.template CopyItems( - input1.meta(), - 1, - static_cast(input1.raw_data()), - &(temp_params[0])); - - if (InputSize() > 2) { - CAFFE_ENFORCE( - Input(2).ndim() == 1 && Input(2).size() == 1, - "Input `axis` should be a vector of size 1."); - - const auto& input2 = Input(2); - context_.template CopyItems( - input2.meta(), - 1, - static_cast(input2.raw_data()), - &(temp_params[1])); - } else { - CAFFE_ENFORCE( - OperatorBase::HasArgument("axis"), - "Argument `axis` is missing and was not specified as input."); - } - } else { - CAFFE_ENFORCE( - OperatorBase::HasArgument("tiles"), - "Argument `tiles` is missing and was not specified as input."); - CAFFE_ENFORCE( - OperatorBase::HasArgument("axis"), - "Argument `axis` is missing and was not specified as input."); - } - - tiles_ = temp_params[0]; - axis_ = temp_params[1]; - - const auto& input = Input(0); - auto* output = Output(0); - const auto axis = input.canonical_axis_index(axis_); - - // reshape output to be input "untiled" along the axis - vector output_dims(input.dims()); - output_dims[axis_] = output_dims[axis_] / tiles_; - output->Resize(output_dims); - - // size up to (and not including) axis - const auto outer_dim = output->size_to_dim(axis); - // size from axis up - const auto inner_dim = output->size_from_dim(axis); - - /** - * How this works: - * Imagine a 2D tensor (matrix) of size 3x10, tiled 2 times along axis 1 - * (column). - * This is equivalent to multiplying by a vector of 1s transposed. - * The gradient of this is all 1s in the shape of the input matrix - * (call it X). - * So the output gradient should be the matrix multipication result - * of input gradient (gradient of tiled tensor output) and X. - */ - const char* input_data = static_cast(input.raw_data()); - char* output_data = - static_cast(output->raw_mutable_data(input.meta())); - - DoTileGradient( - input.meta(), - input.itemsize(), - outer_dim, - inner_dim, - input_data, - output_data); - - return true; - } - - private: - void DoTileGradient( - const TypeMeta& meta, - int item_size, - int outer_dim, - int inner_dim, - const char* input_data, - char* output_data) { - for (auto i = 0; i < outer_dim; ++i) { - context_.template CopyItems( - meta, inner_dim, input_data, output_data); - input_data += inner_dim * item_size; - for (auto t = 1; t < tiles_; ++t) { - math::Axpy( - inner_dim, - T(1), - reinterpret_cast(input_data), - reinterpret_cast(output_data), - &context_); - input_data += inner_dim * item_size; - } - output_data += inner_dim * item_size; - } - } - - int32_t tiles_; - int32_t axis_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TILE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/top_k.h b/app/src/main/cpp/caffe2/operators/top_k.h deleted file mode 100644 index 3400691..0000000 --- a/app/src/main/cpp/caffe2/operators/top_k.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TOP_K_H_ -#define CAFFE2_OPERATORS_TOP_K_H_ - -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class TopKOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - TopKOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), OP_SINGLE_ARG(int, "k", k_, -1) { - CAFFE_ENFORCE(k_ >= 1, "k argument must be >= 1"); - } - - bool RunOnDevice() override; - - private: - int k_; -}; - -template -class TopKGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - TopKGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TOP_K_H_ diff --git a/app/src/main/cpp/caffe2/operators/transpose_op.h b/app/src/main/cpp/caffe2/operators/transpose_op.h deleted file mode 100644 index baefc5f..0000000 --- a/app/src/main/cpp/caffe2/operators/transpose_op.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TRANSPOSE_H_ -#define CAFFE2_OPERATORS_TRANSPOSE_H_ -#define MAX_BLOB_NUM 1024 - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class TransposeOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - TransposeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - axes_(OperatorBase::GetRepeatedArgument("axes")) { - // We will check the legality of axes_: it should be from 0 to axes_.size(). - std::vector axes_sorted(axes_); - std::sort(axes_sorted.begin(), axes_sorted.end()); - for (int i = 0; i < axes_sorted.size(); ++i) { - if (axes_sorted[i] != i) { - CAFFE_THROW("Axes should be a permutation of 0 to ndim."); - } - } - } - ~TransposeOp() {} - - bool RunOnDevice() override { - const auto& X = Input(0); - auto* Y = Output(0); - new_dims_.resize(X.ndim()); - if (axes_.size() == 0) { - axes_.resize(X.ndim()); - for (int i = 0; i < axes_.size(); ++i) { - axes_[i] = axes_.size() - 1 - i; - } - new_dims_.assign(X.dims().rbegin(), X.dims().rend()); - } else { - CAFFE_ENFORCE_EQ(X.ndim(), axes_.size()); - for (int i = 0; i < new_dims_.size(); ++i) { - new_dims_[i] = X.dim(axes_[i]); - } - } - Y->Resize(new_dims_); - // Do the actual transpose, which is implemented in DoRunWithType(). - return DispatchHelper>::call( - this, Input(0)); - } - - protected: - template - bool DoRunWithType(); - - std::vector axes_; - std::vector new_dims_; - // buffer_ is used in TransposeOp so we can obtain a consistent - // buffer on the GPU. It is not used in the CPUContext implementation. - Tensor buffer_; - TensorCPU buffer_cpu_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TRANSPOSE_H_ diff --git a/app/src/main/cpp/caffe2/operators/tt_linear_op.h b/app/src/main/cpp/caffe2/operators/tt_linear_op.h deleted file mode 100644 index 05653c9..0000000 --- a/app/src/main/cpp/caffe2/operators/tt_linear_op.h +++ /dev/null @@ -1,188 +0,0 @@ -#ifndef CAFFE2_OPERATORS_TT_LINEAR_OP_H_ -#define CAFFE2_OPERATORS_TT_LINEAR_OP_H_ - -#ifdef CAFFE2_USE_MKL -#include -#endif // CAFFE2_USE_MKL - -#include "Eigen/Core" -#include "Eigen/Dense" -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class TTLinearOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTLinearOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - inp_sizes_(OperatorBase::GetRepeatedArgument("inp_sizes")), - out_sizes_(OperatorBase::GetRepeatedArgument("out_sizes")), - tt_ranks_(OperatorBase::GetRepeatedArgument("tt_ranks")), - Y_temp_(unique_ptr(new Blob())) {} - ~TTLinearOp() {} - - bool RunOnDevice() override { - const auto& X = Input(0); // Input array - const auto& b = Input(1); // Bias array - const auto& cores = Input(2); // 1D array containing the TT-cores - auto* Y = Output(0); - - CAFFE_ENFORCE(X.ndim() > 1, "Number of dimensions in X: ", X.ndim()); - CAFFE_ENFORCE(b.ndim() == 1, "Number of dimensions in b: ", b.ndim()); - CAFFE_ENFORCE( - inp_sizes_.size() == out_sizes_.size(), - "inp_sizes has size: ", - inp_sizes_.size(), - ", out_sizes has size: ", - out_sizes_.size()); - CAFFE_ENFORCE( - cores.ndim() == 1, "Number of dimensions in cores: ", cores.ndim()); - // batch size - const int batch_size = X.ndim() > 1 ? X.dim32(0) : 1; - - // dimension d of tensors - const int d = inp_sizes_.size(); - - // Keep track of index of current core in multiplication - int cores_idx = 0; - - // Temporary buffer to facilitate multiplication of TT-cores with input - auto Y_buf = Y_temp_->GetMutable>(); - Y_buf->ResizeLike(X); - Y_buf->CopyFrom(X); - - // The overall forward pass involves multiplication with each core, where - // each core has sizes dictated by inp_sizes_ and out_sizes_. Each core thus - // has size inp_sizes_[i] * tt_ranks_[i] * tt_ranks_[i + 1] * out_sizes_[i]. - for (int i = (d - 1); i >= 0; --i) { - int curr_rows = inp_sizes_[i] * tt_ranks_[i + 1]; - int curr_cols = tt_ranks_[i] * out_sizes_[i]; - - // TODO Replace by Reshape(), once wrappers are written - Y_buf->Resize(Y_buf->size() / curr_rows, curr_rows); - Y->Resize(Y_buf->size() / curr_rows, curr_cols); - - // Defensive checks - CAFFE_ENFORCE(Y_buf->size() % curr_rows == 0, Y_buf->size(), curr_rows); - CAFFE_ENFORCE( - cores_idx + curr_rows * curr_cols <= cores.size(), - cores_idx + curr_rows * curr_cols, - cores.size()); - - // Multiply ith core with the intermediate output - math::Gemm( - CblasNoTrans, - CblasNoTrans, - Y_buf->size() / curr_rows, - curr_cols, - curr_rows, - 1, - Y_buf->template data(), - cores.template data() + cores_idx, - 0, - Y->template mutable_data(), - &context_); - - CAFFE_ENFORCE(Y->size() % out_sizes_[i] == 0, Y->size(), out_sizes_[i]); - - // TODO Add GPU support by writing a generic wrapper. - auto Y_mat = EigenMatrixMap( - Y->template mutable_data(), - Y->size() / out_sizes_[i], - out_sizes_[i]); - Y_mat = ConstEigenMatrixMap( - Y->template data(), - out_sizes_[i], - Y->size() / out_sizes_[i]) - .transpose() - .eval(); - - // Resize operation - Y_buf->Resize(Y->dim32(0), Y->dim32(1)); - context_.template Copy( - Y->size(), - Y->template data(), - Y_buf->template mutable_data()); - - cores_idx += curr_rows * curr_cols; - } - - // TODO Add GPU support by writing a generic wrapper. - auto Y_mat = EigenMatrixMap( - Y->template mutable_data(), batch_size, Y->size() / batch_size); - Y_mat = ConstEigenMatrixMap( - Y->template data(), Y->size() / batch_size, batch_size) - .transpose() - .eval(); - // TODO Replace by Reshape(), once wrappers are written - Y->Resize(batch_size, Y->size() / batch_size); - - // Check that output size of Y is the element-wise product of out_sizes - int prod_out_sizes = 1; - for (int i = 0; i < out_sizes_.size(); i++) { - prod_out_sizes *= out_sizes_[i]; - } - CAFFE_ENFORCE( - Y->dim32(1) == prod_out_sizes, - "Output dimension of Y: ", - Y->dim32(1), - ", product of out_sizes: ", - prod_out_sizes); - - // Add bias term - if (bias_multiplier_.size() != batch_size) { - // If the helper bias multiplier is not M, reshape and fill it with one. - bias_multiplier_.Resize(batch_size); - math::Set( - batch_size, - static_cast(1), - bias_multiplier_.template mutable_data(), - &context_); - } - math::Gemm( - CblasNoTrans, - CblasNoTrans, - Y->dim32(0), - Y->dim32(1), - 1, - 1, - bias_multiplier_.template data(), - b.template data(), - 1, - Y->template mutable_data(), - &context_); - return true; - } - - protected: - Tensor bias_multiplier_; - std::vector inp_sizes_; - std::vector out_sizes_; - std::vector tt_ranks_; - std::unique_ptr Y_temp_; -}; - -// TODO: Complete after verifying utility of TT-layer's forward pass. -template -class TTLinearGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - TTLinearGradientOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - ~TTLinearGradientOp() {} - - bool RunOnDevice() override { - return false; - } - - protected: - Tensor bias_multiplier_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_TT_LINEAR_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/utility_ops.h b/app/src/main/cpp/caffe2/operators/utility_ops.h deleted file mode 100644 index 4cdb9aa..0000000 --- a/app/src/main/cpp/caffe2/operators/utility_ops.h +++ /dev/null @@ -1,1548 +0,0 @@ -#ifndef CAFFE2_OPERATORS_UTILITY_OPS_H_ -#define CAFFE2_OPERATORS_UTILITY_OPS_H_ - -#include - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/types.h" -#include "caffe2/utils/math.h" - -#include -#include - -namespace caffe2 { - -template -class NanCheckOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - NanCheckOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override; - - private: - TensorPrinter tensorPrinter_; - Tensor scratch_; -}; - -struct GetNanCheckGradient : public GradientMakerBase { - using GradientMakerBase::GradientMakerBase; - std::vector GetGradientDefs() override { - return {CreateOperatorDef( - "NanCheck", - "", - std::vector{GO(0)}, - std::vector{GI(0)})}; - } -}; - -template -class WallClockTimeOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - WallClockTimeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - int64_t nanoseconds = static_cast( - std::chrono::duration_cast( - std::chrono::high_resolution_clock::now().time_since_epoch()) - .count()); - - TensorCPU* output = OperatorBase::Output(0); - output->Resize(); - *output->template mutable_data() = nanoseconds; - - return true; - } -}; - -const char kPrintFileExtension[] = ".log"; - -template -class PrintOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_DISPATCH_HELPER; - PrintOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - tensor_printer_( - operator_def.input(0), - OperatorBase::GetSingleArgument("to_file", 0) - ? ws->RootFolder() + "/" + operator_def.input(0) + - kPrintFileExtension - : "", - OperatorBase::GetSingleArgument("limit", 0)), - every_n_(OperatorBase::GetSingleArgument("every_n", 1)) { - CAFFE_ENFORCE_GE(every_n_, 1); - } - - bool RunOnDevice() override { - if (++occurrences_mod_n_ > every_n_) { - occurrences_mod_n_ -= every_n_; - } - if (occurrences_mod_n_ != 1) { - return true; - } - - if (!OperatorBase::InputIsType>(0) && - !OperatorBase::InputIsType(0)) { - LOG(INFO) << "Blob of type: " - << OperatorBase::Inputs().at(0)->meta().name(); - return true; - } - // special-case empty tensors since they may have no meta() - if (Input(0).size() == 0) { - tensor_printer_.PrintMeta(Input(0)); - return true; - } - - using Types = TensorTypes< - float, - double, - int, - long, - bool, - char, - unsigned char, - std::string>; - - if (OperatorBase::InputIsType(0)) { - return DispatchHelper::call( - this, OperatorBase::Input(0)); - } else { - return DispatchHelper::call(this, Input(0)); - } - } - - private: - template - bool DoRunWithType() { - // A simple strategy to copy tensor if needed, and have the tensor pointer - // pointing to the right instantiation. Note that tensor_copy_if_needed - // will handle memory deallocation itself so no smart pointer is needed. - const TensorCPU* tensor; - TensorCPU tensor_copy_if_needed; - if (OperatorBase::InputIsType(0)) { - tensor = &OperatorBase::Input(0); - } else { - tensor_copy_if_needed.CopyFrom(Input(0), &context_); - // Make sure that the copy is finished. - context_.FinishDeviceComputation(); - tensor = &tensor_copy_if_needed; - } - tensor_printer_.Print(*tensor); - return true; - } - - private: - TensorPrinter tensor_printer_; - int every_n_; - int occurrences_mod_n_{0}; -}; - -/** - * @brief Alias op makes the output and the input share the same underlying - * storage. - * - * WARNING: in general, in caffe2's operator interface different tensors should - * have different underlying storage, which is the assumption made by - * components such as the dependency engine and memory optimization. Thus, in - * normal situations you should not use the AliasOp, especially in a normal - * forward-backward pass. - * - * The Alias op is provided so one can achieve true asynchrony, such as - * Hogwild, in a graph. But make sure you understand all the implications - * similar to multi-thread computation before you use it explicitly. - */ -template -class AliasOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(AliasOp); - - bool RunOnDevice() override { - auto& input = Input(0); - CAFFE_ENFORCE_GE(input.size(), 0, "Tensor is not initialized"); - Output(0)->ResizeLike(input); - Output(0)->ShareData(input); - return true; - } -}; - -/** - * @brief Pass inputs to outputs. - * Input: - * DATA - dense tensor. - * Output: - * DATA - same tensor as input. - */ -template -class EnsureDenseOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(EnsureDenseOp) - - bool RunOnDevice() override { - const auto& input = Input(0); - auto* output = Output(0); - CAFFE_ENFORCE_GT(input.ndim(), 0, "Input has to be at least a vector."); - // it is allowed to have the output inplace overwrite the input but also - // allow the output to be copied from the input - if (&input != output) { - output->ResizeLike(input); - output->CopyFrom(input, &context_); - } - return true; - } -}; - -template -class FlattenOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(FlattenOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - CAFFE_ENFORCE_GE( - input.dims().size(), 2, "The rank of the tensor must be >= 2."); - output->Resize(input.dim(0), input.size_from_dim(1)); - context_.template CopyItems( - input.meta(), - input.size(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - return true; - } -}; - -template -class FlattenToVecOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(FlattenToVecOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - CAFFE_ENFORCE_GE( - input.dims().size(), 1, "The rank of the tensor must be >= 1."); - output->Resize(input.size()); - - context_.template CopyItems( - input.meta(), - input.size(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - return true; - } -}; - -// Output gets the data of input(0), but reshapes it like input(1). -template -class ResizeLikeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ResizeLikeOp); - - bool RunOnDevice() override { - auto& input0 = Input(0); - auto& input1 = Input(1); - auto* output = Output(0); - CAFFE_ENFORCE_EQ(input0.size(), input1.size()); - output->ResizeLike(Input(1)); - context_.template CopyItems( - input0.meta(), - input0.size(), - input0.raw_data(), - output->raw_mutable_data(input0.meta())); - return true; - } -}; - -template -class SumOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(SumOp); - - template - bool DoRunWithType() { - auto& input0 = Input(0); - auto* output = Output(0); - if (InputSize() == 1) { - output->CopyFrom(input0, &context_); - return true; - } - output->ResizeLike(input0); - T* output_data = output->template mutable_data(); - // Dimension checking - for (int i = 1; i < InputSize(); ++i) { - if (output->dims() != Input(i).dims()) { - CAFFE_THROW( - "Check failed: output->dims() == Input(i).dims().", - "Description: Input #", - i, - ", input dimension:", - Input(i).dims(), - " should match output dimension: ", - output->dims()); - } - } - - // Add the first two - works if in-place or not. - math::Add( - output->size(), - input0.template data(), - Input(1).template data(), - output_data, - &context_); - // Add remaining. - for (int i = 2; i < InputSize(); ++i) { - math::Add( - output->size(), - output_data, - Input(i).template data(), - output_data, - &context_); - } - return true; - } - - bool RunOnDevice() override { - if (Input(0).template IsType()) { - return DoRunWithType(); - } else if (Input(0).template IsType()) { - return DoRunWithType(); - } else { - CAFFE_THROW( - "Sum operator only supports 32-bit float and ints, but", - " input was of type ", - Input(0).meta().name()); - } - } -}; - -// WeightedSumOp computes the weighted sum of several tensors. The input should -// be in the form X_0, weight_0, X_1, weight_1, ... where X_i all have the same -// shape, and weight_i are size 1 tensors that specifies the weight of each -// vector. Note that if one wants to do in-place computation, it could only be -// done with X_0 also as the output, but not other X_i. -template -class WeightedSumOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(WeightedSumOp); - - template - bool DoRunWithType() { - CAFFE_ENFORCE_EQ(InputSize() % 2, 0); - auto& X0 = Input(0); - auto& weight0 = Input(1); - CAFFE_ENFORCE_GT(X0.size(), 0); - CAFFE_ENFORCE_EQ(weight0.size(), 1); - int size = X0.size(); - auto* output = Output(0); - output->ResizeLike(X0); - math::Scale( - size, - weight0.template data(), - X0.template data(), - output->template mutable_data(), - &context_); - for (int i = 2; i < InputSize(); i += 2) { - auto& X = Input(i); - // Do a check: if the input is the same as output, we have a problem - - // in-place update should always only happen with the zeroth input. - if (&X == output) { - LOG(ERROR) << "Input #" << i << " is the same as output. " - << "If you want to do in-place updates, put the output as " - << "input #0."; - return false; - } - auto& weight = Input(i + 1); - CAFFE_ENFORCE_EQ(X.size(), size); - CAFFE_ENFORCE_EQ(weight.size(), 1); - math::Axpy( - size, - weight.template data(), - X.template data(), - output->template mutable_data(), - &context_); - } - return true; - } - bool RunOnDevice() override; -}; - -/** - * @brief Update slices of the tensor in-place with weighted sum. - * - * ScatterWeightedSumOp is similar to WeightedSum and computes the weighted sum - * of several tensors. The first tensor has to be in-place and only slices of it - * on the first dimension as indexed by INDICES will be updated. - * - * Input: - * X_0 - tensor to be updated - * weight_0 - scalar weight for X_0, applied only to slices affected, - * INDICES - 1-D list of indices on the first dimension of X_0 that need to be - * updated - * X_1 - update slices, has to have shape of len(INDICES) + shape(X_0)[1:] - * weight_1 - scalar weight for X_1 update - * X_2, weight_2, ... - * - * Output: - * X_0 - has to be exactly the same tensor as the input 0 - * - * Note: The op pretty much ignores the exact shapes of the input arguments and - * cares only about sizes. It's done for performance consideration to avoid - * unnecessary reshapes. Only first dimension of X_0 is important, let's call it - * N. If M is the total size of X_0 and K is the size of INDICES then X_i is - * assumed to be of shape K x (M / N) regardless of the real shape. - * - * Note: Each update in INDICES is applied independently which means that if - * duplicated elements are present in INDICES the corresponding slice of X_0 - * will be scaled multiple times. Manual collapsing of INDICES is required - * beforehand if necessary. - * - * Note: Updates are applied sequentially by inputs which might have undesired - * consequences if the input tensor is accessed concurrently by different op - * (e.g. when doing Hogwild). Other threads might see intermediate results even - * on individual slice level, e.g. X_0 scaled by weight_0 but without any - * updates applied. - * - * For now really works only on CPU because of INDICES access - */ -template -class ScatterWeightedSumOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ScatterWeightedSumOp); - USE_DISPATCH_HELPER; - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(2)); - } - - private: - template - bool DoRunWithType() { - TIndex block_size = Input(0).size_from_dim(1); - return DispatchHelper, Index>::call(this, block_size); - } - - template - bool DoRunWithValue() { - CAFFE_ENFORCE_EQ(InputSize() % 2, 1); - auto& X0 = Input(0); - auto& weight0 = Input(1); - auto& indices = Input(2); - auto* output = Output(0); - CAFFE_ENFORCE_EQ(&X0, output, "In place operation is required"); - - CAFFE_ENFORCE_GT(X0.size(), 0); - CAFFE_ENFORCE_GT(X0.ndim(), 0, "X0 has to be at least the vector"); - CAFFE_ENFORCE_EQ(weight0.size(), 1); - TIndex M = X0.size(); - TIndex N = X0.dim(0); - TIndex K = indices.size(); - TIndex block_size = M / N; - T* data = output->template mutable_data(); - const Index* idxs = indices.template data(); - T w0 = *weight0.template data(); - // It's most likely a constant so exact comparison is fine - if (w0 != 1.0) { - for (int i = 0; i < K; ++i) { - Index idx = idxs[i]; - CAFFE_ENFORCE( - 0 <= idx && idx < N, - "Index out of bounds: ", - idx, - ", range 0 to ", - N); - math::ScaleFixedSize( - block_size, - w0, - data + block_size * idx, - data + block_size * idx, - &context_); - } - } - for (int inp = 3; inp < InputSize(); inp += 2) { - auto& X = Input(inp); - auto& weight = Input(inp + 1); - CAFFE_ENFORCE_EQ(X.size(), block_size * K); - CAFFE_ENFORCE_EQ(weight.size(), 1); - const T* x_data = X.template data(); - T w = *weight.template data(); - for (int i = 0; i < K; ++i) { - Index idx = idxs[i]; - // double-checking the indices, but it's fine as it's DCHECK only - DCHECK(0 <= idx && idx < N) << "Index out of bounds: " << idx - << ", range 0 to " << N; - math::AxpyFixedSize( - block_size, - w, - x_data + block_size * i, - data + block_size * idx, - &context_); - } - } - return true; - } - Tensor x_data_host_; - Tensor weights_host_; - Tensor x_data_device_; - Tensor weights_device_; -}; - - -template -class MaxOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(MaxOp); - - bool RunOnDevice() override { - auto& input0 = Input(0); - auto* output = Output(0); - - output->ResizeLike(input0); - output->CopyFrom(input0, &context_); - - if (InputSize() == 1) { - return true; - } - - // Dimension checking - for (int i = 1; i < InputSize(); ++i) { - CAFFE_ENFORCE_EQ( - output->dims(), - Input(i).dims(), - "Description: Input #", - i, - ", input dimension:", - Input(i).dims(), - " should match output dimension: ", - output->dims()); - } - - return Compute(); - } - - virtual bool Compute(); -}; - -template -class MaxGradientOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(MaxGradientOp); - - bool RunOnDevice() override; -}; - -/** - * @brief Update slices of the tensor in-place by overriding. - * - * Input: - * DATA - tensor to be updated - * INDICES - 1-D list of indices on the first dimension of X_0 that need to be - * updated - * SLICES - update slices, has to have shape of len(INDICES) + shape(X_0)[1:] - * - * Output: - * DATA - has to be exactly the same tensor as the input 0 - * - * Note: The op pretty much ignores the exact shapes of the input arguments and - * cares only about sizes. It's done for performance consideration to avoid - * unnecessary reshapes. Only first dimension of X_0 is important, let's call it - * N. If M is the total size of X_0 and K is the size of INDICES then X_i is - * assumed to be of shape K x (M / N) regardless of the real shape. - * - * Note: Each update in INDICES is applied independently which means that if - * duplicated elements are present in INDICES arbitrary one will win. - * - * For now really works only on CPU because of INDICES access - */ -template -class ScatterAssignOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - virtual ~ScatterAssignOp() {} - - ScatterAssignOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - runners_({{{TensorProto_DataType_INT32, TensorProto_DataType_FLOAT}, - &ScatterAssignOp::DoRun}, - {{TensorProto_DataType_INT32, TensorProto_DataType_FLOAT16}, - &ScatterAssignOp::DoRun}, - {{TensorProto_DataType_INT64, TensorProto_DataType_FLOAT}, - &ScatterAssignOp::DoRun}, - {{TensorProto_DataType_INT64, TensorProto_DataType_FLOAT16}, - &ScatterAssignOp::DoRun}}) {} - - bool RunOnDevice() override { - const auto& data = Input(DATA); - const auto& slices = Input(SLICES); - auto& indices = Input(INDICES); - - const auto dataType = TypeMetaToDataType(data.meta()); - const auto slicesType = TypeMetaToDataType(slices.meta()); - const auto indicesType = TypeMetaToDataType(indices.meta()); - auto* output = Output(0); - - auto runner = GetRunner(dataType, slicesType, indicesType); - (this->*runner)(); - return true; - } - - private: - typedef void (ScatterAssignOp::*RunnerType)(); - typedef std:: - map, RunnerType> - RunnerMap; - - RunnerMap runners_; - - RunnerType GetRunner( - const TensorProto_DataType dataType, - const TensorProto_DataType slicesType, - const TensorProto_DataType indicesType) { - CAFFE_ENFORCE_EQ(dataType, slicesType, "Data and slice types must match"); - auto it = runners_.find({indicesType, dataType}); - CAFFE_ENFORCE( - it != runners_.end(), - "Could not find the runner corresponding to indicesType, dataType = ", - indicesType, - " ", - dataType); - return it->second; - } - - template - void DoRun() { - auto& input = Input(DATA); - auto& indices = Input(INDICES); - auto& slices = Input(SLICES); - auto* output = Output(0); - CAFFE_ENFORCE_EQ(&input, output, "In place operation is required"); - - CAFFE_ENFORCE_GT(input.ndim(), 0, "X0 has to be at least the vector"); - TIndex M = input.size(); - TIndex N = input.dim(0); - TIndex K = indices.size(); - TIndex block_size = M / N; - CAFFE_ENFORCE_EQ(slices.size(), block_size * K); - // TODO(dzhulgakov): it can be made to work with arbitrary data type by - // using raw_mutable_data - T* data = output->template mutable_data(); - const Index* idxs = indices.template data(); - const T* slicesData = slices.template data(); - for (int i = 0; i < K; ++i) { - Index idx = idxs[i]; - // double-checking the indices, but it's fine as it's DCHECK only - DCHECK(0 <= idx && idx < N) << "Index out of bounds: " << idx - << ", range 0 to " << N; - context_.template Copy( - block_size, slicesData + block_size * i, data + block_size * idx); - } - } - - INPUT_TAGS(DATA, INDICES, SLICES); -}; - -template -class CopyOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(CopyOp); - - bool RunOnDevice() override { - auto& input = OperatorBase::Input>(0); - auto* output = OperatorBase::Output>(0); - output->ResizeLike(input); - this->context_.template CopyItems( - input.meta(), - input.size(), - input.raw_data(), - output->raw_mutable_data(input.meta())); - return true; - } -}; - -template -class CopyOnDeviceLikeOp : public CopyOp { - public: - CopyOnDeviceLikeOp(const OperatorDef& operator_def, Workspace* ws) - : CopyOp(operator_def, ws) {} -}; - -template -class LengthsToSegmentIdsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsToSegmentIdsOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - auto* input_data = input.template data(); - - CAFFE_ENFORCE(input.dims().size() == 1, "Input must be a vector."); - auto total_length = - std::accumulate(input_data, input_data + input.size(), 0); - - output->Resize(total_length); - auto* output_data = output->template mutable_data(); - - for (int i = 0; i < input.size(); ++i) { - auto len = input_data[i]; - std::fill(output_data, output_data + len, i); - output_data += len; - } - return true; - } -}; - -template -class LengthsToRangesOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsToRangesOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - auto* input_data = input.template data(); - - CAFFE_ENFORCE(input.dims().size() == 1, "Input must be a vector."); - auto size = input.size(); - - output->Resize(size, 2); - auto* output_data = output->template mutable_data(); - - int32_t offset = 0; - for (int i = 0; i < size; ++i) { - auto len = input_data[i]; - output_data[i * 2] = offset; - output_data[i * 2 + 1] = len; - offset += len; - } - return true; - } -}; - -template -class SegmentIdsToLengthsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(SegmentIdsToLengthsOp); - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - if (input.ndim() == 2) { - CAFFE_ENFORCE( - input.dim32(0) == 1 || input.dim32(1) == 1, - "Input must be a vector."); - } else { - CAFFE_ENFORCE_EQ(input.ndim(), 1, "Input must be a vector."); - } - auto* input_data = input.template data(); - auto input_size = input.size(); - auto* output = Output(0); - // segment id starts from 0 - auto num_segments = input_size ? input_data[input_size - 1] + 1 : 0; - if (InputSize() > 1) { - CAFFE_ENFORCE_GE(Input(1).ndim(), 1); - CAFFE_ENFORCE_LE( - num_segments, - Input(1).dim(0), - "The number of segments inferred should *NOT* be larger " - "than the size of Input(1)'s first dimension"); - num_segments = Input(1).dim(0); - } - CAFFE_ENFORCE(0 <= num_segments, "Indices must be in 0..K-1 range"); - output->Resize(num_segments); - auto* output_data = output->template mutable_data(); - if (num_segments == 0) { - return true; - } - std::fill(output_data, output_data + num_segments, 0); - Index prev = 0; // Assume that segment_id >= 0. - for (int64_t i = 0; i < input_size; i++) { - CAFFE_ENFORCE( - prev <= input_data[i], - "Segment ids must be sorted: ", - prev, - " vs ", - input_data[i]); - prev = input_data[i]; - output_data[input_data[i]] += 1; - } - - return true; - } -}; - -template -class SegmentIdsToRangesOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(SegmentIdsToRangesOp); - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - CAFFE_ENFORCE(input.dims().size() == 1, "Input must be a vector."); - auto* input_data = input.template data(); - auto input_size = input.size(); - auto* output = Output(0); - // segment id starts from 0 - auto num_segments = input_size ? input_data[input_size - 1] + 1 : 0; - if (InputSize() > 1) { - CAFFE_ENFORCE_GE(Input(1).ndim(), 1); - CAFFE_ENFORCE_LE( - num_segments, - Input(1).dim(0), - "The number of segments inferred should *NOT* be larger " - "than the size of Input(1)'s first dimension"); - num_segments = Input(1).dim(0); - } - CAFFE_ENFORCE(0 <= num_segments, "Indices must be in 0..K-1 range"); - output->Resize(num_segments, 2); - auto* output_data = output->template mutable_data(); - if (num_segments == 0) { - return true; - } - std::fill(output_data, output_data + num_segments * 2, 0); - Index prev = input_data[0]; - for (int64_t i = 0; i < input_size; i++) { - CAFFE_ENFORCE( - prev <= input_data[i], - "Segment ids must be sorted: ", - prev, - " vs ", - input_data[i]); - while (prev != input_data[i]) { - ++prev; - output_data[prev * 2] = i; - } - output_data[input_data[i] * 2 + 1] += 1; - } - - return true; - } -}; - -template -class LengthsToWeightsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - LengthsToWeightsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - power_(OperatorBase::GetSingleArgument("power", 0.5)) {} - - bool RunOnDevice() override { - return DispatchHelper>::call(this, Input(0)); - } - - template - bool DoRunWithType() { - auto& input = Input(0); - CAFFE_ENFORCE(input.dims().size() == 1, "Input must be a vector."); - auto* input_data = input.template data(); - auto input_size = input.size(); - auto* output = Output(0); - - int64_t output_size = 0; - for (auto i = 0; i < input_size; i++) { - CAFFE_ENFORCE_GE(input_data[i], 0, "unexpected negative length value"); - output_size += input_data[i]; - } - - std::function getWeight; - if (power_ == 0.5) { - getWeight = [](const int64_t& length, const float& /*power*/) { - return 1.0 / std::sqrt(length); - }; - } else if (power_ == 1) { - getWeight = [](const int64_t& length, const float& /*power*/) { - return 1.0 / length; - }; - } else { - getWeight = [](const int64_t& length, const float& power) { - return 1.0 / std::pow(length, power); - }; - } - - output->Resize(output_size); - auto* output_data = output->template mutable_data(); - int64_t cnt = 0; - for (auto i = 0; i < input_size; i++) { - auto len = input_data[i]; - if (len == 0) { - continue; - } - CAFFE_ENFORCE_LE(cnt + len, output_size, "unexpected lengths value"); - - float weight_value = getWeight(len, power_); - std::fill(output_data + cnt, output_data + cnt + len, weight_value); - cnt += len; - } - - return true; - } - - private: - float power_; -}; - -template -class HasElementsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(HasElementsOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = input.size() > 0; - return true; - } -}; - -template -class IsEmptyOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(IsEmptyOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = OperatorBase::Output(0); - output->Resize(std::vector{}); - *output->template mutable_data() = (input.size() == 0); - return true; - } -}; - -// Return the size of a tensor -template -class SizeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(SizeOp); - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - - output->Resize(vector()); - auto* output_data = output->template mutable_data(); - - auto size = input.size(); - math::Set( - 1, static_cast(size), output_data, &context_); - - return true; - } -}; - -// returns a shape to be passed to Reshape -template -class LengthsToShapeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsToShapeOp); - - bool RunOnDevice() override { - auto& input = Input(0); - - CAFFE_ENFORCE(input.dims().size() == 1, "Input must be a vector."); - auto* output = Output(0); - auto* input_data = input.template data(); - - auto size = input.size(); - auto first = input_data[0]; - - for (int i = 1; i < size; i++) { - CAFFE_ENFORCE( - input_data[i] == first, "All elements of input must be same "); - } - - output->Resize(2); - auto* output_data = output->template mutable_data(); - output_data[0] = size; - output_data[1] = first; - - return true; - } -}; - -template -class SqueezeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SqueezeOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - dims_(OperatorBase::GetRepeatedArgument("dims")) { - auto originalSize = dims_.size(); - CAFFE_ENFORCE(originalSize > 0, "Parameter `dims` must be provided."); - - std::sort(dims_.begin(), dims_.end()); - dims_.erase(std::unique(dims_.begin(), dims_.end()), dims_.end()); - if (dims_.size() < originalSize) { - LOG(WARNING) << "Parameter `dims` has repeated dimensions."; - } - CAFFE_ENFORCE(dims_.front() >= 0, "Dimension ids must be non-negative."); - } - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - output->CopyFrom(input, &context_); - - CAFFE_ENFORCE_GT( - input.ndim(), - dims_.back(), - "Input needs at least ", - (dims_.back() + 1), - " dimensions."); - - std::vector newDims = ComputeDims(input.dims(), dims_); - output->Reshape(newDims); - return true; - } - - static std::vector ComputeDims( - std::vector inputDims, - std::vector dims) { - int j = 0; - std::vector newDims; - for (int i = 0; i < inputDims.size(); ++i) { - if (j < dims.size() && dims[j] == i) { - CAFFE_ENFORCE_EQ( - inputDims[i], - 1, - "Dimension ", - i, - " of input must be 1", - " instead of ", - inputDims[i], - "."); - ++j; - continue; - } - newDims.push_back(inputDims.at(i)); - } - return newDims; - } - - private: - vector dims_; - - public: - DISABLE_COPY_AND_ASSIGN(SqueezeOp); -}; - -template -class ExpandDimsOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - ExpandDimsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - dims_(OperatorBase::GetRepeatedArgument("dims")) { - auto originalSize = dims_.size(); - CAFFE_ENFORCE(originalSize > 0, "Parameter `dims` must be provided."); - std::sort(dims_.begin(), dims_.end()); - dims_.erase(std::unique(dims_.begin(), dims_.end()), dims_.end()); - if (dims_.size() < originalSize) { - LOG(WARNING) << "Parameter `dims` has repeated dimensions."; - } - CAFFE_ENFORCE(dims_.front() >= 0, "Dimension ids must be non-negative."); - } - - bool RunOnDevice() override { - auto& input = Input(0); - auto* output = Output(0); - output->CopyFrom(input, &context_); - if (dims_.empty()) { - return true; - } - - auto newDims = input.dims(); - CAFFE_ENFORCE_GE( - input.dims().size() + dims_.size(), - dims_.back() + 1, - "Input needs at least ", - (1 + dims_.back() - dims_.size()), - " dimensions given `dims`."); - for (const auto dim : dims_) { - newDims.insert(newDims.begin() + dim, 1); - } - output->Reshape(newDims); - return true; - } - - private: - vector dims_; -}; - -template -class GatherOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(GatherOp); - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(INDICES)); - } - - template - bool DoRunWithType() { - // If we endup using it on GPU doing O(N) memcpy is probably not best :) - // TODO: implement prefetching if it starts mattering (TF does it) - auto& data = Input(DATA); - auto& indices = Input(INDICES); - auto* output = Output(0); - - CAFFE_ENFORCE_GE(data.ndim(), 1, "DATA should be at least 1-D"); - auto shape = indices.dims(); - shape.insert(shape.end(), data.dims().begin() + 1, data.dims().end()); - output->Resize(shape); - - int block_size = data.size_from_dim(1); - auto block_bytesize = data.size_from_dim(1) * data.meta().itemsize(); - int N = indices.size(); - - auto src_base = static_cast(data.raw_data()); - const Index* idxs = indices.template data(); - auto out = static_cast(output->raw_mutable_data(data.meta())); - - for (int i = 0; i < N; ++i) { - auto idx = idxs[i]; - CAFFE_ENFORCE( - 0 <= idx && idx < data.dim(0), - "INDICES element is out of DATA bounds, id=", - idx, - " data_dim=", - data.dim(0)); - auto src = src_base + idx * block_bytesize; - context_.template CopyItems( - data.meta(), block_size, src, out + block_bytesize * i); - } - return true; - } - - INPUT_TAGS(DATA, INDICES); -}; - -template -class GatherRangesOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(GatherRangesOp); - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(RANGES)); - } - - template - bool DoRunWithType() { - auto& data = Input(DATA); - auto& ranges = Input(RANGES); - auto* outputData = Output(0); - auto* outputLengths = Output(1); - - auto batchSize = ranges.dim(0); - CAFFE_ENFORCE(data.ndim() == 1, "Data has to be 1-D"); - CAFFE_ENFORCE(ranges.ndim() == 3, "Ranges must be 3-D"); - CAFFE_ENFORCE(ranges.dim(1) > 0, "There has to be at least one range"); - CAFFE_ENFORCE_EQ( - ranges.dim(2), 2, "Ranges last dimention should be of size 2"); - - auto* rawData = static_cast(data.raw_data()); - auto* rangesData = ranges.template data(); - - outputLengths->Resize(batchSize); - auto* outputLengthsPtr = outputLengths->template mutable_data(); - size_t start = 0; - size_t blockSize = ranges.size_from_dim(1); - for (size_t i = 0; i < batchSize; ++i) { - auto end = start + blockSize; - outputLengthsPtr[i] = accumulate(rangesData, start, end); - start = end; - } - - size_t outputSize = accumulate(rangesData, 0, ranges.size()); - outputData->Resize(outputSize); - - auto outputRawData = - static_cast(outputData->raw_mutable_data(data.meta())); - VLOG(1) << "Copying data"; - size_t outputOffsetBytes = 0; - auto itemsize = data.meta().itemsize(); - for (int i = 0; i < ranges.size(); i += 2) { - auto rangeStart = rangesData[i]; - auto rangeLength = rangesData[i + 1]; - if (!rangeLength) { - continue; - } - auto rangeSizeBytes = rangeLength * itemsize; - CAFFE_ENFORCE(outputOffsetBytes < outputSize * itemsize); - CAFFE_ENFORCE(rangeStart + rangeLength <= data.size()); - context_.template CopyItems( - data.meta(), - rangeLength, - rawData + rangeStart * itemsize, - outputRawData + outputOffsetBytes); - outputOffsetBytes += rangeSizeBytes; - } - CAFFE_ENFORCE(outputOffsetBytes == outputSize * itemsize); - return true; - } - - INPUT_TAGS(DATA, RANGES, LENGTHS); - - private: - template - size_t accumulate(Index* ranges, size_t start, size_t end) { - size_t result = 0; - for (int i = start + 1; i < end; i += 2) { - result += ranges[i]; - } - return result; - } -}; - -template -class LengthsGatherOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(LengthsGatherOp); - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, OperatorBase::Input(INDICES)); - } - - template - bool DoRunWithType() { - auto& items = Input(ITEMS); - auto& lengths = Input(LENGTHS); - auto& indices = Input(INDICES); - auto* output = Output(0); - - CAFFE_ENFORCE_GE(items.ndim(), 1, "ITEMS should be at least 1-D"); - CAFFE_ENFORCE_EQ(lengths.ndim(), 1, "LENGTHS should be 1-D"); - CAFFE_ENFORCE_EQ(indices.ndim(), 1, "INDICES should be 1-D"); - - const auto* lengths_data = lengths.template data(); - const auto* indices_data = indices.template data(); - - TIndex total_length = 0; - for (size_t i = 0; i < indices.size(); ++i) { - auto idx = indices_data[i]; - CAFFE_ENFORCE_LT(idx, lengths.size()); - total_length += lengths_data[idx]; - } - auto shape = items.dims(); - shape[0] = total_length; - output->Resize(shape); - - offsets_.clear(); - TIndex running_offset = 0; - offsets_.reserve(lengths.size()); - for (size_t i = 0; i < lengths.size(); ++i) { - offsets_.push_back(running_offset); - running_offset += lengths_data[i]; - } - CAFFE_ENFORCE_EQ( - items.dim(0), - running_offset, - "LENGTHS must match the first dimension of ITEMS"); - - auto src_base = static_cast(items.raw_data()); - auto block_size = items.size_from_dim(1); - auto block_bytesize = block_size * items.itemsize(); - auto out = static_cast(output->raw_mutable_data(items.meta())); - - for (size_t i = 0; i < indices.size(); ++i) { - auto idx = indices_data[i]; - auto length = lengths_data[idx]; - context_.template CopyItems( - items.meta(), - length * block_size, - src_base + offsets_[idx] * block_bytesize, - out); - out += length * block_bytesize; - } - return true; - } - - std::vector offsets_; - - INPUT_TAGS(ITEMS, LENGTHS, INDICES); -}; - -// Since we just do copying, consider untemplating it on T and using raw_data() -/** - * Deduplicates input indices vector and optionally produces reverse remapping. - * Current implementation produces a sorted list but it's not guaranteed in - * general. - */ -template -class UniqueOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(UniqueOp); - - bool RunOnDevice() override { - // Use run-time polymorphism - auto& input = Input(0); - if (input.template IsType()) { - DoRun(); - } else if (input.template IsType()) { - DoRun(); - } else { - LOG(FATAL) << "Unsupported type of input in Unique: " - << input.meta().name(); - } - return true; - } - - private: - vector order_; - Tensor thrust_unique_buffer_; - Tensor cuda_order_buffer_; - Tensor second_order_buffer_; - - template - void DoRun(); - - public: - OUTPUT_TAGS(UNIQUE, REMAPPING); -}; - -template -class UnsafeCoalesceOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - - bool RunOnDevice() override { - size_t coalesced_size = 0; - for (int i = 0; i < InputSize(); ++i) { - CAFFE_ENFORCE( - !Input(i).meta().ctor(), - "Must only coalesce fundamental types, error at input: ", - i); - } - - auto roundToAlignment = [](size_t bytes) -> size_t { - return ((bytes + gCaffe2Alignment - 1) / gCaffe2Alignment) * - gCaffe2Alignment; - }; - - for (int i = 0; i < InputSize(); ++i) { - coalesced_size += roundToAlignment(Input(i).nbytes()); - } - - auto* coalesced = Output(OutputSize() - 1); - coalesced->Resize(coalesced_size); - math::Set( - coalesced_size, - 0.0, - coalesced->template mutable_data(), - &context_); - - size_t coalesced_offset = 0; - for (auto i = 0; i < InputSize(); ++i) { - const auto input_nbytes = Input(i).nbytes(); - context_.template CopyBytes( - input_nbytes, - (const uint8_t*)Input(i).raw_data(), - coalesced->template mutable_data() + coalesced_offset); - - // Note: this could cause Input(i) to free it's data if - // Output(i) and Input(i) alias each other. This is safe on a - // GPU (as the copy will happen-before the free), but it's - // worth mentioning. - - Output(i)->ResizeLike(Input(i)); - Output(i)->ShareExternalPointer( - static_cast( - coalesced->template mutable_data() + coalesced_offset), - Input(i).meta(), - input_nbytes); - coalesced_offset += roundToAlignment(input_nbytes); - } - return true; - } -}; - -template -class AccumulateHistogramOp : public Operator { - public: - AccumulateHistogramOp(const OperatorDef& def, Workspace* ws) - : Operator(def, ws), - lower_bound_( - OperatorBase::GetSingleArgument("lower_bound", 0.0)), - upper_bound_( - OperatorBase::GetSingleArgument("upper_bound", 1.0)), - num_buckets_(OperatorBase::GetSingleArgument("num_buckets", 1)) { - CAFFE_ENFORCE_GT(num_buckets_, 0); - // 2 more for histograms < lower_bound, >= upper_bound respectively - num_output_buckets_ = num_buckets_ + 2; - accumulate_hist_ = std::vector(num_output_buckets_, 0); - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - auto& X = Input(X_IN); - auto* X_data = X.template data(); - int N = X.size(); - auto* cur_hist = Output(CUR_HIST); - auto* acc_hist = Output(ACC_HIST); - cur_hist->Resize(num_output_buckets_); - acc_hist->Resize(num_output_buckets_); - auto* cur_hist_data = cur_hist->template mutable_data(); - auto* acc_hist_data = acc_hist->template mutable_data(); - auto segment = (upper_bound_ - lower_bound_) / num_buckets_; - math::Set( - num_output_buckets_, 0, cur_hist_data, &context_); - - for (int i = 0; i < N; i++) { - int bucket_index = -1; - if (X_data[i] < lower_bound_) { - bucket_index = 0; - } else if (X_data[i] >= upper_bound_) { - bucket_index = num_buckets_ + 1; - } else { - bucket_index = (int)((X_data[i] - lower_bound_) / segment) + 1; - } - cur_hist_data[bucket_index] += 1; - accumulate_hist_[bucket_index] += 1; - } - - for (int i = 0; i < num_output_buckets_; i++) { - acc_hist_data[i] = accumulate_hist_[i]; - } - - return true; - } - - private: - float lower_bound_; - float upper_bound_; - int num_buckets_; - int num_output_buckets_; - std::vector accumulate_hist_; - - INPUT_TAGS(X_IN); - OUTPUT_TAGS(CUR_HIST, ACC_HIST); -}; - -template -class RangeOp : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(RangeOp) - - bool RunOnDevice() override { - return DispatchHelper>::call( - this, Input(0)); - } - - template - T readScalarInput(const int index) { - if (std::is_same::value) { - return Input(index).template data()[0]; - } else { - local_.template CopyFrom(Input(index)); - return local_.template data()[0]; - } - } - - template - bool DoRunWithType() { - T stop = 0; - T start = 0; - T step = 1; - - for (int i = 0; i < InputSize(); ++i) { - CAFFE_ENFORCE_EQ(Input(0).ndim(), 0, "All inputs must be scalar."); - } - - switch (InputSize()) { - case 1: - stop = readScalarInput(0); - break; - case 2: - start = readScalarInput(0); - stop = readScalarInput(1); - break; - case 3: - step = readScalarInput(2); - start = readScalarInput(0); - stop = readScalarInput(1); - break; - } - CAFFE_ENFORCE_NE(step, 0, "Step size cannot be 0."); - int length; - auto diff = stop - start; - if (std::is_integral::value) { - // Avoid casting to and from floats in case it introduces rounding and - // avoid mod because the compiler doesn't strip unused code until later. - length = diff / step; - if (length * step < diff) { - length += 1; - } - } else { - length = static_cast(ceil(diff / step)); - } - auto* output = Output(0); - // Match numpy's behavior here. - if (length <= 0) { - output->Resize(0); - // Called for the side effect of setting the data. - output->template mutable_data(); - return true; - } else { - output->Resize(length); - return DoRunOnDevice(start, step, output); - } - } - - template - bool DoRunOnDevice(const T& start, const T& step, Tensor* output); - - private: - // local CPU tensor for copying constants. - TensorCPU local_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_UTILITY_OPS_H_ diff --git a/app/src/main/cpp/caffe2/operators/while_op.h b/app/src/main/cpp/caffe2/operators/while_op.h deleted file mode 100644 index f3a36c9..0000000 --- a/app/src/main/cpp/caffe2/operators/while_op.h +++ /dev/null @@ -1,47 +0,0 @@ -#ifndef CAFFE2_OPERATORS_WHILE_OP_H_ -#define CAFFE2_OPERATORS_WHILE_OP_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class WhileOp final : public Operator { - public: - WhileOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - CAFFE_ENFORCE( - this->template HasSingleArgumentOfType("loop_net"), - "loop_net must be specified in While operator"); - loop_net_def_ = - this->template GetSingleArgument("loop_net", NetDef()); - loop_net_ = CreateNet(loop_net_def_, ws); - CAFFE_ENFORCE(loop_net_, "Failed to initialize loop subnet"); - - cond_net_ = nullptr; - bool has_cond_net = - this->template HasSingleArgumentOfType("cond_net"); - if (has_cond_net) { - cond_net_def_ = - this->template GetSingleArgument("cond_net", NetDef()); - cond_net_ = CreateNet(cond_net_def_, ws); - CAFFE_ENFORCE(cond_net_, "Failed to initialize condition subnet"); - } - } - - USE_OPERATOR_CONTEXT_FUNCTIONS; - bool RunOnDevice() override; - - private: - NetDef loop_net_def_; - std::unique_ptr loop_net_; - - NetDef cond_net_def_; - std::unique_ptr cond_net_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_OPERATORS_WHILE_OP_H_ diff --git a/app/src/main/cpp/caffe2/operators/zero_gradient_op.h b/app/src/main/cpp/caffe2/operators/zero_gradient_op.h deleted file mode 100644 index ed664fb..0000000 --- a/app/src/main/cpp/caffe2/operators/zero_gradient_op.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class ZeroGradientOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - USE_SIMPLE_CTOR_DTOR(ZeroGradientOp); - - bool RunOnDevice() override { - return true; - } -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/perfkernels/common.h b/app/src/main/cpp/caffe2/perfkernels/common.h deleted file mode 100644 index 22334e0..0000000 --- a/app/src/main/cpp/caffe2/perfkernels/common.h +++ /dev/null @@ -1,83 +0,0 @@ -// Common utilities for writing performance kernels and easy dispatching of -// different backends. -/* -The general workflow shall be as follows, say we want to -implement a functionality called void foo(int a, float b). - -In foo.h, do: - void foo(int a, float b); - -In foo_avx2.cc, do: - void foo__avx2(int a, float b) { - [actual avx2 implementation] - } - -In foo_avx.cc, do: - void foo__avx(int a, float b) { - [actual avx implementation] - } - -In foo.cc, do: - // The base implementation should *always* be provided. - void foo__base(int a, float b) { - [base, possibly slow implementation] - } - void foo(int a, float b) { - // You should always order things by their preference, faster - // implementations earlier in the function. - AVX2_DO(foo, a, b); - AVX_DO(foo, a, b); - BASE_DO(foo, a, b); - } - -*/ -// Details: this functionality basically covers the cases for both build time -// and run time architecture support. -// -// During build time: -// The build system should provide flags CAFFE2_PERF_WITH_AVX2 and -// CAFFE2_PERF_WITH_AVX that corresponds to the __AVX__ and __AVX2__ flags -// the compiler provides. Note that we do not use the compiler flags but -// rely on the build system flags, because the common files (like foo.cc -// above) will always be built without __AVX__ and __AVX2__. -// During run time: -// we use cpuid to identify cpu support and run the proper functions. - -#pragma once - -// DO macros: these should be used in your entry function, similar to foo() -// above, that routes implementations based on CPU capability. - -#define BASE_DO(funcname, ...) return funcname##__base(__VA_ARGS__); - -#ifdef CAFFE2_PERF_WITH_AVX2 -#define AVX2_DO(funcname, ...) \ - decltype(funcname##__base) funcname##__avx2; \ - if (GetCpuId().avx2()) { \ - return funcname##__avx2(__VA_ARGS__); \ - } -#define AVX2_FMA_DO(funcname, ...) \ - decltype(funcname##__base) funcname##__avx2_fma; \ - if (GetCpuId().avx2() && GetCpuId().fma()) { \ - return funcname##__avx2_fma(__VA_ARGS__); \ - } -#else // CAFFE2_PERF_WITH_AVX2 -#define AVX2_DO(funcname, ...) -#define AVX2_FMA_DO(funcname, ...) -#endif // CAFFE2_PERF_WITH_AVX2 - -#ifdef CAFFE2_PERF_WITH_AVX -#define AVX_DO(funcname, ...) \ - decltype(funcname##__base) funcname##__avx; \ - if (GetCpuId().avx()) { \ - return funcname##__avx(__VA_ARGS__); \ - } -#define AVX_F16C_DO(funcname, ...) \ - decltype(funcname##__base) funcname##__avx_f16c; \ - if (GetCpuId().avx() && GetCpuId().f16c()) { \ - return funcname##__avx_f16c(__VA_ARGS__); \ - } -#else // CAFFE2_PERF_WITH_AVX -#define AVX_DO(funcname, ...) -#define AVX_F16C_DO(funcname, ...) -#endif // CAFFE2_PERF_WITH_AVX diff --git a/app/src/main/cpp/caffe2/perfkernels/cvtsh_ss_bugfix.h b/app/src/main/cpp/caffe2/perfkernels/cvtsh_ss_bugfix.h deleted file mode 100644 index ce99e73..0000000 --- a/app/src/main/cpp/caffe2/perfkernels/cvtsh_ss_bugfix.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#if defined(__APPLE__) && ((__clang_major__ < 8) || ((__clang_major__ == 8) && (__clang_minor__ < 1))) - -#include - -// This version of apple clang has a bug that _cvtsh_ss is not defined, see -// https://reviews.llvm.org/D16177 -static __inline float - __attribute__((__always_inline__, __nodebug__, __target__("f16c"))) -_cvtsh_ss(unsigned short a) -{ - __v8hi v = {(short)a, 0, 0, 0, 0, 0, 0, 0}; - __v4sf r = __builtin_ia32_vcvtph2ps(v); - return r[0]; -} - -#endif // defined(__APPLE__) && (__clang_major__ < 8) - -#ifdef _MSC_VER - -// It seems that microsoft msvc does not have a _cvtsh_ss implementation so -// we will add a dummy version to it. - -static inline float -_cvtsh_ss(unsigned short x) { - union { - uint32_t intval; - float floatval; - } t1; - uint32_t t2, t3; - t1.intval = x & 0x7fff; // Non-sign bits - t2 = x & 0x8000; // Sign bit - t3 = x & 0x7c00; // Exponent - t1.intval <<= 13; // Align mantissa on MSB - t2 <<= 16; // Shift sign bit into position - t1.intval += 0x38000000; // Adjust bias - t1.intval = (t3 == 0 ? 0 : t1.intval); // Denormals-as-zero - t1.intval |= t2; // Re-insert sign bit - return t1.floatval; -} - -#endif // _MSC_VER diff --git a/app/src/main/cpp/caffe2/perfkernels/embedding_lookup.h b/app/src/main/cpp/caffe2/perfkernels/embedding_lookup.h deleted file mode 100644 index dfbfd11..0000000 --- a/app/src/main/cpp/caffe2/perfkernels/embedding_lookup.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" - -namespace caffe2 { - -/** - * Embedding lookup with reduction. - * - * `input` of size data_size * block_size - * `indices` of size index_size - * `lengths` of size output_size - * `weights` nullptr or array of size index_size - * `out` of size output_size * block_size - * sum(lengths[i]) == index_size - * - * Behavior is roughly equivalent to pseudocode: - * - * pos = 0 - * for (i = 0..index_size-1) - * for (k = 0..block_size-1) - * out[i*block_size + k] = 0 - * for (j = 0..lengths[i]-1) - * for (k = 0..block_size-1) - * out[i*block_size + k] += input[indices[pos]*block_size + k] * - * (weights ? weights[pos] : 1.0) - * pos += 1 - * if (normalize_weights && lengths[i] > 0) - * for (k = 0..block_size-1) - * out[i*block_size + k] /= lengths[i] - * - */ -template -void EmbeddingLookup( - const TIndex block_size, - const TIndex output_size, - const TIndex index_size, - const TIndex data_size, - const InType* input, - const IndexType* indices, - const int* lengths, - const float* weights, // optional, can be null for non-weighted sum - const float* scale_bias, // optional scale & bias params for uint8 input - bool normalize_by_lengths, - OutType* out); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/perfkernels/typed_axpy.h b/app/src/main/cpp/caffe2/perfkernels/typed_axpy.h deleted file mode 100644 index 85b1add..0000000 --- a/app/src/main/cpp/caffe2/perfkernels/typed_axpy.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -namespace caffe2 { - -// Similar to Axpy that calculate y = a * x + y, but allowing x and y to be -// of different data types. -// It also provides a performance optimization hint (use_a) to see if a is going -// to be 1 or not. -template -void TypedAxpy(int N, const OUT a, const IN* x, OUT* y); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/proto/caffe2.pb.h b/app/src/main/cpp/caffe2/proto/caffe2.pb.h deleted file mode 100644 index 1fa07fa..0000000 --- a/app/src/main/cpp/caffe2/proto/caffe2.pb.h +++ /dev/null @@ -1,5899 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/caffe2.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fcaffe2_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fcaffe2_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - -class Argument; -class BlobProto; -class DBReaderProto; -class DeviceOption; -class ExecutionStep; -class NetDef; -class OperatorDef; -class PlanDef; -class QTensorProto; -class TensorProto; -class TensorProto_Segment; -class TensorProtos; -class TensorShape; -class TensorShapes; - -enum TensorProto_DataType { - TensorProto_DataType_UNDEFINED = 0, - TensorProto_DataType_FLOAT = 1, - TensorProto_DataType_INT32 = 2, - TensorProto_DataType_BYTE = 3, - TensorProto_DataType_STRING = 4, - TensorProto_DataType_BOOL = 5, - TensorProto_DataType_UINT8 = 6, - TensorProto_DataType_INT8 = 7, - TensorProto_DataType_UINT16 = 8, - TensorProto_DataType_INT16 = 9, - TensorProto_DataType_INT64 = 10, - TensorProto_DataType_FLOAT16 = 12, - TensorProto_DataType_DOUBLE = 13 -}; -bool TensorProto_DataType_IsValid(int value); -const TensorProto_DataType TensorProto_DataType_DataType_MIN = TensorProto_DataType_UNDEFINED; -const TensorProto_DataType TensorProto_DataType_DataType_MAX = TensorProto_DataType_DOUBLE; -const int TensorProto_DataType_DataType_ARRAYSIZE = TensorProto_DataType_DataType_MAX + 1; - -const ::google::protobuf::EnumDescriptor* TensorProto_DataType_descriptor(); -inline const ::std::string& TensorProto_DataType_Name(TensorProto_DataType value) { - return ::google::protobuf::internal::NameOfEnum( - TensorProto_DataType_descriptor(), value); -} -inline bool TensorProto_DataType_Parse( - const ::std::string& name, TensorProto_DataType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - TensorProto_DataType_descriptor(), name, value); -} -enum DeviceType { - CPU = 0, - CUDA = 1, - MKLDNN = 2, - COMPILE_TIME_MAX_DEVICE_TYPES = 3, - ONLY_FOR_TEST = 20901701 -}; -bool DeviceType_IsValid(int value); -const DeviceType DeviceType_MIN = CPU; -const DeviceType DeviceType_MAX = ONLY_FOR_TEST; -const int DeviceType_ARRAYSIZE = DeviceType_MAX + 1; - -const ::google::protobuf::EnumDescriptor* DeviceType_descriptor(); -inline const ::std::string& DeviceType_Name(DeviceType value) { - return ::google::protobuf::internal::NameOfEnum( - DeviceType_descriptor(), value); -} -inline bool DeviceType_Parse( - const ::std::string& name, DeviceType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - DeviceType_descriptor(), name, value); -} -// =================================================================== - -class TensorProto_Segment : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TensorProto.Segment) */ { - public: - TensorProto_Segment(); - virtual ~TensorProto_Segment(); - - TensorProto_Segment(const TensorProto_Segment& from); - - inline TensorProto_Segment& operator=(const TensorProto_Segment& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TensorProto_Segment& default_instance(); - - static const TensorProto_Segment* internal_default_instance(); - - void Swap(TensorProto_Segment* other); - - // implements Message ---------------------------------------------- - - inline TensorProto_Segment* New() const { return New(NULL); } - - TensorProto_Segment* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TensorProto_Segment& from); - void MergeFrom(const TensorProto_Segment& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TensorProto_Segment* other); - void UnsafeMergeFrom(const TensorProto_Segment& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required int64 begin = 1; - bool has_begin() const; - void clear_begin(); - static const int kBeginFieldNumber = 1; - ::google::protobuf::int64 begin() const; - void set_begin(::google::protobuf::int64 value); - - // required int64 end = 2; - bool has_end() const; - void clear_end(); - static const int kEndFieldNumber = 2; - ::google::protobuf::int64 end() const; - void set_end(::google::protobuf::int64 value); - - // @@protoc_insertion_point(class_scope:caffe2.TensorProto.Segment) - private: - inline void set_has_begin(); - inline void clear_has_begin(); - inline void set_has_end(); - inline void clear_has_end(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::int64 begin_; - ::google::protobuf::int64 end_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TensorProto_Segment_default_instance_; - -// ------------------------------------------------------------------- - -class TensorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TensorProto) */ { - public: - TensorProto(); - virtual ~TensorProto(); - - TensorProto(const TensorProto& from); - - inline TensorProto& operator=(const TensorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TensorProto& default_instance(); - - static const TensorProto* internal_default_instance(); - - void Swap(TensorProto* other); - - // implements Message ---------------------------------------------- - - inline TensorProto* New() const { return New(NULL); } - - TensorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TensorProto& from); - void MergeFrom(const TensorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TensorProto* other); - void UnsafeMergeFrom(const TensorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef TensorProto_Segment Segment; - - typedef TensorProto_DataType DataType; - static const DataType UNDEFINED = - TensorProto_DataType_UNDEFINED; - static const DataType FLOAT = - TensorProto_DataType_FLOAT; - static const DataType INT32 = - TensorProto_DataType_INT32; - static const DataType BYTE = - TensorProto_DataType_BYTE; - static const DataType STRING = - TensorProto_DataType_STRING; - static const DataType BOOL = - TensorProto_DataType_BOOL; - static const DataType UINT8 = - TensorProto_DataType_UINT8; - static const DataType INT8 = - TensorProto_DataType_INT8; - static const DataType UINT16 = - TensorProto_DataType_UINT16; - static const DataType INT16 = - TensorProto_DataType_INT16; - static const DataType INT64 = - TensorProto_DataType_INT64; - static const DataType FLOAT16 = - TensorProto_DataType_FLOAT16; - static const DataType DOUBLE = - TensorProto_DataType_DOUBLE; - static inline bool DataType_IsValid(int value) { - return TensorProto_DataType_IsValid(value); - } - static const DataType DataType_MIN = - TensorProto_DataType_DataType_MIN; - static const DataType DataType_MAX = - TensorProto_DataType_DataType_MAX; - static const int DataType_ARRAYSIZE = - TensorProto_DataType_DataType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - DataType_descriptor() { - return TensorProto_DataType_descriptor(); - } - static inline const ::std::string& DataType_Name(DataType value) { - return TensorProto_DataType_Name(value); - } - static inline bool DataType_Parse(const ::std::string& name, - DataType* value) { - return TensorProto_DataType_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // repeated int64 dims = 1; - int dims_size() const; - void clear_dims(); - static const int kDimsFieldNumber = 1; - ::google::protobuf::int64 dims(int index) const; - void set_dims(int index, ::google::protobuf::int64 value); - void add_dims(::google::protobuf::int64 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - dims() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_dims(); - - // optional .caffe2.TensorProto.DataType data_type = 2 [default = FLOAT]; - bool has_data_type() const; - void clear_data_type(); - static const int kDataTypeFieldNumber = 2; - ::caffe2::TensorProto_DataType data_type() const; - void set_data_type(::caffe2::TensorProto_DataType value); - - // repeated float float_data = 3 [packed = true]; - int float_data_size() const; - void clear_float_data(); - static const int kFloatDataFieldNumber = 3; - float float_data(int index) const; - void set_float_data(int index, float value); - void add_float_data(float value); - const ::google::protobuf::RepeatedField< float >& - float_data() const; - ::google::protobuf::RepeatedField< float >* - mutable_float_data(); - - // repeated int32 int32_data = 4 [packed = true]; - int int32_data_size() const; - void clear_int32_data(); - static const int kInt32DataFieldNumber = 4; - ::google::protobuf::int32 int32_data(int index) const; - void set_int32_data(int index, ::google::protobuf::int32 value); - void add_int32_data(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - int32_data() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_int32_data(); - - // optional bytes byte_data = 5; - bool has_byte_data() const; - void clear_byte_data(); - static const int kByteDataFieldNumber = 5; - const ::std::string& byte_data() const; - void set_byte_data(const ::std::string& value); - void set_byte_data(const char* value); - void set_byte_data(const void* value, size_t size); - ::std::string* mutable_byte_data(); - ::std::string* release_byte_data(); - void set_allocated_byte_data(::std::string* byte_data); - - // repeated bytes string_data = 6; - int string_data_size() const; - void clear_string_data(); - static const int kStringDataFieldNumber = 6; - const ::std::string& string_data(int index) const; - ::std::string* mutable_string_data(int index); - void set_string_data(int index, const ::std::string& value); - void set_string_data(int index, const char* value); - void set_string_data(int index, const void* value, size_t size); - ::std::string* add_string_data(); - void add_string_data(const ::std::string& value); - void add_string_data(const char* value); - void add_string_data(const void* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& string_data() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_string_data(); - - // repeated double double_data = 9 [packed = true]; - int double_data_size() const; - void clear_double_data(); - static const int kDoubleDataFieldNumber = 9; - double double_data(int index) const; - void set_double_data(int index, double value); - void add_double_data(double value); - const ::google::protobuf::RepeatedField< double >& - double_data() const; - ::google::protobuf::RepeatedField< double >* - mutable_double_data(); - - // repeated int64 int64_data = 10 [packed = true]; - int int64_data_size() const; - void clear_int64_data(); - static const int kInt64DataFieldNumber = 10; - ::google::protobuf::int64 int64_data(int index) const; - void set_int64_data(int index, ::google::protobuf::int64 value); - void add_int64_data(::google::protobuf::int64 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - int64_data() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_int64_data(); - - // optional string name = 7; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 7; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional .caffe2.DeviceOption device_detail = 8; - bool has_device_detail() const; - void clear_device_detail(); - static const int kDeviceDetailFieldNumber = 8; - const ::caffe2::DeviceOption& device_detail() const; - ::caffe2::DeviceOption* mutable_device_detail(); - ::caffe2::DeviceOption* release_device_detail(); - void set_allocated_device_detail(::caffe2::DeviceOption* device_detail); - - // optional .caffe2.TensorProto.Segment segment = 11; - bool has_segment() const; - void clear_segment(); - static const int kSegmentFieldNumber = 11; - const ::caffe2::TensorProto_Segment& segment() const; - ::caffe2::TensorProto_Segment* mutable_segment(); - ::caffe2::TensorProto_Segment* release_segment(); - void set_allocated_segment(::caffe2::TensorProto_Segment* segment); - - // @@protoc_insertion_point(class_scope:caffe2.TensorProto) - private: - inline void set_has_data_type(); - inline void clear_has_data_type(); - inline void set_has_byte_data(); - inline void clear_has_byte_data(); - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_device_detail(); - inline void clear_has_device_detail(); - inline void set_has_segment(); - inline void clear_has_segment(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > dims_; - ::google::protobuf::RepeatedField< float > float_data_; - mutable int _float_data_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > int32_data_; - mutable int _int32_data_cached_byte_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> string_data_; - ::google::protobuf::RepeatedField< double > double_data_; - mutable int _double_data_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > int64_data_; - mutable int _int64_data_cached_byte_size_; - ::google::protobuf::internal::ArenaStringPtr byte_data_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::caffe2::DeviceOption* device_detail_; - ::caffe2::TensorProto_Segment* segment_; - int data_type_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TensorProto_default_instance_; - -// ------------------------------------------------------------------- - -class QTensorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.QTensorProto) */ { - public: - QTensorProto(); - virtual ~QTensorProto(); - - QTensorProto(const QTensorProto& from); - - inline QTensorProto& operator=(const QTensorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const QTensorProto& default_instance(); - - static const QTensorProto* internal_default_instance(); - - void Swap(QTensorProto* other); - - // implements Message ---------------------------------------------- - - inline QTensorProto* New() const { return New(NULL); } - - QTensorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const QTensorProto& from); - void MergeFrom(const QTensorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(QTensorProto* other); - void UnsafeMergeFrom(const QTensorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int64 dims = 1; - int dims_size() const; - void clear_dims(); - static const int kDimsFieldNumber = 1; - ::google::protobuf::int64 dims(int index) const; - void set_dims(int index, ::google::protobuf::int64 value); - void add_dims(::google::protobuf::int64 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - dims() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_dims(); - - // required int32 precision = 2; - bool has_precision() const; - void clear_precision(); - static const int kPrecisionFieldNumber = 2; - ::google::protobuf::int32 precision() const; - void set_precision(::google::protobuf::int32 value); - - // required double scale = 3; - bool has_scale() const; - void clear_scale(); - static const int kScaleFieldNumber = 3; - double scale() const; - void set_scale(double value); - - // required double bias = 4; - bool has_bias() const; - void clear_bias(); - static const int kBiasFieldNumber = 4; - double bias() const; - void set_bias(double value); - - // required bool is_signed = 5; - bool has_is_signed() const; - void clear_is_signed(); - static const int kIsSignedFieldNumber = 5; - bool is_signed() const; - void set_is_signed(bool value); - - // repeated int32 data = 6 [packed = true]; - int data_size() const; - void clear_data(); - static const int kDataFieldNumber = 6; - ::google::protobuf::int32 data(int index) const; - void set_data(int index, ::google::protobuf::int32 value); - void add_data(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - data() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_data(); - - // optional string name = 7; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 7; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // @@protoc_insertion_point(class_scope:caffe2.QTensorProto) - private: - inline void set_has_precision(); - inline void clear_has_precision(); - inline void set_has_scale(); - inline void clear_has_scale(); - inline void set_has_bias(); - inline void clear_has_bias(); - inline void set_has_is_signed(); - inline void clear_has_is_signed(); - inline void set_has_name(); - inline void clear_has_name(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > dims_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > data_; - mutable int _data_cached_byte_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - double scale_; - ::google::protobuf::int32 precision_; - bool is_signed_; - double bias_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed QTensorProto_default_instance_; - -// ------------------------------------------------------------------- - -class TensorProtos : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TensorProtos) */ { - public: - TensorProtos(); - virtual ~TensorProtos(); - - TensorProtos(const TensorProtos& from); - - inline TensorProtos& operator=(const TensorProtos& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TensorProtos& default_instance(); - - static const TensorProtos* internal_default_instance(); - - void Swap(TensorProtos* other); - - // implements Message ---------------------------------------------- - - inline TensorProtos* New() const { return New(NULL); } - - TensorProtos* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TensorProtos& from); - void MergeFrom(const TensorProtos& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TensorProtos* other); - void UnsafeMergeFrom(const TensorProtos& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .caffe2.TensorProto protos = 1; - int protos_size() const; - void clear_protos(); - static const int kProtosFieldNumber = 1; - const ::caffe2::TensorProto& protos(int index) const; - ::caffe2::TensorProto* mutable_protos(int index); - ::caffe2::TensorProto* add_protos(); - ::google::protobuf::RepeatedPtrField< ::caffe2::TensorProto >* - mutable_protos(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::TensorProto >& - protos() const; - - // @@protoc_insertion_point(class_scope:caffe2.TensorProtos) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::TensorProto > protos_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TensorProtos_default_instance_; - -// ------------------------------------------------------------------- - -class TensorShape : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TensorShape) */ { - public: - TensorShape(); - virtual ~TensorShape(); - - TensorShape(const TensorShape& from); - - inline TensorShape& operator=(const TensorShape& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TensorShape& default_instance(); - - static const TensorShape* internal_default_instance(); - - void Swap(TensorShape* other); - - // implements Message ---------------------------------------------- - - inline TensorShape* New() const { return New(NULL); } - - TensorShape* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TensorShape& from); - void MergeFrom(const TensorShape& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TensorShape* other); - void UnsafeMergeFrom(const TensorShape& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int64 dims = 1; - int dims_size() const; - void clear_dims(); - static const int kDimsFieldNumber = 1; - ::google::protobuf::int64 dims(int index) const; - void set_dims(int index, ::google::protobuf::int64 value); - void add_dims(::google::protobuf::int64 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - dims() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_dims(); - - // optional .caffe2.TensorProto.DataType data_type = 2 [default = FLOAT]; - bool has_data_type() const; - void clear_data_type(); - static const int kDataTypeFieldNumber = 2; - ::caffe2::TensorProto_DataType data_type() const; - void set_data_type(::caffe2::TensorProto_DataType value); - - // repeated int32 unknown_dims = 3; - int unknown_dims_size() const; - void clear_unknown_dims(); - static const int kUnknownDimsFieldNumber = 3; - ::google::protobuf::int32 unknown_dims(int index) const; - void set_unknown_dims(int index, ::google::protobuf::int32 value); - void add_unknown_dims(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - unknown_dims() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_unknown_dims(); - - // optional bool unknown_shape = 4 [default = false]; - bool has_unknown_shape() const; - void clear_unknown_shape(); - static const int kUnknownShapeFieldNumber = 4; - bool unknown_shape() const; - void set_unknown_shape(bool value); - - // optional string name = 5; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 5; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // @@protoc_insertion_point(class_scope:caffe2.TensorShape) - private: - inline void set_has_data_type(); - inline void clear_has_data_type(); - inline void set_has_unknown_shape(); - inline void clear_has_unknown_shape(); - inline void set_has_name(); - inline void clear_has_name(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > dims_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > unknown_dims_; - ::google::protobuf::internal::ArenaStringPtr name_; - bool unknown_shape_; - int data_type_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TensorShape_default_instance_; - -// ------------------------------------------------------------------- - -class TensorShapes : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TensorShapes) */ { - public: - TensorShapes(); - virtual ~TensorShapes(); - - TensorShapes(const TensorShapes& from); - - inline TensorShapes& operator=(const TensorShapes& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TensorShapes& default_instance(); - - static const TensorShapes* internal_default_instance(); - - void Swap(TensorShapes* other); - - // implements Message ---------------------------------------------- - - inline TensorShapes* New() const { return New(NULL); } - - TensorShapes* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TensorShapes& from); - void MergeFrom(const TensorShapes& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TensorShapes* other); - void UnsafeMergeFrom(const TensorShapes& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .caffe2.TensorShape shapes = 1; - int shapes_size() const; - void clear_shapes(); - static const int kShapesFieldNumber = 1; - const ::caffe2::TensorShape& shapes(int index) const; - ::caffe2::TensorShape* mutable_shapes(int index); - ::caffe2::TensorShape* add_shapes(); - ::google::protobuf::RepeatedPtrField< ::caffe2::TensorShape >* - mutable_shapes(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::TensorShape >& - shapes() const; - - // @@protoc_insertion_point(class_scope:caffe2.TensorShapes) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::TensorShape > shapes_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TensorShapes_default_instance_; - -// ------------------------------------------------------------------- - -class Argument : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.Argument) */ { - public: - Argument(); - virtual ~Argument(); - - Argument(const Argument& from); - - inline Argument& operator=(const Argument& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Argument& default_instance(); - - static const Argument* internal_default_instance(); - - void Swap(Argument* other); - - // implements Message ---------------------------------------------- - - inline Argument* New() const { return New(NULL); } - - Argument* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Argument& from); - void MergeFrom(const Argument& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Argument* other); - void UnsafeMergeFrom(const Argument& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional float f = 2; - bool has_f() const; - void clear_f(); - static const int kFFieldNumber = 2; - float f() const; - void set_f(float value); - - // optional int64 i = 3; - bool has_i() const; - void clear_i(); - static const int kIFieldNumber = 3; - ::google::protobuf::int64 i() const; - void set_i(::google::protobuf::int64 value); - - // optional bytes s = 4; - bool has_s() const; - void clear_s(); - static const int kSFieldNumber = 4; - const ::std::string& s() const; - void set_s(const ::std::string& value); - void set_s(const char* value); - void set_s(const void* value, size_t size); - ::std::string* mutable_s(); - ::std::string* release_s(); - void set_allocated_s(::std::string* s); - - // optional .caffe2.NetDef n = 8; - bool has_n() const; - void clear_n(); - static const int kNFieldNumber = 8; - const ::caffe2::NetDef& n() const; - ::caffe2::NetDef* mutable_n(); - ::caffe2::NetDef* release_n(); - void set_allocated_n(::caffe2::NetDef* n); - - // repeated float floats = 5; - int floats_size() const; - void clear_floats(); - static const int kFloatsFieldNumber = 5; - float floats(int index) const; - void set_floats(int index, float value); - void add_floats(float value); - const ::google::protobuf::RepeatedField< float >& - floats() const; - ::google::protobuf::RepeatedField< float >* - mutable_floats(); - - // repeated int64 ints = 6; - int ints_size() const; - void clear_ints(); - static const int kIntsFieldNumber = 6; - ::google::protobuf::int64 ints(int index) const; - void set_ints(int index, ::google::protobuf::int64 value); - void add_ints(::google::protobuf::int64 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& - ints() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* - mutable_ints(); - - // repeated bytes strings = 7; - int strings_size() const; - void clear_strings(); - static const int kStringsFieldNumber = 7; - const ::std::string& strings(int index) const; - ::std::string* mutable_strings(int index); - void set_strings(int index, const ::std::string& value); - void set_strings(int index, const char* value); - void set_strings(int index, const void* value, size_t size); - ::std::string* add_strings(); - void add_strings(const ::std::string& value); - void add_strings(const char* value); - void add_strings(const void* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& strings() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_strings(); - - // repeated .caffe2.NetDef nets = 9; - int nets_size() const; - void clear_nets(); - static const int kNetsFieldNumber = 9; - const ::caffe2::NetDef& nets(int index) const; - ::caffe2::NetDef* mutable_nets(int index); - ::caffe2::NetDef* add_nets(); - ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >* - mutable_nets(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >& - nets() const; - - // @@protoc_insertion_point(class_scope:caffe2.Argument) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_f(); - inline void clear_has_f(); - inline void set_has_i(); - inline void clear_has_i(); - inline void set_has_s(); - inline void clear_has_s(); - inline void set_has_n(); - inline void clear_has_n(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< float > floats_; - ::google::protobuf::RepeatedField< ::google::protobuf::int64 > ints_; - ::google::protobuf::RepeatedPtrField< ::std::string> strings_; - ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef > nets_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr s_; - ::caffe2::NetDef* n_; - ::google::protobuf::int64 i_; - float f_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Argument_default_instance_; - -// ------------------------------------------------------------------- - -class DeviceOption : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.DeviceOption) */ { - public: - DeviceOption(); - virtual ~DeviceOption(); - - DeviceOption(const DeviceOption& from); - - inline DeviceOption& operator=(const DeviceOption& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DeviceOption& default_instance(); - - static const DeviceOption* internal_default_instance(); - - void Swap(DeviceOption* other); - - // implements Message ---------------------------------------------- - - inline DeviceOption* New() const { return New(NULL); } - - DeviceOption* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DeviceOption& from); - void MergeFrom(const DeviceOption& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(DeviceOption* other); - void UnsafeMergeFrom(const DeviceOption& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 device_type = 1 [default = 0]; - bool has_device_type() const; - void clear_device_type(); - static const int kDeviceTypeFieldNumber = 1; - ::google::protobuf::int32 device_type() const; - void set_device_type(::google::protobuf::int32 value); - - // optional int32 cuda_gpu_id = 2; - bool has_cuda_gpu_id() const; - void clear_cuda_gpu_id(); - static const int kCudaGpuIdFieldNumber = 2; - ::google::protobuf::int32 cuda_gpu_id() const; - void set_cuda_gpu_id(::google::protobuf::int32 value); - - // optional uint32 random_seed = 3; - bool has_random_seed() const; - void clear_random_seed(); - static const int kRandomSeedFieldNumber = 3; - ::google::protobuf::uint32 random_seed() const; - void set_random_seed(::google::protobuf::uint32 value); - - // optional string node_name = 4; - bool has_node_name() const; - void clear_node_name(); - static const int kNodeNameFieldNumber = 4; - const ::std::string& node_name() const; - void set_node_name(const ::std::string& value); - void set_node_name(const char* value); - void set_node_name(const char* value, size_t size); - ::std::string* mutable_node_name(); - ::std::string* release_node_name(); - void set_allocated_node_name(::std::string* node_name); - - // @@protoc_insertion_point(class_scope:caffe2.DeviceOption) - private: - inline void set_has_device_type(); - inline void clear_has_device_type(); - inline void set_has_cuda_gpu_id(); - inline void clear_has_cuda_gpu_id(); - inline void set_has_random_seed(); - inline void clear_has_random_seed(); - inline void set_has_node_name(); - inline void clear_has_node_name(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr node_name_; - ::google::protobuf::int32 device_type_; - ::google::protobuf::int32 cuda_gpu_id_; - ::google::protobuf::uint32 random_seed_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed DeviceOption_default_instance_; - -// ------------------------------------------------------------------- - -class OperatorDef : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.OperatorDef) */ { - public: - OperatorDef(); - virtual ~OperatorDef(); - - OperatorDef(const OperatorDef& from); - - inline OperatorDef& operator=(const OperatorDef& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OperatorDef& default_instance(); - - static const OperatorDef* internal_default_instance(); - - void Swap(OperatorDef* other); - - // implements Message ---------------------------------------------- - - inline OperatorDef* New() const { return New(NULL); } - - OperatorDef* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OperatorDef& from); - void MergeFrom(const OperatorDef& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(OperatorDef* other); - void UnsafeMergeFrom(const OperatorDef& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string input = 1; - int input_size() const; - void clear_input(); - static const int kInputFieldNumber = 1; - const ::std::string& input(int index) const; - ::std::string* mutable_input(int index); - void set_input(int index, const ::std::string& value); - void set_input(int index, const char* value); - void set_input(int index, const char* value, size_t size); - ::std::string* add_input(); - void add_input(const ::std::string& value); - void add_input(const char* value); - void add_input(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& input() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_input(); - - // repeated string output = 2; - int output_size() const; - void clear_output(); - static const int kOutputFieldNumber = 2; - const ::std::string& output(int index) const; - ::std::string* mutable_output(int index); - void set_output(int index, const ::std::string& value); - void set_output(int index, const char* value); - void set_output(int index, const char* value, size_t size); - ::std::string* add_output(); - void add_output(const ::std::string& value); - void add_output(const char* value); - void add_output(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& output() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_output(); - - // optional string name = 3; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 3; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string type = 4; - bool has_type() const; - void clear_type(); - static const int kTypeFieldNumber = 4; - const ::std::string& type() const; - void set_type(const ::std::string& value); - void set_type(const char* value); - void set_type(const char* value, size_t size); - ::std::string* mutable_type(); - ::std::string* release_type(); - void set_allocated_type(::std::string* type); - - // repeated .caffe2.Argument arg = 5; - int arg_size() const; - void clear_arg(); - static const int kArgFieldNumber = 5; - const ::caffe2::Argument& arg(int index) const; - ::caffe2::Argument* mutable_arg(int index); - ::caffe2::Argument* add_arg(); - ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >* - mutable_arg(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >& - arg() const; - - // optional .caffe2.DeviceOption device_option = 6; - bool has_device_option() const; - void clear_device_option(); - static const int kDeviceOptionFieldNumber = 6; - const ::caffe2::DeviceOption& device_option() const; - ::caffe2::DeviceOption* mutable_device_option(); - ::caffe2::DeviceOption* release_device_option(); - void set_allocated_device_option(::caffe2::DeviceOption* device_option); - - // optional string engine = 7; - bool has_engine() const; - void clear_engine(); - static const int kEngineFieldNumber = 7; - const ::std::string& engine() const; - void set_engine(const ::std::string& value); - void set_engine(const char* value); - void set_engine(const char* value, size_t size); - ::std::string* mutable_engine(); - ::std::string* release_engine(); - void set_allocated_engine(::std::string* engine); - - // repeated string control_input = 8; - int control_input_size() const; - void clear_control_input(); - static const int kControlInputFieldNumber = 8; - const ::std::string& control_input(int index) const; - ::std::string* mutable_control_input(int index); - void set_control_input(int index, const ::std::string& value); - void set_control_input(int index, const char* value); - void set_control_input(int index, const char* value, size_t size); - ::std::string* add_control_input(); - void add_control_input(const ::std::string& value); - void add_control_input(const char* value); - void add_control_input(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& control_input() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_control_input(); - - // optional bool is_gradient_op = 9 [default = false]; - bool has_is_gradient_op() const; - void clear_is_gradient_op(); - static const int kIsGradientOpFieldNumber = 9; - bool is_gradient_op() const; - void set_is_gradient_op(bool value); - - // @@protoc_insertion_point(class_scope:caffe2.OperatorDef) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_type(); - inline void clear_has_type(); - inline void set_has_device_option(); - inline void clear_has_device_option(); - inline void set_has_engine(); - inline void clear_has_engine(); - inline void set_has_is_gradient_op(); - inline void clear_has_is_gradient_op(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> input_; - ::google::protobuf::RepeatedPtrField< ::std::string> output_; - ::google::protobuf::RepeatedPtrField< ::caffe2::Argument > arg_; - ::google::protobuf::RepeatedPtrField< ::std::string> control_input_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_; - ::google::protobuf::internal::ArenaStringPtr engine_; - ::caffe2::DeviceOption* device_option_; - bool is_gradient_op_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed OperatorDef_default_instance_; - -// ------------------------------------------------------------------- - -class NetDef : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.NetDef) */ { - public: - NetDef(); - virtual ~NetDef(); - - NetDef(const NetDef& from); - - inline NetDef& operator=(const NetDef& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const NetDef& default_instance(); - - static const NetDef* internal_default_instance(); - - void Swap(NetDef* other); - - // implements Message ---------------------------------------------- - - inline NetDef* New() const { return New(NULL); } - - NetDef* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const NetDef& from); - void MergeFrom(const NetDef& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(NetDef* other); - void UnsafeMergeFrom(const NetDef& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .caffe2.OperatorDef op = 2; - int op_size() const; - void clear_op(); - static const int kOpFieldNumber = 2; - const ::caffe2::OperatorDef& op(int index) const; - ::caffe2::OperatorDef* mutable_op(int index); - ::caffe2::OperatorDef* add_op(); - ::google::protobuf::RepeatedPtrField< ::caffe2::OperatorDef >* - mutable_op(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::OperatorDef >& - op() const; - - // optional string type = 3; - bool has_type() const; - void clear_type(); - static const int kTypeFieldNumber = 3; - const ::std::string& type() const; - void set_type(const ::std::string& value); - void set_type(const char* value); - void set_type(const char* value, size_t size); - ::std::string* mutable_type(); - ::std::string* release_type(); - void set_allocated_type(::std::string* type); - - // optional int32 num_workers = 4 [deprecated = true]; - GOOGLE_PROTOBUF_DEPRECATED_ATTR bool has_num_workers() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void clear_num_workers(); - GOOGLE_PROTOBUF_DEPRECATED_ATTR static const int kNumWorkersFieldNumber = 4; - GOOGLE_PROTOBUF_DEPRECATED_ATTR ::google::protobuf::int32 num_workers() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_num_workers(::google::protobuf::int32 value); - - // optional .caffe2.DeviceOption device_option = 5; - bool has_device_option() const; - void clear_device_option(); - static const int kDeviceOptionFieldNumber = 5; - const ::caffe2::DeviceOption& device_option() const; - ::caffe2::DeviceOption* mutable_device_option(); - ::caffe2::DeviceOption* release_device_option(); - void set_allocated_device_option(::caffe2::DeviceOption* device_option); - - // repeated .caffe2.Argument arg = 6; - int arg_size() const; - void clear_arg(); - static const int kArgFieldNumber = 6; - const ::caffe2::Argument& arg(int index) const; - ::caffe2::Argument* mutable_arg(int index); - ::caffe2::Argument* add_arg(); - ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >* - mutable_arg(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >& - arg() const; - - // repeated string external_input = 7; - int external_input_size() const; - void clear_external_input(); - static const int kExternalInputFieldNumber = 7; - const ::std::string& external_input(int index) const; - ::std::string* mutable_external_input(int index); - void set_external_input(int index, const ::std::string& value); - void set_external_input(int index, const char* value); - void set_external_input(int index, const char* value, size_t size); - ::std::string* add_external_input(); - void add_external_input(const ::std::string& value); - void add_external_input(const char* value); - void add_external_input(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& external_input() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_external_input(); - - // repeated string external_output = 8; - int external_output_size() const; - void clear_external_output(); - static const int kExternalOutputFieldNumber = 8; - const ::std::string& external_output(int index) const; - ::std::string* mutable_external_output(int index); - void set_external_output(int index, const ::std::string& value); - void set_external_output(int index, const char* value); - void set_external_output(int index, const char* value, size_t size); - ::std::string* add_external_output(); - void add_external_output(const ::std::string& value); - void add_external_output(const char* value); - void add_external_output(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& external_output() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_external_output(); - - // @@protoc_insertion_point(class_scope:caffe2.NetDef) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_type(); - inline void clear_has_type(); - inline void set_has_num_workers(); - inline void clear_has_num_workers(); - inline void set_has_device_option(); - inline void clear_has_device_option(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::OperatorDef > op_; - ::google::protobuf::RepeatedPtrField< ::caffe2::Argument > arg_; - ::google::protobuf::RepeatedPtrField< ::std::string> external_input_; - ::google::protobuf::RepeatedPtrField< ::std::string> external_output_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_; - ::caffe2::DeviceOption* device_option_; - ::google::protobuf::int32 num_workers_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed NetDef_default_instance_; - -// ------------------------------------------------------------------- - -class ExecutionStep : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.ExecutionStep) */ { - public: - ExecutionStep(); - virtual ~ExecutionStep(); - - ExecutionStep(const ExecutionStep& from); - - inline ExecutionStep& operator=(const ExecutionStep& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ExecutionStep& default_instance(); - - static const ExecutionStep* internal_default_instance(); - - void Swap(ExecutionStep* other); - - // implements Message ---------------------------------------------- - - inline ExecutionStep* New() const { return New(NULL); } - - ExecutionStep* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ExecutionStep& from); - void MergeFrom(const ExecutionStep& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ExecutionStep* other); - void UnsafeMergeFrom(const ExecutionStep& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .caffe2.ExecutionStep substep = 2; - int substep_size() const; - void clear_substep(); - static const int kSubstepFieldNumber = 2; - const ::caffe2::ExecutionStep& substep(int index) const; - ::caffe2::ExecutionStep* mutable_substep(int index); - ::caffe2::ExecutionStep* add_substep(); - ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >* - mutable_substep(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >& - substep() const; - - // repeated string network = 3; - int network_size() const; - void clear_network(); - static const int kNetworkFieldNumber = 3; - const ::std::string& network(int index) const; - ::std::string* mutable_network(int index); - void set_network(int index, const ::std::string& value); - void set_network(int index, const char* value); - void set_network(int index, const char* value, size_t size); - ::std::string* add_network(); - void add_network(const ::std::string& value); - void add_network(const char* value); - void add_network(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& network() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_network(); - - // optional int64 num_iter = 4; - bool has_num_iter() const; - void clear_num_iter(); - static const int kNumIterFieldNumber = 4; - ::google::protobuf::int64 num_iter() const; - void set_num_iter(::google::protobuf::int64 value); - - // optional string criteria_network = 5 [deprecated = true]; - GOOGLE_PROTOBUF_DEPRECATED_ATTR bool has_criteria_network() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void clear_criteria_network(); - GOOGLE_PROTOBUF_DEPRECATED_ATTR static const int kCriteriaNetworkFieldNumber = 5; - GOOGLE_PROTOBUF_DEPRECATED_ATTR const ::std::string& criteria_network() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_criteria_network(const ::std::string& value); - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_criteria_network(const char* value); - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_criteria_network(const char* value, size_t size); - GOOGLE_PROTOBUF_DEPRECATED_ATTR ::std::string* mutable_criteria_network(); - GOOGLE_PROTOBUF_DEPRECATED_ATTR ::std::string* release_criteria_network(); - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_allocated_criteria_network(::std::string* criteria_network); - - // optional string report_net = 7; - bool has_report_net() const; - void clear_report_net(); - static const int kReportNetFieldNumber = 7; - const ::std::string& report_net() const; - void set_report_net(const ::std::string& value); - void set_report_net(const char* value); - void set_report_net(const char* value, size_t size); - ::std::string* mutable_report_net(); - ::std::string* release_report_net(); - void set_allocated_report_net(::std::string* report_net); - - // optional int32 report_interval = 8; - bool has_report_interval() const; - void clear_report_interval(); - static const int kReportIntervalFieldNumber = 8; - ::google::protobuf::int32 report_interval() const; - void set_report_interval(::google::protobuf::int32 value); - - // optional int64 run_every_ms = 11; - bool has_run_every_ms() const; - void clear_run_every_ms(); - static const int kRunEveryMsFieldNumber = 11; - ::google::protobuf::int64 run_every_ms() const; - void set_run_every_ms(::google::protobuf::int64 value); - - // optional bool concurrent_substeps = 6; - bool has_concurrent_substeps() const; - void clear_concurrent_substeps(); - static const int kConcurrentSubstepsFieldNumber = 6; - bool concurrent_substeps() const; - void set_concurrent_substeps(bool value); - - // optional string should_stop_blob = 9; - bool has_should_stop_blob() const; - void clear_should_stop_blob(); - static const int kShouldStopBlobFieldNumber = 9; - const ::std::string& should_stop_blob() const; - void set_should_stop_blob(const ::std::string& value); - void set_should_stop_blob(const char* value); - void set_should_stop_blob(const char* value, size_t size); - ::std::string* mutable_should_stop_blob(); - ::std::string* release_should_stop_blob(); - void set_allocated_should_stop_blob(::std::string* should_stop_blob); - - // optional bool only_once = 10; - bool has_only_once() const; - void clear_only_once(); - static const int kOnlyOnceFieldNumber = 10; - bool only_once() const; - void set_only_once(bool value); - - // optional bool create_workspace = 12; - bool has_create_workspace() const; - void clear_create_workspace(); - static const int kCreateWorkspaceFieldNumber = 12; - bool create_workspace() const; - void set_create_workspace(bool value); - - // optional int32 num_concurrent_instances = 13; - bool has_num_concurrent_instances() const; - void clear_num_concurrent_instances(); - static const int kNumConcurrentInstancesFieldNumber = 13; - ::google::protobuf::int32 num_concurrent_instances() const; - void set_num_concurrent_instances(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:caffe2.ExecutionStep) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_num_iter(); - inline void clear_has_num_iter(); - inline void set_has_criteria_network(); - inline void clear_has_criteria_network(); - inline void set_has_report_net(); - inline void clear_has_report_net(); - inline void set_has_report_interval(); - inline void clear_has_report_interval(); - inline void set_has_run_every_ms(); - inline void clear_has_run_every_ms(); - inline void set_has_concurrent_substeps(); - inline void clear_has_concurrent_substeps(); - inline void set_has_should_stop_blob(); - inline void clear_has_should_stop_blob(); - inline void set_has_only_once(); - inline void clear_has_only_once(); - inline void set_has_create_workspace(); - inline void clear_has_create_workspace(); - inline void set_has_num_concurrent_instances(); - inline void clear_has_num_concurrent_instances(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep > substep_; - ::google::protobuf::RepeatedPtrField< ::std::string> network_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr criteria_network_; - ::google::protobuf::internal::ArenaStringPtr report_net_; - ::google::protobuf::internal::ArenaStringPtr should_stop_blob_; - ::google::protobuf::int64 num_iter_; - ::google::protobuf::int64 run_every_ms_; - ::google::protobuf::int32 report_interval_; - bool concurrent_substeps_; - bool only_once_; - bool create_workspace_; - ::google::protobuf::int32 num_concurrent_instances_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ExecutionStep_default_instance_; - -// ------------------------------------------------------------------- - -class PlanDef : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.PlanDef) */ { - public: - PlanDef(); - virtual ~PlanDef(); - - PlanDef(const PlanDef& from); - - inline PlanDef& operator=(const PlanDef& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const PlanDef& default_instance(); - - static const PlanDef* internal_default_instance(); - - void Swap(PlanDef* other); - - // implements Message ---------------------------------------------- - - inline PlanDef* New() const { return New(NULL); } - - PlanDef* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const PlanDef& from); - void MergeFrom(const PlanDef& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(PlanDef* other); - void UnsafeMergeFrom(const PlanDef& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .caffe2.NetDef network = 2; - int network_size() const; - void clear_network(); - static const int kNetworkFieldNumber = 2; - const ::caffe2::NetDef& network(int index) const; - ::caffe2::NetDef* mutable_network(int index); - ::caffe2::NetDef* add_network(); - ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >* - mutable_network(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >& - network() const; - - // repeated .caffe2.ExecutionStep execution_step = 3; - int execution_step_size() const; - void clear_execution_step(); - static const int kExecutionStepFieldNumber = 3; - const ::caffe2::ExecutionStep& execution_step(int index) const; - ::caffe2::ExecutionStep* mutable_execution_step(int index); - ::caffe2::ExecutionStep* add_execution_step(); - ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >* - mutable_execution_step(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >& - execution_step() const; - - // @@protoc_insertion_point(class_scope:caffe2.PlanDef) - private: - inline void set_has_name(); - inline void clear_has_name(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef > network_; - ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep > execution_step_; - ::google::protobuf::internal::ArenaStringPtr name_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed PlanDef_default_instance_; - -// ------------------------------------------------------------------- - -class BlobProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.BlobProto) */ { - public: - BlobProto(); - virtual ~BlobProto(); - - BlobProto(const BlobProto& from); - - inline BlobProto& operator=(const BlobProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const BlobProto& default_instance(); - - static const BlobProto* internal_default_instance(); - - void Swap(BlobProto* other); - - // implements Message ---------------------------------------------- - - inline BlobProto* New() const { return New(NULL); } - - BlobProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const BlobProto& from); - void MergeFrom(const BlobProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(BlobProto* other); - void UnsafeMergeFrom(const BlobProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string type = 2; - bool has_type() const; - void clear_type(); - static const int kTypeFieldNumber = 2; - const ::std::string& type() const; - void set_type(const ::std::string& value); - void set_type(const char* value); - void set_type(const char* value, size_t size); - ::std::string* mutable_type(); - ::std::string* release_type(); - void set_allocated_type(::std::string* type); - - // optional .caffe2.TensorProto tensor = 3; - bool has_tensor() const; - void clear_tensor(); - static const int kTensorFieldNumber = 3; - const ::caffe2::TensorProto& tensor() const; - ::caffe2::TensorProto* mutable_tensor(); - ::caffe2::TensorProto* release_tensor(); - void set_allocated_tensor(::caffe2::TensorProto* tensor); - - // optional bytes content = 4; - bool has_content() const; - void clear_content(); - static const int kContentFieldNumber = 4; - const ::std::string& content() const; - void set_content(const ::std::string& value); - void set_content(const char* value); - void set_content(const void* value, size_t size); - ::std::string* mutable_content(); - ::std::string* release_content(); - void set_allocated_content(::std::string* content); - - // optional .caffe2.QTensorProto qtensor = 5; - bool has_qtensor() const; - void clear_qtensor(); - static const int kQtensorFieldNumber = 5; - const ::caffe2::QTensorProto& qtensor() const; - ::caffe2::QTensorProto* mutable_qtensor(); - ::caffe2::QTensorProto* release_qtensor(); - void set_allocated_qtensor(::caffe2::QTensorProto* qtensor); - - // optional int32 content_num_chunks = 6; - bool has_content_num_chunks() const; - void clear_content_num_chunks(); - static const int kContentNumChunksFieldNumber = 6; - ::google::protobuf::int32 content_num_chunks() const; - void set_content_num_chunks(::google::protobuf::int32 value); - - // optional int32 content_chunk_id = 7; - bool has_content_chunk_id() const; - void clear_content_chunk_id(); - static const int kContentChunkIdFieldNumber = 7; - ::google::protobuf::int32 content_chunk_id() const; - void set_content_chunk_id(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:caffe2.BlobProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_type(); - inline void clear_has_type(); - inline void set_has_tensor(); - inline void clear_has_tensor(); - inline void set_has_content(); - inline void clear_has_content(); - inline void set_has_qtensor(); - inline void clear_has_qtensor(); - inline void set_has_content_num_chunks(); - inline void clear_has_content_num_chunks(); - inline void set_has_content_chunk_id(); - inline void clear_has_content_chunk_id(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_; - ::google::protobuf::internal::ArenaStringPtr content_; - ::caffe2::TensorProto* tensor_; - ::caffe2::QTensorProto* qtensor_; - ::google::protobuf::int32 content_num_chunks_; - ::google::protobuf::int32 content_chunk_id_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed BlobProto_default_instance_; - -// ------------------------------------------------------------------- - -class DBReaderProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.DBReaderProto) */ { - public: - DBReaderProto(); - virtual ~DBReaderProto(); - - DBReaderProto(const DBReaderProto& from); - - inline DBReaderProto& operator=(const DBReaderProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DBReaderProto& default_instance(); - - static const DBReaderProto* internal_default_instance(); - - void Swap(DBReaderProto* other); - - // implements Message ---------------------------------------------- - - inline DBReaderProto* New() const { return New(NULL); } - - DBReaderProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DBReaderProto& from); - void MergeFrom(const DBReaderProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(DBReaderProto* other); - void UnsafeMergeFrom(const DBReaderProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string source = 2; - bool has_source() const; - void clear_source(); - static const int kSourceFieldNumber = 2; - const ::std::string& source() const; - void set_source(const ::std::string& value); - void set_source(const char* value); - void set_source(const char* value, size_t size); - ::std::string* mutable_source(); - ::std::string* release_source(); - void set_allocated_source(::std::string* source); - - // optional string db_type = 3; - bool has_db_type() const; - void clear_db_type(); - static const int kDbTypeFieldNumber = 3; - const ::std::string& db_type() const; - void set_db_type(const ::std::string& value); - void set_db_type(const char* value); - void set_db_type(const char* value, size_t size); - ::std::string* mutable_db_type(); - ::std::string* release_db_type(); - void set_allocated_db_type(::std::string* db_type); - - // optional string key = 4; - bool has_key() const; - void clear_key(); - static const int kKeyFieldNumber = 4; - const ::std::string& key() const; - void set_key(const ::std::string& value); - void set_key(const char* value); - void set_key(const char* value, size_t size); - ::std::string* mutable_key(); - ::std::string* release_key(); - void set_allocated_key(::std::string* key); - - // @@protoc_insertion_point(class_scope:caffe2.DBReaderProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_source(); - inline void clear_has_source(); - inline void set_has_db_type(); - inline void clear_has_db_type(); - inline void set_has_key(); - inline void clear_has_key(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr source_; - ::google::protobuf::internal::ArenaStringPtr db_type_; - ::google::protobuf::internal::ArenaStringPtr key_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed DBReaderProto_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// TensorProto_Segment - -// required int64 begin = 1; -inline bool TensorProto_Segment::has_begin() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TensorProto_Segment::set_has_begin() { - _has_bits_[0] |= 0x00000001u; -} -inline void TensorProto_Segment::clear_has_begin() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TensorProto_Segment::clear_begin() { - begin_ = GOOGLE_LONGLONG(0); - clear_has_begin(); -} -inline ::google::protobuf::int64 TensorProto_Segment::begin() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.Segment.begin) - return begin_; -} -inline void TensorProto_Segment::set_begin(::google::protobuf::int64 value) { - set_has_begin(); - begin_ = value; - // @@protoc_insertion_point(field_set:caffe2.TensorProto.Segment.begin) -} - -// required int64 end = 2; -inline bool TensorProto_Segment::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TensorProto_Segment::set_has_end() { - _has_bits_[0] |= 0x00000002u; -} -inline void TensorProto_Segment::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TensorProto_Segment::clear_end() { - end_ = GOOGLE_LONGLONG(0); - clear_has_end(); -} -inline ::google::protobuf::int64 TensorProto_Segment::end() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.Segment.end) - return end_; -} -inline void TensorProto_Segment::set_end(::google::protobuf::int64 value) { - set_has_end(); - end_ = value; - // @@protoc_insertion_point(field_set:caffe2.TensorProto.Segment.end) -} - -inline const TensorProto_Segment* TensorProto_Segment::internal_default_instance() { - return &TensorProto_Segment_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// TensorProto - -// repeated int64 dims = 1; -inline int TensorProto::dims_size() const { - return dims_.size(); -} -inline void TensorProto::clear_dims() { - dims_.Clear(); -} -inline ::google::protobuf::int64 TensorProto::dims(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.dims) - return dims_.Get(index); -} -inline void TensorProto::set_dims(int index, ::google::protobuf::int64 value) { - dims_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.dims) -} -inline void TensorProto::add_dims(::google::protobuf::int64 value) { - dims_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.dims) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TensorProto::dims() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.dims) - return dims_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TensorProto::mutable_dims() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.dims) - return &dims_; -} - -// optional .caffe2.TensorProto.DataType data_type = 2 [default = FLOAT]; -inline bool TensorProto::has_data_type() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TensorProto::set_has_data_type() { - _has_bits_[0] |= 0x00000002u; -} -inline void TensorProto::clear_has_data_type() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TensorProto::clear_data_type() { - data_type_ = 1; - clear_has_data_type(); -} -inline ::caffe2::TensorProto_DataType TensorProto::data_type() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.data_type) - return static_cast< ::caffe2::TensorProto_DataType >(data_type_); -} -inline void TensorProto::set_data_type(::caffe2::TensorProto_DataType value) { - assert(::caffe2::TensorProto_DataType_IsValid(value)); - set_has_data_type(); - data_type_ = value; - // @@protoc_insertion_point(field_set:caffe2.TensorProto.data_type) -} - -// repeated float float_data = 3 [packed = true]; -inline int TensorProto::float_data_size() const { - return float_data_.size(); -} -inline void TensorProto::clear_float_data() { - float_data_.Clear(); -} -inline float TensorProto::float_data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.float_data) - return float_data_.Get(index); -} -inline void TensorProto::set_float_data(int index, float value) { - float_data_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.float_data) -} -inline void TensorProto::add_float_data(float value) { - float_data_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.float_data) -} -inline const ::google::protobuf::RepeatedField< float >& -TensorProto::float_data() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.float_data) - return float_data_; -} -inline ::google::protobuf::RepeatedField< float >* -TensorProto::mutable_float_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.float_data) - return &float_data_; -} - -// repeated int32 int32_data = 4 [packed = true]; -inline int TensorProto::int32_data_size() const { - return int32_data_.size(); -} -inline void TensorProto::clear_int32_data() { - int32_data_.Clear(); -} -inline ::google::protobuf::int32 TensorProto::int32_data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.int32_data) - return int32_data_.Get(index); -} -inline void TensorProto::set_int32_data(int index, ::google::protobuf::int32 value) { - int32_data_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.int32_data) -} -inline void TensorProto::add_int32_data(::google::protobuf::int32 value) { - int32_data_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.int32_data) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TensorProto::int32_data() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.int32_data) - return int32_data_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TensorProto::mutable_int32_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.int32_data) - return &int32_data_; -} - -// optional bytes byte_data = 5; -inline bool TensorProto::has_byte_data() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TensorProto::set_has_byte_data() { - _has_bits_[0] |= 0x00000010u; -} -inline void TensorProto::clear_has_byte_data() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TensorProto::clear_byte_data() { - byte_data_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_byte_data(); -} -inline const ::std::string& TensorProto::byte_data() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.byte_data) - return byte_data_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorProto::set_byte_data(const ::std::string& value) { - set_has_byte_data(); - byte_data_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.byte_data) -} -inline void TensorProto::set_byte_data(const char* value) { - set_has_byte_data(); - byte_data_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.TensorProto.byte_data) -} -inline void TensorProto::set_byte_data(const void* value, size_t size) { - set_has_byte_data(); - byte_data_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.TensorProto.byte_data) -} -inline ::std::string* TensorProto::mutable_byte_data() { - set_has_byte_data(); - // @@protoc_insertion_point(field_mutable:caffe2.TensorProto.byte_data) - return byte_data_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* TensorProto::release_byte_data() { - // @@protoc_insertion_point(field_release:caffe2.TensorProto.byte_data) - clear_has_byte_data(); - return byte_data_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorProto::set_allocated_byte_data(::std::string* byte_data) { - if (byte_data != NULL) { - set_has_byte_data(); - } else { - clear_has_byte_data(); - } - byte_data_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), byte_data); - // @@protoc_insertion_point(field_set_allocated:caffe2.TensorProto.byte_data) -} - -// repeated bytes string_data = 6; -inline int TensorProto::string_data_size() const { - return string_data_.size(); -} -inline void TensorProto::clear_string_data() { - string_data_.Clear(); -} -inline const ::std::string& TensorProto::string_data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.string_data) - return string_data_.Get(index); -} -inline ::std::string* TensorProto::mutable_string_data(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.TensorProto.string_data) - return string_data_.Mutable(index); -} -inline void TensorProto::set_string_data(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.TensorProto.string_data) - string_data_.Mutable(index)->assign(value); -} -inline void TensorProto::set_string_data(int index, const char* value) { - string_data_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.TensorProto.string_data) -} -inline void TensorProto::set_string_data(int index, const void* value, size_t size) { - string_data_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.TensorProto.string_data) -} -inline ::std::string* TensorProto::add_string_data() { - // @@protoc_insertion_point(field_add_mutable:caffe2.TensorProto.string_data) - return string_data_.Add(); -} -inline void TensorProto::add_string_data(const ::std::string& value) { - string_data_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.string_data) -} -inline void TensorProto::add_string_data(const char* value) { - string_data_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.TensorProto.string_data) -} -inline void TensorProto::add_string_data(const void* value, size_t size) { - string_data_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.TensorProto.string_data) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -TensorProto::string_data() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.string_data) - return string_data_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -TensorProto::mutable_string_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.string_data) - return &string_data_; -} - -// repeated double double_data = 9 [packed = true]; -inline int TensorProto::double_data_size() const { - return double_data_.size(); -} -inline void TensorProto::clear_double_data() { - double_data_.Clear(); -} -inline double TensorProto::double_data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.double_data) - return double_data_.Get(index); -} -inline void TensorProto::set_double_data(int index, double value) { - double_data_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.double_data) -} -inline void TensorProto::add_double_data(double value) { - double_data_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.double_data) -} -inline const ::google::protobuf::RepeatedField< double >& -TensorProto::double_data() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.double_data) - return double_data_; -} -inline ::google::protobuf::RepeatedField< double >* -TensorProto::mutable_double_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.double_data) - return &double_data_; -} - -// repeated int64 int64_data = 10 [packed = true]; -inline int TensorProto::int64_data_size() const { - return int64_data_.size(); -} -inline void TensorProto::clear_int64_data() { - int64_data_.Clear(); -} -inline ::google::protobuf::int64 TensorProto::int64_data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.int64_data) - return int64_data_.Get(index); -} -inline void TensorProto::set_int64_data(int index, ::google::protobuf::int64 value) { - int64_data_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.int64_data) -} -inline void TensorProto::add_int64_data(::google::protobuf::int64 value) { - int64_data_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorProto.int64_data) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TensorProto::int64_data() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProto.int64_data) - return int64_data_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TensorProto::mutable_int64_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProto.int64_data) - return &int64_data_; -} - -// optional string name = 7; -inline bool TensorProto::has_name() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void TensorProto::set_has_name() { - _has_bits_[0] |= 0x00000100u; -} -inline void TensorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000100u; -} -inline void TensorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& TensorProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.TensorProto.name) -} -inline void TensorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.TensorProto.name) -} -inline void TensorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.TensorProto.name) -} -inline ::std::string* TensorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.TensorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* TensorProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.TensorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.TensorProto.name) -} - -// optional .caffe2.DeviceOption device_detail = 8; -inline bool TensorProto::has_device_detail() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void TensorProto::set_has_device_detail() { - _has_bits_[0] |= 0x00000200u; -} -inline void TensorProto::clear_has_device_detail() { - _has_bits_[0] &= ~0x00000200u; -} -inline void TensorProto::clear_device_detail() { - if (device_detail_ != NULL) device_detail_->::caffe2::DeviceOption::Clear(); - clear_has_device_detail(); -} -inline const ::caffe2::DeviceOption& TensorProto::device_detail() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.device_detail) - return device_detail_ != NULL ? *device_detail_ - : *::caffe2::DeviceOption::internal_default_instance(); -} -inline ::caffe2::DeviceOption* TensorProto::mutable_device_detail() { - set_has_device_detail(); - if (device_detail_ == NULL) { - device_detail_ = new ::caffe2::DeviceOption; - } - // @@protoc_insertion_point(field_mutable:caffe2.TensorProto.device_detail) - return device_detail_; -} -inline ::caffe2::DeviceOption* TensorProto::release_device_detail() { - // @@protoc_insertion_point(field_release:caffe2.TensorProto.device_detail) - clear_has_device_detail(); - ::caffe2::DeviceOption* temp = device_detail_; - device_detail_ = NULL; - return temp; -} -inline void TensorProto::set_allocated_device_detail(::caffe2::DeviceOption* device_detail) { - delete device_detail_; - device_detail_ = device_detail; - if (device_detail) { - set_has_device_detail(); - } else { - clear_has_device_detail(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.TensorProto.device_detail) -} - -// optional .caffe2.TensorProto.Segment segment = 11; -inline bool TensorProto::has_segment() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void TensorProto::set_has_segment() { - _has_bits_[0] |= 0x00000400u; -} -inline void TensorProto::clear_has_segment() { - _has_bits_[0] &= ~0x00000400u; -} -inline void TensorProto::clear_segment() { - if (segment_ != NULL) segment_->::caffe2::TensorProto_Segment::Clear(); - clear_has_segment(); -} -inline const ::caffe2::TensorProto_Segment& TensorProto::segment() const { - // @@protoc_insertion_point(field_get:caffe2.TensorProto.segment) - return segment_ != NULL ? *segment_ - : *::caffe2::TensorProto_Segment::internal_default_instance(); -} -inline ::caffe2::TensorProto_Segment* TensorProto::mutable_segment() { - set_has_segment(); - if (segment_ == NULL) { - segment_ = new ::caffe2::TensorProto_Segment; - } - // @@protoc_insertion_point(field_mutable:caffe2.TensorProto.segment) - return segment_; -} -inline ::caffe2::TensorProto_Segment* TensorProto::release_segment() { - // @@protoc_insertion_point(field_release:caffe2.TensorProto.segment) - clear_has_segment(); - ::caffe2::TensorProto_Segment* temp = segment_; - segment_ = NULL; - return temp; -} -inline void TensorProto::set_allocated_segment(::caffe2::TensorProto_Segment* segment) { - delete segment_; - segment_ = segment; - if (segment) { - set_has_segment(); - } else { - clear_has_segment(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.TensorProto.segment) -} - -inline const TensorProto* TensorProto::internal_default_instance() { - return &TensorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// QTensorProto - -// repeated int64 dims = 1; -inline int QTensorProto::dims_size() const { - return dims_.size(); -} -inline void QTensorProto::clear_dims() { - dims_.Clear(); -} -inline ::google::protobuf::int64 QTensorProto::dims(int index) const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.dims) - return dims_.Get(index); -} -inline void QTensorProto::set_dims(int index, ::google::protobuf::int64 value) { - dims_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.dims) -} -inline void QTensorProto::add_dims(::google::protobuf::int64 value) { - dims_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.QTensorProto.dims) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -QTensorProto::dims() const { - // @@protoc_insertion_point(field_list:caffe2.QTensorProto.dims) - return dims_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -QTensorProto::mutable_dims() { - // @@protoc_insertion_point(field_mutable_list:caffe2.QTensorProto.dims) - return &dims_; -} - -// required int32 precision = 2; -inline bool QTensorProto::has_precision() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void QTensorProto::set_has_precision() { - _has_bits_[0] |= 0x00000002u; -} -inline void QTensorProto::clear_has_precision() { - _has_bits_[0] &= ~0x00000002u; -} -inline void QTensorProto::clear_precision() { - precision_ = 0; - clear_has_precision(); -} -inline ::google::protobuf::int32 QTensorProto::precision() const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.precision) - return precision_; -} -inline void QTensorProto::set_precision(::google::protobuf::int32 value) { - set_has_precision(); - precision_ = value; - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.precision) -} - -// required double scale = 3; -inline bool QTensorProto::has_scale() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void QTensorProto::set_has_scale() { - _has_bits_[0] |= 0x00000004u; -} -inline void QTensorProto::clear_has_scale() { - _has_bits_[0] &= ~0x00000004u; -} -inline void QTensorProto::clear_scale() { - scale_ = 0; - clear_has_scale(); -} -inline double QTensorProto::scale() const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.scale) - return scale_; -} -inline void QTensorProto::set_scale(double value) { - set_has_scale(); - scale_ = value; - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.scale) -} - -// required double bias = 4; -inline bool QTensorProto::has_bias() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void QTensorProto::set_has_bias() { - _has_bits_[0] |= 0x00000008u; -} -inline void QTensorProto::clear_has_bias() { - _has_bits_[0] &= ~0x00000008u; -} -inline void QTensorProto::clear_bias() { - bias_ = 0; - clear_has_bias(); -} -inline double QTensorProto::bias() const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.bias) - return bias_; -} -inline void QTensorProto::set_bias(double value) { - set_has_bias(); - bias_ = value; - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.bias) -} - -// required bool is_signed = 5; -inline bool QTensorProto::has_is_signed() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void QTensorProto::set_has_is_signed() { - _has_bits_[0] |= 0x00000010u; -} -inline void QTensorProto::clear_has_is_signed() { - _has_bits_[0] &= ~0x00000010u; -} -inline void QTensorProto::clear_is_signed() { - is_signed_ = false; - clear_has_is_signed(); -} -inline bool QTensorProto::is_signed() const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.is_signed) - return is_signed_; -} -inline void QTensorProto::set_is_signed(bool value) { - set_has_is_signed(); - is_signed_ = value; - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.is_signed) -} - -// repeated int32 data = 6 [packed = true]; -inline int QTensorProto::data_size() const { - return data_.size(); -} -inline void QTensorProto::clear_data() { - data_.Clear(); -} -inline ::google::protobuf::int32 QTensorProto::data(int index) const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.data) - return data_.Get(index); -} -inline void QTensorProto::set_data(int index, ::google::protobuf::int32 value) { - data_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.data) -} -inline void QTensorProto::add_data(::google::protobuf::int32 value) { - data_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.QTensorProto.data) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -QTensorProto::data() const { - // @@protoc_insertion_point(field_list:caffe2.QTensorProto.data) - return data_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -QTensorProto::mutable_data() { - // @@protoc_insertion_point(field_mutable_list:caffe2.QTensorProto.data) - return &data_; -} - -// optional string name = 7; -inline bool QTensorProto::has_name() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void QTensorProto::set_has_name() { - _has_bits_[0] |= 0x00000040u; -} -inline void QTensorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000040u; -} -inline void QTensorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& QTensorProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.QTensorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void QTensorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.QTensorProto.name) -} -inline void QTensorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.QTensorProto.name) -} -inline void QTensorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.QTensorProto.name) -} -inline ::std::string* QTensorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.QTensorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* QTensorProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.QTensorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void QTensorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.QTensorProto.name) -} - -inline const QTensorProto* QTensorProto::internal_default_instance() { - return &QTensorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// TensorProtos - -// repeated .caffe2.TensorProto protos = 1; -inline int TensorProtos::protos_size() const { - return protos_.size(); -} -inline void TensorProtos::clear_protos() { - protos_.Clear(); -} -inline const ::caffe2::TensorProto& TensorProtos::protos(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorProtos.protos) - return protos_.Get(index); -} -inline ::caffe2::TensorProto* TensorProtos::mutable_protos(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.TensorProtos.protos) - return protos_.Mutable(index); -} -inline ::caffe2::TensorProto* TensorProtos::add_protos() { - // @@protoc_insertion_point(field_add:caffe2.TensorProtos.protos) - return protos_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::TensorProto >* -TensorProtos::mutable_protos() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorProtos.protos) - return &protos_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::TensorProto >& -TensorProtos::protos() const { - // @@protoc_insertion_point(field_list:caffe2.TensorProtos.protos) - return protos_; -} - -inline const TensorProtos* TensorProtos::internal_default_instance() { - return &TensorProtos_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// TensorShape - -// repeated int64 dims = 1; -inline int TensorShape::dims_size() const { - return dims_.size(); -} -inline void TensorShape::clear_dims() { - dims_.Clear(); -} -inline ::google::protobuf::int64 TensorShape::dims(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorShape.dims) - return dims_.Get(index); -} -inline void TensorShape::set_dims(int index, ::google::protobuf::int64 value) { - dims_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorShape.dims) -} -inline void TensorShape::add_dims(::google::protobuf::int64 value) { - dims_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorShape.dims) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -TensorShape::dims() const { - // @@protoc_insertion_point(field_list:caffe2.TensorShape.dims) - return dims_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -TensorShape::mutable_dims() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorShape.dims) - return &dims_; -} - -// optional .caffe2.TensorProto.DataType data_type = 2 [default = FLOAT]; -inline bool TensorShape::has_data_type() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void TensorShape::set_has_data_type() { - _has_bits_[0] |= 0x00000002u; -} -inline void TensorShape::clear_has_data_type() { - _has_bits_[0] &= ~0x00000002u; -} -inline void TensorShape::clear_data_type() { - data_type_ = 1; - clear_has_data_type(); -} -inline ::caffe2::TensorProto_DataType TensorShape::data_type() const { - // @@protoc_insertion_point(field_get:caffe2.TensorShape.data_type) - return static_cast< ::caffe2::TensorProto_DataType >(data_type_); -} -inline void TensorShape::set_data_type(::caffe2::TensorProto_DataType value) { - assert(::caffe2::TensorProto_DataType_IsValid(value)); - set_has_data_type(); - data_type_ = value; - // @@protoc_insertion_point(field_set:caffe2.TensorShape.data_type) -} - -// repeated int32 unknown_dims = 3; -inline int TensorShape::unknown_dims_size() const { - return unknown_dims_.size(); -} -inline void TensorShape::clear_unknown_dims() { - unknown_dims_.Clear(); -} -inline ::google::protobuf::int32 TensorShape::unknown_dims(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorShape.unknown_dims) - return unknown_dims_.Get(index); -} -inline void TensorShape::set_unknown_dims(int index, ::google::protobuf::int32 value) { - unknown_dims_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.TensorShape.unknown_dims) -} -inline void TensorShape::add_unknown_dims(::google::protobuf::int32 value) { - unknown_dims_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.TensorShape.unknown_dims) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -TensorShape::unknown_dims() const { - // @@protoc_insertion_point(field_list:caffe2.TensorShape.unknown_dims) - return unknown_dims_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -TensorShape::mutable_unknown_dims() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorShape.unknown_dims) - return &unknown_dims_; -} - -// optional bool unknown_shape = 4 [default = false]; -inline bool TensorShape::has_unknown_shape() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void TensorShape::set_has_unknown_shape() { - _has_bits_[0] |= 0x00000008u; -} -inline void TensorShape::clear_has_unknown_shape() { - _has_bits_[0] &= ~0x00000008u; -} -inline void TensorShape::clear_unknown_shape() { - unknown_shape_ = false; - clear_has_unknown_shape(); -} -inline bool TensorShape::unknown_shape() const { - // @@protoc_insertion_point(field_get:caffe2.TensorShape.unknown_shape) - return unknown_shape_; -} -inline void TensorShape::set_unknown_shape(bool value) { - set_has_unknown_shape(); - unknown_shape_ = value; - // @@protoc_insertion_point(field_set:caffe2.TensorShape.unknown_shape) -} - -// optional string name = 5; -inline bool TensorShape::has_name() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void TensorShape::set_has_name() { - _has_bits_[0] |= 0x00000010u; -} -inline void TensorShape::clear_has_name() { - _has_bits_[0] &= ~0x00000010u; -} -inline void TensorShape::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& TensorShape::name() const { - // @@protoc_insertion_point(field_get:caffe2.TensorShape.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorShape::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.TensorShape.name) -} -inline void TensorShape::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.TensorShape.name) -} -inline void TensorShape::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.TensorShape.name) -} -inline ::std::string* TensorShape::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.TensorShape.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* TensorShape::release_name() { - // @@protoc_insertion_point(field_release:caffe2.TensorShape.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void TensorShape::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.TensorShape.name) -} - -inline const TensorShape* TensorShape::internal_default_instance() { - return &TensorShape_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// TensorShapes - -// repeated .caffe2.TensorShape shapes = 1; -inline int TensorShapes::shapes_size() const { - return shapes_.size(); -} -inline void TensorShapes::clear_shapes() { - shapes_.Clear(); -} -inline const ::caffe2::TensorShape& TensorShapes::shapes(int index) const { - // @@protoc_insertion_point(field_get:caffe2.TensorShapes.shapes) - return shapes_.Get(index); -} -inline ::caffe2::TensorShape* TensorShapes::mutable_shapes(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.TensorShapes.shapes) - return shapes_.Mutable(index); -} -inline ::caffe2::TensorShape* TensorShapes::add_shapes() { - // @@protoc_insertion_point(field_add:caffe2.TensorShapes.shapes) - return shapes_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::TensorShape >* -TensorShapes::mutable_shapes() { - // @@protoc_insertion_point(field_mutable_list:caffe2.TensorShapes.shapes) - return &shapes_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::TensorShape >& -TensorShapes::shapes() const { - // @@protoc_insertion_point(field_list:caffe2.TensorShapes.shapes) - return shapes_; -} - -inline const TensorShapes* TensorShapes::internal_default_instance() { - return &TensorShapes_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// Argument - -// optional string name = 1; -inline bool Argument::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void Argument::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void Argument::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void Argument::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& Argument::name() const { - // @@protoc_insertion_point(field_get:caffe2.Argument.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Argument::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.Argument.name) -} -inline void Argument::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.Argument.name) -} -inline void Argument::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.Argument.name) -} -inline ::std::string* Argument::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.Argument.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Argument::release_name() { - // @@protoc_insertion_point(field_release:caffe2.Argument.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Argument::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.Argument.name) -} - -// optional float f = 2; -inline bool Argument::has_f() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void Argument::set_has_f() { - _has_bits_[0] |= 0x00000002u; -} -inline void Argument::clear_has_f() { - _has_bits_[0] &= ~0x00000002u; -} -inline void Argument::clear_f() { - f_ = 0; - clear_has_f(); -} -inline float Argument::f() const { - // @@protoc_insertion_point(field_get:caffe2.Argument.f) - return f_; -} -inline void Argument::set_f(float value) { - set_has_f(); - f_ = value; - // @@protoc_insertion_point(field_set:caffe2.Argument.f) -} - -// optional int64 i = 3; -inline bool Argument::has_i() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void Argument::set_has_i() { - _has_bits_[0] |= 0x00000004u; -} -inline void Argument::clear_has_i() { - _has_bits_[0] &= ~0x00000004u; -} -inline void Argument::clear_i() { - i_ = GOOGLE_LONGLONG(0); - clear_has_i(); -} -inline ::google::protobuf::int64 Argument::i() const { - // @@protoc_insertion_point(field_get:caffe2.Argument.i) - return i_; -} -inline void Argument::set_i(::google::protobuf::int64 value) { - set_has_i(); - i_ = value; - // @@protoc_insertion_point(field_set:caffe2.Argument.i) -} - -// optional bytes s = 4; -inline bool Argument::has_s() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void Argument::set_has_s() { - _has_bits_[0] |= 0x00000008u; -} -inline void Argument::clear_has_s() { - _has_bits_[0] &= ~0x00000008u; -} -inline void Argument::clear_s() { - s_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_s(); -} -inline const ::std::string& Argument::s() const { - // @@protoc_insertion_point(field_get:caffe2.Argument.s) - return s_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Argument::set_s(const ::std::string& value) { - set_has_s(); - s_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.Argument.s) -} -inline void Argument::set_s(const char* value) { - set_has_s(); - s_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.Argument.s) -} -inline void Argument::set_s(const void* value, size_t size) { - set_has_s(); - s_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.Argument.s) -} -inline ::std::string* Argument::mutable_s() { - set_has_s(); - // @@protoc_insertion_point(field_mutable:caffe2.Argument.s) - return s_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Argument::release_s() { - // @@protoc_insertion_point(field_release:caffe2.Argument.s) - clear_has_s(); - return s_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Argument::set_allocated_s(::std::string* s) { - if (s != NULL) { - set_has_s(); - } else { - clear_has_s(); - } - s_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), s); - // @@protoc_insertion_point(field_set_allocated:caffe2.Argument.s) -} - -// optional .caffe2.NetDef n = 8; -inline bool Argument::has_n() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void Argument::set_has_n() { - _has_bits_[0] |= 0x00000010u; -} -inline void Argument::clear_has_n() { - _has_bits_[0] &= ~0x00000010u; -} -inline void Argument::clear_n() { - if (n_ != NULL) n_->::caffe2::NetDef::Clear(); - clear_has_n(); -} -inline const ::caffe2::NetDef& Argument::n() const { - // @@protoc_insertion_point(field_get:caffe2.Argument.n) - return n_ != NULL ? *n_ - : *::caffe2::NetDef::internal_default_instance(); -} -inline ::caffe2::NetDef* Argument::mutable_n() { - set_has_n(); - if (n_ == NULL) { - n_ = new ::caffe2::NetDef; - } - // @@protoc_insertion_point(field_mutable:caffe2.Argument.n) - return n_; -} -inline ::caffe2::NetDef* Argument::release_n() { - // @@protoc_insertion_point(field_release:caffe2.Argument.n) - clear_has_n(); - ::caffe2::NetDef* temp = n_; - n_ = NULL; - return temp; -} -inline void Argument::set_allocated_n(::caffe2::NetDef* n) { - delete n_; - n_ = n; - if (n) { - set_has_n(); - } else { - clear_has_n(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.Argument.n) -} - -// repeated float floats = 5; -inline int Argument::floats_size() const { - return floats_.size(); -} -inline void Argument::clear_floats() { - floats_.Clear(); -} -inline float Argument::floats(int index) const { - // @@protoc_insertion_point(field_get:caffe2.Argument.floats) - return floats_.Get(index); -} -inline void Argument::set_floats(int index, float value) { - floats_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.Argument.floats) -} -inline void Argument::add_floats(float value) { - floats_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.Argument.floats) -} -inline const ::google::protobuf::RepeatedField< float >& -Argument::floats() const { - // @@protoc_insertion_point(field_list:caffe2.Argument.floats) - return floats_; -} -inline ::google::protobuf::RepeatedField< float >* -Argument::mutable_floats() { - // @@protoc_insertion_point(field_mutable_list:caffe2.Argument.floats) - return &floats_; -} - -// repeated int64 ints = 6; -inline int Argument::ints_size() const { - return ints_.size(); -} -inline void Argument::clear_ints() { - ints_.Clear(); -} -inline ::google::protobuf::int64 Argument::ints(int index) const { - // @@protoc_insertion_point(field_get:caffe2.Argument.ints) - return ints_.Get(index); -} -inline void Argument::set_ints(int index, ::google::protobuf::int64 value) { - ints_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.Argument.ints) -} -inline void Argument::add_ints(::google::protobuf::int64 value) { - ints_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.Argument.ints) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int64 >& -Argument::ints() const { - // @@protoc_insertion_point(field_list:caffe2.Argument.ints) - return ints_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int64 >* -Argument::mutable_ints() { - // @@protoc_insertion_point(field_mutable_list:caffe2.Argument.ints) - return &ints_; -} - -// repeated bytes strings = 7; -inline int Argument::strings_size() const { - return strings_.size(); -} -inline void Argument::clear_strings() { - strings_.Clear(); -} -inline const ::std::string& Argument::strings(int index) const { - // @@protoc_insertion_point(field_get:caffe2.Argument.strings) - return strings_.Get(index); -} -inline ::std::string* Argument::mutable_strings(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.Argument.strings) - return strings_.Mutable(index); -} -inline void Argument::set_strings(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.Argument.strings) - strings_.Mutable(index)->assign(value); -} -inline void Argument::set_strings(int index, const char* value) { - strings_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.Argument.strings) -} -inline void Argument::set_strings(int index, const void* value, size_t size) { - strings_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.Argument.strings) -} -inline ::std::string* Argument::add_strings() { - // @@protoc_insertion_point(field_add_mutable:caffe2.Argument.strings) - return strings_.Add(); -} -inline void Argument::add_strings(const ::std::string& value) { - strings_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.Argument.strings) -} -inline void Argument::add_strings(const char* value) { - strings_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.Argument.strings) -} -inline void Argument::add_strings(const void* value, size_t size) { - strings_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.Argument.strings) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -Argument::strings() const { - // @@protoc_insertion_point(field_list:caffe2.Argument.strings) - return strings_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -Argument::mutable_strings() { - // @@protoc_insertion_point(field_mutable_list:caffe2.Argument.strings) - return &strings_; -} - -// repeated .caffe2.NetDef nets = 9; -inline int Argument::nets_size() const { - return nets_.size(); -} -inline void Argument::clear_nets() { - nets_.Clear(); -} -inline const ::caffe2::NetDef& Argument::nets(int index) const { - // @@protoc_insertion_point(field_get:caffe2.Argument.nets) - return nets_.Get(index); -} -inline ::caffe2::NetDef* Argument::mutable_nets(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.Argument.nets) - return nets_.Mutable(index); -} -inline ::caffe2::NetDef* Argument::add_nets() { - // @@protoc_insertion_point(field_add:caffe2.Argument.nets) - return nets_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >* -Argument::mutable_nets() { - // @@protoc_insertion_point(field_mutable_list:caffe2.Argument.nets) - return &nets_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >& -Argument::nets() const { - // @@protoc_insertion_point(field_list:caffe2.Argument.nets) - return nets_; -} - -inline const Argument* Argument::internal_default_instance() { - return &Argument_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// DeviceOption - -// optional int32 device_type = 1 [default = 0]; -inline bool DeviceOption::has_device_type() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DeviceOption::set_has_device_type() { - _has_bits_[0] |= 0x00000001u; -} -inline void DeviceOption::clear_has_device_type() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DeviceOption::clear_device_type() { - device_type_ = 0; - clear_has_device_type(); -} -inline ::google::protobuf::int32 DeviceOption::device_type() const { - // @@protoc_insertion_point(field_get:caffe2.DeviceOption.device_type) - return device_type_; -} -inline void DeviceOption::set_device_type(::google::protobuf::int32 value) { - set_has_device_type(); - device_type_ = value; - // @@protoc_insertion_point(field_set:caffe2.DeviceOption.device_type) -} - -// optional int32 cuda_gpu_id = 2; -inline bool DeviceOption::has_cuda_gpu_id() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void DeviceOption::set_has_cuda_gpu_id() { - _has_bits_[0] |= 0x00000002u; -} -inline void DeviceOption::clear_has_cuda_gpu_id() { - _has_bits_[0] &= ~0x00000002u; -} -inline void DeviceOption::clear_cuda_gpu_id() { - cuda_gpu_id_ = 0; - clear_has_cuda_gpu_id(); -} -inline ::google::protobuf::int32 DeviceOption::cuda_gpu_id() const { - // @@protoc_insertion_point(field_get:caffe2.DeviceOption.cuda_gpu_id) - return cuda_gpu_id_; -} -inline void DeviceOption::set_cuda_gpu_id(::google::protobuf::int32 value) { - set_has_cuda_gpu_id(); - cuda_gpu_id_ = value; - // @@protoc_insertion_point(field_set:caffe2.DeviceOption.cuda_gpu_id) -} - -// optional uint32 random_seed = 3; -inline bool DeviceOption::has_random_seed() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void DeviceOption::set_has_random_seed() { - _has_bits_[0] |= 0x00000004u; -} -inline void DeviceOption::clear_has_random_seed() { - _has_bits_[0] &= ~0x00000004u; -} -inline void DeviceOption::clear_random_seed() { - random_seed_ = 0u; - clear_has_random_seed(); -} -inline ::google::protobuf::uint32 DeviceOption::random_seed() const { - // @@protoc_insertion_point(field_get:caffe2.DeviceOption.random_seed) - return random_seed_; -} -inline void DeviceOption::set_random_seed(::google::protobuf::uint32 value) { - set_has_random_seed(); - random_seed_ = value; - // @@protoc_insertion_point(field_set:caffe2.DeviceOption.random_seed) -} - -// optional string node_name = 4; -inline bool DeviceOption::has_node_name() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void DeviceOption::set_has_node_name() { - _has_bits_[0] |= 0x00000008u; -} -inline void DeviceOption::clear_has_node_name() { - _has_bits_[0] &= ~0x00000008u; -} -inline void DeviceOption::clear_node_name() { - node_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_node_name(); -} -inline const ::std::string& DeviceOption::node_name() const { - // @@protoc_insertion_point(field_get:caffe2.DeviceOption.node_name) - return node_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DeviceOption::set_node_name(const ::std::string& value) { - set_has_node_name(); - node_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.DeviceOption.node_name) -} -inline void DeviceOption::set_node_name(const char* value) { - set_has_node_name(); - node_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.DeviceOption.node_name) -} -inline void DeviceOption::set_node_name(const char* value, size_t size) { - set_has_node_name(); - node_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.DeviceOption.node_name) -} -inline ::std::string* DeviceOption::mutable_node_name() { - set_has_node_name(); - // @@protoc_insertion_point(field_mutable:caffe2.DeviceOption.node_name) - return node_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DeviceOption::release_node_name() { - // @@protoc_insertion_point(field_release:caffe2.DeviceOption.node_name) - clear_has_node_name(); - return node_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DeviceOption::set_allocated_node_name(::std::string* node_name) { - if (node_name != NULL) { - set_has_node_name(); - } else { - clear_has_node_name(); - } - node_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), node_name); - // @@protoc_insertion_point(field_set_allocated:caffe2.DeviceOption.node_name) -} - -inline const DeviceOption* DeviceOption::internal_default_instance() { - return &DeviceOption_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// OperatorDef - -// repeated string input = 1; -inline int OperatorDef::input_size() const { - return input_.size(); -} -inline void OperatorDef::clear_input() { - input_.Clear(); -} -inline const ::std::string& OperatorDef::input(int index) const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.input) - return input_.Get(index); -} -inline ::std::string* OperatorDef::mutable_input(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.input) - return input_.Mutable(index); -} -inline void OperatorDef::set_input(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.input) - input_.Mutable(index)->assign(value); -} -inline void OperatorDef::set_input(int index, const char* value) { - input_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.input) -} -inline void OperatorDef::set_input(int index, const char* value, size_t size) { - input_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.input) -} -inline ::std::string* OperatorDef::add_input() { - // @@protoc_insertion_point(field_add_mutable:caffe2.OperatorDef.input) - return input_.Add(); -} -inline void OperatorDef::add_input(const ::std::string& value) { - input_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.OperatorDef.input) -} -inline void OperatorDef::add_input(const char* value) { - input_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.OperatorDef.input) -} -inline void OperatorDef::add_input(const char* value, size_t size) { - input_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.OperatorDef.input) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -OperatorDef::input() const { - // @@protoc_insertion_point(field_list:caffe2.OperatorDef.input) - return input_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -OperatorDef::mutable_input() { - // @@protoc_insertion_point(field_mutable_list:caffe2.OperatorDef.input) - return &input_; -} - -// repeated string output = 2; -inline int OperatorDef::output_size() const { - return output_.size(); -} -inline void OperatorDef::clear_output() { - output_.Clear(); -} -inline const ::std::string& OperatorDef::output(int index) const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.output) - return output_.Get(index); -} -inline ::std::string* OperatorDef::mutable_output(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.output) - return output_.Mutable(index); -} -inline void OperatorDef::set_output(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.output) - output_.Mutable(index)->assign(value); -} -inline void OperatorDef::set_output(int index, const char* value) { - output_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.output) -} -inline void OperatorDef::set_output(int index, const char* value, size_t size) { - output_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.output) -} -inline ::std::string* OperatorDef::add_output() { - // @@protoc_insertion_point(field_add_mutable:caffe2.OperatorDef.output) - return output_.Add(); -} -inline void OperatorDef::add_output(const ::std::string& value) { - output_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.OperatorDef.output) -} -inline void OperatorDef::add_output(const char* value) { - output_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.OperatorDef.output) -} -inline void OperatorDef::add_output(const char* value, size_t size) { - output_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.OperatorDef.output) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -OperatorDef::output() const { - // @@protoc_insertion_point(field_list:caffe2.OperatorDef.output) - return output_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -OperatorDef::mutable_output() { - // @@protoc_insertion_point(field_mutable_list:caffe2.OperatorDef.output) - return &output_; -} - -// optional string name = 3; -inline bool OperatorDef::has_name() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void OperatorDef::set_has_name() { - _has_bits_[0] |= 0x00000004u; -} -inline void OperatorDef::clear_has_name() { - _has_bits_[0] &= ~0x00000004u; -} -inline void OperatorDef::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& OperatorDef::name() const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.name) -} -inline void OperatorDef::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.name) -} -inline void OperatorDef::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.name) -} -inline ::std::string* OperatorDef::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* OperatorDef::release_name() { - // @@protoc_insertion_point(field_release:caffe2.OperatorDef.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.OperatorDef.name) -} - -// optional string type = 4; -inline bool OperatorDef::has_type() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void OperatorDef::set_has_type() { - _has_bits_[0] |= 0x00000008u; -} -inline void OperatorDef::clear_has_type() { - _has_bits_[0] &= ~0x00000008u; -} -inline void OperatorDef::clear_type() { - type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_type(); -} -inline const ::std::string& OperatorDef::type() const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.type) - return type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_type(const ::std::string& value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.type) -} -inline void OperatorDef::set_type(const char* value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.type) -} -inline void OperatorDef::set_type(const char* value, size_t size) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.type) -} -inline ::std::string* OperatorDef::mutable_type() { - set_has_type(); - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.type) - return type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* OperatorDef::release_type() { - // @@protoc_insertion_point(field_release:caffe2.OperatorDef.type) - clear_has_type(); - return type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_allocated_type(::std::string* type) { - if (type != NULL) { - set_has_type(); - } else { - clear_has_type(); - } - type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type); - // @@protoc_insertion_point(field_set_allocated:caffe2.OperatorDef.type) -} - -// repeated .caffe2.Argument arg = 5; -inline int OperatorDef::arg_size() const { - return arg_.size(); -} -inline void OperatorDef::clear_arg() { - arg_.Clear(); -} -inline const ::caffe2::Argument& OperatorDef::arg(int index) const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.arg) - return arg_.Get(index); -} -inline ::caffe2::Argument* OperatorDef::mutable_arg(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.arg) - return arg_.Mutable(index); -} -inline ::caffe2::Argument* OperatorDef::add_arg() { - // @@protoc_insertion_point(field_add:caffe2.OperatorDef.arg) - return arg_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >* -OperatorDef::mutable_arg() { - // @@protoc_insertion_point(field_mutable_list:caffe2.OperatorDef.arg) - return &arg_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >& -OperatorDef::arg() const { - // @@protoc_insertion_point(field_list:caffe2.OperatorDef.arg) - return arg_; -} - -// optional .caffe2.DeviceOption device_option = 6; -inline bool OperatorDef::has_device_option() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void OperatorDef::set_has_device_option() { - _has_bits_[0] |= 0x00000020u; -} -inline void OperatorDef::clear_has_device_option() { - _has_bits_[0] &= ~0x00000020u; -} -inline void OperatorDef::clear_device_option() { - if (device_option_ != NULL) device_option_->::caffe2::DeviceOption::Clear(); - clear_has_device_option(); -} -inline const ::caffe2::DeviceOption& OperatorDef::device_option() const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.device_option) - return device_option_ != NULL ? *device_option_ - : *::caffe2::DeviceOption::internal_default_instance(); -} -inline ::caffe2::DeviceOption* OperatorDef::mutable_device_option() { - set_has_device_option(); - if (device_option_ == NULL) { - device_option_ = new ::caffe2::DeviceOption; - } - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.device_option) - return device_option_; -} -inline ::caffe2::DeviceOption* OperatorDef::release_device_option() { - // @@protoc_insertion_point(field_release:caffe2.OperatorDef.device_option) - clear_has_device_option(); - ::caffe2::DeviceOption* temp = device_option_; - device_option_ = NULL; - return temp; -} -inline void OperatorDef::set_allocated_device_option(::caffe2::DeviceOption* device_option) { - delete device_option_; - device_option_ = device_option; - if (device_option) { - set_has_device_option(); - } else { - clear_has_device_option(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.OperatorDef.device_option) -} - -// optional string engine = 7; -inline bool OperatorDef::has_engine() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void OperatorDef::set_has_engine() { - _has_bits_[0] |= 0x00000040u; -} -inline void OperatorDef::clear_has_engine() { - _has_bits_[0] &= ~0x00000040u; -} -inline void OperatorDef::clear_engine() { - engine_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_engine(); -} -inline const ::std::string& OperatorDef::engine() const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.engine) - return engine_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_engine(const ::std::string& value) { - set_has_engine(); - engine_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.engine) -} -inline void OperatorDef::set_engine(const char* value) { - set_has_engine(); - engine_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.engine) -} -inline void OperatorDef::set_engine(const char* value, size_t size) { - set_has_engine(); - engine_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.engine) -} -inline ::std::string* OperatorDef::mutable_engine() { - set_has_engine(); - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.engine) - return engine_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* OperatorDef::release_engine() { - // @@protoc_insertion_point(field_release:caffe2.OperatorDef.engine) - clear_has_engine(); - return engine_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OperatorDef::set_allocated_engine(::std::string* engine) { - if (engine != NULL) { - set_has_engine(); - } else { - clear_has_engine(); - } - engine_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), engine); - // @@protoc_insertion_point(field_set_allocated:caffe2.OperatorDef.engine) -} - -// repeated string control_input = 8; -inline int OperatorDef::control_input_size() const { - return control_input_.size(); -} -inline void OperatorDef::clear_control_input() { - control_input_.Clear(); -} -inline const ::std::string& OperatorDef::control_input(int index) const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.control_input) - return control_input_.Get(index); -} -inline ::std::string* OperatorDef::mutable_control_input(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.OperatorDef.control_input) - return control_input_.Mutable(index); -} -inline void OperatorDef::set_control_input(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.control_input) - control_input_.Mutable(index)->assign(value); -} -inline void OperatorDef::set_control_input(int index, const char* value) { - control_input_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.OperatorDef.control_input) -} -inline void OperatorDef::set_control_input(int index, const char* value, size_t size) { - control_input_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.OperatorDef.control_input) -} -inline ::std::string* OperatorDef::add_control_input() { - // @@protoc_insertion_point(field_add_mutable:caffe2.OperatorDef.control_input) - return control_input_.Add(); -} -inline void OperatorDef::add_control_input(const ::std::string& value) { - control_input_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.OperatorDef.control_input) -} -inline void OperatorDef::add_control_input(const char* value) { - control_input_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.OperatorDef.control_input) -} -inline void OperatorDef::add_control_input(const char* value, size_t size) { - control_input_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.OperatorDef.control_input) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -OperatorDef::control_input() const { - // @@protoc_insertion_point(field_list:caffe2.OperatorDef.control_input) - return control_input_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -OperatorDef::mutable_control_input() { - // @@protoc_insertion_point(field_mutable_list:caffe2.OperatorDef.control_input) - return &control_input_; -} - -// optional bool is_gradient_op = 9 [default = false]; -inline bool OperatorDef::has_is_gradient_op() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void OperatorDef::set_has_is_gradient_op() { - _has_bits_[0] |= 0x00000100u; -} -inline void OperatorDef::clear_has_is_gradient_op() { - _has_bits_[0] &= ~0x00000100u; -} -inline void OperatorDef::clear_is_gradient_op() { - is_gradient_op_ = false; - clear_has_is_gradient_op(); -} -inline bool OperatorDef::is_gradient_op() const { - // @@protoc_insertion_point(field_get:caffe2.OperatorDef.is_gradient_op) - return is_gradient_op_; -} -inline void OperatorDef::set_is_gradient_op(bool value) { - set_has_is_gradient_op(); - is_gradient_op_ = value; - // @@protoc_insertion_point(field_set:caffe2.OperatorDef.is_gradient_op) -} - -inline const OperatorDef* OperatorDef::internal_default_instance() { - return &OperatorDef_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// NetDef - -// optional string name = 1; -inline bool NetDef::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void NetDef::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void NetDef::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void NetDef::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& NetDef::name() const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetDef::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.NetDef.name) -} -inline void NetDef::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.NetDef.name) -} -inline void NetDef::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.NetDef.name) -} -inline ::std::string* NetDef::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* NetDef::release_name() { - // @@protoc_insertion_point(field_release:caffe2.NetDef.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetDef::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.NetDef.name) -} - -// repeated .caffe2.OperatorDef op = 2; -inline int NetDef::op_size() const { - return op_.size(); -} -inline void NetDef::clear_op() { - op_.Clear(); -} -inline const ::caffe2::OperatorDef& NetDef::op(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.op) - return op_.Get(index); -} -inline ::caffe2::OperatorDef* NetDef::mutable_op(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.op) - return op_.Mutable(index); -} -inline ::caffe2::OperatorDef* NetDef::add_op() { - // @@protoc_insertion_point(field_add:caffe2.NetDef.op) - return op_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::OperatorDef >* -NetDef::mutable_op() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NetDef.op) - return &op_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::OperatorDef >& -NetDef::op() const { - // @@protoc_insertion_point(field_list:caffe2.NetDef.op) - return op_; -} - -// optional string type = 3; -inline bool NetDef::has_type() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void NetDef::set_has_type() { - _has_bits_[0] |= 0x00000004u; -} -inline void NetDef::clear_has_type() { - _has_bits_[0] &= ~0x00000004u; -} -inline void NetDef::clear_type() { - type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_type(); -} -inline const ::std::string& NetDef::type() const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.type) - return type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetDef::set_type(const ::std::string& value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.NetDef.type) -} -inline void NetDef::set_type(const char* value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.NetDef.type) -} -inline void NetDef::set_type(const char* value, size_t size) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.NetDef.type) -} -inline ::std::string* NetDef::mutable_type() { - set_has_type(); - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.type) - return type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* NetDef::release_type() { - // @@protoc_insertion_point(field_release:caffe2.NetDef.type) - clear_has_type(); - return type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetDef::set_allocated_type(::std::string* type) { - if (type != NULL) { - set_has_type(); - } else { - clear_has_type(); - } - type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type); - // @@protoc_insertion_point(field_set_allocated:caffe2.NetDef.type) -} - -// optional int32 num_workers = 4 [deprecated = true]; -inline bool NetDef::has_num_workers() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void NetDef::set_has_num_workers() { - _has_bits_[0] |= 0x00000008u; -} -inline void NetDef::clear_has_num_workers() { - _has_bits_[0] &= ~0x00000008u; -} -inline void NetDef::clear_num_workers() { - num_workers_ = 0; - clear_has_num_workers(); -} -inline ::google::protobuf::int32 NetDef::num_workers() const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.num_workers) - return num_workers_; -} -inline void NetDef::set_num_workers(::google::protobuf::int32 value) { - set_has_num_workers(); - num_workers_ = value; - // @@protoc_insertion_point(field_set:caffe2.NetDef.num_workers) -} - -// optional .caffe2.DeviceOption device_option = 5; -inline bool NetDef::has_device_option() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void NetDef::set_has_device_option() { - _has_bits_[0] |= 0x00000010u; -} -inline void NetDef::clear_has_device_option() { - _has_bits_[0] &= ~0x00000010u; -} -inline void NetDef::clear_device_option() { - if (device_option_ != NULL) device_option_->::caffe2::DeviceOption::Clear(); - clear_has_device_option(); -} -inline const ::caffe2::DeviceOption& NetDef::device_option() const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.device_option) - return device_option_ != NULL ? *device_option_ - : *::caffe2::DeviceOption::internal_default_instance(); -} -inline ::caffe2::DeviceOption* NetDef::mutable_device_option() { - set_has_device_option(); - if (device_option_ == NULL) { - device_option_ = new ::caffe2::DeviceOption; - } - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.device_option) - return device_option_; -} -inline ::caffe2::DeviceOption* NetDef::release_device_option() { - // @@protoc_insertion_point(field_release:caffe2.NetDef.device_option) - clear_has_device_option(); - ::caffe2::DeviceOption* temp = device_option_; - device_option_ = NULL; - return temp; -} -inline void NetDef::set_allocated_device_option(::caffe2::DeviceOption* device_option) { - delete device_option_; - device_option_ = device_option; - if (device_option) { - set_has_device_option(); - } else { - clear_has_device_option(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.NetDef.device_option) -} - -// repeated .caffe2.Argument arg = 6; -inline int NetDef::arg_size() const { - return arg_.size(); -} -inline void NetDef::clear_arg() { - arg_.Clear(); -} -inline const ::caffe2::Argument& NetDef::arg(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.arg) - return arg_.Get(index); -} -inline ::caffe2::Argument* NetDef::mutable_arg(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.arg) - return arg_.Mutable(index); -} -inline ::caffe2::Argument* NetDef::add_arg() { - // @@protoc_insertion_point(field_add:caffe2.NetDef.arg) - return arg_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >* -NetDef::mutable_arg() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NetDef.arg) - return &arg_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::Argument >& -NetDef::arg() const { - // @@protoc_insertion_point(field_list:caffe2.NetDef.arg) - return arg_; -} - -// repeated string external_input = 7; -inline int NetDef::external_input_size() const { - return external_input_.size(); -} -inline void NetDef::clear_external_input() { - external_input_.Clear(); -} -inline const ::std::string& NetDef::external_input(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.external_input) - return external_input_.Get(index); -} -inline ::std::string* NetDef::mutable_external_input(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.external_input) - return external_input_.Mutable(index); -} -inline void NetDef::set_external_input(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.NetDef.external_input) - external_input_.Mutable(index)->assign(value); -} -inline void NetDef::set_external_input(int index, const char* value) { - external_input_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.NetDef.external_input) -} -inline void NetDef::set_external_input(int index, const char* value, size_t size) { - external_input_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.NetDef.external_input) -} -inline ::std::string* NetDef::add_external_input() { - // @@protoc_insertion_point(field_add_mutable:caffe2.NetDef.external_input) - return external_input_.Add(); -} -inline void NetDef::add_external_input(const ::std::string& value) { - external_input_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.NetDef.external_input) -} -inline void NetDef::add_external_input(const char* value) { - external_input_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.NetDef.external_input) -} -inline void NetDef::add_external_input(const char* value, size_t size) { - external_input_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.NetDef.external_input) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -NetDef::external_input() const { - // @@protoc_insertion_point(field_list:caffe2.NetDef.external_input) - return external_input_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -NetDef::mutable_external_input() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NetDef.external_input) - return &external_input_; -} - -// repeated string external_output = 8; -inline int NetDef::external_output_size() const { - return external_output_.size(); -} -inline void NetDef::clear_external_output() { - external_output_.Clear(); -} -inline const ::std::string& NetDef::external_output(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NetDef.external_output) - return external_output_.Get(index); -} -inline ::std::string* NetDef::mutable_external_output(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.NetDef.external_output) - return external_output_.Mutable(index); -} -inline void NetDef::set_external_output(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.NetDef.external_output) - external_output_.Mutable(index)->assign(value); -} -inline void NetDef::set_external_output(int index, const char* value) { - external_output_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.NetDef.external_output) -} -inline void NetDef::set_external_output(int index, const char* value, size_t size) { - external_output_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.NetDef.external_output) -} -inline ::std::string* NetDef::add_external_output() { - // @@protoc_insertion_point(field_add_mutable:caffe2.NetDef.external_output) - return external_output_.Add(); -} -inline void NetDef::add_external_output(const ::std::string& value) { - external_output_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.NetDef.external_output) -} -inline void NetDef::add_external_output(const char* value) { - external_output_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.NetDef.external_output) -} -inline void NetDef::add_external_output(const char* value, size_t size) { - external_output_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.NetDef.external_output) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -NetDef::external_output() const { - // @@protoc_insertion_point(field_list:caffe2.NetDef.external_output) - return external_output_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -NetDef::mutable_external_output() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NetDef.external_output) - return &external_output_; -} - -inline const NetDef* NetDef::internal_default_instance() { - return &NetDef_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// ExecutionStep - -// optional string name = 1; -inline bool ExecutionStep::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ExecutionStep::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void ExecutionStep::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ExecutionStep::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& ExecutionStep::name() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.name) -} -inline void ExecutionStep::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ExecutionStep.name) -} -inline void ExecutionStep::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ExecutionStep.name) -} -inline ::std::string* ExecutionStep::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ExecutionStep::release_name() { - // @@protoc_insertion_point(field_release:caffe2.ExecutionStep.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.ExecutionStep.name) -} - -// repeated .caffe2.ExecutionStep substep = 2; -inline int ExecutionStep::substep_size() const { - return substep_.size(); -} -inline void ExecutionStep::clear_substep() { - substep_.Clear(); -} -inline const ::caffe2::ExecutionStep& ExecutionStep::substep(int index) const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.substep) - return substep_.Get(index); -} -inline ::caffe2::ExecutionStep* ExecutionStep::mutable_substep(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.substep) - return substep_.Mutable(index); -} -inline ::caffe2::ExecutionStep* ExecutionStep::add_substep() { - // @@protoc_insertion_point(field_add:caffe2.ExecutionStep.substep) - return substep_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >* -ExecutionStep::mutable_substep() { - // @@protoc_insertion_point(field_mutable_list:caffe2.ExecutionStep.substep) - return &substep_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >& -ExecutionStep::substep() const { - // @@protoc_insertion_point(field_list:caffe2.ExecutionStep.substep) - return substep_; -} - -// repeated string network = 3; -inline int ExecutionStep::network_size() const { - return network_.size(); -} -inline void ExecutionStep::clear_network() { - network_.Clear(); -} -inline const ::std::string& ExecutionStep::network(int index) const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.network) - return network_.Get(index); -} -inline ::std::string* ExecutionStep::mutable_network(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.network) - return network_.Mutable(index); -} -inline void ExecutionStep::set_network(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.network) - network_.Mutable(index)->assign(value); -} -inline void ExecutionStep::set_network(int index, const char* value) { - network_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.ExecutionStep.network) -} -inline void ExecutionStep::set_network(int index, const char* value, size_t size) { - network_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.ExecutionStep.network) -} -inline ::std::string* ExecutionStep::add_network() { - // @@protoc_insertion_point(field_add_mutable:caffe2.ExecutionStep.network) - return network_.Add(); -} -inline void ExecutionStep::add_network(const ::std::string& value) { - network_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.ExecutionStep.network) -} -inline void ExecutionStep::add_network(const char* value) { - network_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.ExecutionStep.network) -} -inline void ExecutionStep::add_network(const char* value, size_t size) { - network_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.ExecutionStep.network) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -ExecutionStep::network() const { - // @@protoc_insertion_point(field_list:caffe2.ExecutionStep.network) - return network_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -ExecutionStep::mutable_network() { - // @@protoc_insertion_point(field_mutable_list:caffe2.ExecutionStep.network) - return &network_; -} - -// optional int64 num_iter = 4; -inline bool ExecutionStep::has_num_iter() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void ExecutionStep::set_has_num_iter() { - _has_bits_[0] |= 0x00000008u; -} -inline void ExecutionStep::clear_has_num_iter() { - _has_bits_[0] &= ~0x00000008u; -} -inline void ExecutionStep::clear_num_iter() { - num_iter_ = GOOGLE_LONGLONG(0); - clear_has_num_iter(); -} -inline ::google::protobuf::int64 ExecutionStep::num_iter() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.num_iter) - return num_iter_; -} -inline void ExecutionStep::set_num_iter(::google::protobuf::int64 value) { - set_has_num_iter(); - num_iter_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.num_iter) -} - -// optional string criteria_network = 5 [deprecated = true]; -inline bool ExecutionStep::has_criteria_network() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void ExecutionStep::set_has_criteria_network() { - _has_bits_[0] |= 0x00000010u; -} -inline void ExecutionStep::clear_has_criteria_network() { - _has_bits_[0] &= ~0x00000010u; -} -inline void ExecutionStep::clear_criteria_network() { - criteria_network_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_criteria_network(); -} -inline const ::std::string& ExecutionStep::criteria_network() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.criteria_network) - return criteria_network_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_criteria_network(const ::std::string& value) { - set_has_criteria_network(); - criteria_network_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.criteria_network) -} -inline void ExecutionStep::set_criteria_network(const char* value) { - set_has_criteria_network(); - criteria_network_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ExecutionStep.criteria_network) -} -inline void ExecutionStep::set_criteria_network(const char* value, size_t size) { - set_has_criteria_network(); - criteria_network_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ExecutionStep.criteria_network) -} -inline ::std::string* ExecutionStep::mutable_criteria_network() { - set_has_criteria_network(); - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.criteria_network) - return criteria_network_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ExecutionStep::release_criteria_network() { - // @@protoc_insertion_point(field_release:caffe2.ExecutionStep.criteria_network) - clear_has_criteria_network(); - return criteria_network_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_allocated_criteria_network(::std::string* criteria_network) { - if (criteria_network != NULL) { - set_has_criteria_network(); - } else { - clear_has_criteria_network(); - } - criteria_network_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), criteria_network); - // @@protoc_insertion_point(field_set_allocated:caffe2.ExecutionStep.criteria_network) -} - -// optional string report_net = 7; -inline bool ExecutionStep::has_report_net() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void ExecutionStep::set_has_report_net() { - _has_bits_[0] |= 0x00000020u; -} -inline void ExecutionStep::clear_has_report_net() { - _has_bits_[0] &= ~0x00000020u; -} -inline void ExecutionStep::clear_report_net() { - report_net_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_report_net(); -} -inline const ::std::string& ExecutionStep::report_net() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.report_net) - return report_net_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_report_net(const ::std::string& value) { - set_has_report_net(); - report_net_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.report_net) -} -inline void ExecutionStep::set_report_net(const char* value) { - set_has_report_net(); - report_net_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ExecutionStep.report_net) -} -inline void ExecutionStep::set_report_net(const char* value, size_t size) { - set_has_report_net(); - report_net_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ExecutionStep.report_net) -} -inline ::std::string* ExecutionStep::mutable_report_net() { - set_has_report_net(); - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.report_net) - return report_net_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ExecutionStep::release_report_net() { - // @@protoc_insertion_point(field_release:caffe2.ExecutionStep.report_net) - clear_has_report_net(); - return report_net_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_allocated_report_net(::std::string* report_net) { - if (report_net != NULL) { - set_has_report_net(); - } else { - clear_has_report_net(); - } - report_net_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), report_net); - // @@protoc_insertion_point(field_set_allocated:caffe2.ExecutionStep.report_net) -} - -// optional int32 report_interval = 8; -inline bool ExecutionStep::has_report_interval() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void ExecutionStep::set_has_report_interval() { - _has_bits_[0] |= 0x00000040u; -} -inline void ExecutionStep::clear_has_report_interval() { - _has_bits_[0] &= ~0x00000040u; -} -inline void ExecutionStep::clear_report_interval() { - report_interval_ = 0; - clear_has_report_interval(); -} -inline ::google::protobuf::int32 ExecutionStep::report_interval() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.report_interval) - return report_interval_; -} -inline void ExecutionStep::set_report_interval(::google::protobuf::int32 value) { - set_has_report_interval(); - report_interval_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.report_interval) -} - -// optional int64 run_every_ms = 11; -inline bool ExecutionStep::has_run_every_ms() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void ExecutionStep::set_has_run_every_ms() { - _has_bits_[0] |= 0x00000080u; -} -inline void ExecutionStep::clear_has_run_every_ms() { - _has_bits_[0] &= ~0x00000080u; -} -inline void ExecutionStep::clear_run_every_ms() { - run_every_ms_ = GOOGLE_LONGLONG(0); - clear_has_run_every_ms(); -} -inline ::google::protobuf::int64 ExecutionStep::run_every_ms() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.run_every_ms) - return run_every_ms_; -} -inline void ExecutionStep::set_run_every_ms(::google::protobuf::int64 value) { - set_has_run_every_ms(); - run_every_ms_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.run_every_ms) -} - -// optional bool concurrent_substeps = 6; -inline bool ExecutionStep::has_concurrent_substeps() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void ExecutionStep::set_has_concurrent_substeps() { - _has_bits_[0] |= 0x00000100u; -} -inline void ExecutionStep::clear_has_concurrent_substeps() { - _has_bits_[0] &= ~0x00000100u; -} -inline void ExecutionStep::clear_concurrent_substeps() { - concurrent_substeps_ = false; - clear_has_concurrent_substeps(); -} -inline bool ExecutionStep::concurrent_substeps() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.concurrent_substeps) - return concurrent_substeps_; -} -inline void ExecutionStep::set_concurrent_substeps(bool value) { - set_has_concurrent_substeps(); - concurrent_substeps_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.concurrent_substeps) -} - -// optional string should_stop_blob = 9; -inline bool ExecutionStep::has_should_stop_blob() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void ExecutionStep::set_has_should_stop_blob() { - _has_bits_[0] |= 0x00000200u; -} -inline void ExecutionStep::clear_has_should_stop_blob() { - _has_bits_[0] &= ~0x00000200u; -} -inline void ExecutionStep::clear_should_stop_blob() { - should_stop_blob_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_should_stop_blob(); -} -inline const ::std::string& ExecutionStep::should_stop_blob() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.should_stop_blob) - return should_stop_blob_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_should_stop_blob(const ::std::string& value) { - set_has_should_stop_blob(); - should_stop_blob_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.should_stop_blob) -} -inline void ExecutionStep::set_should_stop_blob(const char* value) { - set_has_should_stop_blob(); - should_stop_blob_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ExecutionStep.should_stop_blob) -} -inline void ExecutionStep::set_should_stop_blob(const char* value, size_t size) { - set_has_should_stop_blob(); - should_stop_blob_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ExecutionStep.should_stop_blob) -} -inline ::std::string* ExecutionStep::mutable_should_stop_blob() { - set_has_should_stop_blob(); - // @@protoc_insertion_point(field_mutable:caffe2.ExecutionStep.should_stop_blob) - return should_stop_blob_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ExecutionStep::release_should_stop_blob() { - // @@protoc_insertion_point(field_release:caffe2.ExecutionStep.should_stop_blob) - clear_has_should_stop_blob(); - return should_stop_blob_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ExecutionStep::set_allocated_should_stop_blob(::std::string* should_stop_blob) { - if (should_stop_blob != NULL) { - set_has_should_stop_blob(); - } else { - clear_has_should_stop_blob(); - } - should_stop_blob_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), should_stop_blob); - // @@protoc_insertion_point(field_set_allocated:caffe2.ExecutionStep.should_stop_blob) -} - -// optional bool only_once = 10; -inline bool ExecutionStep::has_only_once() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void ExecutionStep::set_has_only_once() { - _has_bits_[0] |= 0x00000400u; -} -inline void ExecutionStep::clear_has_only_once() { - _has_bits_[0] &= ~0x00000400u; -} -inline void ExecutionStep::clear_only_once() { - only_once_ = false; - clear_has_only_once(); -} -inline bool ExecutionStep::only_once() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.only_once) - return only_once_; -} -inline void ExecutionStep::set_only_once(bool value) { - set_has_only_once(); - only_once_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.only_once) -} - -// optional bool create_workspace = 12; -inline bool ExecutionStep::has_create_workspace() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void ExecutionStep::set_has_create_workspace() { - _has_bits_[0] |= 0x00000800u; -} -inline void ExecutionStep::clear_has_create_workspace() { - _has_bits_[0] &= ~0x00000800u; -} -inline void ExecutionStep::clear_create_workspace() { - create_workspace_ = false; - clear_has_create_workspace(); -} -inline bool ExecutionStep::create_workspace() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.create_workspace) - return create_workspace_; -} -inline void ExecutionStep::set_create_workspace(bool value) { - set_has_create_workspace(); - create_workspace_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.create_workspace) -} - -// optional int32 num_concurrent_instances = 13; -inline bool ExecutionStep::has_num_concurrent_instances() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void ExecutionStep::set_has_num_concurrent_instances() { - _has_bits_[0] |= 0x00001000u; -} -inline void ExecutionStep::clear_has_num_concurrent_instances() { - _has_bits_[0] &= ~0x00001000u; -} -inline void ExecutionStep::clear_num_concurrent_instances() { - num_concurrent_instances_ = 0; - clear_has_num_concurrent_instances(); -} -inline ::google::protobuf::int32 ExecutionStep::num_concurrent_instances() const { - // @@protoc_insertion_point(field_get:caffe2.ExecutionStep.num_concurrent_instances) - return num_concurrent_instances_; -} -inline void ExecutionStep::set_num_concurrent_instances(::google::protobuf::int32 value) { - set_has_num_concurrent_instances(); - num_concurrent_instances_ = value; - // @@protoc_insertion_point(field_set:caffe2.ExecutionStep.num_concurrent_instances) -} - -inline const ExecutionStep* ExecutionStep::internal_default_instance() { - return &ExecutionStep_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// PlanDef - -// optional string name = 1; -inline bool PlanDef::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PlanDef::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void PlanDef::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void PlanDef::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& PlanDef::name() const { - // @@protoc_insertion_point(field_get:caffe2.PlanDef.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void PlanDef::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.PlanDef.name) -} -inline void PlanDef::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PlanDef.name) -} -inline void PlanDef::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PlanDef.name) -} -inline ::std::string* PlanDef::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.PlanDef.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* PlanDef::release_name() { - // @@protoc_insertion_point(field_release:caffe2.PlanDef.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void PlanDef::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.PlanDef.name) -} - -// repeated .caffe2.NetDef network = 2; -inline int PlanDef::network_size() const { - return network_.size(); -} -inline void PlanDef::clear_network() { - network_.Clear(); -} -inline const ::caffe2::NetDef& PlanDef::network(int index) const { - // @@protoc_insertion_point(field_get:caffe2.PlanDef.network) - return network_.Get(index); -} -inline ::caffe2::NetDef* PlanDef::mutable_network(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.PlanDef.network) - return network_.Mutable(index); -} -inline ::caffe2::NetDef* PlanDef::add_network() { - // @@protoc_insertion_point(field_add:caffe2.PlanDef.network) - return network_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >* -PlanDef::mutable_network() { - // @@protoc_insertion_point(field_mutable_list:caffe2.PlanDef.network) - return &network_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::NetDef >& -PlanDef::network() const { - // @@protoc_insertion_point(field_list:caffe2.PlanDef.network) - return network_; -} - -// repeated .caffe2.ExecutionStep execution_step = 3; -inline int PlanDef::execution_step_size() const { - return execution_step_.size(); -} -inline void PlanDef::clear_execution_step() { - execution_step_.Clear(); -} -inline const ::caffe2::ExecutionStep& PlanDef::execution_step(int index) const { - // @@protoc_insertion_point(field_get:caffe2.PlanDef.execution_step) - return execution_step_.Get(index); -} -inline ::caffe2::ExecutionStep* PlanDef::mutable_execution_step(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.PlanDef.execution_step) - return execution_step_.Mutable(index); -} -inline ::caffe2::ExecutionStep* PlanDef::add_execution_step() { - // @@protoc_insertion_point(field_add:caffe2.PlanDef.execution_step) - return execution_step_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >* -PlanDef::mutable_execution_step() { - // @@protoc_insertion_point(field_mutable_list:caffe2.PlanDef.execution_step) - return &execution_step_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::ExecutionStep >& -PlanDef::execution_step() const { - // @@protoc_insertion_point(field_list:caffe2.PlanDef.execution_step) - return execution_step_; -} - -inline const PlanDef* PlanDef::internal_default_instance() { - return &PlanDef_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// BlobProto - -// optional string name = 1; -inline bool BlobProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void BlobProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void BlobProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void BlobProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& BlobProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.BlobProto.name) -} -inline void BlobProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.BlobProto.name) -} -inline void BlobProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.BlobProto.name) -} -inline ::std::string* BlobProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.BlobProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* BlobProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.BlobProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobProto.name) -} - -// optional string type = 2; -inline bool BlobProto::has_type() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void BlobProto::set_has_type() { - _has_bits_[0] |= 0x00000002u; -} -inline void BlobProto::clear_has_type() { - _has_bits_[0] &= ~0x00000002u; -} -inline void BlobProto::clear_type() { - type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_type(); -} -inline const ::std::string& BlobProto::type() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.type) - return type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_type(const ::std::string& value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.BlobProto.type) -} -inline void BlobProto::set_type(const char* value) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.BlobProto.type) -} -inline void BlobProto::set_type(const char* value, size_t size) { - set_has_type(); - type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.BlobProto.type) -} -inline ::std::string* BlobProto::mutable_type() { - set_has_type(); - // @@protoc_insertion_point(field_mutable:caffe2.BlobProto.type) - return type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* BlobProto::release_type() { - // @@protoc_insertion_point(field_release:caffe2.BlobProto.type) - clear_has_type(); - return type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_allocated_type(::std::string* type) { - if (type != NULL) { - set_has_type(); - } else { - clear_has_type(); - } - type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type); - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobProto.type) -} - -// optional .caffe2.TensorProto tensor = 3; -inline bool BlobProto::has_tensor() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void BlobProto::set_has_tensor() { - _has_bits_[0] |= 0x00000004u; -} -inline void BlobProto::clear_has_tensor() { - _has_bits_[0] &= ~0x00000004u; -} -inline void BlobProto::clear_tensor() { - if (tensor_ != NULL) tensor_->::caffe2::TensorProto::Clear(); - clear_has_tensor(); -} -inline const ::caffe2::TensorProto& BlobProto::tensor() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.tensor) - return tensor_ != NULL ? *tensor_ - : *::caffe2::TensorProto::internal_default_instance(); -} -inline ::caffe2::TensorProto* BlobProto::mutable_tensor() { - set_has_tensor(); - if (tensor_ == NULL) { - tensor_ = new ::caffe2::TensorProto; - } - // @@protoc_insertion_point(field_mutable:caffe2.BlobProto.tensor) - return tensor_; -} -inline ::caffe2::TensorProto* BlobProto::release_tensor() { - // @@protoc_insertion_point(field_release:caffe2.BlobProto.tensor) - clear_has_tensor(); - ::caffe2::TensorProto* temp = tensor_; - tensor_ = NULL; - return temp; -} -inline void BlobProto::set_allocated_tensor(::caffe2::TensorProto* tensor) { - delete tensor_; - tensor_ = tensor; - if (tensor) { - set_has_tensor(); - } else { - clear_has_tensor(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobProto.tensor) -} - -// optional bytes content = 4; -inline bool BlobProto::has_content() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void BlobProto::set_has_content() { - _has_bits_[0] |= 0x00000008u; -} -inline void BlobProto::clear_has_content() { - _has_bits_[0] &= ~0x00000008u; -} -inline void BlobProto::clear_content() { - content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_content(); -} -inline const ::std::string& BlobProto::content() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.content) - return content_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_content(const ::std::string& value) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.BlobProto.content) -} -inline void BlobProto::set_content(const char* value) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.BlobProto.content) -} -inline void BlobProto::set_content(const void* value, size_t size) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.BlobProto.content) -} -inline ::std::string* BlobProto::mutable_content() { - set_has_content(); - // @@protoc_insertion_point(field_mutable:caffe2.BlobProto.content) - return content_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* BlobProto::release_content() { - // @@protoc_insertion_point(field_release:caffe2.BlobProto.content) - clear_has_content(); - return content_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobProto::set_allocated_content(::std::string* content) { - if (content != NULL) { - set_has_content(); - } else { - clear_has_content(); - } - content_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), content); - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobProto.content) -} - -// optional .caffe2.QTensorProto qtensor = 5; -inline bool BlobProto::has_qtensor() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void BlobProto::set_has_qtensor() { - _has_bits_[0] |= 0x00000010u; -} -inline void BlobProto::clear_has_qtensor() { - _has_bits_[0] &= ~0x00000010u; -} -inline void BlobProto::clear_qtensor() { - if (qtensor_ != NULL) qtensor_->::caffe2::QTensorProto::Clear(); - clear_has_qtensor(); -} -inline const ::caffe2::QTensorProto& BlobProto::qtensor() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.qtensor) - return qtensor_ != NULL ? *qtensor_ - : *::caffe2::QTensorProto::internal_default_instance(); -} -inline ::caffe2::QTensorProto* BlobProto::mutable_qtensor() { - set_has_qtensor(); - if (qtensor_ == NULL) { - qtensor_ = new ::caffe2::QTensorProto; - } - // @@protoc_insertion_point(field_mutable:caffe2.BlobProto.qtensor) - return qtensor_; -} -inline ::caffe2::QTensorProto* BlobProto::release_qtensor() { - // @@protoc_insertion_point(field_release:caffe2.BlobProto.qtensor) - clear_has_qtensor(); - ::caffe2::QTensorProto* temp = qtensor_; - qtensor_ = NULL; - return temp; -} -inline void BlobProto::set_allocated_qtensor(::caffe2::QTensorProto* qtensor) { - delete qtensor_; - qtensor_ = qtensor; - if (qtensor) { - set_has_qtensor(); - } else { - clear_has_qtensor(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobProto.qtensor) -} - -// optional int32 content_num_chunks = 6; -inline bool BlobProto::has_content_num_chunks() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void BlobProto::set_has_content_num_chunks() { - _has_bits_[0] |= 0x00000020u; -} -inline void BlobProto::clear_has_content_num_chunks() { - _has_bits_[0] &= ~0x00000020u; -} -inline void BlobProto::clear_content_num_chunks() { - content_num_chunks_ = 0; - clear_has_content_num_chunks(); -} -inline ::google::protobuf::int32 BlobProto::content_num_chunks() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.content_num_chunks) - return content_num_chunks_; -} -inline void BlobProto::set_content_num_chunks(::google::protobuf::int32 value) { - set_has_content_num_chunks(); - content_num_chunks_ = value; - // @@protoc_insertion_point(field_set:caffe2.BlobProto.content_num_chunks) -} - -// optional int32 content_chunk_id = 7; -inline bool BlobProto::has_content_chunk_id() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void BlobProto::set_has_content_chunk_id() { - _has_bits_[0] |= 0x00000040u; -} -inline void BlobProto::clear_has_content_chunk_id() { - _has_bits_[0] &= ~0x00000040u; -} -inline void BlobProto::clear_content_chunk_id() { - content_chunk_id_ = 0; - clear_has_content_chunk_id(); -} -inline ::google::protobuf::int32 BlobProto::content_chunk_id() const { - // @@protoc_insertion_point(field_get:caffe2.BlobProto.content_chunk_id) - return content_chunk_id_; -} -inline void BlobProto::set_content_chunk_id(::google::protobuf::int32 value) { - set_has_content_chunk_id(); - content_chunk_id_ = value; - // @@protoc_insertion_point(field_set:caffe2.BlobProto.content_chunk_id) -} - -inline const BlobProto* BlobProto::internal_default_instance() { - return &BlobProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// DBReaderProto - -// optional string name = 1; -inline bool DBReaderProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DBReaderProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void DBReaderProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DBReaderProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& DBReaderProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.DBReaderProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.DBReaderProto.name) -} -inline void DBReaderProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.DBReaderProto.name) -} -inline void DBReaderProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.DBReaderProto.name) -} -inline ::std::string* DBReaderProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.DBReaderProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DBReaderProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.DBReaderProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.DBReaderProto.name) -} - -// optional string source = 2; -inline bool DBReaderProto::has_source() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void DBReaderProto::set_has_source() { - _has_bits_[0] |= 0x00000002u; -} -inline void DBReaderProto::clear_has_source() { - _has_bits_[0] &= ~0x00000002u; -} -inline void DBReaderProto::clear_source() { - source_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_source(); -} -inline const ::std::string& DBReaderProto::source() const { - // @@protoc_insertion_point(field_get:caffe2.DBReaderProto.source) - return source_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_source(const ::std::string& value) { - set_has_source(); - source_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.DBReaderProto.source) -} -inline void DBReaderProto::set_source(const char* value) { - set_has_source(); - source_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.DBReaderProto.source) -} -inline void DBReaderProto::set_source(const char* value, size_t size) { - set_has_source(); - source_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.DBReaderProto.source) -} -inline ::std::string* DBReaderProto::mutable_source() { - set_has_source(); - // @@protoc_insertion_point(field_mutable:caffe2.DBReaderProto.source) - return source_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DBReaderProto::release_source() { - // @@protoc_insertion_point(field_release:caffe2.DBReaderProto.source) - clear_has_source(); - return source_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_allocated_source(::std::string* source) { - if (source != NULL) { - set_has_source(); - } else { - clear_has_source(); - } - source_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), source); - // @@protoc_insertion_point(field_set_allocated:caffe2.DBReaderProto.source) -} - -// optional string db_type = 3; -inline bool DBReaderProto::has_db_type() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void DBReaderProto::set_has_db_type() { - _has_bits_[0] |= 0x00000004u; -} -inline void DBReaderProto::clear_has_db_type() { - _has_bits_[0] &= ~0x00000004u; -} -inline void DBReaderProto::clear_db_type() { - db_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_db_type(); -} -inline const ::std::string& DBReaderProto::db_type() const { - // @@protoc_insertion_point(field_get:caffe2.DBReaderProto.db_type) - return db_type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_db_type(const ::std::string& value) { - set_has_db_type(); - db_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.DBReaderProto.db_type) -} -inline void DBReaderProto::set_db_type(const char* value) { - set_has_db_type(); - db_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.DBReaderProto.db_type) -} -inline void DBReaderProto::set_db_type(const char* value, size_t size) { - set_has_db_type(); - db_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.DBReaderProto.db_type) -} -inline ::std::string* DBReaderProto::mutable_db_type() { - set_has_db_type(); - // @@protoc_insertion_point(field_mutable:caffe2.DBReaderProto.db_type) - return db_type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DBReaderProto::release_db_type() { - // @@protoc_insertion_point(field_release:caffe2.DBReaderProto.db_type) - clear_has_db_type(); - return db_type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_allocated_db_type(::std::string* db_type) { - if (db_type != NULL) { - set_has_db_type(); - } else { - clear_has_db_type(); - } - db_type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), db_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.DBReaderProto.db_type) -} - -// optional string key = 4; -inline bool DBReaderProto::has_key() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void DBReaderProto::set_has_key() { - _has_bits_[0] |= 0x00000008u; -} -inline void DBReaderProto::clear_has_key() { - _has_bits_[0] &= ~0x00000008u; -} -inline void DBReaderProto::clear_key() { - key_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_key(); -} -inline const ::std::string& DBReaderProto::key() const { - // @@protoc_insertion_point(field_get:caffe2.DBReaderProto.key) - return key_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_key(const ::std::string& value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.DBReaderProto.key) -} -inline void DBReaderProto::set_key(const char* value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.DBReaderProto.key) -} -inline void DBReaderProto::set_key(const char* value, size_t size) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.DBReaderProto.key) -} -inline ::std::string* DBReaderProto::mutable_key() { - set_has_key(); - // @@protoc_insertion_point(field_mutable:caffe2.DBReaderProto.key) - return key_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DBReaderProto::release_key() { - // @@protoc_insertion_point(field_release:caffe2.DBReaderProto.key) - clear_has_key(); - return key_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DBReaderProto::set_allocated_key(::std::string* key) { - if (key != NULL) { - set_has_key(); - } else { - clear_has_key(); - } - key_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), key); - // @@protoc_insertion_point(field_set_allocated:caffe2.DBReaderProto.key) -} - -inline const DBReaderProto* DBReaderProto::internal_default_instance() { - return &DBReaderProto_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> struct is_proto_enum< ::caffe2::TensorProto_DataType> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::caffe2::TensorProto_DataType>() { - return ::caffe2::TensorProto_DataType_descriptor(); -} -template <> struct is_proto_enum< ::caffe2::DeviceType> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::caffe2::DeviceType>() { - return ::caffe2::DeviceType_descriptor(); -} - -} // namespace protobuf -} // namespace google -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fcaffe2_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/proto/caffe2_legacy.pb.h b/app/src/main/cpp/caffe2/proto/caffe2_legacy.pb.h deleted file mode 100644 index 587b438..0000000 --- a/app/src/main/cpp/caffe2/proto/caffe2_legacy.pb.h +++ /dev/null @@ -1,92 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/caffe2_legacy.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fcaffe2_5flegacy_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fcaffe2_5flegacy_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fcaffe2_5flegacy_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fcaffe2_5flegacy_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fcaffe2_5flegacy_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fcaffe2_5flegacy_2eproto(); - - -enum LegacyPadding { - NOTSET = 0, - VALID = 1, - SAME = 2, - CAFFE_LEGACY_POOLING = 3 -}; -bool LegacyPadding_IsValid(int value); -const LegacyPadding LegacyPadding_MIN = NOTSET; -const LegacyPadding LegacyPadding_MAX = CAFFE_LEGACY_POOLING; -const int LegacyPadding_ARRAYSIZE = LegacyPadding_MAX + 1; - -const ::google::protobuf::EnumDescriptor* LegacyPadding_descriptor(); -inline const ::std::string& LegacyPadding_Name(LegacyPadding value) { - return ::google::protobuf::internal::NameOfEnum( - LegacyPadding_descriptor(), value); -} -inline bool LegacyPadding_Parse( - const ::std::string& name, LegacyPadding* value) { - return ::google::protobuf::internal::ParseNamedEnum( - LegacyPadding_descriptor(), name, value); -} -// =================================================================== - - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> struct is_proto_enum< ::caffe2::LegacyPadding> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::caffe2::LegacyPadding>() { - return ::caffe2::LegacyPadding_descriptor(); -} - -} // namespace protobuf -} // namespace google -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fcaffe2_5flegacy_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/proto/hsm.pb.h b/app/src/main/cpp/caffe2/proto/hsm.pb.h deleted file mode 100644 index 76d55b3..0000000 --- a/app/src/main/cpp/caffe2/proto/hsm.pb.h +++ /dev/null @@ -1,1086 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/hsm.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fhsm_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fhsm_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - -class HierarchyProto; -class NodeProto; -class PathNodeProto; -class PathProto; -class TreeProto; - -// =================================================================== - -class NodeProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.NodeProto) */ { - public: - NodeProto(); - virtual ~NodeProto(); - - NodeProto(const NodeProto& from); - - inline NodeProto& operator=(const NodeProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const NodeProto& default_instance(); - - static const NodeProto* internal_default_instance(); - - void Swap(NodeProto* other); - - // implements Message ---------------------------------------------- - - inline NodeProto* New() const { return New(NULL); } - - NodeProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const NodeProto& from); - void MergeFrom(const NodeProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(NodeProto* other); - void UnsafeMergeFrom(const NodeProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .caffe2.NodeProto children = 1; - int children_size() const; - void clear_children(); - static const int kChildrenFieldNumber = 1; - const ::caffe2::NodeProto& children(int index) const; - ::caffe2::NodeProto* mutable_children(int index); - ::caffe2::NodeProto* add_children(); - ::google::protobuf::RepeatedPtrField< ::caffe2::NodeProto >* - mutable_children(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::NodeProto >& - children() const; - - // repeated int32 word_ids = 2; - int word_ids_size() const; - void clear_word_ids(); - static const int kWordIdsFieldNumber = 2; - ::google::protobuf::int32 word_ids(int index) const; - void set_word_ids(int index, ::google::protobuf::int32 value); - void add_word_ids(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - word_ids() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_word_ids(); - - // optional int32 offset = 3; - bool has_offset() const; - void clear_offset(); - static const int kOffsetFieldNumber = 3; - ::google::protobuf::int32 offset() const; - void set_offset(::google::protobuf::int32 value); - - // optional string name = 4; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 4; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated float scores = 5; - int scores_size() const; - void clear_scores(); - static const int kScoresFieldNumber = 5; - float scores(int index) const; - void set_scores(int index, float value); - void add_scores(float value); - const ::google::protobuf::RepeatedField< float >& - scores() const; - ::google::protobuf::RepeatedField< float >* - mutable_scores(); - - // @@protoc_insertion_point(class_scope:caffe2.NodeProto) - private: - inline void set_has_offset(); - inline void clear_has_offset(); - inline void set_has_name(); - inline void clear_has_name(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::NodeProto > children_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > word_ids_; - ::google::protobuf::RepeatedField< float > scores_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::int32 offset_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed NodeProto_default_instance_; - -// ------------------------------------------------------------------- - -class TreeProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.TreeProto) */ { - public: - TreeProto(); - virtual ~TreeProto(); - - TreeProto(const TreeProto& from); - - inline TreeProto& operator=(const TreeProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const TreeProto& default_instance(); - - static const TreeProto* internal_default_instance(); - - void Swap(TreeProto* other); - - // implements Message ---------------------------------------------- - - inline TreeProto* New() const { return New(NULL); } - - TreeProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const TreeProto& from); - void MergeFrom(const TreeProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(TreeProto* other); - void UnsafeMergeFrom(const TreeProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .caffe2.NodeProto root_node = 1; - bool has_root_node() const; - void clear_root_node(); - static const int kRootNodeFieldNumber = 1; - const ::caffe2::NodeProto& root_node() const; - ::caffe2::NodeProto* mutable_root_node(); - ::caffe2::NodeProto* release_root_node(); - void set_allocated_root_node(::caffe2::NodeProto* root_node); - - // @@protoc_insertion_point(class_scope:caffe2.TreeProto) - private: - inline void set_has_root_node(); - inline void clear_has_root_node(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::caffe2::NodeProto* root_node_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed TreeProto_default_instance_; - -// ------------------------------------------------------------------- - -class HierarchyProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.HierarchyProto) */ { - public: - HierarchyProto(); - virtual ~HierarchyProto(); - - HierarchyProto(const HierarchyProto& from); - - inline HierarchyProto& operator=(const HierarchyProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const HierarchyProto& default_instance(); - - static const HierarchyProto* internal_default_instance(); - - void Swap(HierarchyProto* other); - - // implements Message ---------------------------------------------- - - inline HierarchyProto* New() const { return New(NULL); } - - HierarchyProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const HierarchyProto& from); - void MergeFrom(const HierarchyProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(HierarchyProto* other); - void UnsafeMergeFrom(const HierarchyProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 size = 1; - bool has_size() const; - void clear_size(); - static const int kSizeFieldNumber = 1; - ::google::protobuf::int32 size() const; - void set_size(::google::protobuf::int32 value); - - // repeated .caffe2.PathProto paths = 2; - int paths_size() const; - void clear_paths(); - static const int kPathsFieldNumber = 2; - const ::caffe2::PathProto& paths(int index) const; - ::caffe2::PathProto* mutable_paths(int index); - ::caffe2::PathProto* add_paths(); - ::google::protobuf::RepeatedPtrField< ::caffe2::PathProto >* - mutable_paths(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::PathProto >& - paths() const; - - // @@protoc_insertion_point(class_scope:caffe2.HierarchyProto) - private: - inline void set_has_size(); - inline void clear_has_size(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::PathProto > paths_; - ::google::protobuf::int32 size_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed HierarchyProto_default_instance_; - -// ------------------------------------------------------------------- - -class PathProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.PathProto) */ { - public: - PathProto(); - virtual ~PathProto(); - - PathProto(const PathProto& from); - - inline PathProto& operator=(const PathProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const PathProto& default_instance(); - - static const PathProto* internal_default_instance(); - - void Swap(PathProto* other); - - // implements Message ---------------------------------------------- - - inline PathProto* New() const { return New(NULL); } - - PathProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const PathProto& from); - void MergeFrom(const PathProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(PathProto* other); - void UnsafeMergeFrom(const PathProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 word_id = 1; - bool has_word_id() const; - void clear_word_id(); - static const int kWordIdFieldNumber = 1; - ::google::protobuf::int32 word_id() const; - void set_word_id(::google::protobuf::int32 value); - - // repeated .caffe2.PathNodeProto path_nodes = 2; - int path_nodes_size() const; - void clear_path_nodes(); - static const int kPathNodesFieldNumber = 2; - const ::caffe2::PathNodeProto& path_nodes(int index) const; - ::caffe2::PathNodeProto* mutable_path_nodes(int index); - ::caffe2::PathNodeProto* add_path_nodes(); - ::google::protobuf::RepeatedPtrField< ::caffe2::PathNodeProto >* - mutable_path_nodes(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::PathNodeProto >& - path_nodes() const; - - // @@protoc_insertion_point(class_scope:caffe2.PathProto) - private: - inline void set_has_word_id(); - inline void clear_has_word_id(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::PathNodeProto > path_nodes_; - ::google::protobuf::int32 word_id_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed PathProto_default_instance_; - -// ------------------------------------------------------------------- - -class PathNodeProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.PathNodeProto) */ { - public: - PathNodeProto(); - virtual ~PathNodeProto(); - - PathNodeProto(const PathNodeProto& from); - - inline PathNodeProto& operator=(const PathNodeProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const PathNodeProto& default_instance(); - - static const PathNodeProto* internal_default_instance(); - - void Swap(PathNodeProto* other); - - // implements Message ---------------------------------------------- - - inline PathNodeProto* New() const { return New(NULL); } - - PathNodeProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const PathNodeProto& from); - void MergeFrom(const PathNodeProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(PathNodeProto* other); - void UnsafeMergeFrom(const PathNodeProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 index = 1; - bool has_index() const; - void clear_index(); - static const int kIndexFieldNumber = 1; - ::google::protobuf::int32 index() const; - void set_index(::google::protobuf::int32 value); - - // optional int32 length = 2; - bool has_length() const; - void clear_length(); - static const int kLengthFieldNumber = 2; - ::google::protobuf::int32 length() const; - void set_length(::google::protobuf::int32 value); - - // optional int32 target = 3; - bool has_target() const; - void clear_target(); - static const int kTargetFieldNumber = 3; - ::google::protobuf::int32 target() const; - void set_target(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:caffe2.PathNodeProto) - private: - inline void set_has_index(); - inline void clear_has_index(); - inline void set_has_length(); - inline void clear_has_length(); - inline void set_has_target(); - inline void clear_has_target(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::int32 index_; - ::google::protobuf::int32 length_; - ::google::protobuf::int32 target_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fhsm_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fhsm_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fhsm_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed PathNodeProto_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// NodeProto - -// repeated .caffe2.NodeProto children = 1; -inline int NodeProto::children_size() const { - return children_.size(); -} -inline void NodeProto::clear_children() { - children_.Clear(); -} -inline const ::caffe2::NodeProto& NodeProto::children(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NodeProto.children) - return children_.Get(index); -} -inline ::caffe2::NodeProto* NodeProto::mutable_children(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.NodeProto.children) - return children_.Mutable(index); -} -inline ::caffe2::NodeProto* NodeProto::add_children() { - // @@protoc_insertion_point(field_add:caffe2.NodeProto.children) - return children_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::NodeProto >* -NodeProto::mutable_children() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NodeProto.children) - return &children_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::NodeProto >& -NodeProto::children() const { - // @@protoc_insertion_point(field_list:caffe2.NodeProto.children) - return children_; -} - -// repeated int32 word_ids = 2; -inline int NodeProto::word_ids_size() const { - return word_ids_.size(); -} -inline void NodeProto::clear_word_ids() { - word_ids_.Clear(); -} -inline ::google::protobuf::int32 NodeProto::word_ids(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NodeProto.word_ids) - return word_ids_.Get(index); -} -inline void NodeProto::set_word_ids(int index, ::google::protobuf::int32 value) { - word_ids_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.NodeProto.word_ids) -} -inline void NodeProto::add_word_ids(::google::protobuf::int32 value) { - word_ids_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.NodeProto.word_ids) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -NodeProto::word_ids() const { - // @@protoc_insertion_point(field_list:caffe2.NodeProto.word_ids) - return word_ids_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -NodeProto::mutable_word_ids() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NodeProto.word_ids) - return &word_ids_; -} - -// optional int32 offset = 3; -inline bool NodeProto::has_offset() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void NodeProto::set_has_offset() { - _has_bits_[0] |= 0x00000004u; -} -inline void NodeProto::clear_has_offset() { - _has_bits_[0] &= ~0x00000004u; -} -inline void NodeProto::clear_offset() { - offset_ = 0; - clear_has_offset(); -} -inline ::google::protobuf::int32 NodeProto::offset() const { - // @@protoc_insertion_point(field_get:caffe2.NodeProto.offset) - return offset_; -} -inline void NodeProto::set_offset(::google::protobuf::int32 value) { - set_has_offset(); - offset_ = value; - // @@protoc_insertion_point(field_set:caffe2.NodeProto.offset) -} - -// optional string name = 4; -inline bool NodeProto::has_name() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void NodeProto::set_has_name() { - _has_bits_[0] |= 0x00000008u; -} -inline void NodeProto::clear_has_name() { - _has_bits_[0] &= ~0x00000008u; -} -inline void NodeProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& NodeProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.NodeProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NodeProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.NodeProto.name) -} -inline void NodeProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.NodeProto.name) -} -inline void NodeProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.NodeProto.name) -} -inline ::std::string* NodeProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.NodeProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* NodeProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.NodeProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NodeProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.NodeProto.name) -} - -// repeated float scores = 5; -inline int NodeProto::scores_size() const { - return scores_.size(); -} -inline void NodeProto::clear_scores() { - scores_.Clear(); -} -inline float NodeProto::scores(int index) const { - // @@protoc_insertion_point(field_get:caffe2.NodeProto.scores) - return scores_.Get(index); -} -inline void NodeProto::set_scores(int index, float value) { - scores_.Set(index, value); - // @@protoc_insertion_point(field_set:caffe2.NodeProto.scores) -} -inline void NodeProto::add_scores(float value) { - scores_.Add(value); - // @@protoc_insertion_point(field_add:caffe2.NodeProto.scores) -} -inline const ::google::protobuf::RepeatedField< float >& -NodeProto::scores() const { - // @@protoc_insertion_point(field_list:caffe2.NodeProto.scores) - return scores_; -} -inline ::google::protobuf::RepeatedField< float >* -NodeProto::mutable_scores() { - // @@protoc_insertion_point(field_mutable_list:caffe2.NodeProto.scores) - return &scores_; -} - -inline const NodeProto* NodeProto::internal_default_instance() { - return &NodeProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// TreeProto - -// optional .caffe2.NodeProto root_node = 1; -inline bool TreeProto::has_root_node() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void TreeProto::set_has_root_node() { - _has_bits_[0] |= 0x00000001u; -} -inline void TreeProto::clear_has_root_node() { - _has_bits_[0] &= ~0x00000001u; -} -inline void TreeProto::clear_root_node() { - if (root_node_ != NULL) root_node_->::caffe2::NodeProto::Clear(); - clear_has_root_node(); -} -inline const ::caffe2::NodeProto& TreeProto::root_node() const { - // @@protoc_insertion_point(field_get:caffe2.TreeProto.root_node) - return root_node_ != NULL ? *root_node_ - : *::caffe2::NodeProto::internal_default_instance(); -} -inline ::caffe2::NodeProto* TreeProto::mutable_root_node() { - set_has_root_node(); - if (root_node_ == NULL) { - root_node_ = new ::caffe2::NodeProto; - } - // @@protoc_insertion_point(field_mutable:caffe2.TreeProto.root_node) - return root_node_; -} -inline ::caffe2::NodeProto* TreeProto::release_root_node() { - // @@protoc_insertion_point(field_release:caffe2.TreeProto.root_node) - clear_has_root_node(); - ::caffe2::NodeProto* temp = root_node_; - root_node_ = NULL; - return temp; -} -inline void TreeProto::set_allocated_root_node(::caffe2::NodeProto* root_node) { - delete root_node_; - root_node_ = root_node; - if (root_node) { - set_has_root_node(); - } else { - clear_has_root_node(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.TreeProto.root_node) -} - -inline const TreeProto* TreeProto::internal_default_instance() { - return &TreeProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// HierarchyProto - -// optional int32 size = 1; -inline bool HierarchyProto::has_size() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void HierarchyProto::set_has_size() { - _has_bits_[0] |= 0x00000001u; -} -inline void HierarchyProto::clear_has_size() { - _has_bits_[0] &= ~0x00000001u; -} -inline void HierarchyProto::clear_size() { - size_ = 0; - clear_has_size(); -} -inline ::google::protobuf::int32 HierarchyProto::size() const { - // @@protoc_insertion_point(field_get:caffe2.HierarchyProto.size) - return size_; -} -inline void HierarchyProto::set_size(::google::protobuf::int32 value) { - set_has_size(); - size_ = value; - // @@protoc_insertion_point(field_set:caffe2.HierarchyProto.size) -} - -// repeated .caffe2.PathProto paths = 2; -inline int HierarchyProto::paths_size() const { - return paths_.size(); -} -inline void HierarchyProto::clear_paths() { - paths_.Clear(); -} -inline const ::caffe2::PathProto& HierarchyProto::paths(int index) const { - // @@protoc_insertion_point(field_get:caffe2.HierarchyProto.paths) - return paths_.Get(index); -} -inline ::caffe2::PathProto* HierarchyProto::mutable_paths(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.HierarchyProto.paths) - return paths_.Mutable(index); -} -inline ::caffe2::PathProto* HierarchyProto::add_paths() { - // @@protoc_insertion_point(field_add:caffe2.HierarchyProto.paths) - return paths_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::PathProto >* -HierarchyProto::mutable_paths() { - // @@protoc_insertion_point(field_mutable_list:caffe2.HierarchyProto.paths) - return &paths_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::PathProto >& -HierarchyProto::paths() const { - // @@protoc_insertion_point(field_list:caffe2.HierarchyProto.paths) - return paths_; -} - -inline const HierarchyProto* HierarchyProto::internal_default_instance() { - return &HierarchyProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// PathProto - -// optional int32 word_id = 1; -inline bool PathProto::has_word_id() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PathProto::set_has_word_id() { - _has_bits_[0] |= 0x00000001u; -} -inline void PathProto::clear_has_word_id() { - _has_bits_[0] &= ~0x00000001u; -} -inline void PathProto::clear_word_id() { - word_id_ = 0; - clear_has_word_id(); -} -inline ::google::protobuf::int32 PathProto::word_id() const { - // @@protoc_insertion_point(field_get:caffe2.PathProto.word_id) - return word_id_; -} -inline void PathProto::set_word_id(::google::protobuf::int32 value) { - set_has_word_id(); - word_id_ = value; - // @@protoc_insertion_point(field_set:caffe2.PathProto.word_id) -} - -// repeated .caffe2.PathNodeProto path_nodes = 2; -inline int PathProto::path_nodes_size() const { - return path_nodes_.size(); -} -inline void PathProto::clear_path_nodes() { - path_nodes_.Clear(); -} -inline const ::caffe2::PathNodeProto& PathProto::path_nodes(int index) const { - // @@protoc_insertion_point(field_get:caffe2.PathProto.path_nodes) - return path_nodes_.Get(index); -} -inline ::caffe2::PathNodeProto* PathProto::mutable_path_nodes(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.PathProto.path_nodes) - return path_nodes_.Mutable(index); -} -inline ::caffe2::PathNodeProto* PathProto::add_path_nodes() { - // @@protoc_insertion_point(field_add:caffe2.PathProto.path_nodes) - return path_nodes_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::PathNodeProto >* -PathProto::mutable_path_nodes() { - // @@protoc_insertion_point(field_mutable_list:caffe2.PathProto.path_nodes) - return &path_nodes_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::PathNodeProto >& -PathProto::path_nodes() const { - // @@protoc_insertion_point(field_list:caffe2.PathProto.path_nodes) - return path_nodes_; -} - -inline const PathProto* PathProto::internal_default_instance() { - return &PathProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// PathNodeProto - -// optional int32 index = 1; -inline bool PathNodeProto::has_index() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PathNodeProto::set_has_index() { - _has_bits_[0] |= 0x00000001u; -} -inline void PathNodeProto::clear_has_index() { - _has_bits_[0] &= ~0x00000001u; -} -inline void PathNodeProto::clear_index() { - index_ = 0; - clear_has_index(); -} -inline ::google::protobuf::int32 PathNodeProto::index() const { - // @@protoc_insertion_point(field_get:caffe2.PathNodeProto.index) - return index_; -} -inline void PathNodeProto::set_index(::google::protobuf::int32 value) { - set_has_index(); - index_ = value; - // @@protoc_insertion_point(field_set:caffe2.PathNodeProto.index) -} - -// optional int32 length = 2; -inline bool PathNodeProto::has_length() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void PathNodeProto::set_has_length() { - _has_bits_[0] |= 0x00000002u; -} -inline void PathNodeProto::clear_has_length() { - _has_bits_[0] &= ~0x00000002u; -} -inline void PathNodeProto::clear_length() { - length_ = 0; - clear_has_length(); -} -inline ::google::protobuf::int32 PathNodeProto::length() const { - // @@protoc_insertion_point(field_get:caffe2.PathNodeProto.length) - return length_; -} -inline void PathNodeProto::set_length(::google::protobuf::int32 value) { - set_has_length(); - length_ = value; - // @@protoc_insertion_point(field_set:caffe2.PathNodeProto.length) -} - -// optional int32 target = 3; -inline bool PathNodeProto::has_target() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void PathNodeProto::set_has_target() { - _has_bits_[0] |= 0x00000004u; -} -inline void PathNodeProto::clear_has_target() { - _has_bits_[0] &= ~0x00000004u; -} -inline void PathNodeProto::clear_target() { - target_ = 0; - clear_has_target(); -} -inline ::google::protobuf::int32 PathNodeProto::target() const { - // @@protoc_insertion_point(field_get:caffe2.PathNodeProto.target) - return target_; -} -inline void PathNodeProto::set_target(::google::protobuf::int32 value) { - set_has_target(); - target_ = value; - // @@protoc_insertion_point(field_set:caffe2.PathNodeProto.target) -} - -inline const PathNodeProto* PathNodeProto::internal_default_instance() { - return &PathNodeProto_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fhsm_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/proto/metanet.pb.h b/app/src/main/cpp/caffe2/proto/metanet.pb.h deleted file mode 100644 index e66fc63..0000000 --- a/app/src/main/cpp/caffe2/proto/metanet.pb.h +++ /dev/null @@ -1,1755 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/metanet.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fmetanet_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fmetanet_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include "caffe2/proto/caffe2.pb.h" -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - -class BlobsMap; -class MetaNetDef; -class ModelInfo; -class NetsMap; -class PlansMap; -class StringMap; - -// =================================================================== - -class ModelInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.ModelInfo) */ { - public: - ModelInfo(); - virtual ~ModelInfo(); - - ModelInfo(const ModelInfo& from); - - inline ModelInfo& operator=(const ModelInfo& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ModelInfo& default_instance(); - - static const ModelInfo* internal_default_instance(); - - void Swap(ModelInfo* other); - - // implements Message ---------------------------------------------- - - inline ModelInfo* New() const { return New(NULL); } - - ModelInfo* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ModelInfo& from); - void MergeFrom(const ModelInfo& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ModelInfo* other); - void UnsafeMergeFrom(const ModelInfo& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string project = 1; - bool has_project() const; - void clear_project(); - static const int kProjectFieldNumber = 1; - const ::std::string& project() const; - void set_project(const ::std::string& value); - void set_project(const char* value); - void set_project(const char* value, size_t size); - ::std::string* mutable_project(); - ::std::string* release_project(); - void set_allocated_project(::std::string* project); - - // optional string modelClass = 2; - bool has_modelclass() const; - void clear_modelclass(); - static const int kModelClassFieldNumber = 2; - const ::std::string& modelclass() const; - void set_modelclass(const ::std::string& value); - void set_modelclass(const char* value); - void set_modelclass(const char* value, size_t size); - ::std::string* mutable_modelclass(); - ::std::string* release_modelclass(); - void set_allocated_modelclass(::std::string* modelclass); - - // optional string version = 3; - bool has_version() const; - void clear_version(); - static const int kVersionFieldNumber = 3; - const ::std::string& version() const; - void set_version(const ::std::string& value); - void set_version(const char* value); - void set_version(const char* value, size_t size); - ::std::string* mutable_version(); - ::std::string* release_version(); - void set_allocated_version(::std::string* version); - - // optional string predictorType = 4 [default = "SINGLE_PREDICTOR"]; - bool has_predictortype() const; - void clear_predictortype(); - static const int kPredictorTypeFieldNumber = 4; - const ::std::string& predictortype() const; - void set_predictortype(const ::std::string& value); - void set_predictortype(const char* value); - void set_predictortype(const char* value, size_t size); - ::std::string* mutable_predictortype(); - ::std::string* release_predictortype(); - void set_allocated_predictortype(::std::string* predictortype); - - // optional string modelId = 5; - bool has_modelid() const; - void clear_modelid(); - static const int kModelIdFieldNumber = 5; - const ::std::string& modelid() const; - void set_modelid(const ::std::string& value); - void set_modelid(const char* value); - void set_modelid(const char* value, size_t size); - ::std::string* mutable_modelid(); - ::std::string* release_modelid(); - void set_allocated_modelid(::std::string* modelid); - - // @@protoc_insertion_point(class_scope:caffe2.ModelInfo) - private: - inline void set_has_project(); - inline void clear_has_project(); - inline void set_has_modelclass(); - inline void clear_has_modelclass(); - inline void set_has_version(); - inline void clear_has_version(); - inline void set_has_predictortype(); - inline void clear_has_predictortype(); - inline void set_has_modelid(); - inline void clear_has_modelid(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr project_; - ::google::protobuf::internal::ArenaStringPtr modelclass_; - ::google::protobuf::internal::ArenaStringPtr version_; - static ::std::string* _default_predictortype_; - ::google::protobuf::internal::ArenaStringPtr predictortype_; - ::google::protobuf::internal::ArenaStringPtr modelid_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ModelInfo_default_instance_; - -// ------------------------------------------------------------------- - -class BlobsMap : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.BlobsMap) */ { - public: - BlobsMap(); - virtual ~BlobsMap(); - - BlobsMap(const BlobsMap& from); - - inline BlobsMap& operator=(const BlobsMap& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const BlobsMap& default_instance(); - - static const BlobsMap* internal_default_instance(); - - void Swap(BlobsMap* other); - - // implements Message ---------------------------------------------- - - inline BlobsMap* New() const { return New(NULL); } - - BlobsMap* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const BlobsMap& from); - void MergeFrom(const BlobsMap& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(BlobsMap* other); - void UnsafeMergeFrom(const BlobsMap& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string key = 1; - bool has_key() const; - void clear_key(); - static const int kKeyFieldNumber = 1; - const ::std::string& key() const; - void set_key(const ::std::string& value); - void set_key(const char* value); - void set_key(const char* value, size_t size); - ::std::string* mutable_key(); - ::std::string* release_key(); - void set_allocated_key(::std::string* key); - - // repeated string value = 2; - int value_size() const; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::std::string& value(int index) const; - ::std::string* mutable_value(int index); - void set_value(int index, const ::std::string& value); - void set_value(int index, const char* value); - void set_value(int index, const char* value, size_t size); - ::std::string* add_value(); - void add_value(const ::std::string& value); - void add_value(const char* value); - void add_value(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& value() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_value(); - - // @@protoc_insertion_point(class_scope:caffe2.BlobsMap) - private: - inline void set_has_key(); - inline void clear_has_key(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> value_; - ::google::protobuf::internal::ArenaStringPtr key_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed BlobsMap_default_instance_; - -// ------------------------------------------------------------------- - -class NetsMap : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.NetsMap) */ { - public: - NetsMap(); - virtual ~NetsMap(); - - NetsMap(const NetsMap& from); - - inline NetsMap& operator=(const NetsMap& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const NetsMap& default_instance(); - - static const NetsMap* internal_default_instance(); - - void Swap(NetsMap* other); - - // implements Message ---------------------------------------------- - - inline NetsMap* New() const { return New(NULL); } - - NetsMap* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const NetsMap& from); - void MergeFrom(const NetsMap& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(NetsMap* other); - void UnsafeMergeFrom(const NetsMap& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string key = 1; - bool has_key() const; - void clear_key(); - static const int kKeyFieldNumber = 1; - const ::std::string& key() const; - void set_key(const ::std::string& value); - void set_key(const char* value); - void set_key(const char* value, size_t size); - ::std::string* mutable_key(); - ::std::string* release_key(); - void set_allocated_key(::std::string* key); - - // required .caffe2.NetDef value = 2; - bool has_value() const; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::caffe2::NetDef& value() const; - ::caffe2::NetDef* mutable_value(); - ::caffe2::NetDef* release_value(); - void set_allocated_value(::caffe2::NetDef* value); - - // @@protoc_insertion_point(class_scope:caffe2.NetsMap) - private: - inline void set_has_key(); - inline void clear_has_key(); - inline void set_has_value(); - inline void clear_has_value(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr key_; - ::caffe2::NetDef* value_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed NetsMap_default_instance_; - -// ------------------------------------------------------------------- - -class PlansMap : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.PlansMap) */ { - public: - PlansMap(); - virtual ~PlansMap(); - - PlansMap(const PlansMap& from); - - inline PlansMap& operator=(const PlansMap& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const PlansMap& default_instance(); - - static const PlansMap* internal_default_instance(); - - void Swap(PlansMap* other); - - // implements Message ---------------------------------------------- - - inline PlansMap* New() const { return New(NULL); } - - PlansMap* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const PlansMap& from); - void MergeFrom(const PlansMap& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(PlansMap* other); - void UnsafeMergeFrom(const PlansMap& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string key = 1; - bool has_key() const; - void clear_key(); - static const int kKeyFieldNumber = 1; - const ::std::string& key() const; - void set_key(const ::std::string& value); - void set_key(const char* value); - void set_key(const char* value, size_t size); - ::std::string* mutable_key(); - ::std::string* release_key(); - void set_allocated_key(::std::string* key); - - // required .caffe2.PlanDef value = 2; - bool has_value() const; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::caffe2::PlanDef& value() const; - ::caffe2::PlanDef* mutable_value(); - ::caffe2::PlanDef* release_value(); - void set_allocated_value(::caffe2::PlanDef* value); - - // @@protoc_insertion_point(class_scope:caffe2.PlansMap) - private: - inline void set_has_key(); - inline void clear_has_key(); - inline void set_has_value(); - inline void clear_has_value(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr key_; - ::caffe2::PlanDef* value_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed PlansMap_default_instance_; - -// ------------------------------------------------------------------- - -class StringMap : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.StringMap) */ { - public: - StringMap(); - virtual ~StringMap(); - - StringMap(const StringMap& from); - - inline StringMap& operator=(const StringMap& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const StringMap& default_instance(); - - static const StringMap* internal_default_instance(); - - void Swap(StringMap* other); - - // implements Message ---------------------------------------------- - - inline StringMap* New() const { return New(NULL); } - - StringMap* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const StringMap& from); - void MergeFrom(const StringMap& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(StringMap* other); - void UnsafeMergeFrom(const StringMap& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string key = 1; - bool has_key() const; - void clear_key(); - static const int kKeyFieldNumber = 1; - const ::std::string& key() const; - void set_key(const ::std::string& value); - void set_key(const char* value); - void set_key(const char* value, size_t size); - ::std::string* mutable_key(); - ::std::string* release_key(); - void set_allocated_key(::std::string* key); - - // required string value = 2; - bool has_value() const; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::std::string& value() const; - void set_value(const ::std::string& value); - void set_value(const char* value); - void set_value(const char* value, size_t size); - ::std::string* mutable_value(); - ::std::string* release_value(); - void set_allocated_value(::std::string* value); - - // @@protoc_insertion_point(class_scope:caffe2.StringMap) - private: - inline void set_has_key(); - inline void clear_has_key(); - inline void set_has_value(); - inline void clear_has_value(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr key_; - ::google::protobuf::internal::ArenaStringPtr value_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed StringMap_default_instance_; - -// ------------------------------------------------------------------- - -class MetaNetDef : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.MetaNetDef) */ { - public: - MetaNetDef(); - virtual ~MetaNetDef(); - - MetaNetDef(const MetaNetDef& from); - - inline MetaNetDef& operator=(const MetaNetDef& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MetaNetDef& default_instance(); - - static const MetaNetDef* internal_default_instance(); - - void Swap(MetaNetDef* other); - - // implements Message ---------------------------------------------- - - inline MetaNetDef* New() const { return New(NULL); } - - MetaNetDef* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MetaNetDef& from); - void MergeFrom(const MetaNetDef& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(MetaNetDef* other); - void UnsafeMergeFrom(const MetaNetDef& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .caffe2.BlobsMap blobs = 1; - int blobs_size() const; - void clear_blobs(); - static const int kBlobsFieldNumber = 1; - const ::caffe2::BlobsMap& blobs(int index) const; - ::caffe2::BlobsMap* mutable_blobs(int index); - ::caffe2::BlobsMap* add_blobs(); - ::google::protobuf::RepeatedPtrField< ::caffe2::BlobsMap >* - mutable_blobs(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::BlobsMap >& - blobs() const; - - // repeated .caffe2.NetsMap nets = 2; - int nets_size() const; - void clear_nets(); - static const int kNetsFieldNumber = 2; - const ::caffe2::NetsMap& nets(int index) const; - ::caffe2::NetsMap* mutable_nets(int index); - ::caffe2::NetsMap* add_nets(); - ::google::protobuf::RepeatedPtrField< ::caffe2::NetsMap >* - mutable_nets(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::NetsMap >& - nets() const; - - // optional .caffe2.ModelInfo modelInfo = 3; - bool has_modelinfo() const; - void clear_modelinfo(); - static const int kModelInfoFieldNumber = 3; - const ::caffe2::ModelInfo& modelinfo() const; - ::caffe2::ModelInfo* mutable_modelinfo(); - ::caffe2::ModelInfo* release_modelinfo(); - void set_allocated_modelinfo(::caffe2::ModelInfo* modelinfo); - - // repeated .caffe2.PlansMap plans = 4; - int plans_size() const; - void clear_plans(); - static const int kPlansFieldNumber = 4; - const ::caffe2::PlansMap& plans(int index) const; - ::caffe2::PlansMap* mutable_plans(int index); - ::caffe2::PlansMap* add_plans(); - ::google::protobuf::RepeatedPtrField< ::caffe2::PlansMap >* - mutable_plans(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::PlansMap >& - plans() const; - - // repeated .caffe2.StringMap applicationSpecificInfo = 5; - int applicationspecificinfo_size() const; - void clear_applicationspecificinfo(); - static const int kApplicationSpecificInfoFieldNumber = 5; - const ::caffe2::StringMap& applicationspecificinfo(int index) const; - ::caffe2::StringMap* mutable_applicationspecificinfo(int index); - ::caffe2::StringMap* add_applicationspecificinfo(); - ::google::protobuf::RepeatedPtrField< ::caffe2::StringMap >* - mutable_applicationspecificinfo(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::StringMap >& - applicationspecificinfo() const; - - // @@protoc_insertion_point(class_scope:caffe2.MetaNetDef) - private: - inline void set_has_modelinfo(); - inline void clear_has_modelinfo(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::BlobsMap > blobs_; - ::google::protobuf::RepeatedPtrField< ::caffe2::NetsMap > nets_; - ::google::protobuf::RepeatedPtrField< ::caffe2::PlansMap > plans_; - ::google::protobuf::RepeatedPtrField< ::caffe2::StringMap > applicationspecificinfo_; - ::caffe2::ModelInfo* modelinfo_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fmetanet_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fmetanet_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fmetanet_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed MetaNetDef_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// ModelInfo - -// optional string project = 1; -inline bool ModelInfo::has_project() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ModelInfo::set_has_project() { - _has_bits_[0] |= 0x00000001u; -} -inline void ModelInfo::clear_has_project() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ModelInfo::clear_project() { - project_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_project(); -} -inline const ::std::string& ModelInfo::project() const { - // @@protoc_insertion_point(field_get:caffe2.ModelInfo.project) - return project_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_project(const ::std::string& value) { - set_has_project(); - project_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ModelInfo.project) -} -inline void ModelInfo::set_project(const char* value) { - set_has_project(); - project_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ModelInfo.project) -} -inline void ModelInfo::set_project(const char* value, size_t size) { - set_has_project(); - project_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ModelInfo.project) -} -inline ::std::string* ModelInfo::mutable_project() { - set_has_project(); - // @@protoc_insertion_point(field_mutable:caffe2.ModelInfo.project) - return project_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ModelInfo::release_project() { - // @@protoc_insertion_point(field_release:caffe2.ModelInfo.project) - clear_has_project(); - return project_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_allocated_project(::std::string* project) { - if (project != NULL) { - set_has_project(); - } else { - clear_has_project(); - } - project_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), project); - // @@protoc_insertion_point(field_set_allocated:caffe2.ModelInfo.project) -} - -// optional string modelClass = 2; -inline bool ModelInfo::has_modelclass() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void ModelInfo::set_has_modelclass() { - _has_bits_[0] |= 0x00000002u; -} -inline void ModelInfo::clear_has_modelclass() { - _has_bits_[0] &= ~0x00000002u; -} -inline void ModelInfo::clear_modelclass() { - modelclass_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_modelclass(); -} -inline const ::std::string& ModelInfo::modelclass() const { - // @@protoc_insertion_point(field_get:caffe2.ModelInfo.modelClass) - return modelclass_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_modelclass(const ::std::string& value) { - set_has_modelclass(); - modelclass_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ModelInfo.modelClass) -} -inline void ModelInfo::set_modelclass(const char* value) { - set_has_modelclass(); - modelclass_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ModelInfo.modelClass) -} -inline void ModelInfo::set_modelclass(const char* value, size_t size) { - set_has_modelclass(); - modelclass_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ModelInfo.modelClass) -} -inline ::std::string* ModelInfo::mutable_modelclass() { - set_has_modelclass(); - // @@protoc_insertion_point(field_mutable:caffe2.ModelInfo.modelClass) - return modelclass_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ModelInfo::release_modelclass() { - // @@protoc_insertion_point(field_release:caffe2.ModelInfo.modelClass) - clear_has_modelclass(); - return modelclass_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_allocated_modelclass(::std::string* modelclass) { - if (modelclass != NULL) { - set_has_modelclass(); - } else { - clear_has_modelclass(); - } - modelclass_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), modelclass); - // @@protoc_insertion_point(field_set_allocated:caffe2.ModelInfo.modelClass) -} - -// optional string version = 3; -inline bool ModelInfo::has_version() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ModelInfo::set_has_version() { - _has_bits_[0] |= 0x00000004u; -} -inline void ModelInfo::clear_has_version() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ModelInfo::clear_version() { - version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_version(); -} -inline const ::std::string& ModelInfo::version() const { - // @@protoc_insertion_point(field_get:caffe2.ModelInfo.version) - return version_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_version(const ::std::string& value) { - set_has_version(); - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ModelInfo.version) -} -inline void ModelInfo::set_version(const char* value) { - set_has_version(); - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ModelInfo.version) -} -inline void ModelInfo::set_version(const char* value, size_t size) { - set_has_version(); - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ModelInfo.version) -} -inline ::std::string* ModelInfo::mutable_version() { - set_has_version(); - // @@protoc_insertion_point(field_mutable:caffe2.ModelInfo.version) - return version_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ModelInfo::release_version() { - // @@protoc_insertion_point(field_release:caffe2.ModelInfo.version) - clear_has_version(); - return version_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_allocated_version(::std::string* version) { - if (version != NULL) { - set_has_version(); - } else { - clear_has_version(); - } - version_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), version); - // @@protoc_insertion_point(field_set_allocated:caffe2.ModelInfo.version) -} - -// optional string predictorType = 4 [default = "SINGLE_PREDICTOR"]; -inline bool ModelInfo::has_predictortype() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void ModelInfo::set_has_predictortype() { - _has_bits_[0] |= 0x00000008u; -} -inline void ModelInfo::clear_has_predictortype() { - _has_bits_[0] &= ~0x00000008u; -} -inline void ModelInfo::clear_predictortype() { - predictortype_.ClearToDefaultNoArena(_default_predictortype_); - clear_has_predictortype(); -} -inline const ::std::string& ModelInfo::predictortype() const { - // @@protoc_insertion_point(field_get:caffe2.ModelInfo.predictorType) - return predictortype_.GetNoArena(_default_predictortype_); -} -inline void ModelInfo::set_predictortype(const ::std::string& value) { - set_has_predictortype(); - predictortype_.SetNoArena(_default_predictortype_, value); - // @@protoc_insertion_point(field_set:caffe2.ModelInfo.predictorType) -} -inline void ModelInfo::set_predictortype(const char* value) { - set_has_predictortype(); - predictortype_.SetNoArena(_default_predictortype_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ModelInfo.predictorType) -} -inline void ModelInfo::set_predictortype(const char* value, size_t size) { - set_has_predictortype(); - predictortype_.SetNoArena(_default_predictortype_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ModelInfo.predictorType) -} -inline ::std::string* ModelInfo::mutable_predictortype() { - set_has_predictortype(); - // @@protoc_insertion_point(field_mutable:caffe2.ModelInfo.predictorType) - return predictortype_.MutableNoArena(_default_predictortype_); -} -inline ::std::string* ModelInfo::release_predictortype() { - // @@protoc_insertion_point(field_release:caffe2.ModelInfo.predictorType) - clear_has_predictortype(); - return predictortype_.ReleaseNoArena(_default_predictortype_); -} -inline void ModelInfo::set_allocated_predictortype(::std::string* predictortype) { - if (predictortype != NULL) { - set_has_predictortype(); - } else { - clear_has_predictortype(); - } - predictortype_.SetAllocatedNoArena(_default_predictortype_, predictortype); - // @@protoc_insertion_point(field_set_allocated:caffe2.ModelInfo.predictorType) -} - -// optional string modelId = 5; -inline bool ModelInfo::has_modelid() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void ModelInfo::set_has_modelid() { - _has_bits_[0] |= 0x00000010u; -} -inline void ModelInfo::clear_has_modelid() { - _has_bits_[0] &= ~0x00000010u; -} -inline void ModelInfo::clear_modelid() { - modelid_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_modelid(); -} -inline const ::std::string& ModelInfo::modelid() const { - // @@protoc_insertion_point(field_get:caffe2.ModelInfo.modelId) - return modelid_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_modelid(const ::std::string& value) { - set_has_modelid(); - modelid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ModelInfo.modelId) -} -inline void ModelInfo::set_modelid(const char* value) { - set_has_modelid(); - modelid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ModelInfo.modelId) -} -inline void ModelInfo::set_modelid(const char* value, size_t size) { - set_has_modelid(); - modelid_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ModelInfo.modelId) -} -inline ::std::string* ModelInfo::mutable_modelid() { - set_has_modelid(); - // @@protoc_insertion_point(field_mutable:caffe2.ModelInfo.modelId) - return modelid_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ModelInfo::release_modelid() { - // @@protoc_insertion_point(field_release:caffe2.ModelInfo.modelId) - clear_has_modelid(); - return modelid_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ModelInfo::set_allocated_modelid(::std::string* modelid) { - if (modelid != NULL) { - set_has_modelid(); - } else { - clear_has_modelid(); - } - modelid_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), modelid); - // @@protoc_insertion_point(field_set_allocated:caffe2.ModelInfo.modelId) -} - -inline const ModelInfo* ModelInfo::internal_default_instance() { - return &ModelInfo_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// BlobsMap - -// required string key = 1; -inline bool BlobsMap::has_key() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void BlobsMap::set_has_key() { - _has_bits_[0] |= 0x00000001u; -} -inline void BlobsMap::clear_has_key() { - _has_bits_[0] &= ~0x00000001u; -} -inline void BlobsMap::clear_key() { - key_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_key(); -} -inline const ::std::string& BlobsMap::key() const { - // @@protoc_insertion_point(field_get:caffe2.BlobsMap.key) - return key_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobsMap::set_key(const ::std::string& value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.BlobsMap.key) -} -inline void BlobsMap::set_key(const char* value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.BlobsMap.key) -} -inline void BlobsMap::set_key(const char* value, size_t size) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.BlobsMap.key) -} -inline ::std::string* BlobsMap::mutable_key() { - set_has_key(); - // @@protoc_insertion_point(field_mutable:caffe2.BlobsMap.key) - return key_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* BlobsMap::release_key() { - // @@protoc_insertion_point(field_release:caffe2.BlobsMap.key) - clear_has_key(); - return key_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void BlobsMap::set_allocated_key(::std::string* key) { - if (key != NULL) { - set_has_key(); - } else { - clear_has_key(); - } - key_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), key); - // @@protoc_insertion_point(field_set_allocated:caffe2.BlobsMap.key) -} - -// repeated string value = 2; -inline int BlobsMap::value_size() const { - return value_.size(); -} -inline void BlobsMap::clear_value() { - value_.Clear(); -} -inline const ::std::string& BlobsMap::value(int index) const { - // @@protoc_insertion_point(field_get:caffe2.BlobsMap.value) - return value_.Get(index); -} -inline ::std::string* BlobsMap::mutable_value(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.BlobsMap.value) - return value_.Mutable(index); -} -inline void BlobsMap::set_value(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:caffe2.BlobsMap.value) - value_.Mutable(index)->assign(value); -} -inline void BlobsMap::set_value(int index, const char* value) { - value_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:caffe2.BlobsMap.value) -} -inline void BlobsMap::set_value(int index, const char* value, size_t size) { - value_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:caffe2.BlobsMap.value) -} -inline ::std::string* BlobsMap::add_value() { - // @@protoc_insertion_point(field_add_mutable:caffe2.BlobsMap.value) - return value_.Add(); -} -inline void BlobsMap::add_value(const ::std::string& value) { - value_.Add()->assign(value); - // @@protoc_insertion_point(field_add:caffe2.BlobsMap.value) -} -inline void BlobsMap::add_value(const char* value) { - value_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:caffe2.BlobsMap.value) -} -inline void BlobsMap::add_value(const char* value, size_t size) { - value_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:caffe2.BlobsMap.value) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -BlobsMap::value() const { - // @@protoc_insertion_point(field_list:caffe2.BlobsMap.value) - return value_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -BlobsMap::mutable_value() { - // @@protoc_insertion_point(field_mutable_list:caffe2.BlobsMap.value) - return &value_; -} - -inline const BlobsMap* BlobsMap::internal_default_instance() { - return &BlobsMap_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// NetsMap - -// required string key = 1; -inline bool NetsMap::has_key() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void NetsMap::set_has_key() { - _has_bits_[0] |= 0x00000001u; -} -inline void NetsMap::clear_has_key() { - _has_bits_[0] &= ~0x00000001u; -} -inline void NetsMap::clear_key() { - key_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_key(); -} -inline const ::std::string& NetsMap::key() const { - // @@protoc_insertion_point(field_get:caffe2.NetsMap.key) - return key_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetsMap::set_key(const ::std::string& value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.NetsMap.key) -} -inline void NetsMap::set_key(const char* value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.NetsMap.key) -} -inline void NetsMap::set_key(const char* value, size_t size) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.NetsMap.key) -} -inline ::std::string* NetsMap::mutable_key() { - set_has_key(); - // @@protoc_insertion_point(field_mutable:caffe2.NetsMap.key) - return key_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* NetsMap::release_key() { - // @@protoc_insertion_point(field_release:caffe2.NetsMap.key) - clear_has_key(); - return key_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void NetsMap::set_allocated_key(::std::string* key) { - if (key != NULL) { - set_has_key(); - } else { - clear_has_key(); - } - key_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), key); - // @@protoc_insertion_point(field_set_allocated:caffe2.NetsMap.key) -} - -// required .caffe2.NetDef value = 2; -inline bool NetsMap::has_value() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void NetsMap::set_has_value() { - _has_bits_[0] |= 0x00000002u; -} -inline void NetsMap::clear_has_value() { - _has_bits_[0] &= ~0x00000002u; -} -inline void NetsMap::clear_value() { - if (value_ != NULL) value_->::caffe2::NetDef::Clear(); - clear_has_value(); -} -inline const ::caffe2::NetDef& NetsMap::value() const { - // @@protoc_insertion_point(field_get:caffe2.NetsMap.value) - return value_ != NULL ? *value_ - : *::caffe2::NetDef::internal_default_instance(); -} -inline ::caffe2::NetDef* NetsMap::mutable_value() { - set_has_value(); - if (value_ == NULL) { - value_ = new ::caffe2::NetDef; - } - // @@protoc_insertion_point(field_mutable:caffe2.NetsMap.value) - return value_; -} -inline ::caffe2::NetDef* NetsMap::release_value() { - // @@protoc_insertion_point(field_release:caffe2.NetsMap.value) - clear_has_value(); - ::caffe2::NetDef* temp = value_; - value_ = NULL; - return temp; -} -inline void NetsMap::set_allocated_value(::caffe2::NetDef* value) { - delete value_; - value_ = value; - if (value) { - set_has_value(); - } else { - clear_has_value(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.NetsMap.value) -} - -inline const NetsMap* NetsMap::internal_default_instance() { - return &NetsMap_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// PlansMap - -// required string key = 1; -inline bool PlansMap::has_key() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PlansMap::set_has_key() { - _has_bits_[0] |= 0x00000001u; -} -inline void PlansMap::clear_has_key() { - _has_bits_[0] &= ~0x00000001u; -} -inline void PlansMap::clear_key() { - key_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_key(); -} -inline const ::std::string& PlansMap::key() const { - // @@protoc_insertion_point(field_get:caffe2.PlansMap.key) - return key_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void PlansMap::set_key(const ::std::string& value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.PlansMap.key) -} -inline void PlansMap::set_key(const char* value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PlansMap.key) -} -inline void PlansMap::set_key(const char* value, size_t size) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PlansMap.key) -} -inline ::std::string* PlansMap::mutable_key() { - set_has_key(); - // @@protoc_insertion_point(field_mutable:caffe2.PlansMap.key) - return key_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* PlansMap::release_key() { - // @@protoc_insertion_point(field_release:caffe2.PlansMap.key) - clear_has_key(); - return key_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void PlansMap::set_allocated_key(::std::string* key) { - if (key != NULL) { - set_has_key(); - } else { - clear_has_key(); - } - key_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), key); - // @@protoc_insertion_point(field_set_allocated:caffe2.PlansMap.key) -} - -// required .caffe2.PlanDef value = 2; -inline bool PlansMap::has_value() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void PlansMap::set_has_value() { - _has_bits_[0] |= 0x00000002u; -} -inline void PlansMap::clear_has_value() { - _has_bits_[0] &= ~0x00000002u; -} -inline void PlansMap::clear_value() { - if (value_ != NULL) value_->::caffe2::PlanDef::Clear(); - clear_has_value(); -} -inline const ::caffe2::PlanDef& PlansMap::value() const { - // @@protoc_insertion_point(field_get:caffe2.PlansMap.value) - return value_ != NULL ? *value_ - : *::caffe2::PlanDef::internal_default_instance(); -} -inline ::caffe2::PlanDef* PlansMap::mutable_value() { - set_has_value(); - if (value_ == NULL) { - value_ = new ::caffe2::PlanDef; - } - // @@protoc_insertion_point(field_mutable:caffe2.PlansMap.value) - return value_; -} -inline ::caffe2::PlanDef* PlansMap::release_value() { - // @@protoc_insertion_point(field_release:caffe2.PlansMap.value) - clear_has_value(); - ::caffe2::PlanDef* temp = value_; - value_ = NULL; - return temp; -} -inline void PlansMap::set_allocated_value(::caffe2::PlanDef* value) { - delete value_; - value_ = value; - if (value) { - set_has_value(); - } else { - clear_has_value(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.PlansMap.value) -} - -inline const PlansMap* PlansMap::internal_default_instance() { - return &PlansMap_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// StringMap - -// required string key = 1; -inline bool StringMap::has_key() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void StringMap::set_has_key() { - _has_bits_[0] |= 0x00000001u; -} -inline void StringMap::clear_has_key() { - _has_bits_[0] &= ~0x00000001u; -} -inline void StringMap::clear_key() { - key_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_key(); -} -inline const ::std::string& StringMap::key() const { - // @@protoc_insertion_point(field_get:caffe2.StringMap.key) - return key_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void StringMap::set_key(const ::std::string& value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.StringMap.key) -} -inline void StringMap::set_key(const char* value) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.StringMap.key) -} -inline void StringMap::set_key(const char* value, size_t size) { - set_has_key(); - key_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.StringMap.key) -} -inline ::std::string* StringMap::mutable_key() { - set_has_key(); - // @@protoc_insertion_point(field_mutable:caffe2.StringMap.key) - return key_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* StringMap::release_key() { - // @@protoc_insertion_point(field_release:caffe2.StringMap.key) - clear_has_key(); - return key_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void StringMap::set_allocated_key(::std::string* key) { - if (key != NULL) { - set_has_key(); - } else { - clear_has_key(); - } - key_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), key); - // @@protoc_insertion_point(field_set_allocated:caffe2.StringMap.key) -} - -// required string value = 2; -inline bool StringMap::has_value() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void StringMap::set_has_value() { - _has_bits_[0] |= 0x00000002u; -} -inline void StringMap::clear_has_value() { - _has_bits_[0] &= ~0x00000002u; -} -inline void StringMap::clear_value() { - value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_value(); -} -inline const ::std::string& StringMap::value() const { - // @@protoc_insertion_point(field_get:caffe2.StringMap.value) - return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void StringMap::set_value(const ::std::string& value) { - set_has_value(); - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.StringMap.value) -} -inline void StringMap::set_value(const char* value) { - set_has_value(); - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.StringMap.value) -} -inline void StringMap::set_value(const char* value, size_t size) { - set_has_value(); - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.StringMap.value) -} -inline ::std::string* StringMap::mutable_value() { - set_has_value(); - // @@protoc_insertion_point(field_mutable:caffe2.StringMap.value) - return value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* StringMap::release_value() { - // @@protoc_insertion_point(field_release:caffe2.StringMap.value) - clear_has_value(); - return value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void StringMap::set_allocated_value(::std::string* value) { - if (value != NULL) { - set_has_value(); - } else { - clear_has_value(); - } - value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set_allocated:caffe2.StringMap.value) -} - -inline const StringMap* StringMap::internal_default_instance() { - return &StringMap_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// MetaNetDef - -// repeated .caffe2.BlobsMap blobs = 1; -inline int MetaNetDef::blobs_size() const { - return blobs_.size(); -} -inline void MetaNetDef::clear_blobs() { - blobs_.Clear(); -} -inline const ::caffe2::BlobsMap& MetaNetDef::blobs(int index) const { - // @@protoc_insertion_point(field_get:caffe2.MetaNetDef.blobs) - return blobs_.Get(index); -} -inline ::caffe2::BlobsMap* MetaNetDef::mutable_blobs(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.MetaNetDef.blobs) - return blobs_.Mutable(index); -} -inline ::caffe2::BlobsMap* MetaNetDef::add_blobs() { - // @@protoc_insertion_point(field_add:caffe2.MetaNetDef.blobs) - return blobs_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::BlobsMap >* -MetaNetDef::mutable_blobs() { - // @@protoc_insertion_point(field_mutable_list:caffe2.MetaNetDef.blobs) - return &blobs_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::BlobsMap >& -MetaNetDef::blobs() const { - // @@protoc_insertion_point(field_list:caffe2.MetaNetDef.blobs) - return blobs_; -} - -// repeated .caffe2.NetsMap nets = 2; -inline int MetaNetDef::nets_size() const { - return nets_.size(); -} -inline void MetaNetDef::clear_nets() { - nets_.Clear(); -} -inline const ::caffe2::NetsMap& MetaNetDef::nets(int index) const { - // @@protoc_insertion_point(field_get:caffe2.MetaNetDef.nets) - return nets_.Get(index); -} -inline ::caffe2::NetsMap* MetaNetDef::mutable_nets(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.MetaNetDef.nets) - return nets_.Mutable(index); -} -inline ::caffe2::NetsMap* MetaNetDef::add_nets() { - // @@protoc_insertion_point(field_add:caffe2.MetaNetDef.nets) - return nets_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::NetsMap >* -MetaNetDef::mutable_nets() { - // @@protoc_insertion_point(field_mutable_list:caffe2.MetaNetDef.nets) - return &nets_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::NetsMap >& -MetaNetDef::nets() const { - // @@protoc_insertion_point(field_list:caffe2.MetaNetDef.nets) - return nets_; -} - -// optional .caffe2.ModelInfo modelInfo = 3; -inline bool MetaNetDef::has_modelinfo() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void MetaNetDef::set_has_modelinfo() { - _has_bits_[0] |= 0x00000004u; -} -inline void MetaNetDef::clear_has_modelinfo() { - _has_bits_[0] &= ~0x00000004u; -} -inline void MetaNetDef::clear_modelinfo() { - if (modelinfo_ != NULL) modelinfo_->::caffe2::ModelInfo::Clear(); - clear_has_modelinfo(); -} -inline const ::caffe2::ModelInfo& MetaNetDef::modelinfo() const { - // @@protoc_insertion_point(field_get:caffe2.MetaNetDef.modelInfo) - return modelinfo_ != NULL ? *modelinfo_ - : *::caffe2::ModelInfo::internal_default_instance(); -} -inline ::caffe2::ModelInfo* MetaNetDef::mutable_modelinfo() { - set_has_modelinfo(); - if (modelinfo_ == NULL) { - modelinfo_ = new ::caffe2::ModelInfo; - } - // @@protoc_insertion_point(field_mutable:caffe2.MetaNetDef.modelInfo) - return modelinfo_; -} -inline ::caffe2::ModelInfo* MetaNetDef::release_modelinfo() { - // @@protoc_insertion_point(field_release:caffe2.MetaNetDef.modelInfo) - clear_has_modelinfo(); - ::caffe2::ModelInfo* temp = modelinfo_; - modelinfo_ = NULL; - return temp; -} -inline void MetaNetDef::set_allocated_modelinfo(::caffe2::ModelInfo* modelinfo) { - delete modelinfo_; - modelinfo_ = modelinfo; - if (modelinfo) { - set_has_modelinfo(); - } else { - clear_has_modelinfo(); - } - // @@protoc_insertion_point(field_set_allocated:caffe2.MetaNetDef.modelInfo) -} - -// repeated .caffe2.PlansMap plans = 4; -inline int MetaNetDef::plans_size() const { - return plans_.size(); -} -inline void MetaNetDef::clear_plans() { - plans_.Clear(); -} -inline const ::caffe2::PlansMap& MetaNetDef::plans(int index) const { - // @@protoc_insertion_point(field_get:caffe2.MetaNetDef.plans) - return plans_.Get(index); -} -inline ::caffe2::PlansMap* MetaNetDef::mutable_plans(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.MetaNetDef.plans) - return plans_.Mutable(index); -} -inline ::caffe2::PlansMap* MetaNetDef::add_plans() { - // @@protoc_insertion_point(field_add:caffe2.MetaNetDef.plans) - return plans_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::PlansMap >* -MetaNetDef::mutable_plans() { - // @@protoc_insertion_point(field_mutable_list:caffe2.MetaNetDef.plans) - return &plans_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::PlansMap >& -MetaNetDef::plans() const { - // @@protoc_insertion_point(field_list:caffe2.MetaNetDef.plans) - return plans_; -} - -// repeated .caffe2.StringMap applicationSpecificInfo = 5; -inline int MetaNetDef::applicationspecificinfo_size() const { - return applicationspecificinfo_.size(); -} -inline void MetaNetDef::clear_applicationspecificinfo() { - applicationspecificinfo_.Clear(); -} -inline const ::caffe2::StringMap& MetaNetDef::applicationspecificinfo(int index) const { - // @@protoc_insertion_point(field_get:caffe2.MetaNetDef.applicationSpecificInfo) - return applicationspecificinfo_.Get(index); -} -inline ::caffe2::StringMap* MetaNetDef::mutable_applicationspecificinfo(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.MetaNetDef.applicationSpecificInfo) - return applicationspecificinfo_.Mutable(index); -} -inline ::caffe2::StringMap* MetaNetDef::add_applicationspecificinfo() { - // @@protoc_insertion_point(field_add:caffe2.MetaNetDef.applicationSpecificInfo) - return applicationspecificinfo_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::StringMap >* -MetaNetDef::mutable_applicationspecificinfo() { - // @@protoc_insertion_point(field_mutable_list:caffe2.MetaNetDef.applicationSpecificInfo) - return &applicationspecificinfo_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::StringMap >& -MetaNetDef::applicationspecificinfo() const { - // @@protoc_insertion_point(field_list:caffe2.MetaNetDef.applicationSpecificInfo) - return applicationspecificinfo_; -} - -inline const MetaNetDef* MetaNetDef::internal_default_instance() { - return &MetaNetDef_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fmetanet_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/proto/predictor_consts.pb.h b/app/src/main/cpp/caffe2/proto/predictor_consts.pb.h deleted file mode 100644 index 0e2f3df..0000000 --- a/app/src/main/cpp/caffe2/proto/predictor_consts.pb.h +++ /dev/null @@ -1,989 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/predictor_consts.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fpredictor_5fconsts_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fpredictor_5fconsts_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); - -class PredictorConsts; - -// =================================================================== - -class PredictorConsts : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.PredictorConsts) */ { - public: - PredictorConsts(); - virtual ~PredictorConsts(); - - PredictorConsts(const PredictorConsts& from); - - inline PredictorConsts& operator=(const PredictorConsts& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const PredictorConsts& default_instance(); - - static const PredictorConsts* internal_default_instance(); - - void Swap(PredictorConsts* other); - - // implements Message ---------------------------------------------- - - inline PredictorConsts* New() const { return New(NULL); } - - PredictorConsts* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const PredictorConsts& from); - void MergeFrom(const PredictorConsts& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(PredictorConsts* other); - void UnsafeMergeFrom(const PredictorConsts& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string META_NET_DEF = 1 [default = "!!META_NET_DEF"]; - bool has_meta_net_def() const; - void clear_meta_net_def(); - static const int kMETANETDEFFieldNumber = 1; - const ::std::string& meta_net_def() const; - void set_meta_net_def(const ::std::string& value); - void set_meta_net_def(const char* value); - void set_meta_net_def(const char* value, size_t size); - ::std::string* mutable_meta_net_def(); - ::std::string* release_meta_net_def(); - void set_allocated_meta_net_def(::std::string* meta_net_def); - - // optional string PREDICTOR_DBREADER = 2 [default = "!!PREDICTOR_DBREADER"]; - bool has_predictor_dbreader() const; - void clear_predictor_dbreader(); - static const int kPREDICTORDBREADERFieldNumber = 2; - const ::std::string& predictor_dbreader() const; - void set_predictor_dbreader(const ::std::string& value); - void set_predictor_dbreader(const char* value); - void set_predictor_dbreader(const char* value, size_t size); - ::std::string* mutable_predictor_dbreader(); - ::std::string* release_predictor_dbreader(); - void set_allocated_predictor_dbreader(::std::string* predictor_dbreader); - - // optional string PARAMETERS_BLOB_TYPE = 3 [default = "PARAMETERS_BLOB_TYPE"]; - bool has_parameters_blob_type() const; - void clear_parameters_blob_type(); - static const int kPARAMETERSBLOBTYPEFieldNumber = 3; - const ::std::string& parameters_blob_type() const; - void set_parameters_blob_type(const ::std::string& value); - void set_parameters_blob_type(const char* value); - void set_parameters_blob_type(const char* value, size_t size); - ::std::string* mutable_parameters_blob_type(); - ::std::string* release_parameters_blob_type(); - void set_allocated_parameters_blob_type(::std::string* parameters_blob_type); - - // optional string INPUTS_BLOB_TYPE = 4 [default = "INPUTS_BLOB_TYPE"]; - bool has_inputs_blob_type() const; - void clear_inputs_blob_type(); - static const int kINPUTSBLOBTYPEFieldNumber = 4; - const ::std::string& inputs_blob_type() const; - void set_inputs_blob_type(const ::std::string& value); - void set_inputs_blob_type(const char* value); - void set_inputs_blob_type(const char* value, size_t size); - ::std::string* mutable_inputs_blob_type(); - ::std::string* release_inputs_blob_type(); - void set_allocated_inputs_blob_type(::std::string* inputs_blob_type); - - // optional string OUTPUTS_BLOB_TYPE = 5 [default = "OUTPUTS_BLOB_TYPE"]; - bool has_outputs_blob_type() const; - void clear_outputs_blob_type(); - static const int kOUTPUTSBLOBTYPEFieldNumber = 5; - const ::std::string& outputs_blob_type() const; - void set_outputs_blob_type(const ::std::string& value); - void set_outputs_blob_type(const char* value); - void set_outputs_blob_type(const char* value, size_t size); - ::std::string* mutable_outputs_blob_type(); - ::std::string* release_outputs_blob_type(); - void set_allocated_outputs_blob_type(::std::string* outputs_blob_type); - - // optional string GLOBAL_INIT_NET_TYPE = 6 [default = "GLOBAL_INIT_NET_TYPE"]; - bool has_global_init_net_type() const; - void clear_global_init_net_type(); - static const int kGLOBALINITNETTYPEFieldNumber = 6; - const ::std::string& global_init_net_type() const; - void set_global_init_net_type(const ::std::string& value); - void set_global_init_net_type(const char* value); - void set_global_init_net_type(const char* value, size_t size); - ::std::string* mutable_global_init_net_type(); - ::std::string* release_global_init_net_type(); - void set_allocated_global_init_net_type(::std::string* global_init_net_type); - - // optional string PREDICT_INIT_NET_TYPE = 7 [default = "PREDICT_INIT_NET_TYPE"]; - bool has_predict_init_net_type() const; - void clear_predict_init_net_type(); - static const int kPREDICTINITNETTYPEFieldNumber = 7; - const ::std::string& predict_init_net_type() const; - void set_predict_init_net_type(const ::std::string& value); - void set_predict_init_net_type(const char* value); - void set_predict_init_net_type(const char* value, size_t size); - ::std::string* mutable_predict_init_net_type(); - ::std::string* release_predict_init_net_type(); - void set_allocated_predict_init_net_type(::std::string* predict_init_net_type); - - // optional string PREDICT_NET_TYPE = 8 [default = "PREDICT_NET_TYPE"]; - bool has_predict_net_type() const; - void clear_predict_net_type(); - static const int kPREDICTNETTYPEFieldNumber = 8; - const ::std::string& predict_net_type() const; - void set_predict_net_type(const ::std::string& value); - void set_predict_net_type(const char* value); - void set_predict_net_type(const char* value, size_t size); - ::std::string* mutable_predict_net_type(); - ::std::string* release_predict_net_type(); - void set_allocated_predict_net_type(::std::string* predict_net_type); - - // optional string SINGLE_PREDICTOR = 9 [default = "SINGLE_PREDICTOR"]; - bool has_single_predictor() const; - void clear_single_predictor(); - static const int kSINGLEPREDICTORFieldNumber = 9; - const ::std::string& single_predictor() const; - void set_single_predictor(const ::std::string& value); - void set_single_predictor(const char* value); - void set_single_predictor(const char* value, size_t size); - ::std::string* mutable_single_predictor(); - ::std::string* release_single_predictor(); - void set_allocated_single_predictor(::std::string* single_predictor); - - // optional string MULTI_PREDICTOR = 10 [default = "MULTI_PREDICTOR"]; - bool has_multi_predictor() const; - void clear_multi_predictor(); - static const int kMULTIPREDICTORFieldNumber = 10; - const ::std::string& multi_predictor() const; - void set_multi_predictor(const ::std::string& value); - void set_multi_predictor(const char* value); - void set_multi_predictor(const char* value, size_t size); - ::std::string* mutable_multi_predictor(); - ::std::string* release_multi_predictor(); - void set_allocated_multi_predictor(::std::string* multi_predictor); - - // optional string TRAIN_INIT_PLAN_TYPE = 11 [default = "TRAIN_INIT_PLAN_TYPE"]; - bool has_train_init_plan_type() const; - void clear_train_init_plan_type(); - static const int kTRAININITPLANTYPEFieldNumber = 11; - const ::std::string& train_init_plan_type() const; - void set_train_init_plan_type(const ::std::string& value); - void set_train_init_plan_type(const char* value); - void set_train_init_plan_type(const char* value, size_t size); - ::std::string* mutable_train_init_plan_type(); - ::std::string* release_train_init_plan_type(); - void set_allocated_train_init_plan_type(::std::string* train_init_plan_type); - - // optional string TRAIN_PLAN_TYPE = 12 [default = "TRAIN_PLAN_TYPE"]; - bool has_train_plan_type() const; - void clear_train_plan_type(); - static const int kTRAINPLANTYPEFieldNumber = 12; - const ::std::string& train_plan_type() const; - void set_train_plan_type(const ::std::string& value); - void set_train_plan_type(const char* value); - void set_train_plan_type(const char* value, size_t size); - ::std::string* mutable_train_plan_type(); - ::std::string* release_train_plan_type(); - void set_allocated_train_plan_type(::std::string* train_plan_type); - - // @@protoc_insertion_point(class_scope:caffe2.PredictorConsts) - private: - inline void set_has_meta_net_def(); - inline void clear_has_meta_net_def(); - inline void set_has_predictor_dbreader(); - inline void clear_has_predictor_dbreader(); - inline void set_has_parameters_blob_type(); - inline void clear_has_parameters_blob_type(); - inline void set_has_inputs_blob_type(); - inline void clear_has_inputs_blob_type(); - inline void set_has_outputs_blob_type(); - inline void clear_has_outputs_blob_type(); - inline void set_has_global_init_net_type(); - inline void clear_has_global_init_net_type(); - inline void set_has_predict_init_net_type(); - inline void clear_has_predict_init_net_type(); - inline void set_has_predict_net_type(); - inline void clear_has_predict_net_type(); - inline void set_has_single_predictor(); - inline void clear_has_single_predictor(); - inline void set_has_multi_predictor(); - inline void clear_has_multi_predictor(); - inline void set_has_train_init_plan_type(); - inline void clear_has_train_init_plan_type(); - inline void set_has_train_plan_type(); - inline void clear_has_train_plan_type(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - static ::std::string* _default_meta_net_def_; - ::google::protobuf::internal::ArenaStringPtr meta_net_def_; - static ::std::string* _default_predictor_dbreader_; - ::google::protobuf::internal::ArenaStringPtr predictor_dbreader_; - static ::std::string* _default_parameters_blob_type_; - ::google::protobuf::internal::ArenaStringPtr parameters_blob_type_; - static ::std::string* _default_inputs_blob_type_; - ::google::protobuf::internal::ArenaStringPtr inputs_blob_type_; - static ::std::string* _default_outputs_blob_type_; - ::google::protobuf::internal::ArenaStringPtr outputs_blob_type_; - static ::std::string* _default_global_init_net_type_; - ::google::protobuf::internal::ArenaStringPtr global_init_net_type_; - static ::std::string* _default_predict_init_net_type_; - ::google::protobuf::internal::ArenaStringPtr predict_init_net_type_; - static ::std::string* _default_predict_net_type_; - ::google::protobuf::internal::ArenaStringPtr predict_net_type_; - static ::std::string* _default_single_predictor_; - ::google::protobuf::internal::ArenaStringPtr single_predictor_; - static ::std::string* _default_multi_predictor_; - ::google::protobuf::internal::ArenaStringPtr multi_predictor_; - static ::std::string* _default_train_init_plan_type_; - ::google::protobuf::internal::ArenaStringPtr train_init_plan_type_; - static ::std::string* _default_train_plan_type_; - ::google::protobuf::internal::ArenaStringPtr train_plan_type_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fpredictor_5fconsts_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fpredictor_5fconsts_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fpredictor_5fconsts_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed PredictorConsts_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// PredictorConsts - -// optional string META_NET_DEF = 1 [default = "!!META_NET_DEF"]; -inline bool PredictorConsts::has_meta_net_def() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void PredictorConsts::set_has_meta_net_def() { - _has_bits_[0] |= 0x00000001u; -} -inline void PredictorConsts::clear_has_meta_net_def() { - _has_bits_[0] &= ~0x00000001u; -} -inline void PredictorConsts::clear_meta_net_def() { - meta_net_def_.ClearToDefaultNoArena(_default_meta_net_def_); - clear_has_meta_net_def(); -} -inline const ::std::string& PredictorConsts::meta_net_def() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.META_NET_DEF) - return meta_net_def_.GetNoArena(_default_meta_net_def_); -} -inline void PredictorConsts::set_meta_net_def(const ::std::string& value) { - set_has_meta_net_def(); - meta_net_def_.SetNoArena(_default_meta_net_def_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.META_NET_DEF) -} -inline void PredictorConsts::set_meta_net_def(const char* value) { - set_has_meta_net_def(); - meta_net_def_.SetNoArena(_default_meta_net_def_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.META_NET_DEF) -} -inline void PredictorConsts::set_meta_net_def(const char* value, size_t size) { - set_has_meta_net_def(); - meta_net_def_.SetNoArena(_default_meta_net_def_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.META_NET_DEF) -} -inline ::std::string* PredictorConsts::mutable_meta_net_def() { - set_has_meta_net_def(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.META_NET_DEF) - return meta_net_def_.MutableNoArena(_default_meta_net_def_); -} -inline ::std::string* PredictorConsts::release_meta_net_def() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.META_NET_DEF) - clear_has_meta_net_def(); - return meta_net_def_.ReleaseNoArena(_default_meta_net_def_); -} -inline void PredictorConsts::set_allocated_meta_net_def(::std::string* meta_net_def) { - if (meta_net_def != NULL) { - set_has_meta_net_def(); - } else { - clear_has_meta_net_def(); - } - meta_net_def_.SetAllocatedNoArena(_default_meta_net_def_, meta_net_def); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.META_NET_DEF) -} - -// optional string PREDICTOR_DBREADER = 2 [default = "!!PREDICTOR_DBREADER"]; -inline bool PredictorConsts::has_predictor_dbreader() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void PredictorConsts::set_has_predictor_dbreader() { - _has_bits_[0] |= 0x00000002u; -} -inline void PredictorConsts::clear_has_predictor_dbreader() { - _has_bits_[0] &= ~0x00000002u; -} -inline void PredictorConsts::clear_predictor_dbreader() { - predictor_dbreader_.ClearToDefaultNoArena(_default_predictor_dbreader_); - clear_has_predictor_dbreader(); -} -inline const ::std::string& PredictorConsts::predictor_dbreader() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.PREDICTOR_DBREADER) - return predictor_dbreader_.GetNoArena(_default_predictor_dbreader_); -} -inline void PredictorConsts::set_predictor_dbreader(const ::std::string& value) { - set_has_predictor_dbreader(); - predictor_dbreader_.SetNoArena(_default_predictor_dbreader_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.PREDICTOR_DBREADER) -} -inline void PredictorConsts::set_predictor_dbreader(const char* value) { - set_has_predictor_dbreader(); - predictor_dbreader_.SetNoArena(_default_predictor_dbreader_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.PREDICTOR_DBREADER) -} -inline void PredictorConsts::set_predictor_dbreader(const char* value, size_t size) { - set_has_predictor_dbreader(); - predictor_dbreader_.SetNoArena(_default_predictor_dbreader_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.PREDICTOR_DBREADER) -} -inline ::std::string* PredictorConsts::mutable_predictor_dbreader() { - set_has_predictor_dbreader(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.PREDICTOR_DBREADER) - return predictor_dbreader_.MutableNoArena(_default_predictor_dbreader_); -} -inline ::std::string* PredictorConsts::release_predictor_dbreader() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.PREDICTOR_DBREADER) - clear_has_predictor_dbreader(); - return predictor_dbreader_.ReleaseNoArena(_default_predictor_dbreader_); -} -inline void PredictorConsts::set_allocated_predictor_dbreader(::std::string* predictor_dbreader) { - if (predictor_dbreader != NULL) { - set_has_predictor_dbreader(); - } else { - clear_has_predictor_dbreader(); - } - predictor_dbreader_.SetAllocatedNoArena(_default_predictor_dbreader_, predictor_dbreader); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.PREDICTOR_DBREADER) -} - -// optional string PARAMETERS_BLOB_TYPE = 3 [default = "PARAMETERS_BLOB_TYPE"]; -inline bool PredictorConsts::has_parameters_blob_type() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void PredictorConsts::set_has_parameters_blob_type() { - _has_bits_[0] |= 0x00000004u; -} -inline void PredictorConsts::clear_has_parameters_blob_type() { - _has_bits_[0] &= ~0x00000004u; -} -inline void PredictorConsts::clear_parameters_blob_type() { - parameters_blob_type_.ClearToDefaultNoArena(_default_parameters_blob_type_); - clear_has_parameters_blob_type(); -} -inline const ::std::string& PredictorConsts::parameters_blob_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) - return parameters_blob_type_.GetNoArena(_default_parameters_blob_type_); -} -inline void PredictorConsts::set_parameters_blob_type(const ::std::string& value) { - set_has_parameters_blob_type(); - parameters_blob_type_.SetNoArena(_default_parameters_blob_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) -} -inline void PredictorConsts::set_parameters_blob_type(const char* value) { - set_has_parameters_blob_type(); - parameters_blob_type_.SetNoArena(_default_parameters_blob_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) -} -inline void PredictorConsts::set_parameters_blob_type(const char* value, size_t size) { - set_has_parameters_blob_type(); - parameters_blob_type_.SetNoArena(_default_parameters_blob_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) -} -inline ::std::string* PredictorConsts::mutable_parameters_blob_type() { - set_has_parameters_blob_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) - return parameters_blob_type_.MutableNoArena(_default_parameters_blob_type_); -} -inline ::std::string* PredictorConsts::release_parameters_blob_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) - clear_has_parameters_blob_type(); - return parameters_blob_type_.ReleaseNoArena(_default_parameters_blob_type_); -} -inline void PredictorConsts::set_allocated_parameters_blob_type(::std::string* parameters_blob_type) { - if (parameters_blob_type != NULL) { - set_has_parameters_blob_type(); - } else { - clear_has_parameters_blob_type(); - } - parameters_blob_type_.SetAllocatedNoArena(_default_parameters_blob_type_, parameters_blob_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.PARAMETERS_BLOB_TYPE) -} - -// optional string INPUTS_BLOB_TYPE = 4 [default = "INPUTS_BLOB_TYPE"]; -inline bool PredictorConsts::has_inputs_blob_type() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void PredictorConsts::set_has_inputs_blob_type() { - _has_bits_[0] |= 0x00000008u; -} -inline void PredictorConsts::clear_has_inputs_blob_type() { - _has_bits_[0] &= ~0x00000008u; -} -inline void PredictorConsts::clear_inputs_blob_type() { - inputs_blob_type_.ClearToDefaultNoArena(_default_inputs_blob_type_); - clear_has_inputs_blob_type(); -} -inline const ::std::string& PredictorConsts::inputs_blob_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) - return inputs_blob_type_.GetNoArena(_default_inputs_blob_type_); -} -inline void PredictorConsts::set_inputs_blob_type(const ::std::string& value) { - set_has_inputs_blob_type(); - inputs_blob_type_.SetNoArena(_default_inputs_blob_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) -} -inline void PredictorConsts::set_inputs_blob_type(const char* value) { - set_has_inputs_blob_type(); - inputs_blob_type_.SetNoArena(_default_inputs_blob_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) -} -inline void PredictorConsts::set_inputs_blob_type(const char* value, size_t size) { - set_has_inputs_blob_type(); - inputs_blob_type_.SetNoArena(_default_inputs_blob_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) -} -inline ::std::string* PredictorConsts::mutable_inputs_blob_type() { - set_has_inputs_blob_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) - return inputs_blob_type_.MutableNoArena(_default_inputs_blob_type_); -} -inline ::std::string* PredictorConsts::release_inputs_blob_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) - clear_has_inputs_blob_type(); - return inputs_blob_type_.ReleaseNoArena(_default_inputs_blob_type_); -} -inline void PredictorConsts::set_allocated_inputs_blob_type(::std::string* inputs_blob_type) { - if (inputs_blob_type != NULL) { - set_has_inputs_blob_type(); - } else { - clear_has_inputs_blob_type(); - } - inputs_blob_type_.SetAllocatedNoArena(_default_inputs_blob_type_, inputs_blob_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.INPUTS_BLOB_TYPE) -} - -// optional string OUTPUTS_BLOB_TYPE = 5 [default = "OUTPUTS_BLOB_TYPE"]; -inline bool PredictorConsts::has_outputs_blob_type() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void PredictorConsts::set_has_outputs_blob_type() { - _has_bits_[0] |= 0x00000010u; -} -inline void PredictorConsts::clear_has_outputs_blob_type() { - _has_bits_[0] &= ~0x00000010u; -} -inline void PredictorConsts::clear_outputs_blob_type() { - outputs_blob_type_.ClearToDefaultNoArena(_default_outputs_blob_type_); - clear_has_outputs_blob_type(); -} -inline const ::std::string& PredictorConsts::outputs_blob_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) - return outputs_blob_type_.GetNoArena(_default_outputs_blob_type_); -} -inline void PredictorConsts::set_outputs_blob_type(const ::std::string& value) { - set_has_outputs_blob_type(); - outputs_blob_type_.SetNoArena(_default_outputs_blob_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) -} -inline void PredictorConsts::set_outputs_blob_type(const char* value) { - set_has_outputs_blob_type(); - outputs_blob_type_.SetNoArena(_default_outputs_blob_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) -} -inline void PredictorConsts::set_outputs_blob_type(const char* value, size_t size) { - set_has_outputs_blob_type(); - outputs_blob_type_.SetNoArena(_default_outputs_blob_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) -} -inline ::std::string* PredictorConsts::mutable_outputs_blob_type() { - set_has_outputs_blob_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) - return outputs_blob_type_.MutableNoArena(_default_outputs_blob_type_); -} -inline ::std::string* PredictorConsts::release_outputs_blob_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) - clear_has_outputs_blob_type(); - return outputs_blob_type_.ReleaseNoArena(_default_outputs_blob_type_); -} -inline void PredictorConsts::set_allocated_outputs_blob_type(::std::string* outputs_blob_type) { - if (outputs_blob_type != NULL) { - set_has_outputs_blob_type(); - } else { - clear_has_outputs_blob_type(); - } - outputs_blob_type_.SetAllocatedNoArena(_default_outputs_blob_type_, outputs_blob_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.OUTPUTS_BLOB_TYPE) -} - -// optional string GLOBAL_INIT_NET_TYPE = 6 [default = "GLOBAL_INIT_NET_TYPE"]; -inline bool PredictorConsts::has_global_init_net_type() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void PredictorConsts::set_has_global_init_net_type() { - _has_bits_[0] |= 0x00000020u; -} -inline void PredictorConsts::clear_has_global_init_net_type() { - _has_bits_[0] &= ~0x00000020u; -} -inline void PredictorConsts::clear_global_init_net_type() { - global_init_net_type_.ClearToDefaultNoArena(_default_global_init_net_type_); - clear_has_global_init_net_type(); -} -inline const ::std::string& PredictorConsts::global_init_net_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) - return global_init_net_type_.GetNoArena(_default_global_init_net_type_); -} -inline void PredictorConsts::set_global_init_net_type(const ::std::string& value) { - set_has_global_init_net_type(); - global_init_net_type_.SetNoArena(_default_global_init_net_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) -} -inline void PredictorConsts::set_global_init_net_type(const char* value) { - set_has_global_init_net_type(); - global_init_net_type_.SetNoArena(_default_global_init_net_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) -} -inline void PredictorConsts::set_global_init_net_type(const char* value, size_t size) { - set_has_global_init_net_type(); - global_init_net_type_.SetNoArena(_default_global_init_net_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) -} -inline ::std::string* PredictorConsts::mutable_global_init_net_type() { - set_has_global_init_net_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) - return global_init_net_type_.MutableNoArena(_default_global_init_net_type_); -} -inline ::std::string* PredictorConsts::release_global_init_net_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) - clear_has_global_init_net_type(); - return global_init_net_type_.ReleaseNoArena(_default_global_init_net_type_); -} -inline void PredictorConsts::set_allocated_global_init_net_type(::std::string* global_init_net_type) { - if (global_init_net_type != NULL) { - set_has_global_init_net_type(); - } else { - clear_has_global_init_net_type(); - } - global_init_net_type_.SetAllocatedNoArena(_default_global_init_net_type_, global_init_net_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.GLOBAL_INIT_NET_TYPE) -} - -// optional string PREDICT_INIT_NET_TYPE = 7 [default = "PREDICT_INIT_NET_TYPE"]; -inline bool PredictorConsts::has_predict_init_net_type() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void PredictorConsts::set_has_predict_init_net_type() { - _has_bits_[0] |= 0x00000040u; -} -inline void PredictorConsts::clear_has_predict_init_net_type() { - _has_bits_[0] &= ~0x00000040u; -} -inline void PredictorConsts::clear_predict_init_net_type() { - predict_init_net_type_.ClearToDefaultNoArena(_default_predict_init_net_type_); - clear_has_predict_init_net_type(); -} -inline const ::std::string& PredictorConsts::predict_init_net_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) - return predict_init_net_type_.GetNoArena(_default_predict_init_net_type_); -} -inline void PredictorConsts::set_predict_init_net_type(const ::std::string& value) { - set_has_predict_init_net_type(); - predict_init_net_type_.SetNoArena(_default_predict_init_net_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) -} -inline void PredictorConsts::set_predict_init_net_type(const char* value) { - set_has_predict_init_net_type(); - predict_init_net_type_.SetNoArena(_default_predict_init_net_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) -} -inline void PredictorConsts::set_predict_init_net_type(const char* value, size_t size) { - set_has_predict_init_net_type(); - predict_init_net_type_.SetNoArena(_default_predict_init_net_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) -} -inline ::std::string* PredictorConsts::mutable_predict_init_net_type() { - set_has_predict_init_net_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) - return predict_init_net_type_.MutableNoArena(_default_predict_init_net_type_); -} -inline ::std::string* PredictorConsts::release_predict_init_net_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) - clear_has_predict_init_net_type(); - return predict_init_net_type_.ReleaseNoArena(_default_predict_init_net_type_); -} -inline void PredictorConsts::set_allocated_predict_init_net_type(::std::string* predict_init_net_type) { - if (predict_init_net_type != NULL) { - set_has_predict_init_net_type(); - } else { - clear_has_predict_init_net_type(); - } - predict_init_net_type_.SetAllocatedNoArena(_default_predict_init_net_type_, predict_init_net_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.PREDICT_INIT_NET_TYPE) -} - -// optional string PREDICT_NET_TYPE = 8 [default = "PREDICT_NET_TYPE"]; -inline bool PredictorConsts::has_predict_net_type() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void PredictorConsts::set_has_predict_net_type() { - _has_bits_[0] |= 0x00000080u; -} -inline void PredictorConsts::clear_has_predict_net_type() { - _has_bits_[0] &= ~0x00000080u; -} -inline void PredictorConsts::clear_predict_net_type() { - predict_net_type_.ClearToDefaultNoArena(_default_predict_net_type_); - clear_has_predict_net_type(); -} -inline const ::std::string& PredictorConsts::predict_net_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.PREDICT_NET_TYPE) - return predict_net_type_.GetNoArena(_default_predict_net_type_); -} -inline void PredictorConsts::set_predict_net_type(const ::std::string& value) { - set_has_predict_net_type(); - predict_net_type_.SetNoArena(_default_predict_net_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.PREDICT_NET_TYPE) -} -inline void PredictorConsts::set_predict_net_type(const char* value) { - set_has_predict_net_type(); - predict_net_type_.SetNoArena(_default_predict_net_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.PREDICT_NET_TYPE) -} -inline void PredictorConsts::set_predict_net_type(const char* value, size_t size) { - set_has_predict_net_type(); - predict_net_type_.SetNoArena(_default_predict_net_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.PREDICT_NET_TYPE) -} -inline ::std::string* PredictorConsts::mutable_predict_net_type() { - set_has_predict_net_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.PREDICT_NET_TYPE) - return predict_net_type_.MutableNoArena(_default_predict_net_type_); -} -inline ::std::string* PredictorConsts::release_predict_net_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.PREDICT_NET_TYPE) - clear_has_predict_net_type(); - return predict_net_type_.ReleaseNoArena(_default_predict_net_type_); -} -inline void PredictorConsts::set_allocated_predict_net_type(::std::string* predict_net_type) { - if (predict_net_type != NULL) { - set_has_predict_net_type(); - } else { - clear_has_predict_net_type(); - } - predict_net_type_.SetAllocatedNoArena(_default_predict_net_type_, predict_net_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.PREDICT_NET_TYPE) -} - -// optional string SINGLE_PREDICTOR = 9 [default = "SINGLE_PREDICTOR"]; -inline bool PredictorConsts::has_single_predictor() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void PredictorConsts::set_has_single_predictor() { - _has_bits_[0] |= 0x00000100u; -} -inline void PredictorConsts::clear_has_single_predictor() { - _has_bits_[0] &= ~0x00000100u; -} -inline void PredictorConsts::clear_single_predictor() { - single_predictor_.ClearToDefaultNoArena(_default_single_predictor_); - clear_has_single_predictor(); -} -inline const ::std::string& PredictorConsts::single_predictor() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.SINGLE_PREDICTOR) - return single_predictor_.GetNoArena(_default_single_predictor_); -} -inline void PredictorConsts::set_single_predictor(const ::std::string& value) { - set_has_single_predictor(); - single_predictor_.SetNoArena(_default_single_predictor_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.SINGLE_PREDICTOR) -} -inline void PredictorConsts::set_single_predictor(const char* value) { - set_has_single_predictor(); - single_predictor_.SetNoArena(_default_single_predictor_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.SINGLE_PREDICTOR) -} -inline void PredictorConsts::set_single_predictor(const char* value, size_t size) { - set_has_single_predictor(); - single_predictor_.SetNoArena(_default_single_predictor_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.SINGLE_PREDICTOR) -} -inline ::std::string* PredictorConsts::mutable_single_predictor() { - set_has_single_predictor(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.SINGLE_PREDICTOR) - return single_predictor_.MutableNoArena(_default_single_predictor_); -} -inline ::std::string* PredictorConsts::release_single_predictor() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.SINGLE_PREDICTOR) - clear_has_single_predictor(); - return single_predictor_.ReleaseNoArena(_default_single_predictor_); -} -inline void PredictorConsts::set_allocated_single_predictor(::std::string* single_predictor) { - if (single_predictor != NULL) { - set_has_single_predictor(); - } else { - clear_has_single_predictor(); - } - single_predictor_.SetAllocatedNoArena(_default_single_predictor_, single_predictor); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.SINGLE_PREDICTOR) -} - -// optional string MULTI_PREDICTOR = 10 [default = "MULTI_PREDICTOR"]; -inline bool PredictorConsts::has_multi_predictor() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void PredictorConsts::set_has_multi_predictor() { - _has_bits_[0] |= 0x00000200u; -} -inline void PredictorConsts::clear_has_multi_predictor() { - _has_bits_[0] &= ~0x00000200u; -} -inline void PredictorConsts::clear_multi_predictor() { - multi_predictor_.ClearToDefaultNoArena(_default_multi_predictor_); - clear_has_multi_predictor(); -} -inline const ::std::string& PredictorConsts::multi_predictor() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.MULTI_PREDICTOR) - return multi_predictor_.GetNoArena(_default_multi_predictor_); -} -inline void PredictorConsts::set_multi_predictor(const ::std::string& value) { - set_has_multi_predictor(); - multi_predictor_.SetNoArena(_default_multi_predictor_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.MULTI_PREDICTOR) -} -inline void PredictorConsts::set_multi_predictor(const char* value) { - set_has_multi_predictor(); - multi_predictor_.SetNoArena(_default_multi_predictor_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.MULTI_PREDICTOR) -} -inline void PredictorConsts::set_multi_predictor(const char* value, size_t size) { - set_has_multi_predictor(); - multi_predictor_.SetNoArena(_default_multi_predictor_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.MULTI_PREDICTOR) -} -inline ::std::string* PredictorConsts::mutable_multi_predictor() { - set_has_multi_predictor(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.MULTI_PREDICTOR) - return multi_predictor_.MutableNoArena(_default_multi_predictor_); -} -inline ::std::string* PredictorConsts::release_multi_predictor() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.MULTI_PREDICTOR) - clear_has_multi_predictor(); - return multi_predictor_.ReleaseNoArena(_default_multi_predictor_); -} -inline void PredictorConsts::set_allocated_multi_predictor(::std::string* multi_predictor) { - if (multi_predictor != NULL) { - set_has_multi_predictor(); - } else { - clear_has_multi_predictor(); - } - multi_predictor_.SetAllocatedNoArena(_default_multi_predictor_, multi_predictor); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.MULTI_PREDICTOR) -} - -// optional string TRAIN_INIT_PLAN_TYPE = 11 [default = "TRAIN_INIT_PLAN_TYPE"]; -inline bool PredictorConsts::has_train_init_plan_type() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void PredictorConsts::set_has_train_init_plan_type() { - _has_bits_[0] |= 0x00000400u; -} -inline void PredictorConsts::clear_has_train_init_plan_type() { - _has_bits_[0] &= ~0x00000400u; -} -inline void PredictorConsts::clear_train_init_plan_type() { - train_init_plan_type_.ClearToDefaultNoArena(_default_train_init_plan_type_); - clear_has_train_init_plan_type(); -} -inline const ::std::string& PredictorConsts::train_init_plan_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) - return train_init_plan_type_.GetNoArena(_default_train_init_plan_type_); -} -inline void PredictorConsts::set_train_init_plan_type(const ::std::string& value) { - set_has_train_init_plan_type(); - train_init_plan_type_.SetNoArena(_default_train_init_plan_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) -} -inline void PredictorConsts::set_train_init_plan_type(const char* value) { - set_has_train_init_plan_type(); - train_init_plan_type_.SetNoArena(_default_train_init_plan_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) -} -inline void PredictorConsts::set_train_init_plan_type(const char* value, size_t size) { - set_has_train_init_plan_type(); - train_init_plan_type_.SetNoArena(_default_train_init_plan_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) -} -inline ::std::string* PredictorConsts::mutable_train_init_plan_type() { - set_has_train_init_plan_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) - return train_init_plan_type_.MutableNoArena(_default_train_init_plan_type_); -} -inline ::std::string* PredictorConsts::release_train_init_plan_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) - clear_has_train_init_plan_type(); - return train_init_plan_type_.ReleaseNoArena(_default_train_init_plan_type_); -} -inline void PredictorConsts::set_allocated_train_init_plan_type(::std::string* train_init_plan_type) { - if (train_init_plan_type != NULL) { - set_has_train_init_plan_type(); - } else { - clear_has_train_init_plan_type(); - } - train_init_plan_type_.SetAllocatedNoArena(_default_train_init_plan_type_, train_init_plan_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.TRAIN_INIT_PLAN_TYPE) -} - -// optional string TRAIN_PLAN_TYPE = 12 [default = "TRAIN_PLAN_TYPE"]; -inline bool PredictorConsts::has_train_plan_type() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void PredictorConsts::set_has_train_plan_type() { - _has_bits_[0] |= 0x00000800u; -} -inline void PredictorConsts::clear_has_train_plan_type() { - _has_bits_[0] &= ~0x00000800u; -} -inline void PredictorConsts::clear_train_plan_type() { - train_plan_type_.ClearToDefaultNoArena(_default_train_plan_type_); - clear_has_train_plan_type(); -} -inline const ::std::string& PredictorConsts::train_plan_type() const { - // @@protoc_insertion_point(field_get:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) - return train_plan_type_.GetNoArena(_default_train_plan_type_); -} -inline void PredictorConsts::set_train_plan_type(const ::std::string& value) { - set_has_train_plan_type(); - train_plan_type_.SetNoArena(_default_train_plan_type_, value); - // @@protoc_insertion_point(field_set:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) -} -inline void PredictorConsts::set_train_plan_type(const char* value) { - set_has_train_plan_type(); - train_plan_type_.SetNoArena(_default_train_plan_type_, ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) -} -inline void PredictorConsts::set_train_plan_type(const char* value, size_t size) { - set_has_train_plan_type(); - train_plan_type_.SetNoArena(_default_train_plan_type_, - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) -} -inline ::std::string* PredictorConsts::mutable_train_plan_type() { - set_has_train_plan_type(); - // @@protoc_insertion_point(field_mutable:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) - return train_plan_type_.MutableNoArena(_default_train_plan_type_); -} -inline ::std::string* PredictorConsts::release_train_plan_type() { - // @@protoc_insertion_point(field_release:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) - clear_has_train_plan_type(); - return train_plan_type_.ReleaseNoArena(_default_train_plan_type_); -} -inline void PredictorConsts::set_allocated_train_plan_type(::std::string* train_plan_type) { - if (train_plan_type != NULL) { - set_has_train_plan_type(); - } else { - clear_has_train_plan_type(); - } - train_plan_type_.SetAllocatedNoArena(_default_train_plan_type_, train_plan_type); - // @@protoc_insertion_point(field_set_allocated:caffe2.PredictorConsts.TRAIN_PLAN_TYPE) -} - -inline const PredictorConsts* PredictorConsts::internal_default_instance() { - return &PredictorConsts_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fpredictor_5fconsts_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/proto/prof_dag.pb.h b/app/src/main/cpp/caffe2/proto/prof_dag.pb.h deleted file mode 100644 index 810213e..0000000 --- a/app/src/main/cpp/caffe2/proto/prof_dag.pb.h +++ /dev/null @@ -1,430 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: caffe2/proto/prof_dag.proto - -#ifndef PROTOBUF_caffe2_2fproto_2fprof_5fdag_2eproto__INCLUDED -#define PROTOBUF_caffe2_2fproto_2fprof_5fdag_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace caffe2 { - -// Internal implementation detail -- do not call these. -void protobuf_AddDesc_caffe2_2fproto_2fprof_5fdag_2eproto(); -void protobuf_InitDefaults_caffe2_2fproto_2fprof_5fdag_2eproto(); -void protobuf_AssignDesc_caffe2_2fproto_2fprof_5fdag_2eproto(); -void protobuf_ShutdownFile_caffe2_2fproto_2fprof_5fdag_2eproto(); - -class ProfDAGProto; -class ProfDAGProtos; - -// =================================================================== - -class ProfDAGProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.ProfDAGProto) */ { - public: - ProfDAGProto(); - virtual ~ProfDAGProto(); - - ProfDAGProto(const ProfDAGProto& from); - - inline ProfDAGProto& operator=(const ProfDAGProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ProfDAGProto& default_instance(); - - static const ProfDAGProto* internal_default_instance(); - - void Swap(ProfDAGProto* other); - - // implements Message ---------------------------------------------- - - inline ProfDAGProto* New() const { return New(NULL); } - - ProfDAGProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ProfDAGProto& from); - void MergeFrom(const ProfDAGProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ProfDAGProto* other); - void UnsafeMergeFrom(const ProfDAGProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // required float mean = 2; - bool has_mean() const; - void clear_mean(); - static const int kMeanFieldNumber = 2; - float mean() const; - void set_mean(float value); - - // required float stddev = 3; - bool has_stddev() const; - void clear_stddev(); - static const int kStddevFieldNumber = 3; - float stddev() const; - void set_stddev(float value); - - // @@protoc_insertion_point(class_scope:caffe2.ProfDAGProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_mean(); - inline void clear_has_mean(); - inline void set_has_stddev(); - inline void clear_has_stddev(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - float mean_; - float stddev_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fprof_5fdag_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fprof_5fdag_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fprof_5fdag_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fprof_5fdag_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ProfDAGProto_default_instance_; - -// ------------------------------------------------------------------- - -class ProfDAGProtos : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:caffe2.ProfDAGProtos) */ { - public: - ProfDAGProtos(); - virtual ~ProfDAGProtos(); - - ProfDAGProtos(const ProfDAGProtos& from); - - inline ProfDAGProtos& operator=(const ProfDAGProtos& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ProfDAGProtos& default_instance(); - - static const ProfDAGProtos* internal_default_instance(); - - void Swap(ProfDAGProtos* other); - - // implements Message ---------------------------------------------- - - inline ProfDAGProtos* New() const { return New(NULL); } - - ProfDAGProtos* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ProfDAGProtos& from); - void MergeFrom(const ProfDAGProtos& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ProfDAGProtos* other); - void UnsafeMergeFrom(const ProfDAGProtos& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .caffe2.ProfDAGProto stats = 1; - int stats_size() const; - void clear_stats(); - static const int kStatsFieldNumber = 1; - const ::caffe2::ProfDAGProto& stats(int index) const; - ::caffe2::ProfDAGProto* mutable_stats(int index); - ::caffe2::ProfDAGProto* add_stats(); - ::google::protobuf::RepeatedPtrField< ::caffe2::ProfDAGProto >* - mutable_stats(); - const ::google::protobuf::RepeatedPtrField< ::caffe2::ProfDAGProto >& - stats() const; - - // @@protoc_insertion_point(class_scope:caffe2.ProfDAGProtos) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::caffe2::ProfDAGProto > stats_; - friend void protobuf_InitDefaults_caffe2_2fproto_2fprof_5fdag_2eproto_impl(); - friend void protobuf_AddDesc_caffe2_2fproto_2fprof_5fdag_2eproto_impl(); - friend void protobuf_AssignDesc_caffe2_2fproto_2fprof_5fdag_2eproto(); - friend void protobuf_ShutdownFile_caffe2_2fproto_2fprof_5fdag_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ProfDAGProtos_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// ProfDAGProto - -// required string name = 1; -inline bool ProfDAGProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ProfDAGProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void ProfDAGProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ProfDAGProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& ProfDAGProto::name() const { - // @@protoc_insertion_point(field_get:caffe2.ProfDAGProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ProfDAGProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:caffe2.ProfDAGProto.name) -} -inline void ProfDAGProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:caffe2.ProfDAGProto.name) -} -inline void ProfDAGProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:caffe2.ProfDAGProto.name) -} -inline ::std::string* ProfDAGProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:caffe2.ProfDAGProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ProfDAGProto::release_name() { - // @@protoc_insertion_point(field_release:caffe2.ProfDAGProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ProfDAGProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:caffe2.ProfDAGProto.name) -} - -// required float mean = 2; -inline bool ProfDAGProto::has_mean() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void ProfDAGProto::set_has_mean() { - _has_bits_[0] |= 0x00000002u; -} -inline void ProfDAGProto::clear_has_mean() { - _has_bits_[0] &= ~0x00000002u; -} -inline void ProfDAGProto::clear_mean() { - mean_ = 0; - clear_has_mean(); -} -inline float ProfDAGProto::mean() const { - // @@protoc_insertion_point(field_get:caffe2.ProfDAGProto.mean) - return mean_; -} -inline void ProfDAGProto::set_mean(float value) { - set_has_mean(); - mean_ = value; - // @@protoc_insertion_point(field_set:caffe2.ProfDAGProto.mean) -} - -// required float stddev = 3; -inline bool ProfDAGProto::has_stddev() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ProfDAGProto::set_has_stddev() { - _has_bits_[0] |= 0x00000004u; -} -inline void ProfDAGProto::clear_has_stddev() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ProfDAGProto::clear_stddev() { - stddev_ = 0; - clear_has_stddev(); -} -inline float ProfDAGProto::stddev() const { - // @@protoc_insertion_point(field_get:caffe2.ProfDAGProto.stddev) - return stddev_; -} -inline void ProfDAGProto::set_stddev(float value) { - set_has_stddev(); - stddev_ = value; - // @@protoc_insertion_point(field_set:caffe2.ProfDAGProto.stddev) -} - -inline const ProfDAGProto* ProfDAGProto::internal_default_instance() { - return &ProfDAGProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// ProfDAGProtos - -// repeated .caffe2.ProfDAGProto stats = 1; -inline int ProfDAGProtos::stats_size() const { - return stats_.size(); -} -inline void ProfDAGProtos::clear_stats() { - stats_.Clear(); -} -inline const ::caffe2::ProfDAGProto& ProfDAGProtos::stats(int index) const { - // @@protoc_insertion_point(field_get:caffe2.ProfDAGProtos.stats) - return stats_.Get(index); -} -inline ::caffe2::ProfDAGProto* ProfDAGProtos::mutable_stats(int index) { - // @@protoc_insertion_point(field_mutable:caffe2.ProfDAGProtos.stats) - return stats_.Mutable(index); -} -inline ::caffe2::ProfDAGProto* ProfDAGProtos::add_stats() { - // @@protoc_insertion_point(field_add:caffe2.ProfDAGProtos.stats) - return stats_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::caffe2::ProfDAGProto >* -ProfDAGProtos::mutable_stats() { - // @@protoc_insertion_point(field_mutable_list:caffe2.ProfDAGProtos.stats) - return &stats_; -} -inline const ::google::protobuf::RepeatedPtrField< ::caffe2::ProfDAGProto >& -ProfDAGProtos::stats() const { - // @@protoc_insertion_point(field_list:caffe2.ProfDAGProtos.stats) - return stats_; -} - -inline const ProfDAGProtos* ProfDAGProtos::internal_default_instance() { - return &ProfDAGProtos_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace caffe2 - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_caffe2_2fproto_2fprof_5fdag_2eproto__INCLUDED diff --git a/app/src/main/cpp/caffe2/python/pybind_state.h b/app/src/main/cpp/caffe2/python/pybind_state.h deleted file mode 100644 index a1df4bc..0000000 --- a/app/src/main/cpp/caffe2/python/pybind_state.h +++ /dev/null @@ -1,270 +0,0 @@ -#pragma once - -#include - -#include "caffe2/core/context.h" -#include "caffe2/core/init.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/memonger.h" -#include "caffe2/core/net.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/scope_guard.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/types.h" -#include "caffe2/core/workspace.h" -#include "caffe2/proto/caffe2.pb.h" - -#include -#include - -#include -#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -#define PY_ARRAY_UNIQUE_SYMBOL caffe2_python_ARRAY_API -#include - -// Temporary solution for numpy < 1.7 versions: old macro, no promises. -// You're strongly advised to upgrade to >= 1.7. -#ifndef NPY_ARRAY_C_CONTIGUOUS -#define NPY_ARRAY_C_CONTIGUOUS NPY_C_CONTIGUOUS -#define PyArray_SetBaseObject(arr, x) (PyArray_BASE(arr) = (x)) -#endif - -namespace caffe2 { -namespace python { - -namespace py = pybind11; - -// Add methods common to both CPU and GPU mode. -void addGlobalMethods(pybind11::module& m); -// Expose Workspace, Net, Blob -void addObjectMethods(pybind11::module& m); - -class BlobFetcherBase { - public: - struct FetchedBlob { - pybind11::object obj; - bool copied; - }; - virtual ~BlobFetcherBase(); - virtual pybind11::object Fetch(const Blob& blob) = 0; -}; - -class BlobFeederBase { - public: - virtual ~BlobFeederBase(); - virtual void - Feed(const DeviceOption& option, PyArrayObject* array, Blob* blob) = 0; -}; - -CAFFE_DECLARE_TYPED_REGISTRY(BlobFetcherRegistry, CaffeTypeId, BlobFetcherBase); -#define REGISTER_BLOB_FETCHER(id, ...) \ - CAFFE_REGISTER_TYPED_CLASS(BlobFetcherRegistry, id, __VA_ARGS__) -inline unique_ptr CreateFetcher(CaffeTypeId id) { - return BlobFetcherRegistry()->Create(id); -} - -CAFFE_DECLARE_TYPED_REGISTRY(BlobFeederRegistry, int, BlobFeederBase); -#define REGISTER_BLOB_FEEDER(device_type, ...) \ - CAFFE_REGISTER_TYPED_CLASS(BlobFeederRegistry, device_type, __VA_ARGS__) -inline unique_ptr CreateFeeder(int device_type) { - return BlobFeederRegistry()->Create(device_type); -} - -static_assert( - sizeof(int) == sizeof(int32_t), - "We make an assumption that int is always int32 for numpy " - "type mapping."); - -int CaffeToNumpyType(const TypeMeta& meta); -const TypeMeta& NumpyTypeToCaffe(int numpy_type); - -template -class TensorFetcher : public BlobFetcherBase { - public: - pybind11::object Fetch(const Blob& blob) override { - return FetchTensor(blob.Get>(), true).obj; - } - - bool NeedsCopy(const TypeMeta& meta) const { - return !std::is_same::value || - CaffeToNumpyType(meta) == NPY_OBJECT; - } - - FetchedBlob FetchTensor(const Tensor& tensor, bool force_copy) { - FetchedBlob result; - CAFFE_ENFORCE_GE(tensor.size(), 0, "Trying to fetch unitilized tensor"); - const int numpy_type = CaffeToNumpyType(tensor.meta()); - CAFFE_ENFORCE( - numpy_type != -1, - "This tensor's data type is not supported: ", - tensor.meta().name(), - "."); - std::vector npy_dims; - for (const auto dim : tensor.dims()) { - npy_dims.push_back(dim); - } - result.copied = force_copy || NeedsCopy(tensor.meta()); - void* outPtr; - if (result.copied) { - result.obj = pybind11::object( - PyArray_SimpleNew(tensor.ndim(), npy_dims.data(), numpy_type), - /* borrowed */ false); - outPtr = static_cast( - PyArray_DATA(reinterpret_cast(result.obj.ptr()))); - } else { - outPtr = const_cast&>(tensor).raw_mutable_data(); - result.obj = pybind11::object( - PyArray_SimpleNewFromData( - tensor.ndim(), npy_dims.data(), numpy_type, outPtr), - /* borrowed */ false); - } - - if (numpy_type == NPY_OBJECT) { - PyObject** outObj = reinterpret_cast(outPtr); - auto* str = tensor.template data(); - for (int i = 0; i < tensor.size(); ++i) { - outObj[i] = PyBytes_FromStringAndSize(str->data(), str->size()); - str++; - // cleanup on failure - if (outObj[i] == nullptr) { - for (int j = 0; j < i; ++j) { - Py_DECREF(outObj[j]); - } - CAFFE_THROW("Failed to allocate string for ndarray of strings."); - } - } - return result; - } - - if (result.copied) { - Context context; - context.template CopyBytes( - tensor.nbytes(), tensor.raw_data(), outPtr); - context.FinishDeviceComputation(); - } - return result; - } -}; - -template -class TensorFeeder : public BlobFeederBase { - public: - void FeedTensor( - const DeviceOption& option, - PyArrayObject* original_array, - Tensor* tensor) { - PyArrayObject* array = PyArray_GETCONTIGUOUS(original_array); - auto g = MakeGuard([&]() { Py_XDECREF(array); }); - - const auto npy_type = PyArray_TYPE(array); - const TypeMeta& meta = NumpyTypeToCaffe(npy_type); - CAFFE_ENFORCE( - meta.id() != 0, - "This numpy data type is not supported: ", - PyArray_TYPE(array), - "."); - Context context(option); - context.SwitchToDevice(); - // numpy requires long int as its dims. - int ndim = PyArray_NDIM(array); - npy_intp* npy_dims = PyArray_DIMS(array); - std::vector dims; - for (int i = 0; i < ndim; ++i) { - dims.push_back(npy_dims[i]); - } - tensor->Resize(dims); - - // Now, copy the data to the tensor. - switch (npy_type) { - case NPY_OBJECT: { - PyObject** input = reinterpret_cast(PyArray_DATA(array)); - auto* outPtr = tensor->template mutable_data(); - for (int i = 0; i < tensor->size(); ++i) { - char* str; - Py_ssize_t strSize; -#if PY_MAJOR_VERSION > 2 - if (PyBytes_Check(input[i])) { - CAFFE_ENFORCE( - PyBytes_AsStringAndSize(input[i], &str, &strSize) != -1, - "Had a PyBytes object but cannot convert it to a string."); - } else if (PyUnicode_Check(input[i])) { // string - str = PyUnicode_AsUTF8AndSize(input[i], &strSize); - CAFFE_ENFORCE( - str, - "Had a PyUnicode object but cannot convert it to a string."); - } else { - CAFFE_THROW("Unsupported python object type passed into ndarray."); - } -#else - CAFFE_ENFORCE( - PyBytes_AsStringAndSize(input[i], &str, &strSize) != -1, - "Unsupported python object type passed into ndarray."); -#endif // PY_MAJOR_VERSION > 2 - outPtr[i] = std::string(str, strSize); - } - break; - } - case NPY_UNICODE: - CAFFE_THROW( - "You are feeding in a numpy array of unicode. Caffe2 C++ does not " - "support unicode yet. Please ensure that you are passing in bytes " - "instead of unicode strings."); - break; - default: - context.template CopyBytes( - tensor->size() * meta.itemsize(), - static_cast(PyArray_DATA(array)), - tensor->raw_mutable_data(meta)); - } - context.FinishDeviceComputation(); - } - - virtual void - Feed(const DeviceOption& option, PyArrayObject* original_array, Blob* blob) { - FeedTensor(option, original_array, blob->GetMutable>()); - } -}; - -namespace python_detail { -struct Func; -} - -class PythonOpBase : public Operator { - public: - PythonOpBase( - const OperatorDef& operator_def, - Workspace* ws, - const std::string& pickled_builder_arg_name); - - bool RunOnDevice() override final; - virtual ~PythonOpBase(); - - protected: - virtual const python_detail::Func& getFunc(const std::string& token) = 0; - Workspace* ws_; - - private: - const std::string token_; - std::unique_ptr built_func_; -}; - -class PythonOp final : public PythonOpBase { - public: - PythonOp(const OperatorDef& operator_def, Workspace* ws) - : PythonOpBase(operator_def, ws, "pickled_builder") {} - - protected: - const python_detail::Func& getFunc(const std::string& token) override; -}; - -class PythonGradientOp final : public PythonOpBase { - public: - PythonGradientOp(const OperatorDef& operator_def, Workspace* ws) - : PythonOpBase(operator_def, ws, "pickled_grad_builder") {} - - protected: - const python_detail::Func& getFunc(const std::string& token) override; -}; - -} // namespace python -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/queue/blobs_queue.h b/app/src/main/cpp/caffe2/queue/blobs_queue.h deleted file mode 100644 index 6af56a7..0000000 --- a/app/src/main/cpp/caffe2/queue/blobs_queue.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "caffe2/core/blob_stats.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/stats.h" -#include "caffe2/core/tensor.h" -#include "caffe2/core/workspace.h" - -namespace caffe2 { - -// A thread-safe, bounded, blocking queue. -// Modelled as a circular buffer. - -// Containing blobs are owned by the workspace. -// On read, we swap out the underlying data for the blob passed in for blobs - -class BlobsQueue : public std::enable_shared_from_this { - public: - BlobsQueue( - Workspace* ws, - const std::string& queueName, - size_t capacity, - size_t numBlobs, - bool enforceUniqueName, - const std::vector& fieldNames = {}); - - ~BlobsQueue() { - close(); - } - - bool blockingRead( - const std::vector& inputs, - float timeout_secs = 0.0f); - bool tryWrite(const std::vector& inputs); - bool blockingWrite(const std::vector& inputs); - void close(); - size_t getNumBlobs() const { - return numBlobs_; - } - - private: - bool canWrite(); - void doWrite(const std::vector& inputs); - - std::atomic closing_{false}; - - size_t numBlobs_; - std::mutex mutex_; // protects all variables in the class. - std::condition_variable cv_; - int64_t reader_{0}; - int64_t writer_{0}; - std::vector> queue_; - const std::string name_; - - struct QueueStats { - CAFFE_STAT_CTOR(QueueStats); - CAFFE_EXPORTED_STAT(queue_balance); - CAFFE_EXPORTED_STAT(queue_dequeued_records); - CAFFE_DETAILED_EXPORTED_STAT(queue_dequeued_bytes); - } stats_; -}; -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/queue/blobs_queue_db.h b/app/src/main/cpp/caffe2/queue/blobs_queue_db.h deleted file mode 100644 index f76d460..0000000 --- a/app/src/main/cpp/caffe2/queue/blobs_queue_db.h +++ /dev/null @@ -1,146 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include -#include - -#include "caffe2/core/db.h" -#include "caffe2/core/logging.h" -#include "caffe2/core/stats.h" -#include "caffe2/queue/blobs_queue.h" - -namespace caffe2 { -namespace db { - -namespace { -const std::string& GetStringFromBlob(Blob* blob) { - if (blob->template IsType()) { - return blob->template Get(); - } else if (blob->template IsType>()) { - return *blob->template Get>().template data(); - } else { - CAFFE_THROW("Unsupported Blob type"); - } -} -} - -class BlobsQueueDBCursor : public Cursor { - public: - explicit BlobsQueueDBCursor( - std::shared_ptr queue, - int key_blob_index, - int value_blob_index, - float timeout_secs) - : queue_(queue), - key_blob_index_(key_blob_index), - value_blob_index_(value_blob_index), - timeout_secs_(timeout_secs), - inited_(false), - valid_(false) { - LOG(INFO) << "BlobsQueueDBCursor constructed"; - CAFFE_ENFORCE(queue_ != nullptr, "queue is null"); - CAFFE_ENFORCE(value_blob_index_ >= 0, "value_blob_index < 0"); - } - - virtual ~BlobsQueueDBCursor() {} - - void Seek(const string& /* unused */) override { - CAFFE_THROW("Seek is not supported."); - } - - bool SupportsSeek() override { - return false; - } - - void SeekToFirst() override { - // not applicable - } - - void Next() override { - unique_ptr blob = make_unique(); - vector blob_vector{blob.get()}; - auto success = queue_->blockingRead(blob_vector, timeout_secs_); - if (!success) { - LOG(ERROR) << "Timed out reading from BlobsQueue or it is closed"; - valid_ = false; - return; - } - - if (key_blob_index_ >= 0) { - key_ = GetStringFromBlob(blob_vector[key_blob_index_]); - } - value_ = GetStringFromBlob(blob_vector[value_blob_index_]); - valid_ = true; - } - - string key() override { - if (!inited_) { - Next(); - inited_ = true; - } - return key_; - } - - string value() override { - if (!inited_) { - Next(); - inited_ = true; - } - return value_; - } - - bool Valid() override { - return valid_; - } - - private: - std::shared_ptr queue_; - int key_blob_index_; - int value_blob_index_; - float timeout_secs_; - bool inited_; - string key_; - string value_; - bool valid_; -}; - -class BlobsQueueDB : public DB { - public: - BlobsQueueDB( - const string& source, - Mode mode, - std::shared_ptr queue, - int key_blob_index = -1, - int value_blob_index = 0, - float timeout_secs = 0.0) - : DB(source, mode), - queue_(queue), - key_blob_index_(key_blob_index), - value_blob_index_(value_blob_index), - timeout_secs_(timeout_secs) { - LOG(INFO) << "BlobsQueueDB constructed"; - } - - virtual ~BlobsQueueDB() { - Close(); - } - - void Close() override {} - unique_ptr NewCursor() override { - return make_unique( - queue_, key_blob_index_, value_blob_index_, timeout_secs_); - } - - unique_ptr NewTransaction() override { - CAFFE_THROW("Not implemented."); - } - - private: - std::shared_ptr queue_; - int key_blob_index_; - int value_blob_index_; - float timeout_secs_; -}; -} // namespace db -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/queue/queue_ops.h b/app/src/main/cpp/caffe2/queue/queue_ops.h deleted file mode 100644 index 8bd4fb7..0000000 --- a/app/src/main/cpp/caffe2/queue/queue_ops.h +++ /dev/null @@ -1,245 +0,0 @@ -#pragma once - -#include -#include "blobs_queue.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -class CreateBlobsQueueOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - CreateBlobsQueueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - ws_(ws), - name(operator_def.output().Get(0)) {} - - bool RunOnDevice() override { - const auto capacity = - OperatorBase::template GetSingleArgument("capacity", 1); - const auto numBlobs = - OperatorBase::template GetSingleArgument("num_blobs", 1); - const auto enforceUniqueName = - OperatorBase::template GetSingleArgument( - "enforce_unique_name", false); - const auto fieldNames = - OperatorBase::template GetRepeatedArgument("field_names"); - CAFFE_ENFORCE_EQ(this->OutputSize(), 1); - auto queuePtr = Operator::Outputs()[0] - ->template GetMutable>(); - CAFFE_ENFORCE(queuePtr); - *queuePtr = std::make_shared( - ws_, name, capacity, numBlobs, enforceUniqueName, fieldNames); - return true; - } - - private: - Workspace* ws_{nullptr}; - const std::string name; -}; - -template -class EnqueueBlobsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - bool RunOnDevice() override { - CAFFE_ENFORCE(InputSize() > 1); - auto queue = Operator::Inputs()[0] - ->template Get>(); - CAFFE_ENFORCE(queue && OutputSize() == queue->getNumBlobs()); - return queue->blockingWrite(this->Outputs()); - } - - private: -}; - -template -class DequeueBlobsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - DequeueBlobsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - timeout_secs_ = OperatorBase::GetSingleArgument("timeout_secs", 0); - } - - bool RunOnDevice() override { - CAFFE_ENFORCE(InputSize() == 1); - auto queue = - OperatorBase::Inputs()[0]->template Get>(); - CAFFE_ENFORCE(queue && OutputSize() == queue->getNumBlobs()); - return queue->blockingRead(this->Outputs(), timeout_secs_); - } - - private: - float timeout_secs_; -}; - -template -class CloseBlobsQueueOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - bool RunOnDevice() override { - CAFFE_ENFORCE_EQ(InputSize(), 1); - auto queue = - OperatorBase::Inputs()[0]->template Get>(); - CAFFE_ENFORCE(queue); - queue->close(); - return true; - } - - private: -}; - -template -class SafeEnqueueBlobsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - bool RunOnDevice() override { - auto queue = Operator::Inputs()[0] - ->template Get>(); - CAFFE_ENFORCE(queue); - auto size = queue->getNumBlobs(); - CAFFE_ENFORCE( - OutputSize() == size + 1, - "Expected " + caffe2::to_string(size + 1) + ", " + " got: " + - caffe2::to_string(size)); - bool status = queue->blockingWrite(this->Outputs()); - Output(size)->Resize(); - math::Set( - 1, !status, Output(size)->template mutable_data(), &context_); - return true; - } -}; - -template -class SafeDequeueBlobsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - using Operator::Operator; - - SafeDequeueBlobsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - numRecords_(OperatorBase::GetSingleArgument("num_records", 1)) { - CAFFE_ENFORCE_GT(numRecords_, 0); - } - - bool dequeueMany(std::shared_ptr& queue) { - auto size = queue->getNumBlobs(); - - if (blobs_.size() != size) { - blobs_.resize(size); - blobPtrs_.resize(size); - for (int col = 0; col < size; ++col) { - blobPtrs_.at(col) = &blobs_.at(col); - } - } - - const int kTensorGrowthPct = 40; - for (int i = 0; i < numRecords_; ++i) { - if (!queue->blockingRead(blobPtrs_)) { - // if we read at least one record, status is still true - return i > 0; - } - for (int col = 0; col < size; ++col) { - auto* out = this->Output(col); - const auto& in = blobPtrs_.at(col)->template Get>(); - if (i == 0) { - out->CopyFrom(in); - } else { - auto oldSize = out->size(); - out->Extend(in.dims()[0], kTensorGrowthPct, &context_); - auto* dst = - (char*)out->raw_mutable_data() + oldSize * in.meta().itemsize(); - context_.template CopyItems( - in.meta(), in.size(), in.raw_data(), dst); - } - } - } - return true; - } - - bool dequeueOne(std::shared_ptr& queue) { - return queue->blockingRead(this->Outputs()); - } - - bool RunOnDevice() override { - CAFFE_ENFORCE(InputSize() == 1); - auto queue = Operator::Inputs()[0] - ->template Get>(); - CAFFE_ENFORCE(queue); - - auto size = queue->getNumBlobs(); - CAFFE_ENFORCE_EQ(OutputSize(), size + 1); - - bool status = numRecords_ > 1 ? dequeueMany(queue) : dequeueOne(queue); - - Output(size)->Resize(); - math::Set( - 1, !status, Output(size)->template mutable_data(), &context_); - return true; - } - - private: - int numRecords_; - std::vector blobs_; - std::vector blobPtrs_; -}; - -template -class WeightedSampleDequeueBlobsOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - WeightedSampleDequeueBlobsOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) { - vector weights = OperatorBase::GetRepeatedArgument("weights"); - if (weights.empty()) { - weights.resize(InputSize(), 1.0f); - } - CAFFE_ENFORCE_EQ(InputSize(), weights.size()); - - float sum = accumulate(weights.begin(), weights.end(), 0.0f); - CAFFE_ENFORCE(sum > 0.0f, "Sum of weights must be positive"); - cumProbs_.resize(weights.size()); - for (int i = 0; i < weights.size(); i++) { - cumProbs_[i] = weights[i] / sum; - CAFFE_ENFORCE_GE( - cumProbs_[i], 0.0f, "Each probability must be non-negative"); - } - std::partial_sum(cumProbs_.begin(), cumProbs_.end(), cumProbs_.begin()); - // Put last value to be 1.0001 to avoid numerical issues. - cumProbs_.back() = 1.0001; - - LOG(INFO) << "Dequeue weights: " << weights; - LOG(INFO) << "cumProbs: " << cumProbs_; - } - - bool RunOnDevice() override { - float r; - math::RandUniform(1, 0.0f, 1.0f, &r, &context_); - auto lb = lower_bound(cumProbs_.begin(), cumProbs_.end(), r); - CAFFE_ENFORCE(lb != cumProbs_.end(), "Cannot find ", r, " in cumProbs_."); - - auto queue = Operator::Inputs()[lb - cumProbs_.begin()] - ->template Get>(); - - CAFFE_ENFORCE(queue); - auto size = queue->getNumBlobs(); - CAFFE_ENFORCE_EQ(OutputSize(), size + 1); - bool status = queue->blockingRead(this->Outputs()); - Output(size)->Resize(); - math::Set( - 1, !status, Output(size)->template mutable_data(), &context_); - return true; - } - - private: - vector cumProbs_; -}; -} diff --git a/app/src/main/cpp/caffe2/queue/rebatching_queue.h b/app/src/main/cpp/caffe2/queue/rebatching_queue.h deleted file mode 100644 index 052402e..0000000 --- a/app/src/main/cpp/caffe2/queue/rebatching_queue.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "caffe2/core/logging.h" -#include "caffe2/core/operator.h" -#include "caffe2/core/stats.h" -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -// TODO: This is a very naive implementation with a single mutex. We can do the -// atomic index + circular queue optimizations or pull something more -// heavy-weight later - -class RebatchingQueue { - public: - RebatchingQueue(size_t capacity, size_t numBlobs); - - ~RebatchingQueue(); - - bool enqueueOne( - CPUContext& context, - const std::vector& inputs); - - bool enqueueMany( - CPUContext& context, - const std::vector& inputs); - - bool dequeue( - CPUContext& context, - size_t numElements, - const std::vector& outputs); - - size_t capacity() const; - - size_t numBlobs() const; - - bool isClosed() const; - - void close(); - - private: - bool enqueue(std::vector> splittedInputs); - - bool canWrite() const; - bool canRead() const; - - const size_t capacity_; - const size_t numBlobs_; - - mutable std::mutex mutex_; - - bool isClosed_{false}; - - uint64_t head_{0}; - uint64_t tail_{0}; - - std::condition_variable cvEmpty_; - std::condition_variable cvOverflow_; - - std::vector> queue_; -}; -} // caffe2 diff --git a/app/src/main/cpp/caffe2/queue/rebatching_queue_ops.h b/app/src/main/cpp/caffe2/queue/rebatching_queue_ops.h deleted file mode 100644 index 80749a4..0000000 --- a/app/src/main/cpp/caffe2/queue/rebatching_queue_ops.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include "rebatching_queue.h" - -namespace caffe2 { - -using RebatchingQueuePtr = std::unique_ptr; - -class CreateRebatchingQueueOp : public Operator { - public: - CreateRebatchingQueueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - *OperatorBase::Output(0) = - RebatchingQueuePtr(new RebatchingQueue( - OperatorBase::GetSingleArgument("capacity", 1), - OperatorBase::GetSingleArgument("num_blobs", 1))); - return true; - } -}; - -class EnqueueRebatchingQueueOp : public Operator { - public: - EnqueueRebatchingQueueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - enqueueBatch_( - OperatorBase::GetSingleArgument("enqueue_batch", false)) {} - bool RunOnDevice() override { - auto& queue = Inputs()[0]->template Get(); - CHECK(queue); - CAFFE_ENFORCE_EQ(InputSize(), queue->numBlobs() + 1); - std::vector inputTensors; - inputTensors.reserve(InputSize() - 1); - for (int i = 1; i < InputSize(); ++i) { - inputTensors.push_back(&Input(i)); - } - - return enqueueBatch_ ? queue->enqueueMany(context_, inputTensors) - : queue->enqueueOne(context_, inputTensors); - } - - private: - const bool enqueueBatch_; -}; - -class DequeueRebatchingQueueOp : public Operator { - public: - DequeueRebatchingQueueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - numElements_(OperatorBase::GetSingleArgument("num_elements", 1)) {} - - bool RunOnDevice() override { - auto& queue = Inputs()[0]->template Get(); - CHECK(queue); - - std::vector outputTensors; - outputTensors.reserve(OutputSize()); - for (int i = 0; i < OutputSize(); ++i) { - outputTensors.push_back(Output(i)); - } - - return queue->dequeue(context_, numElements_, outputTensors); - } - - private: - int numElements_; -}; - -class CloseRebatchingQueueOp : public Operator { - public: - CloseRebatchingQueueOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - CAFFE_ENFORCE_EQ(InputSize(), 1); - auto& queue = Inputs()[0]->template Get(); - CAFFE_ENFORCE(queue); - queue->close(); - return true; - } -}; -} // caffe2 diff --git a/app/src/main/cpp/caffe2/sgd/adagrad_op.h b/app/src/main/cpp/caffe2/sgd/adagrad_op.h deleted file mode 100644 index 20815c4..0000000 --- a/app/src/main/cpp/caffe2/sgd/adagrad_op.h +++ /dev/null @@ -1,241 +0,0 @@ -#pragma once - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -void adagrad_update( - int N, - const float* w, - const float* g, - const float* h, - float* nw, - float* nh, - float epsilon, - float decay, - const float* lr, - Context* /*context*/) { - for (auto i = 0; i < N; ++i) { - float gi = g[i]; - float hi = nh[i] = decay * h[i] + gi * gi; - nw[i] = w[i] + lr[0] * gi / (std::sqrt(hi) + epsilon); - } -} - -template -class AdagradOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - AdagradOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)), - decay_(OperatorBase::GetSingleArgument("decay", 1.0f)) {} - - bool RunOnDevice() override { - CAFFE_ENFORCE(Input(GRAD).size() == Input(MOMENT_1).size()); - CAFFE_ENFORCE(Input(GRAD).size() == Input(PARAM).size()); - Output(OUTPUT_PARAM)->ResizeLike(Input(PARAM)); - Output(OUTPUT_MOMENT_1)->ResizeLike(Input(MOMENT_1)); - adagrad_update( - Input(GRAD).size(), - Input(PARAM).template data(), - Input(GRAD).template data(), - Input(MOMENT_1).template data(), - Output(OUTPUT_PARAM)->template mutable_data(), - Output(OUTPUT_MOMENT_1)->template mutable_data(), - epsilon_, - decay_, - Input(LR).template data(), - &context_); - return true; - } - - protected: - T epsilon_; - T decay_; - INPUT_TAGS(PARAM, MOMENT_1, GRAD, LR); - OUTPUT_TAGS(OUTPUT_PARAM, OUTPUT_MOMENT_1); -}; - -template -class SparseAdagradOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseAdagradOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - - bool RunOnDevice() override { - // Enforce shapes - CAFFE_ENFORCE_EQ(Input(PARAM).size(), Input(MOMENT_1).size()); - CAFFE_ENFORCE_EQ(Input(LR).size(), 1); - CAFFE_ENFORCE_EQ( - Input(PARAM).size_from_dim(1), - Input(GRAD).size_from_dim(Input(INDICES).ndim())); - - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - const auto* lr = Input(LR).template data(); - const auto* indices = Input(INDICES).template data(); - const auto* gradIn = Input(GRAD).template data(); - const auto* paramIn = Input(PARAM).template data(); - const auto* momentIn = Input(MOMENT_1).template data(); - auto* paramOut = Output(OUTPUT_PARAM)->template mutable_data(); - auto* momentOut = Output(OUTPUT_MOMENT_1)->template mutable_data(); - - auto n = Input(INDICES).size(); - if (n == 0) { - return true; - } - - auto block_size = Input(GRAD).size() / n; - for (auto i = 0; i < n; ++i) { - auto idx = indices[i]; - if (block_size == 1) { - float gi = gradIn[i]; - float hi = momentOut[idx] = momentIn[idx] + gi * gi; - paramOut[idx] = paramIn[idx] + lr[0] * gi / (std::sqrt(hi) + epsilon_); - } else { - auto offsetI = i * block_size; - auto offsetIdx = idx * block_size; - -#ifndef NDEBUG - CAFFE_ENFORCE_GE( - Input(PARAM).size(), - block_size + offsetIdx, - this->debug_def().input(PARAM), - ", out of bound, idx:", - idx, - " for input i:", - i, - " and block size:", - block_size); - CAFFE_ENFORCE_GE( - Input(GRAD).size(), - block_size + offsetI, - this->debug_def().input(GRAD), - ", out of bound idx, idx:", - idx, - " for input i:", - i); -#endif - adagrad_update( - block_size, - paramIn + offsetIdx, - gradIn + offsetI, - momentIn + offsetIdx, - paramOut + offsetIdx, - momentOut + offsetIdx, - epsilon_, - 1.0f, - lr, - &context_); - } - } - return true; - } - - protected: - T epsilon_; - INPUT_TAGS(PARAM, MOMENT_1, INDICES, GRAD, LR); - OUTPUT_TAGS(OUTPUT_PARAM, OUTPUT_MOMENT_1); -}; - -template -class RowWiseSparseAdagradOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RowWiseSparseAdagradOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - - bool RunOnDevice() override { - // Enforce shapes - CAFFE_ENFORCE_EQ(Input(PARAM).dims()[0], Input(MOMENT_1).size()); - CAFFE_ENFORCE_EQ(Input(LR).size(), 1); - CAFFE_ENFORCE_EQ( - Input(PARAM).size_from_dim(1), - Input(GRAD).size_from_dim(Input(INDICES).ndim())); - - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - const auto* lr = Input(LR).template data(); - const auto* indices = Input(INDICES).template data(); - const auto* gradIn = Input(GRAD).template data(); - const auto* paramIn = Input(PARAM).template data(); - const auto* momentIn = Input(MOMENT_1).template data(); - auto* paramOut = Output(OUTPUT_PARAM)->template mutable_data(); - auto* momentOut = Output(OUTPUT_MOMENT_1)->template mutable_data(); - - auto n = Input(INDICES).size(); - if (n == 0) { - return true; - } - - auto block_size = Input(GRAD).size() / n; - - for (auto i = 0; i < n; ++i) { - auto idx = indices[i]; - if (block_size == 1) { - float gi = gradIn[i]; - float hi = momentOut[idx] = momentIn[idx] + gi * gi; - paramOut[idx] = paramIn[idx] + lr[0] * gi / (std::sqrt(hi) + epsilon_); - } else { - auto offsetI = i * block_size; - auto offsetIdx = idx * block_size; - -#ifndef NDEBUG - CAFFE_ENFORCE_GE( - Input(PARAM).size(), - block_size + offsetIdx, - this->debug_def().input(PARAM), - ", out of bound, idx:", - idx, - " for input i:", - i, - " and block size:", - block_size); - CAFFE_ENFORCE_GE( - Input(GRAD).size(), - block_size + offsetI, - this->debug_def().input(GRAD), - ", out of bound idx, idx:", - idx, - " for input i:", - i); -#endif - - const float* w = paramIn + offsetIdx; - const float* g = gradIn + offsetI; - const float* h = momentIn + idx; - float* nw = paramOut + offsetIdx; - float* nh = momentOut + idx; - float hs = 0.; - for (auto j = 0; j < block_size; ++j) { - float gj = g[j]; - hs += gj * gj; - } - float hi = nh[0] = h[0] + hs / block_size; - for (auto j = 0; j < block_size; ++j) { - nw[j] = w[j] + lr[0] * g[j] / (std::sqrt(hi) + epsilon_); - } - } - } - return true; - } - - protected: - T epsilon_; - INPUT_TAGS(PARAM, MOMENT_1, INDICES, GRAD, LR); - OUTPUT_TAGS(OUTPUT_PARAM, OUTPUT_MOMENT_1); -}; -} diff --git a/app/src/main/cpp/caffe2/sgd/adam_op.h b/app/src/main/cpp/caffe2/sgd/adam_op.h deleted file mode 100644 index 22e46c6..0000000 --- a/app/src/main/cpp/caffe2/sgd/adam_op.h +++ /dev/null @@ -1,215 +0,0 @@ -#pragma once - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -void adam_update( - int N, - const float* g, - const float* m, - const float* v, - float* ng, - float* nm, - float* nv, - float beta1, - float beta2, - float eps_hat, - float correction, - const float* lr, - Context* /*context*/) { - for (auto i = 0; i < N; ++i) { - float gi = g[i]; - float mi = nm[i] = m[i] * beta1 + gi * (1 - beta1); - float vi = nv[i] = v[i] * beta2 + gi * gi * (1 - beta2); - ng[i] = lr[0] * correction * mi / (std::sqrt(vi) + eps_hat); - } -} - -template -void adam_compute( - int N, - const float* w, - const float* g, - const float* m, - const float* v, - float* nw, - float* nm, - float* nv, - float beta1, - float beta2, - float eps_hat, - float correction, - const float* lr, - Context* /*context*/) { - for (auto i = 0; i < N; ++i) { - float gi = g[i]; - float mi = nm[i] = m[i] * beta1 + gi * (1 - beta1); - float vi = nv[i] = v[i] * beta2 + gi * gi * (1 - beta2); - float ng = lr[0] * correction * mi / (std::sqrt(vi) + eps_hat); - nw[i] = w[i] + ng; - } -} - -template -class AdamOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - AdamOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - beta1_(OperatorBase::GetSingleArgument("beta1", 0.9f)), - beta2_(OperatorBase::GetSingleArgument("beta2", 0.999f)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - bool RunOnDevice() override { - // Iter live on the CPU - CAFFE_ENFORCE(OperatorBase::InputIsType(ITER)); - CAFFE_ENFORCE(Input(LR).size() == 1); - CAFFE_ENFORCE(Input(GRAD).size() == Input(PARAM).size()); - CAFFE_ENFORCE(Input(GRAD).size() == Input(MOMENT_1).size()); - CAFFE_ENFORCE(Input(GRAD).size() == Input(MOMENT_2).size()); - Output(OUTPUT_PARAM)->ResizeLike(Input(PARAM)); - Output(OUTPUT_MOMENT_1)->ResizeLike(Input(MOMENT_1)); - Output(OUTPUT_MOMENT_2)->ResizeLike(Input(MOMENT_2)); - - const auto iter = - OperatorBase::Input(ITER).template data()[0]; - - const auto t = iter + 1; - const auto correction = - std::sqrt(T(1.) - std::pow(beta2_, t)) / (T(1.) - std::pow(beta1_, t)); - adam_compute( - Input(GRAD).size(), - Input(PARAM).template data(), - Input(GRAD).template data(), - Input(MOMENT_1).template data(), - Input(MOMENT_2).template data(), - Output(OUTPUT_PARAM)->template mutable_data(), - Output(OUTPUT_MOMENT_1)->template mutable_data(), - Output(OUTPUT_MOMENT_2)->template mutable_data(), - beta1_, - beta2_, - epsilon_, - correction, - Input(LR).template data(), - &context_); - return true; - } - - protected: - T beta1_{0.9}; - T beta2_{0.999}; - T epsilon_{1e-8}; - INPUT_TAGS(PARAM, MOMENT_1, MOMENT_2, GRAD, LR, ITER); - OUTPUT_TAGS(OUTPUT_PARAM, OUTPUT_MOMENT_1, OUTPUT_MOMENT_2); -}; - -template -class SparseAdamOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseAdamOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - beta1_(OperatorBase::GetSingleArgument("beta1", 0.9f)), - beta2_(OperatorBase::GetSingleArgument("beta2", 0.999f)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - - bool RunOnDevice() override { - // Enforce shapes - CAFFE_ENFORCE_EQ(Input(PARAM).size(), Input(MOMENT_1).size()); - CAFFE_ENFORCE_EQ(Input(PARAM).size(), Input(MOMENT_2).size()); - CAFFE_ENFORCE_EQ(Input(PARAM).size_from_dim(1), - Input(GRAD).size_from_dim(Input(INDICES).ndim())); - CAFFE_ENFORCE_EQ(Input(LR).size(), 1); - - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - const auto* lr = Input(LR).template data(); - const auto iter = - OperatorBase::Input(ITER).template data()[0]; - - const auto t = iter + 1; - const auto correction = - std::sqrt(T(1.) - std::pow(beta2_, t)) / (T(1.) - std::pow(beta1_, t)); - - auto block_size = Input(PARAM).size() / Input(PARAM).dim(0); - auto n = Input(GRAD).size() / block_size; - - const auto* paramIn = Input(PARAM).template data(); - const auto* indices = Input(INDICES).template data(); - const auto* gradIn = Input(GRAD).template data(); - const auto* moment1In = Input(MOMENT_1).template data(); - const auto* moment2In = Input(MOMENT_2).template data(); - auto* paramOut = Output(OUTPUT_PARAM)->template mutable_data(); - auto* moment1Out = Output(OUTPUT_MOMENT_1)->template mutable_data(); - auto* moment2Out = Output(OUTPUT_MOMENT_2)->template mutable_data(); - - for (auto i = 0; i < n; ++i) { - auto idx = indices[i]; - - if (block_size == 1) { - float gi = gradIn[i]; - float mi = moment1Out[idx] = - moment1In[idx] * beta1_ + gi * (1 - beta1_); - float vi = moment2Out[idx] = - moment2In[idx] * beta2_ + gi * gi * (1 - beta2_); - paramOut[idx] = - paramIn[idx] + lr[0] * correction * mi / (std::sqrt(vi) + epsilon_); - - } else { - auto offsetI = i * block_size; - auto offsetIdx = idx * block_size; - -#ifndef NDEBUG - CAFFE_ENFORCE_GE( - Input(PARAM).size(), - block_size + offsetIdx, - this->debug_def().input(PARAM), - ", out of bound, idx:", - idx, - " for input i:", - i, - " and block size:", - block_size); - CAFFE_ENFORCE_GE( - Input(GRAD).size(), - block_size + offsetI, - this->debug_def().input(GRAD), - ", out of bound idx, idx:", - idx, - " for input i:", - i); -#endif - - adam_compute( - block_size, - paramIn + offsetIdx, - gradIn + offsetI, - moment1In + offsetIdx, - moment2In + offsetIdx, - paramOut + offsetIdx, - moment1Out + offsetIdx, - moment2Out + offsetIdx, - beta1_, - beta2_, - epsilon_, - correction, - lr, - &context_); - } - } - return true; - } - - protected: - T beta1_; - T beta2_; - T epsilon_; - INPUT_TAGS(PARAM, MOMENT_1, MOMENT_2, INDICES, GRAD, LR, ITER); - OUTPUT_TAGS(OUTPUT_PARAM, OUTPUT_MOMENT_1, OUTPUT_MOMENT_2); -}; -} diff --git a/app/src/main/cpp/caffe2/sgd/ftrl_op.h b/app/src/main/cpp/caffe2/sgd/ftrl_op.h deleted file mode 100644 index 079fe60..0000000 --- a/app/src/main/cpp/caffe2/sgd/ftrl_op.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -struct FtrlParams { - explicit FtrlParams(OperatorBase* op) - : alphaInv(1.0 / op->GetSingleArgument("alpha", 0.005f)), - beta(op->GetSingleArgument("beta", 1.0f)), - lambda1(op->GetSingleArgument("lambda1", 0.001f)), - lambda2(op->GetSingleArgument("lambda2", 0.001f)) {} - T alphaInv; - T beta; - T lambda1; - T lambda2; -}; - -// TODO(dzhulgakov): implement GPU version if necessary -template -class FtrlOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - FtrlOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), params_(this) { - CAFFE_ENFORCE( - !HasArgument("alpha") || ALPHA >= InputSize(), - "Cannot specify alpha by both input and argument"); - } - bool RunOnDevice() override; - - protected: - FtrlParams params_; - INPUT_TAGS(VAR, N_Z, GRAD, ALPHA); - OUTPUT_TAGS(OUTPUT_VAR, OUTPUT_N_Z); -}; - -template -class SparseFtrlOp final : public Operator { - public: - SparseFtrlOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), params_(this) { - CAFFE_ENFORCE( - !HasArgument("alpha") || ALPHA >= InputSize(), - "Cannot specify alpha by both input and argument"); - } - - bool RunOnDevice() override { - // run time learning rate override - if (ALPHA < InputSize()) { - CAFFE_ENFORCE_EQ(Input(ALPHA).size(), 1, "alpha should be real-valued"); - params_.alphaInv = 1.0 / *(Input(ALPHA).template data()); - } - // Use run-time polymorphism - auto& indices = Input(INDICES); - if (indices.template IsType()) { - DoRun(); - } else if (indices.template IsType()) { - DoRun(); - } else { - LOG(FATAL) << "Unsupported type of INDICES in SparseFtrlOp: " - << indices.meta().name(); - } - return true; - } - - protected: - FtrlParams params_; - INPUT_TAGS(VAR, N_Z, INDICES, GRAD, ALPHA); - OUTPUT_TAGS(OUTPUT_VAR, OUTPUT_N_Z); - - private: - template - void DoRun(); -}; - -} diff --git a/app/src/main/cpp/caffe2/sgd/iter_op.h b/app/src/main/cpp/caffe2/sgd/iter_op.h deleted file mode 100644 index 1ce120d..0000000 --- a/app/src/main/cpp/caffe2/sgd/iter_op.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef CAFFE2_SGD_ITER_OP_H_ -#define CAFFE2_SGD_ITER_OP_H_ - -#include -#include - -#include "caffe2/core/blob_serialization.h" -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -inline void IncrementIter(TensorCPU* output) { - CAFFE_ENFORCE_EQ( - output->size(), - 1, - "The output of IterOp exists, but not of the right size."); - int64_t* iter = output->template mutable_data(); - CAFFE_ENFORCE(*iter >= 0, "Previous iteration number is negative."); - CAFFE_ENFORCE( - *iter < std::numeric_limits::max(), "Overflow will happen!"); - (*iter)++; -} - -// IterOp runs an iteration counter. I cannot think of a case where we would -// need to access the iter variable on device, so this will always produce a -// tensor on the CPU side. If the blob already exists and is a tensor -// object, we will simply increment it (this emulates the case when we want to -// resume training). Otherwise we will have the iter starting with 0. -template -class IterOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - IterOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - if (InputSize() == 0) { - if (!OperatorBase::OutputIsType(0)) { - // This is the first run; set the iter to start with 0. - LOG(ERROR) << "You are using an old definition of IterOp that will " - "be deprecated soon. More specifically, IterOp now " - "requires an explicit in-place input and output."; - - auto* output = OperatorBase::Output(0); - VLOG(1) << "Initializing iter counter."; - output->Resize(1); - output->template mutable_data()[0] = 0; - } - } - IncrementIter(OperatorBase::Output(0)); - return true; - } -}; - -template -class AtomicIterOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - - AtomicIterOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws) {} - - bool RunOnDevice() override { - auto& mutex = OperatorBase::Input>(0); - std::lock_guard lg(*mutex); - IncrementIter(OperatorBase::Output(0)); - return true; - } -}; - -class MutexSerializer : public BlobSerializerBase { - public: - /** - * Serializes a std::unique_ptr. Note that this blob has to - * contain std::unique_ptr, otherwise this function produces a - * fatal error. - */ - void Serialize( - const Blob& blob, - const string& name, - BlobSerializerBase::SerializationAcceptor acceptor) override; -}; - -class MutexDeserializer : public BlobDeserializerBase { - public: - void Deserialize(const BlobProto& proto, Blob* blob) override; -}; - -} // namespace caffe2 - -#endif // CAFFE2_SGD_ITER_OP_H_ diff --git a/app/src/main/cpp/caffe2/sgd/learning_rate_functors.h b/app/src/main/cpp/caffe2/sgd/learning_rate_functors.h deleted file mode 100644 index db00480..0000000 --- a/app/src/main/cpp/caffe2/sgd/learning_rate_functors.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef CAFFE2_SGD_LEARNING_RATE_FUNCTORS_H_ -#define CAFFE2_SGD_LEARNING_RATE_FUNCTORS_H_ - -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -// LearningRateFunctor is a functor that when fed with an iter number, produces -// the learning rate for the corresponding iteration. -template -class LearningRateFunctor { - public: - virtual ~LearningRateFunctor() {} - virtual T operator()(const int64_t iter) const = 0; -}; - -// Fixed: not changing the learning rate at all. -template -class FixedLearningRate : public LearningRateFunctor { - public: - T operator()(const int64_t /*iter*/) const override { - return 1.; - } -}; - -// Step: return gamma ^ (floor(iter / step)) -template -class StepLearningRate : public LearningRateFunctor { - public: - StepLearningRate(const int stepsize, const T gamma) - : stepsize_(stepsize), gamma_(gamma) {} - T operator()(const int64_t iter) const override { - return std::pow(gamma_, static_cast(iter / stepsize_)); - } - - int stepsize_; - T gamma_; -}; - -// Exp: return gamma ^ iter -template -class ExpLearningRate : public LearningRateFunctor { - public: - explicit ExpLearningRate(const T gamma) : gamma_(gamma) {} - T operator()(const int64_t iter) const override { - return std::pow(gamma_, static_cast(iter)); - } - - T gamma_; -}; - -// Inv: return (1 + gamma * iter) ^ (-power) -template -class InvLearningRate : public LearningRateFunctor { - public: - InvLearningRate(const T gamma, const T power) - : gamma_(gamma), power_(power) {} - T operator()(const int64_t iter) const override { - return std::pow(T(1) + gamma_ * iter, -power_); - } - T gamma_; - T power_; -}; - -// Poly: return (1 - iter/max_iter) ^ (power) -template -class PolyLearningRate : public LearningRateFunctor { - public: - PolyLearningRate(const T power, const int64_t max_iter) - : power_(power), max_iter_(max_iter) {} - T operator()(const int64_t iter) const override { - return std::pow(1 - T(iter)/T(max_iter_), power_); - } - T power_; - uint64_t max_iter_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_SGD_LEARNING_RATE_FUNCTORS_H_ diff --git a/app/src/main/cpp/caffe2/sgd/learning_rate_op.h b/app/src/main/cpp/caffe2/sgd/learning_rate_op.h deleted file mode 100644 index a5edab4..0000000 --- a/app/src/main/cpp/caffe2/sgd/learning_rate_op.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef CAFFE2_SGD_LEARNING_RATE_OP_H_ -#define CAFFE2_SGD_LEARNING_RATE_OP_H_ - -#include -#include -#include "caffe2/core/context.h" -#include "caffe2/core/operator.h" -#include "caffe2/sgd/learning_rate_functors.h" - -namespace caffe2 { - -template -class LearningRateOp final : public Operator { - public: - LearningRateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), functor_(nullptr), - base_lr_( - OperatorBase::template GetSingleArgument( - "base_lr", FLT_MAX)) { - CAFFE_ENFORCE_NE(base_lr_, FLT_MAX, "Base learning rate must be set."); - const string policy = OperatorBase::GetSingleArgument("policy", ""); - CAFFE_ENFORCE(policy.size(), "Must specify a learning rate policy."); - if (policy == "fixed") { - functor_.reset(new FixedLearningRate()); - } else if (policy == "step") { - int stepsize = - OperatorBase::template GetSingleArgument("stepsize", 0); - T gamma = OperatorBase::template GetSingleArgument("gamma", 0); - DCHECK_GT(stepsize, 0); - DCHECK_GT(gamma, 0); - functor_.reset(new StepLearningRate(stepsize, gamma)); - } else if (policy == "exp") { - T gamma = OperatorBase::template GetSingleArgument("gamma", 0); - DCHECK_GT(gamma, 0); - functor_.reset(new ExpLearningRate(gamma)); - } else if (policy == "inv") { - T gamma = OperatorBase::template GetSingleArgument("gamma", 0); - T power = OperatorBase::template GetSingleArgument("power", 0); - DCHECK_GT(gamma, 0); - DCHECK_GT(power, 0); - functor_.reset(new InvLearningRate(gamma, power)); - } else if (policy == "poly") { - int max_iter = OperatorBase::template GetSingleArgument("max_iter", -1); - T power = OperatorBase::template GetSingleArgument("power", 0); - DCHECK_GT(power, 0); - functor_.reset(new PolyLearningRate(power, max_iter)); - } else { - LOG(FATAL) << "Unknown learning rate policy: " << policy; - } - } - USE_OPERATOR_CONTEXT_FUNCTIONS; - - bool RunOnDevice() override { - int64_t iter = - OperatorBase::Input(0).template data()[0]; - T learning_rate = base_lr_ * (*functor_)(iter); - // Write to output. - auto* output = Output(0); - output->Resize(vector()); - context_.template Copy( - 1, &learning_rate, Output(0)->template mutable_data()); - return true; - } - - private: - unique_ptr > functor_; - T base_lr_; - -}; - -} // namespace caffe2 - -#endif // CAFFE2_SGD_LEARNING_RATE_OP_H_ diff --git a/app/src/main/cpp/caffe2/sgd/momentum_sgd_op.h b/app/src/main/cpp/caffe2/sgd/momentum_sgd_op.h deleted file mode 100644 index 86a9585..0000000 --- a/app/src/main/cpp/caffe2/sgd/momentum_sgd_op.h +++ /dev/null @@ -1,183 +0,0 @@ -#pragma once - -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -void momentum_sgd_update( - const int N, - const float* g, - const float* m, - float* ng, - float* nm, - const float* lr, - const float momentum, - const bool nesterov, - float* param, - Context* /*context*/) { - const float LR = lr[0]; - for (auto i = 0; i < N; ++i) { - if (!nesterov) { - const float adjusted_gradient = LR * g[i] + momentum * m[i]; - nm[i] = adjusted_gradient; - ng[i] = adjusted_gradient; - } else { - const float mi = m[i]; - const float mi_new = momentum * mi + LR * g[i]; - nm[i] = mi_new; - ng[i] = (1 + momentum) * mi_new - momentum * mi; - } - - if (param) { - param[i] -= ng[i]; - } - } -} - -template -class MomentumSGDOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MomentumSGDOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - momentum_(OperatorBase::GetSingleArgument("momentum", 0.0)), - nesterov_(OperatorBase::GetSingleArgument("nesterov", 0)) {} - - bool RunOnDevice() override { - // Iter live on the CPU - CAFFE_ENFORCE(OperatorBase::InputIsType>(GRAD)); - CAFFE_ENFORCE(OperatorBase::InputIsType>(MOMENTUM)); - CAFFE_ENFORCE(Input(LR).size() == 1); - CAFFE_ENFORCE(Input(GRAD).size() == Input(MOMENTUM).size()); - Output(OUTPUT_GRAD)->ResizeLike(Input(GRAD)); - Output(OUTPUT_MOMENTUM)->ResizeLike(Input(MOMENTUM)); - - momentum_sgd_update( - Input(GRAD).size(), - Input(GRAD).template data(), - Input(MOMENTUM).template data(), - Output(OUTPUT_GRAD)->template mutable_data(), - Output(OUTPUT_MOMENTUM)->template mutable_data(), - Input(LR).template data(), - momentum_, - nesterov_, - NULL, - &context_); - return true; - } - - protected: - T momentum_{0.9}; - bool nesterov_; - INPUT_TAGS(GRAD, MOMENTUM, LR); - OUTPUT_TAGS(OUTPUT_GRAD, OUTPUT_MOMENTUM); -}; - -template -class MomentumSGDUpdateOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - MomentumSGDUpdateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - momentum_(OperatorBase::GetSingleArgument("momentum", 0.0)), - nesterov_(OperatorBase::GetSingleArgument("nesterov", 0)) {} - - bool RunOnDevice() override { - // Iter live on the CPU - CAFFE_ENFORCE(OperatorBase::InputIsType>(GRAD)); - CAFFE_ENFORCE(OperatorBase::InputIsType>(MOMENTUM)); - CAFFE_ENFORCE(Input(LR).size() == 1); - CAFFE_ENFORCE(Input(GRAD).size() == Input(MOMENTUM).size()); - Output(OUTPUT_GRAD)->ResizeLike(Input(GRAD)); - Output(OUTPUT_MOMENTUM)->ResizeLike(Input(MOMENTUM)); - - momentum_sgd_update( - Input(GRAD).size(), - Input(GRAD).template data(), - Input(MOMENTUM).template data(), - Output(OUTPUT_GRAD)->template mutable_data(), - Output(OUTPUT_MOMENTUM)->template mutable_data(), - Input(LR).template data(), - momentum_, - nesterov_, - Output(OUTPUT_PARAM)->template mutable_data(), - &context_); - return true; - } - - protected: - T momentum_{0.9}; - bool nesterov_; - INPUT_TAGS(GRAD, MOMENTUM, LR, PARAM); - OUTPUT_TAGS(OUTPUT_GRAD, OUTPUT_MOMENTUM, OUTPUT_PARAM); -}; - -template -class SparseMomentumSGDUpdateOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - SparseMomentumSGDUpdateOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - momentum_(OperatorBase::GetSingleArgument("momentum", 0.0)), - nesterov_(OperatorBase::GetSingleArgument("nesterov", 0)) {} - - bool RunOnDevice() override { - // Resize [potentially] out-of-place blobs - Output(OUTPUT_GRAD)->ResizeLike(Input(GRAD)); - - // Enforce shapes - CAFFE_ENFORCE_EQ(Input(LR).size(), 1); - CAFFE_ENFORCE_EQ(Input(PARAM).size(), Input(MOMENTUM).size()); - CAFFE_ENFORCE_EQ(Input(PARAM).size_from_dim(1), - Input(GRAD).size_from_dim(Input(INDICES).ndim())); - - return DispatchHelper>::call( - this, Input(INDICES)); - } - - template - bool DoRunWithType() { - auto block_size = Input(PARAM).size() / Input(PARAM).dim(0); - auto n = Input(GRAD).size() / block_size; - - const auto* gradIn = Input(GRAD).template data(); - const auto* momentumIn = Input(MOMENTUM).template data(); - const auto* lr = Input(LR).template data(); - const auto* paramIn = Input(PARAM).template data(); - const auto* indices = Input(INDICES).template data(); - - auto* gradOut = Output(OUTPUT_GRAD)->template mutable_data(); - auto* momentumOut = Output(OUTPUT_MOMENTUM)->template mutable_data(); - auto* paramOut = Output(OUTPUT_PARAM)->template mutable_data(); - - for (auto i = 0; i < n; ++i) { - auto idx = indices[i]; - auto offsetI = i * block_size; - auto offsetIdx = idx * block_size; - - CAFFE_ENFORCE(offsetIdx + block_size <= Input(PARAM).size()); - CAFFE_ENFORCE(offsetI + block_size <= Input(GRAD).size()); - - momentum_sgd_update( - block_size, - gradIn + offsetI, - momentumIn + offsetIdx, - gradOut + offsetI, - momentumOut + offsetIdx, - lr, - momentum_, - nesterov_, - paramOut + offsetIdx, - &context_); - } - return true; - } - - protected: - T momentum_; - bool nesterov_; - INPUT_TAGS(GRAD, MOMENTUM, LR, PARAM, INDICES); - OUTPUT_TAGS(OUTPUT_GRAD, OUTPUT_MOMENTUM, OUTPUT_PARAM); -}; -} diff --git a/app/src/main/cpp/caffe2/sgd/rmsprop_op.h b/app/src/main/cpp/caffe2/sgd/rmsprop_op.h deleted file mode 100644 index e3015f5..0000000 --- a/app/src/main/cpp/caffe2/sgd/rmsprop_op.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include "caffe2/core/common_omp.h" -#include "caffe2/core/operator.h" - -namespace caffe2 { - -template -void rmsprop_update( - int N, - const float* g, - const float* ms, - const float* mom, - float* ng, - float* nms, - float* nmom, - float decay, - float momentum, - float epsilon, - const float* lr, - Context* context); - -template -class RmsPropOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - RmsPropOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - decay_(OperatorBase::GetSingleArgument("decay", 0.9f)), - momentum_(OperatorBase::GetSingleArgument("momentum", 0.0f)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-5f)) {} - bool RunOnDevice() override { - CAFFE_ENFORCE(Input(LR).size() == 1); - CAFFE_ENFORCE(Input(GRAD).size() == Input(MEAN_SQUARES).size()); - CAFFE_ENFORCE(Input(GRAD).size() == Input(OUTPUT_MOMENTUM).size()); - Output(OUTPUT_GRAD)->ResizeLike(Input(GRAD)); - Output(OUTPUT_GRAD)->ResizeLike(Input(GRAD)); - Output(OUTPUT_MEAN_SQUARES)->ResizeLike(Input(MEAN_SQUARES)); - Output(OUTPUT_MOMENTUM)->ResizeLike(Input(MOMENTUM)); - rmsprop_update( - Input(GRAD).size(), - Input(GRAD).template data(), - Input(MEAN_SQUARES).template data(), - Input(MOMENTUM).template data(), - Output(OUTPUT_GRAD)->template mutable_data(), - Output(OUTPUT_MEAN_SQUARES)->template mutable_data(), - Output(OUTPUT_MOMENTUM)->template mutable_data(), - decay_, - momentum_, - epsilon_, - Input(LR).template data(), - &context_); - return true; - } - - protected: - T decay_{0.9}; - T momentum_{0.0}; - T epsilon_{1e-8}; - INPUT_TAGS(GRAD, MEAN_SQUARES, MOMENTUM, LR); - OUTPUT_TAGS(OUTPUT_GRAD, OUTPUT_MEAN_SQUARES, OUTPUT_MOMENTUM); -}; -} diff --git a/app/src/main/cpp/caffe2/sgd/yellowfin_op.h b/app/src/main/cpp/caffe2/sgd/yellowfin_op.h deleted file mode 100644 index 173e18c..0000000 --- a/app/src/main/cpp/caffe2/sgd/yellowfin_op.h +++ /dev/null @@ -1,321 +0,0 @@ -// YellowFin: An automatic tuner for momentum SGD -// (https://arxiv.org/abs/1706.03471) -// The YellowFinOp tunes learning rate and momentum and performs momentum SGD -// steps. The learning rate and momentum are separate for any matrix of -// parameters. - -#pragma once - -#include -#include -#include "caffe2/core/operator.h" -#include "caffe2/utils/math.h" - -namespace caffe2 { - -template -class YellowFinOp final : public Operator { - public: - USE_OPERATOR_CONTEXT_FUNCTIONS; - YellowFinOp(const OperatorDef& operator_def, Workspace* ws) - : Operator(operator_def, ws), - curv_win_width_( - OperatorBase::GetSingleArgument("curv_win_width", 20)), - nesterov_(OperatorBase::GetSingleArgument("nesterov", false)), - zero_debias_( - OperatorBase::GetSingleArgument("zero_debias", true)), - epsilon_(OperatorBase::GetSingleArgument("epsilon", 1e-6f)), - beta_(OperatorBase::GetSingleArgument("beta", 0.999f)) {} - - protected: - // GetLrMu and MomentumSgdUpdate have different implementations for GPU and - // CPU. All other methods are generic. - void GetLrMu(); - void MomentumSgdUpdate(); - - void AfterApply() { - // g - MovingAverage(D_, grad_, g_avg_, g_avg_out_, g_deb_); - // g2 - math::Mul(D_, grad_, grad_, aux_vector_, &context_); - MovingAverage(D_, aux_vector_, g2_avg_, g2_avg_out_, g2_deb_); - // g_norm2 - math::Dot(D_, grad_, grad_, g_norm2_, &context_); - math::Maximum(1, epsilon_, g_norm2_, g_norm2_, &context_); - MovingAverage(1, g_norm2_, g_norm2_avg_, g_norm2_avg_out_, g_norm2_deb_); - // g_norm - math::Sqrt(1, g_norm2_, g_norm_, &context_); - MovingAverage(1, g_norm_, g_norm_avg_, g_norm_avg_out_, g_norm_deb_); - math::Maximum(1, epsilon_, g_norm_deb_, g_norm_deb_, &context_); - // Curvature range: g_norm2_min, g_norm2_max - math::CopyVector(curv_win_width_, curv_win_, curv_win_out_, &context_); - T* curv_win_cell = curv_win_out_ + (iter_ - 1) % curv_win_width_; - math::Log(1, g_norm2_, curv_win_cell, &context_); - int valid_end = std::min(curv_win_width_, iter_); - math::ReduceMin( - valid_end, curv_win_out_, g_norm2_min_, &scratch_tensor_, &context_); - math::ReduceMax( - valid_end, curv_win_out_, g_norm2_max_, &scratch_tensor_, &context_); - MovingAverage( - 1, - g_norm2_min_, - g_norm2_min_avg_, - g_norm2_min_avg_out_, - g_norm2_min_deb_); - MovingAverage( - 1, - g_norm2_max_, - g_norm2_max_avg_, - g_norm2_max_avg_out_, - g_norm2_max_deb_); - math::Exp(1, g_norm2_min_deb_, g_norm2_min_deb_, &context_); - math::Exp(1, g_norm2_max_deb_, g_norm2_max_deb_, &context_); - math::Maximum(1, epsilon_, g_norm2_min_deb_, g_norm2_min_deb_, &context_); - math::Maximum(1, epsilon_, g_norm2_max_deb_, g_norm2_max_deb_, &context_); - // Gradient variance - math::Dot(D_, g_deb_, g_deb_, aux_scalar_, &context_); - - math::Sub(1, g_norm2_deb_, aux_scalar_, variance_, &context_); - math::Maximum(1, epsilon_, variance_, variance_, &context_); - // Distance to opt - math::Div(1, g_norm_avg_out_, g_norm2_avg_out_, distance_, &context_); - MovingAverage( - 1, distance_, distance_avg_, distance_avg_out_, distance_deb_); - if (iter_ > 1) { - GetLrMu(); - } - } - - void MovingAverage( - const int N, - const T* elt, - const T* avg, - T* new_avg, - T* debias_avg) { - const T one = 1; - math::Scale(N, beta_, avg, new_avg, &context_); - math::Axpy(N, one - beta_, elt, new_avg, &context_); - math::Scale(N, debias_factor_, new_avg, debias_avg, &context_); - } - - T ZeroDebiasFactor() { - if (zero_debias_) { - const T one = 1; - return one / (one - std::pow(beta_, iter_)); - } else { - return 1; - } - } - - public: - bool RunOnDevice() override { -// Iter live on the CPU - -#define CAFFE2_YF_READ_INPUT(INPUT_NAME, VAR_NAME) \ - const auto VAR_NAME##_tensor = Input(INPUT_NAME); \ - VAR_NAME##_ = VAR_NAME##_tensor.template data(); - - CAFFE2_YF_READ_INPUT(PARAM, param) - CAFFE2_YF_READ_INPUT(MOMENT, moment) - CAFFE2_YF_READ_INPUT(LR_AVG, lr_avg) - CAFFE2_YF_READ_INPUT(MU_AVG, mu_avg) - CAFFE2_YF_READ_INPUT(CURV_WIN, curv_win) - CAFFE2_YF_READ_INPUT(G_AVG, g_avg) - CAFFE2_YF_READ_INPUT(G2_AVG, g2_avg) - CAFFE2_YF_READ_INPUT(SCALARS_MEMORY, scalars_memory) - CAFFE2_YF_READ_INPUT(GRAD, grad) -#undef CAFFE2_YF_READ_OUTPUT - - CAFFE_ENFORCE(OperatorBase::InputIsType(ITER)); - CAFFE_ENFORCE_EQ(lr_avg_tensor.size(), 1); - CAFFE_ENFORCE_EQ(mu_avg_tensor.size(), 1); - CAFFE_ENFORCE_EQ(param_tensor.ndim(), moment_tensor.ndim()); - CAFFE_ENFORCE_EQ(param_tensor.ndim(), g_avg_tensor.ndim()); - CAFFE_ENFORCE_EQ(param_tensor.ndim(), g2_avg_tensor.ndim()); - CAFFE_ENFORCE_EQ(param_tensor.ndim(), grad_tensor.ndim()); - for (int i = 0; i < param_tensor.ndim(); ++i) { - CAFFE_ENFORCE_EQ(param_tensor.dim32(i), moment_tensor.dim32(i)); - CAFFE_ENFORCE_EQ(param_tensor.dim32(i), g_avg_tensor.dim32(i)); - CAFFE_ENFORCE_EQ(param_tensor.dim32(i), g2_avg_tensor.dim32(i)); - CAFFE_ENFORCE_EQ(param_tensor.dim32(i), grad_tensor.dim32(i)); - } - - iter_ = OperatorBase::Input(ITER).template data()[0]; - - D_ = param_tensor.size(); - - // Input data - persistent memory for internal scalars - // Note: Memory for these scalars is being allocated during initialization - // of the network. If you want to add / remove a scalar, make a - // suitable change of memory size in the initialization. - const T* memory_it = scalars_memory_ - 1; - g_norm_avg_ = ++memory_it; - g_norm2_avg_ = ++memory_it; - g_norm2_min_avg_ = ++memory_it; - g_norm2_max_avg_ = ++memory_it; - distance_avg_ = ++memory_it; - -// Output data - -#define CAFFE2_YF_READ_OUTPUT(OUTPUT_NAME, VAR_NAME) \ - auto VAR_NAME##_out_tensor = Output(OUTPUT_##OUTPUT_NAME); \ - VAR_NAME##_out_tensor->ResizeLike(VAR_NAME##_tensor); \ - VAR_NAME##_out_ = VAR_NAME##_out_tensor->template mutable_data(); - - CAFFE2_YF_READ_OUTPUT(PARAM, param) - CAFFE2_YF_READ_OUTPUT(MOMENT, moment) - CAFFE2_YF_READ_OUTPUT(LR_AVG, lr_avg) - CAFFE2_YF_READ_OUTPUT(MU_AVG, mu_avg) - CAFFE2_YF_READ_OUTPUT(CURV_WIN, curv_win) - CAFFE2_YF_READ_OUTPUT(G_AVG, g_avg) - CAFFE2_YF_READ_OUTPUT(G2_AVG, g2_avg) - CAFFE2_YF_READ_OUTPUT(SCALARS_MEMORY, scalars_memory) -#undef CAFFE2_YF_READ_OUTPUT - - T* out_memory_it = scalars_memory_out_ - 1; - g_norm_avg_out_ = ++out_memory_it; - g_norm2_avg_out_ = ++out_memory_it; - g_norm2_min_avg_out_ = ++out_memory_it; - g_norm2_max_avg_out_ = ++out_memory_it; - distance_avg_out_ = ++out_memory_it; - -#define CAFFE2_YF_INIT_VECTOR(NAME) \ - NAME##_tensor_.Resize(D_); \ - NAME##_ = NAME##_tensor_.template mutable_data(); - - CAFFE2_YF_INIT_VECTOR(aux_vector) - CAFFE2_YF_INIT_VECTOR(g_deb) - CAFFE2_YF_INIT_VECTOR(g2_deb) - CAFFE2_YF_INIT_VECTOR(g_deb2) -#undef CAFFE2_YF_INIT_VECTOR - -#define CAFFE2_YF_INIT_SCALAR(NAME) \ - NAME##_tensor_.Resize(1); \ - NAME##_ = NAME##_tensor_.template mutable_data(); - - CAFFE2_YF_INIT_SCALAR(aux_scalar) - CAFFE2_YF_INIT_SCALAR(distance) - CAFFE2_YF_INIT_SCALAR(distance_deb) - CAFFE2_YF_INIT_SCALAR(g_norm) - CAFFE2_YF_INIT_SCALAR(g_norm_deb) - CAFFE2_YF_INIT_SCALAR(g_norm2) - CAFFE2_YF_INIT_SCALAR(g_norm2_max) - CAFFE2_YF_INIT_SCALAR(g_norm2_max_deb) - CAFFE2_YF_INIT_SCALAR(g_norm2_min) - CAFFE2_YF_INIT_SCALAR(g_norm2_min_deb) - CAFFE2_YF_INIT_SCALAR(g_norm2_deb) - CAFFE2_YF_INIT_SCALAR(lr) - CAFFE2_YF_INIT_SCALAR(lr_deb) - CAFFE2_YF_INIT_SCALAR(mu_deb) - CAFFE2_YF_INIT_SCALAR(mu) - CAFFE2_YF_INIT_SCALAR(variance) -#undef CAFFE2_YF_INIT_SCALAR - - debias_factor_ = ZeroDebiasFactor(); - MomentumSgdUpdate(); - AfterApply(); - return true; - } - - protected: - int curv_win_width_; - bool nesterov_; - bool zero_debias_; - - T epsilon_; - T beta_; - T debias_factor_; - - int D_; - -// Temporary memory on device, listed all variables used in calculations -#define CAFFE2_YF_DEFINE_TENSOR(NAME) \ - Tensor NAME##_tensor_; \ - T* NAME##_; - - CAFFE2_YF_DEFINE_TENSOR(aux_vector) - CAFFE2_YF_DEFINE_TENSOR(g_deb) - CAFFE2_YF_DEFINE_TENSOR(g2_deb) - CAFFE2_YF_DEFINE_TENSOR(g_deb2) - - CAFFE2_YF_DEFINE_TENSOR(aux_scalar) - CAFFE2_YF_DEFINE_TENSOR(distance) - CAFFE2_YF_DEFINE_TENSOR(distance_deb) - CAFFE2_YF_DEFINE_TENSOR(g_norm) - CAFFE2_YF_DEFINE_TENSOR(g_norm_deb) - CAFFE2_YF_DEFINE_TENSOR(g_norm2) - CAFFE2_YF_DEFINE_TENSOR(g_norm2_deb) - CAFFE2_YF_DEFINE_TENSOR(g_norm2_max) - CAFFE2_YF_DEFINE_TENSOR(g_norm2_max_deb) - CAFFE2_YF_DEFINE_TENSOR(g_norm2_min) - CAFFE2_YF_DEFINE_TENSOR(g_norm2_min_deb) - CAFFE2_YF_DEFINE_TENSOR(lr) - CAFFE2_YF_DEFINE_TENSOR(lr_deb) - CAFFE2_YF_DEFINE_TENSOR(mu) - CAFFE2_YF_DEFINE_TENSOR(mu_deb) - CAFFE2_YF_DEFINE_TENSOR(variance) - - Tensor scratch_tensor_; - -#undef CAFFE2_YF_DEFINE_TENSOR - - // Input tensors' data - const T* param_; - const T* moment_; - const T* lr_avg_; - const T* mu_avg_; - const T* curv_win_; - const T* g_avg_; - const T* g2_avg_; - const T* scalars_memory_; - const T* grad_; - int iter_; - - // Scalar data from scalars_memory_ input tensor - const T* g_norm_avg_; - const T* g_norm2_avg_; - const T* g_norm2_min_avg_; - const T* g_norm2_max_avg_; - const T* distance_avg_; - - // Output tensors' data - - T* param_out_; - T* moment_out_; - T* lr_avg_out_; - T* mu_avg_out_; - T* curv_win_out_; - T* g_avg_out_; - T* g2_avg_out_; - T* scalars_memory_out_; - - // Scalar data from scalars_memory_ output tensor - T* g_norm_avg_out_; - T* g_norm2_avg_out_; - T* g_norm2_min_avg_out_; - T* g_norm2_max_avg_out_; - T* distance_avg_out_; - - INPUT_TAGS( - PARAM, - MOMENT, - LR_AVG, - MU_AVG, - CURV_WIN, - G_AVG, - G2_AVG, - SCALARS_MEMORY, - GRAD, - ITER); - OUTPUT_TAGS( - OUTPUT_PARAM, - OUTPUT_MOMENT, - OUTPUT_LR_AVG, - OUTPUT_MU_AVG, - OUTPUT_CURV_WIN, - OUTPUT_G_AVG, - OUTPUT_G2_AVG, - OUTPUT_SCALARS_MEMORY); -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/transforms/common_subexpression_elimination.h b/app/src/main/cpp/caffe2/transforms/common_subexpression_elimination.h deleted file mode 100644 index d50d263..0000000 --- a/app/src/main/cpp/caffe2/transforms/common_subexpression_elimination.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2004-present Facebook. All Rights Reserved. - -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/core/transform.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -/** - * Common Subexpression Elimination - * - * This transforms looks for specific operators (denoted by whitelisted_ops_), - * and removes unnecessary repetition of that operator. - * - * Consider some operator of X, that reads from blob b_ written to by W. - * X_a and X_b read the output of X. However, another operator Y, is the same - * type as X, has the same arguments as X, and reads from the same input b_, - * written to by W. It's output is the same as X. Y_a, Y_b, and Y_c read from Y. - * - * Then, we can eliminate the common subexpressions X and Y, and merge them to - * Z, where X_a, X_b, Y_a, Y_b, and Y_c all read from Z. - * - * - * TODO(benz): Fix the error to not match nodes that write to external output. - */ -class CommonSubexpressionEliminationTransform : public Transform { - public: - CommonSubexpressionEliminationTransform() { - SetPatternMatchType(SORTED_WRT_EXECUTION_ORDER); - } - - protected: - bool PatternRule( - const transform::Graph& g, - const std::vector& subgraph, - int idx) override; - bool ValidatorRule( - const transform::Graph& g, - const std::vector& subgraph) override; - bool ReplaceRule(const std::vector& subgraph, transform::Graph* g_ptr) - override; - - private: - bool IsWhitelisted(string op_type) { - return whitelisted_ops_.count(op_type); - } - std::set whitelisted_ops_ = {"LearningRate", "FC"}; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/transforms/conv_to_nnpack_transform.h b/app/src/main/cpp/caffe2/transforms/conv_to_nnpack_transform.h deleted file mode 100644 index 6438b14..0000000 --- a/app/src/main/cpp/caffe2/transforms/conv_to_nnpack_transform.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/transforms/single_op_transform.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -class ConvToNNPackTransform : public SingleOpTransform { - protected: - // Specify what the op needs to be to match the pattern. - bool MatchOperator(const OperatorDef& op) override { - return ( - op.type() == "Conv" && op.device_option().device_type() == CPU && - op.engine() != "NNPACK"); - } - - // Specify how the operator should be replaced. - void ReplaceOperator(OperatorDef* op) override { - op->set_engine("NNPACK"); - } -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/transforms/pattern_net_transform.h b/app/src/main/cpp/caffe2/transforms/pattern_net_transform.h deleted file mode 100644 index 1f54ccc..0000000 --- a/app/src/main/cpp/caffe2/transforms/pattern_net_transform.h +++ /dev/null @@ -1,133 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/core/transform.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -/** - * PatternNetTransform allows you to create transforms using a simple - * interface. - * - * Simply provide a Pattern NetDef and a Replace NetDef, - * and this Transform will find subgraphs which fit the pattern net, - * and replace it with the replace net. - */ -class PatternNetTransform : public Transform { - public: - PatternNetTransform(const NetDef& pattern_net, const NetDef& replace_net) - : p_(transform::Graph(pattern_net)), r_(transform::Graph(replace_net)) { - // external input and output must match! - CAFFE_ENFORCE( - p_.external_input() == r_.external_input(), - "External inputs do not match!"); - CAFFE_ENFORCE( - p_.external_output() == r_.external_output(), - "External outputs do not match!"); - ordered_ops_ = GetPatternTraversalOrder(p_); - inverse_ops_.resize(ordered_ops_.size()); - for (int i = 0; i < ordered_ops_.size(); i++) { - inverse_ops_[ordered_ops_[i]] = i; - } - } - - void EnableArgumentMatching() { - argument_match_ = true; - } - - void DisableArgumentMatching() { - argument_match_ = false; - } - - protected: - /** - * We want to the final result of subgraph to match the PatternNet in the - * order of ordered_ops, operator by operator. - * - * [[[ ie. g.node(subgraph[i]) should match p.node(ordered_ops[i]) ]]] - * - * PatternRule for PatternNetTransform does the following: - * - * When trying to insert node idx into subgraph[p_idx], - * we need to see if the edges between index and the - * subgraph match the edges between p[ordered_ops[idx]] - * and p[ordered_ops[0]...ordered_ops[p_idx-1]]. - */ - bool PatternRule( - const transform::Graph& g, - const std::vector& subgraph, - int idx) override; - /** - * ValidatorRule for PatternNetTransform does the following: - * - * Checks if the size of subgraph and p.size() are the same. That's it! - */ - bool ValidatorRule( - const transform::Graph& g, - const std::vector& subgraph) override; - /** - * ReplaceRule for PatternNet Transform does the following: - * - * 1) Figure out edge renamings for edges going into/out of the subgraph. - * That is, for each blob in the pattern graph, what is it called in the - * matched subgraph? - * - * 2) Remove the matched subgraph. - * - * 3) Append the replace graph's operators to the graph's operators, and use - * the renamings to rename the blob names. - * - * 4) Create all the children/parent relationships within the replaced graph, - * and stitch together the inputs and outputs into the rest of the graph, - * matching the removed subgraph. - */ - bool ReplaceRule(const std::vector& subgraph, transform::Graph* g_ptr) - override; - - private: - /** - * This returns a permutation of the Pattern Net's operators. - * The permutation satisfies this property: - * - For any index i, order(i) is a neighbor of some node from - * {order(1), ..., order(i-1)}. - * - * Why is this important? Consider the following case: - * PatternNet: 0 ---> 2 <--- 1 - * - * When we have matched onto [0], and trying to add [1] to our subgraph, - * we cannot, since PatternMatch only considers neighbors of the current - * subgraph as a candidate next node. - * - * Therefore, we must present the subgraph in an order such that each node is - * a neighbor of its prefix subgraph. One ordering for the above example is - * [0, 2, 1]. - */ - std::vector GetPatternTraversalOrder(const transform::Graph& g); - - // Graph of Pattern NetDef - transform::Graph p_; - - // The Traversal Order of the Pattern Net's Operators - // This is a permutation of the numbers from {0, ..., p.size()-1} - std::vector ordered_ops_; - - // The Inverse of the Traversal Order of the Pattern Net's Operators - // That is, inverse_ops[ordered_ops[i]] == i is always true. - std::vector inverse_ops_; - - // Graph of Replace NetDef - transform::Graph r_; - - // This flag determines if the transform will match operator arguments. - bool argument_match_ = false; - - const string TransformBlobWrapper(const string& blob_name) { - return "transform/" + blob_name + "_" + caffe2::to_string(ssa_id_); - } - - int ssa_id_ = 0; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/transforms/single_op_transform.h b/app/src/main/cpp/caffe2/transforms/single_op_transform.h deleted file mode 100644 index dbc53e3..0000000 --- a/app/src/main/cpp/caffe2/transforms/single_op_transform.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include "caffe2/core/common.h" -#include "caffe2/core/transform.h" -#include "caffe2/proto/caffe2.pb.h" -#include "caffe2/utils/proto_utils.h" - -namespace caffe2 { - -/** - * Single Op Transform Base class - * - * A transform which is applied to a single node, in place. - * - * Transforms which derive from SingleOpTransform need to override: - * ReplaceOperator and MatchOperator. - */ -class SingleOpTransform : public Transform { - protected: - bool PatternRule( - const transform::Graph& g, - const std::vector& subgraph, - int idx) override; - bool ValidatorRule( - const transform::Graph& g, - const std::vector& subgraph) override; - bool ReplaceRule(const std::vector& subgraph, transform::Graph* g_ptr) - override; - - // Specify what the op needs to be to match the pattern. - virtual bool MatchOperator(const OperatorDef& op) = 0; - - // Specify how the operator should be replaced. - virtual void ReplaceOperator(OperatorDef* op) = 0; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/cast.h b/app/src/main/cpp/caffe2/utils/cast.h deleted file mode 100644 index d73641d..0000000 --- a/app/src/main/cpp/caffe2/utils/cast.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -namespace caffe2 { - -namespace cast { - -inline TensorProto_DataType GetCastDataType(const ArgumentHelper& helper, std::string arg) { - TensorProto_DataType to; - if (helper.HasSingleArgumentOfType(arg)) { -#ifndef CAFFE2_USE_LITE_PROTO - string s = helper.GetSingleArgument(arg, "float"); - std::transform(s.begin(), s.end(), s.begin(), ::toupper); - CAFFE_ENFORCE(TensorProto_DataType_Parse(s, &to), "Unknown 'to' argument: ", s); -#else - CAFFE_THROW("String cast op not supported"); -#endif - } else { - to = static_cast( - helper.GetSingleArgument(arg, TensorProto_DataType_FLOAT)); - } - return to; -} - -}; // namespace cast - -}; // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/cblas.h b/app/src/main/cpp/caffe2/utils/cblas.h deleted file mode 100644 index c91b8bf..0000000 --- a/app/src/main/cpp/caffe2/utils/cblas.h +++ /dev/null @@ -1,606 +0,0 @@ -// This is the exact cblas.h header file, placed here purely in order to get -// the enums. - -#include "caffe2/core/macros.h" - -#ifndef CBLAS_H -#ifdef CAFFE2_USE_MKL -#include -#else // CAFFE2_USE_MKL - -#ifndef CBLAS_ENUM_DEFINED_H - #define CBLAS_ENUM_DEFINED_H - enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 }; - enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113, - AtlasConj=114}; - enum CBLAS_UPLO {CblasUpper=121, CblasLower=122}; - enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132}; - enum CBLAS_SIDE {CblasLeft=141, CblasRight=142}; -#endif - -#ifndef CBLAS_ENUM_ONLY -#define CBLAS_H -#define CBLAS_INDEX int - -int cblas_errprn(int ierr, int info, char *form, ...); -void cblas_xerbla(int p, const char *rout, const char *form, ...); - -/* - * =========================================================================== - * Prototypes for level 1 BLAS functions (complex are recast as routines) - * =========================================================================== - */ -float cblas_sdsdot(const int N, const float alpha, const float *X, - const int incX, const float *Y, const int incY); -double cblas_dsdot(const int N, const float *X, const int incX, const float *Y, - const int incY); -float cblas_sdot(const int N, const float *X, const int incX, - const float *Y, const int incY); -double cblas_ddot(const int N, const double *X, const int incX, - const double *Y, const int incY); -/* - * Functions having prefixes Z and C only - */ -void cblas_cdotu_sub(const int N, const void *X, const int incX, - const void *Y, const int incY, void *dotu); -void cblas_cdotc_sub(const int N, const void *X, const int incX, - const void *Y, const int incY, void *dotc); - -void cblas_zdotu_sub(const int N, const void *X, const int incX, - const void *Y, const int incY, void *dotu); -void cblas_zdotc_sub(const int N, const void *X, const int incX, - const void *Y, const int incY, void *dotc); - - -/* - * Functions having prefixes S D SC DZ - */ -float cblas_snrm2(const int N, const float *X, const int incX); -float cblas_sasum(const int N, const float *X, const int incX); - -double cblas_dnrm2(const int N, const double *X, const int incX); -double cblas_dasum(const int N, const double *X, const int incX); - -float cblas_scnrm2(const int N, const void *X, const int incX); -float cblas_scasum(const int N, const void *X, const int incX); - -double cblas_dznrm2(const int N, const void *X, const int incX); -double cblas_dzasum(const int N, const void *X, const int incX); - - -/* - * Functions having standard 4 prefixes (S D C Z) - */ -CBLAS_INDEX cblas_isamax(const int N, const float *X, const int incX); -CBLAS_INDEX cblas_idamax(const int N, const double *X, const int incX); -CBLAS_INDEX cblas_icamax(const int N, const void *X, const int incX); -CBLAS_INDEX cblas_izamax(const int N, const void *X, const int incX); - -/* - * =========================================================================== - * Prototypes for level 1 BLAS routines - * =========================================================================== - */ - -/* - * Routines with standard 4 prefixes (s, d, c, z) - */ -void cblas_sswap(const int N, float *X, const int incX, - float *Y, const int incY); -void cblas_scopy(const int N, const float *X, const int incX, - float *Y, const int incY); -void cblas_saxpy(const int N, const float alpha, const float *X, - const int incX, float *Y, const int incY); -void catlas_saxpby(const int N, const float alpha, const float *X, - const int incX, const float beta, float *Y, const int incY); -void catlas_sset - (const int N, const float alpha, float *X, const int incX); - -void cblas_dswap(const int N, double *X, const int incX, - double *Y, const int incY); -void cblas_dcopy(const int N, const double *X, const int incX, - double *Y, const int incY); -void cblas_daxpy(const int N, const double alpha, const double *X, - const int incX, double *Y, const int incY); -void catlas_daxpby(const int N, const double alpha, const double *X, - const int incX, const double beta, double *Y, const int incY); -void catlas_dset - (const int N, const double alpha, double *X, const int incX); - -void cblas_cswap(const int N, void *X, const int incX, - void *Y, const int incY); -void cblas_ccopy(const int N, const void *X, const int incX, - void *Y, const int incY); -void cblas_caxpy(const int N, const void *alpha, const void *X, - const int incX, void *Y, const int incY); -void catlas_caxpby(const int N, const void *alpha, const void *X, - const int incX, const void *beta, void *Y, const int incY); -void catlas_cset - (const int N, const void *alpha, void *X, const int incX); - -void cblas_zswap(const int N, void *X, const int incX, - void *Y, const int incY); -void cblas_zcopy(const int N, const void *X, const int incX, - void *Y, const int incY); -void cblas_zaxpy(const int N, const void *alpha, const void *X, - const int incX, void *Y, const int incY); -void catlas_zaxpby(const int N, const void *alpha, const void *X, - const int incX, const void *beta, void *Y, const int incY); -void catlas_zset - (const int N, const void *alpha, void *X, const int incX); - - -/* - * Routines with S and D prefix only - */ -void cblas_srotg(float *a, float *b, float *c, float *s); -void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P); -void cblas_srot(const int N, float *X, const int incX, - float *Y, const int incY, const float c, const float s); -void cblas_srotm(const int N, float *X, const int incX, - float *Y, const int incY, const float *P); - -void cblas_drotg(double *a, double *b, double *c, double *s); -void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P); -void cblas_drot(const int N, double *X, const int incX, - double *Y, const int incY, const double c, const double s); -void cblas_drotm(const int N, double *X, const int incX, - double *Y, const int incY, const double *P); - - -/* - * Routines with S D C Z CS and ZD prefixes - */ -void cblas_sscal(const int N, const float alpha, float *X, const int incX); -void cblas_dscal(const int N, const double alpha, double *X, const int incX); -void cblas_cscal(const int N, const void *alpha, void *X, const int incX); -void cblas_zscal(const int N, const void *alpha, void *X, const int incX); -void cblas_csscal(const int N, const float alpha, void *X, const int incX); -void cblas_zdscal(const int N, const double alpha, void *X, const int incX); - -/* - * Extra reference routines provided by ATLAS, but not mandated by the standard - */ -void cblas_crotg(void *a, void *b, void *c, void *s); -void cblas_zrotg(void *a, void *b, void *c, void *s); -void cblas_csrot(const int N, void *X, const int incX, void *Y, const int incY, - const float c, const float s); -void cblas_zdrot(const int N, void *X, const int incX, void *Y, const int incY, - const double c, const double s); - -/* - * =========================================================================== - * Prototypes for level 2 BLAS - * =========================================================================== - */ - -/* - * Routines with standard 4 prefixes (S, D, C, Z) - */ -void cblas_sgemv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const float alpha, const float *A, const int lda, - const float *X, const int incX, const float beta, - float *Y, const int incY); -void cblas_sgbmv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const int KL, const int KU, const float alpha, - const float *A, const int lda, const float *X, - const int incX, const float beta, float *Y, const int incY); -void cblas_strmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const float *A, const int lda, - float *X, const int incX); -void cblas_stbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const float *A, const int lda, - float *X, const int incX); -void cblas_stpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const float *Ap, float *X, const int incX); -void cblas_strsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const float *A, const int lda, float *X, - const int incX); -void cblas_stbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const float *A, const int lda, - float *X, const int incX); -void cblas_stpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const float *Ap, float *X, const int incX); - -void cblas_dgemv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const double alpha, const double *A, const int lda, - const double *X, const int incX, const double beta, - double *Y, const int incY); -void cblas_dgbmv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const int KL, const int KU, const double alpha, - const double *A, const int lda, const double *X, - const int incX, const double beta, double *Y, const int incY); -void cblas_dtrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const double *A, const int lda, - double *X, const int incX); -void cblas_dtbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const double *A, const int lda, - double *X, const int incX); -void cblas_dtpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const double *Ap, double *X, const int incX); -void cblas_dtrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const double *A, const int lda, double *X, - const int incX); -void cblas_dtbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const double *A, const int lda, - double *X, const int incX); -void cblas_dtpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const double *Ap, double *X, const int incX); - -void cblas_cgemv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *X, const int incX, const void *beta, - void *Y, const int incY); -void cblas_cgbmv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const int KL, const int KU, const void *alpha, - const void *A, const int lda, const void *X, - const int incX, const void *beta, void *Y, const int incY); -void cblas_ctrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *A, const int lda, - void *X, const int incX); -void cblas_ctbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const void *A, const int lda, - void *X, const int incX); -void cblas_ctpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *Ap, void *X, const int incX); -void cblas_ctrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *A, const int lda, void *X, - const int incX); -void cblas_ctbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const void *A, const int lda, - void *X, const int incX); -void cblas_ctpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *Ap, void *X, const int incX); - -void cblas_zgemv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *X, const int incX, const void *beta, - void *Y, const int incY); -void cblas_zgbmv(const enum CBLAS_ORDER Order, - const enum CBLAS_TRANSPOSE TransA, const int M, const int N, - const int KL, const int KU, const void *alpha, - const void *A, const int lda, const void *X, - const int incX, const void *beta, void *Y, const int incY); -void cblas_ztrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *A, const int lda, - void *X, const int incX); -void cblas_ztbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const void *A, const int lda, - void *X, const int incX); -void cblas_ztpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *Ap, void *X, const int incX); -void cblas_ztrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *A, const int lda, void *X, - const int incX); -void cblas_ztbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const int K, const void *A, const int lda, - void *X, const int incX); -void cblas_ztpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag, - const int N, const void *Ap, void *X, const int incX); - - -/* - * Routines with S and D prefixes only - */ -void cblas_ssymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *A, - const int lda, const float *X, const int incX, - const float beta, float *Y, const int incY); -void cblas_ssbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const int K, const float alpha, const float *A, - const int lda, const float *X, const int incX, - const float beta, float *Y, const int incY); -void cblas_sspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *Ap, - const float *X, const int incX, - const float beta, float *Y, const int incY); -void cblas_sger(const enum CBLAS_ORDER Order, const int M, const int N, - const float alpha, const float *X, const int incX, - const float *Y, const int incY, float *A, const int lda); -void cblas_ssyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *X, - const int incX, float *A, const int lda); -void cblas_sspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *X, - const int incX, float *Ap); -void cblas_ssyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *X, - const int incX, const float *Y, const int incY, float *A, - const int lda); -void cblas_sspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const float *X, - const int incX, const float *Y, const int incY, float *A); - -void cblas_dsymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *A, - const int lda, const double *X, const int incX, - const double beta, double *Y, const int incY); -void cblas_dsbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const int K, const double alpha, const double *A, - const int lda, const double *X, const int incX, - const double beta, double *Y, const int incY); -void cblas_dspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *Ap, - const double *X, const int incX, - const double beta, double *Y, const int incY); -void cblas_dger(const enum CBLAS_ORDER Order, const int M, const int N, - const double alpha, const double *X, const int incX, - const double *Y, const int incY, double *A, const int lda); -void cblas_dsyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *X, - const int incX, double *A, const int lda); -void cblas_dspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *X, - const int incX, double *Ap); -void cblas_dsyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *X, - const int incX, const double *Y, const int incY, double *A, - const int lda); -void cblas_dspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const double *X, - const int incX, const double *Y, const int incY, double *A); - - -/* - * Routines with C and Z prefixes only - */ -void cblas_chemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const void *alpha, const void *A, - const int lda, const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_chbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const int K, const void *alpha, const void *A, - const int lda, const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_chpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const void *alpha, const void *Ap, - const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_cgeru(const enum CBLAS_ORDER Order, const int M, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_cgerc(const enum CBLAS_ORDER Order, const int M, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_cher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const void *X, const int incX, - void *A, const int lda); -void cblas_chpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const float alpha, const void *X, - const int incX, void *A); -void cblas_cher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_chpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *Ap); - -void cblas_zhemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const void *alpha, const void *A, - const int lda, const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_zhbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const int K, const void *alpha, const void *A, - const int lda, const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_zhpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const void *alpha, const void *Ap, - const void *X, const int incX, - const void *beta, void *Y, const int incY); -void cblas_zgeru(const enum CBLAS_ORDER Order, const int M, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_zgerc(const enum CBLAS_ORDER Order, const int M, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_zher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const void *X, const int incX, - void *A, const int lda); -void cblas_zhpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const int N, const double alpha, const void *X, - const int incX, void *A); -void cblas_zher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *A, const int lda); -void cblas_zhpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N, - const void *alpha, const void *X, const int incX, - const void *Y, const int incY, void *Ap); - -/* - * =========================================================================== - * Prototypes for level 3 BLAS - * =========================================================================== - */ - -/* - * Routines with standard 4 prefixes (S, D, C, Z) - */ -void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const float alpha, const float *A, - const int lda, const float *B, const int ldb, - const float beta, float *C, const int ldc); -void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const float alpha, const float *A, const int lda, - const float *B, const int ldb, const float beta, - float *C, const int ldc); -void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const float alpha, const float *A, const int lda, - const float beta, float *C, const int ldc); -void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const float alpha, const float *A, const int lda, - const float *B, const int ldb, const float beta, - float *C, const int ldc); -void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const float alpha, const float *A, const int lda, - float *B, const int ldb); -void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const float alpha, const float *A, const int lda, - float *B, const int ldb); - -void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const double alpha, const double *A, - const int lda, const double *B, const int ldb, - const double beta, double *C, const int ldc); -void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const double alpha, const double *A, const int lda, - const double *B, const int ldb, const double beta, - double *C, const int ldc); -void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const double alpha, const double *A, const int lda, - const double beta, double *C, const int ldc); -void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const double alpha, const double *A, const int lda, - const double *B, const int ldb, const double beta, - double *C, const int ldc); -void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const double alpha, const double *A, const int lda, - double *B, const int ldb); -void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const double alpha, const double *A, const int lda, - double *B, const int ldb); - -void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const void *alpha, const void *A, - const int lda, const void *B, const int ldb, - const void *beta, void *C, const int ldc); -void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *beta, void *C, const int ldc); -void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const void *alpha, const void *A, const int lda, - void *B, const int ldb); -void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const void *alpha, const void *A, const int lda, - void *B, const int ldb); - -void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const void *alpha, const void *A, - const int lda, const void *B, const int ldb, - const void *beta, void *C, const int ldc); -void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *beta, void *C, const int ldc); -void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const void *alpha, const void *A, const int lda, - void *B, const int ldb); -void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA, - const enum CBLAS_DIAG Diag, const int M, const int N, - const void *alpha, const void *A, const int lda, - void *B, const int ldb); - - -/* - * Routines with prefixes C and Z only - */ -void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const float alpha, const void *A, const int lda, - const float beta, void *C, const int ldc); -void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const float beta, - void *C, const int ldc); -void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side, - const enum CBLAS_UPLO Uplo, const int M, const int N, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const void *beta, - void *C, const int ldc); -void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const double alpha, const void *A, const int lda, - const double beta, void *C, const int ldc); -void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, - const enum CBLAS_TRANSPOSE Trans, const int N, const int K, - const void *alpha, const void *A, const int lda, - const void *B, const int ldb, const double beta, - void *C, const int ldc); - -int cblas_errprn(int ierr, int info, char *form, ...); - -#endif /* end #ifdef CBLAS_ENUM_ONLY */ -#endif // CAFFE2_USE_MKL -#endif diff --git a/app/src/main/cpp/caffe2/utils/conversions.h b/app/src/main/cpp/caffe2/utils/conversions.h deleted file mode 100644 index 190adae..0000000 --- a/app/src/main/cpp/caffe2/utils/conversions.h +++ /dev/null @@ -1,229 +0,0 @@ -#pragma once - -#include - -#ifdef __CUDA_ARCH__ -// Proxy for including cuda_fp16.h, because common_gpu.h -// has necessary diagnostic guards. -#include -#endif - -#ifdef __CUDA_ARCH__ -#define CONVERSIONS_DECL __host__ __device__ inline -#else -#define CONVERSIONS_DECL inline -#endif - -namespace caffe2 { - -namespace convert { - -namespace { -inline float16 cpu_float2half_rn(float f) { - float16 ret; - - static_assert( - sizeof(unsigned int) == sizeof(float), - "Programming error sizeof(unsigned int) != sizeof(float)"); - - unsigned* xp = reinterpret_cast(&f); - unsigned x = *xp; - unsigned u = (x & 0x7fffffff), remainder, shift, lsb, lsb_s1, lsb_m1; - unsigned sign, exponent, mantissa; - - // Get rid of +NaN/-NaN case first. - if (u > 0x7f800000) { - ret.x = 0x7fffU; - return ret; - } - - sign = ((x >> 16) & 0x8000); - - // Get rid of +Inf/-Inf, +0/-0. - if (u > 0x477fefff) { - ret.x = sign | 0x7c00U; - return ret; - } - if (u < 0x33000001) { - ret.x = (sign | 0x0000); - return ret; - } - - exponent = ((u >> 23) & 0xff); - mantissa = (u & 0x7fffff); - - if (exponent > 0x70) { - shift = 13; - exponent -= 0x70; - } else { - shift = 0x7e - exponent; - exponent = 0; - mantissa |= 0x800000; - } - lsb = (1 << shift); - lsb_s1 = (lsb >> 1); - lsb_m1 = (lsb - 1); - - // Round to nearest even. - remainder = (mantissa & lsb_m1); - mantissa >>= shift; - if (remainder > lsb_s1 || (remainder == lsb_s1 && (mantissa & 0x1))) { - ++mantissa; - if (!(mantissa & 0x3ff)) { - ++exponent; - mantissa = 0; - } - } - - ret.x = (sign | (exponent << 10) | mantissa); - - return ret; -} - -inline float cpu_half2float(float16 h) { - unsigned sign = ((h.x >> 15) & 1); - unsigned exponent = ((h.x >> 10) & 0x1f); - unsigned mantissa = ((h.x & 0x3ff) << 13); - - if (exponent == 0x1f) { /* NaN or Inf */ - mantissa = (mantissa ? (sign = 0, 0x7fffff) : 0); - exponent = 0xff; - } else if (!exponent) { /* Denorm or Zero */ - if (mantissa) { - unsigned int msb; - exponent = 0x71; - do { - msb = (mantissa & 0x400000); - mantissa <<= 1; /* normalize */ - --exponent; - } while (!msb); - mantissa &= 0x7fffff; /* 1.mantissa is implicit */ - } - } else { - exponent += 0x70; - } - - unsigned i = ((sign << 31) | (exponent << 23) | mantissa); - float ret; - memcpy(&ret, &i, sizeof(i)); - return ret; -} - -}; // anonymous - -#if __CUDACC__ - -#if CUDA_VERSION >= 9000 -CONVERSIONS_DECL float16 halfToFloat16(half x) { -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic push -#endif -#pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ - float16 r = *reinterpret_cast(&x); -#ifdef __GNUC__ -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) -#pragma GCC diagnostic pop -#endif -#endif // __GNUC__ - return r; -} - -inline half float16ToHalf(const float16 x) { - __half_raw hr; - hr.x = x.x; - half r(hr); - return r; -} - -inline half floatToHalf(const float x) { - float16 xh = cpu_float2half_rn(x); - return float16ToHalf(xh); -} - -#else -inline float16 halfToFloat16(__half x) { - float16 r; - r.x = x.x; - return r; -} - -inline __half float16ToHalf(const float16 x) { - __half r; - r.x = x.x; - return r; -} - -inline half floatToHalf(const float x) { - float16 xh = cpu_float2half_rn(x); - return float16ToHalf(xh); -} -#endif // CUDA_VERSION - -#endif // __CUDACC__ - -// general version: defer to static_cast -template -CONVERSIONS_DECL OUT To(const IN in) { - return static_cast(in); -} - -// explicit for fp16 -template <> -CONVERSIONS_DECL float16 To(const float in) { -#if __CUDA_ARCH__ - // hacky interface between C2 fp16 and CUDA -#if CUDA_VERSION >= 9000 - half rh = static_cast(in); - return halfToFloat16(rh); -#else - float16 ret; - ret.x = __float2half(in).x; - return ret; -#endif // CUDA_VERSION >= 9000 -#else - return cpu_float2half_rn(in); -#endif -} - -template <> -CONVERSIONS_DECL float To(const float16 in) { -#if __CUDA_ARCH__ -#if CUDA_VERSION >= 9000 - __half_raw tmp; -#else - __half tmp; -#endif - tmp.x = in.x; - return __half2float(tmp); -#else - return cpu_half2float(in); -#endif -}; - -template <> -CONVERSIONS_DECL float To(const float in) { - return in; -} - -template -CONVERSIONS_DECL OUT Get(IN x) { - return static_cast(x); -} - -template <> -CONVERSIONS_DECL float Get(float16 x) { - return To(x); -} - -template <> -CONVERSIONS_DECL float16 Get(float x) { - return To(x); -} - -}; // namespace convert - -}; // namespace caffe2 - -#undef CONVERSIONS_DECL diff --git a/app/src/main/cpp/caffe2/utils/cpu_neon.h b/app/src/main/cpp/caffe2/utils/cpu_neon.h deleted file mode 100644 index 3adcc43..0000000 --- a/app/src/main/cpp/caffe2/utils/cpu_neon.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef CAFFE2_UTILS_CPU_NEON_H_ -#define CAFFE2_UTILS_CPU_NEON_H_ - -// Provides a variety of ARM NEON-specific utility functions -#ifdef __ARM_NEON__ -#include - -namespace caffe2 { - -template -inline bool isPointerAligned(T* p, size_t align) { - return (reinterpret_cast(p) % align == 0); -} - -inline float32x4_t vert_sum_f32(float32x4_t v0, - float32x4_t v1, - float32x4_t v2, - float32x4_t v3) { - v0 = vaddq_f32(v0, v1); - v2 = vaddq_f32(v2, v3); - return vaddq_f32(v0, v2); -} - -inline float horizontal_sum_f32(float32x4_t v0, - float32x4_t v1, - float32x4_t v2, - float32x4_t v3) { - v0 = vert_sum_f32(v0, v1, v2, v3); - float32x2_t v = vadd_f32(vget_high_f32(v0), vget_low_f32(v0)); - return vget_lane_f32(vpadd_f32(v, v), 0); -} - -// Load/store functions that assume alignment - -inline float32x4_t vld1q_f32_aligned(const float* p) { - return vld1q_f32((const float*) - __builtin_assume_aligned(p, sizeof(float32x4_t))); -} - -inline void vst1q_f32_aligned(float* p, float32x4_t v) { - vst1q_f32((float*) __builtin_assume_aligned(p, sizeof(float32x4_t)), v); -} - -inline void vst4_u8_aligned(uint8_t* p, uint8x8x4_t v) { - vst4_u8((uint8_t*) - __builtin_assume_aligned(p, sizeof(uint8x8x4_t)), v); -} - -} // namespace caffe2 - -#endif // __ARM_NEON__ - -#endif // CAFFE2_UTILS_CPU_NEON_H_ diff --git a/app/src/main/cpp/caffe2/utils/cpuid.h b/app/src/main/cpp/caffe2/utils/cpuid.h deleted file mode 100644 index 59b85c9..0000000 --- a/app/src/main/cpp/caffe2/utils/cpuid.h +++ /dev/null @@ -1,141 +0,0 @@ -#pragma once - -#include - -#ifdef _MSC_VER -#include -#endif - -namespace caffe2 { - -class CpuId; - -const CpuId& GetCpuId(); - -/////////////////////////////////////////////////////////////////////////////// -// Implementation of CpuId that is borrowed from folly. -/////////////////////////////////////////////////////////////////////////////// - -/** - * Identification of an Intel CPU. - * Supports CPUID feature flags (EAX=1) and extended features (EAX=7, ECX=0). - * Values from - * http://www.intel.com/content/www/us/en/processors/processor-identification-cpuid-instruction-note.html - */ -class CpuId { - public: - CpuId(); - -#define X(name, r, bit) \ - inline bool name() const { \ - return ((r) & (1U << bit)) != 0; \ - } - -// cpuid(1): Processor Info and Feature Bits. -#define C(name, bit) X(name, f1c_, bit) - C(sse3, 0) - C(pclmuldq, 1) - C(dtes64, 2) - C(monitor, 3) - C(dscpl, 4) - C(vmx, 5) - C(smx, 6) - C(eist, 7) - C(tm2, 8) - C(ssse3, 9) - C(cnxtid, 10) - C(fma, 12) - C(cx16, 13) - C(xtpr, 14) - C(pdcm, 15) - C(pcid, 17) - C(dca, 18) - C(sse41, 19) - C(sse42, 20) - C(x2apic, 21) - C(movbe, 22) - C(popcnt, 23) - C(tscdeadline, 24) - C(aes, 25) - C(xsave, 26) - C(osxsave, 27) - C(avx, 28) - C(f16c, 29) - C(rdrand, 30) -#undef C - -#define D(name, bit) X(name, f1d_, bit) - D(fpu, 0) - D(vme, 1) - D(de, 2) - D(pse, 3) - D(tsc, 4) - D(msr, 5) - D(pae, 6) - D(mce, 7) - D(cx8, 8) - D(apic, 9) - D(sep, 11) - D(mtrr, 12) - D(pge, 13) - D(mca, 14) - D(cmov, 15) - D(pat, 16) - D(pse36, 17) - D(psn, 18) - D(clfsh, 19) - D(ds, 21) - D(acpi, 22) - D(mmx, 23) - D(fxsr, 24) - D(sse, 25) - D(sse2, 26) - D(ss, 27) - D(htt, 28) - D(tm, 29) - D(pbe, 31) -#undef D - -// cpuid(7): Extended Features. -#define B(name, bit) X(name, f7b_, bit) - B(bmi1, 3) - B(hle, 4) - B(avx2, 5) - B(smep, 7) - B(bmi2, 8) - B(erms, 9) - B(invpcid, 10) - B(rtm, 11) - B(mpx, 14) - B(avx512f, 16) - B(avx512dq, 17) - B(rdseed, 18) - B(adx, 19) - B(smap, 20) - B(avx512ifma, 21) - B(pcommit, 22) - B(clflushopt, 23) - B(clwb, 24) - B(avx512pf, 26) - B(avx512er, 27) - B(avx512cd, 28) - B(sha, 29) - B(avx512bw, 30) - B(avx512vl, 31) -#undef B - -#define E(name, bit) X(name, f7c_, bit) - E(prefetchwt1, 0) - E(avx512vbmi, 1) -#undef C - -#undef X - - private: - static uint32_t f1c_; - static uint32_t f1d_; - static uint32_t f7b_; - static uint32_t f7c_; -}; - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/fixed_divisor.h b/app/src/main/cpp/caffe2/utils/fixed_divisor.h deleted file mode 100644 index 8d1be8d..0000000 --- a/app/src/main/cpp/caffe2/utils/fixed_divisor.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef CAFFE2_UTILS_FIXED_DIVISOR_H_ -#define CAFFE2_UTILS_FIXED_DIVISOR_H_ - -#include -#include - -namespace caffe2 { - -// Utility class for quickly calculating quotients and remainders for -// a known integer divisor -template -class FixedDivisor { -}; - -// Works for any positive divisor, 1 to INT_MAX. One 64-bit -// multiplication and one 64-bit shift is used to calculate the -// result. -template <> -class FixedDivisor { - public: - FixedDivisor(int32_t d) : d_(d) { - calcSignedMagic(); - } - - uint64_t getMagic() const { - return magic_; - } - - int getShift() const { - return shift_; - } - - /// Calculates `q = n / d`. - inline int32_t div(int32_t n) const { - // In lieu of a mulhi instruction being available, perform the - // work in uint64 - uint64_t mul64 = magic_ * (uint64_t) n; - return (int32_t) (mul64 >> shift_); - } - - /// Calculates `r = n % d`. - inline int32_t mod(int32_t n) const { - return n - d_ * div(n); - } - - /// Calculates `q = n / d` and `r = n % d` together. - inline void divMod(int32_t n, int32_t& q, int32_t& r) const { - const int32_t quotient = div(n); - q = quotient; - r = n - d_ * quotient; - } - - private: - /** - Calculates magic multiplicative value and shift amount for - calculating `q = n / d` for signed 32-bit integers. - Implementation taken from Hacker's Delight section 10. - */ - void calcSignedMagic() { - if (d_ == 1) { - magic_ = UINT64_C(0x1) << 32; - shift_ = 32; - return; - } - - const uint32_t two31 = UINT32_C(0x80000000); - uint32_t ad = std::abs(d_); - uint32_t t = two31 + ((uint32_t) d_ >> 31); - uint32_t anc = t - 1 - t % ad; // Absolute value of nc. - uint32_t p = 31; // Init. p. - uint32_t q1 = two31 / anc; // Init. q1 = 2**p/|nc|. - uint32_t r1 = two31 - q1 * anc; // Init. r1 = rem(2**p, |nc|). - uint32_t q2 = two31 / ad; // Init. q2 = 2**p/|d|. - uint32_t r2 = two31 - q2 * ad; // Init. r2 = rem(2**p, |d|). - uint32_t delta = 0; - - do { - p = p + 1; - q1 = 2 * q1; // Update q1 = 2**p/|nc|. - r1 = 2 * r1; // Update r1 = rem(2**p, |nc|). - - if (r1 >= anc) { // (Must be an unsigned - q1 = q1 + 1; // comparison here). - r1 = r1 - anc; - } - - q2 = 2 * q2; // Update q2 = 2**p/|d|. - r2 = 2 * r2; // Update r2 = rem(2**p, |d|). - - if (r2 >= ad) { // (Must be an unsigned - q2 = q2 + 1; // comparison here). - r2 = r2 - ad; - } - - delta = ad - r2; - } while (q1 < delta || (q1 == delta && r1 == 0)); - - int32_t magic = q2 + 1; - if (d_ < 0) { - magic = -magic; - } - shift_ = p; - magic_ = (uint64_t) (uint32_t) magic; - } - - int32_t d_; - uint64_t magic_; - int shift_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_UTILS_FIXED_DIVISOR_H_ diff --git a/app/src/main/cpp/caffe2/utils/math-detail.h b/app/src/main/cpp/caffe2/utils/math-detail.h deleted file mode 100644 index 5630729..0000000 --- a/app/src/main/cpp/caffe2/utils/math-detail.h +++ /dev/null @@ -1,90 +0,0 @@ -#ifndef CAFFE2_UTILS_MATH_DETAIL_H_ -#define CAFFE2_UTILS_MATH_DETAIL_H_ -namespace caffe2 { - -class CPUContext; - -namespace math { -namespace detail { - -// proxy to a class because of partial specialization limitations for functions - -template -struct ScaleImpl { - inline void operator()( - const int N, - const float alpha, - const T* x, - T* y, - Context* context) { - Scale(N, alpha, x, y, context); - } -}; - -// Put light-weight implementations in .h file to enable inlining -template -struct ScaleImpl { - inline void operator()( - const int N, - const float alpha, - const T* x, - T* y, - CPUContext* /*context*/) { - DCHECK_EQ(N, 1); - *y = *x * alpha; - } -}; - -template -struct AxpyImpl { - inline void operator()( - const int N, - const float alpha, - const T* x, - T* y, - Context* context) { - Axpy(N, alpha, x, y, context); - } -}; - -// Put light-weight implementations in .h file to enable inlining -template -struct AxpyImpl { - inline void operator()( - const int N, - const float alpha, - const T* x, - T* y, - CPUContext* /*context*/) { - DCHECK_EQ(N, 1); - *y += *x * alpha; - } -}; - - -} // namespace detail - -template -inline void ScaleFixedSize( - const int N, - const float alpha, - const T* x, - T* y, - Context* context) { - detail::ScaleImpl()(N, alpha, x, y, context); -} - -template -inline void AxpyFixedSize( - const int N, - const float alpha, - const T* x, - T* y, - Context* context) { - detail::AxpyImpl()(N, alpha, x, y, context); -} - -} // namespace math -} // namespace caffe2 - -#endif // CAFFE2_UTILS_MATH_DETAIL_H_ diff --git a/app/src/main/cpp/caffe2/utils/math.h b/app/src/main/cpp/caffe2/utils/math.h deleted file mode 100644 index 0576b18..0000000 --- a/app/src/main/cpp/caffe2/utils/math.h +++ /dev/null @@ -1,479 +0,0 @@ -#ifndef CAFFE2_UTILS_MATH_H_ -#define CAFFE2_UTILS_MATH_H_ -// This is a simple translation from the old Caffe math interfaces. We aim to -// still keep it simple, so all platforms would be able to support it fairly -// easily. - -// We include the cblas header here so that we can obtain the macros from cblas. -extern "C" { -#include "caffe2/utils/cblas.h" -} - -#ifdef CAFFE2_USE_ACCELERATE -#include -#endif // CAFFE2_USE_ACCELERATE - -#include "caffe2/core/common.h" -#include "caffe2/core/types.h" - -#ifndef __CUDACC__ -#include "Eigen/Core" -#include "Eigen/Dense" -#endif - -namespace caffe2 { - -template -class Tensor; - -// An empty class as a placeholder for a math function that has no specific -// engine specified. -class DefaultEngine {}; - -#ifndef __CUDACC__ -// Common Eigen types that we will often use -template -using EigenMatrixMap = - Eigen::Map >; -template -using EigenArrayMap = - Eigen::Map >; -template -using EigenVectorMap = Eigen::Map >; -template -using EigenVectorArrayMap = Eigen::Map >; -template -using ConstEigenMatrixMap = - Eigen::Map >; -template -using ConstEigenArrayMap = - Eigen::Map >; -template -using ConstEigenVectorMap = - Eigen::Map >; -template -using ConstEigenVectorArrayMap = - Eigen::Map >; -#endif - -namespace math { - -template -void Exp(const int N, const T* x, T* y, Context* context); -template -void Log(const int N, const T* x, T* y, Context* context); -template -void Cos(const int N, const T* x, T* y, Context* context); -template -void Sin(const int N, const T* x, T* y, Context* context); -template -void SinCos(const int N, const T* x, T* ys, T* yc, Context* context); -template -void Abs(const int N, const T* x, T* y, Context* context); -template -void Sqrt(const int N, const T* x, T* y, Context* context); -template -void InvSqrt(const int N, const T* x, T* y, Context* context); -template -void Sqr(const int N, const T* x, T* y, Context* context); - -template -void Not(const int N, const T* x, T* y, Context* context); - -template -void Powx(const int N, const T* a, const T b, T* y, Context* context); - -#define CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(name) \ - template \ - void name(const int N, const T* a, const T* b, bool* y, Context* context); \ - template \ - void name##ToRow( \ - const int M, \ - const int N, \ - const T* a, \ - const T* b, \ - bool* y, \ - Context* context); - -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(LT); -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(LE); -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(GT); -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(GE); - -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(And); -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(Or); -CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT(Xor); - -#undef CAFFE2_DECLARE_BINARY_OP_BINARY_RESULT - -#define CAFFE2_DECLARE_BINARY_OP(name) \ - template \ - void name(const int N, const T* a, const T* b, T* y, Context* context); \ - template \ - void name##ToRow( \ - const int M, \ - const int N, \ - const T* a, \ - const T* b, \ - T* y, \ - Context* context); \ - template \ - void name##ToRow( \ - const int M, const int N, const T* x, T* y, Context* context); \ - template \ - void name##ToCol( \ - const int M, const int N, const T* x, T* y, Context* context); - -CAFFE2_DECLARE_BINARY_OP(Add); -CAFFE2_DECLARE_BINARY_OP(Sub); -CAFFE2_DECLARE_BINARY_OP(Mul); -CAFFE2_DECLARE_BINARY_OP(Div); - -#undef CAFFE2_DECLARE_BINARY_OP - -template -void ReduceMin( - const int N, - const T* x, - T* y, - Tensor* scratch_ptr, - Context* context); -template -void ReduceMax( - const int N, - const T* x, - T* y, - Tensor* scratch_ptr, - Context* context); - -// Adds batch sub-tensors elementwise to output. Stripe is the stripe length -// and N is the number of elements to add (size of Y). -template -void AddStripedBatch( - const int N, - const T* first, - T* y, - const int stripe, - const int batch, - Context* context); - -// Compute the row-wise max of a N*D matrix X, and write it to a N -// dimensional vector y. -template -void RowwiseMax(const int N, const int D, const T* x, T* y, - Context* context); - -// Compute the column-wise max of a N*D matrix X, and write it to a D -// dimensional vector y. -template -void ColwiseMax(const int N, const int D, const T* x, T* y, - Context* context); - -// Elemwise maximum of vector x and vector y. z[i] = max(x[i], y[i]) -template -void ElemwiseMax(const int N, const T* x, const T* y, T* z, Context* context); - -// Elemwise maximum of vector x and scalar alpha. y[i] = max(x[i], alpha) -template -void Maximum( - const int N, - const float alpha, - const T* x, - T* y, - Context* context); - -// Decaf gemm provides a simpler interface to the gemm functions, with the -// limitation that the data has to be contiguous in memory. -template -void Gemm( - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const int M, - const int N, - const int K, - const float alpha, - const T* A, - const T* B, - const float beta, - T* C, - Context* context, - TensorProto::DataType math_type = TensorProto_DataType_FLOAT); - -// We also provide a gemm that has explicit lda, ldb and ldc specified. -// In most cases you probably want to use the function above, though. -template -void GemmEx( - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const int M, - const int N, - const int K, - const T alpha, - const T* A, - const int lda, - const T* B, - const int ldb, - const T beta, - T* C, - const int ldc, - Context* context); - -// GemmBatched provides a simple abstraction into library routines -template -void GemmBatched( - const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, - const int A_size, - const int A_batches, - const int B_size, - const int B_batches, - const int M, - const int N, - const int K, - const float alpha, - const T* A, - const T* B, - const float beta, - T* C, - Context* context, - Tensor* scratch = nullptr, - TensorProto::DataType math_type = TensorProto_DataType_FLOAT); - -// Gemv always takes in a M*N matrix A, and depending on whether we set TransA -// to Trans, the output is: -// CblasNoTrans: x is an N dim vector and y is an M dim vector. -// CblasTrans: x is an M dim vector and y is an N dim vector. -template -void Gemv( - const CBLAS_TRANSPOSE TransA, - const int M, - const int N, - const float alpha, - const T* A, - const T* x, - const float beta, - T* y, - Context* context, - TensorProto::DataType math_type = TensorProto_DataType_FLOAT); - -template -void Set(const TIndex N, const T alpha, T* X, Context* context); - -template -void RandUniform(const int n, const T a, const T b, T* r, - Context* context); - -template -void RandUniformUnique( - const size_t n, - const T a, - const T b, - T* r, - const size_t m, - const T* avoid, - Context* context); - -template -void RandGaussian( - const int n, - const T mean, - const T std, - T* r, - Context* context); - -// Dot matrix of vector a and b, and writes the result to a single value y. -template -void Dot(const int N, const T* a, const T* b, T* y, Context* context); - -// Sum of vector x, and writes the result to a single value y. -template -void Sum(const int N, const T* x, T* y, Context* context, - Tensor* scratch_ptr = nullptr); - -// Sum of squares of vector x, and writes the result to a single value y. -template -void SumSqr( - const int N, - const T* x, - T* y, - Context* context, - Tensor* scratch_ptr = nullptr); - -// Select does index selection of the rows a N*D matrix x, and gives the N -// dimensional vector y that contains the selected data. -template -void Select(const int N, const int D, const T* x, const int* idx, T* y, - Context* context); - -template -void Scale(const int N, const float alpha, const T* x, T* y, Context* context); - -// Different from the Scale function above, if alpha is passed in -// as a pointer, we will assume that it lives on the Context device, -// for example on GPU. -template -void Scale(const int N, const float* alpha, const T* x, T* y, Context* context); - -template -void Axpy(const int N, const float alpha, const T* x, T* y, Context* context); - -// Different from the Axpy function above, if alpha is passed in -// as a pointer, we will assume that it lives on the Context device, -// for example on GPU. -template -void Axpy(const int N, const float* alpha, const T* x, T* y, Context* context); - -template -void Axpby( - const int N, - const float alpha, - const T* x, - const T b, - T* y, - Context* context); - -template -void Im2colNd( - const T* data_img, - const int* im_shape, - const int* col_shape, - const int img_size, - const int col_size, - const int* kernel_shape, - const int* stride, - const int* dilation, - const int* pad, - const int N, - T* data_col, - Context* context, - bool accumulate_output = false); - -template -void Col2imNd( - const T* data_col, - const int* img_shape, - const int* col_shape, - const int img_size, - const int col_size, - const int* kernel_shape, - const int* stride, - const int* dilation, - const int* pad, - const int N, - T* data_img, - Context* context); - -template -void Im2col( - const T* data_im, - const int channels, - const int height, - const int width, - const int kernel_h, - const int kernel_w, - const int dilation_h, - const int dilation_w, - const int pad_t, - const int pad_l, - const int pad_b, - const int pad_r, - const int stride_h, - const int stride_w, - T* data_col, - Context* context); - -template -void Col2im( - const T* data_col, - const int channels, - const int height, - const int width, - const int patch_h, - const int patch_w, - const int dilation_h, - const int dilation_w, - const int pad_t, - const int pad_l, - const int pad_b, - const int pad_r, - const int stride_h, - const int stride_w, - T* data_im, - Context* context); - -// Applies a per-channel bias value to each channel of the input -// image. image_size is H * W -template -void BiasCHW( - const T* bias, - const int bias_channels, - const int image_size, - T* image, - Context* context); - -template -void CopyMatrix(const size_t item_size, const int M, const int N, const void* A, - const int lda, void* B, const int ldb, Context* context); - -template -void CopyVector(const int N, const T* A, T* B, Context* context); - -uint32_t randomNumberSeed(); - -// Function uses casting from int to unsigned to compare if value of -// parameter a is greater or equal to zero and lower than value of -// parameter b. The b parameter is of type signed and is always -// positive, -// therefore its value is always lower than 0x800... where casting -// negative value of a parameter converts it to value higher than -// 0x800... -// The casting allows to use one condition instead of two. -inline bool is_a_ge_zero_and_a_lt_b(int a, int b) { - return static_cast(a) < static_cast(b); -} - -// Calculates ceil(a / b). User must be careful to ensure that there -// is no overflow or underflow in the calculation. -template -constexpr T divUp(T a, T b) { - return (a + b - (T) 1) / b; -} - -// Rounds a up to the next highest multiple of b. User must be careful -// to ensure that there is no overflow or underflow in the calculation -// of divUp. -template -constexpr T roundUp(T a, T b) { - return divUp(a, b) * b; -} - -// Returns true if the given integer type is a power-of-2 (positive only) -// Note(jiayq): windows reported an error per -// https://github.com/caffe2/caffe2/issues/997 -// and as a result will make it a macro. -#ifdef _MSC_VER -#define integerIsPowerOf2(v) ((v) && !((v) & ((v) - 1))) -#else // _MSC_VER -template -constexpr bool integerIsPowerOf2(T v) { - return (v && !(v & (v - 1))); -} -#endif // _MSC_VER - -// Returns log2(n) for a positive integer type -template -constexpr int integerLog2(T n, int p = 0) { - return (n <= 1) ? p : integerLog2(n / 2, p + 1); -} - -// Returns the next highest power-of-2 for an integer type -template -constexpr T integerNextHighestPowerOf2(T v) { - return (integerIsPowerOf2(v) ? (T)2 * v : ((T)1 << (integerLog2(v) + 1))); -} - -} // namespace math -} // namespace caffe2 - -#include "caffe2/utils/math-detail.h" -#endif // CAFFE2_UTILS_MATH_H_ diff --git a/app/src/main/cpp/caffe2/utils/murmur_hash3.h b/app/src/main/cpp/caffe2/utils/murmur_hash3.h deleted file mode 100644 index ea67e71..0000000 --- a/app/src/main/cpp/caffe2/utils/murmur_hash3.h +++ /dev/null @@ -1,34 +0,0 @@ -//----------------------------------------------------------------------------- -// MurmurHash3 was written by Austin Appleby, and is placed in the public -// domain. The author hereby disclaims copyright to this source code. - -#pragma once - -//----------------------------------------------------------------------------- -// Platform-specific functions and macros - -// Microsoft Visual Studio - -#if defined(_MSC_VER) && (_MSC_VER < 1600) - -typedef unsigned char uint8_t; -typedef unsigned int uint32_t; -typedef unsigned __int64 uint64_t; - -// Other compilers - -#else // defined(_MSC_VER) - -#include - -#endif // !defined(_MSC_VER) - -namespace caffe2 { - -void MurmurHash3_x86_32(const void* key, int len, uint32_t seed, void* out); - -void MurmurHash3_x86_128(const void* key, int len, uint32_t seed, void* out); - -void MurmurHash3_x64_128(const void* key, int len, uint32_t seed, void* out); - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/proto_utils.h b/app/src/main/cpp/caffe2/utils/proto_utils.h deleted file mode 100644 index 5f992cc..0000000 --- a/app/src/main/cpp/caffe2/utils/proto_utils.h +++ /dev/null @@ -1,286 +0,0 @@ -#ifndef CAFFE2_UTILS_PROTO_UTILS_H_ -#define CAFFE2_UTILS_PROTO_UTILS_H_ - -#ifdef CAFFE2_USE_LITE_PROTO -#include -#else // CAFFE2_USE_LITE_PROTO -#include -#endif // !CAFFE2_USE_LITE_PROTO - -#include "caffe2/core/logging.h" -#include "caffe2/proto/caffe2.pb.h" - -namespace caffe2 { - -using std::string; -using ::google::protobuf::MessageLite; - -// A wrapper function to return device name string for use in blob serialization -// / deserialization. This should have one to one correspondence with -// caffe2/proto/caffe2.proto: enum DeviceType. -// -// Note that we can't use DeviceType_Name, because that is only available in -// protobuf-full, and some platforms (like mobile) may want to use -// protobuf-lite instead. -std::string DeviceTypeName(const int32_t& d); - -// Returns if the two DeviceOptions are pointing to the same device. -bool IsSameDevice(const DeviceOption& lhs, const DeviceOption& rhs); - -// Common interfaces that reads file contents into a string. -bool ReadStringFromFile(const char* filename, string* str); -bool WriteStringToFile(const string& str, const char* filename); - -// Common interfaces that are supported by both lite and full protobuf. -bool ReadProtoFromBinaryFile(const char* filename, MessageLite* proto); -inline bool ReadProtoFromBinaryFile(const string filename, MessageLite* proto) { - return ReadProtoFromBinaryFile(filename.c_str(), proto); -} - -void WriteProtoToBinaryFile(const MessageLite& proto, const char* filename); -inline void WriteProtoToBinaryFile(const MessageLite& proto, - const string& filename) { - return WriteProtoToBinaryFile(proto, filename.c_str()); -} - -#ifdef CAFFE2_USE_LITE_PROTO - -inline string ProtoDebugString(const MessageLite& proto) { - return proto.SerializeAsString(); -} - -// Text format MessageLite wrappers: these functions do nothing but just -// allowing things to compile. It will produce a runtime error if you are using -// MessageLite but still want text support. -inline bool ReadProtoFromTextFile( - const char* /*filename*/, - MessageLite* /*proto*/) { - LOG(FATAL) << "If you are running lite version, you should not be " - << "calling any text-format protobuffers."; - return false; // Just to suppress compiler warning. -} -inline bool ReadProtoFromTextFile(const string filename, MessageLite* proto) { - return ReadProtoFromTextFile(filename.c_str(), proto); -} - -inline void WriteProtoToTextFile( - const MessageLite& /*proto*/, - const char* /*filename*/) { - LOG(FATAL) << "If you are running lite version, you should not be " - << "calling any text-format protobuffers."; -} -inline void WriteProtoToTextFile(const MessageLite& proto, - const string& filename) { - return WriteProtoToTextFile(proto, filename.c_str()); -} - -inline bool ReadProtoFromFile(const char* filename, MessageLite* proto) { - return (ReadProtoFromBinaryFile(filename, proto) || - ReadProtoFromTextFile(filename, proto)); -} - -inline bool ReadProtoFromFile(const string& filename, MessageLite* proto) { - return ReadProtoFromFile(filename.c_str(), proto); -} - -#else // CAFFE2_USE_LITE_PROTO - -using ::google::protobuf::Message; - -inline string ProtoDebugString(const Message& proto) { - return proto.ShortDebugString(); -} - -bool ReadProtoFromTextFile(const char* filename, Message* proto); -inline bool ReadProtoFromTextFile(const string filename, Message* proto) { - return ReadProtoFromTextFile(filename.c_str(), proto); -} - -void WriteProtoToTextFile(const Message& proto, const char* filename); -inline void WriteProtoToTextFile(const Message& proto, const string& filename) { - return WriteProtoToTextFile(proto, filename.c_str()); -} - -// Read Proto from a file, letting the code figure out if it is text or binary. -inline bool ReadProtoFromFile(const char* filename, Message* proto) { - return (ReadProtoFromBinaryFile(filename, proto) || - ReadProtoFromTextFile(filename, proto)); -} - -inline bool ReadProtoFromFile(const string& filename, Message* proto) { - return ReadProtoFromFile(filename.c_str(), proto); -} - -#endif // CAFFE2_USE_LITE_PROTO - -template < - class IterableInputs = std::initializer_list, - class IterableOutputs = std::initializer_list, - class IterableArgs = std::initializer_list> -OperatorDef CreateOperatorDef( - const string& type, - const string& name, - const IterableInputs& inputs, - const IterableOutputs& outputs, - const IterableArgs& args, - const DeviceOption& device_option = DeviceOption(), - const string& engine = "") { - OperatorDef def; - def.set_type(type); - def.set_name(name); - for (const string& in : inputs) { - def.add_input(in); - } - for (const string& out : outputs) { - def.add_output(out); - } - for (const Argument& arg : args) { - def.add_arg()->CopyFrom(arg); - } - if (device_option.has_device_type()) { - def.mutable_device_option()->CopyFrom(device_option); - } - if (engine.size()) { - def.set_engine(engine); - } - return def; -} - -// A simplified version compared to the full CreateOperator, if you do not need -// to specify args. -template < - class IterableInputs = std::initializer_list, - class IterableOutputs = std::initializer_list> -inline OperatorDef CreateOperatorDef( - const string& type, - const string& name, - const IterableInputs& inputs, - const IterableOutputs& outputs, - const DeviceOption& device_option = DeviceOption(), - const string& engine = "") { - return CreateOperatorDef( - type, - name, - inputs, - outputs, - std::vector(), - device_option, - engine); -} - -bool HasOutput(const OperatorDef& op, const std::string& output); -bool HasInput(const OperatorDef& op, const std::string& input); - -/** - * @brief A helper class to index into arguments. - * - * This helper helps us to more easily index into a set of arguments - * that are present in the operator. To save memory, the argument helper - * does not copy the operator def, so one would need to make sure that the - * lifetime of the OperatorDef object outlives that of the ArgumentHelper. - */ -class ArgumentHelper { - public: - template - static bool HasArgument(const Def& def, const string& name) { - return ArgumentHelper(def).HasArgument(name); - } - - template - static T GetSingleArgument( - const Def& def, - const string& name, - const T& default_value) { - return ArgumentHelper(def).GetSingleArgument(name, default_value); - } - - template - static bool HasSingleArgumentOfType(const Def& def, const string& name) { - return ArgumentHelper(def).HasSingleArgumentOfType(name); - } - - template - static vector GetRepeatedArgument( - const Def& def, - const string& name, - const std::vector& default_value = std::vector()) { - return ArgumentHelper(def).GetRepeatedArgument(name, default_value); - } - - template - static MessageType GetMessageArgument(const Def& def, const string& name) { - return ArgumentHelper(def).GetMessageArgument(name); - } - - template - static vector GetRepeatedMessageArgument( - const Def& def, - const string& name) { - return ArgumentHelper(def).GetRepeatedMessageArgument(name); - } - - explicit ArgumentHelper(const OperatorDef& def); - explicit ArgumentHelper(const NetDef& netdef); - bool HasArgument(const string& name) const; - - template - T GetSingleArgument(const string& name, const T& default_value) const; - template - bool HasSingleArgumentOfType(const string& name) const; - template - vector GetRepeatedArgument( - const string& name, - const std::vector& default_value = std::vector()) const; - - template - MessageType GetMessageArgument(const string& name) const { - CAFFE_ENFORCE(arg_map_.count(name), "Cannot find parameter named ", name); - MessageType message; - if (arg_map_.at(name).has_s()) { - CAFFE_ENFORCE( - message.ParseFromString(arg_map_.at(name).s()), - "Faild to parse content from the string"); - } else { - VLOG(1) << "Return empty message for parameter " << name; - } - return message; - } - - template - vector GetRepeatedMessageArgument(const string& name) const { - CAFFE_ENFORCE(arg_map_.count(name), "Cannot find parameter named ", name); - vector messages(arg_map_.at(name).strings_size()); - for (int i = 0; i < messages.size(); ++i) { - CAFFE_ENFORCE( - messages[i].ParseFromString(arg_map_.at(name).strings(i)), - "Faild to parse content from the string"); - } - return messages; - } - - private: - CaffeMap arg_map_; -}; - -const Argument& GetArgument(const OperatorDef& def, const string& name); -bool GetFlagArgument( - const OperatorDef& def, - const string& name, - bool def_value = false); - -Argument* GetMutableArgument( - const string& name, - const bool create_if_missing, - OperatorDef* def); - -template -Argument MakeArgument(const string& name, const T& value); - -template -inline void AddArgument(const string& name, const T& value, OperatorDef* def) { - GetMutableArgument(name, true, def)->CopyFrom(MakeArgument(name, value)); -} - -} // namespace caffe2 - -#endif // CAFFE2_UTILS_PROTO_UTILS_H_ diff --git a/app/src/main/cpp/caffe2/utils/signal_handler.h b/app/src/main/cpp/caffe2/utils/signal_handler.h deleted file mode 100644 index e0c12a6..0000000 --- a/app/src/main/cpp/caffe2/utils/signal_handler.h +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#if defined(__APPLE__) -#define CAFFE2_SUPPORTS_SIGNAL_HANDLER -#elif defined(__linux__) -#define CAFFE2_SUPPORTS_FATAL_SIGNAL_HANDLERS -#define CAFFE2_SUPPORTS_SIGNAL_HANDLER -#endif - -namespace caffe2 { - -class SignalHandler { - public: - enum class Action { - NONE, - STOP - }; - - // Contructor. Specify what action to take when a signal is received. - SignalHandler(Action SIGINT_action, - Action SIGHUP_action); - ~SignalHandler(); - - Action CheckForSignals(); - - private: - bool GotSIGINT(); - bool GotSIGHUP(); - Action SIGINT_action_; - Action SIGHUP_action_; - unsigned long my_sigint_count_; - unsigned long my_sighup_count_; -}; - -#if defined(CAFFE2_SUPPORTS_FATAL_SIGNAL_HANDLERS) -// This works by setting up certain fatal signal handlers. Previous fatal -// signal handlers will still be called when the signal is raised. Defaults -// to being off. -void setPrintStackTracesOnFatalSignal(bool print); -bool printStackTracesOnFatalSignal(); -#endif // defined(CAFFE2_SUPPORTS_SIGNAL_HANDLER) - -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/simple_queue.h b/app/src/main/cpp/caffe2/utils/simple_queue.h deleted file mode 100644 index 5adedf1..0000000 --- a/app/src/main/cpp/caffe2/utils/simple_queue.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef CAFFE2_UTILS_SIMPLE_QUEUE_H_ -#define CAFFE2_UTILS_SIMPLE_QUEUE_H_ - -#include // NOLINT -#include // NOLINT -#include - -#include "caffe2/core/logging.h" - -namespace caffe2 { - -// This is a very simple queue that Yangqing wrote when bottlefeeding the baby, -// so don't take it seriously. What it does is a minimal thread-safe queue that -// allows me to run network as a DAG. -// -// A usual work pattern looks like this: one or multiple producers push jobs -// into this queue, and one or multiple workers pops jobs from this queue. If -// nothing is in the queue but NoMoreJobs() is not called yet, the pop calls -// will wait. If NoMoreJobs() has been called, pop calls will return false, -// which serves as a message to the workers that they should exit. -template -class SimpleQueue { - public: - SimpleQueue() : no_more_jobs_(false) {} - - // Pops a value and writes it to the value pointer. If there is nothing in the - // queue, this will wait till a value is inserted to the queue. If there are - // no more jobs to pop, the function returns false. Otherwise, it returns - // true. - bool Pop(T* value) { - std::unique_lock mutex_lock(mutex_); - while (queue_.size() == 0 && !no_more_jobs_) cv_.wait(mutex_lock); - if (queue_.size() == 0 && no_more_jobs_) return false; - *value = queue_.front(); - queue_.pop(); - return true; - } - - int size() { - std::unique_lock mutex_lock(mutex_); - return queue_.size(); - } - - // Push pushes a value to the queue. - void Push(const T& value) { - { - std::lock_guard mutex_lock(mutex_); - CAFFE_ENFORCE(!no_more_jobs_, "Cannot push to a closed queue."); - queue_.push(value); - } - cv_.notify_one(); - } - - // NoMoreJobs() marks the close of this queue. It also notifies all waiting - // Pop() calls so that they either check out remaining jobs, or return false. - // After NoMoreJobs() is called, this queue is considered closed - no more - // Push() functions are allowed, and once existing items are all checked out - // by the Pop() functions, any more Pop() function will immediately return - // false with nothing set to the value. - void NoMoreJobs() { - { - std::lock_guard mutex_lock(mutex_); - no_more_jobs_ = true; - } - cv_.notify_all(); - } - - private: - std::mutex mutex_; - std::condition_variable cv_; - std::queue queue_; - bool no_more_jobs_; - // We do not allow copy constructors. - SimpleQueue(const SimpleQueue& /*src*/) {} -}; - -} // namespace caffe2 - -#endif // CAFFE2_UTILS_SIMPLE_QUEUE_H_ diff --git a/app/src/main/cpp/caffe2/utils/smart_tensor_printer.h b/app/src/main/cpp/caffe2/utils/smart_tensor_printer.h deleted file mode 100644 index f99226d..0000000 --- a/app/src/main/cpp/caffe2/utils/smart_tensor_printer.h +++ /dev/null @@ -1,52 +0,0 @@ -#pragma once - -#include "caffe2/core/tensor.h" - -namespace caffe2 { - -// This is a wrapper around the TensorPrinter that doesn't require the user to -// explicit specify the type of the tensor while calling the Print() method. -// It also supports a convenience function with a default constructed printer as -// a static method. -class SmartTensorPrinter { - public: - // The proliferation of constructors is to give the feature parity with - // TensorPrinter - // yet not repeat the default arguments explicitly in case they change in the - // future. - SmartTensorPrinter() = default; - - explicit SmartTensorPrinter(const std::string& tensor_name); - - SmartTensorPrinter( - const std::string& tensor_name, - const std::string& file_name); - - SmartTensorPrinter( - const std::string& tensor_name, - const std::string& file_name, - int limit); - - void Print(const Tensor& tensor); - - template - void PrintMeta(const Tensor& tensor) { - tensorPrinter_.PrintMeta(tensor); - } - - // Uses a default constructed SmartTensorPrinter - static void PrintTensor(const Tensor& tensor); - - // Uses a default constructed SmartTensorPrinter - template - void PrintTensorMeta(const Tensor& tensor) { - DefaultTensorPrinter().PrintMeta(tensor); - } - - private: - // Returns a thread local default constructed TensorPrinter - static SmartTensorPrinter& DefaultTensorPrinter(); - - TensorPrinter tensorPrinter_; -}; -} diff --git a/app/src/main/cpp/caffe2/utils/string_utils.h b/app/src/main/cpp/caffe2/utils/string_utils.h deleted file mode 100644 index 580558a..0000000 --- a/app/src/main/cpp/caffe2/utils/string_utils.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace caffe2 { - -std::vector split(char separator, const std::string& string); -size_t editDistance( - const std::string& s1, const std::string& s2, size_t max_distance = 0); - -int32_t editDistanceHelper(const char* s1, - size_t s1_len, - const char* s2, - size_t s2_len, - std::vector ¤t, - std::vector &previous, - std::vector &previous1, - size_t max_distance); -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/thread_pool.h b/app/src/main/cpp/caffe2/utils/thread_pool.h deleted file mode 100644 index e8453f1..0000000 --- a/app/src/main/cpp/caffe2/utils/thread_pool.h +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef CAFFE2_UTILS_THREAD_POOL_H_ -#define CAFFE2_UTILS_THREAD_POOL_H_ - -#include -#include -#include -#include -#include -#include - -class TaskThreadPool{ - private: - struct task_element_t { - bool run_with_id; - const std::function< void() > no_id; - const std::function< void(std::size_t) > with_id; - - explicit task_element_t(const std::function< void() >& f) : - run_with_id(false), no_id(f), with_id(nullptr) { } - explicit task_element_t(const std::function< void(std::size_t) >& f) : - run_with_id(true), no_id(nullptr), with_id(f) { } - }; - std::queue tasks_; - std::vector threads_; - std::mutex mutex_; - std::condition_variable condition_; - std::condition_variable completed_; - bool running_; - bool complete_; - std::size_t available_; - std::size_t total_; - - public: - /// @brief Constructor. - explicit TaskThreadPool(std::size_t pool_size) - : threads_(pool_size), running_(true), complete_(true), - available_(pool_size), total_(pool_size) { - for ( std::size_t i = 0; i < pool_size; ++i ) { - threads_[i] = std::thread( - std::bind(&TaskThreadPool::main_loop, this, i)); - } - } - - /// @brief Destructor. - ~TaskThreadPool() { - // Set running flag to false then notify all threads. - { - std::unique_lock< std::mutex > lock(mutex_); - running_ = false; - condition_.notify_all(); - } - - try { - for (auto& t : threads_) { - t.join(); - } - } - // Suppress all exceptions. - catch (const std::exception&) {} - } - - /// @brief Add task to the thread pool if a thread is currently available. - template - void runTask(Task task) { - std::unique_lock lock(mutex_); - - // Set task and signal condition variable so that a worker thread will - // wake up and use the task. - tasks_.push(task_element_t(static_cast>(task))); - complete_ = false; - condition_.notify_one(); - } - - template - void runTaskWithID(Task task) { - std::unique_lock lock(mutex_); - - // Set task and signal condition variable so that a worker thread will - // wake up and use the task. - tasks_.push(task_element_t(static_cast>( - task))); - complete_ = false; - condition_.notify_one(); - } - - /// @brief Wait for queue to be empty - void waitWorkComplete() { - std::unique_lock lock(mutex_); - while (!complete_) - completed_.wait(lock); - } - - private: - /// @brief Entry point for pool threads. - void main_loop(std::size_t index) { - while (running_) { - // Wait on condition variable while the task is empty and - // the pool is still running. - std::unique_lock lock(mutex_); - while (tasks_.empty() && running_) { - condition_.wait(lock); - } - // If pool is no longer running, break out of loop. - if (!running_) break; - - // Copy task locally and remove from the queue. This is - // done within its own scope so that the task object is - // destructed immediately after running the task. This is - // useful in the event that the function contains - // shared_ptr arguments bound via bind. - { - auto tasks = tasks_.front(); - tasks_.pop(); - // Decrement count, indicating thread is no longer available. - --available_; - - lock.unlock(); - - // Run the task. - try { - if (tasks.run_with_id) { - tasks.with_id(index); - } else { - tasks.no_id(); - } - } - // Suppress all exceptions. - catch ( const std::exception& ) {} - - // Update status of empty, maybe - // Need to recover the lock first - lock.lock(); - - // Increment count, indicating thread is available. - ++available_; - if (tasks_.empty() && available_ == total_) { - complete_ = true; - completed_.notify_one(); - } - } - } // while running_ - } -}; - -#endif diff --git a/app/src/main/cpp/caffe2/utils/threadpool/ThreadPool.h b/app/src/main/cpp/caffe2/utils/threadpool/ThreadPool.h deleted file mode 100644 index d8769f8..0000000 --- a/app/src/main/cpp/caffe2/utils/threadpool/ThreadPool.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef CAFFE2_UTILS_THREADPOOL_H_ -#define CAFFE2_UTILS_THREADPOOL_H_ - -#include "ThreadPoolCommon.h" - -#ifndef CAFFE2_THREADPOOL_MOBILE -#error "mobile build state not defined" -#endif - -// ThreadPool only used in mobile builds at the moment -#if CAFFE2_THREADPOOL_MOBILE - -#include -#include -#include - -// -// A work-stealing threadpool loosely based off of pthreadpool -// - -namespace caffe2 { - -class Task; -class WorkersPool; - -constexpr size_t kCacheLineSize = 64; - -class alignas(kCacheLineSize) ThreadPool { - public: - // Constructs a work-stealing threadpool with the given number of - // threads - static std::unique_ptr defaultThreadPool(); - ThreadPool(int numThreads); - ~ThreadPool(); - // Returns the number of threads currently in use - int getNumThreads() const; - - // Sets the minimum work size (range) for which to invoke the - // threadpool; work sizes smaller than this will just be run on the - // main (calling) thread - void setMinWorkSize(size_t size); - size_t getMinWorkSize() const { return minWorkSize_; } - void run(const std::function& fn, size_t range); - -private: - mutable std::mutex executionMutex_; - size_t minWorkSize_; - size_t numThreads_; - std::shared_ptr workersPool_; - std::vector> tasks_; -}; - -} // namespace caffe2 - -#endif // CAFFE2_THREADPOOL_MOBILE - -#endif // CAFFE2_UTILS_THREADPOOL_H_ diff --git a/app/src/main/cpp/caffe2/utils/threadpool/ThreadPoolCommon.h b/app/src/main/cpp/caffe2/utils/threadpool/ThreadPoolCommon.h deleted file mode 100644 index 4d7112a..0000000 --- a/app/src/main/cpp/caffe2/utils/threadpool/ThreadPoolCommon.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef CAFFE2_UTILS_THREADPOOL_COMMON_H_ -#define CAFFE2_UTILS_THREADPOOL_COMMON_H_ - -#ifdef __APPLE__ -#include -#endif - -// caffe2 depends upon NNPACK, which depends upon this threadpool, so -// unfortunately we can't reference core/common.h here - -// This is copied from core/common.h's definition of CAFFE2_MOBILE -// Define enabled when building for iOS or Android devices -#if !defined(CAFFE2_THREADPOOL_MOBILE) -#if defined(__ANDROID__) -#define CAFFE2_ANDROID 1 -#define CAFFE2_THREADPOOL_MOBILE 1 -#elif (defined(__APPLE__) && \ - (TARGET_IPHONE_SIMULATOR || TARGET_OS_SIMULATOR || TARGET_OS_IPHONE)) -#define CAFFE2_IOS 1 -#define CAFFE2_THREADPOOL_MOBILE 1 -#elif (defined(__APPLE__) && TARGET_OS_MAC) -#define CAFFE2_IOS 1 -#define CAFFE2_THREADPOOL_MOBILE 1 -#else -#define CAFFE2_THREADPOOL_MOBILE 0 -#endif // ANDROID / IOS / MACOS -#endif // CAFFE2_THREADPOOL_MOBILE - -#endif // CAFFE2_UTILS_THREADPOOL_COMMON_H_ diff --git a/app/src/main/cpp/caffe2/utils/threadpool/WorkersPool.h b/app/src/main/cpp/caffe2/utils/threadpool/WorkersPool.h deleted file mode 100644 index dc26f74..0000000 --- a/app/src/main/cpp/caffe2/utils/threadpool/WorkersPool.h +++ /dev/null @@ -1,365 +0,0 @@ -#include "caffe2/core/common.h" -#include "caffe2/core/logging.h" -#include -#include -#include - -#if defined(_MSC_VER) -#include -#endif - -namespace caffe2 { - -// Uses code derived from gemmlowp, -// https://github.com/google/gemmlowp/blob/6c91e1ed0c2eff1182d804310b92911fe9c18019/internal/multi_thread_gemm.h -// Changes: -// - allocation-free execute() -// - Use RAII where possible. -// - Run the first task on the main thread (since that is the largest task). -// - removed custom allocator. -// - Removed some ifdef's -// - cache-line align Worker. -// - use std::atomic instead of volatile and custom barriers. -// - use std::mutex/std::condition_variable instead of raw pthreads. - -constexpr size_t kGEMMLOWPCacheLineSize = 64; - -template -struct AllocAligned { - // Allocate a T aligned at an `align` byte address - template - static T* alloc(Args&&... args) { - void* p = nullptr; - -#if defined(__ANDROID__) - p = memalign(kGEMMLOWPCacheLineSize, sizeof(T)); -#elif defined(_MSC_VER) - p = _aligned_malloc(sizeof(T), kGEMMLOWPCacheLineSize); -#else - posix_memalign((void**)&p, kGEMMLOWPCacheLineSize, sizeof(T)); -#endif - - if (p) { - return new (p) T(std::forward(args)...); - } - - return nullptr; - } - - // Free a T previously allocated via AllocAligned::alloc() - static void release(T* p) { - if (p) { - p->~T(); - free((void*)p); - } - } -}; - -// Deleter object for unique_ptr for an aligned object -template -struct AlignedDeleter { - void operator()(T* p) const { AllocAligned::release(p); } -}; - -// make_unique that guarantees alignment -template -struct MakeAligned { - template - static std::unique_ptr> make(Args&&... args) { - return std::unique_ptr>( - AllocAligned::alloc(std::forward(args)...)); - } -}; - -const int kMaxBusyWaitNOPs = 32 * 1000 * 1000; - -#if defined(_MSC_VER) -#define GEMMLOWP_NOP __nop(); -#else -#define GEMMLOWP_NOP "nop\n" -#endif - -#define GEMMLOWP_STRING_CONCAT_4(X) X X X X -#define GEMMLOWP_NOP4 GEMMLOWP_STRING_CONCAT_4(GEMMLOWP_NOP) -#define GEMMLOWP_NOP16 GEMMLOWP_STRING_CONCAT_4(GEMMLOWP_NOP4) -#define GEMMLOWP_NOP64 GEMMLOWP_STRING_CONCAT_4(GEMMLOWP_NOP16) - -inline int Do256NOPs() { -#if defined(_MSC_VER) - GEMMLOWP_NOP64; -#else - asm volatile(GEMMLOWP_NOP64); -#endif - return 64; -} - -#undef GEMMLOWP_STRING_CONCAT_4 -#undef GEMMLOWP_NOP256 -#undef GEMMLOWP_NOP64 -#undef GEMMLOWP_NOP16 -#undef GEMMLOWP_NOP4 -#undef GEMMLOWP_NOP - -// Waits until *var != initial_value. -// -// Returns the new value of *var. The guarantee here is that -// the return value is different from initial_value, and that that -// new value has been taken by *var at some point during the -// execution of this function. There is no guarantee that this is -// still the value of *var when this function returns, since *var is -// not assumed to be guarded by any lock. -// -// First does some busy-waiting for a fixed number of no-op cycles, -// then falls back to passive waiting for the given condvar, guarded -// by the given mutex. -// -// The idea of doing some initial busy-waiting is to help get -// better and more consistent multithreading benefits for small GEMM sizes. -// Busy-waiting help ensuring that if we need to wake up soon after having -// started waiting, then we can wake up quickly (as opposed to, say, -// having to wait to be scheduled again by the OS). On the other hand, -// we must still eventually revert to passive waiting for longer waits -// (e.g. worker threads having finished a GEMM and waiting until the next GEMM) -// so as to avoid permanently spinning. -// -template -T WaitForVariableChange(std::atomic* var, - T initial_value, - std::condition_variable* cond, - std::mutex* mutex) { - // If we are on a platform that supports it, spin for some time. - { - int nops = 0; - // First, trivial case where the variable already changed value. - T new_value = var->load(std::memory_order_relaxed); - if (new_value != initial_value) { - std::atomic_thread_fence(std::memory_order_acquire); - return new_value; - } - // Then try busy-waiting. - while (nops < kMaxBusyWaitNOPs) { - nops += Do256NOPs(); - new_value = var->load(std::memory_order_relaxed); - if (new_value != initial_value) { - std::atomic_thread_fence(std::memory_order_acquire); - return new_value; - } - } - } - - // Finally, do real passive waiting. - { - std::unique_lock g(*mutex); - T new_value = var->load(std::memory_order_relaxed); - // Handle spurious wakeups. - cond->wait(g, [&]() { - new_value = var->load(std::memory_order_relaxed); - return new_value != initial_value; - }); - DCHECK_NE(static_cast(new_value), static_cast(initial_value)); - return new_value; - } -} - -// A BlockingCounter lets one thread to wait for N events to occur. -// This is how the master thread waits for all the worker threads -// to have finished working. -class BlockingCounter { - public: - // Sets/resets the counter; initial_count is the number of - // decrementing events that the Wait() call will be waiting for. - void Reset(std::size_t initial_count) { - std::lock_guard g(mutex_); - DCHECK_EQ(count_, 0); - count_ = initial_count; - } - - // Decrements the counter; if the counter hits zero, signals - // the thread that was waiting for that, and returns true. - // Otherwise (if the decremented count is still nonzero), - // returns false. - bool DecrementCount() { - const auto count_value = count_.fetch_sub(1, std::memory_order_relaxed) - 1; - DCHECK_GE(count_value, 0); - if (count_value == 0) { - std::lock_guard g(mutex_); - cond_.notify_one(); - } - bool retval = count_value == 0; - return retval; - } - - // Waits for the N other threads (N having been set by Reset()) - // to hit the BlockingCounter. - void Wait() { - while (size_t count_value = count_.load(std::memory_order_relaxed)) { - WaitForVariableChange(&count_, count_value, &cond_, &mutex_); - } - } - - private: - std::condition_variable cond_; - std::mutex mutex_; - std::atomic count_{0}; -}; - -// A workload for a worker. -struct Task { - Task() {} - virtual ~Task() {} - virtual void Run() = 0; -}; - -// A worker thread. -class alignas(kGEMMLOWPCacheLineSize) Worker { - public: - enum class State : uint8_t { - ThreadStartup, // The initial state before the thread main loop runs. - Ready, // Is not working, has not yet received new work to do. - HasWork, // Has work to do. - ExitAsSoonAsPossible // Should exit at earliest convenience. - }; - - explicit Worker(BlockingCounter* counter_to_decrement_when_ready) - : task_(nullptr), - state_(State::ThreadStartup), - counter_to_decrement_when_ready_(counter_to_decrement_when_ready) { - thread_ = caffe2::make_unique([this]() { this->ThreadFunc(); }); - } - - ~Worker() { - ChangeState(State::ExitAsSoonAsPossible); - thread_->join(); - } - - // Changes State; may be called from either the worker thread - // or the master thread; however, not all state transitions are legal, - // which is guarded by assertions. - void ChangeState(State new_state) { - std::lock_guard g(state_mutex_); - DCHECK(new_state != state_.load(std::memory_order_relaxed)); - switch (state_.load(std::memory_order_relaxed)) { - case State::ThreadStartup: - DCHECK(new_state == State::Ready); - break; - case State::Ready: - DCHECK(new_state == State::HasWork || new_state == State::ExitAsSoonAsPossible); - break; - case State::HasWork: - DCHECK(new_state == State::Ready || new_state == State::ExitAsSoonAsPossible); - break; - default: - abort(); - } - state_.store(new_state, std::memory_order_relaxed); - state_cond_.notify_one(); - if (new_state == State::Ready) { - counter_to_decrement_when_ready_->DecrementCount(); - } - } - - // Thread entry point. - void ThreadFunc() { - ChangeState(State::Ready); - - // Thread main loop - while (true) { - // Get a state to act on - // In the 'Ready' state, we have nothing to do but to wait until - // we switch to another state. - State state_to_act_upon = - WaitForVariableChange(&state_, State::Ready, &state_cond_, &state_mutex_); - - // We now have a state to act on, so act. - switch (state_to_act_upon) { - case State::HasWork: - // Got work to do! So do it, and then revert to 'Ready' state. - DCHECK(task_); - task_->Run(); - task_ = nullptr; - ChangeState(State::Ready); - break; - case State::ExitAsSoonAsPossible: - return; - default: - abort(); - } - } - } - - static void* ThreadFunc(void* arg) { - static_cast(arg)->ThreadFunc(); - return nullptr; - } - - // Called by the master thead to give this worker work to do. - // It is only legal to call this if the worker - void StartWork(Task* task) { - DCHECK(!task_); - task_ = task; - DCHECK(state_.load(std::memory_order_acquire) == State::Ready); - ChangeState(State::HasWork); - } - - private: - // The underlying thread. - std::unique_ptr thread_; - - // The task to be worked on. - // Visibility of writes to task_ guarded by state_mutex_. - Task* task_; - - // The condition variable and mutex guarding state changes. - std::condition_variable state_cond_; - std::mutex state_mutex_; - - // The state enum tells if we're currently working, waiting for work, etc. - std::atomic state_; - - // pointer to the master's thread BlockingCounter object, to notify the - // master thread of when this worker switches to the 'Ready' state. - BlockingCounter* const counter_to_decrement_when_ready_; -}; - -class WorkersPool { - public: - WorkersPool() {} - - void Execute(const std::vector>& tasks) { - CAFFE_ENFORCE_GE(tasks.size(), 1); - // One of the tasks will be run on the current thread. - int workers_count = tasks.size() - 1; - CreateWorkers(workers_count); - DCHECK_LE(workers_count, workers_.size()); - counter_to_decrement_when_ready_.Reset(workers_count); - for (auto task = 1; task < tasks.size(); ++task) { - workers_[task - 1]->StartWork(tasks[task].get()); - } - // Execute the remaining workload immediately on the current thread. - auto& task = tasks.front(); - task->Run(); - // Wait for the workers submitted above to finish. - counter_to_decrement_when_ready_.Wait(); - } - - private: - // Ensures that the pool has at least the given count of workers. - // If any new worker has to be created, this function waits for it to - // be ready. - void CreateWorkers(std::size_t workers_count) { - if (workers_.size() >= workers_count) { - return; - } - counter_to_decrement_when_ready_.Reset(workers_count - workers_.size()); - while (workers_.size() < workers_count) { - workers_.push_back(MakeAligned::make(&counter_to_decrement_when_ready_)); - } - counter_to_decrement_when_ready_.Wait(); - } - - DISABLE_COPY_AND_ASSIGN(WorkersPool); - std::vector>> workers_; - // The BlockingCounter used to wait for the workers. - BlockingCounter counter_to_decrement_when_ready_; -}; -} // namespace caffe2 diff --git a/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool.h b/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool.h deleted file mode 100644 index d45309d..0000000 --- a/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool.h +++ /dev/null @@ -1,111 +0,0 @@ -// pthreadpool header from https://github.com/Maratyszcza/pthreadpool -// for NNPACK -#ifndef CAFFE2_UTILS_PTHREADPOOL_H_ -#define CAFFE2_UTILS_PTHREADPOOL_H_ - -#include "ThreadPoolCommon.h" - -#ifndef CAFFE2_THREADPOOL_MOBILE -#error "mobile build state not defined" -#endif - -// ThreadPool only used in mobile builds at the moment -#if CAFFE2_THREADPOOL_MOBILE - -#include // for size_t - -typedef struct pthreadpool* pthreadpool_t; - -typedef void (*pthreadpool_function_1d_t)(void*, size_t); -typedef void (*pthreadpool_function_1d_tiled_t)(void*, size_t, size_t); -typedef void (*pthreadpool_function_2d_t)(void*, size_t, size_t); -typedef void (*pthreadpool_function_2d_tiled_t)(void*, size_t, size_t, size_t, size_t); -typedef void (*pthreadpool_function_3d_t)(void*, size_t, size_t, size_t); - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Creates a thread pool with the specified number of threads. - * - * @param[in] threads_count The number of threads in the thread pool. - * A value of 0 has special interpretation: it creates a thread for each - * processor core available in the system. - * - * @returns A pointer to an opaque thread pool object. - * On error the function returns NULL and sets errno accordingly. - */ -pthreadpool_t pthreadpool_create(size_t threads_count); - -/** - * Queries the number of threads in a thread pool. - * - * @param[in] threadpool The thread pool to query. - * - * @returns The number of threads in the thread pool. - */ -size_t pthreadpool_get_threads_count(pthreadpool_t threadpool); - - -/** - * Processes items in parallel using threads from a thread pool. - * - * When the call returns, all items have been processed and the thread pool is - * ready for a new task. - * - * @note If multiple threads call this function with the same thread pool, the - * calls are serialized. - * - * @param[in] threadpool The thread pool to use for parallelisation. - * @param[in] function The function to call for each item. - * @param[in] argument The first argument passed to the @a function. - * @param[in] items The number of items to process. The @a function - * will be called once for each item. - */ -void pthreadpool_compute_1d( - pthreadpool_t threadpool, - pthreadpool_function_1d_t function, - void* argument, - size_t range); - -void pthreadpool_compute_1d_tiled( - pthreadpool_t threadpool, - pthreadpool_function_1d_tiled_t function, - void* argument, - size_t range, - size_t tile); - -void pthreadpool_compute_2d( - pthreadpool_t threadpool, - pthreadpool_function_2d_t function, - void* argument, - size_t range_i, - size_t range_j); - -void pthreadpool_compute_2d_tiled( - pthreadpool_t threadpool, - pthreadpool_function_2d_tiled_t function, - void* argument, - size_t range_i, - size_t range_j, - size_t tile_i, - size_t tile_j); - -/** - * Terminates threads in the thread pool and releases associated resources. - * - * @warning Accessing the thread pool after a call to this function constitutes - * undefined behaviour and may cause data corruption. - * - * @param[in,out] threadpool The thread pool to destroy. - */ -void pthreadpool_destroy(pthreadpool_t threadpool); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif // CAFFE2_THREADPOOL_MOBILE - -#endif // CAFFE2_UTILS_PTHREADPOOL_H_ diff --git a/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool_impl.h b/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool_impl.h deleted file mode 100644 index ecc82b1..0000000 --- a/app/src/main/cpp/caffe2/utils/threadpool/pthreadpool_impl.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef CAFFE2_UTILS_PTHREADPOOL_IMPL_H_ -#define CAFFE2_UTILS_PTHREADPOOL_IMPL_H_ - -#include "ThreadPoolCommon.h" - -#ifndef CAFFE2_THREADPOOL_MOBILE -#error "mobile build state not defined" -#endif - -#if CAFFE2_THREADPOOL_MOBILE - -namespace caffe2 { - -struct ThreadPool; - -} // namespace caffe2 - -extern "C" { - -// Wrapper for the caffe2 threadpool for the usage of NNPACK -struct pthreadpool { - pthreadpool(caffe2::ThreadPool* pool) : pool_(pool) {} - caffe2::ThreadPool* pool_; -}; - -} // extern "C" - -#endif // CAFFE2_THREADPOOL_MOBILE - -#endif // CAFFE2_UTILS_PTHREADPOOL_IMPL_H_ diff --git a/app/src/main/cpp/caffe2/utils/zmq_helper.h b/app/src/main/cpp/caffe2/utils/zmq_helper.h deleted file mode 100644 index be03d98..0000000 --- a/app/src/main/cpp/caffe2/utils/zmq_helper.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef CAFFE2_UTILS_ZMQ_HELPER_H_ -#define CAFFE2_UTILS_ZMQ_HELPER_H_ - -#include - -#include "caffe2/core/logging.h" - -namespace caffe2 { - -class ZmqContext { - public: - explicit ZmqContext(int io_threads) : ptr_(zmq_ctx_new()) { - CAFFE_ENFORCE(ptr_ != nullptr, "Failed to create zmq context."); - int rc = zmq_ctx_set(ptr_, ZMQ_IO_THREADS, io_threads); - CAFFE_ENFORCE_EQ(rc, 0); - rc = zmq_ctx_set(ptr_, ZMQ_MAX_SOCKETS, ZMQ_MAX_SOCKETS_DFLT); - CAFFE_ENFORCE_EQ(rc, 0); - } - ~ZmqContext() { - int rc = zmq_ctx_destroy(ptr_); - CAFFE_ENFORCE_EQ(rc, 0); - } - - void* ptr() { return ptr_; } - - private: - void* ptr_; - - DISABLE_COPY_AND_ASSIGN(ZmqContext); -}; - -class ZmqMessage { - public: - ZmqMessage() { - int rc = zmq_msg_init(&msg_); - CAFFE_ENFORCE_EQ(rc, 0); - } - - ~ZmqMessage() { - int rc = zmq_msg_close(&msg_); - CAFFE_ENFORCE_EQ(rc, 0); - } - - zmq_msg_t* msg() { return &msg_; } - - void* data() { return zmq_msg_data(&msg_); } - size_t size() { return zmq_msg_size(&msg_); } - - private: - zmq_msg_t msg_; - DISABLE_COPY_AND_ASSIGN(ZmqMessage); -}; - -class ZmqSocket { - public: - explicit ZmqSocket(int type) - : context_(1), ptr_(zmq_socket(context_.ptr(), type)) { - CAFFE_ENFORCE(ptr_ != nullptr, "Faild to create zmq socket."); - } - - ~ZmqSocket() { - int rc = zmq_close(ptr_); - CAFFE_ENFORCE_EQ(rc, 0); - } - - void Bind(const string& addr) { - int rc = zmq_bind(ptr_, addr.c_str()); - CAFFE_ENFORCE_EQ(rc, 0); - } - - void Unbind(const string& addr) { - int rc = zmq_unbind(ptr_, addr.c_str()); - CAFFE_ENFORCE_EQ(rc, 0); - } - - void Connect(const string& addr) { - int rc = zmq_connect(ptr_, addr.c_str()); - CAFFE_ENFORCE_EQ(rc, 0); - } - - void Disconnect(const string& addr) { - int rc = zmq_disconnect(ptr_, addr.c_str()); - CAFFE_ENFORCE_EQ(rc, 0); - } - - int Send(const string& msg, int flags) { - int nbytes = zmq_send(ptr_, msg.c_str(), msg.size(), flags); - if (nbytes) { - return nbytes; - } else if (zmq_errno() == EAGAIN) { - return 0; - } else { - LOG(FATAL) << "Cannot send zmq message. Error number: " - << zmq_errno(); - return 0; - } - } - - int SendTillSuccess(const string& msg, int flags) { - CAFFE_ENFORCE(msg.size(), "You cannot send an empty message."); - int nbytes = 0; - do { - nbytes = Send(msg, flags); - } while (nbytes == 0); - return nbytes; - } - - int Recv(ZmqMessage* msg) { - int nbytes = zmq_msg_recv(msg->msg(), ptr_, 0); - if (nbytes >= 0) { - return nbytes; - } else if (zmq_errno() == EAGAIN || zmq_errno() == EINTR) { - return 0; - } else { - LOG(FATAL) << "Cannot receive zmq message. Error number: " - << zmq_errno(); - return 0; - } - } - - int RecvTillSuccess(ZmqMessage* msg) { - int nbytes = 0; - do { - nbytes = Recv(msg); - } while (nbytes == 0); - return nbytes; - } - - private: - ZmqContext context_; - void* ptr_; -}; - -} // namespace caffe2 - - -#endif // CAFFE2_UTILS_ZMQ_HELPER_H_ diff --git a/app/src/main/cpp/caffe2/video/video_decoder.h b/app/src/main/cpp/caffe2/video/video_decoder.h deleted file mode 100644 index 4853753..0000000 --- a/app/src/main/cpp/caffe2/video/video_decoder.h +++ /dev/null @@ -1,386 +0,0 @@ -#ifndef CAFFE2_VIDEO_VIDEO_DECODER_H_ -#define CAFFE2_VIDEO_VIDEO_DECODER_H_ - -#include -#include -#include -#include -#include "caffe2/core/logging.h" - -extern "C" { -#include -#include -} - -namespace caffe2 { - -#define VIO_BUFFER_SZ 32768 -#define MAX_DECODING_FRAMES 10000 - -// enum to specify 3 special fps sampling behaviors: -// 0: disable fps sampling, no frame sampled at all -// -1: unlimited fps sampling, will sample at native video fps -// -2: disable fps sampling, but will get the frame at specific timestamp -enum SpecialFps { - SAMPLE_NO_FRAME = 0, - SAMPLE_ALL_FRAMES = -1, - SAMPLE_TIMESTAMP_ONLY = -2, -}; - -// sampling interval for fps starting at specified timestamp -// use enum SpecialFps to set special fps decoding behavior -// note sampled fps will not always accurately follow the target fps, -// because sampled frame has to snap to actual frame timestamp, -// e.g. video fps = 25, sample fps = 4 will sample every 0.28s, not 0.25 -// video fps = 25, sample fps = 5 will sample every 0.24s, not 0.2, -// because of floating-point division accuracy (1 / 5.0 is not exactly 0.2) -struct SampleInterval { - double timestamp; - double fps; - SampleInterval() : timestamp(-1), fps(SpecialFps::SAMPLE_ALL_FRAMES) {} - SampleInterval(double ts, double f) : timestamp(ts), fps(f) {} - bool operator<(const SampleInterval& itvl) const { - return (timestamp < itvl.timestamp); - } -}; - -class Params { - public: - // return all key-frames regardless of specified fps - bool keyFrames_ = false; - - // Output image pixel format - AVPixelFormat pixelFormat_ = AVPixelFormat::AV_PIX_FMT_RGB24; - - // Index of stream to decode. - // -1 will automatically decode the first video stream. - int streamIndex_ = -1; - - // How many frames to output at most from the video - // -1 no limit - int maximumOutputFrames_ = -1; - - // Output video size, -1 to preserve origianl dimension - int outputWidth_ = -1; - int outputHeight_ = -1; - - // max output dimension, -1 to preserve original size - // the larger dimension of the video will be scaled to this size, - // and the second dimension will be scaled to preserve aspect ratio - int maxOutputDimension_ = -1; - - // intervals_ control variable sampling fps between different timestamps - // intervals_ must be ordered strictly ascending by timestamps - // the first interval must have a timestamp of zero - // fps must be either the 3 special fps defined in SpecialFps, or > 0 - std::vector intervals_ = {{0, SpecialFps::SAMPLE_ALL_FRAMES}}; - - Params() {} - - /** - * FPS of output frames - * setting here will reset intervals_ and force decoding at target FPS - * This can be used if user just want to decode at a steady fps - */ - Params& fps(float v) { - intervals_.clear(); - intervals_.emplace_back(0, v); - return *this; - } - - /** - * Pixel format of output buffer, default PIX_FMT_RGB24 - */ - Params& pixelFormat(AVPixelFormat pixelFormat) { - pixelFormat_ = pixelFormat; - return *this; - } - - /** - * Return all key-frames - */ - Params& keyFrames(bool keyFrames) { - keyFrames_ = keyFrames; - return *this; - } - - /** - * Index of video stream to process, defaults to the first video stream - */ - Params& streamIndex(int index) { - streamIndex_ = index; - return *this; - } - - /** - * Only output this many frames, default to no limit - */ - Params& maxOutputFrames(int count) { - maximumOutputFrames_ = count; - return *this; - } - - /** - * Output frame width, default to video width - */ - Params& outputWidth(int width) { - outputWidth_ = width; - return *this; - } - - /** - * Output frame height, default to video height - */ - Params& outputHeight(int height) { - outputHeight_ = height; - return *this; - } - - /** - * Max dimension of either width or height, if any is bigger - * it will be scaled down to this and econd dimension - * will be scaled down to maintain aspect ratio. - */ - Params& maxOutputDimension(int size) { - maxOutputDimension_ = size; - return *this; - } -}; - -// data structure for storing decoded video frames -class DecodedFrame { - public: - struct avDeleter { - void operator()(unsigned char* p) const { - av_free(p); - } - }; - typedef std::unique_ptr AvDataPtr; - - // decoded data buffer - AvDataPtr data_; - - // size in bytes - int size_ = 0; - - // frame dimensions - int width_ = 0; - int height_ = 0; - - // timestamp in seconds since beginning of video - double timestamp_ = 0; - - // true if this is a key frame. - bool keyFrame_ = false; - - // index of frame in video - int index_ = -1; - - // Sequential number of outputted frame - int outputFrameIndex_ = -1; -}; - -class VideoIOContext { - public: - explicit VideoIOContext(const std::string fname) - : workBuffersize_(VIO_BUFFER_SZ), - workBuffer_((uint8_t*)av_malloc(workBuffersize_)), - inputFile_(nullptr), - inputBuffer_(nullptr), - inputBufferSize_(0) { - inputFile_ = fopen(fname.c_str(), "rb"); - if (inputFile_ == nullptr) { - LOG(ERROR) << "Error opening video file " << fname; - } - ctx_ = avio_alloc_context( - static_cast(workBuffer_.get()), - workBuffersize_, - 0, - this, - &VideoIOContext::readFile, - nullptr, // no write function - &VideoIOContext::seekFile); - } - - explicit VideoIOContext(const char* buffer, int size) - : workBuffersize_(VIO_BUFFER_SZ), - workBuffer_((uint8_t*)av_malloc(workBuffersize_)), - inputFile_(nullptr), - inputBuffer_(buffer), - inputBufferSize_(size) { - ctx_ = avio_alloc_context( - static_cast(workBuffer_.get()), - workBuffersize_, - 0, - this, - &VideoIOContext::readMemory, - nullptr, // no write function - &VideoIOContext::seekMemory); - } - - ~VideoIOContext() { - av_free(ctx_); - if (inputFile_) { - fclose(inputFile_); - } - } - - int read(unsigned char* buf, int buf_size) { - if (inputBuffer_) { - return readMemory(this, buf, buf_size); - } else if (inputFile_) { - return readFile(this, buf, buf_size); - } else { - return -1; - } - } - - int64_t seek(int64_t offset, int whence) { - if (inputBuffer_) { - return seekMemory(this, offset, whence); - } else if (inputFile_) { - return seekFile(this, offset, whence); - } else { - return -1; - } - } - - static int readFile(void* opaque, unsigned char* buf, int buf_size) { - VideoIOContext* h = static_cast(opaque); - if (feof(h->inputFile_)) { - return AVERROR_EOF; - } - size_t ret = fread(buf, 1, buf_size, h->inputFile_); - if (ret < buf_size) { - if (ferror(h->inputFile_)) { - return -1; - } - } - return ret; - } - - static int64_t seekFile(void* opaque, int64_t offset, int whence) { - VideoIOContext* h = static_cast(opaque); - switch (whence) { - case SEEK_CUR: // from current position - case SEEK_END: // from eof - case SEEK_SET: // from beginning of file - return fseek(h->inputFile_, static_cast(offset), whence); - break; - case AVSEEK_SIZE: - int64_t cur = ftell(h->inputFile_); - fseek(h->inputFile_, 0L, SEEK_END); - int64_t size = ftell(h->inputFile_); - fseek(h->inputFile_, cur, SEEK_SET); - return size; - } - - return -1; - } - - static int readMemory(void* opaque, unsigned char* buf, int buf_size) { - VideoIOContext* h = static_cast(opaque); - if (buf_size < 0) { - return -1; - } - - int reminder = h->inputBufferSize_ - h->offset_; - int r = buf_size < reminder ? buf_size : reminder; - if (r < 0) { - return AVERROR_EOF; - } - - memcpy(buf, h->inputBuffer_ + h->offset_, r); - h->offset_ += r; - return r; - } - - static int64_t seekMemory(void* opaque, int64_t offset, int whence) { - VideoIOContext* h = static_cast(opaque); - switch (whence) { - case SEEK_CUR: // from current position - h->offset_ += offset; - break; - case SEEK_END: // from eof - h->offset_ = h->inputBufferSize_ + offset; - break; - case SEEK_SET: // from beginning of file - h->offset_ = offset; - break; - case AVSEEK_SIZE: - return h->inputBufferSize_; - } - return h->offset_; - } - - AVIOContext* get_avio() { - return ctx_; - } - - private: - int workBuffersize_; - DecodedFrame::AvDataPtr workBuffer_; - // for file mode - FILE* inputFile_; - - // for memory mode - const char* inputBuffer_; - int inputBufferSize_; - int offset_ = 0; - - AVIOContext* ctx_; -}; - -struct VideoMeta { - double fps; - int width; - int height; - enum AVMediaType codec_type; - AVPixelFormat pixFormat; - VideoMeta() - : fps(-1), - width(-1), - height(-1), - codec_type(AVMEDIA_TYPE_VIDEO), - pixFormat(AVPixelFormat::AV_PIX_FMT_RGB24) {} -}; - -class VideoDecoder { - public: - VideoDecoder(); - - void decodeFile( - const std::string filename, - const Params& params, - std::vector>& sampledFrames, - int maxFrames = 0, /* max frames we want decoded. 0 implies decode all */ - bool decodeFromStart = true /* decode from start or randomly seek into - intermediate frame ? */ - ); - - void decodeMemory( - const char* buffer, - const int size, - const Params& params, - std::vector>& sampledFrames, - int maxFrames = 0, /* max frames we want decoded. 0 implies decode all */ - bool decodeFromStart = true /* decode from start or randomly seek into - intermediate frame ? */ - ); - - private: - std::string ffmpegErrorStr(int result); - - void decodeLoop( - const std::string& videoName, - VideoIOContext& ioctx, - const Params& params, - std::vector>& sampledFrames, - int maxFrames = 0, /* max frames we want decoded. 0 implies decode all */ - bool decodeFromStart = true /* decode from start or randomly seek into - intermediate frame ? */ - ); -}; -} - -#endif // CAFFE2_VIDEO_VIDEO_DECODER_H_ diff --git a/app/src/main/cpp/caffe2/video/video_input_op.h b/app/src/main/cpp/caffe2/video/video_input_op.h deleted file mode 100644 index c86e7f2..0000000 --- a/app/src/main/cpp/caffe2/video/video_input_op.h +++ /dev/null @@ -1,397 +0,0 @@ -#ifndef CAFFE2_VIDEO_VIDEO_INPUT_OP_H_ -#define CAFFE2_VIDEO_VIDEO_INPUT_OP_H_ - -#include -#include -#include - -#include - -#include "caffe2/core/db.h" -#include "caffe2/core/logging.h" -#include "caffe2/operators/prefetch_op.h" -#include "caffe2/utils/math.h" -#include "caffe2/utils/thread_pool.h" -#include "caffe2/video/video_io.h" - -namespace caffe2 { - -template -class VideoInputOp final : public PrefetchOperator { - public: - using OperatorBase::OutputSize; - using PrefetchOperator::context_; - using PrefetchOperator::prefetch_thread_; - explicit VideoInputOp(const OperatorDef& operator_def, Workspace* ws); - ~VideoInputOp() { - PrefetchOperator::Finalize(); - } - - // override methods - bool Prefetch() override; - bool CopyPrefetched() override; - - private: - bool GetClipAndLabelFromDBValue( - const std::string& value, - float*& buffer, - int* label_data, - std::mt19937* randgen); - - void DecodeAndTransform( - const std::string value, - float* clip_data, - int* label_data, - const int crop_size, - const bool mirror, - const float mean, - const float std, - std::mt19937* randgen, - std::bernoulli_distribution* mirror_this_clip); - - const db::DBReader* reader_; - CPUContext cpu_context_; - TensorCPU prefetched_clip_; - TensorCPU prefetched_label_; - Tensor prefetched_clip_on_device_; - Tensor prefetched_label_on_device_; - int batch_size_; - float mean_; - float std_; - int crop_; - int scale_h_; - int scale_w_; - int length_; - int sampling_rate_; - bool mirror_; - bool temporal_jitter_; - bool use_image_; - bool multiple_label_; - int num_of_labels_; - bool use_local_file_; - bool is_test_; - std::string im_extension_; - - // thread pool for parse + decode - int num_decode_threads_; - std::shared_ptr thread_pool_; -}; - -template -VideoInputOp::VideoInputOp( - const OperatorDef& operator_def, - Workspace* ws) - : PrefetchOperator(operator_def, ws), - reader_(nullptr), - batch_size_( - OperatorBase::template GetSingleArgument("batch_size", 0)), - mean_(OperatorBase::template GetSingleArgument("mean", 0.)), - std_(OperatorBase::template GetSingleArgument("std", 1.)), - crop_(OperatorBase::template GetSingleArgument("crop", -1)), - scale_h_(OperatorBase::template GetSingleArgument("height", 0)), - scale_w_(OperatorBase::template GetSingleArgument("width", 0)), - length_(OperatorBase::template GetSingleArgument("length", 0)), - sampling_rate_( - OperatorBase::template GetSingleArgument("sampling_rate", 1)), - mirror_(OperatorBase::template GetSingleArgument("mirror", 0)), - temporal_jitter_( - OperatorBase::template GetSingleArgument("temporal_jitter", 1)), - use_image_(OperatorBase::template GetSingleArgument("use_image", 0)), - multiple_label_( - OperatorBase::template GetSingleArgument("multiple_label", 0)), - num_of_labels_( - OperatorBase::template GetSingleArgument("num_of_labels", 0)), - use_local_file_( - OperatorBase::template GetSingleArgument("use_local_file", 0)), - is_test_(OperatorBase::template GetSingleArgument( - OpSchema::Arg_IsTest, - 0)), - im_extension_( - OperatorBase::template GetSingleArgument("im_extension", "")), - num_decode_threads_( - OperatorBase::template GetSingleArgument("decode_threads", 4)), - - thread_pool_(new TaskThreadPool(num_decode_threads_)) { - CAFFE_ENFORCE_GT(batch_size_, 0, "Batch size should be nonnegative."); - CAFFE_ENFORCE_GE(scale_h_, 0, "Must provide the scale value."); - CAFFE_ENFORCE_GE(scale_w_, 0, "Must provide the cropping value."); - CAFFE_ENFORCE_GT(length_, 0, "Must provide the clip length value."); - CAFFE_ENFORCE_GT(crop_, 0, "Must provide the cropping value."); - CAFFE_ENFORCE_GE( - scale_h_, - crop_, - "The scaled height must be no smaller than the crop value."); - CAFFE_ENFORCE_GE( - scale_w_, - crop_, - "The scaled width must be no smaller than the crop value."); - if (multiple_label_) { - CAFFE_ENFORCE_GT( - num_of_labels_, - 0, - "Number of labels must be set for using multiple label output."); - } - - // Always need a dbreader, even when using local video files - CAFFE_ENFORCE_GT( - operator_def.input_size(), 0, "Need to have a DBReader blob input"); - - LOG(INFO) << "Creating a clip input op with the following setting: "; - LOG(INFO) << " Using " << num_decode_threads_ << " CPU threads;"; - if (temporal_jitter_) { - LOG(INFO) << " Using temporal jittering;"; - } - LOG(INFO) << " Outputting in batches of " << batch_size_ << " images;"; - LOG(INFO) << " Scaling image to " << scale_h_ << "x" << scale_w_; - - LOG(INFO) << " Cropping video frame to " << crop_ - << (mirror_ ? " with " : " without ") << "random mirroring;"; - LOG(INFO) << " Using " << (is_test_ ? "center" : "random") << " crop"; - LOG(INFO) << " Using a clip of " << length_ << " frames;"; - LOG(INFO) << " Using a sampling rate of 1:" << sampling_rate_; - LOG(INFO) << " Subtract mean " << mean_ << " and divide by std " << std_ - << "."; - vector data_shape(5); - vector label_shape(2); - - data_shape[0] = batch_size_; - // Assume color videos, will convert to 3 channels, even with black & with - // input videos - data_shape[1] = 3; - data_shape[2] = length_; - data_shape[3] = crop_; - data_shape[4] = crop_; - prefetched_clip_.Resize(data_shape); - - // If multiple label is used, outout label is a binary vector of length - // number of labels-dim in indicating which labels present - if (multiple_label_) { - label_shape[0] = batch_size_; - label_shape[1] = num_of_labels_; - prefetched_label_.Resize(label_shape); - } else { - prefetched_label_.Resize(vector(1, batch_size_)); - } -} - -template -bool VideoInputOp::GetClipAndLabelFromDBValue( - const string& value, - float*& buffer, - int* label_data, - std::mt19937* randgen) { - TensorProtos protos; - CAFFE_ENFORCE(protos.ParseFromString(value)); - const TensorProto& video_proto = protos.protos(0); - const TensorProto& label_proto = protos.protos(1); - - int start_frm = -1; - if (!temporal_jitter_) { - const TensorProto& start_frm_proto = protos.protos(2); - start_frm = start_frm_proto.int32_data(0); - } - - // assign labels - if (!multiple_label_) { - label_data[0] = label_proto.int32_data(0); - } else { - // For multiple label case, output label is a binary vector - // where presented concepts are makred 1 - memset(label_data, 0, sizeof(int) * num_of_labels_); - for (int i = 0; i < label_proto.int32_data_size(); i++) { - label_data[label_proto.int32_data(i)] = 1; - } - } - - if (use_local_file_) { - CAFFE_ENFORCE_EQ( - video_proto.data_type(), - TensorProto::STRING, - "Database with a file_list is expected to be string data"); - } - - if (video_proto.data_type() == TensorProto::STRING) { - const string& encoded_video_str = video_proto.string_data(0); - int encoded_size = encoded_video_str.size(); - if (!use_local_file_) { - DecodeClipFromMemoryBuffer( - const_cast(encoded_video_str.data()), - encoded_size, - start_frm, - length_, - scale_h_, - scale_w_, - sampling_rate_, - buffer, - randgen); - } else { - // encoded string contains an absolute path to a local file or folder - std::string filename = encoded_video_str; - if (use_image_) { - CAFFE_ENFORCE( - !temporal_jitter_, - "Temporal jittering is not suported for image sequence input" - ); - CHECK(ReadClipFromFrames( - filename, - start_frm, - im_extension_, - length_, - scale_h_, - scale_w_, - sampling_rate_, - buffer)); - } else { - if (temporal_jitter_) { - int num_of_frames = GetNumberOfFrames(filename); - start_frm = std::uniform_int_distribution<>( - 0, num_of_frames - length_ * sampling_rate_ + 1)(*randgen); - CHECK(DecodeClipFromVideoFile( - filename, - start_frm, - length_, - scale_h_, - scale_w_, - sampling_rate_, - buffer)); - } else { - CHECK(DecodeClipFromVideoFile( - filename, - start_frm, - length_, - scale_h_, - scale_w_, - sampling_rate_, - buffer)); - } - } - } - } else if (video_proto.data_type() == TensorProto::BYTE) { - DecodeClipFromMemoryBuffer( - video_proto.byte_data().data(), - video_proto.byte_data().size(), - start_frm, - length_, - scale_h_, - scale_w_, - sampling_rate_, - buffer, - randgen); - } else { - LOG(FATAL) << "Unknown video data type."; - } - return true; -} - -template -void VideoInputOp::DecodeAndTransform( - const std::string value, - float* clip_data, - int* label_data, - const int crop_size, - const bool mirror, - const float mean, - const float std, - std::mt19937* randgen, - std::bernoulli_distribution* mirror_this_clip) { - float* buffer = nullptr; - - // Decode the video from memory or read from a local file - CHECK(GetClipAndLabelFromDBValue(value, buffer, label_data, randgen)); - - if (buffer) { - ClipTransform( - buffer, - 3, - length_, - scale_h_, - scale_w_, - crop_size, - mirror, - mean, - std, - clip_data, - randgen, - mirror_this_clip, - is_test_); - - delete[] buffer; - } -} - -template -bool VideoInputOp::Prefetch() { - // We will get the reader pointer from input. - // If we use local clips, db will store the list - reader_ = &OperatorBase::Input(0); - - const int channels = 3; - - // Call mutable_data() once to allocate the underlying memory. - prefetched_clip_.mutable_data(); - prefetched_label_.mutable_data(); - - // Prefetching handled with a thread pool of "decode_threads" threads. - std::mt19937 meta_randgen(time(nullptr)); - std::vector randgen_per_thread; - for (int i = 0; i < num_decode_threads_; ++i) { - randgen_per_thread.emplace_back(meta_randgen()); - } - - std::bernoulli_distribution mirror_this_clip(0.5); - for (int item_id = 0; item_id < batch_size_; ++item_id) { - std::mt19937* randgen = &randgen_per_thread[item_id % num_decode_threads_]; - - // get the label data pointer for the item_id -th example - int* label_data = prefetched_label_.mutable_data() + - (multiple_label_ ? num_of_labels_ : 1) * item_id; - - // get the clip data pointer for the item_id -th example - float* clip_data = prefetched_clip_.mutable_data() + - crop_ * crop_ * length_ * channels * item_id; - - std::string key, value; - // read data - reader_->Read(&key, &value); - - thread_pool_->runTask(std::bind( - &VideoInputOp::DecodeAndTransform, - this, - std::string(value), - clip_data, - label_data, - crop_, - mirror_, - mean_, - std_, - randgen, - &mirror_this_clip)); - } // for over the batch - thread_pool_->waitWorkComplete(); - - // If the context is not CPUContext, we will need to do a copy in the - // prefetch function as well. - if (!std::is_same::value) { - prefetched_clip_on_device_.CopyFrom(prefetched_clip_, &context_); - prefetched_label_on_device_.CopyFrom(prefetched_label_, &context_); - } - return true; -} - -template -bool VideoInputOp::CopyPrefetched() { - auto* clip_output = OperatorBase::Output>(0); - auto* label_output = OperatorBase::Output>(1); - if (std::is_same::value) { - clip_output->CopyFrom(prefetched_clip_, &context_); - label_output->CopyFrom(prefetched_label_, &context_); - } else { - clip_output->CopyFrom(prefetched_clip_on_device_, &context_); - label_output->CopyFrom(prefetched_label_on_device_, &context_); - } - return true; -} - -} // namespace caffe2 - -#endif // CAFFE2_VIDEO_VIDEO_INPUT_OP_H_ diff --git a/app/src/main/cpp/caffe2/video/video_io.h b/app/src/main/cpp/caffe2/video/video_io.h deleted file mode 100644 index 15d0cc0..0000000 --- a/app/src/main/cpp/caffe2/video/video_io.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef CAFFE2_VIDEO_VIDEO_IO_H_ -#define CAFFE2_VIDEO_VIDEO_IO_H_ - -#include -#include -#include "caffe/proto/caffe.pb.h" - -#include - -namespace caffe2 { - -void ImageChannelToBuffer(const cv::Mat* img, float* buffer, int c); - -void ImageDataToBuffer( - unsigned char* data_buffer, - int height, - int width, - float* buffer, - int c); - -int GetNumberOfFrames(std::string filename); - -double GetVideoFPS(std::string filename); - -void GetVideoMeta(std::string filename, int& number_of_frames, double& fps); - -void ClipTransform( - const float* clip_data, - const int channels, - const int length, - const int height, - const int width, - const int crop, - const bool mirror, - float mean, - float std, - float* transformed_clip, - std::mt19937* randgen, - std::bernoulli_distribution* mirror_this_clip, - const bool use_center_crop); - -bool ReadClipFromFrames( - std::string input_dir, - const int start_frm, - std::string file_extension, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer); - -bool ReadClipFromVideoLazzy( - std::string filename, - const int start_frm, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer); - -bool ReadClipFromVideoSequential( - std::string filename, - const int start_frm, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer); - -bool ReadClipFromVideo( - std::string filename, - const int start_frm, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer); - -bool DecodeClipFromVideoFile( - std::string filename, - const int start_frm, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer); - -bool DecodeClipFromMemoryBuffer( - const char* video_buffer, - const int size, - const int start_frm, - const int length, - const int height, - const int width, - const int sampling_rate, - float*& buffer, - std::mt19937* randgen); -} - -#endif // CAFFE2_VIDEO_VIDEO_IO_H_ diff --git a/app/src/main/cpp/google/protobuf/any.h b/app/src/main/cpp/google/protobuf/any.h deleted file mode 100644 index 04e5416..0000000 --- a/app/src/main/cpp/google/protobuf/any.h +++ /dev/null @@ -1,107 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_ANY_H__ -#define GOOGLE_PROTOBUF_ANY_H__ - -#include - -#include -#include -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Helper class used to implement google::protobuf::Any. -class LIBPROTOBUF_EXPORT AnyMetadata { - typedef ArenaStringPtr UrlType; - typedef ArenaStringPtr ValueType; - public: - // AnyMetadata does not take ownership of "type_url" and "value". - AnyMetadata(UrlType* type_url, ValueType* value); - - // Packs a message using the default type URL prefix: "type.googleapis.com". - // The resulted type URL will be "type.googleapis.com/". - void PackFrom(const Message& message); - // Packs a message using the given type URL prefix. The type URL will be - // constructed by concatenating the message type's full name to the prefix - // with an optional "/" separator if the prefix doesn't already end up "/". - // For example, both PackFrom(message, "type.googleapis.com") and - // PackFrom(message, "type.googleapis.com/") yield the same result type - // URL: "type.googleapis.com/". - void PackFrom(const Message& message, const string& type_url_prefix); - - // Unpacks the payload into the given message. Returns false if the message's - // type doesn't match the type specified in the type URL (i.e., the full - // name after the last "/" of the type URL doesn't match the message's actaul - // full name) or parsing the payload has failed. - bool UnpackTo(Message* message) const; - - // Checks whether the type specified in the type URL matches the given type. - // A type is consdiered matching if its full name matches the full name after - // the last "/" in the type URL. - template - bool Is() const { - return InternalIs(T::default_instance().GetDescriptor()); - } - - private: - bool InternalIs(const Descriptor* message) const; - - UrlType* type_url_; - ValueType* value_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(AnyMetadata); -}; - -extern const char kAnyFullTypeName[]; // "google.protobuf.Any". -extern const char kTypeGoogleApisComPrefix[]; // "type.googleapis.com/". -extern const char kTypeGoogleProdComPrefix[]; // "type.googleprod.com/". - -// Get the proto type name from Any::type_url value. For example, passing -// "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in -// *full_type_name. Returns false if type_url does not start with -// "type.googleapis.com" or "type.googleprod.com". -bool ParseAnyTypeUrl(const string& type_url, string* full_type_name); - -// See if message is of type google.protobuf.Any, if so, return the descriptors -// for "type_url" and "value" fields. -bool GetAnyFieldDescriptors(const Message& message, - const FieldDescriptor** type_url_field, - const FieldDescriptor** value_field); - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_ANY_H__ diff --git a/app/src/main/cpp/google/protobuf/any.pb.h b/app/src/main/cpp/google/protobuf/any.pb.h deleted file mode 100644 index 0641e24..0000000 --- a/app/src/main/cpp/google/protobuf/any.pb.h +++ /dev/null @@ -1,266 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/any.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fany_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fany_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto(); - -class Any; - -// =================================================================== - -class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Any) */ { - public: - Any(); - virtual ~Any(); - - Any(const Any& from); - - inline Any& operator=(const Any& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Any& default_instance(); - - static const Any* internal_default_instance(); - - // implements Any ----------------------------------------------- - - void PackFrom(const ::google::protobuf::Message& message); - void PackFrom(const ::google::protobuf::Message& message, - const ::std::string& type_url_prefix); - bool UnpackTo(::google::protobuf::Message* message) const; - template bool Is() const { - return _any_metadata_.Is(); - } - - void Swap(Any* other); - - // implements Message ---------------------------------------------- - - inline Any* New() const { return New(NULL); } - - Any* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Any& from); - void MergeFrom(const Any& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Any* other); - void UnsafeMergeFrom(const Any& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string type_url = 1; - void clear_type_url(); - static const int kTypeUrlFieldNumber = 1; - const ::std::string& type_url() const; - void set_type_url(const ::std::string& value); - void set_type_url(const char* value); - void set_type_url(const char* value, size_t size); - ::std::string* mutable_type_url(); - ::std::string* release_type_url(); - void set_allocated_type_url(::std::string* type_url); - - // optional bytes value = 2; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::std::string& value() const; - void set_value(const ::std::string& value); - void set_value(const char* value); - void set_value(const void* value, size_t size); - ::std::string* mutable_value(); - ::std::string* release_value(); - void set_allocated_value(::std::string* value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Any) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::ArenaStringPtr type_url_; - ::google::protobuf::internal::ArenaStringPtr value_; - mutable int _cached_size_; - ::google::protobuf::internal::AnyMetadata _any_metadata_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fany_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fany_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fany_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fany_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Any_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Any - -// optional string type_url = 1; -inline void Any::clear_type_url() { - type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Any::type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Any.type_url) - return type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Any::set_type_url(const ::std::string& value) { - - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Any.type_url) -} -inline void Any::set_type_url(const char* value) { - - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Any.type_url) -} -inline void Any::set_type_url(const char* value, size_t size) { - - type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.type_url) -} -inline ::std::string* Any::mutable_type_url() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Any.type_url) - return type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Any::release_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Any.type_url) - - return type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Any::set_allocated_type_url(::std::string* type_url) { - if (type_url != NULL) { - - } else { - - } - type_url_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type_url); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.type_url) -} - -// optional bytes value = 2; -inline void Any::clear_value() { - value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Any::value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Any.value) - return value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Any::set_value(const ::std::string& value) { - - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Any.value) -} -inline void Any::set_value(const char* value) { - - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Any.value) -} -inline void Any::set_value(const void* value, size_t size) { - - value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Any.value) -} -inline ::std::string* Any::mutable_value() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Any.value) - return value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Any::release_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Any.value) - - return value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Any::set_allocated_value(::std::string* value) { - if (value != NULL) { - - } else { - - } - value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value) -} - -inline const Any* Any::internal_default_instance() { - return &Any_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fany_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/any.proto b/app/src/main/cpp/google/protobuf/any.proto deleted file mode 100644 index 9bd3f50..0000000 --- a/app/src/main/cpp/google/protobuf/any.proto +++ /dev/null @@ -1,139 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/any"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "AnyProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// `Any` contains an arbitrary serialized protocol buffer message along with a -// URL that describes the type of the serialized message. -// -// Protobuf library provides support to pack/unpack Any values in the form -// of utility functions or additional generated methods of the Any type. -// -// Example 1: Pack and unpack a message in C++. -// -// Foo foo = ...; -// Any any; -// any.PackFrom(foo); -// ... -// if (any.UnpackTo(&foo)) { -// ... -// } -// -// Example 2: Pack and unpack a message in Java. -// -// Foo foo = ...; -// Any any = Any.pack(foo); -// ... -// if (any.is(Foo.class)) { -// foo = any.unpack(Foo.class); -// } -// -// Example 3: Pack and unpack a message in Python. -// -// foo = Foo(...) -// any = Any() -// any.Pack(foo) -// ... -// if any.Is(Foo.DESCRIPTOR): -// any.Unpack(foo) -// ... -// -// The pack methods provided by protobuf library will by default use -// 'type.googleapis.com/full.type.name' as the type URL and the unpack -// methods only use the fully qualified type name after the last '/' -// in the type URL, for example "foo.bar.com/x/y.z" will yield type -// name "y.z". -// -// -// JSON -// ==== -// The JSON representation of an `Any` value uses the regular -// representation of the deserialized, embedded message, with an -// additional field `@type` which contains the type URL. Example: -// -// package google.profile; -// message Person { -// string first_name = 1; -// string last_name = 2; -// } -// -// { -// "@type": "type.googleapis.com/google.profile.Person", -// "firstName": , -// "lastName": -// } -// -// If the embedded message type is well-known and has a custom JSON -// representation, that representation will be embedded adding a field -// `value` which holds the custom JSON in addition to the `@type` -// field. Example (for message [google.protobuf.Duration][]): -// -// { -// "@type": "type.googleapis.com/google.protobuf.Duration", -// "value": "1.212s" -// } -// -message Any { - // A URL/resource name whose content describes the type of the - // serialized protocol buffer message. - // - // For URLs which use the scheme `http`, `https`, or no scheme, the - // following restrictions and interpretations apply: - // - // * If no scheme is provided, `https` is assumed. - // * The last segment of the URL's path must represent the fully - // qualified name of the type (as in `path/google.protobuf.Duration`). - // The name should be in a canonical form (e.g., leading "." is - // not accepted). - // * An HTTP GET on the URL must yield a [google.protobuf.Type][] - // value in binary format, or produce an error. - // * Applications are allowed to cache lookup results based on the - // URL, or have them precompiled into a binary to avoid any - // lookup. Therefore, binary compatibility needs to be preserved - // on changes to types. (Use versioned type names to manage - // breaking changes.) - // - // Schemes other than `http`, `https` (or the empty scheme) might be - // used with implementation specific semantics. - // - string type_url = 1; - - // Must be a valid serialized protocol buffer of the above specified type. - bytes value = 2; -} diff --git a/app/src/main/cpp/google/protobuf/api.pb.h b/app/src/main/cpp/google/protobuf/api.pb.h deleted file mode 100644 index 9410286..0000000 --- a/app/src/main/cpp/google/protobuf/api.pb.h +++ /dev/null @@ -1,1019 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/api.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fapi_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fapi_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); - -class Api; -class Method; -class Mixin; - -// =================================================================== - -class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Api) */ { - public: - Api(); - virtual ~Api(); - - Api(const Api& from); - - inline Api& operator=(const Api& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Api& default_instance(); - - static const Api* internal_default_instance(); - - void Swap(Api* other); - - // implements Message ---------------------------------------------- - - inline Api* New() const { return New(NULL); } - - Api* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Api& from); - void MergeFrom(const Api& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Api* other); - void UnsafeMergeFrom(const Api& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .google.protobuf.Method methods = 2; - int methods_size() const; - void clear_methods(); - static const int kMethodsFieldNumber = 2; - const ::google::protobuf::Method& methods(int index) const; - ::google::protobuf::Method* mutable_methods(int index); - ::google::protobuf::Method* add_methods(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method >* - mutable_methods(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method >& - methods() const; - - // repeated .google.protobuf.Option options = 3; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // optional string version = 4; - void clear_version(); - static const int kVersionFieldNumber = 4; - const ::std::string& version() const; - void set_version(const ::std::string& value); - void set_version(const char* value); - void set_version(const char* value, size_t size); - ::std::string* mutable_version(); - ::std::string* release_version(); - void set_allocated_version(::std::string* version); - - // optional .google.protobuf.SourceContext source_context = 5; - bool has_source_context() const; - void clear_source_context(); - static const int kSourceContextFieldNumber = 5; - const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); - ::google::protobuf::SourceContext* release_source_context(); - void set_allocated_source_context(::google::protobuf::SourceContext* source_context); - - // repeated .google.protobuf.Mixin mixins = 6; - int mixins_size() const; - void clear_mixins(); - static const int kMixinsFieldNumber = 6; - const ::google::protobuf::Mixin& mixins(int index) const; - ::google::protobuf::Mixin* mutable_mixins(int index); - ::google::protobuf::Mixin* add_mixins(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >* - mutable_mixins(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >& - mixins() const; - - // optional .google.protobuf.Syntax syntax = 7; - void clear_syntax(); - static const int kSyntaxFieldNumber = 7; - ::google::protobuf::Syntax syntax() const; - void set_syntax(::google::protobuf::Syntax value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Api) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method > methods_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin > mixins_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr version_; - ::google::protobuf::SourceContext* source_context_; - int syntax_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Api_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Method) */ { - public: - Method(); - virtual ~Method(); - - Method(const Method& from); - - inline Method& operator=(const Method& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Method& default_instance(); - - static const Method* internal_default_instance(); - - void Swap(Method* other); - - // implements Message ---------------------------------------------- - - inline Method* New() const { return New(NULL); } - - Method* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Method& from); - void MergeFrom(const Method& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Method* other); - void UnsafeMergeFrom(const Method& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string request_type_url = 2; - void clear_request_type_url(); - static const int kRequestTypeUrlFieldNumber = 2; - const ::std::string& request_type_url() const; - void set_request_type_url(const ::std::string& value); - void set_request_type_url(const char* value); - void set_request_type_url(const char* value, size_t size); - ::std::string* mutable_request_type_url(); - ::std::string* release_request_type_url(); - void set_allocated_request_type_url(::std::string* request_type_url); - - // optional bool request_streaming = 3; - void clear_request_streaming(); - static const int kRequestStreamingFieldNumber = 3; - bool request_streaming() const; - void set_request_streaming(bool value); - - // optional string response_type_url = 4; - void clear_response_type_url(); - static const int kResponseTypeUrlFieldNumber = 4; - const ::std::string& response_type_url() const; - void set_response_type_url(const ::std::string& value); - void set_response_type_url(const char* value); - void set_response_type_url(const char* value, size_t size); - ::std::string* mutable_response_type_url(); - ::std::string* release_response_type_url(); - void set_allocated_response_type_url(::std::string* response_type_url); - - // optional bool response_streaming = 5; - void clear_response_streaming(); - static const int kResponseStreamingFieldNumber = 5; - bool response_streaming() const; - void set_response_streaming(bool value); - - // repeated .google.protobuf.Option options = 6; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 6; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // optional .google.protobuf.Syntax syntax = 7; - void clear_syntax(); - static const int kSyntaxFieldNumber = 7; - ::google::protobuf::Syntax syntax() const; - void set_syntax(::google::protobuf::Syntax value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Method) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr request_type_url_; - ::google::protobuf::internal::ArenaStringPtr response_type_url_; - bool request_streaming_; - bool response_streaming_; - int syntax_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Method_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Mixin) */ { - public: - Mixin(); - virtual ~Mixin(); - - Mixin(const Mixin& from); - - inline Mixin& operator=(const Mixin& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const Mixin& default_instance(); - - static const Mixin* internal_default_instance(); - - void Swap(Mixin* other); - - // implements Message ---------------------------------------------- - - inline Mixin* New() const { return New(NULL); } - - Mixin* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Mixin& from); - void MergeFrom(const Mixin& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Mixin* other); - void UnsafeMergeFrom(const Mixin& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string root = 2; - void clear_root(); - static const int kRootFieldNumber = 2; - const ::std::string& root() const; - void set_root(const ::std::string& value); - void set_root(const char* value); - void set_root(const char* value, size_t size); - ::std::string* mutable_root(); - ::std::string* release_root(); - void set_allocated_root(::std::string* root); - - // @@protoc_insertion_point(class_scope:google.protobuf.Mixin) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr root_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fapi_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fapi_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fapi_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fapi_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Mixin_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Api - -// optional string name = 1; -inline void Api::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Api::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Api::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Api.name) -} -inline void Api::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Api.name) -} -inline void Api::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.name) -} -inline ::std::string* Api::mutable_name() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Api::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.name) - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Api::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.name) -} - -// repeated .google.protobuf.Method methods = 2; -inline int Api::methods_size() const { - return methods_.size(); -} -inline void Api::clear_methods() { - methods_.Clear(); -} -inline const ::google::protobuf::Method& Api::methods(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.methods) - return methods_.Get(index); -} -inline ::google::protobuf::Method* Api::mutable_methods(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.methods) - return methods_.Mutable(index); -} -inline ::google::protobuf::Method* Api::add_methods() { - // @@protoc_insertion_point(field_add:google.protobuf.Api.methods) - return methods_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method >* -Api::mutable_methods() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.methods) - return &methods_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Method >& -Api::methods() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.methods) - return methods_; -} - -// repeated .google.protobuf.Option options = 3; -inline int Api::options_size() const { - return options_.size(); -} -inline void Api::clear_options() { - options_.Clear(); -} -inline const ::google::protobuf::Option& Api::options(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.options) - return options_.Get(index); -} -inline ::google::protobuf::Option* Api::mutable_options(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.options) - return options_.Mutable(index); -} -inline ::google::protobuf::Option* Api::add_options() { - // @@protoc_insertion_point(field_add:google.protobuf.Api.options) - return options_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* -Api::mutable_options() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.options) - return &options_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& -Api::options() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.options) - return options_; -} - -// optional string version = 4; -inline void Api::clear_version() { - version_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Api::version() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.version) - return version_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Api::set_version(const ::std::string& value) { - - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Api.version) -} -inline void Api::set_version(const char* value) { - - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Api.version) -} -inline void Api::set_version(const char* value, size_t size) { - - version_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Api.version) -} -inline ::std::string* Api::mutable_version() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.version) - return version_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Api::release_version() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.version) - - return version_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Api::set_allocated_version(::std::string* version) { - if (version != NULL) { - - } else { - - } - version_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), version); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.version) -} - -// optional .google.protobuf.SourceContext source_context = 5; -inline bool Api::has_source_context() const { - return this != internal_default_instance() && source_context_ != NULL; -} -inline void Api::clear_source_context() { - if (GetArenaNoVirtual() == NULL && source_context_ != NULL) delete source_context_; - source_context_ = NULL; -} -inline const ::google::protobuf::SourceContext& Api::source_context() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); -} -inline ::google::protobuf::SourceContext* Api::mutable_source_context() { - - if (source_context_ == NULL) { - source_context_ = new ::google::protobuf::SourceContext; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.source_context) - return source_context_; -} -inline ::google::protobuf::SourceContext* Api::release_source_context() { - // @@protoc_insertion_point(field_release:google.protobuf.Api.source_context) - - ::google::protobuf::SourceContext* temp = source_context_; - source_context_ = NULL; - return temp; -} -inline void Api::set_allocated_source_context(::google::protobuf::SourceContext* source_context) { - delete source_context_; - source_context_ = source_context; - if (source_context) { - - } else { - - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Api.source_context) -} - -// repeated .google.protobuf.Mixin mixins = 6; -inline int Api::mixins_size() const { - return mixins_.size(); -} -inline void Api::clear_mixins() { - mixins_.Clear(); -} -inline const ::google::protobuf::Mixin& Api::mixins(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.mixins) - return mixins_.Get(index); -} -inline ::google::protobuf::Mixin* Api::mutable_mixins(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Api.mixins) - return mixins_.Mutable(index); -} -inline ::google::protobuf::Mixin* Api::add_mixins() { - // @@protoc_insertion_point(field_add:google.protobuf.Api.mixins) - return mixins_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >* -Api::mutable_mixins() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Api.mixins) - return &mixins_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Mixin >& -Api::mixins() const { - // @@protoc_insertion_point(field_list:google.protobuf.Api.mixins) - return mixins_; -} - -// optional .google.protobuf.Syntax syntax = 7; -inline void Api::clear_syntax() { - syntax_ = 0; -} -inline ::google::protobuf::Syntax Api::syntax() const { - // @@protoc_insertion_point(field_get:google.protobuf.Api.syntax) - return static_cast< ::google::protobuf::Syntax >(syntax_); -} -inline void Api::set_syntax(::google::protobuf::Syntax value) { - - syntax_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Api.syntax) -} - -inline const Api* Api::internal_default_instance() { - return &Api_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// Method - -// optional string name = 1; -inline void Method::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Method::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.name) -} -inline void Method::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Method.name) -} -inline void Method::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.name) -} -inline ::std::string* Method::mutable_name() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Method::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.name) - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.name) -} - -// optional string request_type_url = 2; -inline void Method::clear_request_type_url() { - request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Method::request_type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.request_type_url) - return request_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_request_type_url(const ::std::string& value) { - - request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.request_type_url) -} -inline void Method::set_request_type_url(const char* value) { - - request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Method.request_type_url) -} -inline void Method::set_request_type_url(const char* value, size_t size) { - - request_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.request_type_url) -} -inline ::std::string* Method::mutable_request_type_url() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.request_type_url) - return request_type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Method::release_request_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.request_type_url) - - return request_type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_allocated_request_type_url(::std::string* request_type_url) { - if (request_type_url != NULL) { - - } else { - - } - request_type_url_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), request_type_url); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.request_type_url) -} - -// optional bool request_streaming = 3; -inline void Method::clear_request_streaming() { - request_streaming_ = false; -} -inline bool Method::request_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.request_streaming) - return request_streaming_; -} -inline void Method::set_request_streaming(bool value) { - - request_streaming_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Method.request_streaming) -} - -// optional string response_type_url = 4; -inline void Method::clear_response_type_url() { - response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Method::response_type_url() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.response_type_url) - return response_type_url_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_response_type_url(const ::std::string& value) { - - response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Method.response_type_url) -} -inline void Method::set_response_type_url(const char* value) { - - response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Method.response_type_url) -} -inline void Method::set_response_type_url(const char* value, size_t size) { - - response_type_url_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Method.response_type_url) -} -inline ::std::string* Method::mutable_response_type_url() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.response_type_url) - return response_type_url_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Method::release_response_type_url() { - // @@protoc_insertion_point(field_release:google.protobuf.Method.response_type_url) - - return response_type_url_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Method::set_allocated_response_type_url(::std::string* response_type_url) { - if (response_type_url != NULL) { - - } else { - - } - response_type_url_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), response_type_url); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Method.response_type_url) -} - -// optional bool response_streaming = 5; -inline void Method::clear_response_streaming() { - response_streaming_ = false; -} -inline bool Method::response_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.response_streaming) - return response_streaming_; -} -inline void Method::set_response_streaming(bool value) { - - response_streaming_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Method.response_streaming) -} - -// repeated .google.protobuf.Option options = 6; -inline int Method::options_size() const { - return options_.size(); -} -inline void Method::clear_options() { - options_.Clear(); -} -inline const ::google::protobuf::Option& Method::options(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.options) - return options_.Get(index); -} -inline ::google::protobuf::Option* Method::mutable_options(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.Method.options) - return options_.Mutable(index); -} -inline ::google::protobuf::Option* Method::add_options() { - // @@protoc_insertion_point(field_add:google.protobuf.Method.options) - return options_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* -Method::mutable_options() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.Method.options) - return &options_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& -Method::options() const { - // @@protoc_insertion_point(field_list:google.protobuf.Method.options) - return options_; -} - -// optional .google.protobuf.Syntax syntax = 7; -inline void Method::clear_syntax() { - syntax_ = 0; -} -inline ::google::protobuf::Syntax Method::syntax() const { - // @@protoc_insertion_point(field_get:google.protobuf.Method.syntax) - return static_cast< ::google::protobuf::Syntax >(syntax_); -} -inline void Method::set_syntax(::google::protobuf::Syntax value) { - - syntax_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Method.syntax) -} - -inline const Method* Method::internal_default_instance() { - return &Method_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// Mixin - -// optional string name = 1; -inline void Mixin::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Mixin::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.Mixin.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Mixin::set_name(const ::std::string& value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Mixin.name) -} -inline void Mixin::set_name(const char* value) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.name) -} -inline void Mixin::set_name(const char* value, size_t size) { - - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.name) -} -inline ::std::string* Mixin::mutable_name() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Mixin::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.Mixin.name) - - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Mixin::set_allocated_name(::std::string* name) { - if (name != NULL) { - - } else { - - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.name) -} - -// optional string root = 2; -inline void Mixin::clear_root() { - root_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& Mixin::root() const { - // @@protoc_insertion_point(field_get:google.protobuf.Mixin.root) - return root_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Mixin::set_root(const ::std::string& value) { - - root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.Mixin.root) -} -inline void Mixin::set_root(const char* value) { - - root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.Mixin.root) -} -inline void Mixin::set_root(const char* value, size_t size) { - - root_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Mixin.root) -} -inline ::std::string* Mixin::mutable_root() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.Mixin.root) - return root_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* Mixin::release_root() { - // @@protoc_insertion_point(field_release:google.protobuf.Mixin.root) - - return root_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void Mixin::set_allocated_root(::std::string* root) { - if (root != NULL) { - - } else { - - } - root_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), root); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root) -} - -inline const Mixin* Mixin::internal_default_instance() { - return &Mixin_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fapi_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/api.proto b/app/src/main/cpp/google/protobuf/api.proto deleted file mode 100644 index bbbe983..0000000 --- a/app/src/main/cpp/google/protobuf/api.proto +++ /dev/null @@ -1,201 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -import "google/protobuf/source_context.proto"; -import "google/protobuf/type.proto"; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "ApiProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// Api is a light-weight descriptor for a protocol buffer service. -message Api { - - // The fully qualified name of this api, including package name - // followed by the api's simple name. - string name = 1; - - // The methods of this api, in unspecified order. - repeated Method methods = 2; - - // Any metadata attached to the API. - repeated Option options = 3; - - // A version string for this api. If specified, must have the form - // `major-version.minor-version`, as in `1.10`. If the minor version - // is omitted, it defaults to zero. If the entire version field is - // empty, the major version is derived from the package name, as - // outlined below. If the field is not empty, the version in the - // package name will be verified to be consistent with what is - // provided here. - // - // The versioning schema uses [semantic - // versioning](http://semver.org) where the major version number - // indicates a breaking change and the minor version an additive, - // non-breaking change. Both version numbers are signals to users - // what to expect from different versions, and should be carefully - // chosen based on the product plan. - // - // The major version is also reflected in the package name of the - // API, which must end in `v`, as in - // `google.feature.v1`. For major versions 0 and 1, the suffix can - // be omitted. Zero major versions must only be used for - // experimental, none-GA apis. - // - // - string version = 4; - - // Source context for the protocol buffer service represented by this - // message. - SourceContext source_context = 5; - - // Included APIs. See [Mixin][]. - repeated Mixin mixins = 6; - - // The source syntax of the service. - Syntax syntax = 7; -} - -// Method represents a method of an api. -message Method { - - // The simple name of this method. - string name = 1; - - // A URL of the input message type. - string request_type_url = 2; - - // If true, the request is streamed. - bool request_streaming = 3; - - // The URL of the output message type. - string response_type_url = 4; - - // If true, the response is streamed. - bool response_streaming = 5; - - // Any metadata attached to the method. - repeated Option options = 6; - - // The source syntax of this method. - Syntax syntax = 7; -} - -// Declares an API to be included in this API. The including API must -// redeclare all the methods from the included API, but documentation -// and options are inherited as follows: -// -// - If after comment and whitespace stripping, the documentation -// string of the redeclared method is empty, it will be inherited -// from the original method. -// -// - Each annotation belonging to the service config (http, -// visibility) which is not set in the redeclared method will be -// inherited. -// -// - If an http annotation is inherited, the path pattern will be -// modified as follows. Any version prefix will be replaced by the -// version of the including API plus the [root][] path if specified. -// -// Example of a simple mixin: -// -// package google.acl.v1; -// service AccessControl { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v1/{resource=**}:getAcl"; -// } -// } -// -// package google.storage.v2; -// service Storage { -// rpc GetAcl(GetAclRequest) returns (Acl); -// -// // Get a data record. -// rpc GetData(GetDataRequest) returns (Data) { -// option (google.api.http).get = "/v2/{resource=**}"; -// } -// } -// -// Example of a mixin configuration: -// -// apis: -// - name: google.storage.v2.Storage -// mixins: -// - name: google.acl.v1.AccessControl -// -// The mixin construct implies that all methods in `AccessControl` are -// also declared with same name and request/response types in -// `Storage`. A documentation generator or annotation processor will -// see the effective `Storage.GetAcl` method after inherting -// documentation and annotations as follows: -// -// service Storage { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v2/{resource=**}:getAcl"; -// } -// ... -// } -// -// Note how the version in the path pattern changed from `v1` to `v2`. -// -// If the `root` field in the mixin is specified, it should be a -// relative path under which inherited HTTP paths are placed. Example: -// -// apis: -// - name: google.storage.v2.Storage -// mixins: -// - name: google.acl.v1.AccessControl -// root: acls -// -// This implies the following inherited HTTP annotation: -// -// service Storage { -// // Get the underlying ACL object. -// rpc GetAcl(GetAclRequest) returns (Acl) { -// option (google.api.http).get = "/v2/acls/{resource=**}:getAcl"; -// } -// ... -// } -message Mixin { - // The fully qualified name of the API which is included. - string name = 1; - - // If non-empty specifies a path under which inherited HTTP paths - // are rooted. - string root = 2; -} diff --git a/app/src/main/cpp/google/protobuf/arena.h b/app/src/main/cpp/google/protobuf/arena.h deleted file mode 100644 index f05277e..0000000 --- a/app/src/main/cpp/google/protobuf/arena.h +++ /dev/null @@ -1,930 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file defines an Arena allocator for better allocation performance. - -#ifndef GOOGLE_PROTOBUF_ARENA_H__ -#define GOOGLE_PROTOBUF_ARENA_H__ - -#include -#ifdef max -#undef max // Visual Studio defines this macro -#endif -#if __cplusplus >= 201103L -#include -#endif -#if defined(_MSC_VER) && !_HAS_EXCEPTIONS -// Work around bugs in MSVC header when _HAS_EXCEPTIONS=0. -#include -#include -namespace std { -using type_info = ::type_info; -} -#else -#include -#endif - -#include -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { - -class Arena; // defined below -class Message; // message.h - -namespace internal { -class ArenaString; // arenastring.h -class LazyField; // lazy_field.h - -template -class GenericTypeHandler; // repeated_field.h - -// Templated cleanup methods. -template void arena_destruct_object(void* object) { - reinterpret_cast(object)->~T(); -} -template void arena_delete_object(void* object) { - delete reinterpret_cast(object); -} -inline void arena_free(void* object, size_t size) { -#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) - ::operator delete(object, size); -#else - ::operator delete(object); -#endif -} - -} // namespace internal - -// ArenaOptions provides optional additional parameters to arena construction -// that control its block-allocation behavior. -struct ArenaOptions { - // This defines the size of the first block requested from the system malloc. - // Subsequent block sizes will increase in a geometric series up to a maximum. - size_t start_block_size; - - // This defines the maximum block size requested from system malloc (unless an - // individual arena allocation request occurs with a size larger than this - // maximum). Requested block sizes increase up to this value, then remain - // here. - size_t max_block_size; - - // An initial block of memory for the arena to use, or NULL for none. If - // provided, the block must live at least as long as the arena itself. The - // creator of the Arena retains ownership of the block after the Arena is - // destroyed. - char* initial_block; - - // The size of the initial block, if provided. - size_t initial_block_size; - - // A function pointer to an alloc method that returns memory blocks of size - // requested. By default, it contains a ptr to the malloc function. - // - // NOTE: block_alloc and dealloc functions are expected to behave like - // malloc and free, including Asan poisoning. - void* (*block_alloc)(size_t); - // A function pointer to a dealloc method that takes ownership of the blocks - // from the arena. By default, it contains a ptr to a wrapper function that - // calls free. - void (*block_dealloc)(void*, size_t); - - // Hooks for adding external functionality such as user-specific metrics - // collection, specific debugging abilities, etc. - // Init hook may return a pointer to a cookie to be stored in the arena. - // reset and destruction hooks will then be called with the same cookie - // pointer. This allows us to save an external object per arena instance and - // use it on the other hooks (Note: It is just as legal for init to return - // NULL and not use the cookie feature). - // on_arena_reset and on_arena_destruction also receive the space used in - // the arena just before the reset. - void* (*on_arena_init)(Arena* arena); - void (*on_arena_reset)(Arena* arena, void* cookie, uint64 space_used); - void (*on_arena_destruction)(Arena* arena, void* cookie, uint64 space_used); - - // type_info is promised to be static - its lifetime extends to - // match program's lifetime (It is given by typeid operator). - // Note: typeid(void) will be passed as allocated_type every time we - // intentionally want to avoid monitoring an allocation. (i.e. internal - // allocations for managing the arena) - void (*on_arena_allocation)(const std::type_info* allocated_type, - uint64 alloc_size, void* cookie); - - ArenaOptions() - : start_block_size(kDefaultStartBlockSize), - max_block_size(kDefaultMaxBlockSize), - initial_block(NULL), - initial_block_size(0), - block_alloc(&::operator new), - block_dealloc(&internal::arena_free), - on_arena_init(NULL), - on_arena_reset(NULL), - on_arena_destruction(NULL), - on_arena_allocation(NULL) {} - - private: - // Constants define default starting block size and max block size for - // arena allocator behavior -- see descriptions above. - static const size_t kDefaultStartBlockSize = 256; - static const size_t kDefaultMaxBlockSize = 8192; -}; - -// Support for non-RTTI environments. (The metrics hooks API uses type -// information.) -#ifndef GOOGLE_PROTOBUF_NO_RTTI -#define RTTI_TYPE_ID(type) (&typeid(type)) -#else -#define RTTI_TYPE_ID(type) (NULL) -#endif - -// Arena allocator. Arena allocation replaces ordinary (heap-based) allocation -// with new/delete, and improves performance by aggregating allocations into -// larger blocks and freeing allocations all at once. Protocol messages are -// allocated on an arena by using Arena::CreateMessage(Arena*), below, and -// are automatically freed when the arena is destroyed. -// -// This is a thread-safe implementation: multiple threads may allocate from the -// arena concurrently. Destruction is not thread-safe and the destructing -// thread must synchronize with users of the arena first. -// -// An arena provides two allocation interfaces: CreateMessage, which works -// for arena-enabled proto2 message types as well as other types that satisfy -// the appropriate protocol (described below), and Create, which works for -// any arbitrary type T. CreateMessage is better when the type T supports it, -// because this interface (i) passes the arena pointer to the created object so -// that its sub-objects and internal allocations can use the arena too, and (ii) -// elides the object's destructor call when possible. Create does not place -// any special requirements on the type T, and will invoke the object's -// destructor when the arena is destroyed. -// -// The arena message allocation protocol, required by CreateMessage, is as -// follows: -// -// - The type T must have (at least) two constructors: a constructor with no -// arguments, called when a T is allocated on the heap; and a constructor with -// a google::protobuf::Arena* argument, called when a T is allocated on an arena. If the -// second constructor is called with a NULL arena pointer, it must be -// equivalent to invoking the first (no-argument) constructor. -// -// - The type T must have a particular type trait: a nested type -// |InternalArenaConstructable_|. This is usually a typedef to |void|. If no -// such type trait exists, then the instantiation CreateMessage will fail -// to compile. -// -// - The type T *may* have the type trait |DestructorSkippable_|. If this type -// trait is present in the type, then its destructor will not be called if and -// only if it was passed a non-NULL arena pointer. If this type trait is not -// present on the type, then its destructor is always called when the -// containing arena is destroyed. -// -// - One- and two-user-argument forms of CreateMessage() also exist that -// forward these constructor arguments to T's constructor: for example, -// CreateMessage(Arena*, arg1, arg2) forwards to a constructor T(Arena*, -// arg1, arg2). -// -// This protocol is implemented by all arena-enabled proto2 message classes as -// well as RepeatedPtrField. -// -// Do NOT subclass Arena. This class will be marked as final when C++11 is -// enabled. -class LIBPROTOBUF_EXPORT Arena { - public: - // Arena constructor taking custom options. See ArenaOptions below for - // descriptions of the options available. - explicit Arena(const ArenaOptions& options) : options_(options) { - Init(); - } - - // Default constructor with sensible default options, tuned for average - // use-cases. - Arena() { - Init(); - } - - // Destructor deletes all owned heap allocated objects, and destructs objects - // that have non-trivial destructors, except for proto2 message objects whose - // destructors can be skipped. Also, frees all blocks except the initial block - // if it was passed in. - ~Arena(); - - // API to create proto2 message objects on the arena. If the arena passed in - // is NULL, then a heap allocated object is returned. Type T must be a message - // defined in a .proto file with cc_enable_arenas set to true, otherwise a - // compilation error will occur. - // - // RepeatedField and RepeatedPtrField may also be instantiated directly on an - // arena with this method. - // - // This function also accepts any type T that satisfies the arena message - // allocation protocol, documented above. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateMessage(::google::protobuf::Arena* arena) { - if (arena == NULL) { - return new T; - } else { - return arena->CreateMessageInternal(static_cast(0)); - } - } - - // One-argument form of CreateMessage. This is useful for constructing objects - // that implement the arena message construction protocol described above but - // take additional constructor arguments. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateMessage(::google::protobuf::Arena* arena, const Arg& arg) { - if (arena == NULL) { - return new T(NULL, arg); - } else { - return arena->CreateMessageInternal(static_cast(0), - arg); - } - } - - // Two-argument form of CreateMessage. This is useful for constructing objects - // that implement the arena message construction protocol described above but - // take additional constructor arguments. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateMessage(::google::protobuf::Arena* arena, - const Arg1& arg1, - const Arg2& arg2) { - if (arena == NULL) { - return new T(NULL, arg1, arg2); - } else { - return arena->CreateMessageInternal(static_cast(0), - arg1, arg2); - } - } - - // API to create any objects on the arena. Note that only the object will - // be created on the arena; the underlying ptrs (in case of a proto2 message) - // will be still heap allocated. Proto messages should usually be allocated - // with CreateMessage() instead. - // - // Note that even if T satisfies the arena message construction protocol - // (InternalArenaConstructable_ trait and optional DestructorSkippable_ - // trait), as described above, this function does not follow the protocol; - // instead, it treats T as a black-box type, just as if it did not have these - // traits. Specifically, T's constructor arguments will always be only those - // passed to Create() -- no additional arena pointer is implicitly added. - // Furthermore, the destructor will always be called at arena destruction time - // (unless the destructor is trivial). Hence, from T's point of view, it is as - // if the object were allocated on the heap (except that the underlying memory - // is obtained from the arena). - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* Create(::google::protobuf::Arena* arena) { - if (arena == NULL) { - return new T(); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value); - } - } - - // Version of the above with one constructor argument for the created object. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* Create(::google::protobuf::Arena* arena, const Arg& arg) { - if (arena == NULL) { - return new T(arg); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg); - } - } - - // Version of the above with two constructor arguments for the created object. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* Create(::google::protobuf::Arena* arena, const Arg1& arg1, const Arg2& arg2) { - if (arena == NULL) { - return new T(arg1, arg2); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2); - } - } - - // Version of the above with three constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3) { - if (arena == NULL) { - return new T(arg1, arg2, arg3); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3); - } - } - - // Version of the above with four constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4) { - if (arena == NULL) { - return new T(arg1, arg2, arg3, arg4); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3, arg4); - } - } - - // Version of the above with five constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, - const Arg5& arg5) { - if (arena == NULL) { - return new T(arg1, arg2, arg3, arg4, arg5); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3, arg4, arg5); - } - } - - // Version of the above with six constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, - const Arg5& arg5, const Arg6& arg6) { - if (arena == NULL) { - return new T(arg1, arg2, arg3, arg4, arg5, arg6); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3, arg4, arg5, arg6); - } - } - - // Version of the above with seven constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, - const Arg5& arg5, const Arg6& arg6, - const Arg7& arg7) { - if (arena == NULL) { - return new T(arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } else { - return arena->CreateInternal(google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3, arg4, arg5, arg6, arg7); - } - } - - // Version of the above with eight constructor arguments for the created - // object. - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* Create(::google::protobuf::Arena* arena, - const Arg1& arg1, const Arg2& arg2, - const Arg3& arg3, const Arg4& arg4, - const Arg5& arg5, const Arg6& arg6, - const Arg7& arg7, const Arg8& arg8) { - if (arena == NULL) { - return new T(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } else { - return arena->CreateInternal( - google::protobuf::internal::has_trivial_destructor::value, - arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - } - } - - // Create an array of object type T on the arena *without* invoking the - // constructor of T. If `arena` is null, then the return value should be freed - // with `delete[] x;` (or `::operator delete[](x);`). - // To ensure safe uses, this function checks at compile time - // (when compiled as C++11) that T is trivially default-constructible and - // trivially destructible. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateArray(::google::protobuf::Arena* arena, size_t num_elements) { - GOOGLE_CHECK_LE(num_elements, - std::numeric_limits::max() / sizeof(T)) - << "Requested size is too large to fit into size_t."; - if (arena == NULL) { - return static_cast(::operator new[](num_elements * sizeof(T))); - } else { - return arena->CreateInternalRawArray(num_elements); - } - } - - // Returns the total space used by the arena, which is the sums of the sizes - // of the underlying blocks. The total space used may not include the new - // blocks that are allocated by this arena from other threads concurrently - // with the call to this method. - GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceAllocated() const; - // As above, but does not include any free space in underlying blocks. - GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceUsed() const; - - // Combines SpaceAllocated and SpaceUsed. Returns a pair of - // . - GOOGLE_ATTRIBUTE_NOINLINE std::pair SpaceAllocatedAndUsed() const; - - // Frees all storage allocated by this arena after calling destructors - // registered with OwnDestructor() and freeing objects registered with Own(). - // Any objects allocated on this arena are unusable after this call. It also - // returns the total space used by the arena which is the sums of the sizes - // of the allocated blocks. This method is not thread-safe. - GOOGLE_ATTRIBUTE_NOINLINE uint64 Reset(); - - // Adds |object| to a list of heap-allocated objects to be freed with |delete| - // when the arena is destroyed or reset. - template GOOGLE_ATTRIBUTE_NOINLINE - void Own(T* object) { - OwnInternal(object, google::protobuf::internal::is_convertible()); - } - - // Adds |object| to a list of objects whose destructors will be manually - // called when the arena is destroyed or reset. This differs from Own() in - // that it does not free the underlying memory with |delete|; hence, it is - // normally only used for objects that are placement-newed into - // arena-allocated memory. - template GOOGLE_ATTRIBUTE_NOINLINE - void OwnDestructor(T* object) { - if (object != NULL) { - AddListNode(object, &internal::arena_destruct_object); - } - } - - // Adds a custom member function on an object to the list of destructors that - // will be manually called when the arena is destroyed or reset. This differs - // from OwnDestructor() in that any member function may be specified, not only - // the class destructor. - GOOGLE_ATTRIBUTE_NOINLINE void OwnCustomDestructor(void* object, - void (*destruct)(void*)) { - AddListNode(object, destruct); - } - - // Retrieves the arena associated with |value| if |value| is an arena-capable - // message, or NULL otherwise. This differs from value->GetArena() in that the - // latter is a virtual call, while this method is a templated call that - // resolves at compile-time. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static ::google::protobuf::Arena* GetArena(const T* value) { - return GetArenaInternal(value, static_cast(0)); - } - - private: - struct InternalIsArenaConstructableHelper { - template - static char ArenaConstructable( - const typename U::InternalArenaConstructable_*); - template - static double ArenaConstructable(...); - }; - - public: - // Helper typetrait that indicates support for arenas in a type T at compile - // time. This is public only to allow construction of higher-level templated - // utilities. is_arena_constructable::value is true if the message type T - // has arena support enabled, and false otherwise. - // - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template - struct is_arena_constructable - : public google::protobuf::internal::integral_constant< - bool, sizeof(InternalIsArenaConstructableHelper::ArenaConstructable< - const T>(static_cast(0))) == sizeof(char)> { - }; - - private: - // Blocks are variable length malloc-ed objects. The following structure - // describes the common header for all blocks. - struct Block { - void* owner; // &ThreadCache of thread that owns this block, or - // &this->owner if not yet owned by a thread. - Block* next; // Next block in arena (may have different owner) - // ((char*) &block) + pos is next available byte. It is always - // aligned at a multiple of 8 bytes. - size_t pos; - size_t size; // total size of the block. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE size_t avail() const { return size - pos; } - // data follows - }; - - template friend class ::google::protobuf::internal::GenericTypeHandler; - friend class MockArena; // For unit-testing. - friend class internal::ArenaString; // For AllocateAligned. - friend class internal::LazyField; // For CreateMaybeMessage. - - struct ThreadCache { - // The ThreadCache is considered valid as long as this matches the - // lifecycle_id of the arena being used. - int64 last_lifecycle_id_seen; - Block* last_block_used_; - }; - - static const size_t kHeaderSize = sizeof(Block); - static google::protobuf::internal::SequenceNumber lifecycle_id_generator_; -#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) - // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread - // local storage class we implemented. - // iOS also does not support the GOOGLE_THREAD_LOCAL keyword. - static ThreadCache& thread_cache(); -#elif defined(PROTOBUF_USE_DLLS) - // Thread local variables cannot be exposed through DLL interface but we can - // wrap them in static functions. - static ThreadCache& thread_cache(); -#else - static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_; - static ThreadCache& thread_cache() { return thread_cache_; } -#endif - - // SFINAE for skipping addition to delete list for a message type when created - // with CreateMessage. This is mainly to skip proto2/proto1 message objects - // with cc_enable_arenas=true from being part of the delete list. Also, note, - // compiler will optimize out the branch in CreateInternal. - template - static inline bool SkipDeleteList(typename T::DestructorSkippable_*) { - return true; - } - - // For message objects that don't have the DestructorSkippable_ trait, we - // always add to the delete list. - template - static inline bool SkipDeleteList(...) { - return google::protobuf::internal::has_trivial_destructor::value; - } - - private: - struct InternalIsDestructorSkippableHelper { - template - static char DestructorSkippable( - const typename U::DestructorSkippable_*); - template - static double DestructorSkippable(...); - }; - - public: - // Helper typetrait that indicates whether the desctructor of type T should be - // called when arena is destroyed at compile time. This is only to allow - // construction of higher-level templated utilities. - // is_destructor_skippable::value is true if the destructor of the message - // type T should not be called when arena is destroyed or false otherwise. - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template - struct is_destructor_skippable - : public google::protobuf::internal::integral_constant< - bool, - sizeof(InternalIsDestructorSkippableHelper::DestructorSkippable< - const T>(static_cast(0))) == sizeof(char) || - google::protobuf::internal::has_trivial_destructor::value> {}; - - private: - // CreateMessage requires that T supports arenas, but this private method - // works whether or not T supports arenas. These are not exposed to user code - // as it can cause confusing API usages, and end up having double free in - // user code. These are used only internally from LazyField and Repeated - // fields, since they are designed to work in all mode combinations. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static Msg* CreateMaybeMessage( - Arena* arena, typename Msg::InternalArenaConstructable_*) { - return CreateMessage(arena); - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateMaybeMessage(Arena* arena, ...) { - return Create(arena); - } - - // Just allocate the required size for the given type assuming the - // type has a trivial constructor. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternalRawArray(size_t num_elements) { - GOOGLE_CHECK_LE(num_elements, - std::numeric_limits::max() / sizeof(T)) - << "Requested size is too large to fit into size_t."; - return static_cast( - AllocateAligned(RTTI_TYPE_ID(T), sizeof(T) * num_elements)); - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal(bool skip_explicit_ownership) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal(bool skip_explicit_ownership, const Arg& arg) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal( - bool skip_explicit_ownership, const Arg1& arg1, const Arg2& arg2) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg1, arg2); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3, arg4); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3, arg4, arg5); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5, - const Arg6& arg6) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3, arg4, arg5, arg6); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5, - const Arg6& arg6, - const Arg7& arg7) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3, arg4, arg5, arg6, arg7); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, - const Arg1& arg1, - const Arg2& arg2, - const Arg3& arg3, - const Arg4& arg4, - const Arg5& arg5, - const Arg6& arg6, - const Arg7& arg7, - const Arg8& arg8) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) - T(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object); - } - return t; - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this); - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*, - const Arg& arg) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this, arg); - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*, - const Arg1& arg1, const Arg2& arg2) { - return CreateInternal(SkipDeleteList(static_cast(0)), - this, arg1, arg2); - } - - // CreateInArenaStorage is used to implement map field. Without it, - // google::protobuf::Map need to call generated message's protected arena constructor, - // which needs to declare google::protobuf::Map as friend of generated message. - template - static void CreateInArenaStorage(T* ptr, Arena* arena) { - CreateInArenaStorageInternal(ptr, arena, - typename is_arena_constructable::type()); - RegisterDestructorInternal(ptr, arena, - typename is_destructor_skippable::type()); - } - - template - static void CreateInArenaStorageInternal( - T* ptr, Arena* arena, google::protobuf::internal::true_type) { - new (ptr) T(arena); - } - template - static void CreateInArenaStorageInternal( - T* ptr, Arena* arena, google::protobuf::internal::false_type) { - new (ptr) T(); - } - - template - static void RegisterDestructorInternal( - T* ptr, Arena* arena, google::protobuf::internal::true_type) {} - template - static void RegisterDestructorInternal( - T* ptr, Arena* arena, google::protobuf::internal::false_type) { - arena->OwnDestructor(ptr); - } - - // These implement Own(), which registers an object for deletion (destructor - // call and operator delete()). The second parameter has type 'true_type' if T - // is a subtype of ::google::protobuf::Message and 'false_type' otherwise. Collapsing - // all template instantiations to one for generic Message reduces code size, - // using the virtual destructor instead. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - void OwnInternal(T* object, google::protobuf::internal::true_type) { - if (object != NULL) { - AddListNode(object, &internal::arena_delete_object< ::google::protobuf::Message >); - } - } - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - void OwnInternal(T* object, google::protobuf::internal::false_type) { - if (object != NULL) { - AddListNode(object, &internal::arena_delete_object); - } - } - - // Implementation for GetArena(). Only message objects with - // InternalArenaConstructable_ tags can be associated with an arena, and such - // objects must implement a GetArenaNoVirtual() method. - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static ::google::protobuf::Arena* GetArenaInternal( - const T* value, typename T::InternalArenaConstructable_*) { - return value->GetArenaNoVirtual(); - } - - template GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static ::google::protobuf::Arena* GetArenaInternal(const T* value, ...) { - return NULL; - } - - // Allocate and also optionally call on_arena_allocation callback with the - // allocated type info when the hooks are in place in ArenaOptions and - // the cookie is not null. - void* AllocateAligned(const std::type_info* allocated, size_t n); - - // Allocate an internal allocation, avoiding optional typed monitoring. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* AllocateAligned(size_t n) { - return AllocateAligned(NULL, n); - } - - void Init(); - - // Free all blocks and return the total space used which is the sums of sizes - // of the all the allocated blocks. - uint64 FreeBlocks(); - - // Add object pointer and cleanup function pointer to the list. - // TODO(rohananil, cfallin): We could pass in a sub-arena into this method - // to avoid polluting blocks of this arena with list nodes. This would help in - // mixed mode (where many protobufs have cc_enable_arenas=false), and is an - // alternative to a chunked linked-list, but with extra overhead of *next. - void AddListNode(void* elem, void (*cleanup)(void*)); - // Delete or Destruct all objects owned by the arena. - void CleanupList(); - uint64 ResetInternal(); - - inline void SetThreadCacheBlock(Block* block) { - thread_cache().last_block_used_ = block; - thread_cache().last_lifecycle_id_seen = lifecycle_id_; - } - - int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). - - google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks - google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access - - // Node contains the ptr of the object to be cleaned up and the associated - // cleanup function ptr. - struct Node { - void* elem; // Pointer to the object to be cleaned up. - void (*cleanup)(void*); // Function pointer to the destructor or deleter. - Node* next; // Next node in the list. - }; - - google::protobuf::internal::AtomicWord cleanup_list_; // Head of a linked list of nodes containing object - // ptrs and cleanup methods. - - bool owns_first_block_; // Indicates that arena owns the first block - Mutex blocks_lock_; - - void AddBlock(Block* b); - // Access must be synchronized, either by blocks_lock_ or by being called from - // Init()/Reset(). - void AddBlockInternal(Block* b); - void* SlowAlloc(size_t n); - Block* FindBlock(void* me); - Block* NewBlock(void* me, Block* my_last_block, size_t n, - size_t start_block_size, size_t max_block_size); - static void* AllocFromBlock(Block* b, size_t n); - template - friend class Map; - - // The arena may save a cookie it receives from the external on_init hook - // and then use it when calling the on_reset and on_destruction hooks. - void* hooks_cookie_; - - ArenaOptions options_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Arena); -}; - -// Defined above for supporting environments without RTTI. -#undef RTTI_TYPE_ID - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_ARENA_H__ diff --git a/app/src/main/cpp/google/protobuf/arenastring.h b/app/src/main/cpp/google/protobuf/arenastring.h deleted file mode 100644 index 590ffce..0000000 --- a/app/src/main/cpp/google/protobuf/arenastring.h +++ /dev/null @@ -1,314 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_ARENASTRING_H__ -#define GOOGLE_PROTOBUF_ARENASTRING_H__ - -#include - -#include -#include -#include -#include -#include - - - -// This is the implementation of arena string fields written for the open-source -// release. The ArenaStringPtr struct below is an internal implementation class -// and *should not be used* by user code. It is used to collect string -// operations together into one place and abstract away the underlying -// string-field pointer representation, so that (for example) an alternate -// implementation that knew more about ::std::string's internals could integrate more -// closely with the arena allocator. - -namespace google { -namespace protobuf { -namespace internal { - -struct LIBPROTOBUF_EXPORT ArenaStringPtr { - inline void Set(const ::std::string* default_value, - const ::std::string& value, ::google::protobuf::Arena* arena) { - if (ptr_ == default_value) { - CreateInstance(arena, &value); - } else { - *ptr_ = value; - } - } - - // Basic accessors. - inline const ::std::string& Get(const ::std::string* /* default_value */) const { - return *ptr_; - } - - inline ::std::string* Mutable(const ::std::string* default_value, - ::google::protobuf::Arena* arena) { - if (ptr_ == default_value) { - CreateInstance(arena, default_value); - } - return ptr_; - } - - // Release returns a ::std::string* instance that is heap-allocated and is not - // Own()'d by any arena. If the field was not set, it returns NULL. The caller - // retains ownership. Clears this field back to NULL state. Used to implement - // release_() methods on generated classes. - inline ::std::string* Release(const ::std::string* default_value, - ::google::protobuf::Arena* arena) { - if (ptr_ == default_value) { - return NULL; - } - ::std::string* released = NULL; - if (arena != NULL) { - // ptr_ is owned by the arena -- we need to return a copy. - released = new ::std::string(*ptr_); - } else { - released = ptr_; - } - ptr_ = const_cast< ::std::string* >(default_value); - return released; - } - - // UnsafeArenaRelease returns a ::std::string*, but it may be arena-owned (i.e. - // have its destructor already registered) if arena != NULL. If the field was - // not set, this returns NULL. This method clears this field back to NULL - // state. Used to implement unsafe_arena_release_() methods on - // generated classes. - inline ::std::string* UnsafeArenaRelease(const ::std::string* default_value, - ::google::protobuf::Arena* /* arena */) { - if (ptr_ == default_value) { - return NULL; - } - ::std::string* released = ptr_; - ptr_ = const_cast< ::std::string* >(default_value); - return released; - } - - // Takes a string that is heap-allocated, and takes ownership. The string's - // destructor is registered with the arena. Used to implement - // set_allocated_ in generated classes. - inline void SetAllocated(const ::std::string* default_value, - ::std::string* value, ::google::protobuf::Arena* arena) { - if (arena == NULL && ptr_ != default_value) { - Destroy(default_value, arena); - } - if (value != NULL) { - ptr_ = value; - if (arena != NULL) { - arena->Own(value); - } - } else { - ptr_ = const_cast< ::std::string* >(default_value); - } - } - - // Takes a string that has lifetime equal to the arena's lifetime. The arena - // must be non-null. It is safe only to pass this method a value returned by - // UnsafeArenaRelease() on another field of a message in the same arena. Used - // to implement unsafe_arena_set_allocated_ in generated classes. - inline void UnsafeArenaSetAllocated(const ::std::string* default_value, - ::std::string* value, - ::google::protobuf::Arena* /* arena */) { - if (value != NULL) { - ptr_ = value; - } else { - ptr_ = const_cast< ::std::string* >(default_value); - } - } - - // Swaps internal pointers. Arena-safety semantics: this is guarded by the - // logic in Swap()/UnsafeArenaSwap() at the message level, so this method is - // 'unsafe' if called directly. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(ArenaStringPtr* other) { - std::swap(ptr_, other->ptr_); - } - - // Frees storage (if not on an arena) and sets field to default value. - inline void Destroy(const ::std::string* default_value, - ::google::protobuf::Arena* arena) { - if (arena == NULL && ptr_ != default_value) { - delete ptr_; - } - ptr_ = const_cast< ::std::string* >(default_value); - } - - // Clears content, but keeps allocated string if arena != NULL, to avoid the - // overhead of heap operations. After this returns, the content (as seen by - // the user) will always be the empty string. Assumes that |default_value| - // is an empty string. - inline void ClearToEmpty(const ::std::string* default_value, - ::google::protobuf::Arena* /* arena */) { - if (ptr_ == default_value) { - // Already set to default (which is empty) -- do nothing. - } else { - ptr_->clear(); - } - } - - // Clears content, but keeps allocated string if arena != NULL, to avoid the - // overhead of heap operations. After this returns, the content (as seen by - // the user) will always be equal to |default_value|. - inline void ClearToDefault(const ::std::string* default_value, - ::google::protobuf::Arena* /* arena */) { - if (ptr_ == default_value) { - // Already set to default -- do nothing. - } else { - // Have another allocated string -- rather than throwing this away and - // resetting ptr_ to the canonical default string instance, we just reuse - // this instance. - *ptr_ = *default_value; - } - } - - // Called from generated code / reflection runtime only. Resets value to point - // to a default string pointer, with the semantics that this ArenaStringPtr - // does not own the pointed-to memory. Disregards initial value of ptr_ (so - // this is the *ONLY* safe method to call after construction or when - // reinitializing after becoming the active field in a oneof union). - inline void UnsafeSetDefault(const ::std::string* default_value) { - // Casting away 'const' is safe here: accessors ensure that ptr_ is only - // returned as a const if it is equal to default_value. - ptr_ = const_cast< ::std::string* >(default_value); - } - - // The 'NoArena' variants of methods below assume arena == NULL and are - // optimized to provide very little overhead relative to a raw string pointer - // (while still being in-memory compatible with other code that assumes - // ArenaStringPtr). Note the invariant that a class instance that has only - // ever been mutated by NoArena methods must *only* be in the String state - // (i.e., tag bits are not used), *NEVER* ArenaString. This allows all - // tagged-pointer manipulations to be avoided. - inline void SetNoArena(const ::std::string* default_value, - const ::std::string& value) { - if (ptr_ == default_value) { - CreateInstanceNoArena(&value); - } else { - *ptr_ = value; - } - } - - void AssignWithDefault(const ::std::string* default_value, ArenaStringPtr value); - - inline const ::std::string& GetNoArena(const ::std::string* /* default_value */) const { - return *ptr_; - } - - inline ::std::string* MutableNoArena(const ::std::string* default_value) { - if (ptr_ == default_value) { - CreateInstanceNoArena(default_value); - } - return ptr_; - } - - inline ::std::string* ReleaseNoArena(const ::std::string* default_value) { - if (ptr_ == default_value) { - return NULL; - } else { - ::std::string* released = ptr_; - ptr_ = const_cast< ::std::string* >(default_value); - return released; - } - } - - inline void SetAllocatedNoArena(const ::std::string* default_value, - ::std::string* value) { - if (ptr_ != default_value) { - delete ptr_; - } - if (value != NULL) { - ptr_ = value; - } else { - ptr_ = const_cast< ::std::string* >(default_value); - } - } - - inline void DestroyNoArena(const ::std::string* default_value) { - if (ptr_ != default_value) { - delete ptr_; - } - ptr_ = NULL; - } - - inline void ClearToEmptyNoArena(const ::std::string* default_value) { - if (ptr_ == default_value) { - // Nothing: already equal to default (which is the empty string). - } else { - ptr_->clear(); - } - } - - inline void ClearToDefaultNoArena(const ::std::string* default_value) { - if (ptr_ == default_value) { - // Nothing: already set to default. - } else { - // Reuse existing allocated instance. - *ptr_ = *default_value; - } - } - - // Internal accessor used only at parse time to provide direct access to the - // raw pointer from the shared parse routine (in the non-arenas case). The - // parse routine does the string allocation in order to save code size in the - // generated parsing code. - inline ::std::string** UnsafeRawStringPointer() { - return &ptr_; - } - - private: - ::std::string* ptr_; - - GOOGLE_ATTRIBUTE_NOINLINE void CreateInstance(::google::protobuf::Arena* arena, - const ::std::string* initial_value) { - // Assumes ptr_ is not NULL. - if (initial_value != NULL) { - ptr_ = new ::std::string(*initial_value); - } else { - ptr_ = new ::std::string(); - } - if (arena != NULL) { - arena->Own(ptr_); - } - } - GOOGLE_ATTRIBUTE_NOINLINE void CreateInstanceNoArena(const ::std::string* initial_value) { - if (initial_value != NULL) { - ptr_ = new ::std::string(*initial_value); - } else { - ptr_ = new ::std::string(); - } - } -}; - -} // namespace internal -} // namespace protobuf - - - -} // namespace google -#endif // GOOGLE_PROTOBUF_ARENASTRING_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/code_generator.h b/app/src/main/cpp/google/protobuf/compiler/code_generator.h deleted file mode 100644 index 642bbfa..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/code_generator.h +++ /dev/null @@ -1,167 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines the abstract interface implemented by each of the language-specific -// code generators. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { class ZeroCopyOutputStream; } -class FileDescriptor; - -namespace compiler { - -// Defined in this file. -class CodeGenerator; -class GeneratorContext; - -// The abstract interface to a class which generates code implementing a -// particular proto file in a particular language. A number of these may -// be registered with CommandLineInterface to support various languages. -class LIBPROTOC_EXPORT CodeGenerator { - public: - inline CodeGenerator() {} - virtual ~CodeGenerator(); - - // Generates code for the given proto file, generating one or more files in - // the given output directory. - // - // A parameter to be passed to the generator can be specified on the command - // line. This is intended to be used to pass generator specific parameters. - // It is empty if no parameter was given. ParseGeneratorParameter (below), - // can be used to accept multiple parameters within the single parameter - // command line flag. - // - // Returns true if successful. Otherwise, sets *error to a description of - // the problem (e.g. "invalid parameter") and returns false. - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const = 0; - - // Generates code for all given proto files. - // - // WARNING: The canonical code generator design produces one or two output - // files per input .proto file, and we do not wish to encourage alternate - // designs. - // - // A parameter is given as passed on the command line, as in |Generate()| - // above. - // - // Returns true if successful. Otherwise, sets *error to a description of - // the problem (e.g. "invalid parameter") and returns false. - virtual bool GenerateAll(const vector& files, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; - - // This is no longer used, but this class is part of the opensource protobuf - // library, so it has to remain to keep vtables the same for the current - // version of the library. When protobufs does a api breaking change, the - // method can be removed. - virtual bool HasGenerateAll() const { return true; } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodeGenerator); -}; - -// CodeGenerators generate one or more files in a given directory. This -// abstract interface represents the directory to which the CodeGenerator is -// to write and other information about the context in which the Generator -// runs. -class LIBPROTOC_EXPORT GeneratorContext { - public: - inline GeneratorContext() {} - virtual ~GeneratorContext(); - - // Opens the given file, truncating it if it exists, and returns a - // ZeroCopyOutputStream that writes to the file. The caller takes ownership - // of the returned object. This method never fails (a dummy stream will be - // returned instead). - // - // The filename given should be relative to the root of the source tree. - // E.g. the C++ generator, when generating code for "foo/bar.proto", will - // generate the files "foo/bar.pb.h" and "foo/bar.pb.cc"; note that - // "foo/" is included in these filenames. The filename is not allowed to - // contain "." or ".." components. - virtual io::ZeroCopyOutputStream* Open(const string& filename) = 0; - - // Similar to Open() but the output will be appended to the file if exists - virtual io::ZeroCopyOutputStream* OpenForAppend(const string& filename); - - // Creates a ZeroCopyOutputStream which will insert code into the given file - // at the given insertion point. See plugin.proto (plugin.pb.h) for more - // information on insertion points. The default implementation - // assert-fails -- it exists only for backwards-compatibility. - // - // WARNING: This feature is currently EXPERIMENTAL and is subject to change. - virtual io::ZeroCopyOutputStream* OpenForInsert( - const string& filename, const string& insertion_point); - - // Returns a vector of FileDescriptors for all the files being compiled - // in this run. Useful for languages, such as Go, that treat files - // differently when compiled as a set rather than individually. - virtual void ListParsedFiles(vector* output); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); -}; - -// The type GeneratorContext was once called OutputDirectory. This typedef -// provides backward compatibility. -typedef GeneratorContext OutputDirectory; - -// Several code generators treat the parameter argument as holding a -// list of options separated by commas. This helper function parses -// a set of comma-delimited name/value pairs: e.g., -// "foo=bar,baz,qux=corge" -// parses to the pairs: -// ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void ParseGeneratorParameter(const string&, - vector >*); - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CODE_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/command_line_interface.h b/app/src/main/cpp/google/protobuf/compiler/command_line_interface.h deleted file mode 100644 index c38e65a..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/command_line_interface.h +++ /dev/null @@ -1,404 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Implements the Protocol Compiler front-end such that it may be reused by -// custom compilers written to support other languages. - -#ifndef GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ -#define GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -class Descriptor; // descriptor.h -class DescriptorPool; // descriptor.h -class FileDescriptor; // descriptor.h -class FileDescriptorProto; // descriptor.pb.h -template class RepeatedPtrField; // repeated_field.h - -} // namespace protobuf -} // namespace google - -namespace google { -namespace protobuf { -namespace compiler { - -class CodeGenerator; // code_generator.h -class GeneratorContext; // code_generator.h -class DiskSourceTree; // importer.h - -// This class implements the command-line interface to the protocol compiler. -// It is designed to make it very easy to create a custom protocol compiler -// supporting the languages of your choice. For example, if you wanted to -// create a custom protocol compiler binary which includes both the regular -// C++ support plus support for your own custom output "Foo", you would -// write a class "FooGenerator" which implements the CodeGenerator interface, -// then write a main() procedure like this: -// -// int main(int argc, char* argv[]) { -// google::protobuf::compiler::CommandLineInterface cli; -// -// // Support generation of C++ source and headers. -// google::protobuf::compiler::cpp::CppGenerator cpp_generator; -// cli.RegisterGenerator("--cpp_out", &cpp_generator, -// "Generate C++ source and header."); -// -// // Support generation of Foo code. -// FooGenerator foo_generator; -// cli.RegisterGenerator("--foo_out", &foo_generator, -// "Generate Foo file."); -// -// return cli.Run(argc, argv); -// } -// -// The compiler is invoked with syntax like: -// protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto -// -// For a full description of the command-line syntax, invoke it with --help. -class LIBPROTOC_EXPORT CommandLineInterface { - public: - CommandLineInterface(); - ~CommandLineInterface(); - - // Register a code generator for a language. - // - // Parameters: - // * flag_name: The command-line flag used to specify an output file of - // this type. The name must start with a '-'. If the name is longer - // than one letter, it must start with two '-'s. - // * generator: The CodeGenerator which will be called to generate files - // of this type. - // * help_text: Text describing this flag in the --help output. - // - // Some generators accept extra parameters. You can specify this parameter - // on the command-line by placing it before the output directory, separated - // by a colon: - // protoc --foo_out=enable_bar:outdir - // The text before the colon is passed to CodeGenerator::Generate() as the - // "parameter". - void RegisterGenerator(const string& flag_name, - CodeGenerator* generator, - const string& help_text); - - // Register a code generator for a language. - // Besides flag_name you can specify another option_flag_name that could be - // used to pass extra parameters to the registered code generator. - // Suppose you have registered a generator by calling: - // command_line_interface.RegisterGenerator("--foo_out", "--foo_opt", ...) - // Then you could invoke the compiler with a command like: - // protoc --foo_out=enable_bar:outdir --foo_opt=enable_baz - // This will pass "enable_bar,enable_baz" as the parameter to the generator. - void RegisterGenerator(const string& flag_name, - const string& option_flag_name, - CodeGenerator* generator, - const string& help_text); - - // Enables "plugins". In this mode, if a command-line flag ends with "_out" - // but does not match any registered generator, the compiler will attempt to - // find a "plugin" to implement the generator. Plugins are just executables. - // They should live somewhere in the PATH. - // - // The compiler determines the executable name to search for by concatenating - // exe_name_prefix with the unrecognized flag name, removing "_out". So, for - // example, if exe_name_prefix is "protoc-" and you pass the flag --foo_out, - // the compiler will try to run the program "protoc-foo". - // - // The plugin program should implement the following usage: - // plugin [--out=OUTDIR] [--parameter=PARAMETER] PROTO_FILES < DESCRIPTORS - // --out indicates the output directory (as passed to the --foo_out - // parameter); if omitted, the current directory should be used. --parameter - // gives the generator parameter, if any was provided. The PROTO_FILES list - // the .proto files which were given on the compiler command-line; these are - // the files for which the plugin is expected to generate output code. - // Finally, DESCRIPTORS is an encoded FileDescriptorSet (as defined in - // descriptor.proto). This is piped to the plugin's stdin. The set will - // include descriptors for all the files listed in PROTO_FILES as well as - // all files that they import. The plugin MUST NOT attempt to read the - // PROTO_FILES directly -- it must use the FileDescriptorSet. - // - // The plugin should generate whatever files are necessary, as code generators - // normally do. It should write the names of all files it generates to - // stdout. The names should be relative to the output directory, NOT absolute - // names or relative to the current directory. If any errors occur, error - // messages should be written to stderr. If an error is fatal, the plugin - // should exit with a non-zero exit code. - void AllowPlugins(const string& exe_name_prefix); - - // Run the Protocol Compiler with the given command-line parameters. - // Returns the error code which should be returned by main(). - // - // It may not be safe to call Run() in a multi-threaded environment because - // it calls strerror(). I'm not sure why you'd want to do this anyway. - int Run(int argc, const char* const argv[]); - - // Call SetInputsAreCwdRelative(true) if the input files given on the command - // line should be interpreted relative to the proto import path specified - // using --proto_path or -I flags. Otherwise, input file names will be - // interpreted relative to the current working directory (or as absolute - // paths if they start with '/'), though they must still reside inside - // a directory given by --proto_path or the compiler will fail. The latter - // mode is generally more intuitive and easier to use, especially e.g. when - // defining implicit rules in Makefiles. - void SetInputsAreProtoPathRelative(bool enable) { - inputs_are_proto_path_relative_ = enable; - } - - // Provides some text which will be printed when the --version flag is - // used. The version of libprotoc will also be printed on the next line - // after this text. - void SetVersionInfo(const string& text) { - version_info_ = text; - } - - - private: - // ----------------------------------------------------------------- - - class ErrorPrinter; - class GeneratorContextImpl; - class MemoryOutputStream; - typedef hash_map GeneratorContextMap; - - // Clear state from previous Run(). - void Clear(); - - // Remaps each file in input_files_ so that it is relative to one of the - // directories in proto_path_. Returns false if an error occurred. This - // is only used if inputs_are_proto_path_relative_ is false. - bool MakeInputsBeProtoPathRelative( - DiskSourceTree* source_tree); - - // Return status for ParseArguments() and InterpretArgument(). - enum ParseArgumentStatus { - PARSE_ARGUMENT_DONE_AND_CONTINUE, - PARSE_ARGUMENT_DONE_AND_EXIT, - PARSE_ARGUMENT_FAIL - }; - - // Parse all command-line arguments. - ParseArgumentStatus ParseArguments(int argc, const char* const argv[]); - - - // Parses a command-line argument into a name/value pair. Returns - // true if the next argument in the argv should be used as the value, - // false otherwise. - // - // Examples: - // "-Isrc/protos" -> - // name = "-I", value = "src/protos" - // "--cpp_out=src/foo.pb2.cc" -> - // name = "--cpp_out", value = "src/foo.pb2.cc" - // "foo.proto" -> - // name = "", value = "foo.proto" - bool ParseArgument(const char* arg, string* name, string* value); - - // Interprets arguments parsed with ParseArgument. - ParseArgumentStatus InterpretArgument(const string& name, - const string& value); - - // Print the --help text to stderr. - void PrintHelpText(); - - // Generate the given output file from the given input. - struct OutputDirective; // see below - bool GenerateOutput(const vector& parsed_files, - const OutputDirective& output_directive, - GeneratorContext* generator_context); - bool GeneratePluginOutput(const vector& parsed_files, - const string& plugin_name, - const string& parameter, - GeneratorContext* generator_context, - string* error); - - // Implements --encode and --decode. - bool EncodeOrDecode(const DescriptorPool* pool); - - // Implements the --descriptor_set_out option. - bool WriteDescriptorSet(const vector parsed_files); - - // Implements the --dependency_out option - bool GenerateDependencyManifestFile( - const vector& parsed_files, - const GeneratorContextMap& output_directories, - DiskSourceTree* source_tree); - - // Get all transitive dependencies of the given file (including the file - // itself), adding them to the given list of FileDescriptorProtos. The - // protos will be ordered such that every file is listed before any file that - // depends on it, so that you can call DescriptorPool::BuildFile() on them - // in order. Any files in *already_seen will not be added, and each file - // added will be inserted into *already_seen. If include_source_code_info is - // true then include the source code information in the FileDescriptorProtos. - // If include_json_name is true, populate the json_name field of - // FieldDescriptorProto for all fields. - static void GetTransitiveDependencies( - const FileDescriptor* file, - bool include_json_name, - bool include_source_code_info, - set* already_seen, - RepeatedPtrField* output); - - // Implements the --print_free_field_numbers. This function prints free field - // numbers into stdout for the message and it's nested message types in - // post-order, i.e. nested types first. Printed range are left-right - // inclusive, i.e. [a, b]. - // - // Groups: - // For historical reasons, groups are considered to share the same - // field number space with the parent message, thus it will not print free - // field numbers for groups. The field numbers used in the groups are - // excluded in the free field numbers of the parent message. - // - // Extension Ranges: - // Extension ranges are considered ocuppied field numbers and they will not be - // listed as free numbers in the output. - void PrintFreeFieldNumbers(const Descriptor* descriptor); - - // ----------------------------------------------------------------- - - // The name of the executable as invoked (i.e. argv[0]). - string executable_name_; - - // Version info set with SetVersionInfo(). - string version_info_; - - // Registered generators. - struct GeneratorInfo { - string flag_name; - string option_flag_name; - CodeGenerator* generator; - string help_text; - }; - typedef map GeneratorMap; - GeneratorMap generators_by_flag_name_; - GeneratorMap generators_by_option_name_; - // A map from generator names to the parameters specified using the option - // flag. For example, if the user invokes the compiler with: - // protoc --foo_out=outputdir --foo_opt=enable_bar ... - // Then there will be an entry ("--foo_out", "enable_bar") in this map. - map generator_parameters_; - - // See AllowPlugins(). If this is empty, plugins aren't allowed. - string plugin_prefix_; - - // Maps specific plugin names to files. When executing a plugin, this map - // is searched first to find the plugin executable. If not found here, the - // PATH (or other OS-specific search strategy) is searched. - map plugins_; - - // Stuff parsed from command line. - enum Mode { - MODE_COMPILE, // Normal mode: parse .proto files and compile them. - MODE_ENCODE, // --encode: read text from stdin, write binary to stdout. - MODE_DECODE, // --decode: read binary from stdin, write text to stdout. - MODE_PRINT, // Print mode: print info of the given .proto files and exit. - }; - - Mode mode_; - - enum PrintMode { - PRINT_NONE, // Not in MODE_PRINT - PRINT_FREE_FIELDS, // --print_free_fields - }; - - PrintMode print_mode_; - - enum ErrorFormat { - ERROR_FORMAT_GCC, // GCC error output format (default). - ERROR_FORMAT_MSVS // Visual Studio output (--error_format=msvs). - }; - - ErrorFormat error_format_; - - vector > proto_path_; // Search path for proto files. - vector input_files_; // Names of the input proto files. - - // Names of proto files which are allowed to be imported. Used by build - // systems to enforce depend-on-what-you-import. - set direct_dependencies_; - bool direct_dependencies_explicitly_set_; - - // output_directives_ lists all the files we are supposed to output and what - // generator to use for each. - struct OutputDirective { - string name; // E.g. "--foo_out" - CodeGenerator* generator; // NULL for plugins - string parameter; - string output_location; - }; - vector output_directives_; - - // When using --encode or --decode, this names the type we are encoding or - // decoding. (Empty string indicates --decode_raw.) - string codec_type_; - - // If --descriptor_set_out was given, this is the filename to which the - // FileDescriptorSet should be written. Otherwise, empty. - string descriptor_set_name_; - - // If --dependency_out was given, this is the path to the file where the - // dependency file will be written. Otherwise, empty. - string dependency_out_name_; - - // True if --include_imports was given, meaning that we should - // write all transitive dependencies to the DescriptorSet. Otherwise, only - // the .proto files listed on the command-line are added. - bool imports_in_descriptor_set_; - - // True if --include_source_info was given, meaning that we should not strip - // SourceCodeInfo from the DescriptorSet. - bool source_info_in_descriptor_set_; - - // Was the --disallow_services flag used? - bool disallow_services_; - - // See SetInputsAreProtoPathRelative(). - bool inputs_are_proto_path_relative_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_COMMAND_LINE_INTERFACE_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/cpp/cpp_generator.h b/app/src/main/cpp/google/protobuf/compiler/cpp/cpp_generator.h deleted file mode 100644 index 3d517cf..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/cpp/cpp_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Generates C++ code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace cpp { - -// CodeGenerator implementation which generates a C++ source file and -// header. If you create your own protocol compiler binary and you want -// it to support C++ output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator { - public: - CppGenerator(); - ~CppGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator); -}; - -} // namespace cpp -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_generator.h b/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_generator.h deleted file mode 100644 index fd41d85..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_generator.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Generates C# code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ - -#include - -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace csharp { - -// CodeGenerator implementation which generates a C# source file and -// header. If you create your own protocol compiler binary and you want -// it to support C# output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator - : public google::protobuf::compiler::CodeGenerator { - virtual bool Generate( - const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; -}; - -} // namespace csharp -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_GENERATOR_H__ - diff --git a/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_names.h b/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_names.h deleted file mode 100644 index 3080518..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/csharp/csharp_names.h +++ /dev/null @@ -1,103 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Provides a mechanism for mapping a descriptor to the -// fully-qualified name of the corresponding C# class. - -#ifndef GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ -#define GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ - -#include - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class FileDescriptor; -class ServiceDescriptor; - -namespace compiler { -namespace csharp { - -// Requires: -// descriptor != NULL -// -// Returns: -// The namespace to use for given file descriptor. -string GetFileNamespace(const FileDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified C# class name. -string GetClassName(const Descriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified name of the C# class that provides -// access to the file descriptor. Proto compiler generates -// such class for each .proto file processed. -string GetReflectionClassName(const FileDescriptor* descriptor); - -// Generates output file name for given file descriptor. If generate_directories -// is true, the output file will be put under directory corresponding to file's -// namespace. base_namespace can be used to strip some of the top level -// directories. E.g. for file with namespace "Bar.Foo" and base_namespace="Bar", -// the resulting file will be put under directory "Foo" (and not "Bar/Foo"). -// -// Requires: -// descriptor != NULL -// error != NULL -// -// Returns: -// The file name to use as output file for given file descriptor. In case -// of failure, this function will return empty string and error parameter -// will contain the error message. -string GetOutputFile( - const google::protobuf::FileDescriptor* descriptor, - const string file_extension, - const bool generate_directories, - const string base_namespace, - string* error); - -} // namespace csharp -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_CSHARP_NAMES_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/importer.h b/app/src/main/cpp/google/protobuf/compiler/importer.h deleted file mode 100644 index cc8fcc3..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/importer.h +++ /dev/null @@ -1,326 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file is the public interface to the .proto file parser. - -#ifndef GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ -#define GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { class ZeroCopyInputStream; } - -namespace compiler { - -// Defined in this file. -class Importer; -class MultiFileErrorCollector; -class SourceTree; -class DiskSourceTree; - -// TODO(kenton): Move all SourceTree stuff to a separate file? - -// An implementation of DescriptorDatabase which loads files from a SourceTree -// and parses them. -// -// Note: This class is not thread-safe since it maintains a table of source -// code locations for error reporting. However, when a DescriptorPool wraps -// a DescriptorDatabase, it uses mutex locking to make sure only one method -// of the database is called at a time, even if the DescriptorPool is used -// from multiple threads. Therefore, there is only a problem if you create -// multiple DescriptorPools wrapping the same SourceTreeDescriptorDatabase -// and use them from multiple threads. -// -// Note: This class does not implement FindFileContainingSymbol() or -// FindFileContainingExtension(); these will always return false. -class LIBPROTOBUF_EXPORT SourceTreeDescriptorDatabase : public DescriptorDatabase { - public: - SourceTreeDescriptorDatabase(SourceTree* source_tree); - ~SourceTreeDescriptorDatabase(); - - // Instructs the SourceTreeDescriptorDatabase to report any parse errors - // to the given MultiFileErrorCollector. This should be called before - // parsing. error_collector must remain valid until either this method - // is called again or the SourceTreeDescriptorDatabase is destroyed. - void RecordErrorsTo(MultiFileErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Gets a DescriptorPool::ErrorCollector which records errors to the - // MultiFileErrorCollector specified with RecordErrorsTo(). This collector - // has the ability to determine exact line and column numbers of errors - // from the information given to it by the DescriptorPool. - DescriptorPool::ErrorCollector* GetValidationErrorCollector() { - using_validation_error_collector_ = true; - return &validation_error_collector_; - } - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - - private: - class SingleFileErrorCollector; - - SourceTree* source_tree_; - MultiFileErrorCollector* error_collector_; - - class LIBPROTOBUF_EXPORT ValidationErrorCollector : public DescriptorPool::ErrorCollector { - public: - ValidationErrorCollector(SourceTreeDescriptorDatabase* owner); - ~ValidationErrorCollector(); - - // implements ErrorCollector --------------------------------------- - void AddError(const string& filename, - const string& element_name, - const Message* descriptor, - ErrorLocation location, - const string& message); - - virtual void AddWarning(const string& filename, - const string& element_name, - const Message* descriptor, - ErrorLocation location, - const string& message); - - private: - SourceTreeDescriptorDatabase* owner_; - }; - friend class ValidationErrorCollector; - - bool using_validation_error_collector_; - SourceLocationTable source_locations_; - ValidationErrorCollector validation_error_collector_; -}; - -// Simple interface for parsing .proto files. This wraps the process -// of opening the file, parsing it with a Parser, recursively parsing all its -// imports, and then cross-linking the results to produce a FileDescriptor. -// -// This is really just a thin wrapper around SourceTreeDescriptorDatabase. -// You may find that SourceTreeDescriptorDatabase is more flexible. -// -// TODO(kenton): I feel like this class is not well-named. -class LIBPROTOBUF_EXPORT Importer { - public: - Importer(SourceTree* source_tree, - MultiFileErrorCollector* error_collector); - ~Importer(); - - // Import the given file and build a FileDescriptor representing it. If - // the file is already in the DescriptorPool, the existing FileDescriptor - // will be returned. The FileDescriptor is property of the DescriptorPool, - // and will remain valid until it is destroyed. If any errors occur, they - // will be reported using the error collector and Import() will return NULL. - // - // A particular Importer object will only report errors for a particular - // file once. All future attempts to import the same file will return NULL - // without reporting any errors. The idea is that you might want to import - // a lot of files without seeing the same errors over and over again. If - // you want to see errors for the same files repeatedly, you can use a - // separate Importer object to import each one (but use the same - // DescriptorPool so that they can be cross-linked). - const FileDescriptor* Import(const string& filename); - - // The DescriptorPool in which all imported FileDescriptors and their - // contents are stored. - inline const DescriptorPool* pool() const { - return &pool_; - } - - void AddUnusedImportTrackFile(const string& file_name); - void ClearUnusedImportTrackFiles(); - - private: - SourceTreeDescriptorDatabase database_; - DescriptorPool pool_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Importer); -}; - -// If the importer encounters problems while trying to import the proto files, -// it reports them to a MultiFileErrorCollector. -class LIBPROTOBUF_EXPORT MultiFileErrorCollector { - public: - inline MultiFileErrorCollector() {} - virtual ~MultiFileErrorCollector(); - - // Line and column numbers are zero-based. A line number of -1 indicates - // an error with the entire file (e.g. "not found"). - virtual void AddError(const string& filename, int line, int column, - const string& message) = 0; - - virtual void AddWarning(const string& filename, int line, int column, - const string& message) {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultiFileErrorCollector); -}; - -// Abstract interface which represents a directory tree containing proto files. -// Used by the default implementation of Importer to resolve import statements -// Most users will probably want to use the DiskSourceTree implementation, -// below. -class LIBPROTOBUF_EXPORT SourceTree { - public: - inline SourceTree() {} - virtual ~SourceTree(); - - // Open the given file and return a stream that reads it, or NULL if not - // found. The caller takes ownership of the returned object. The filename - // must be a path relative to the root of the source tree and must not - // contain "." or ".." components. - virtual io::ZeroCopyInputStream* Open(const string& filename) = 0; - - // If Open() returns NULL, calling this method immediately will return an - // description of the error. - // Subclasses should implement this method and return a meaningful value for - // better error reporting. - // TODO(xiaofeng): change this to a pure virtual function. - virtual string GetLastErrorMessage(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SourceTree); -}; - -// An implementation of SourceTree which loads files from locations on disk. -// Multiple mappings can be set up to map locations in the DiskSourceTree to -// locations in the physical filesystem. -class LIBPROTOBUF_EXPORT DiskSourceTree : public SourceTree { - public: - DiskSourceTree(); - ~DiskSourceTree(); - - // Map a path on disk to a location in the SourceTree. The path may be - // either a file or a directory. If it is a directory, the entire tree - // under it will be mapped to the given virtual location. To map a directory - // to the root of the source tree, pass an empty string for virtual_path. - // - // If multiple mapped paths apply when opening a file, they will be searched - // in order. For example, if you do: - // MapPath("bar", "foo/bar"); - // MapPath("", "baz"); - // and then you do: - // Open("bar/qux"); - // the DiskSourceTree will first try to open foo/bar/qux, then baz/bar/qux, - // returning the first one that opens successfuly. - // - // disk_path may be an absolute path or relative to the current directory, - // just like a path you'd pass to open(). - void MapPath(const string& virtual_path, const string& disk_path); - - // Return type for DiskFileToVirtualFile(). - enum DiskFileToVirtualFileResult { - SUCCESS, - SHADOWED, - CANNOT_OPEN, - NO_MAPPING - }; - - // Given a path to a file on disk, find a virtual path mapping to that - // file. The first mapping created with MapPath() whose disk_path contains - // the filename is used. However, that virtual path may not actually be - // usable to open the given file. Possible return values are: - // * SUCCESS: The mapping was found. *virtual_file is filled in so that - // calling Open(*virtual_file) will open the file named by disk_file. - // * SHADOWED: A mapping was found, but using Open() to open this virtual - // path will end up returning some different file. This is because some - // other mapping with a higher precedence also matches this virtual path - // and maps it to a different file that exists on disk. *virtual_file - // is filled in as it would be in the SUCCESS case. *shadowing_disk_file - // is filled in with the disk path of the file which would be opened if - // you were to call Open(*virtual_file). - // * CANNOT_OPEN: The mapping was found and was not shadowed, but the - // file specified cannot be opened. When this value is returned, - // errno will indicate the reason the file cannot be opened. *virtual_file - // will be set to the virtual path as in the SUCCESS case, even though - // it is not useful. - // * NO_MAPPING: Indicates that no mapping was found which contains this - // file. - DiskFileToVirtualFileResult - DiskFileToVirtualFile(const string& disk_file, - string* virtual_file, - string* shadowing_disk_file); - - // Given a virtual path, find the path to the file on disk. - // Return true and update disk_file with the on-disk path if the file exists. - // Return false and leave disk_file untouched if the file doesn't exist. - bool VirtualFileToDiskFile(const string& virtual_file, string* disk_file); - - // implements SourceTree ------------------------------------------- - virtual io::ZeroCopyInputStream* Open(const string& filename); - - virtual string GetLastErrorMessage(); - - private: - struct Mapping { - string virtual_path; - string disk_path; - - inline Mapping(const string& virtual_path_param, - const string& disk_path_param) - : virtual_path(virtual_path_param), disk_path(disk_path_param) {} - }; - vector mappings_; - string last_error_message_; - - // Like Open(), but returns the on-disk path in disk_file if disk_file is - // non-NULL and the file could be successfully opened. - io::ZeroCopyInputStream* OpenVirtualFile(const string& virtual_file, - string* disk_file); - - // Like Open() but given the actual on-disk path. - io::ZeroCopyInputStream* OpenDiskFile(const string& filename); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DiskSourceTree); -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_IMPORTER_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/java/java_generator.h b/app/src/main/cpp/google/protobuf/compiler/java/java_generator.h deleted file mode 100644 index 47f76be..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/java/java_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Generates Java code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace java { - -// CodeGenerator implementation which generates Java code. If you create your -// own protocol compiler binary and you want it to support Java output, you -// can do so by registering an instance of this CodeGenerator with the -// CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT JavaGenerator : public CodeGenerator { - public: - JavaGenerator(); - ~JavaGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaGenerator); -}; - -} // namespace java -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/java/java_names.h b/app/src/main/cpp/google/protobuf/compiler/java/java_names.h deleted file mode 100644 index 0d61433..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/java/java_names.h +++ /dev/null @@ -1,87 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Provides a mechanism for mapping a descriptor to the -// fully-qualified name of the corresponding Java class. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ - -#include - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class FileDescriptor; -class ServiceDescriptor; - -namespace compiler { -namespace java { - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. -string ClassName(const Descriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. -string ClassName(const EnumDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. -string ClassName(const FileDescriptor* descriptor); - -// Requires: -// descriptor != NULL -// -// Returns: -// The fully-qualified Java class name. -string ClassName(const ServiceDescriptor* descriptor); - -} // namespace java -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_NAMES_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/javanano/javanano_generator.h b/app/src/main/cpp/google/protobuf/compiler/javanano/javanano_generator.h deleted file mode 100644 index 6f9f7f2..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/javanano/javanano_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Generates Java nano code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JAVANANO_NANO_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JAVANANO_NANO_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace javanano { - -// CodeGenerator implementation which generates Java nano code. If you create your -// own protocol compiler binary and you want it to support Java output for the -// nano runtime, you can do so by registering an instance of this CodeGenerator with -// the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT JavaNanoGenerator : public CodeGenerator { - public: - JavaNanoGenerator(); - ~JavaNanoGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* output_directory, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(JavaNanoGenerator); -}; - -} // namespace javanano -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JAVANANO_NANO_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/js/js_generator.h b/app/src/main/cpp/google/protobuf/compiler/js/js_generator.h deleted file mode 100644 index 4ca3493..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/js/js_generator.h +++ /dev/null @@ -1,336 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Generates JavaScript code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__ - -#include -#include - -#include -#include -#include - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class FieldDescriptor; -class OneofDescriptor; -class FileDescriptor; - -namespace io { class Printer; } - -namespace compiler { -namespace js { - -struct GeneratorOptions { - // Output path. - string output_dir; - // Namespace prefix. - string namespace_prefix; - // Enable binary-format support? - bool binary; - // What style of imports should be used. - enum ImportStyle { - kImportClosure, // goog.require() - kImportCommonJs, // require() - kImportBrowser, // no import statements - kImportEs6, // import { member } from '' - } import_style; - - GeneratorOptions() - : output_dir("."), - namespace_prefix(""), - binary(false), - import_style(kImportClosure), - add_require_for_enums(false), - testonly(false), - library(""), - error_on_name_conflict(false), - broken_proto3_semantics(false), - extension(".js"), - one_output_file_per_input_file(false) {} - - bool ParseFromOptions( - const vector< pair< string, string > >& options, - string* error); - - // Returns the file name extension to use for generated code. - string GetFileNameExtension() const { - return import_style == kImportClosure ? extension : "_pb.js"; - } - - enum OutputMode { - // Create an output file for each input .proto file. - kOneOutputFilePerInputFile, - // Create an output file for each type. - kOneOutputFilePerType, - // Put everything in a single file named by the library option. - kEverythingInOneFile, - }; - - // Indicates how to output the generated code based on the provided options. - OutputMode output_mode() const; - - // The remaining options are only relevant when we are using kImportClosure. - - // Add a `goog.requires()` call for each enum type used. If not set, a - // forward declaration with `goog.forwardDeclare` is produced instead. - bool add_require_for_enums; - // Set this as a test-only module via `goog.setTestOnly();`. - bool testonly; - // Create a library with name _lib.js rather than a separate .js file - // per type? - string library; - // Error if there are two types that would generate the same output file? - bool error_on_name_conflict; - // Preserve the broken proto3 semantics from the old codegen? This amounts - // to using proto2 field presence semantics even for proto3 files. DO NOT - // USE except for migrating legacy code. - bool broken_proto3_semantics; - // The extension to use for output file names. - string extension; - // Create a separate output file for each input file? - bool one_output_file_per_input_file; -}; - -// CodeGenerator implementation which generates a JavaScript source file and -// header. If you create your own protocol compiler binary and you want it to -// support JavaScript output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator : public CodeGenerator { - public: - Generator() {} - virtual ~Generator() {} - - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const { - *error = "Unimplemented Generate() method. Call GenerateAll() instead."; - return false; - } - - virtual bool HasGenerateAll() const { return true; } - - virtual bool GenerateAll(const vector& files, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - void GenerateHeader(const GeneratorOptions& options, - io::Printer* printer) const; - - // Generate goog.provides() calls. - void FindProvides(const GeneratorOptions& options, - io::Printer* printer, - const vector& file, - std::set* provided) const; - void FindProvidesForFile(const GeneratorOptions& options, - io::Printer* printer, - const FileDescriptor* file, - std::set* provided) const; - void FindProvidesForMessage(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc, - std::set* provided) const; - void FindProvidesForEnum(const GeneratorOptions& options, - io::Printer* printer, - const EnumDescriptor* enumdesc, - std::set* provided) const; - // For extension fields at file scope. - void FindProvidesForFields(const GeneratorOptions& options, - io::Printer* printer, - const vector& fields, - std::set* provided) const; - // Print the goog.provides() found by the methods above. - void GenerateProvides(const GeneratorOptions& options, - io::Printer* printer, - std::set* provided) const; - - // Generate goog.setTestOnly() if indicated. - void GenerateTestOnly(const GeneratorOptions& options, - io::Printer* printer) const; - - // Generate goog.requires() calls. - void GenerateRequiresForLibrary(const GeneratorOptions& options, - io::Printer* printer, - const vector& files, - std::set* provided) const; - void GenerateRequiresForMessage(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc, - std::set* provided) const; - // For extension fields at file scope. - void GenerateRequiresForExtensions( - const GeneratorOptions& options, io::Printer* printer, - const vector& fields, - std::set* provided) const; - void GenerateRequiresImpl(const GeneratorOptions& options, - io::Printer* printer, - std::set* required, - std::set* forwards, - std::set* provided, - bool require_jspb, - bool require_extension) const; - void FindRequiresForMessage(const GeneratorOptions& options, - const Descriptor* desc, - std::set* required, - std::set* forwards, - bool* have_message) const; - void FindRequiresForField(const GeneratorOptions& options, - const FieldDescriptor* field, - std::set* required, - std::set* forwards) const; - void FindRequiresForExtension(const GeneratorOptions& options, - const FieldDescriptor* field, - std::set* required, - std::set* forwards) const; - - void GenerateFile(const GeneratorOptions& options, - io::Printer* printer, - const FileDescriptor* file) const; - - // Generate definitions for all message classes and enums in all files, - // processing the files in dependence order. - void GenerateFilesInDepOrder(const GeneratorOptions& options, - io::Printer* printer, - const vector& file) const; - // Helper for above. - void GenerateFileAndDeps(const GeneratorOptions& options, - io::Printer* printer, - const FileDescriptor* root, - std::set* all_files, - std::set* generated) const; - - // Generate definitions for all message classes and enums. - void GenerateClassesAndEnums(const GeneratorOptions& options, - io::Printer* printer, - const FileDescriptor* file) const; - - void GenerateFieldValueExpression(io::Printer* printer, - const char* obj_reference, - const FieldDescriptor* field, - bool use_default) const; - - // Generate definition for one class. - void GenerateClass(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassConstructor(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassFieldInfo(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassXid(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateOneofCaseDefinition(const GeneratorOptions& options, - io::Printer* printer, - const OneofDescriptor* oneof) const; - void GenerateClassToObject(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassFieldToObject(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - void GenerateClassFromObject(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassFieldFromObject(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - void GenerateClassClone(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassRegistration(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassFields(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassField(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* desc) const; - void GenerateClassExtensionFieldInfo(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassDeserialize(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassDeserializeBinary(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassDeserializeBinaryField(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - void GenerateClassSerializeBinary(const GeneratorOptions& options, - io::Printer* printer, - const Descriptor* desc) const; - void GenerateClassSerializeBinaryField(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - - // Generate definition for one enum. - void GenerateEnum(const GeneratorOptions& options, - io::Printer* printer, - const EnumDescriptor* enumdesc) const; - - // Generate an extension definition. - void GenerateExtension(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - - // Generate addFoo() method for repeated primitive fields. - void GenerateRepeatedPrimitiveHelperMethods(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field, - bool untyped) const; - - // Generate addFoo() method for repeated message fields. - void GenerateRepeatedMessageHelperMethods(const GeneratorOptions& options, - io::Printer* printer, - const FieldDescriptor* field) const; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); -}; - -} // namespace js -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_JS_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_generator.h b/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_generator.h deleted file mode 100644 index b172331..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_generator.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Generates ObjectiveC code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// CodeGenerator implementation which generates a ObjectiveC source file and -// header. If you create your own protocol compiler binary and you want it to -// support ObjectiveC output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT ObjectiveCGenerator : public CodeGenerator { - public: - ObjectiveCGenerator(); - ~ObjectiveCGenerator(); - - // implements CodeGenerator ---------------------------------------- - bool HasGenerateAll() const; - bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* context, - string* error) const; - bool GenerateAll(const vector& files, - const string& parameter, - GeneratorContext* context, - string* error) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjectiveCGenerator); -}; - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_helpers.h b/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_helpers.h deleted file mode 100644 index 316069e..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/objectivec/objectivec_helpers.h +++ /dev/null @@ -1,281 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Helper functions for generating ObjectiveC code. - -#ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ -#define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ - -#include -#include - -#include -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace objectivec { - -// Generator options (see objectivec_generator.cc for a description of each): -struct Options { - Options(); - string expected_prefixes_path; - string generate_for_named_framework; - string named_framework_to_proto_path_mappings_path; -}; - -// Escape C++ trigraphs by escaping question marks to "\?". -string EscapeTrigraphs(const string& to_escape); - -// Strips ".proto" or ".protodevel" from the end of a filename. -string StripProto(const string& filename); - -// Remove white space from either end of a StringPiece. -void StringPieceTrimWhitespace(StringPiece* input); - -// Returns true if the name requires a ns_returns_not_retained attribute applied -// to it. -bool IsRetainedName(const string& name); - -// Returns true if the name starts with "init" and will need to have special -// handling under ARC. -bool IsInitName(const string& name); - -// Gets the objc_class_prefix. -string FileClassPrefix(const FileDescriptor* file); - -// Gets the path of the file we're going to generate (sans the .pb.h -// extension). The path will be dependent on the objectivec package -// declared in the proto package. -string FilePath(const FileDescriptor* file); - -// Just like FilePath(), but without the directory part. -string FilePathBasename(const FileDescriptor* file); - -// Gets the name of the root class we'll generate in the file. This class -// is not meant for external consumption, but instead contains helpers that -// the rest of the classes need -string FileClassName(const FileDescriptor* file); - -// These return the fully-qualified class name corresponding to the given -// descriptor. -string ClassName(const Descriptor* descriptor); -string ClassName(const Descriptor* descriptor, string* out_suffix_added); -string EnumName(const EnumDescriptor* descriptor); - -// Returns the fully-qualified name of the enum value corresponding to the -// the descriptor. -string EnumValueName(const EnumValueDescriptor* descriptor); - -// Returns the name of the enum value corresponding to the descriptor. -string EnumValueShortName(const EnumValueDescriptor* descriptor); - -// Reverse what an enum does. -string UnCamelCaseEnumShortName(const string& name); - -// Returns the name to use for the extension (used as the method off the file's -// Root class). -string ExtensionMethodName(const FieldDescriptor* descriptor); - -// Returns the transformed field name. -string FieldName(const FieldDescriptor* field); -string FieldNameCapitalized(const FieldDescriptor* field); - -// Returns the transformed oneof name. -string OneofEnumName(const OneofDescriptor* descriptor); -string OneofName(const OneofDescriptor* descriptor); -string OneofNameCapitalized(const OneofDescriptor* descriptor); - -inline bool HasFieldPresence(const FileDescriptor* file) { - return file->syntax() != FileDescriptor::SYNTAX_PROTO3; -} - -inline bool HasPreservingUnknownEnumSemantics(const FileDescriptor* file) { - return file->syntax() == FileDescriptor::SYNTAX_PROTO3; -} - -inline bool IsMapEntryMessage(const Descriptor* descriptor) { - return descriptor->options().map_entry(); -} - -// Reverse of the above. -string UnCamelCaseFieldName(const string& name, const FieldDescriptor* field); - -enum ObjectiveCType { - OBJECTIVECTYPE_INT32, - OBJECTIVECTYPE_UINT32, - OBJECTIVECTYPE_INT64, - OBJECTIVECTYPE_UINT64, - OBJECTIVECTYPE_FLOAT, - OBJECTIVECTYPE_DOUBLE, - OBJECTIVECTYPE_BOOLEAN, - OBJECTIVECTYPE_STRING, - OBJECTIVECTYPE_DATA, - OBJECTIVECTYPE_ENUM, - OBJECTIVECTYPE_MESSAGE -}; - -enum FlagType { - FLAGTYPE_DESCRIPTOR_INITIALIZATION, - FLAGTYPE_EXTENSION, - FLAGTYPE_FIELD -}; - -template -string GetOptionalDeprecatedAttribute(const TDescriptor* descriptor, bool preSpace = true, bool postNewline = false) { - if (descriptor->options().deprecated()) { - string result = "DEPRECATED_ATTRIBUTE"; - if (preSpace) { - result.insert(0, " "); - } - if (postNewline) { - result.append("\n"); - } - return result; - } else { - return ""; - } -} - -string GetCapitalizedType(const FieldDescriptor* field); - -ObjectiveCType GetObjectiveCType(FieldDescriptor::Type field_type); - -inline ObjectiveCType GetObjectiveCType(const FieldDescriptor* field) { - return GetObjectiveCType(field->type()); -} - -bool IsPrimitiveType(const FieldDescriptor* field); -bool IsReferenceType(const FieldDescriptor* field); - -string GPBGenericValueFieldName(const FieldDescriptor* field); -string DefaultValue(const FieldDescriptor* field); -bool HasNonZeroDefaultValue(const FieldDescriptor* field); - -string BuildFlagsString(const FlagType type, const vector& strings); - -// Builds HeaderDoc/appledoc style comments out of the comments in the .proto -// file. -string BuildCommentsString(const SourceLocation& location, - bool prefer_single_line); - -// The name the commonly used by the library when built as a framework. -// This lines up to the name used in the CocoaPod. -extern const char* const ProtobufLibraryFrameworkName; -// Returns the CPP symbol name to use as the gate for framework style imports -// for the given framework name to use. -string ProtobufFrameworkImportSymbol(const string& framework_name); - -// Checks if the file is one of the proto's bundled with the library. -bool IsProtobufLibraryBundledProtoFile(const FileDescriptor* file); - -// Checks the prefix for the given files and outputs any warnings as needed. If -// there are flat out errors, then out_error is filled in with the first error -// and the result is false. -bool ValidateObjCClassPrefixes(const vector& files, - const Options& generation_options, - string* out_error); - -// Generate decode data needed for ObjC's GPBDecodeTextFormatName() to transform -// the input into the expected output. -class LIBPROTOC_EXPORT TextFormatDecodeData { - public: - TextFormatDecodeData(); - ~TextFormatDecodeData(); - - void AddString(int32 key, const string& input_for_decode, - const string& desired_output); - size_t num_entries() const { return entries_.size(); } - string Data() const; - - static string DecodeDataForString(const string& input_for_decode, - const string& desired_output); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormatDecodeData); - - typedef std::pair DataEntry; - vector entries_; -}; - -// Helper for parsing simple files. -class LIBPROTOC_EXPORT LineConsumer { - public: - LineConsumer(); - virtual ~LineConsumer(); - virtual bool ConsumeLine(const StringPiece& line, string* out_error) = 0; -}; - -bool ParseSimpleFile( - const string& path, LineConsumer* line_consumer, string* out_error); - - -// Helper class for parsing framework import mappings and generating -// import statements. -class LIBPROTOC_EXPORT ImportWriter { - public: - ImportWriter(const string& generate_for_named_framework, - const string& named_framework_to_proto_path_mappings_path); - ~ImportWriter(); - - void AddFile(const FileDescriptor* file, const string& header_extension); - void Print(io::Printer *printer) const; - - private: - class ProtoFrameworkCollector : public LineConsumer { - public: - ProtoFrameworkCollector(map* inout_proto_file_to_framework_name) - : map_(inout_proto_file_to_framework_name) {} - - virtual bool ConsumeLine(const StringPiece& line, string* out_error); - - private: - map* map_; - }; - - void ParseFrameworkMappings(); - - const string generate_for_named_framework_; - const string named_framework_to_proto_path_mappings_path_; - map proto_file_to_framework_name_; - bool need_to_parse_mapping_file_; - - vector protobuf_framework_imports_; - vector protobuf_non_framework_imports_; - vector other_framework_imports_; - vector other_imports_; -}; - -} // namespace objectivec -} // namespace compiler -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_HELPERS_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/parser.h b/app/src/main/cpp/google/protobuf/compiler/parser.h deleted file mode 100644 index 0f80e78..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/parser.h +++ /dev/null @@ -1,569 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Implements parsing of .proto files to FileDescriptorProtos. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PARSER_H__ -#define GOOGLE_PROTOBUF_COMPILER_PARSER_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { class Message; } - -namespace protobuf { -namespace compiler { - -// Defined in this file. -class Parser; -class SourceLocationTable; - -// Implements parsing of protocol definitions (such as .proto files). -// -// Note that most users will be more interested in the Importer class. -// Parser is a lower-level class which simply converts a single .proto file -// to a FileDescriptorProto. It does not resolve import directives or perform -// many other kinds of validation needed to construct a complete -// FileDescriptor. -class LIBPROTOBUF_EXPORT Parser { - public: - Parser(); - ~Parser(); - - // Parse the entire input and construct a FileDescriptorProto representing - // it. Returns true if no errors occurred, false otherwise. - bool Parse(io::Tokenizer* input, FileDescriptorProto* file); - - // Optional features: - - // DEPRECATED: New code should use the SourceCodeInfo embedded in the - // FileDescriptorProto. - // - // Requests that locations of certain definitions be recorded to the given - // SourceLocationTable while parsing. This can be used to look up exact line - // and column numbers for errors reported by DescriptorPool during validation. - // Set to NULL (the default) to discard source location information. - void RecordSourceLocationsTo(SourceLocationTable* location_table) { - source_location_table_ = location_table; - } - - // Requests that errors be recorded to the given ErrorCollector while - // parsing. Set to NULL (the default) to discard error messages. - void RecordErrorsTo(io::ErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Returns the identifier used in the "syntax = " declaration, if one was - // seen during the last call to Parse(), or the empty string otherwise. - const string& GetSyntaxIdentifier() { return syntax_identifier_; } - - // If set true, input files will be required to begin with a syntax - // identifier. Otherwise, files may omit this. If a syntax identifier - // is provided, it must be 'syntax = "proto2";' and must appear at the - // top of this file regardless of whether or not it was required. - void SetRequireSyntaxIdentifier(bool value) { - require_syntax_identifier_ = value; - } - - // Call SetStopAfterSyntaxIdentifier(true) to tell the parser to stop - // parsing as soon as it has seen the syntax identifier, or lack thereof. - // This is useful for quickly identifying the syntax of the file without - // parsing the whole thing. If this is enabled, no error will be recorded - // if the syntax identifier is something other than "proto2" (since - // presumably the caller intends to deal with that), but other kinds of - // errors (e.g. parse errors) will still be reported. When this is enabled, - // you may pass a NULL FileDescriptorProto to Parse(). - void SetStopAfterSyntaxIdentifier(bool value) { - stop_after_syntax_identifier_ = value; - } - - private: - class LocationRecorder; - - // ================================================================= - // Error recovery helpers - - // Consume the rest of the current statement. This consumes tokens - // until it sees one of: - // ';' Consumes the token and returns. - // '{' Consumes the brace then calls SkipRestOfBlock(). - // '}' Returns without consuming. - // EOF Returns (can't consume). - // The Parser often calls SkipStatement() after encountering a syntax - // error. This allows it to go on parsing the following lines, allowing - // it to report more than just one error in the file. - void SkipStatement(); - - // Consume the rest of the current block, including nested blocks, - // ending after the closing '}' is encountered and consumed, or at EOF. - void SkipRestOfBlock(); - - // ----------------------------------------------------------------- - // Single-token consuming helpers - // - // These make parsing code more readable. - - // True if the current token is TYPE_END. - inline bool AtEnd(); - - // True if the next token matches the given text. - inline bool LookingAt(const char* text); - // True if the next token is of the given type. - inline bool LookingAtType(io::Tokenizer::TokenType token_type); - - // If the next token exactly matches the text given, consume it and return - // true. Otherwise, return false without logging an error. - bool TryConsume(const char* text); - - // These attempt to read some kind of token from the input. If successful, - // they return true. Otherwise they return false and add the given error - // to the error list. - - // Consume a token with the exact text given. - bool Consume(const char* text, const char* error); - // Same as above, but automatically generates the error "Expected \"text\".", - // where "text" is the expected token text. - bool Consume(const char* text); - // Consume a token of type IDENTIFIER and store its text in "output". - bool ConsumeIdentifier(string* output, const char* error); - // Consume an integer and store its value in "output". - bool ConsumeInteger(int* output, const char* error); - // Consume a signed integer and store its value in "output". - bool ConsumeSignedInteger(int* output, const char* error); - // Consume a 64-bit integer and store its value in "output". If the value - // is greater than max_value, an error will be reported. - bool ConsumeInteger64(uint64 max_value, uint64* output, const char* error); - // Consume a number and store its value in "output". This will accept - // tokens of either INTEGER or FLOAT type. - bool ConsumeNumber(double* output, const char* error); - // Consume a string literal and store its (unescaped) value in "output". - bool ConsumeString(string* output, const char* error); - - // Consume a token representing the end of the statement. Comments between - // this token and the next will be harvested for documentation. The given - // LocationRecorder should refer to the declaration that was just parsed; - // it will be populated with these comments. - // - // TODO(kenton): The LocationRecorder is const because historically locations - // have been passed around by const reference, for no particularly good - // reason. We should probably go through and change them all to mutable - // pointer to make this more intuitive. - bool TryConsumeEndOfDeclaration( - const char* text, const LocationRecorder* location); - bool TryConsumeEndOfDeclarationFinishScope( - const char* text, const LocationRecorder* location); - - bool ConsumeEndOfDeclaration( - const char* text, const LocationRecorder* location); - - // ----------------------------------------------------------------- - // Error logging helpers - - // Invokes error_collector_->AddError(), if error_collector_ is not NULL. - void AddError(int line, int column, const string& error); - - // Invokes error_collector_->AddError() with the line and column number - // of the current token. - void AddError(const string& error); - - // Records a location in the SourceCodeInfo.location table (see - // descriptor.proto). We use RAII to ensure that the start and end locations - // are recorded -- the constructor records the start location and the - // destructor records the end location. Since the parser is - // recursive-descent, this works out beautifully. - class LIBPROTOBUF_EXPORT LocationRecorder { - public: - // Construct the file's "root" location. - LocationRecorder(Parser* parser); - - // Construct a location that represents a declaration nested within the - // given parent. E.g. a field's location is nested within the location - // for a message type. The parent's path will be copied, so you should - // call AddPath() only to add the path components leading from the parent - // to the child (as opposed to leading from the root to the child). - LocationRecorder(const LocationRecorder& parent); - - // Convenience constructors that call AddPath() one or two times. - LocationRecorder(const LocationRecorder& parent, int path1); - LocationRecorder(const LocationRecorder& parent, int path1, int path2); - - ~LocationRecorder(); - - // Add a path component. See SourceCodeInfo.Location.path in - // descriptor.proto. - void AddPath(int path_component); - - // By default the location is considered to start at the current token at - // the time the LocationRecorder is created. StartAt() sets the start - // location to the given token instead. - void StartAt(const io::Tokenizer::Token& token); - - // Start at the same location as some other LocationRecorder. - void StartAt(const LocationRecorder& other); - - // By default the location is considered to end at the previous token at - // the time the LocationRecorder is destroyed. EndAt() sets the end - // location to the given token instead. - void EndAt(const io::Tokenizer::Token& token); - - // Records the start point of this location to the SourceLocationTable that - // was passed to RecordSourceLocationsTo(), if any. SourceLocationTable - // is an older way of keeping track of source locations which is still - // used in some places. - void RecordLegacyLocation(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location); - - // Attaches leading and trailing comments to the location. The two strings - // will be swapped into place, so after this is called *leading and - // *trailing will be empty. - // - // TODO(kenton): See comment on TryConsumeEndOfDeclaration(), above, for - // why this is const. - void AttachComments(string* leading, string* trailing, - vector* detached_comments) const; - - private: - // Indexes of parent and current location in the parent - // SourceCodeInfo.location repeated field. For top-level elements, - // parent_index_ is -1. - Parser* parser_; - SourceCodeInfo::Location* location_; - - void Init(const LocationRecorder& parent); - }; - - // ================================================================= - // Parsers for various language constructs - - // Parses the "syntax = \"proto2\";" line at the top of the file. Returns - // false if it failed to parse or if the syntax identifier was not - // recognized. - bool ParseSyntaxIdentifier(const LocationRecorder& parent); - - // These methods parse various individual bits of code. They return - // false if they completely fail to parse the construct. In this case, - // it is probably necessary to skip the rest of the statement to recover. - // However, if these methods return true, it does NOT mean that there - // were no errors; only that there were no *syntax* errors. For instance, - // if a service method is defined using proper syntax but uses a primitive - // type as its input or output, ParseMethodField() still returns true - // and only reports the error by calling AddError(). In practice, this - // makes logic much simpler for the caller. - - // Parse a top-level message, enum, service, etc. - bool ParseTopLevelStatement(FileDescriptorProto* file, - const LocationRecorder& root_location); - - // Parse various language high-level language construrcts. - bool ParseMessageDefinition(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumDefinition(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceDefinition(ServiceDescriptorProto* service, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - bool ParsePackage(FileDescriptorProto* file, - const LocationRecorder& root_location, - const FileDescriptorProto* containing_file); - bool ParseImport(RepeatedPtrField* dependency, - RepeatedField* public_dependency, - RepeatedField* weak_dependency, - const LocationRecorder& root_location, - const FileDescriptorProto* containing_file); - - // These methods parse the contents of a message, enum, or service type and - // add them to the given object. They consume the entire block including - // the beginning and ending brace. - bool ParseMessageBlock(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumBlock(EnumDescriptorProto* enum_type, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceBlock(ServiceDescriptorProto* service, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - - // Parse one statement within a message, enum, or service block, including - // final semicolon. - bool ParseMessageStatement(DescriptorProto* message, - const LocationRecorder& message_location, - const FileDescriptorProto* containing_file); - bool ParseEnumStatement(EnumDescriptorProto* message, - const LocationRecorder& enum_location, - const FileDescriptorProto* containing_file); - bool ParseServiceStatement(ServiceDescriptorProto* message, - const LocationRecorder& service_location, - const FileDescriptorProto* containing_file); - - // Parse a field of a message. If the field is a group, its type will be - // added to "messages". - // - // parent_location and location_field_number_for_nested_type are needed when - // parsing groups -- we need to generate a nested message type within the - // parent and record its location accordingly. Since the parent could be - // either a FileDescriptorProto or a DescriptorProto, we must pass in the - // correct field number to use. - bool ParseMessageField(FieldDescriptorProto* field, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - // Like ParseMessageField() but expects the label has already been filled in - // by the caller. - bool ParseMessageFieldNoLabel(FieldDescriptorProto* field, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - // Parse an "extensions" declaration. - bool ParseExtensions(DescriptorProto* message, - const LocationRecorder& extensions_location, - const FileDescriptorProto* containing_file); - - // Parse a "reserved" declaration. - bool ParseReserved(DescriptorProto* message, - const LocationRecorder& message_location); - bool ParseReservedNames(DescriptorProto* message, - const LocationRecorder& parent_location); - bool ParseReservedNumbers(DescriptorProto* message, - const LocationRecorder& parent_location); - - // Parse an "extend" declaration. (See also comments for - // ParseMessageField().) - bool ParseExtend(RepeatedPtrField* extensions, - RepeatedPtrField* messages, - const LocationRecorder& parent_location, - int location_field_number_for_nested_type, - const LocationRecorder& extend_location, - const FileDescriptorProto* containing_file); - - // Parse a "oneof" declaration. The caller is responsible for setting - // oneof_decl->label() since it will have had to parse the label before it - // knew it was parsing a oneof. - bool ParseOneof(OneofDescriptorProto* oneof_decl, - DescriptorProto* containing_type, - int oneof_index, - const LocationRecorder& oneof_location, - const LocationRecorder& containing_type_location, - const FileDescriptorProto* containing_file); - - // Parse a single enum value within an enum block. - bool ParseEnumConstant(EnumValueDescriptorProto* enum_value, - const LocationRecorder& enum_value_location, - const FileDescriptorProto* containing_file); - - // Parse enum constant options, i.e. the list in square brackets at the end - // of the enum constant value definition. - bool ParseEnumConstantOptions(EnumValueDescriptorProto* value, - const LocationRecorder& enum_value_location, - const FileDescriptorProto* containing_file); - - // Parse a single method within a service definition. - bool ParseServiceMethod(MethodDescriptorProto* method, - const LocationRecorder& method_location, - const FileDescriptorProto* containing_file); - - - // Parse options of a single method or stream. - bool ParseMethodOptions(const LocationRecorder& parent_location, - const FileDescriptorProto* containing_file, - const int optionsFieldNumber, - Message* mutable_options); - - // Parse "required", "optional", or "repeated" and fill in "label" - // with the value. Returns true if such a label is consumed. - bool ParseLabel(FieldDescriptorProto::Label* label, - const FileDescriptorProto* containing_file); - - // Parse a type name and fill in "type" (if it is a primitive) or - // "type_name" (if it is not) with the type parsed. - bool ParseType(FieldDescriptorProto::Type* type, - string* type_name); - // Parse a user-defined type and fill in "type_name" with the name. - // If a primitive type is named, it is treated as an error. - bool ParseUserDefinedType(string* type_name); - - // Parses field options, i.e. the stuff in square brackets at the end - // of a field definition. Also parses default value. - bool ParseFieldOptions(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - // Parse the "default" option. This needs special handling because its - // type is the field's type. - bool ParseDefaultAssignment(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - bool ParseJsonName(FieldDescriptorProto* field, - const LocationRecorder& field_location, - const FileDescriptorProto* containing_file); - - enum OptionStyle { - OPTION_ASSIGNMENT, // just "name = value" - OPTION_STATEMENT // "option name = value;" - }; - - // Parse a single option name/value pair, e.g. "ctype = CORD". The name - // identifies a field of the given Message, and the value of that field - // is set to the parsed value. - bool ParseOption(Message* options, - const LocationRecorder& options_location, - const FileDescriptorProto* containing_file, - OptionStyle style); - - // Parses a single part of a multipart option name. A multipart name consists - // of names separated by dots. Each name is either an identifier or a series - // of identifiers separated by dots and enclosed in parentheses. E.g., - // "foo.(bar.baz).qux". - bool ParseOptionNamePart(UninterpretedOption* uninterpreted_option, - const LocationRecorder& part_location, - const FileDescriptorProto* containing_file); - - // Parses a string surrounded by balanced braces. Strips off the outer - // braces and stores the enclosed string in *value. - // E.g., - // { foo } *value gets 'foo' - // { foo { bar: box } } *value gets 'foo { bar: box }' - // {} *value gets '' - // - // REQUIRES: LookingAt("{") - // When finished successfully, we are looking at the first token past - // the ending brace. - bool ParseUninterpretedBlock(string* value); - - struct MapField { - // Whether the field is a map field. - bool is_map_field; - // The types of the key and value if they are primitive types. - FieldDescriptorProto::Type key_type; - FieldDescriptorProto::Type value_type; - // Or the type names string if the types are customized types. - string key_type_name; - string value_type_name; - - MapField() : is_map_field(false) {} - }; - // Desugar the map syntax to generate a nested map entry message. - void GenerateMapEntry(const MapField& map_field, FieldDescriptorProto* field, - RepeatedPtrField* messages); - - // Whether fields without label default to optional fields. - bool DefaultToOptionalFields() const { - return syntax_identifier_ == "proto3"; - } - - - bool ValidateEnum(const EnumDescriptorProto* proto); - - // ================================================================= - - io::Tokenizer* input_; - io::ErrorCollector* error_collector_; - SourceCodeInfo* source_code_info_; - SourceLocationTable* source_location_table_; // legacy - bool had_errors_; - bool require_syntax_identifier_; - bool stop_after_syntax_identifier_; - string syntax_identifier_; - - // Leading doc comments for the next declaration. These are not complete - // yet; use ConsumeEndOfDeclaration() to get the complete comments. - string upcoming_doc_comments_; - - // Detached comments are not connected to any syntax entities. Elements in - // this vector are paragraphs of comments separated by empty lines. The - // detached comments will be put into the leading_detached_comments field for - // the next element (See SourceCodeInfo.Location in descriptor.proto), when - // ConsumeEndOfDeclaration() is called. - vector upcoming_detached_comments_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Parser); -}; - -// A table mapping (descriptor, ErrorLocation) pairs -- as reported by -// DescriptorPool when validating descriptors -- to line and column numbers -// within the original source code. -// -// This is semi-obsolete: FileDescriptorProto.source_code_info now contains -// far more complete information about source locations. However, as of this -// writing you still need to use SourceLocationTable when integrating with -// DescriptorPool. -class LIBPROTOBUF_EXPORT SourceLocationTable { - public: - SourceLocationTable(); - ~SourceLocationTable(); - - // Finds the precise location of the given error and fills in *line and - // *column with the line and column numbers. If not found, sets *line to - // -1 and *column to 0 (since line = -1 is used to mean "error has no exact - // location" in the ErrorCollector interface). Returns true if found, false - // otherwise. - bool Find(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, - int* line, int* column) const; - - // Adds a location to the table. - void Add(const Message* descriptor, - DescriptorPool::ErrorCollector::ErrorLocation location, - int line, int column); - - // Clears the contents of the table. - void Clear(); - - private: - typedef map< - pair, - pair > LocationMap; - LocationMap location_map_; -}; - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PARSER_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/php/php_generator.h b/app/src/main/cpp/google/protobuf/compiler/php/php_generator.h deleted file mode 100644 index ce2b000..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/php/php_generator.h +++ /dev/null @@ -1,57 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ - -#include - -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace php { - -class LIBPROTOC_EXPORT Generator - : public google::protobuf::compiler::CodeGenerator { - virtual bool Generate( - const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; -}; - -} // namespace php -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_PHP_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/plugin.h b/app/src/main/cpp/google/protobuf/compiler/plugin.h deleted file mode 100644 index d2793a9..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/plugin.h +++ /dev/null @@ -1,90 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// Front-end for protoc code generator plugins written in C++. -// -// To implement a protoc plugin in C++, simply write an implementation of -// CodeGenerator, then create a main() function like: -// int main(int argc, char* argv[]) { -// MyCodeGenerator generator; -// return google::protobuf::compiler::PluginMain(argc, argv, &generator); -// } -// You must link your plugin against libprotobuf and libprotoc. -// -// The core part of PluginMain is to invoke the given CodeGenerator on a -// CodeGeneratorRequest to generate a CodeGeneratorResponse. This part is -// abstracted out and made into function GenerateCode so that it can be reused, -// for example, to implement a variant of PluginMain that does some -// preprocessing on the input CodeGeneratorRequest before feeding the request -// to the given code generator. -// -// To get protoc to use the plugin, do one of the following: -// * Place the plugin binary somewhere in the PATH and give it the name -// "protoc-gen-NAME" (replacing "NAME" with the name of your plugin). If you -// then invoke protoc with the parameter --NAME_out=OUT_DIR (again, replace -// "NAME" with your plugin's name), protoc will invoke your plugin to generate -// the output, which will be placed in OUT_DIR. -// * Place the plugin binary anywhere, with any name, and pass the --plugin -// parameter to protoc to direct it to your plugin like so: -// protoc --plugin=protoc-gen-NAME=path/to/mybinary --NAME_out=OUT_DIR -// On Windows, make sure to include the .exe suffix: -// protoc --plugin=protoc-gen-NAME=path/to/mybinary.exe --NAME_out=OUT_DIR - -#ifndef GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ -#define GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ - -#include - -#include -namespace google { -namespace protobuf { -namespace compiler { - -class CodeGenerator; // code_generator.h -class CodeGeneratorRequest; -class CodeGeneratorResponse; - -// Implements main() for a protoc plugin exposing the given code generator. -LIBPROTOC_EXPORT int PluginMain(int argc, char* argv[], const CodeGenerator* generator); - -// Generates code using the given code generator. Returns true if the code -// generation is successful. If the code geneartion fails, error_msg may be -// populated to describe the failure cause. -bool GenerateCode(const CodeGeneratorRequest& request, - const CodeGenerator& generator, CodeGeneratorResponse* response, - string* error_msg); - -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PLUGIN_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/plugin.pb.h b/app/src/main/cpp/google/protobuf/compiler/plugin.pb.h deleted file mode 100644 index f9a99e7..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/plugin.pb.h +++ /dev/null @@ -1,855 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/compiler/plugin.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { -namespace compiler { - -// Internal implementation detail -- do not call these. -void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); -void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - -class CodeGeneratorRequest; -class CodeGeneratorResponse; -class CodeGeneratorResponse_File; - -// =================================================================== - -class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorRequest) */ { - public: - CodeGeneratorRequest(); - virtual ~CodeGeneratorRequest(); - - CodeGeneratorRequest(const CodeGeneratorRequest& from); - - inline CodeGeneratorRequest& operator=(const CodeGeneratorRequest& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorRequest& default_instance(); - - static const CodeGeneratorRequest* internal_default_instance(); - - void Swap(CodeGeneratorRequest* other); - - // implements Message ---------------------------------------------- - - inline CodeGeneratorRequest* New() const { return New(NULL); } - - CodeGeneratorRequest* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorRequest& from); - void MergeFrom(const CodeGeneratorRequest& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(CodeGeneratorRequest* other); - void UnsafeMergeFrom(const CodeGeneratorRequest& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string file_to_generate = 1; - int file_to_generate_size() const; - void clear_file_to_generate(); - static const int kFileToGenerateFieldNumber = 1; - const ::std::string& file_to_generate(int index) const; - ::std::string* mutable_file_to_generate(int index); - void set_file_to_generate(int index, const ::std::string& value); - void set_file_to_generate(int index, const char* value); - void set_file_to_generate(int index, const char* value, size_t size); - ::std::string* add_file_to_generate(); - void add_file_to_generate(const ::std::string& value); - void add_file_to_generate(const char* value); - void add_file_to_generate(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& file_to_generate() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_file_to_generate(); - - // optional string parameter = 2; - bool has_parameter() const; - void clear_parameter(); - static const int kParameterFieldNumber = 2; - const ::std::string& parameter() const; - void set_parameter(const ::std::string& value); - void set_parameter(const char* value); - void set_parameter(const char* value, size_t size); - ::std::string* mutable_parameter(); - ::std::string* release_parameter(); - void set_allocated_parameter(::std::string* parameter); - - // repeated .google.protobuf.FileDescriptorProto proto_file = 15; - int proto_file_size() const; - void clear_proto_file(); - static const int kProtoFileFieldNumber = 15; - const ::google::protobuf::FileDescriptorProto& proto_file(int index) const; - ::google::protobuf::FileDescriptorProto* mutable_proto_file(int index); - ::google::protobuf::FileDescriptorProto* add_proto_file(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* - mutable_proto_file(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& - proto_file() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorRequest) - private: - inline void set_has_parameter(); - inline void clear_has_parameter(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> file_to_generate_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > proto_file_; - ::google::protobuf::internal::ArenaStringPtr parameter_; - friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorRequest_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse.File) */ { - public: - CodeGeneratorResponse_File(); - virtual ~CodeGeneratorResponse_File(); - - CodeGeneratorResponse_File(const CodeGeneratorResponse_File& from); - - inline CodeGeneratorResponse_File& operator=(const CodeGeneratorResponse_File& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorResponse_File& default_instance(); - - static const CodeGeneratorResponse_File* internal_default_instance(); - - void Swap(CodeGeneratorResponse_File* other); - - // implements Message ---------------------------------------------- - - inline CodeGeneratorResponse_File* New() const { return New(NULL); } - - CodeGeneratorResponse_File* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorResponse_File& from); - void MergeFrom(const CodeGeneratorResponse_File& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(CodeGeneratorResponse_File* other); - void UnsafeMergeFrom(const CodeGeneratorResponse_File& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string insertion_point = 2; - bool has_insertion_point() const; - void clear_insertion_point(); - static const int kInsertionPointFieldNumber = 2; - const ::std::string& insertion_point() const; - void set_insertion_point(const ::std::string& value); - void set_insertion_point(const char* value); - void set_insertion_point(const char* value, size_t size); - ::std::string* mutable_insertion_point(); - ::std::string* release_insertion_point(); - void set_allocated_insertion_point(::std::string* insertion_point); - - // optional string content = 15; - bool has_content() const; - void clear_content(); - static const int kContentFieldNumber = 15; - const ::std::string& content() const; - void set_content(const ::std::string& value); - void set_content(const char* value); - void set_content(const char* value, size_t size); - ::std::string* mutable_content(); - ::std::string* release_content(); - void set_allocated_content(::std::string* content); - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse.File) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_insertion_point(); - inline void clear_has_insertion_point(); - inline void set_has_content(); - inline void clear_has_content(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr insertion_point_; - ::google::protobuf::internal::ArenaStringPtr content_; - friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorResponse_File_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.compiler.CodeGeneratorResponse) */ { - public: - CodeGeneratorResponse(); - virtual ~CodeGeneratorResponse(); - - CodeGeneratorResponse(const CodeGeneratorResponse& from); - - inline CodeGeneratorResponse& operator=(const CodeGeneratorResponse& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const CodeGeneratorResponse& default_instance(); - - static const CodeGeneratorResponse* internal_default_instance(); - - void Swap(CodeGeneratorResponse* other); - - // implements Message ---------------------------------------------- - - inline CodeGeneratorResponse* New() const { return New(NULL); } - - CodeGeneratorResponse* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const CodeGeneratorResponse& from); - void MergeFrom(const CodeGeneratorResponse& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(CodeGeneratorResponse* other); - void UnsafeMergeFrom(const CodeGeneratorResponse& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef CodeGeneratorResponse_File File; - - // accessors ------------------------------------------------------- - - // optional string error = 1; - bool has_error() const; - void clear_error(); - static const int kErrorFieldNumber = 1; - const ::std::string& error() const; - void set_error(const ::std::string& value); - void set_error(const char* value); - void set_error(const char* value, size_t size); - ::std::string* mutable_error(); - ::std::string* release_error(); - void set_allocated_error(::std::string* error); - - // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; - int file_size() const; - void clear_file(); - static const int kFileFieldNumber = 15; - const ::google::protobuf::compiler::CodeGeneratorResponse_File& file(int index) const; - ::google::protobuf::compiler::CodeGeneratorResponse_File* mutable_file(int index); - ::google::protobuf::compiler::CodeGeneratorResponse_File* add_file(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* - mutable_file(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& - file() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.compiler.CodeGeneratorResponse) - private: - inline void set_has_error(); - inline void clear_has_error(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File > file_; - ::google::protobuf::internal::ArenaStringPtr error_; - friend void LIBPROTOC_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void LIBPROTOC_EXPORT protobuf_AddDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fcompiler_2fplugin_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed CodeGeneratorResponse_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// CodeGeneratorRequest - -// repeated string file_to_generate = 1; -inline int CodeGeneratorRequest::file_to_generate_size() const { - return file_to_generate_.size(); -} -inline void CodeGeneratorRequest::clear_file_to_generate() { - file_to_generate_.Clear(); -} -inline const ::std::string& CodeGeneratorRequest::file_to_generate(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - return file_to_generate_.Get(index); -} -inline ::std::string* CodeGeneratorRequest::mutable_file_to_generate(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - return file_to_generate_.Mutable(index); -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - file_to_generate_.Mutable(index)->assign(value); -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value) { - file_to_generate_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) -} -inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, size_t size) { - file_to_generate_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) -} -inline ::std::string* CodeGeneratorRequest::add_file_to_generate() { - // @@protoc_insertion_point(field_add_mutable:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - return file_to_generate_.Add(); -} -inline void CodeGeneratorRequest::add_file_to_generate(const ::std::string& value) { - file_to_generate_.Add()->assign(value); - // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) -} -inline void CodeGeneratorRequest::add_file_to_generate(const char* value) { - file_to_generate_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) -} -inline void CodeGeneratorRequest::add_file_to_generate(const char* value, size_t size) { - file_to_generate_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -CodeGeneratorRequest::file_to_generate() const { - // @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - return file_to_generate_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -CodeGeneratorRequest::mutable_file_to_generate() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate) - return &file_to_generate_; -} - -// optional string parameter = 2; -inline bool CodeGeneratorRequest::has_parameter() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void CodeGeneratorRequest::set_has_parameter() { - _has_bits_[0] |= 0x00000002u; -} -inline void CodeGeneratorRequest::clear_has_parameter() { - _has_bits_[0] &= ~0x00000002u; -} -inline void CodeGeneratorRequest::clear_parameter() { - parameter_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_parameter(); -} -inline const ::std::string& CodeGeneratorRequest::parameter() const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.parameter) - return parameter_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorRequest::set_parameter(const ::std::string& value) { - set_has_parameter(); - parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorRequest.parameter) -} -inline void CodeGeneratorRequest::set_parameter(const char* value) { - set_has_parameter(); - parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.parameter) -} -inline void CodeGeneratorRequest::set_parameter(const char* value, size_t size) { - set_has_parameter(); - parameter_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorRequest.parameter) -} -inline ::std::string* CodeGeneratorRequest::mutable_parameter() { - set_has_parameter(); - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.parameter) - return parameter_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* CodeGeneratorRequest::release_parameter() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorRequest.parameter) - clear_has_parameter(); - return parameter_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorRequest::set_allocated_parameter(::std::string* parameter) { - if (parameter != NULL) { - set_has_parameter(); - } else { - clear_has_parameter(); - } - parameter_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), parameter); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorRequest.parameter) -} - -// repeated .google.protobuf.FileDescriptorProto proto_file = 15; -inline int CodeGeneratorRequest::proto_file_size() const { - return proto_file_.size(); -} -inline void CodeGeneratorRequest::clear_proto_file() { - proto_file_.Clear(); -} -inline const ::google::protobuf::FileDescriptorProto& CodeGeneratorRequest::proto_file(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.proto_file) - return proto_file_.Get(index); -} -inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::mutable_proto_file(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorRequest.proto_file) - return proto_file_.Mutable(index); -} -inline ::google::protobuf::FileDescriptorProto* CodeGeneratorRequest::add_proto_file() { - // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorRequest.proto_file) - return proto_file_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* -CodeGeneratorRequest::mutable_proto_file() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.CodeGeneratorRequest.proto_file) - return &proto_file_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& -CodeGeneratorRequest::proto_file() const { - // @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorRequest.proto_file) - return proto_file_; -} - -inline const CodeGeneratorRequest* CodeGeneratorRequest::internal_default_instance() { - return &CodeGeneratorRequest_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// CodeGeneratorResponse_File - -// optional string name = 1; -inline bool CodeGeneratorResponse_File::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void CodeGeneratorResponse_File::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void CodeGeneratorResponse_File::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& CodeGeneratorResponse_File::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.name) -} -inline void CodeGeneratorResponse_File::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.name) -} -inline void CodeGeneratorResponse_File::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.name) -} -inline ::std::string* CodeGeneratorResponse_File::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* CodeGeneratorResponse_File::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.name) -} - -// optional string insertion_point = 2; -inline bool CodeGeneratorResponse_File::has_insertion_point() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_insertion_point() { - _has_bits_[0] |= 0x00000002u; -} -inline void CodeGeneratorResponse_File::clear_has_insertion_point() { - _has_bits_[0] &= ~0x00000002u; -} -inline void CodeGeneratorResponse_File::clear_insertion_point() { - insertion_point_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_insertion_point(); -} -inline const ::std::string& CodeGeneratorResponse_File::insertion_point() const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) - return insertion_point_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_insertion_point(const ::std::string& value) { - set_has_insertion_point(); - insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) -} -inline void CodeGeneratorResponse_File::set_insertion_point(const char* value) { - set_has_insertion_point(); - insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) -} -inline void CodeGeneratorResponse_File::set_insertion_point(const char* value, size_t size) { - set_has_insertion_point(); - insertion_point_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) -} -inline ::std::string* CodeGeneratorResponse_File::mutable_insertion_point() { - set_has_insertion_point(); - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) - return insertion_point_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* CodeGeneratorResponse_File::release_insertion_point() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) - clear_has_insertion_point(); - return insertion_point_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_allocated_insertion_point(::std::string* insertion_point) { - if (insertion_point != NULL) { - set_has_insertion_point(); - } else { - clear_has_insertion_point(); - } - insertion_point_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), insertion_point); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.insertion_point) -} - -// optional string content = 15; -inline bool CodeGeneratorResponse_File::has_content() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void CodeGeneratorResponse_File::set_has_content() { - _has_bits_[0] |= 0x00000004u; -} -inline void CodeGeneratorResponse_File::clear_has_content() { - _has_bits_[0] &= ~0x00000004u; -} -inline void CodeGeneratorResponse_File::clear_content() { - content_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_content(); -} -inline const ::std::string& CodeGeneratorResponse_File::content() const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.File.content) - return content_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_content(const ::std::string& value) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.File.content) -} -inline void CodeGeneratorResponse_File::set_content(const char* value) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.File.content) -} -inline void CodeGeneratorResponse_File::set_content(const char* value, size_t size) { - set_has_content(); - content_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.File.content) -} -inline ::std::string* CodeGeneratorResponse_File::mutable_content() { - set_has_content(); - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.File.content) - return content_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* CodeGeneratorResponse_File::release_content() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.File.content) - clear_has_content(); - return content_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse_File::set_allocated_content(::std::string* content) { - if (content != NULL) { - set_has_content(); - } else { - clear_has_content(); - } - content_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), content); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.File.content) -} - -inline const CodeGeneratorResponse_File* CodeGeneratorResponse_File::internal_default_instance() { - return &CodeGeneratorResponse_File_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// CodeGeneratorResponse - -// optional string error = 1; -inline bool CodeGeneratorResponse::has_error() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void CodeGeneratorResponse::set_has_error() { - _has_bits_[0] |= 0x00000001u; -} -inline void CodeGeneratorResponse::clear_has_error() { - _has_bits_[0] &= ~0x00000001u; -} -inline void CodeGeneratorResponse::clear_error() { - error_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_error(); -} -inline const ::std::string& CodeGeneratorResponse::error() const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.error) - return error_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse::set_error(const ::std::string& value) { - set_has_error(); - error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.compiler.CodeGeneratorResponse.error) -} -inline void CodeGeneratorResponse::set_error(const char* value) { - set_has_error(); - error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorResponse.error) -} -inline void CodeGeneratorResponse::set_error(const char* value, size_t size) { - set_has_error(); - error_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.compiler.CodeGeneratorResponse.error) -} -inline ::std::string* CodeGeneratorResponse::mutable_error() { - set_has_error(); - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.error) - return error_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* CodeGeneratorResponse::release_error() { - // @@protoc_insertion_point(field_release:google.protobuf.compiler.CodeGeneratorResponse.error) - clear_has_error(); - return error_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void CodeGeneratorResponse::set_allocated_error(::std::string* error) { - if (error != NULL) { - set_has_error(); - } else { - clear_has_error(); - } - error_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), error); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.compiler.CodeGeneratorResponse.error) -} - -// repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; -inline int CodeGeneratorResponse::file_size() const { - return file_.size(); -} -inline void CodeGeneratorResponse::clear_file() { - file_.Clear(); -} -inline const ::google::protobuf::compiler::CodeGeneratorResponse_File& CodeGeneratorResponse::file(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorResponse.file) - return file_.Get(index); -} -inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::mutable_file(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.compiler.CodeGeneratorResponse.file) - return file_.Mutable(index); -} -inline ::google::protobuf::compiler::CodeGeneratorResponse_File* CodeGeneratorResponse::add_file() { - // @@protoc_insertion_point(field_add:google.protobuf.compiler.CodeGeneratorResponse.file) - return file_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >* -CodeGeneratorResponse::mutable_file() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.compiler.CodeGeneratorResponse.file) - return &file_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::compiler::CodeGeneratorResponse_File >& -CodeGeneratorResponse::file() const { - // @@protoc_insertion_point(field_list:google.protobuf.compiler.CodeGeneratorResponse.file) - return file_; -} - -inline const CodeGeneratorResponse* CodeGeneratorResponse::internal_default_instance() { - return &CodeGeneratorResponse_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace compiler -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fcompiler_2fplugin_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/compiler/plugin.proto b/app/src/main/cpp/google/protobuf/compiler/plugin.proto deleted file mode 100644 index acaee1f..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/plugin.proto +++ /dev/null @@ -1,150 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// WARNING: The plugin interface is currently EXPERIMENTAL and is subject to -// change. -// -// protoc (aka the Protocol Compiler) can be extended via plugins. A plugin is -// just a program that reads a CodeGeneratorRequest from stdin and writes a -// CodeGeneratorResponse to stdout. -// -// Plugins written using C++ can use google/protobuf/compiler/plugin.h instead -// of dealing with the raw protocol defined here. -// -// A plugin executable needs only to be placed somewhere in the path. The -// plugin should be named "protoc-gen-$NAME", and will then be used when the -// flag "--${NAME}_out" is passed to protoc. - -syntax = "proto2"; -package google.protobuf.compiler; -option java_package = "com.google.protobuf.compiler"; -option java_outer_classname = "PluginProtos"; - -option go_package = "plugin_go"; - -import "google/protobuf/descriptor.proto"; - -// An encoded CodeGeneratorRequest is written to the plugin's stdin. -message CodeGeneratorRequest { - // The .proto files that were explicitly listed on the command-line. The - // code generator should generate code only for these files. Each file's - // descriptor will be included in proto_file, below. - repeated string file_to_generate = 1; - - // The generator parameter passed on the command-line. - optional string parameter = 2; - - // FileDescriptorProtos for all files in files_to_generate and everything - // they import. The files will appear in topological order, so each file - // appears before any file that imports it. - // - // protoc guarantees that all proto_files will be written after - // the fields above, even though this is not technically guaranteed by the - // protobuf wire format. This theoretically could allow a plugin to stream - // in the FileDescriptorProtos and handle them one by one rather than read - // the entire set into memory at once. However, as of this writing, this - // is not similarly optimized on protoc's end -- it will store all fields in - // memory at once before sending them to the plugin. - repeated FileDescriptorProto proto_file = 15; -} - -// The plugin writes an encoded CodeGeneratorResponse to stdout. -message CodeGeneratorResponse { - // Error message. If non-empty, code generation failed. The plugin process - // should exit with status code zero even if it reports an error in this way. - // - // This should be used to indicate errors in .proto files which prevent the - // code generator from generating correct code. Errors which indicate a - // problem in protoc itself -- such as the input CodeGeneratorRequest being - // unparseable -- should be reported by writing a message to stderr and - // exiting with a non-zero status code. - optional string error = 1; - - // Represents a single generated file. - message File { - // The file name, relative to the output directory. The name must not - // contain "." or ".." components and must be relative, not be absolute (so, - // the file cannot lie outside the output directory). "/" must be used as - // the path separator, not "\". - // - // If the name is omitted, the content will be appended to the previous - // file. This allows the generator to break large files into small chunks, - // and allows the generated text to be streamed back to protoc so that large - // files need not reside completely in memory at one time. Note that as of - // this writing protoc does not optimize for this -- it will read the entire - // CodeGeneratorResponse before writing files to disk. - optional string name = 1; - - // If non-empty, indicates that the named file should already exist, and the - // content here is to be inserted into that file at a defined insertion - // point. This feature allows a code generator to extend the output - // produced by another code generator. The original generator may provide - // insertion points by placing special annotations in the file that look - // like: - // @@protoc_insertion_point(NAME) - // The annotation can have arbitrary text before and after it on the line, - // which allows it to be placed in a comment. NAME should be replaced with - // an identifier naming the point -- this is what other generators will use - // as the insertion_point. Code inserted at this point will be placed - // immediately above the line containing the insertion point (thus multiple - // insertions to the same point will come out in the order they were added). - // The double-@ is intended to make it unlikely that the generated code - // could contain things that look like insertion points by accident. - // - // For example, the C++ code generator places the following line in the - // .pb.h files that it generates: - // // @@protoc_insertion_point(namespace_scope) - // This line appears within the scope of the file's package namespace, but - // outside of any particular class. Another plugin can then specify the - // insertion_point "namespace_scope" to generate additional classes or - // other declarations that should be placed in this scope. - // - // Note that if the line containing the insertion point begins with - // whitespace, the same whitespace will be added to every line of the - // inserted text. This is useful for languages like Python, where - // indentation matters. In these languages, the insertion point comment - // should be indented the same amount as any inserted code will need to be - // in order to work correctly in that context. - // - // The code generator that generates the initial file and the one which - // inserts into it must both run as part of a single invocation of protoc. - // Code generators are executed in the order in which they appear on the - // command line. - // - // If |insertion_point| is present, |name| must also be present. - optional string insertion_point = 2; - - // The file contents. - optional string content = 15; - } - repeated File file = 15; -} diff --git a/app/src/main/cpp/google/protobuf/compiler/python/python_generator.h b/app/src/main/cpp/google/protobuf/compiler/python/python_generator.h deleted file mode 100644 index 7583aa6..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/python/python_generator.h +++ /dev/null @@ -1,174 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: robinson@google.com (Will Robinson) -// -// Generates Python code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ - -#include - -#include -#include -#include - -namespace google { -namespace protobuf { - -class Descriptor; -class EnumDescriptor; -class EnumValueDescriptor; -class FieldDescriptor; -class OneofDescriptor; -class ServiceDescriptor; - -namespace io { class Printer; } - -namespace compiler { -namespace python { - -// CodeGenerator implementation for generated Python protocol buffer classes. -// If you create your own protocol compiler binary and you want it to support -// Python output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator : public CodeGenerator { - public: - Generator(); - virtual ~Generator(); - - // CodeGenerator methods. - virtual bool Generate(const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; - - private: - void PrintImports() const; - void PrintFileDescriptor() const; - void PrintTopLevelEnums() const; - void PrintAllNestedEnumsInFile() const; - void PrintNestedEnums(const Descriptor& descriptor) const; - void PrintEnum(const EnumDescriptor& enum_descriptor) const; - - void PrintTopLevelExtensions() const; - - void PrintFieldDescriptor( - const FieldDescriptor& field, bool is_extension) const; - void PrintFieldDescriptorsInDescriptor( - const Descriptor& message_descriptor, - bool is_extension, - const string& list_variable_name, - int (Descriptor::*CountFn)() const, - const FieldDescriptor* (Descriptor::*GetterFn)(int) const) const; - void PrintFieldsInDescriptor(const Descriptor& message_descriptor) const; - void PrintExtensionsInDescriptor(const Descriptor& message_descriptor) const; - void PrintMessageDescriptors() const; - void PrintDescriptor(const Descriptor& message_descriptor) const; - void PrintNestedDescriptors(const Descriptor& containing_descriptor) const; - - void PrintMessages() const; - void PrintMessage(const Descriptor& message_descriptor, const string& prefix, - vector* to_register) const; - void PrintNestedMessages(const Descriptor& containing_descriptor, - const string& prefix, - vector* to_register) const; - - void FixForeignFieldsInDescriptors() const; - void FixForeignFieldsInDescriptor( - const Descriptor& descriptor, - const Descriptor* containing_descriptor) const; - void FixForeignFieldsInField(const Descriptor* containing_type, - const FieldDescriptor& field, - const string& python_dict_name) const; - void AddMessageToFileDescriptor(const Descriptor& descriptor) const; - void AddEnumToFileDescriptor(const EnumDescriptor& descriptor) const; - void AddExtensionToFileDescriptor(const FieldDescriptor& descriptor) const; - string FieldReferencingExpression(const Descriptor* containing_type, - const FieldDescriptor& field, - const string& python_dict_name) const; - template - void FixContainingTypeInDescriptor( - const DescriptorT& descriptor, - const Descriptor* containing_descriptor) const; - - void FixForeignFieldsInExtensions() const; - void FixForeignFieldsInExtension( - const FieldDescriptor& extension_field) const; - void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const; - - void PrintServices() const; - void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; - void PrintServiceClass(const ServiceDescriptor& descriptor) const; - void PrintServiceStub(const ServiceDescriptor& descriptor) const; - void PrintDescriptorKeyAndModuleName( - const ServiceDescriptor& descriptor) const ; - - void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; - string OptionsValue(const string& class_name, - const string& serialized_options) const; - bool GeneratingDescriptorProto() const; - - template - string ModuleLevelDescriptorName(const DescriptorT& descriptor) const; - string ModuleLevelMessageName(const Descriptor& descriptor) const; - string ModuleLevelServiceDescriptorName( - const ServiceDescriptor& descriptor) const; - - template - void PrintSerializedPbInterval( - const DescriptorT& descriptor, DescriptorProtoT& proto) const; - - void FixAllDescriptorOptions() const; - void FixOptionsForField(const FieldDescriptor& field) const; - void FixOptionsForOneof(const OneofDescriptor& oneof) const; - void FixOptionsForEnum(const EnumDescriptor& descriptor) const; - void FixOptionsForMessage(const Descriptor& descriptor) const; - - void CopyPublicDependenciesAliases( - const string& copy_from, const FileDescriptor* file) const; - - // Very coarse-grained lock to ensure that Generate() is reentrant. - // Guards file_, printer_ and file_descriptor_serialized_. - mutable Mutex mutex_; - mutable const FileDescriptor* file_; // Set in Generate(). Under mutex_. - mutable string file_descriptor_serialized_; - mutable io::Printer* printer_; // Set in Generate(). Under mutex_. - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator); -}; - -} // namespace python -} // namespace compiler -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_COMPILER_PYTHON_GENERATOR_H__ diff --git a/app/src/main/cpp/google/protobuf/compiler/ruby/ruby_generator.h b/app/src/main/cpp/google/protobuf/compiler/ruby/ruby_generator.h deleted file mode 100644 index 8c1dfa2..0000000 --- a/app/src/main/cpp/google/protobuf/compiler/ruby/ruby_generator.h +++ /dev/null @@ -1,64 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Generates Ruby code for a given .proto file. - -#ifndef GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ -#define GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ - -#include - -#include - -namespace google { -namespace protobuf { -namespace compiler { -namespace ruby { - -// CodeGenerator implementation for generated Ruby protocol buffer classes. -// If you create your own protocol compiler binary and you want it to support -// Ruby output, you can do so by registering an instance of this -// CodeGenerator with the CommandLineInterface in your main() function. -class LIBPROTOC_EXPORT Generator - : public google::protobuf::compiler::CodeGenerator { - virtual bool Generate( - const FileDescriptor* file, - const string& parameter, - GeneratorContext* generator_context, - string* error) const; -}; - -} // namespace ruby -} // namespace compiler -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMPILER_RUBY_GENERATOR_H__ - diff --git a/app/src/main/cpp/google/protobuf/descriptor.h b/app/src/main/cpp/google/protobuf/descriptor.h deleted file mode 100644 index 0151e1d..0000000 --- a/app/src/main/cpp/google/protobuf/descriptor.h +++ /dev/null @@ -1,1924 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains classes which describe a type of protocol message. -// You can use a message's descriptor to learn at runtime what fields -// it contains and what the types of those fields are. The Message -// interface also allows you to dynamically access and modify individual -// fields by passing the FieldDescriptor of the field you are interested -// in. -// -// Most users will not care about descriptors, because they will write -// code specific to certain protocol types and will simply use the classes -// generated by the protocol compiler directly. Advanced users who want -// to operate on arbitrary types (not known at compile time) may want to -// read descriptors in order to learn about the contents of a message. -// A very small number of users will want to construct their own -// Descriptors, either because they are implementing Message manually or -// because they are writing something like the protocol compiler. -// -// For an example of how you might use descriptors, see the code example -// at the top of message.h. - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_H__ -#define GOOGLE_PROTOBUF_DESCRIPTOR_H__ - -#include -#ifndef _SHARED_PTR_H -#include -#endif -#include -#include -#include -#include - -// TYPE_BOOL is defined in the MacOS's ConditionalMacros.h. -#ifdef TYPE_BOOL -#undef TYPE_BOOL -#endif // TYPE_BOOL - -namespace google { -namespace protobuf { - -// Defined in this file. -class Descriptor; -class FieldDescriptor; -class OneofDescriptor; -class EnumDescriptor; -class EnumValueDescriptor; -class ServiceDescriptor; -class MethodDescriptor; -class FileDescriptor; -class DescriptorDatabase; -class DescriptorPool; - -// Defined in descriptor.proto -class DescriptorProto; -class FieldDescriptorProto; -class OneofDescriptorProto; -class EnumDescriptorProto; -class EnumValueDescriptorProto; -class ServiceDescriptorProto; -class MethodDescriptorProto; -class FileDescriptorProto; -class MessageOptions; -class FieldOptions; -class OneofOptions; -class EnumOptions; -class EnumValueOptions; -class ServiceOptions; -class MethodOptions; -class FileOptions; -class UninterpretedOption; -class SourceCodeInfo; - -// Defined in message.h -class Message; - -// Defined in descriptor.cc -class DescriptorBuilder; -class FileDescriptorTables; - -// Defined in unknown_field_set.h. -class UnknownField; - -// Defined in generated_message_reflection.h. -namespace internal { -class GeneratedMessageReflection; -} // namespace internal - -// Defined in command_line_interface.cc -namespace compiler { -class CommandLineInterface; -} // namespace compiler - -namespace descriptor_unittest { -class DescriptorTest; -} // namespace descriptor_unittest - -// Defined in printer.h -namespace io { -class Printer; -} // namespace io - -// NB, all indices are zero-based. -struct SourceLocation { - int start_line; - int end_line; - int start_column; - int end_column; - - // Doc comments found at the source location. - // See the comments in SourceCodeInfo.Location (descriptor.proto) for details. - string leading_comments; - string trailing_comments; - std::vector leading_detached_comments; -}; - -// Options when generating machine-parsable output from a descriptor with -// DebugString(). -struct DebugStringOptions { - // include original user comments as recorded in SourceLocation entries. N.B. - // that this must be |false| by default: several other pieces of code (for - // example, the C++ code generation for fields in the proto compiler) rely on - // DebugString() output being unobstructed by user comments. - bool include_comments; - // If true, elide the braced body in the debug string. - bool elide_group_body; - bool elide_oneof_body; - - DebugStringOptions() - : include_comments(false), - elide_group_body(false), - elide_oneof_body(false) {} -}; - -// Describes a type of protocol message, or a particular group within a -// message. To obtain the Descriptor for a given message object, call -// Message::GetDescriptor(). Generated message classes also have a -// static method called descriptor() which returns the type's descriptor. -// Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT Descriptor { - public: - // The name of the message type, not including its scope. - const string& name() const; - - // The fully-qualified name of the message type, scope delimited by - // periods. For example, message type "Foo" which is declared in package - // "bar" has full name "bar.Foo". If a type "Baz" is nested within - // Foo, Baz's full_name is "bar.Foo.Baz". To get only the part that - // comes after the last '.', use name(). - const string& full_name() const; - - // Index of this descriptor within the file or containing type's message - // type array. - int index() const; - - // The .proto file in which this message type was defined. Never NULL. - const FileDescriptor* file() const; - - // If this Descriptor describes a nested type, this returns the type - // in which it is nested. Otherwise, returns NULL. - const Descriptor* containing_type() const; - - // Get options for this message type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the message definition. - // Allowed options are defined by MessageOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const MessageOptions& options() const; - - // Write the contents of this Descriptor into the given DescriptorProto. - // The target DescriptorProto must be clear before calling this; if it - // isn't, the result may be garbage. - void CopyTo(DescriptorProto* proto) const; - - // Write the contents of this decriptor in a human-readable form. Output - // will be suitable for re-parsing. - string DebugString() const; - - // Similar to DebugString(), but additionally takes options (e.g., - // include original user comments in output). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Returns true if this is a placeholder for an unknown type. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - // Field stuff ----------------------------------------------------- - - // The number of fields in this message type. - int field_count() const; - // Gets a field by index, where 0 <= index < field_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* field(int index) const; - - // Looks up a field by declared tag number. Returns NULL if no such field - // exists. - const FieldDescriptor* FindFieldByNumber(int number) const; - // Looks up a field by name. Returns NULL if no such field exists. - const FieldDescriptor* FindFieldByName(const string& name) const; - - // Looks up a field by lowercased name (as returned by lowercase_name()). - // This lookup may be ambiguous if multiple field names differ only by case, - // in which case the field returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByLowercaseName( - const string& lowercase_name) const; - - // Looks up a field by camel-case name (as returned by camelcase_name()). - // This lookup may be ambiguous if multiple field names differ in a way that - // leads them to have identical camel-case names, in which case the field - // returned is chosen arbitrarily from the matches. - const FieldDescriptor* FindFieldByCamelcaseName( - const string& camelcase_name) const; - - // The number of oneofs in this message type. - int oneof_decl_count() const; - // Get a oneof by index, where 0 <= index < oneof_decl_count(). - // These are returned in the order they were defined in the .proto file. - const OneofDescriptor* oneof_decl(int index) const; - - // Looks up a oneof by name. Returns NULL if no such oneof exists. - const OneofDescriptor* FindOneofByName(const string& name) const; - - // Nested type stuff ----------------------------------------------- - - // The number of nested types in this message type. - int nested_type_count() const; - // Gets a nested type by index, where 0 <= index < nested_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* nested_type(int index) const; - - // Looks up a nested type by name. Returns NULL if no such nested type - // exists. - const Descriptor* FindNestedTypeByName(const string& name) const; - - // Enum stuff ------------------------------------------------------ - - // The number of enum types in this message type. - int enum_type_count() const; - // Gets an enum type by index, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Looks up an enum type by name. Returns NULL if no such enum type exists. - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - - // Looks up an enum value by name, among all enum types in this message. - // Returns NULL if no such value exists. - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - - // Extensions ------------------------------------------------------ - - // A range of field numbers which are designated for third-party - // extensions. - struct ExtensionRange { - int start; // inclusive - int end; // exclusive - }; - - // The number of extension ranges in this message type. - int extension_range_count() const; - // Gets an extension range by index, where 0 <= index < - // extension_range_count(). These are returned in the order they were defined - // in the .proto file. - const ExtensionRange* extension_range(int index) const; - - // Returns true if the number is in one of the extension ranges. - bool IsExtensionNumber(int number) const; - - // Returns NULL if no extension range contains the given number. - const ExtensionRange* FindExtensionRangeContainingNumber(int number) const; - - // The number of extensions -- extending *other* messages -- that were - // defined nested within this message type's scope. - int extension_count() const; - // Get an extension by index, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Looks up a named extension (which extends some *other* message type) - // defined within this message type's scope. - const FieldDescriptor* FindExtensionByName(const string& name) const; - - // Similar to FindFieldByLowercaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; - - // Similar to FindFieldByCamelcaseName(), but finds extensions defined within - // this message type's scope. - const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; - - // Reserved fields ------------------------------------------------- - - // A range of reserved field numbers. - struct ReservedRange { - int start; // inclusive - int end; // exclusive - }; - - // The number of reserved ranges in this message type. - int reserved_range_count() const; - // Gets an reserved range by index, where 0 <= index < - // reserved_range_count(). These are returned in the order they were defined - // in the .proto file. - const ReservedRange* reserved_range(int index) const; - - // Returns true if the number is in one of the reserved ranges. - bool IsReservedNumber(int number) const; - - // Returns NULL if no reserved range contains the given number. - const ReservedRange* FindReservedRangeContainingNumber(int number) const; - - // The number of reserved field names in this message type. - int reserved_name_count() const; - - // Gets a reserved name by index, where 0 <= index < reserved_name_count(). - const string& reserved_name(int index) const; - - // Returns true if the field name is reserved. - bool IsReservedName(const string& name) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this message declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef MessageOptions OptionsType; - - // Allows tests to test CopyTo(proto, true). - friend class ::google::protobuf::descriptor_unittest::DescriptorTest; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // Fill the json_name field of FieldDescriptorProto. - void CopyJsonNameTo(DescriptorProto* proto) const; - - // Internal version of DebugString; controls the level of indenting for - // correct depth. Takes |options| to control debug-string options, and - // |include_opening_clause| to indicate whether the "message ... " part of the - // clause has already been generated (this varies depending on context). - void DebugString(int depth, string *contents, - const DebugStringOptions& options, - bool include_opening_clause) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const MessageOptions* options_; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_; - - int field_count_; - FieldDescriptor* fields_; - int oneof_decl_count_; - OneofDescriptor* oneof_decls_; - int nested_type_count_; - Descriptor* nested_types_; - int enum_type_count_; - EnumDescriptor* enum_types_; - int extension_range_count_; - ExtensionRange* extension_ranges_; - int extension_count_; - FieldDescriptor* extensions_; - int reserved_range_count_; - ReservedRange* reserved_ranges_; - int reserved_name_count_; - const string** reserved_names_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in descriptor.cc - // and update them to initialize the field. - - // Must be constructed using DescriptorPool. - Descriptor() {} - friend class DescriptorBuilder; - friend class EnumDescriptor; - friend class FieldDescriptor; - friend class OneofDescriptor; - friend class MethodDescriptor; - friend class FileDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); -}; - -// Describes a single field of a message. To get the descriptor for a given -// field, first get the Descriptor for the message in which it is defined, -// then call Descriptor::FindFieldByName(). To get a FieldDescriptor for -// an extension, do one of the following: -// - Get the Descriptor or FileDescriptor for its containing scope, then -// call Descriptor::FindExtensionByName() or -// FileDescriptor::FindExtensionByName(). -// - Given a DescriptorPool, call DescriptorPool::FindExtensionByNumber(). -// - Given a Reflection for a message object, call -// Reflection::FindKnownExtensionByName() or -// Reflection::FindKnownExtensionByNumber(). -// Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT FieldDescriptor { - public: - // Identifies a field type. 0 is reserved for errors. The order is weird - // for historical reasons. Types 12 and up are new in proto2. - enum Type { - TYPE_DOUBLE = 1, // double, exactly eight bytes on the wire. - TYPE_FLOAT = 2, // float, exactly four bytes on the wire. - TYPE_INT64 = 3, // int64, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT64 if negative - // values are likely. - TYPE_UINT64 = 4, // uint64, varint on the wire. - TYPE_INT32 = 5, // int32, varint on the wire. Negative numbers - // take 10 bytes. Use TYPE_SINT32 if negative - // values are likely. - TYPE_FIXED64 = 6, // uint64, exactly eight bytes on the wire. - TYPE_FIXED32 = 7, // uint32, exactly four bytes on the wire. - TYPE_BOOL = 8, // bool, varint on the wire. - TYPE_STRING = 9, // UTF-8 text. - TYPE_GROUP = 10, // Tag-delimited message. Deprecated. - TYPE_MESSAGE = 11, // Length-delimited message. - - TYPE_BYTES = 12, // Arbitrary byte array. - TYPE_UINT32 = 13, // uint32, varint on the wire - TYPE_ENUM = 14, // Enum, varint on the wire - TYPE_SFIXED32 = 15, // int32, exactly four bytes on the wire - TYPE_SFIXED64 = 16, // int64, exactly eight bytes on the wire - TYPE_SINT32 = 17, // int32, ZigZag-encoded varint on the wire - TYPE_SINT64 = 18, // int64, ZigZag-encoded varint on the wire - - MAX_TYPE = 18, // Constant useful for defining lookup tables - // indexed by Type. - }; - - // Specifies the C++ data type used to represent the field. There is a - // fixed mapping from Type to CppType where each Type maps to exactly one - // CppType. 0 is reserved for errors. - enum CppType { - CPPTYPE_INT32 = 1, // TYPE_INT32, TYPE_SINT32, TYPE_SFIXED32 - CPPTYPE_INT64 = 2, // TYPE_INT64, TYPE_SINT64, TYPE_SFIXED64 - CPPTYPE_UINT32 = 3, // TYPE_UINT32, TYPE_FIXED32 - CPPTYPE_UINT64 = 4, // TYPE_UINT64, TYPE_FIXED64 - CPPTYPE_DOUBLE = 5, // TYPE_DOUBLE - CPPTYPE_FLOAT = 6, // TYPE_FLOAT - CPPTYPE_BOOL = 7, // TYPE_BOOL - CPPTYPE_ENUM = 8, // TYPE_ENUM - CPPTYPE_STRING = 9, // TYPE_STRING, TYPE_BYTES - CPPTYPE_MESSAGE = 10, // TYPE_MESSAGE, TYPE_GROUP - - MAX_CPPTYPE = 10, // Constant useful for defining lookup tables - // indexed by CppType. - }; - - // Identifies whether the field is optional, required, or repeated. 0 is - // reserved for errors. - enum Label { - LABEL_OPTIONAL = 1, // optional - LABEL_REQUIRED = 2, // required - LABEL_REPEATED = 3, // repeated - - MAX_LABEL = 3, // Constant useful for defining lookup tables - // indexed by Label. - }; - - // Valid field numbers are positive integers up to kMaxNumber. - static const int kMaxNumber = (1 << 29) - 1; - - // First field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kFirstReservedNumber = 19000; - // Last field number reserved for the protocol buffer library implementation. - // Users may not declare fields that use reserved numbers. - static const int kLastReservedNumber = 19999; - - const string& name() const; // Name of this field within the message. - const string& full_name() const; // Fully-qualified name of the field. - const string& json_name() const; // JSON name of this field. - const FileDescriptor* file() const;// File in which this field was defined. - bool is_extension() const; // Is this an extension field? - int number() const; // Declared tag number. - - // Same as name() except converted to lower-case. This (and especially the - // FindFieldByLowercaseName() method) can be useful when parsing formats - // which prefer to use lowercase naming style. (Although, technically - // field names should be lowercased anyway according to the protobuf style - // guide, so this only makes a difference when dealing with old .proto files - // which do not follow the guide.) - const string& lowercase_name() const; - - // Same as name() except converted to camel-case. In this conversion, any - // time an underscore appears in the name, it is removed and the next - // letter is capitalized. Furthermore, the first letter of the name is - // lower-cased. Examples: - // FooBar -> fooBar - // foo_bar -> fooBar - // fooBar -> fooBar - // This (and especially the FindFieldByCamelcaseName() method) can be useful - // when parsing formats which prefer to use camel-case naming style. - const string& camelcase_name() const; - - Type type() const; // Declared type of this field. - const char* type_name() const; // Name of the declared type. - CppType cpp_type() const; // C++ type of this field. - const char* cpp_type_name() const; // Name of the C++ type. - Label label() const; // optional/required/repeated - - bool is_required() const; // shorthand for label() == LABEL_REQUIRED - bool is_optional() const; // shorthand for label() == LABEL_OPTIONAL - bool is_repeated() const; // shorthand for label() == LABEL_REPEATED - bool is_packable() const; // shorthand for is_repeated() && - // IsTypePackable(type()) - bool is_packed() const; // shorthand for is_packable() && - // options().packed() - bool is_map() const; // shorthand for type() == TYPE_MESSAGE && - // message_type()->options().map_entry() - - // Index of this field within the message's field array, or the file or - // extension scope's extensions array. - int index() const; - - // Does this field have an explicitly-declared default value? - bool has_default_value() const; - - // Whether the user has specified the json_name field option in the .proto - // file. - bool has_json_name() const; - - // Get the field default value if cpp_type() == CPPTYPE_INT32. If no - // explicit default was defined, the default is 0. - int32 default_value_int32() const; - // Get the field default value if cpp_type() == CPPTYPE_INT64. If no - // explicit default was defined, the default is 0. - int64 default_value_int64() const; - // Get the field default value if cpp_type() == CPPTYPE_UINT32. If no - // explicit default was defined, the default is 0. - uint32 default_value_uint32() const; - // Get the field default value if cpp_type() == CPPTYPE_UINT64. If no - // explicit default was defined, the default is 0. - uint64 default_value_uint64() const; - // Get the field default value if cpp_type() == CPPTYPE_FLOAT. If no - // explicit default was defined, the default is 0.0. - float default_value_float() const; - // Get the field default value if cpp_type() == CPPTYPE_DOUBLE. If no - // explicit default was defined, the default is 0.0. - double default_value_double() const; - // Get the field default value if cpp_type() == CPPTYPE_BOOL. If no - // explicit default was defined, the default is false. - bool default_value_bool() const; - // Get the field default value if cpp_type() == CPPTYPE_ENUM. If no - // explicit default was defined, the default is the first value defined - // in the enum type (all enum types are required to have at least one value). - // This never returns NULL. - const EnumValueDescriptor* default_value_enum() const; - // Get the field default value if cpp_type() == CPPTYPE_STRING. If no - // explicit default was defined, the default is the empty string. - const string& default_value_string() const; - - // The Descriptor for the message of which this is a field. For extensions, - // this is the extended type. Never NULL. - const Descriptor* containing_type() const; - - // If the field is a member of a oneof, this is the one, otherwise this is - // NULL. - const OneofDescriptor* containing_oneof() const; - - // If the field is a member of a oneof, returns the index in that oneof. - int index_in_oneof() const; - - // An extension may be declared within the scope of another message. If this - // field is an extension (is_extension() is true), then extension_scope() - // returns that message, or NULL if the extension was declared at global - // scope. If this is not an extension, extension_scope() is undefined (may - // assert-fail). - const Descriptor* extension_scope() const; - - // If type is TYPE_MESSAGE or TYPE_GROUP, returns a descriptor for the - // message or the group type. Otherwise, returns null. - const Descriptor* message_type() const; - // If type is TYPE_ENUM, returns a descriptor for the enum. Otherwise, - // returns null. - const EnumDescriptor* enum_type() const; - - // Get the FieldOptions for this field. This includes things listed in - // square brackets after the field definition. E.g., the field: - // optional string text = 1 [ctype=CORD]; - // has the "ctype" option set. Allowed options are defined by FieldOptions - // in google/protobuf/descriptor.proto, and any available extensions of that - // message. - const FieldOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(FieldDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Helper method to get the CppType for a particular Type. - static CppType TypeToCppType(Type type); - - // Helper method to get the name of a Type. - static const char* TypeName(Type type); - - // Helper method to get the name of a CppType. - static const char* CppTypeName(CppType cpp_type); - - // Return true iff [packed = true] is valid for fields of this type. - static inline bool IsTypePackable(Type field_type); - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this field declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef FieldOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // Fill the json_name field of FieldDescriptorProto. - void CopyJsonNameTo(FieldDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - enum PrintLabelFlag { PRINT_LABEL, OMIT_LABEL }; - void DebugString(int depth, PrintLabelFlag print_label_flag, - string* contents, const DebugStringOptions& options) const; - - // formats the default value appropriately and returns it as a string. - // Must have a default value to call this. If quote_string_type is true, then - // types of CPPTYPE_STRING whill be surrounded by quotes and CEscaped. - string DefaultValueAsString(bool quote_string_type) const; - - // Helper function that returns the field type name for DebugString. - string FieldTypeNameDebugString() const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const string* lowercase_name_; - const string* camelcase_name_; - // Whether the user has specified the json_name field option in the .proto - // file. - bool has_json_name_; - // If has_json_name_ is true, it's the value specified by the user. - // Otherwise, it has the same value as camelcase_name_. - const string* json_name_; - const FileDescriptor* file_; - int number_; - Type type_; - Label label_; - bool is_extension_; - int index_in_oneof_; - const Descriptor* containing_type_; - const OneofDescriptor* containing_oneof_; - const Descriptor* extension_scope_; - const Descriptor* message_type_; - const EnumDescriptor* enum_type_; - const FieldOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - bool has_default_value_; - union { - int32 default_value_int32_; - int64 default_value_int64_; - uint32 default_value_uint32_; - uint64 default_value_uint64_; - float default_value_float_; - double default_value_double_; - bool default_value_bool_; - - const EnumValueDescriptor* default_value_enum_; - const string* default_value_string_; - }; - - static const CppType kTypeToCppTypeMap[MAX_TYPE + 1]; - - static const char * const kTypeToName[MAX_TYPE + 1]; - - static const char * const kCppTypeToName[MAX_CPPTYPE + 1]; - - static const char * const kLabelToName[MAX_LABEL + 1]; - - // Must be constructed using DescriptorPool. - FieldDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class Descriptor; - friend class OneofDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); -}; - -// Describes a oneof defined in a message type. -class LIBPROTOBUF_EXPORT OneofDescriptor { - public: - const string& name() const; // Name of this oneof. - const string& full_name() const; // Fully-qualified name of the oneof. - - // Index of this oneof within the message's oneof array. - int index() const; - - // The Descriptor for the message containing this oneof. - const Descriptor* containing_type() const; - - // The number of (non-extension) fields which are members of this oneof. - int field_count() const; - // Get a member of this oneof, in the order in which they were declared in the - // .proto file. Does not include extensions. - const FieldDescriptor* field(int index) const; - - const OneofOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(OneofDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this oneof declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef OneofOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // See Descriptor::DebugString(). - void DebugString(int depth, string* contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const Descriptor* containing_type_; - bool is_extendable_; - int field_count_; - const FieldDescriptor** fields_; - const OneofOptions* options_; - - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() - // in descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - OneofDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OneofDescriptor); -}; - -// Describes an enum type defined in a .proto file. To get the EnumDescriptor -// for a generated enum type, call TypeName_descriptor(). Use DescriptorPool -// to construct your own descriptors. -class LIBPROTOBUF_EXPORT EnumDescriptor { - public: - // The name of this enum type in the containing scope. - const string& name() const; - - // The fully-qualified name of the enum type, scope delimited by periods. - const string& full_name() const; - - // Index of this enum within the file or containing message's enum array. - int index() const; - - // The .proto file in which this enum type was defined. Never NULL. - const FileDescriptor* file() const; - - // The number of values for this EnumDescriptor. Guaranteed to be greater - // than zero. - int value_count() const; - // Gets a value by index, where 0 <= index < value_count(). - // These are returned in the order they were defined in the .proto file. - const EnumValueDescriptor* value(int index) const; - - // Looks up a value by name. Returns NULL if no such value exists. - const EnumValueDescriptor* FindValueByName(const string& name) const; - // Looks up a value by number. Returns NULL if no such value exists. If - // multiple values have this number, the first one defined is returned. - const EnumValueDescriptor* FindValueByNumber(int number) const; - - // If this enum type is nested in a message type, this is that message type. - // Otherwise, NULL. - const Descriptor* containing_type() const; - - // Get options for this enum type. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in the enum definition. Allowed - // options are defined by EnumOptions in google/protobuf/descriptor.proto, - // and any available extensions of that message. - const EnumOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - - // Returns true if this is a placeholder for an unknown enum. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this enum declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef EnumOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // Looks up a value by number. If the value does not exist, dynamically - // creates a new EnumValueDescriptor for that value, assuming that it was - // unknown. If a new descriptor is created, this is done in a thread-safe way, - // and future calls will return the same value descriptor pointer. - // - // This is private but is used by GeneratedMessageReflection (which is - // friended below) to return a valid EnumValueDescriptor from GetEnum() when - // this feature is enabled. - const EnumValueDescriptor* - FindValueByNumberCreatingIfUnknown(int number) const; - - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const Descriptor* containing_type_; - const EnumOptions* options_; - - // True if this is a placeholder for an unknown type. - bool is_placeholder_; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_; - - int value_count_; - EnumValueDescriptor* values_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - friend class FieldDescriptor; - friend class EnumValueDescriptor; - friend class FileDescriptor; - friend class internal::GeneratedMessageReflection; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumDescriptor); -}; - -// Describes an individual enum constant of a particular type. To get the -// EnumValueDescriptor for a given enum value, first get the EnumDescriptor -// for its type, then use EnumDescriptor::FindValueByName() or -// EnumDescriptor::FindValueByNumber(). Use DescriptorPool to construct -// your own descriptors. -class LIBPROTOBUF_EXPORT EnumValueDescriptor { - public: - const string& name() const; // Name of this enum constant. - int index() const; // Index within the enums's Descriptor. - int number() const; // Numeric value of this enum constant. - - // The full_name of an enum value is a sibling symbol of the enum type. - // e.g. the full name of FieldDescriptorProto::TYPE_INT32 is actually - // "google.protobuf.FieldDescriptorProto.TYPE_INT32", NOT - // "google.protobuf.FieldDescriptorProto.Type.TYPE_INT32". This is to conform - // with C++ scoping rules for enums. - const string& full_name() const; - - // The type of this value. Never NULL. - const EnumDescriptor* type() const; - - // Get options for this enum value. These are specified in the .proto file - // by adding text like "[foo = 1234]" after an enum value definition. - // Allowed options are defined by EnumValueOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const EnumValueOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(EnumValueDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this enum value declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef EnumValueOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - int number_; - const EnumDescriptor* type_; - const EnumValueOptions* options_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() - // in descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - EnumValueDescriptor() {} - friend class DescriptorBuilder; - friend class EnumDescriptor; - friend class FileDescriptorTables; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumValueDescriptor); -}; - -// Describes an RPC service. To get the ServiceDescriptor for a service, -// call Service::GetDescriptor(). Generated service classes also have a -// static method called descriptor() which returns the type's -// ServiceDescriptor. Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT ServiceDescriptor { - public: - // The name of the service, not including its containing scope. - const string& name() const; - // The fully-qualified name of the service, scope delimited by periods. - const string& full_name() const; - // Index of this service within the file's services array. - int index() const; - - // The .proto file in which this service was defined. Never NULL. - const FileDescriptor* file() const; - - // Get options for this service type. These are specified in the .proto file - // by placing lines like "option foo = 1234;" in the service definition. - // Allowed options are defined by ServiceOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const ServiceOptions& options() const; - - // The number of methods this service defines. - int method_count() const; - // Gets a MethodDescriptor by index, where 0 <= index < method_count(). - // These are returned in the order they were defined in the .proto file. - const MethodDescriptor* method(int index) const; - - // Look up a MethodDescriptor by name. - const MethodDescriptor* FindMethodByName(const string& name) const; - // See Descriptor::CopyTo(). - void CopyTo(ServiceDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this service declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef ServiceOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // See Descriptor::DebugString(). - void DebugString(string *contents, const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const FileDescriptor* file_; - const ServiceOptions* options_; - int method_count_; - MethodDescriptor* methods_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - ServiceDescriptor() {} - friend class DescriptorBuilder; - friend class FileDescriptor; - friend class MethodDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); -}; - -// Describes an individual service method. To obtain a MethodDescriptor given -// a service, first get its ServiceDescriptor, then call -// ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your -// own descriptors. -class LIBPROTOBUF_EXPORT MethodDescriptor { - public: - // Name of this method, not including containing scope. - const string& name() const; - // The fully-qualified name of the method, scope delimited by periods. - const string& full_name() const; - // Index within the service's Descriptor. - int index() const; - - // Gets the service to which this method belongs. Never NULL. - const ServiceDescriptor* service() const; - - // Gets the type of protocol message which this method accepts as input. - const Descriptor* input_type() const; - // Gets the type of protocol message which this message produces as output. - const Descriptor* output_type() const; - - // Gets whether the client streams multiple requests. - bool client_streaming() const; - // Gets whether the server streams multiple responses. - bool server_streaming() const; - - // Get options for this method. These are specified in the .proto file by - // placing lines like "option foo = 1234;" in curly-braces after a method - // declaration. Allowed options are defined by MethodOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const MethodOptions& options() const; - - // See Descriptor::CopyTo(). - void CopyTo(MethodDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - - // Source Location --------------------------------------------------- - - // Updates |*out_location| to the source location of the complete - // extent of this method declaration. Returns false and leaves - // |*out_location| unchanged iff location information was not available. - bool GetSourceLocation(SourceLocation* out_location) const; - - private: - typedef MethodOptions OptionsType; - - // Allows access to GetLocationPath for annotations. - friend class ::google::protobuf::io::Printer; - - // See Descriptor::DebugString(). - void DebugString(int depth, string *contents, - const DebugStringOptions& options) const; - - // Walks up the descriptor tree to generate the source location path - // to this descriptor from the file root. - void GetLocationPath(std::vector* output) const; - - const string* name_; - const string* full_name_; - const ServiceDescriptor* service_; - const Descriptor* input_type_; - const Descriptor* output_type_; - const MethodOptions* options_; - bool client_streaming_; - bool server_streaming_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - // Must be constructed using DescriptorPool. - MethodDescriptor() {} - friend class DescriptorBuilder; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MethodDescriptor); -}; - - -// Describes a whole .proto file. To get the FileDescriptor for a compiled-in -// file, get the descriptor for something defined in that file and call -// descriptor->file(). Use DescriptorPool to construct your own descriptors. -class LIBPROTOBUF_EXPORT FileDescriptor { - public: - // The filename, relative to the source tree. - // e.g. "google/protobuf/descriptor.proto" - const string& name() const; - - // The package, e.g. "google.protobuf.compiler". - const string& package() const; - - // The DescriptorPool in which this FileDescriptor and all its contents were - // allocated. Never NULL. - const DescriptorPool* pool() const; - - // The number of files imported by this one. - int dependency_count() const; - // Gets an imported file by index, where 0 <= index < dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* dependency(int index) const; - - // The number of files public imported by this one. - // The public dependency list is a subset of the dependency list. - int public_dependency_count() const; - // Gets a public imported file by index, where 0 <= index < - // public_dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* public_dependency(int index) const; - - // The number of files that are imported for weak fields. - // The weak dependency list is a subset of the dependency list. - int weak_dependency_count() const; - // Gets a weak imported file by index, where 0 <= index < - // weak_dependency_count(). - // These are returned in the order they were defined in the .proto file. - const FileDescriptor* weak_dependency(int index) const; - - // Number of top-level message types defined in this file. (This does not - // include nested types.) - int message_type_count() const; - // Gets a top-level message type, where 0 <= index < message_type_count(). - // These are returned in the order they were defined in the .proto file. - const Descriptor* message_type(int index) const; - - // Number of top-level enum types defined in this file. (This does not - // include nested types.) - int enum_type_count() const; - // Gets a top-level enum type, where 0 <= index < enum_type_count(). - // These are returned in the order they were defined in the .proto file. - const EnumDescriptor* enum_type(int index) const; - - // Number of services defined in this file. - int service_count() const; - // Gets a service, where 0 <= index < service_count(). - // These are returned in the order they were defined in the .proto file. - const ServiceDescriptor* service(int index) const; - - // Number of extensions defined at file scope. (This does not include - // extensions nested within message types.) - int extension_count() const; - // Gets an extension's descriptor, where 0 <= index < extension_count(). - // These are returned in the order they were defined in the .proto file. - const FieldDescriptor* extension(int index) const; - - // Get options for this file. These are specified in the .proto file by - // placing lines like "option foo = 1234;" at the top level, outside of any - // other definitions. Allowed options are defined by FileOptions in - // google/protobuf/descriptor.proto, and any available extensions of that - // message. - const FileOptions& options() const; - - // Syntax of this file. - enum Syntax { - SYNTAX_UNKNOWN = 0, - SYNTAX_PROTO2 = 2, - SYNTAX_PROTO3 = 3, - }; - Syntax syntax() const; - static const char* SyntaxName(Syntax syntax); - - // Find a top-level message type by name. Returns NULL if not found. - const Descriptor* FindMessageTypeByName(const string& name) const; - // Find a top-level enum type by name. Returns NULL if not found. - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - // Find an enum value defined in any top-level enum by name. Returns NULL if - // not found. - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - // Find a service definition by name. Returns NULL if not found. - const ServiceDescriptor* FindServiceByName(const string& name) const; - // Find a top-level extension definition by name. Returns NULL if not found. - const FieldDescriptor* FindExtensionByName(const string& name) const; - // Similar to FindExtensionByName(), but searches by lowercased-name. See - // Descriptor::FindFieldByLowercaseName(). - const FieldDescriptor* FindExtensionByLowercaseName(const string& name) const; - // Similar to FindExtensionByName(), but searches by camelcased-name. See - // Descriptor::FindFieldByCamelcaseName(). - const FieldDescriptor* FindExtensionByCamelcaseName(const string& name) const; - - // See Descriptor::CopyTo(). - // Notes: - // - This method does NOT copy source code information since it is relatively - // large and rarely needed. See CopySourceCodeInfoTo() below. - void CopyTo(FileDescriptorProto* proto) const; - // Write the source code information of this FileDescriptor into the given - // FileDescriptorProto. See CopyTo() above. - void CopySourceCodeInfoTo(FileDescriptorProto* proto) const; - // Fill the json_name field of FieldDescriptorProto for all fields. Can only - // be called after CopyTo(). - void CopyJsonNameTo(FileDescriptorProto* proto) const; - - // See Descriptor::DebugString(). - string DebugString() const; - - // See Descriptor::DebugStringWithOptions(). - string DebugStringWithOptions(const DebugStringOptions& options) const; - - // Returns true if this is a placeholder for an unknown file. This will - // only be the case if this descriptor comes from a DescriptorPool - // with AllowUnknownDependencies() set. - bool is_placeholder() const; - - // Updates |*out_location| to the source location of the complete extent of - // this file declaration (namely, the empty path). - bool GetSourceLocation(SourceLocation* out_location) const; - - // Updates |*out_location| to the source location of the complete - // extent of the declaration or declaration-part denoted by |path|. - // Returns false and leaves |*out_location| unchanged iff location - // information was not available. (See SourceCodeInfo for - // description of path encoding.) - bool GetSourceLocation(const std::vector& path, - SourceLocation* out_location) const; - - private: - typedef FileOptions OptionsType; - - const string* name_; - const string* package_; - const DescriptorPool* pool_; - int dependency_count_; - const FileDescriptor** dependencies_; - int public_dependency_count_; - int* public_dependencies_; - int weak_dependency_count_; - int* weak_dependencies_; - int message_type_count_; - Descriptor* message_types_; - int enum_type_count_; - EnumDescriptor* enum_types_; - int service_count_; - ServiceDescriptor* services_; - int extension_count_; - Syntax syntax_; - bool is_placeholder_; - FieldDescriptor* extensions_; - const FileOptions* options_; - - const FileDescriptorTables* tables_; - const SourceCodeInfo* source_code_info_; - // IMPORTANT: If you add a new field, make sure to search for all instances - // of Allocate() and AllocateArray() in - // descriptor.cc and update them to initialize the field. - - FileDescriptor() {} - friend class DescriptorBuilder; - friend class Descriptor; - friend class FieldDescriptor; - friend class OneofDescriptor; - friend class EnumDescriptor; - friend class EnumValueDescriptor; - friend class MethodDescriptor; - friend class ServiceDescriptor; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); -}; - -// =================================================================== - -// Used to construct descriptors. -// -// Normally you won't want to build your own descriptors. Message classes -// constructed by the protocol compiler will provide them for you. However, -// if you are implementing Message on your own, or if you are writing a -// program which can operate on totally arbitrary types and needs to load -// them from some sort of database, you might need to. -// -// Since Descriptors are composed of a whole lot of cross-linked bits of -// data that would be a pain to put together manually, the -// DescriptorPool class is provided to make the process easier. It can -// take a FileDescriptorProto (defined in descriptor.proto), validate it, -// and convert it to a set of nicely cross-linked Descriptors. -// -// DescriptorPool also helps with memory management. Descriptors are -// composed of many objects containing static data and pointers to each -// other. In all likelihood, when it comes time to delete this data, -// you'll want to delete it all at once. In fact, it is not uncommon to -// have a whole pool of descriptors all cross-linked with each other which -// you wish to delete all at once. This class represents such a pool, and -// handles the memory management for you. -// -// You can also search for descriptors within a DescriptorPool by name, and -// extensions by number. -class LIBPROTOBUF_EXPORT DescriptorPool { - public: - // Create a normal, empty DescriptorPool. - DescriptorPool(); - - // Constructs a DescriptorPool that, when it can't find something among the - // descriptors already in the pool, looks for it in the given - // DescriptorDatabase. - // Notes: - // - If a DescriptorPool is constructed this way, its BuildFile*() methods - // must not be called (they will assert-fail). The only way to populate - // the pool with descriptors is to call the Find*By*() methods. - // - The Find*By*() methods may block the calling thread if the - // DescriptorDatabase blocks. This in turn means that parsing messages - // may block if they need to look up extensions. - // - The Find*By*() methods will use mutexes for thread-safety, thus making - // them slower even when they don't have to fall back to the database. - // In fact, even the Find*By*() methods of descriptor objects owned by - // this pool will be slower, since they will have to obtain locks too. - // - An ErrorCollector may optionally be given to collect validation errors - // in files loaded from the database. If not given, errors will be printed - // to GOOGLE_LOG(ERROR). Remember that files are built on-demand, so this - // ErrorCollector may be called from any thread that calls one of the - // Find*By*() methods. - // - The DescriptorDatabase must not be mutated during the lifetime of - // the DescriptorPool. Even if the client takes care to avoid data races, - // changes to the content of the DescriptorDatabase may not be reflected - // in subsequent lookups in the DescriptorPool. - class ErrorCollector; - explicit DescriptorPool(DescriptorDatabase* fallback_database, - ErrorCollector* error_collector = NULL); - - ~DescriptorPool(); - - // Get a pointer to the generated pool. Generated protocol message classes - // which are compiled into the binary will allocate their descriptors in - // this pool. Do not add your own descriptors to this pool. - static const DescriptorPool* generated_pool(); - - - // Find a FileDescriptor in the pool by file name. Returns NULL if not - // found. - const FileDescriptor* FindFileByName(const string& name) const; - - // Find the FileDescriptor in the pool which defines the given symbol. - // If any of the Find*ByName() methods below would succeed, then this is - // equivalent to calling that method and calling the result's file() method. - // Otherwise this returns NULL. - const FileDescriptor* FindFileContainingSymbol( - const string& symbol_name) const; - - // Looking up descriptors ------------------------------------------ - // These find descriptors by fully-qualified name. These will find both - // top-level descriptors and nested descriptors. They return NULL if not - // found. - - const Descriptor* FindMessageTypeByName(const string& name) const; - const FieldDescriptor* FindFieldByName(const string& name) const; - const FieldDescriptor* FindExtensionByName(const string& name) const; - const OneofDescriptor* FindOneofByName(const string& name) const; - const EnumDescriptor* FindEnumTypeByName(const string& name) const; - const EnumValueDescriptor* FindEnumValueByName(const string& name) const; - const ServiceDescriptor* FindServiceByName(const string& name) const; - const MethodDescriptor* FindMethodByName(const string& name) const; - - // Finds an extension of the given type by number. The extendee must be - // a member of this DescriptorPool or one of its underlays. - const FieldDescriptor* FindExtensionByNumber(const Descriptor* extendee, - int number) const; - - // Finds extensions of extendee. The extensions will be appended to - // out in an undefined order. Only extensions defined directly in - // this DescriptorPool or one of its underlays are guaranteed to be - // found: extensions defined in the fallback database might not be found - // depending on the database implementation. - void FindAllExtensions(const Descriptor* extendee, - std::vector* out) const; - - // Building descriptors -------------------------------------------- - - // When converting a FileDescriptorProto to a FileDescriptor, various - // errors might be detected in the input. The caller may handle these - // programmatically by implementing an ErrorCollector. - class LIBPROTOBUF_EXPORT ErrorCollector { - public: - inline ErrorCollector() {} - virtual ~ErrorCollector(); - - // These constants specify what exact part of the construct is broken. - // This is useful e.g. for mapping the error back to an exact location - // in a .proto file. - enum ErrorLocation { - NAME, // the symbol name, or the package name for files - NUMBER, // field or extension range number - TYPE, // field type - EXTENDEE, // field extendee - DEFAULT_VALUE, // field default value - INPUT_TYPE, // method input type - OUTPUT_TYPE, // method output type - OPTION_NAME, // name in assignment - OPTION_VALUE, // value in option assignment - OTHER // some other problem - }; - - // Reports an error in the FileDescriptorProto. Use this function if the - // problem occurred should interrupt building the FileDescriptorProto. - virtual void AddError( - const string& filename, // File name in which the error occurred. - const string& element_name, // Full name of the erroneous element. - const Message* descriptor, // Descriptor of the erroneous element. - ErrorLocation location, // One of the location constants, above. - const string& message // Human-readable error message. - ) = 0; - - // Reports a warning in the FileDescriptorProto. Use this function if the - // problem occurred should NOT interrupt building the FileDescriptorProto. - virtual void AddWarning( - const string& /*filename*/, // File name in which the error occurred. - const string& /*element_name*/, // Full name of the erroneous element. - const Message* /*descriptor*/, // Descriptor of the erroneous element. - ErrorLocation /*location*/, // One of the location constants, above. - const string& /*message*/ // Human-readable error message. - ) {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); - }; - - // Convert the FileDescriptorProto to real descriptors and place them in - // this DescriptorPool. All dependencies of the file must already be in - // the pool. Returns the resulting FileDescriptor, or NULL if there were - // problems with the input (e.g. the message was invalid, or dependencies - // were missing). Details about the errors are written to GOOGLE_LOG(ERROR). - const FileDescriptor* BuildFile(const FileDescriptorProto& proto); - - // Same as BuildFile() except errors are sent to the given ErrorCollector. - const FileDescriptor* BuildFileCollectingErrors( - const FileDescriptorProto& proto, - ErrorCollector* error_collector); - - // By default, it is an error if a FileDescriptorProto contains references - // to types or other files that are not found in the DescriptorPool (or its - // backing DescriptorDatabase, if any). If you call - // AllowUnknownDependencies(), however, then unknown types and files - // will be replaced by placeholder descriptors (which can be identified by - // the is_placeholder() method). This can allow you to - // perform some useful operations with a .proto file even if you do not - // have access to other .proto files on which it depends. However, some - // heuristics must be used to fill in the gaps in information, and these - // can lead to descriptors which are inaccurate. For example, the - // DescriptorPool may be forced to guess whether an unknown type is a message - // or an enum, as well as what package it resides in. Furthermore, - // placeholder types will not be discoverable via FindMessageTypeByName() - // and similar methods, which could confuse some descriptor-based algorithms. - // Generally, the results of this option should be handled with extreme care. - void AllowUnknownDependencies() { allow_unknown_ = true; } - - // By default, weak imports are allowed to be missing, in which case we will - // use a placeholder for the dependency and convert the field to be an Empty - // message field. If you call EnforceWeakDependencies(true), however, the - // DescriptorPool will report a import not found error. - void EnforceWeakDependencies(bool enforce) { enforce_weak_ = enforce; } - - // Internal stuff -------------------------------------------------- - // These methods MUST NOT be called from outside the proto2 library. - // These methods may contain hidden pitfalls and may be removed in a - // future library version. - - // Create a DescriptorPool which is overlaid on top of some other pool. - // If you search for a descriptor in the overlay and it is not found, the - // underlay will be searched as a backup. If the underlay has its own - // underlay, that will be searched next, and so on. This also means that - // files built in the overlay will be cross-linked with the underlay's - // descriptors if necessary. The underlay remains property of the caller; - // it must remain valid for the lifetime of the newly-constructed pool. - // - // Example: Say you want to parse a .proto file at runtime in order to use - // its type with a DynamicMessage. Say this .proto file has dependencies, - // but you know that all the dependencies will be things that are already - // compiled into the binary. For ease of use, you'd like to load the types - // right out of generated_pool() rather than have to parse redundant copies - // of all these .protos and runtime. But, you don't want to add the parsed - // types directly into generated_pool(): this is not allowed, and would be - // bad design anyway. So, instead, you could use generated_pool() as an - // underlay for a new DescriptorPool in which you add only the new file. - // - // WARNING: Use of underlays can lead to many subtle gotchas. Instead, - // try to formulate what you want to do in terms of DescriptorDatabases. - explicit DescriptorPool(const DescriptorPool* underlay); - - // Called by generated classes at init time to add their descriptors to - // generated_pool. Do NOT call this in your own code! filename must be a - // permanent string (e.g. a string literal). - static void InternalAddGeneratedFile( - const void* encoded_file_descriptor, int size); - - - // For internal use only: Gets a non-const pointer to the generated pool. - // This is called at static-initialization time only, so thread-safety is - // not a concern. If both an underlay and a fallback database are present, - // the underlay takes precedence. - static DescriptorPool* internal_generated_pool(); - - // For internal use only: Changes the behavior of BuildFile() such that it - // allows the file to make reference to message types declared in other files - // which it did not officially declare as dependencies. - void InternalDontEnforceDependencies(); - - // For internal use only. - void internal_set_underlay(const DescriptorPool* underlay) { - underlay_ = underlay; - } - - // For internal (unit test) use only: Returns true if a FileDescriptor has - // been constructed for the given file, false otherwise. Useful for testing - // lazy descriptor initialization behavior. - bool InternalIsFileLoaded(const string& filename) const; - - - // Add a file to unused_import_track_files_. DescriptorBuilder will log - // warnings for those files if there is any unused import. - void AddUnusedImportTrackFile(const string& file_name); - void ClearUnusedImportTrackFiles(); - - private: - friend class Descriptor; - friend class FieldDescriptor; - friend class EnumDescriptor; - friend class ServiceDescriptor; - friend class FileDescriptor; - friend class DescriptorBuilder; - friend class FileDescriptorTables; - - // Return true if the given name is a sub-symbol of any non-package - // descriptor that already exists in the descriptor pool. (The full - // definition of such types is already known.) - bool IsSubSymbolOfBuiltType(const string& name) const; - - // Tries to find something in the fallback database and link in the - // corresponding proto file. Returns true if successful, in which case - // the caller should search for the thing again. These are declared - // const because they are called by (semantically) const methods. - bool TryFindFileInFallbackDatabase(const string& name) const; - bool TryFindSymbolInFallbackDatabase(const string& name) const; - bool TryFindExtensionInFallbackDatabase(const Descriptor* containing_type, - int field_number) const; - - // Like BuildFile() but called internally when the file has been loaded from - // fallback_database_. Declared const because it is called by (semantically) - // const methods. - const FileDescriptor* BuildFileFromDatabase( - const FileDescriptorProto& proto) const; - - // If fallback_database_ is NULL, this is NULL. Otherwise, this is a mutex - // which must be locked while accessing tables_. - Mutex* mutex_; - - // See constructor. - DescriptorDatabase* fallback_database_; - ErrorCollector* default_error_collector_; - const DescriptorPool* underlay_; - - // This class contains a lot of hash maps with complicated types that - // we'd like to keep out of the header. - class Tables; - google::protobuf::scoped_ptr tables_; - - bool enforce_dependencies_; - bool allow_unknown_; - bool enforce_weak_; - std::set unused_import_track_files_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); -}; - -// inline methods ==================================================== - -// These macros makes this repetitive code more readable. -#define PROTOBUF_DEFINE_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD() const { return FIELD##_; } - -// Strings fields are stored as pointers but returned as const references. -#define PROTOBUF_DEFINE_STRING_ACCESSOR(CLASS, FIELD) \ - inline const string& CLASS::FIELD() const { return *FIELD##_; } - -// Arrays take an index parameter, obviously. -#define PROTOBUF_DEFINE_ARRAY_ACCESSOR(CLASS, FIELD, TYPE) \ - inline TYPE CLASS::FIELD(int index) const { return FIELD##s_ + index; } - -#define PROTOBUF_DEFINE_OPTIONS_ACCESSOR(CLASS, TYPE) \ - inline const TYPE& CLASS::options() const { return *options_; } - -PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(Descriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, containing_type, const Descriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, field_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, oneof_decl_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, nested_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, enum_type_count, int) - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, field, const FieldDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, oneof_decl, const OneofDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, nested_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, enum_type, const EnumDescriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_range_count, int) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, extension_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension_range, - const Descriptor::ExtensionRange*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, extension, - const FieldDescriptor*) - -PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_range_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(Descriptor, reserved_range, - const Descriptor::ReservedRange*) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, reserved_name_count, int) - -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(Descriptor, MessageOptions) -PROTOBUF_DEFINE_ACCESSOR(Descriptor, is_placeholder, bool) - -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, full_name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, json_name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, lowercase_name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, camelcase_name) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, is_extension, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, type, FieldDescriptor::Type) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, label, FieldDescriptor::Label) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, containing_oneof, - const OneofDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, index_in_oneof, int) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, extension_scope, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, enum_type, const EnumDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FieldDescriptor, FieldOptions) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_default_value, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, has_json_name, bool) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int32 , int32 ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_int64 , int64 ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint32, uint32) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_uint64, uint64) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_float , float ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_double, double) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_bool , bool ) -PROTOBUF_DEFINE_ACCESSOR(FieldDescriptor, default_value_enum, - const EnumValueDescriptor*) -PROTOBUF_DEFINE_STRING_ACCESSOR(FieldDescriptor, default_value_string) - -PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(OneofDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(OneofDescriptor, field_count, int) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(OneofDescriptor, OneofOptions) - -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, containing_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, value_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(EnumDescriptor, value, - const EnumValueDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumDescriptor, EnumOptions) -PROTOBUF_DEFINE_ACCESSOR(EnumDescriptor, is_placeholder, bool) - -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(EnumValueDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, number, int) -PROTOBUF_DEFINE_ACCESSOR(EnumValueDescriptor, type, const EnumDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(EnumValueDescriptor, EnumValueOptions) - -PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(ServiceDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, file, const FileDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(ServiceDescriptor, method_count, int) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(ServiceDescriptor, method, - const MethodDescriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(ServiceDescriptor, ServiceOptions) - -PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(MethodDescriptor, full_name) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, service, const ServiceDescriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, input_type, const Descriptor*) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, output_type, const Descriptor*) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(MethodDescriptor, MethodOptions) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, client_streaming, bool) -PROTOBUF_DEFINE_ACCESSOR(MethodDescriptor, server_streaming, bool) - -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, name) -PROTOBUF_DEFINE_STRING_ACCESSOR(FileDescriptor, package) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, pool, const DescriptorPool*) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, public_dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, weak_dependency_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, message_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, enum_type_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, service_count, int) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, extension_count, int) -PROTOBUF_DEFINE_OPTIONS_ACCESSOR(FileDescriptor, FileOptions) -PROTOBUF_DEFINE_ACCESSOR(FileDescriptor, is_placeholder, bool) - -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, message_type, const Descriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, enum_type, const EnumDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, service, - const ServiceDescriptor*) -PROTOBUF_DEFINE_ARRAY_ACCESSOR(FileDescriptor, extension, - const FieldDescriptor*) - -#undef PROTOBUF_DEFINE_ACCESSOR -#undef PROTOBUF_DEFINE_STRING_ACCESSOR -#undef PROTOBUF_DEFINE_ARRAY_ACCESSOR - -// A few accessors differ from the macros... - -inline bool Descriptor::IsExtensionNumber(int number) const { - return FindExtensionRangeContainingNumber(number) != NULL; -} - -inline bool Descriptor::IsReservedNumber(int number) const { - return FindReservedRangeContainingNumber(number) != NULL; -} - -inline bool Descriptor::IsReservedName(const string& name) const { - for (int i = 0; i < reserved_name_count(); i++) { - if (name == reserved_name(i)) { - return true; - } - } - return false; -} - -// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because reserved_names_ is actually -// an array of pointers rather than the usual array of objects. -inline const string& Descriptor::reserved_name(int index) const { - return *reserved_names_[index]; -} - -inline bool FieldDescriptor::is_required() const { - return label() == LABEL_REQUIRED; -} - -inline bool FieldDescriptor::is_optional() const { - return label() == LABEL_OPTIONAL; -} - -inline bool FieldDescriptor::is_repeated() const { - return label() == LABEL_REPEATED; -} - -inline bool FieldDescriptor::is_packable() const { - return is_repeated() && IsTypePackable(type()); -} - -// To save space, index() is computed by looking at the descriptor's position -// in the parent's array of children. -inline int FieldDescriptor::index() const { - if (!is_extension_) { - return static_cast(this - containing_type_->fields_); - } else if (extension_scope_ != NULL) { - return static_cast(this - extension_scope_->extensions_); - } else { - return static_cast(this - file_->extensions_); - } -} - -inline int Descriptor::index() const { - if (containing_type_ == NULL) { - return static_cast(this - file_->message_types_); - } else { - return static_cast(this - containing_type_->nested_types_); - } -} - -inline int OneofDescriptor::index() const { - return static_cast(this - containing_type_->oneof_decls_); -} - -inline int EnumDescriptor::index() const { - if (containing_type_ == NULL) { - return static_cast(this - file_->enum_types_); - } else { - return static_cast(this - containing_type_->enum_types_); - } -} - -inline int EnumValueDescriptor::index() const { - return static_cast(this - type_->values_); -} - -inline int ServiceDescriptor::index() const { - return static_cast(this - file_->services_); -} - -inline int MethodDescriptor::index() const { - return static_cast(this - service_->methods_); -} - -inline const char* FieldDescriptor::type_name() const { - return kTypeToName[type_]; -} - -inline FieldDescriptor::CppType FieldDescriptor::cpp_type() const { - return kTypeToCppTypeMap[type_]; -} - -inline const char* FieldDescriptor::cpp_type_name() const { - return kCppTypeToName[kTypeToCppTypeMap[type_]]; -} - -inline FieldDescriptor::CppType FieldDescriptor::TypeToCppType(Type type) { - return kTypeToCppTypeMap[type]; -} - -inline const char* FieldDescriptor::TypeName(Type type) { - return kTypeToName[type]; -} - -inline const char* FieldDescriptor::CppTypeName(CppType cpp_type) { - return kCppTypeToName[cpp_type]; -} - -inline bool FieldDescriptor::IsTypePackable(Type field_type) { - return (field_type != FieldDescriptor::TYPE_STRING && - field_type != FieldDescriptor::TYPE_GROUP && - field_type != FieldDescriptor::TYPE_MESSAGE && - field_type != FieldDescriptor::TYPE_BYTES); -} - -inline const FileDescriptor* FileDescriptor::dependency(int index) const { - return dependencies_[index]; -} - -inline const FileDescriptor* FileDescriptor::public_dependency( - int index) const { - return dependencies_[public_dependencies_[index]]; -} - -inline const FileDescriptor* FileDescriptor::weak_dependency( - int index) const { - return dependencies_[weak_dependencies_[index]]; -} - -inline FileDescriptor::Syntax FileDescriptor::syntax() const { - return syntax_; -} - -// Can't use PROTOBUF_DEFINE_ARRAY_ACCESSOR because fields_ is actually an array -// of pointers rather than the usual array of objects. -inline const FieldDescriptor* OneofDescriptor::field(int index) const { - return fields_[index]; -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DESCRIPTOR_H__ diff --git a/app/src/main/cpp/google/protobuf/descriptor.pb.h b/app/src/main/cpp/google/protobuf/descriptor.pb.h deleted file mode 100644 index 257dd0f..0000000 --- a/app/src/main/cpp/google/protobuf/descriptor.pb.h +++ /dev/null @@ -1,8212 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/descriptor.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - -class DescriptorProto; -class DescriptorProto_ExtensionRange; -class DescriptorProto_ReservedRange; -class EnumDescriptorProto; -class EnumOptions; -class EnumValueDescriptorProto; -class EnumValueOptions; -class FieldDescriptorProto; -class FieldOptions; -class FileDescriptorProto; -class FileDescriptorSet; -class FileOptions; -class GeneratedCodeInfo; -class GeneratedCodeInfo_Annotation; -class MessageOptions; -class MethodDescriptorProto; -class MethodOptions; -class OneofDescriptorProto; -class OneofOptions; -class ServiceDescriptorProto; -class ServiceOptions; -class SourceCodeInfo; -class SourceCodeInfo_Location; -class UninterpretedOption; -class UninterpretedOption_NamePart; - -enum FieldDescriptorProto_Type { - FieldDescriptorProto_Type_TYPE_DOUBLE = 1, - FieldDescriptorProto_Type_TYPE_FLOAT = 2, - FieldDescriptorProto_Type_TYPE_INT64 = 3, - FieldDescriptorProto_Type_TYPE_UINT64 = 4, - FieldDescriptorProto_Type_TYPE_INT32 = 5, - FieldDescriptorProto_Type_TYPE_FIXED64 = 6, - FieldDescriptorProto_Type_TYPE_FIXED32 = 7, - FieldDescriptorProto_Type_TYPE_BOOL = 8, - FieldDescriptorProto_Type_TYPE_STRING = 9, - FieldDescriptorProto_Type_TYPE_GROUP = 10, - FieldDescriptorProto_Type_TYPE_MESSAGE = 11, - FieldDescriptorProto_Type_TYPE_BYTES = 12, - FieldDescriptorProto_Type_TYPE_UINT32 = 13, - FieldDescriptorProto_Type_TYPE_ENUM = 14, - FieldDescriptorProto_Type_TYPE_SFIXED32 = 15, - FieldDescriptorProto_Type_TYPE_SFIXED64 = 16, - FieldDescriptorProto_Type_TYPE_SINT32 = 17, - FieldDescriptorProto_Type_TYPE_SINT64 = 18 -}; -LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Type_IsValid(int value); -const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MIN = FieldDescriptorProto_Type_TYPE_DOUBLE; -const FieldDescriptorProto_Type FieldDescriptorProto_Type_Type_MAX = FieldDescriptorProto_Type_TYPE_SINT64; -const int FieldDescriptorProto_Type_Type_ARRAYSIZE = FieldDescriptorProto_Type_Type_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Type_descriptor(); -inline const ::std::string& FieldDescriptorProto_Type_Name(FieldDescriptorProto_Type value) { - return ::google::protobuf::internal::NameOfEnum( - FieldDescriptorProto_Type_descriptor(), value); -} -inline bool FieldDescriptorProto_Type_Parse( - const ::std::string& name, FieldDescriptorProto_Type* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldDescriptorProto_Type_descriptor(), name, value); -} -enum FieldDescriptorProto_Label { - FieldDescriptorProto_Label_LABEL_OPTIONAL = 1, - FieldDescriptorProto_Label_LABEL_REQUIRED = 2, - FieldDescriptorProto_Label_LABEL_REPEATED = 3 -}; -LIBPROTOBUF_EXPORT bool FieldDescriptorProto_Label_IsValid(int value); -const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MIN = FieldDescriptorProto_Label_LABEL_OPTIONAL; -const FieldDescriptorProto_Label FieldDescriptorProto_Label_Label_MAX = FieldDescriptorProto_Label_LABEL_REPEATED; -const int FieldDescriptorProto_Label_Label_ARRAYSIZE = FieldDescriptorProto_Label_Label_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldDescriptorProto_Label_descriptor(); -inline const ::std::string& FieldDescriptorProto_Label_Name(FieldDescriptorProto_Label value) { - return ::google::protobuf::internal::NameOfEnum( - FieldDescriptorProto_Label_descriptor(), value); -} -inline bool FieldDescriptorProto_Label_Parse( - const ::std::string& name, FieldDescriptorProto_Label* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldDescriptorProto_Label_descriptor(), name, value); -} -enum FileOptions_OptimizeMode { - FileOptions_OptimizeMode_SPEED = 1, - FileOptions_OptimizeMode_CODE_SIZE = 2, - FileOptions_OptimizeMode_LITE_RUNTIME = 3 -}; -LIBPROTOBUF_EXPORT bool FileOptions_OptimizeMode_IsValid(int value); -const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MIN = FileOptions_OptimizeMode_SPEED; -const FileOptions_OptimizeMode FileOptions_OptimizeMode_OptimizeMode_MAX = FileOptions_OptimizeMode_LITE_RUNTIME; -const int FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE = FileOptions_OptimizeMode_OptimizeMode_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FileOptions_OptimizeMode_descriptor(); -inline const ::std::string& FileOptions_OptimizeMode_Name(FileOptions_OptimizeMode value) { - return ::google::protobuf::internal::NameOfEnum( - FileOptions_OptimizeMode_descriptor(), value); -} -inline bool FileOptions_OptimizeMode_Parse( - const ::std::string& name, FileOptions_OptimizeMode* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FileOptions_OptimizeMode_descriptor(), name, value); -} -enum FieldOptions_CType { - FieldOptions_CType_STRING = 0, - FieldOptions_CType_CORD = 1, - FieldOptions_CType_STRING_PIECE = 2 -}; -LIBPROTOBUF_EXPORT bool FieldOptions_CType_IsValid(int value); -const FieldOptions_CType FieldOptions_CType_CType_MIN = FieldOptions_CType_STRING; -const FieldOptions_CType FieldOptions_CType_CType_MAX = FieldOptions_CType_STRING_PIECE; -const int FieldOptions_CType_CType_ARRAYSIZE = FieldOptions_CType_CType_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldOptions_CType_descriptor(); -inline const ::std::string& FieldOptions_CType_Name(FieldOptions_CType value) { - return ::google::protobuf::internal::NameOfEnum( - FieldOptions_CType_descriptor(), value); -} -inline bool FieldOptions_CType_Parse( - const ::std::string& name, FieldOptions_CType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldOptions_CType_descriptor(), name, value); -} -enum FieldOptions_JSType { - FieldOptions_JSType_JS_NORMAL = 0, - FieldOptions_JSType_JS_STRING = 1, - FieldOptions_JSType_JS_NUMBER = 2 -}; -LIBPROTOBUF_EXPORT bool FieldOptions_JSType_IsValid(int value); -const FieldOptions_JSType FieldOptions_JSType_JSType_MIN = FieldOptions_JSType_JS_NORMAL; -const FieldOptions_JSType FieldOptions_JSType_JSType_MAX = FieldOptions_JSType_JS_NUMBER; -const int FieldOptions_JSType_JSType_ARRAYSIZE = FieldOptions_JSType_JSType_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* FieldOptions_JSType_descriptor(); -inline const ::std::string& FieldOptions_JSType_Name(FieldOptions_JSType value) { - return ::google::protobuf::internal::NameOfEnum( - FieldOptions_JSType_descriptor(), value); -} -inline bool FieldOptions_JSType_Parse( - const ::std::string& name, FieldOptions_JSType* value) { - return ::google::protobuf::internal::ParseNamedEnum( - FieldOptions_JSType_descriptor(), name, value); -} -// =================================================================== - -class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorSet) */ { - public: - FileDescriptorSet(); - virtual ~FileDescriptorSet(); - - FileDescriptorSet(const FileDescriptorSet& from); - - inline FileDescriptorSet& operator=(const FileDescriptorSet& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileDescriptorSet& default_instance(); - - static const FileDescriptorSet* internal_default_instance(); - - void Swap(FileDescriptorSet* other); - - // implements Message ---------------------------------------------- - - inline FileDescriptorSet* New() const { return New(NULL); } - - FileDescriptorSet* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileDescriptorSet& from); - void MergeFrom(const FileDescriptorSet& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FileDescriptorSet* other); - void UnsafeMergeFrom(const FileDescriptorSet& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.FileDescriptorProto file = 1; - int file_size() const; - void clear_file(); - static const int kFileFieldNumber = 1; - const ::google::protobuf::FileDescriptorProto& file(int index) const; - ::google::protobuf::FileDescriptorProto* mutable_file(int index); - ::google::protobuf::FileDescriptorProto* add_file(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* - mutable_file(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& - file() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorSet) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto > file_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FileDescriptorSet_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileDescriptorProto) */ { - public: - FileDescriptorProto(); - virtual ~FileDescriptorProto(); - - FileDescriptorProto(const FileDescriptorProto& from); - - inline FileDescriptorProto& operator=(const FileDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileDescriptorProto& default_instance(); - - static const FileDescriptorProto* internal_default_instance(); - - void Swap(FileDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline FileDescriptorProto* New() const { return New(NULL); } - - FileDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileDescriptorProto& from); - void MergeFrom(const FileDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FileDescriptorProto* other); - void UnsafeMergeFrom(const FileDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string package = 2; - bool has_package() const; - void clear_package(); - static const int kPackageFieldNumber = 2; - const ::std::string& package() const; - void set_package(const ::std::string& value); - void set_package(const char* value); - void set_package(const char* value, size_t size); - ::std::string* mutable_package(); - ::std::string* release_package(); - void set_allocated_package(::std::string* package); - - // repeated string dependency = 3; - int dependency_size() const; - void clear_dependency(); - static const int kDependencyFieldNumber = 3; - const ::std::string& dependency(int index) const; - ::std::string* mutable_dependency(int index); - void set_dependency(int index, const ::std::string& value); - void set_dependency(int index, const char* value); - void set_dependency(int index, const char* value, size_t size); - ::std::string* add_dependency(); - void add_dependency(const ::std::string& value); - void add_dependency(const char* value); - void add_dependency(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& dependency() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_dependency(); - - // repeated int32 public_dependency = 10; - int public_dependency_size() const; - void clear_public_dependency(); - static const int kPublicDependencyFieldNumber = 10; - ::google::protobuf::int32 public_dependency(int index) const; - void set_public_dependency(int index, ::google::protobuf::int32 value); - void add_public_dependency(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - public_dependency() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_public_dependency(); - - // repeated int32 weak_dependency = 11; - int weak_dependency_size() const; - void clear_weak_dependency(); - static const int kWeakDependencyFieldNumber = 11; - ::google::protobuf::int32 weak_dependency(int index) const; - void set_weak_dependency(int index, ::google::protobuf::int32 value); - void add_weak_dependency(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - weak_dependency() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_weak_dependency(); - - // repeated .google.protobuf.DescriptorProto message_type = 4; - int message_type_size() const; - void clear_message_type(); - static const int kMessageTypeFieldNumber = 4; - const ::google::protobuf::DescriptorProto& message_type(int index) const; - ::google::protobuf::DescriptorProto* mutable_message_type(int index); - ::google::protobuf::DescriptorProto* add_message_type(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* - mutable_message_type(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& - message_type() const; - - // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; - int enum_type_size() const; - void clear_enum_type(); - static const int kEnumTypeFieldNumber = 5; - const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; - ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); - ::google::protobuf::EnumDescriptorProto* add_enum_type(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* - mutable_enum_type(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& - enum_type() const; - - // repeated .google.protobuf.ServiceDescriptorProto service = 6; - int service_size() const; - void clear_service(); - static const int kServiceFieldNumber = 6; - const ::google::protobuf::ServiceDescriptorProto& service(int index) const; - ::google::protobuf::ServiceDescriptorProto* mutable_service(int index); - ::google::protobuf::ServiceDescriptorProto* add_service(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* - mutable_service(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& - service() const; - - // repeated .google.protobuf.FieldDescriptorProto extension = 7; - int extension_size() const; - void clear_extension(); - static const int kExtensionFieldNumber = 7; - const ::google::protobuf::FieldDescriptorProto& extension(int index) const; - ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); - ::google::protobuf::FieldDescriptorProto* add_extension(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_extension(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - extension() const; - - // optional .google.protobuf.FileOptions options = 8; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 8; - const ::google::protobuf::FileOptions& options() const; - ::google::protobuf::FileOptions* mutable_options(); - ::google::protobuf::FileOptions* release_options(); - void set_allocated_options(::google::protobuf::FileOptions* options); - - // optional .google.protobuf.SourceCodeInfo source_code_info = 9; - bool has_source_code_info() const; - void clear_source_code_info(); - static const int kSourceCodeInfoFieldNumber = 9; - const ::google::protobuf::SourceCodeInfo& source_code_info() const; - ::google::protobuf::SourceCodeInfo* mutable_source_code_info(); - ::google::protobuf::SourceCodeInfo* release_source_code_info(); - void set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info); - - // optional string syntax = 12; - bool has_syntax() const; - void clear_syntax(); - static const int kSyntaxFieldNumber = 12; - const ::std::string& syntax() const; - void set_syntax(const ::std::string& value); - void set_syntax(const char* value); - void set_syntax(const char* value, size_t size); - ::std::string* mutable_syntax(); - ::std::string* release_syntax(); - void set_allocated_syntax(::std::string* syntax); - - // @@protoc_insertion_point(class_scope:google.protobuf.FileDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_package(); - inline void clear_has_package(); - inline void set_has_options(); - inline void clear_has_options(); - inline void set_has_source_code_info(); - inline void clear_has_source_code_info(); - inline void set_has_syntax(); - inline void clear_has_syntax(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> dependency_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > public_dependency_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > weak_dependency_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > message_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto > service_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr package_; - ::google::protobuf::internal::ArenaStringPtr syntax_; - ::google::protobuf::FileOptions* options_; - ::google::protobuf::SourceCodeInfo* source_code_info_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FileDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ExtensionRange) */ { - public: - DescriptorProto_ExtensionRange(); - virtual ~DescriptorProto_ExtensionRange(); - - DescriptorProto_ExtensionRange(const DescriptorProto_ExtensionRange& from); - - inline DescriptorProto_ExtensionRange& operator=(const DescriptorProto_ExtensionRange& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DescriptorProto_ExtensionRange& default_instance(); - - static const DescriptorProto_ExtensionRange* internal_default_instance(); - - void Swap(DescriptorProto_ExtensionRange* other); - - // implements Message ---------------------------------------------- - - inline DescriptorProto_ExtensionRange* New() const { return New(NULL); } - - DescriptorProto_ExtensionRange* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DescriptorProto_ExtensionRange& from); - void MergeFrom(const DescriptorProto_ExtensionRange& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(DescriptorProto_ExtensionRange* other); - void UnsafeMergeFrom(const DescriptorProto_ExtensionRange& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 start = 1; - bool has_start() const; - void clear_start(); - static const int kStartFieldNumber = 1; - ::google::protobuf::int32 start() const; - void set_start(::google::protobuf::int32 value); - - // optional int32 end = 2; - bool has_end() const; - void clear_end(); - static const int kEndFieldNumber = 2; - ::google::protobuf::int32 end() const; - void set_end(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ExtensionRange) - private: - inline void set_has_start(); - inline void clear_has_start(); - inline void set_has_end(); - inline void clear_has_end(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::int32 start_; - ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed DescriptorProto_ExtensionRange_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto.ReservedRange) */ { - public: - DescriptorProto_ReservedRange(); - virtual ~DescriptorProto_ReservedRange(); - - DescriptorProto_ReservedRange(const DescriptorProto_ReservedRange& from); - - inline DescriptorProto_ReservedRange& operator=(const DescriptorProto_ReservedRange& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DescriptorProto_ReservedRange& default_instance(); - - static const DescriptorProto_ReservedRange* internal_default_instance(); - - void Swap(DescriptorProto_ReservedRange* other); - - // implements Message ---------------------------------------------- - - inline DescriptorProto_ReservedRange* New() const { return New(NULL); } - - DescriptorProto_ReservedRange* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DescriptorProto_ReservedRange& from); - void MergeFrom(const DescriptorProto_ReservedRange& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(DescriptorProto_ReservedRange* other); - void UnsafeMergeFrom(const DescriptorProto_ReservedRange& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int32 start = 1; - bool has_start() const; - void clear_start(); - static const int kStartFieldNumber = 1; - ::google::protobuf::int32 start() const; - void set_start(::google::protobuf::int32 value); - - // optional int32 end = 2; - bool has_end() const; - void clear_end(); - static const int kEndFieldNumber = 2; - ::google::protobuf::int32 end() const; - void set_end(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto.ReservedRange) - private: - inline void set_has_start(); - inline void clear_has_start(); - inline void set_has_end(); - inline void clear_has_end(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::int32 start_; - ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed DescriptorProto_ReservedRange_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.DescriptorProto) */ { - public: - DescriptorProto(); - virtual ~DescriptorProto(); - - DescriptorProto(const DescriptorProto& from); - - inline DescriptorProto& operator=(const DescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const DescriptorProto& default_instance(); - - static const DescriptorProto* internal_default_instance(); - - void Swap(DescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline DescriptorProto* New() const { return New(NULL); } - - DescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const DescriptorProto& from); - void MergeFrom(const DescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(DescriptorProto* other); - void UnsafeMergeFrom(const DescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef DescriptorProto_ExtensionRange ExtensionRange; - typedef DescriptorProto_ReservedRange ReservedRange; - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .google.protobuf.FieldDescriptorProto field = 2; - int field_size() const; - void clear_field(); - static const int kFieldFieldNumber = 2; - const ::google::protobuf::FieldDescriptorProto& field(int index) const; - ::google::protobuf::FieldDescriptorProto* mutable_field(int index); - ::google::protobuf::FieldDescriptorProto* add_field(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_field(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - field() const; - - // repeated .google.protobuf.FieldDescriptorProto extension = 6; - int extension_size() const; - void clear_extension(); - static const int kExtensionFieldNumber = 6; - const ::google::protobuf::FieldDescriptorProto& extension(int index) const; - ::google::protobuf::FieldDescriptorProto* mutable_extension(int index); - ::google::protobuf::FieldDescriptorProto* add_extension(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* - mutable_extension(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& - extension() const; - - // repeated .google.protobuf.DescriptorProto nested_type = 3; - int nested_type_size() const; - void clear_nested_type(); - static const int kNestedTypeFieldNumber = 3; - const ::google::protobuf::DescriptorProto& nested_type(int index) const; - ::google::protobuf::DescriptorProto* mutable_nested_type(int index); - ::google::protobuf::DescriptorProto* add_nested_type(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* - mutable_nested_type(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& - nested_type() const; - - // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; - int enum_type_size() const; - void clear_enum_type(); - static const int kEnumTypeFieldNumber = 4; - const ::google::protobuf::EnumDescriptorProto& enum_type(int index) const; - ::google::protobuf::EnumDescriptorProto* mutable_enum_type(int index); - ::google::protobuf::EnumDescriptorProto* add_enum_type(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* - mutable_enum_type(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& - enum_type() const; - - // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; - int extension_range_size() const; - void clear_extension_range(); - static const int kExtensionRangeFieldNumber = 5; - const ::google::protobuf::DescriptorProto_ExtensionRange& extension_range(int index) const; - ::google::protobuf::DescriptorProto_ExtensionRange* mutable_extension_range(int index); - ::google::protobuf::DescriptorProto_ExtensionRange* add_extension_range(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* - mutable_extension_range(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& - extension_range() const; - - // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; - int oneof_decl_size() const; - void clear_oneof_decl(); - static const int kOneofDeclFieldNumber = 8; - const ::google::protobuf::OneofDescriptorProto& oneof_decl(int index) const; - ::google::protobuf::OneofDescriptorProto* mutable_oneof_decl(int index); - ::google::protobuf::OneofDescriptorProto* add_oneof_decl(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto >* - mutable_oneof_decl(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto >& - oneof_decl() const; - - // optional .google.protobuf.MessageOptions options = 7; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 7; - const ::google::protobuf::MessageOptions& options() const; - ::google::protobuf::MessageOptions* mutable_options(); - ::google::protobuf::MessageOptions* release_options(); - void set_allocated_options(::google::protobuf::MessageOptions* options); - - // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; - int reserved_range_size() const; - void clear_reserved_range(); - static const int kReservedRangeFieldNumber = 9; - const ::google::protobuf::DescriptorProto_ReservedRange& reserved_range(int index) const; - ::google::protobuf::DescriptorProto_ReservedRange* mutable_reserved_range(int index); - ::google::protobuf::DescriptorProto_ReservedRange* add_reserved_range(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange >* - mutable_reserved_range(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange >& - reserved_range() const; - - // repeated string reserved_name = 10; - int reserved_name_size() const; - void clear_reserved_name(); - static const int kReservedNameFieldNumber = 10; - const ::std::string& reserved_name(int index) const; - ::std::string* mutable_reserved_name(int index); - void set_reserved_name(int index, const ::std::string& value); - void set_reserved_name(int index, const char* value); - void set_reserved_name(int index, const char* value, size_t size); - ::std::string* add_reserved_name(); - void add_reserved_name(const ::std::string& value); - void add_reserved_name(const char* value); - void add_reserved_name(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& reserved_name() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_reserved_name(); - - // @@protoc_insertion_point(class_scope:google.protobuf.DescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > field_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto > extension_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto > nested_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto > enum_type_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange > extension_range_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto > oneof_decl_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange > reserved_range_; - ::google::protobuf::RepeatedPtrField< ::std::string> reserved_name_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::MessageOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed DescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { - public: - FieldDescriptorProto(); - virtual ~FieldDescriptorProto(); - - FieldDescriptorProto(const FieldDescriptorProto& from); - - inline FieldDescriptorProto& operator=(const FieldDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FieldDescriptorProto& default_instance(); - - static const FieldDescriptorProto* internal_default_instance(); - - void Swap(FieldDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline FieldDescriptorProto* New() const { return New(NULL); } - - FieldDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FieldDescriptorProto& from); - void MergeFrom(const FieldDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FieldDescriptorProto* other); - void UnsafeMergeFrom(const FieldDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FieldDescriptorProto_Type Type; - static const Type TYPE_DOUBLE = - FieldDescriptorProto_Type_TYPE_DOUBLE; - static const Type TYPE_FLOAT = - FieldDescriptorProto_Type_TYPE_FLOAT; - static const Type TYPE_INT64 = - FieldDescriptorProto_Type_TYPE_INT64; - static const Type TYPE_UINT64 = - FieldDescriptorProto_Type_TYPE_UINT64; - static const Type TYPE_INT32 = - FieldDescriptorProto_Type_TYPE_INT32; - static const Type TYPE_FIXED64 = - FieldDescriptorProto_Type_TYPE_FIXED64; - static const Type TYPE_FIXED32 = - FieldDescriptorProto_Type_TYPE_FIXED32; - static const Type TYPE_BOOL = - FieldDescriptorProto_Type_TYPE_BOOL; - static const Type TYPE_STRING = - FieldDescriptorProto_Type_TYPE_STRING; - static const Type TYPE_GROUP = - FieldDescriptorProto_Type_TYPE_GROUP; - static const Type TYPE_MESSAGE = - FieldDescriptorProto_Type_TYPE_MESSAGE; - static const Type TYPE_BYTES = - FieldDescriptorProto_Type_TYPE_BYTES; - static const Type TYPE_UINT32 = - FieldDescriptorProto_Type_TYPE_UINT32; - static const Type TYPE_ENUM = - FieldDescriptorProto_Type_TYPE_ENUM; - static const Type TYPE_SFIXED32 = - FieldDescriptorProto_Type_TYPE_SFIXED32; - static const Type TYPE_SFIXED64 = - FieldDescriptorProto_Type_TYPE_SFIXED64; - static const Type TYPE_SINT32 = - FieldDescriptorProto_Type_TYPE_SINT32; - static const Type TYPE_SINT64 = - FieldDescriptorProto_Type_TYPE_SINT64; - static inline bool Type_IsValid(int value) { - return FieldDescriptorProto_Type_IsValid(value); - } - static const Type Type_MIN = - FieldDescriptorProto_Type_Type_MIN; - static const Type Type_MAX = - FieldDescriptorProto_Type_Type_MAX; - static const int Type_ARRAYSIZE = - FieldDescriptorProto_Type_Type_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Type_descriptor() { - return FieldDescriptorProto_Type_descriptor(); - } - static inline const ::std::string& Type_Name(Type value) { - return FieldDescriptorProto_Type_Name(value); - } - static inline bool Type_Parse(const ::std::string& name, - Type* value) { - return FieldDescriptorProto_Type_Parse(name, value); - } - - typedef FieldDescriptorProto_Label Label; - static const Label LABEL_OPTIONAL = - FieldDescriptorProto_Label_LABEL_OPTIONAL; - static const Label LABEL_REQUIRED = - FieldDescriptorProto_Label_LABEL_REQUIRED; - static const Label LABEL_REPEATED = - FieldDescriptorProto_Label_LABEL_REPEATED; - static inline bool Label_IsValid(int value) { - return FieldDescriptorProto_Label_IsValid(value); - } - static const Label Label_MIN = - FieldDescriptorProto_Label_Label_MIN; - static const Label Label_MAX = - FieldDescriptorProto_Label_Label_MAX; - static const int Label_ARRAYSIZE = - FieldDescriptorProto_Label_Label_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Label_descriptor() { - return FieldDescriptorProto_Label_descriptor(); - } - static inline const ::std::string& Label_Name(Label value) { - return FieldDescriptorProto_Label_Name(value); - } - static inline bool Label_Parse(const ::std::string& name, - Label* value) { - return FieldDescriptorProto_Label_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional int32 number = 3; - bool has_number() const; - void clear_number(); - static const int kNumberFieldNumber = 3; - ::google::protobuf::int32 number() const; - void set_number(::google::protobuf::int32 value); - - // optional .google.protobuf.FieldDescriptorProto.Label label = 4; - bool has_label() const; - void clear_label(); - static const int kLabelFieldNumber = 4; - ::google::protobuf::FieldDescriptorProto_Label label() const; - void set_label(::google::protobuf::FieldDescriptorProto_Label value); - - // optional .google.protobuf.FieldDescriptorProto.Type type = 5; - bool has_type() const; - void clear_type(); - static const int kTypeFieldNumber = 5; - ::google::protobuf::FieldDescriptorProto_Type type() const; - void set_type(::google::protobuf::FieldDescriptorProto_Type value); - - // optional string type_name = 6; - bool has_type_name() const; - void clear_type_name(); - static const int kTypeNameFieldNumber = 6; - const ::std::string& type_name() const; - void set_type_name(const ::std::string& value); - void set_type_name(const char* value); - void set_type_name(const char* value, size_t size); - ::std::string* mutable_type_name(); - ::std::string* release_type_name(); - void set_allocated_type_name(::std::string* type_name); - - // optional string extendee = 2; - bool has_extendee() const; - void clear_extendee(); - static const int kExtendeeFieldNumber = 2; - const ::std::string& extendee() const; - void set_extendee(const ::std::string& value); - void set_extendee(const char* value); - void set_extendee(const char* value, size_t size); - ::std::string* mutable_extendee(); - ::std::string* release_extendee(); - void set_allocated_extendee(::std::string* extendee); - - // optional string default_value = 7; - bool has_default_value() const; - void clear_default_value(); - static const int kDefaultValueFieldNumber = 7; - const ::std::string& default_value() const; - void set_default_value(const ::std::string& value); - void set_default_value(const char* value); - void set_default_value(const char* value, size_t size); - ::std::string* mutable_default_value(); - ::std::string* release_default_value(); - void set_allocated_default_value(::std::string* default_value); - - // optional int32 oneof_index = 9; - bool has_oneof_index() const; - void clear_oneof_index(); - static const int kOneofIndexFieldNumber = 9; - ::google::protobuf::int32 oneof_index() const; - void set_oneof_index(::google::protobuf::int32 value); - - // optional string json_name = 10; - bool has_json_name() const; - void clear_json_name(); - static const int kJsonNameFieldNumber = 10; - const ::std::string& json_name() const; - void set_json_name(const ::std::string& value); - void set_json_name(const char* value); - void set_json_name(const char* value, size_t size); - ::std::string* mutable_json_name(); - ::std::string* release_json_name(); - void set_allocated_json_name(::std::string* json_name); - - // optional .google.protobuf.FieldOptions options = 8; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 8; - const ::google::protobuf::FieldOptions& options() const; - ::google::protobuf::FieldOptions* mutable_options(); - ::google::protobuf::FieldOptions* release_options(); - void set_allocated_options(::google::protobuf::FieldOptions* options); - - // @@protoc_insertion_point(class_scope:google.protobuf.FieldDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_number(); - inline void clear_has_number(); - inline void set_has_label(); - inline void clear_has_label(); - inline void set_has_type(); - inline void clear_has_type(); - inline void set_has_type_name(); - inline void clear_has_type_name(); - inline void set_has_extendee(); - inline void clear_has_extendee(); - inline void set_has_default_value(); - inline void clear_has_default_value(); - inline void set_has_oneof_index(); - inline void clear_has_oneof_index(); - inline void set_has_json_name(); - inline void clear_has_json_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_name_; - ::google::protobuf::internal::ArenaStringPtr extendee_; - ::google::protobuf::internal::ArenaStringPtr default_value_; - ::google::protobuf::internal::ArenaStringPtr json_name_; - ::google::protobuf::FieldOptions* options_; - ::google::protobuf::int32 number_; - ::google::protobuf::int32 oneof_index_; - int label_; - int type_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FieldDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofDescriptorProto) */ { - public: - OneofDescriptorProto(); - virtual ~OneofDescriptorProto(); - - OneofDescriptorProto(const OneofDescriptorProto& from); - - inline OneofDescriptorProto& operator=(const OneofDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OneofDescriptorProto& default_instance(); - - static const OneofDescriptorProto* internal_default_instance(); - - void Swap(OneofDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline OneofDescriptorProto* New() const { return New(NULL); } - - OneofDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OneofDescriptorProto& from); - void MergeFrom(const OneofDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(OneofDescriptorProto* other); - void UnsafeMergeFrom(const OneofDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional .google.protobuf.OneofOptions options = 2; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 2; - const ::google::protobuf::OneofOptions& options() const; - ::google::protobuf::OneofOptions* mutable_options(); - ::google::protobuf::OneofOptions* release_options(); - void set_allocated_options(::google::protobuf::OneofOptions* options); - - // @@protoc_insertion_point(class_scope:google.protobuf.OneofDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::OneofOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed OneofDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumDescriptorProto) */ { - public: - EnumDescriptorProto(); - virtual ~EnumDescriptorProto(); - - EnumDescriptorProto(const EnumDescriptorProto& from); - - inline EnumDescriptorProto& operator=(const EnumDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumDescriptorProto& default_instance(); - - static const EnumDescriptorProto* internal_default_instance(); - - void Swap(EnumDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline EnumDescriptorProto* New() const { return New(NULL); } - - EnumDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumDescriptorProto& from); - void MergeFrom(const EnumDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(EnumDescriptorProto* other); - void UnsafeMergeFrom(const EnumDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .google.protobuf.EnumValueDescriptorProto value = 2; - int value_size() const; - void clear_value(); - static const int kValueFieldNumber = 2; - const ::google::protobuf::EnumValueDescriptorProto& value(int index) const; - ::google::protobuf::EnumValueDescriptorProto* mutable_value(int index); - ::google::protobuf::EnumValueDescriptorProto* add_value(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* - mutable_value(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& - value() const; - - // optional .google.protobuf.EnumOptions options = 3; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::EnumOptions& options() const; - ::google::protobuf::EnumOptions* mutable_options(); - ::google::protobuf::EnumOptions* release_options(); - void set_allocated_options(::google::protobuf::EnumOptions* options); - - // @@protoc_insertion_point(class_scope:google.protobuf.EnumDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto > value_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::EnumOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed EnumDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueDescriptorProto) */ { - public: - EnumValueDescriptorProto(); - virtual ~EnumValueDescriptorProto(); - - EnumValueDescriptorProto(const EnumValueDescriptorProto& from); - - inline EnumValueDescriptorProto& operator=(const EnumValueDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumValueDescriptorProto& default_instance(); - - static const EnumValueDescriptorProto* internal_default_instance(); - - void Swap(EnumValueDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline EnumValueDescriptorProto* New() const { return New(NULL); } - - EnumValueDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumValueDescriptorProto& from); - void MergeFrom(const EnumValueDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(EnumValueDescriptorProto* other); - void UnsafeMergeFrom(const EnumValueDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional int32 number = 2; - bool has_number() const; - void clear_number(); - static const int kNumberFieldNumber = 2; - ::google::protobuf::int32 number() const; - void set_number(::google::protobuf::int32 value); - - // optional .google.protobuf.EnumValueOptions options = 3; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::EnumValueOptions& options() const; - ::google::protobuf::EnumValueOptions* mutable_options(); - ::google::protobuf::EnumValueOptions* release_options(); - void set_allocated_options(::google::protobuf::EnumValueOptions* options); - - // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_number(); - inline void clear_has_number(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::EnumValueOptions* options_; - ::google::protobuf::int32 number_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed EnumValueDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceDescriptorProto) */ { - public: - ServiceDescriptorProto(); - virtual ~ServiceDescriptorProto(); - - ServiceDescriptorProto(const ServiceDescriptorProto& from); - - inline ServiceDescriptorProto& operator=(const ServiceDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ServiceDescriptorProto& default_instance(); - - static const ServiceDescriptorProto* internal_default_instance(); - - void Swap(ServiceDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline ServiceDescriptorProto* New() const { return New(NULL); } - - ServiceDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ServiceDescriptorProto& from); - void MergeFrom(const ServiceDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ServiceDescriptorProto* other); - void UnsafeMergeFrom(const ServiceDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // repeated .google.protobuf.MethodDescriptorProto method = 2; - int method_size() const; - void clear_method(); - static const int kMethodFieldNumber = 2; - const ::google::protobuf::MethodDescriptorProto& method(int index) const; - ::google::protobuf::MethodDescriptorProto* mutable_method(int index); - ::google::protobuf::MethodDescriptorProto* add_method(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* - mutable_method(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& - method() const; - - // optional .google.protobuf.ServiceOptions options = 3; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::ServiceOptions& options() const; - ::google::protobuf::ServiceOptions* mutable_options(); - ::google::protobuf::ServiceOptions* release_options(); - void set_allocated_options(::google::protobuf::ServiceOptions* options); - - // @@protoc_insertion_point(class_scope:google.protobuf.ServiceDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_options(); - inline void clear_has_options(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto > method_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::ServiceOptions* options_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ServiceDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodDescriptorProto) */ { - public: - MethodDescriptorProto(); - virtual ~MethodDescriptorProto(); - - MethodDescriptorProto(const MethodDescriptorProto& from); - - inline MethodDescriptorProto& operator=(const MethodDescriptorProto& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MethodDescriptorProto& default_instance(); - - static const MethodDescriptorProto* internal_default_instance(); - - void Swap(MethodDescriptorProto* other); - - // implements Message ---------------------------------------------- - - inline MethodDescriptorProto* New() const { return New(NULL); } - - MethodDescriptorProto* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MethodDescriptorProto& from); - void MergeFrom(const MethodDescriptorProto& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(MethodDescriptorProto* other); - void UnsafeMergeFrom(const MethodDescriptorProto& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - bool has_name() const; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - - // optional string input_type = 2; - bool has_input_type() const; - void clear_input_type(); - static const int kInputTypeFieldNumber = 2; - const ::std::string& input_type() const; - void set_input_type(const ::std::string& value); - void set_input_type(const char* value); - void set_input_type(const char* value, size_t size); - ::std::string* mutable_input_type(); - ::std::string* release_input_type(); - void set_allocated_input_type(::std::string* input_type); - - // optional string output_type = 3; - bool has_output_type() const; - void clear_output_type(); - static const int kOutputTypeFieldNumber = 3; - const ::std::string& output_type() const; - void set_output_type(const ::std::string& value); - void set_output_type(const char* value); - void set_output_type(const char* value, size_t size); - ::std::string* mutable_output_type(); - ::std::string* release_output_type(); - void set_allocated_output_type(::std::string* output_type); - - // optional .google.protobuf.MethodOptions options = 4; - bool has_options() const; - void clear_options(); - static const int kOptionsFieldNumber = 4; - const ::google::protobuf::MethodOptions& options() const; - ::google::protobuf::MethodOptions* mutable_options(); - ::google::protobuf::MethodOptions* release_options(); - void set_allocated_options(::google::protobuf::MethodOptions* options); - - // optional bool client_streaming = 5 [default = false]; - bool has_client_streaming() const; - void clear_client_streaming(); - static const int kClientStreamingFieldNumber = 5; - bool client_streaming() const; - void set_client_streaming(bool value); - - // optional bool server_streaming = 6 [default = false]; - bool has_server_streaming() const; - void clear_server_streaming(); - static const int kServerStreamingFieldNumber = 6; - bool server_streaming() const; - void set_server_streaming(bool value); - - // @@protoc_insertion_point(class_scope:google.protobuf.MethodDescriptorProto) - private: - inline void set_has_name(); - inline void clear_has_name(); - inline void set_has_input_type(); - inline void clear_has_input_type(); - inline void set_has_output_type(); - inline void clear_has_output_type(); - inline void set_has_options(); - inline void clear_has_options(); - inline void set_has_client_streaming(); - inline void clear_has_client_streaming(); - inline void set_has_server_streaming(); - inline void clear_has_server_streaming(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr input_type_; - ::google::protobuf::internal::ArenaStringPtr output_type_; - ::google::protobuf::MethodOptions* options_; - bool client_streaming_; - bool server_streaming_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed MethodDescriptorProto_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FileOptions) */ { - public: - FileOptions(); - virtual ~FileOptions(); - - FileOptions(const FileOptions& from); - - inline FileOptions& operator=(const FileOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FileOptions& default_instance(); - - static const FileOptions* internal_default_instance(); - - void Swap(FileOptions* other); - - // implements Message ---------------------------------------------- - - inline FileOptions* New() const { return New(NULL); } - - FileOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FileOptions& from); - void MergeFrom(const FileOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FileOptions* other); - void UnsafeMergeFrom(const FileOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FileOptions_OptimizeMode OptimizeMode; - static const OptimizeMode SPEED = - FileOptions_OptimizeMode_SPEED; - static const OptimizeMode CODE_SIZE = - FileOptions_OptimizeMode_CODE_SIZE; - static const OptimizeMode LITE_RUNTIME = - FileOptions_OptimizeMode_LITE_RUNTIME; - static inline bool OptimizeMode_IsValid(int value) { - return FileOptions_OptimizeMode_IsValid(value); - } - static const OptimizeMode OptimizeMode_MIN = - FileOptions_OptimizeMode_OptimizeMode_MIN; - static const OptimizeMode OptimizeMode_MAX = - FileOptions_OptimizeMode_OptimizeMode_MAX; - static const int OptimizeMode_ARRAYSIZE = - FileOptions_OptimizeMode_OptimizeMode_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - OptimizeMode_descriptor() { - return FileOptions_OptimizeMode_descriptor(); - } - static inline const ::std::string& OptimizeMode_Name(OptimizeMode value) { - return FileOptions_OptimizeMode_Name(value); - } - static inline bool OptimizeMode_Parse(const ::std::string& name, - OptimizeMode* value) { - return FileOptions_OptimizeMode_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional string java_package = 1; - bool has_java_package() const; - void clear_java_package(); - static const int kJavaPackageFieldNumber = 1; - const ::std::string& java_package() const; - void set_java_package(const ::std::string& value); - void set_java_package(const char* value); - void set_java_package(const char* value, size_t size); - ::std::string* mutable_java_package(); - ::std::string* release_java_package(); - void set_allocated_java_package(::std::string* java_package); - - // optional string java_outer_classname = 8; - bool has_java_outer_classname() const; - void clear_java_outer_classname(); - static const int kJavaOuterClassnameFieldNumber = 8; - const ::std::string& java_outer_classname() const; - void set_java_outer_classname(const ::std::string& value); - void set_java_outer_classname(const char* value); - void set_java_outer_classname(const char* value, size_t size); - ::std::string* mutable_java_outer_classname(); - ::std::string* release_java_outer_classname(); - void set_allocated_java_outer_classname(::std::string* java_outer_classname); - - // optional bool java_multiple_files = 10 [default = false]; - bool has_java_multiple_files() const; - void clear_java_multiple_files(); - static const int kJavaMultipleFilesFieldNumber = 10; - bool java_multiple_files() const; - void set_java_multiple_files(bool value); - - // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; - GOOGLE_PROTOBUF_DEPRECATED_ATTR bool has_java_generate_equals_and_hash() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void clear_java_generate_equals_and_hash(); - GOOGLE_PROTOBUF_DEPRECATED_ATTR static const int kJavaGenerateEqualsAndHashFieldNumber = 20; - GOOGLE_PROTOBUF_DEPRECATED_ATTR bool java_generate_equals_and_hash() const; - GOOGLE_PROTOBUF_DEPRECATED_ATTR void set_java_generate_equals_and_hash(bool value); - - // optional bool java_string_check_utf8 = 27 [default = false]; - bool has_java_string_check_utf8() const; - void clear_java_string_check_utf8(); - static const int kJavaStringCheckUtf8FieldNumber = 27; - bool java_string_check_utf8() const; - void set_java_string_check_utf8(bool value); - - // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; - bool has_optimize_for() const; - void clear_optimize_for(); - static const int kOptimizeForFieldNumber = 9; - ::google::protobuf::FileOptions_OptimizeMode optimize_for() const; - void set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value); - - // optional string go_package = 11; - bool has_go_package() const; - void clear_go_package(); - static const int kGoPackageFieldNumber = 11; - const ::std::string& go_package() const; - void set_go_package(const ::std::string& value); - void set_go_package(const char* value); - void set_go_package(const char* value, size_t size); - ::std::string* mutable_go_package(); - ::std::string* release_go_package(); - void set_allocated_go_package(::std::string* go_package); - - // optional bool cc_generic_services = 16 [default = false]; - bool has_cc_generic_services() const; - void clear_cc_generic_services(); - static const int kCcGenericServicesFieldNumber = 16; - bool cc_generic_services() const; - void set_cc_generic_services(bool value); - - // optional bool java_generic_services = 17 [default = false]; - bool has_java_generic_services() const; - void clear_java_generic_services(); - static const int kJavaGenericServicesFieldNumber = 17; - bool java_generic_services() const; - void set_java_generic_services(bool value); - - // optional bool py_generic_services = 18 [default = false]; - bool has_py_generic_services() const; - void clear_py_generic_services(); - static const int kPyGenericServicesFieldNumber = 18; - bool py_generic_services() const; - void set_py_generic_services(bool value); - - // optional bool deprecated = 23 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 23; - bool deprecated() const; - void set_deprecated(bool value); - - // optional bool cc_enable_arenas = 31 [default = false]; - bool has_cc_enable_arenas() const; - void clear_cc_enable_arenas(); - static const int kCcEnableArenasFieldNumber = 31; - bool cc_enable_arenas() const; - void set_cc_enable_arenas(bool value); - - // optional string objc_class_prefix = 36; - bool has_objc_class_prefix() const; - void clear_objc_class_prefix(); - static const int kObjcClassPrefixFieldNumber = 36; - const ::std::string& objc_class_prefix() const; - void set_objc_class_prefix(const ::std::string& value); - void set_objc_class_prefix(const char* value); - void set_objc_class_prefix(const char* value, size_t size); - ::std::string* mutable_objc_class_prefix(); - ::std::string* release_objc_class_prefix(); - void set_allocated_objc_class_prefix(::std::string* objc_class_prefix); - - // optional string csharp_namespace = 37; - bool has_csharp_namespace() const; - void clear_csharp_namespace(); - static const int kCsharpNamespaceFieldNumber = 37; - const ::std::string& csharp_namespace() const; - void set_csharp_namespace(const ::std::string& value); - void set_csharp_namespace(const char* value); - void set_csharp_namespace(const char* value, size_t size); - ::std::string* mutable_csharp_namespace(); - ::std::string* release_csharp_namespace(); - void set_allocated_csharp_namespace(::std::string* csharp_namespace); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FileOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.FileOptions) - private: - inline void set_has_java_package(); - inline void clear_has_java_package(); - inline void set_has_java_outer_classname(); - inline void clear_has_java_outer_classname(); - inline void set_has_java_multiple_files(); - inline void clear_has_java_multiple_files(); - inline void set_has_java_generate_equals_and_hash(); - inline void clear_has_java_generate_equals_and_hash(); - inline void set_has_java_string_check_utf8(); - inline void clear_has_java_string_check_utf8(); - inline void set_has_optimize_for(); - inline void clear_has_optimize_for(); - inline void set_has_go_package(); - inline void clear_has_go_package(); - inline void set_has_cc_generic_services(); - inline void clear_has_cc_generic_services(); - inline void set_has_java_generic_services(); - inline void clear_has_java_generic_services(); - inline void set_has_py_generic_services(); - inline void clear_has_py_generic_services(); - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - inline void set_has_cc_enable_arenas(); - inline void clear_has_cc_enable_arenas(); - inline void set_has_objc_class_prefix(); - inline void clear_has_objc_class_prefix(); - inline void set_has_csharp_namespace(); - inline void clear_has_csharp_namespace(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - ::google::protobuf::internal::ArenaStringPtr java_package_; - ::google::protobuf::internal::ArenaStringPtr java_outer_classname_; - ::google::protobuf::internal::ArenaStringPtr go_package_; - ::google::protobuf::internal::ArenaStringPtr objc_class_prefix_; - ::google::protobuf::internal::ArenaStringPtr csharp_namespace_; - bool java_multiple_files_; - bool java_generate_equals_and_hash_; - bool java_string_check_utf8_; - bool cc_generic_services_; - bool java_generic_services_; - bool py_generic_services_; - bool deprecated_; - bool cc_enable_arenas_; - int optimize_for_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FileOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MessageOptions) */ { - public: - MessageOptions(); - virtual ~MessageOptions(); - - MessageOptions(const MessageOptions& from); - - inline MessageOptions& operator=(const MessageOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MessageOptions& default_instance(); - - static const MessageOptions* internal_default_instance(); - - void Swap(MessageOptions* other); - - // implements Message ---------------------------------------------- - - inline MessageOptions* New() const { return New(NULL); } - - MessageOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MessageOptions& from); - void MergeFrom(const MessageOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(MessageOptions* other); - void UnsafeMergeFrom(const MessageOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool message_set_wire_format = 1 [default = false]; - bool has_message_set_wire_format() const; - void clear_message_set_wire_format(); - static const int kMessageSetWireFormatFieldNumber = 1; - bool message_set_wire_format() const; - void set_message_set_wire_format(bool value); - - // optional bool no_standard_descriptor_accessor = 2 [default = false]; - bool has_no_standard_descriptor_accessor() const; - void clear_no_standard_descriptor_accessor(); - static const int kNoStandardDescriptorAccessorFieldNumber = 2; - bool no_standard_descriptor_accessor() const; - void set_no_standard_descriptor_accessor(bool value); - - // optional bool deprecated = 3 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; - bool deprecated() const; - void set_deprecated(bool value); - - // optional bool map_entry = 7; - bool has_map_entry() const; - void clear_map_entry(); - static const int kMapEntryFieldNumber = 7; - bool map_entry() const; - void set_map_entry(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MessageOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.MessageOptions) - private: - inline void set_has_message_set_wire_format(); - inline void clear_has_message_set_wire_format(); - inline void set_has_no_standard_descriptor_accessor(); - inline void clear_has_no_standard_descriptor_accessor(); - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - inline void set_has_map_entry(); - inline void clear_has_map_entry(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool message_set_wire_format_; - bool no_standard_descriptor_accessor_; - bool deprecated_; - bool map_entry_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed MessageOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldOptions) */ { - public: - FieldOptions(); - virtual ~FieldOptions(); - - FieldOptions(const FieldOptions& from); - - inline FieldOptions& operator=(const FieldOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FieldOptions& default_instance(); - - static const FieldOptions* internal_default_instance(); - - void Swap(FieldOptions* other); - - // implements Message ---------------------------------------------- - - inline FieldOptions* New() const { return New(NULL); } - - FieldOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FieldOptions& from); - void MergeFrom(const FieldOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FieldOptions* other); - void UnsafeMergeFrom(const FieldOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef FieldOptions_CType CType; - static const CType STRING = - FieldOptions_CType_STRING; - static const CType CORD = - FieldOptions_CType_CORD; - static const CType STRING_PIECE = - FieldOptions_CType_STRING_PIECE; - static inline bool CType_IsValid(int value) { - return FieldOptions_CType_IsValid(value); - } - static const CType CType_MIN = - FieldOptions_CType_CType_MIN; - static const CType CType_MAX = - FieldOptions_CType_CType_MAX; - static const int CType_ARRAYSIZE = - FieldOptions_CType_CType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - CType_descriptor() { - return FieldOptions_CType_descriptor(); - } - static inline const ::std::string& CType_Name(CType value) { - return FieldOptions_CType_Name(value); - } - static inline bool CType_Parse(const ::std::string& name, - CType* value) { - return FieldOptions_CType_Parse(name, value); - } - - typedef FieldOptions_JSType JSType; - static const JSType JS_NORMAL = - FieldOptions_JSType_JS_NORMAL; - static const JSType JS_STRING = - FieldOptions_JSType_JS_STRING; - static const JSType JS_NUMBER = - FieldOptions_JSType_JS_NUMBER; - static inline bool JSType_IsValid(int value) { - return FieldOptions_JSType_IsValid(value); - } - static const JSType JSType_MIN = - FieldOptions_JSType_JSType_MIN; - static const JSType JSType_MAX = - FieldOptions_JSType_JSType_MAX; - static const int JSType_ARRAYSIZE = - FieldOptions_JSType_JSType_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - JSType_descriptor() { - return FieldOptions_JSType_descriptor(); - } - static inline const ::std::string& JSType_Name(JSType value) { - return FieldOptions_JSType_Name(value); - } - static inline bool JSType_Parse(const ::std::string& name, - JSType* value) { - return FieldOptions_JSType_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; - bool has_ctype() const; - void clear_ctype(); - static const int kCtypeFieldNumber = 1; - ::google::protobuf::FieldOptions_CType ctype() const; - void set_ctype(::google::protobuf::FieldOptions_CType value); - - // optional bool packed = 2; - bool has_packed() const; - void clear_packed(); - static const int kPackedFieldNumber = 2; - bool packed() const; - void set_packed(bool value); - - // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; - bool has_jstype() const; - void clear_jstype(); - static const int kJstypeFieldNumber = 6; - ::google::protobuf::FieldOptions_JSType jstype() const; - void set_jstype(::google::protobuf::FieldOptions_JSType value); - - // optional bool lazy = 5 [default = false]; - bool has_lazy() const; - void clear_lazy(); - static const int kLazyFieldNumber = 5; - bool lazy() const; - void set_lazy(bool value); - - // optional bool deprecated = 3 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; - bool deprecated() const; - void set_deprecated(bool value); - - // optional bool weak = 10 [default = false]; - bool has_weak() const; - void clear_weak(); - static const int kWeakFieldNumber = 10; - bool weak() const; - void set_weak(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(FieldOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.FieldOptions) - private: - inline void set_has_ctype(); - inline void clear_has_ctype(); - inline void set_has_packed(); - inline void clear_has_packed(); - inline void set_has_jstype(); - inline void clear_has_jstype(); - inline void set_has_lazy(); - inline void clear_has_lazy(); - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - inline void set_has_weak(); - inline void clear_has_weak(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - int ctype_; - int jstype_; - bool packed_; - bool lazy_; - bool deprecated_; - bool weak_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FieldOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.OneofOptions) */ { - public: - OneofOptions(); - virtual ~OneofOptions(); - - OneofOptions(const OneofOptions& from); - - inline OneofOptions& operator=(const OneofOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const OneofOptions& default_instance(); - - static const OneofOptions* internal_default_instance(); - - void Swap(OneofOptions* other); - - // implements Message ---------------------------------------------- - - inline OneofOptions* New() const { return New(NULL); } - - OneofOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const OneofOptions& from); - void MergeFrom(const OneofOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(OneofOptions* other); - void UnsafeMergeFrom(const OneofOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(OneofOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.OneofOptions) - private: - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed OneofOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumOptions) */ { - public: - EnumOptions(); - virtual ~EnumOptions(); - - EnumOptions(const EnumOptions& from); - - inline EnumOptions& operator=(const EnumOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumOptions& default_instance(); - - static const EnumOptions* internal_default_instance(); - - void Swap(EnumOptions* other); - - // implements Message ---------------------------------------------- - - inline EnumOptions* New() const { return New(NULL); } - - EnumOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumOptions& from); - void MergeFrom(const EnumOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(EnumOptions* other); - void UnsafeMergeFrom(const EnumOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool allow_alias = 2; - bool has_allow_alias() const; - void clear_allow_alias(); - static const int kAllowAliasFieldNumber = 2; - bool allow_alias() const; - void set_allow_alias(bool value); - - // optional bool deprecated = 3 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 3; - bool deprecated() const; - void set_deprecated(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.EnumOptions) - private: - inline void set_has_allow_alias(); - inline void clear_has_allow_alias(); - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool allow_alias_; - bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed EnumOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValueOptions) */ { - public: - EnumValueOptions(); - virtual ~EnumValueOptions(); - - EnumValueOptions(const EnumValueOptions& from); - - inline EnumValueOptions& operator=(const EnumValueOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumValueOptions& default_instance(); - - static const EnumValueOptions* internal_default_instance(); - - void Swap(EnumValueOptions* other); - - // implements Message ---------------------------------------------- - - inline EnumValueOptions* New() const { return New(NULL); } - - EnumValueOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumValueOptions& from); - void MergeFrom(const EnumValueOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(EnumValueOptions* other); - void UnsafeMergeFrom(const EnumValueOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool deprecated = 1 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 1; - bool deprecated() const; - void set_deprecated(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(EnumValueOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.EnumValueOptions) - private: - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed EnumValueOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ServiceOptions) */ { - public: - ServiceOptions(); - virtual ~ServiceOptions(); - - ServiceOptions(const ServiceOptions& from); - - inline ServiceOptions& operator=(const ServiceOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const ServiceOptions& default_instance(); - - static const ServiceOptions* internal_default_instance(); - - void Swap(ServiceOptions* other); - - // implements Message ---------------------------------------------- - - inline ServiceOptions* New() const { return New(NULL); } - - ServiceOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ServiceOptions& from); - void MergeFrom(const ServiceOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ServiceOptions* other); - void UnsafeMergeFrom(const ServiceOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool deprecated = 33 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 33; - bool deprecated() const; - void set_deprecated(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ServiceOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.ServiceOptions) - private: - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ServiceOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.MethodOptions) */ { - public: - MethodOptions(); - virtual ~MethodOptions(); - - MethodOptions(const MethodOptions& from); - - inline MethodOptions& operator=(const MethodOptions& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const MethodOptions& default_instance(); - - static const MethodOptions* internal_default_instance(); - - void Swap(MethodOptions* other); - - // implements Message ---------------------------------------------- - - inline MethodOptions* New() const { return New(NULL); } - - MethodOptions* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const MethodOptions& from); - void MergeFrom(const MethodOptions& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(MethodOptions* other); - void UnsafeMergeFrom(const MethodOptions& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional bool deprecated = 33 [default = false]; - bool has_deprecated() const; - void clear_deprecated(); - static const int kDeprecatedFieldNumber = 33; - bool deprecated() const; - void set_deprecated(bool value); - - // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; - int uninterpreted_option_size() const; - void clear_uninterpreted_option(); - static const int kUninterpretedOptionFieldNumber = 999; - const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; - ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); - ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* - mutable_uninterpreted_option(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& - uninterpreted_option() const; - - GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(MethodOptions) - // @@protoc_insertion_point(class_scope:google.protobuf.MethodOptions) - private: - inline void set_has_deprecated(); - inline void clear_has_deprecated(); - - ::google::protobuf::internal::ExtensionSet _extensions_; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; - bool deprecated_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed MethodOptions_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption.NamePart) */ { - public: - UninterpretedOption_NamePart(); - virtual ~UninterpretedOption_NamePart(); - - UninterpretedOption_NamePart(const UninterpretedOption_NamePart& from); - - inline UninterpretedOption_NamePart& operator=(const UninterpretedOption_NamePart& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const UninterpretedOption_NamePart& default_instance(); - - static const UninterpretedOption_NamePart* internal_default_instance(); - - void Swap(UninterpretedOption_NamePart* other); - - // implements Message ---------------------------------------------- - - inline UninterpretedOption_NamePart* New() const { return New(NULL); } - - UninterpretedOption_NamePart* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const UninterpretedOption_NamePart& from); - void MergeFrom(const UninterpretedOption_NamePart& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(UninterpretedOption_NamePart* other); - void UnsafeMergeFrom(const UninterpretedOption_NamePart& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // required string name_part = 1; - bool has_name_part() const; - void clear_name_part(); - static const int kNamePartFieldNumber = 1; - const ::std::string& name_part() const; - void set_name_part(const ::std::string& value); - void set_name_part(const char* value); - void set_name_part(const char* value, size_t size); - ::std::string* mutable_name_part(); - ::std::string* release_name_part(); - void set_allocated_name_part(::std::string* name_part); - - // required bool is_extension = 2; - bool has_is_extension() const; - void clear_is_extension(); - static const int kIsExtensionFieldNumber = 2; - bool is_extension() const; - void set_is_extension(bool value); - - // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption.NamePart) - private: - inline void set_has_name_part(); - inline void clear_has_name_part(); - inline void set_has_is_extension(); - inline void clear_has_is_extension(); - - // helper for ByteSizeLong() - size_t RequiredFieldsByteSizeFallback() const; - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::internal::ArenaStringPtr name_part_; - bool is_extension_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed UninterpretedOption_NamePart_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.UninterpretedOption) */ { - public: - UninterpretedOption(); - virtual ~UninterpretedOption(); - - UninterpretedOption(const UninterpretedOption& from); - - inline UninterpretedOption& operator=(const UninterpretedOption& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const UninterpretedOption& default_instance(); - - static const UninterpretedOption* internal_default_instance(); - - void Swap(UninterpretedOption* other); - - // implements Message ---------------------------------------------- - - inline UninterpretedOption* New() const { return New(NULL); } - - UninterpretedOption* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const UninterpretedOption& from); - void MergeFrom(const UninterpretedOption& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(UninterpretedOption* other); - void UnsafeMergeFrom(const UninterpretedOption& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef UninterpretedOption_NamePart NamePart; - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; - int name_size() const; - void clear_name(); - static const int kNameFieldNumber = 2; - const ::google::protobuf::UninterpretedOption_NamePart& name(int index) const; - ::google::protobuf::UninterpretedOption_NamePart* mutable_name(int index); - ::google::protobuf::UninterpretedOption_NamePart* add_name(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* - mutable_name(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& - name() const; - - // optional string identifier_value = 3; - bool has_identifier_value() const; - void clear_identifier_value(); - static const int kIdentifierValueFieldNumber = 3; - const ::std::string& identifier_value() const; - void set_identifier_value(const ::std::string& value); - void set_identifier_value(const char* value); - void set_identifier_value(const char* value, size_t size); - ::std::string* mutable_identifier_value(); - ::std::string* release_identifier_value(); - void set_allocated_identifier_value(::std::string* identifier_value); - - // optional uint64 positive_int_value = 4; - bool has_positive_int_value() const; - void clear_positive_int_value(); - static const int kPositiveIntValueFieldNumber = 4; - ::google::protobuf::uint64 positive_int_value() const; - void set_positive_int_value(::google::protobuf::uint64 value); - - // optional int64 negative_int_value = 5; - bool has_negative_int_value() const; - void clear_negative_int_value(); - static const int kNegativeIntValueFieldNumber = 5; - ::google::protobuf::int64 negative_int_value() const; - void set_negative_int_value(::google::protobuf::int64 value); - - // optional double double_value = 6; - bool has_double_value() const; - void clear_double_value(); - static const int kDoubleValueFieldNumber = 6; - double double_value() const; - void set_double_value(double value); - - // optional bytes string_value = 7; - bool has_string_value() const; - void clear_string_value(); - static const int kStringValueFieldNumber = 7; - const ::std::string& string_value() const; - void set_string_value(const ::std::string& value); - void set_string_value(const char* value); - void set_string_value(const void* value, size_t size); - ::std::string* mutable_string_value(); - ::std::string* release_string_value(); - void set_allocated_string_value(::std::string* string_value); - - // optional string aggregate_value = 8; - bool has_aggregate_value() const; - void clear_aggregate_value(); - static const int kAggregateValueFieldNumber = 8; - const ::std::string& aggregate_value() const; - void set_aggregate_value(const ::std::string& value); - void set_aggregate_value(const char* value); - void set_aggregate_value(const char* value, size_t size); - ::std::string* mutable_aggregate_value(); - ::std::string* release_aggregate_value(); - void set_allocated_aggregate_value(::std::string* aggregate_value); - - // @@protoc_insertion_point(class_scope:google.protobuf.UninterpretedOption) - private: - inline void set_has_identifier_value(); - inline void clear_has_identifier_value(); - inline void set_has_positive_int_value(); - inline void clear_has_positive_int_value(); - inline void set_has_negative_int_value(); - inline void clear_has_negative_int_value(); - inline void set_has_double_value(); - inline void clear_has_double_value(); - inline void set_has_string_value(); - inline void clear_has_string_value(); - inline void set_has_aggregate_value(); - inline void clear_has_aggregate_value(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart > name_; - ::google::protobuf::internal::ArenaStringPtr identifier_value_; - ::google::protobuf::internal::ArenaStringPtr string_value_; - ::google::protobuf::internal::ArenaStringPtr aggregate_value_; - ::google::protobuf::uint64 positive_int_value_; - ::google::protobuf::int64 negative_int_value_; - double double_value_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed UninterpretedOption_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo.Location) */ { - public: - SourceCodeInfo_Location(); - virtual ~SourceCodeInfo_Location(); - - SourceCodeInfo_Location(const SourceCodeInfo_Location& from); - - inline SourceCodeInfo_Location& operator=(const SourceCodeInfo_Location& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SourceCodeInfo_Location& default_instance(); - - static const SourceCodeInfo_Location* internal_default_instance(); - - void Swap(SourceCodeInfo_Location* other); - - // implements Message ---------------------------------------------- - - inline SourceCodeInfo_Location* New() const { return New(NULL); } - - SourceCodeInfo_Location* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SourceCodeInfo_Location& from); - void MergeFrom(const SourceCodeInfo_Location& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(SourceCodeInfo_Location* other); - void UnsafeMergeFrom(const SourceCodeInfo_Location& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 path = 1 [packed = true]; - int path_size() const; - void clear_path(); - static const int kPathFieldNumber = 1; - ::google::protobuf::int32 path(int index) const; - void set_path(int index, ::google::protobuf::int32 value); - void add_path(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - path() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_path(); - - // repeated int32 span = 2 [packed = true]; - int span_size() const; - void clear_span(); - static const int kSpanFieldNumber = 2; - ::google::protobuf::int32 span(int index) const; - void set_span(int index, ::google::protobuf::int32 value); - void add_span(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - span() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_span(); - - // optional string leading_comments = 3; - bool has_leading_comments() const; - void clear_leading_comments(); - static const int kLeadingCommentsFieldNumber = 3; - const ::std::string& leading_comments() const; - void set_leading_comments(const ::std::string& value); - void set_leading_comments(const char* value); - void set_leading_comments(const char* value, size_t size); - ::std::string* mutable_leading_comments(); - ::std::string* release_leading_comments(); - void set_allocated_leading_comments(::std::string* leading_comments); - - // optional string trailing_comments = 4; - bool has_trailing_comments() const; - void clear_trailing_comments(); - static const int kTrailingCommentsFieldNumber = 4; - const ::std::string& trailing_comments() const; - void set_trailing_comments(const ::std::string& value); - void set_trailing_comments(const char* value); - void set_trailing_comments(const char* value, size_t size); - ::std::string* mutable_trailing_comments(); - ::std::string* release_trailing_comments(); - void set_allocated_trailing_comments(::std::string* trailing_comments); - - // repeated string leading_detached_comments = 6; - int leading_detached_comments_size() const; - void clear_leading_detached_comments(); - static const int kLeadingDetachedCommentsFieldNumber = 6; - const ::std::string& leading_detached_comments(int index) const; - ::std::string* mutable_leading_detached_comments(int index); - void set_leading_detached_comments(int index, const ::std::string& value); - void set_leading_detached_comments(int index, const char* value); - void set_leading_detached_comments(int index, const char* value, size_t size); - ::std::string* add_leading_detached_comments(); - void add_leading_detached_comments(const ::std::string& value); - void add_leading_detached_comments(const char* value); - void add_leading_detached_comments(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& leading_detached_comments() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_leading_detached_comments(); - - // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo.Location) - private: - inline void set_has_leading_comments(); - inline void clear_has_leading_comments(); - inline void set_has_trailing_comments(); - inline void clear_has_trailing_comments(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; - mutable int _path_cached_byte_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > span_; - mutable int _span_cached_byte_size_; - ::google::protobuf::RepeatedPtrField< ::std::string> leading_detached_comments_; - ::google::protobuf::internal::ArenaStringPtr leading_comments_; - ::google::protobuf::internal::ArenaStringPtr trailing_comments_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed SourceCodeInfo_Location_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceCodeInfo) */ { - public: - SourceCodeInfo(); - virtual ~SourceCodeInfo(); - - SourceCodeInfo(const SourceCodeInfo& from); - - inline SourceCodeInfo& operator=(const SourceCodeInfo& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SourceCodeInfo& default_instance(); - - static const SourceCodeInfo* internal_default_instance(); - - void Swap(SourceCodeInfo* other); - - // implements Message ---------------------------------------------- - - inline SourceCodeInfo* New() const { return New(NULL); } - - SourceCodeInfo* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SourceCodeInfo& from); - void MergeFrom(const SourceCodeInfo& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(SourceCodeInfo* other); - void UnsafeMergeFrom(const SourceCodeInfo& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef SourceCodeInfo_Location Location; - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.SourceCodeInfo.Location location = 1; - int location_size() const; - void clear_location(); - static const int kLocationFieldNumber = 1; - const ::google::protobuf::SourceCodeInfo_Location& location(int index) const; - ::google::protobuf::SourceCodeInfo_Location* mutable_location(int index); - ::google::protobuf::SourceCodeInfo_Location* add_location(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* - mutable_location(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& - location() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.SourceCodeInfo) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location > location_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed SourceCodeInfo_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo.Annotation) */ { - public: - GeneratedCodeInfo_Annotation(); - virtual ~GeneratedCodeInfo_Annotation(); - - GeneratedCodeInfo_Annotation(const GeneratedCodeInfo_Annotation& from); - - inline GeneratedCodeInfo_Annotation& operator=(const GeneratedCodeInfo_Annotation& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const GeneratedCodeInfo_Annotation& default_instance(); - - static const GeneratedCodeInfo_Annotation* internal_default_instance(); - - void Swap(GeneratedCodeInfo_Annotation* other); - - // implements Message ---------------------------------------------- - - inline GeneratedCodeInfo_Annotation* New() const { return New(NULL); } - - GeneratedCodeInfo_Annotation* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const GeneratedCodeInfo_Annotation& from); - void MergeFrom(const GeneratedCodeInfo_Annotation& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(GeneratedCodeInfo_Annotation* other); - void UnsafeMergeFrom(const GeneratedCodeInfo_Annotation& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated int32 path = 1 [packed = true]; - int path_size() const; - void clear_path(); - static const int kPathFieldNumber = 1; - ::google::protobuf::int32 path(int index) const; - void set_path(int index, ::google::protobuf::int32 value); - void add_path(::google::protobuf::int32 value); - const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& - path() const; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* - mutable_path(); - - // optional string source_file = 2; - bool has_source_file() const; - void clear_source_file(); - static const int kSourceFileFieldNumber = 2; - const ::std::string& source_file() const; - void set_source_file(const ::std::string& value); - void set_source_file(const char* value); - void set_source_file(const char* value, size_t size); - ::std::string* mutable_source_file(); - ::std::string* release_source_file(); - void set_allocated_source_file(::std::string* source_file); - - // optional int32 begin = 3; - bool has_begin() const; - void clear_begin(); - static const int kBeginFieldNumber = 3; - ::google::protobuf::int32 begin() const; - void set_begin(::google::protobuf::int32 value); - - // optional int32 end = 4; - bool has_end() const; - void clear_end(); - static const int kEndFieldNumber = 4; - ::google::protobuf::int32 end() const; - void set_end(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.GeneratedCodeInfo.Annotation) - private: - inline void set_has_source_file(); - inline void clear_has_source_file(); - inline void set_has_begin(); - inline void clear_has_begin(); - inline void set_has_end(); - inline void clear_has_end(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedField< ::google::protobuf::int32 > path_; - mutable int _path_cached_byte_size_; - ::google::protobuf::internal::ArenaStringPtr source_file_; - ::google::protobuf::int32 begin_; - ::google::protobuf::int32 end_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed GeneratedCodeInfo_Annotation_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.GeneratedCodeInfo) */ { - public: - GeneratedCodeInfo(); - virtual ~GeneratedCodeInfo(); - - GeneratedCodeInfo(const GeneratedCodeInfo& from); - - inline GeneratedCodeInfo& operator=(const GeneratedCodeInfo& from) { - CopyFrom(from); - return *this; - } - - inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { - return _internal_metadata_.unknown_fields(); - } - - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { - return _internal_metadata_.mutable_unknown_fields(); - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const GeneratedCodeInfo& default_instance(); - - static const GeneratedCodeInfo* internal_default_instance(); - - void Swap(GeneratedCodeInfo* other); - - // implements Message ---------------------------------------------- - - inline GeneratedCodeInfo* New() const { return New(NULL); } - - GeneratedCodeInfo* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const GeneratedCodeInfo& from); - void MergeFrom(const GeneratedCodeInfo& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(GeneratedCodeInfo* other); - void UnsafeMergeFrom(const GeneratedCodeInfo& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef GeneratedCodeInfo_Annotation Annotation; - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; - int annotation_size() const; - void clear_annotation(); - static const int kAnnotationFieldNumber = 1; - const ::google::protobuf::GeneratedCodeInfo_Annotation& annotation(int index) const; - ::google::protobuf::GeneratedCodeInfo_Annotation* mutable_annotation(int index); - ::google::protobuf::GeneratedCodeInfo_Annotation* add_annotation(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation >* - mutable_annotation(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation >& - annotation() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.GeneratedCodeInfo) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::HasBits<1> _has_bits_; - mutable int _cached_size_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation > annotation_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fdescriptor_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fdescriptor_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fdescriptor_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed GeneratedCodeInfo_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// FileDescriptorSet - -// repeated .google.protobuf.FileDescriptorProto file = 1; -inline int FileDescriptorSet::file_size() const { - return file_.size(); -} -inline void FileDescriptorSet::clear_file() { - file_.Clear(); -} -inline const ::google::protobuf::FileDescriptorProto& FileDescriptorSet::file(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorSet.file) - return file_.Get(index); -} -inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::mutable_file(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorSet.file) - return file_.Mutable(index); -} -inline ::google::protobuf::FileDescriptorProto* FileDescriptorSet::add_file() { - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorSet.file) - return file_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >* -FileDescriptorSet::mutable_file() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorSet.file) - return &file_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FileDescriptorProto >& -FileDescriptorSet::file() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorSet.file) - return file_; -} - -inline const FileDescriptorSet* FileDescriptorSet::internal_default_instance() { - return &FileDescriptorSet_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// FileDescriptorProto - -// optional string name = 1; -inline bool FileDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FileDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void FileDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FileDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& FileDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.name) -} -inline void FileDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.name) -} -inline void FileDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.name) -} -inline ::std::string* FileDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.name) -} - -// optional string package = 2; -inline bool FileDescriptorProto::has_package() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FileDescriptorProto::set_has_package() { - _has_bits_[0] |= 0x00000002u; -} -inline void FileDescriptorProto::clear_has_package() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FileDescriptorProto::clear_package() { - package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_package(); -} -inline const ::std::string& FileDescriptorProto::package() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.package) - return package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_package(const ::std::string& value) { - set_has_package(); - package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.package) -} -inline void FileDescriptorProto::set_package(const char* value) { - set_has_package(); - package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.package) -} -inline void FileDescriptorProto::set_package(const char* value, size_t size) { - set_has_package(); - package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.package) -} -inline ::std::string* FileDescriptorProto::mutable_package() { - set_has_package(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.package) - return package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileDescriptorProto::release_package() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.package) - clear_has_package(); - return package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_allocated_package(::std::string* package) { - if (package != NULL) { - set_has_package(); - } else { - clear_has_package(); - } - package_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), package); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.package) -} - -// repeated string dependency = 3; -inline int FileDescriptorProto::dependency_size() const { - return dependency_.size(); -} -inline void FileDescriptorProto::clear_dependency() { - dependency_.Clear(); -} -inline const ::std::string& FileDescriptorProto::dependency(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.dependency) - return dependency_.Get(index); -} -inline ::std::string* FileDescriptorProto::mutable_dependency(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.dependency) - return dependency_.Mutable(index); -} -inline void FileDescriptorProto::set_dependency(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.dependency) - dependency_.Mutable(index)->assign(value); -} -inline void FileDescriptorProto::set_dependency(int index, const char* value) { - dependency_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency) -} -inline void FileDescriptorProto::set_dependency(int index, const char* value, size_t size) { - dependency_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.dependency) -} -inline ::std::string* FileDescriptorProto::add_dependency() { - // @@protoc_insertion_point(field_add_mutable:google.protobuf.FileDescriptorProto.dependency) - return dependency_.Add(); -} -inline void FileDescriptorProto::add_dependency(const ::std::string& value) { - dependency_.Add()->assign(value); - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.dependency) -} -inline void FileDescriptorProto::add_dependency(const char* value) { - dependency_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency) -} -inline void FileDescriptorProto::add_dependency(const char* value, size_t size) { - dependency_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:google.protobuf.FileDescriptorProto.dependency) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -FileDescriptorProto::dependency() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.dependency) - return dependency_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -FileDescriptorProto::mutable_dependency() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.dependency) - return &dependency_; -} - -// repeated int32 public_dependency = 10; -inline int FileDescriptorProto::public_dependency_size() const { - return public_dependency_.size(); -} -inline void FileDescriptorProto::clear_public_dependency() { - public_dependency_.Clear(); -} -inline ::google::protobuf::int32 FileDescriptorProto::public_dependency(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.public_dependency) - return public_dependency_.Get(index); -} -inline void FileDescriptorProto::set_public_dependency(int index, ::google::protobuf::int32 value) { - public_dependency_.Set(index, value); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.public_dependency) -} -inline void FileDescriptorProto::add_public_dependency(::google::protobuf::int32 value) { - public_dependency_.Add(value); - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.public_dependency) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -FileDescriptorProto::public_dependency() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.public_dependency) - return public_dependency_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -FileDescriptorProto::mutable_public_dependency() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.public_dependency) - return &public_dependency_; -} - -// repeated int32 weak_dependency = 11; -inline int FileDescriptorProto::weak_dependency_size() const { - return weak_dependency_.size(); -} -inline void FileDescriptorProto::clear_weak_dependency() { - weak_dependency_.Clear(); -} -inline ::google::protobuf::int32 FileDescriptorProto::weak_dependency(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.weak_dependency) - return weak_dependency_.Get(index); -} -inline void FileDescriptorProto::set_weak_dependency(int index, ::google::protobuf::int32 value) { - weak_dependency_.Set(index, value); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.weak_dependency) -} -inline void FileDescriptorProto::add_weak_dependency(::google::protobuf::int32 value) { - weak_dependency_.Add(value); - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.weak_dependency) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -FileDescriptorProto::weak_dependency() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.weak_dependency) - return weak_dependency_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -FileDescriptorProto::mutable_weak_dependency() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.weak_dependency) - return &weak_dependency_; -} - -// repeated .google.protobuf.DescriptorProto message_type = 4; -inline int FileDescriptorProto::message_type_size() const { - return message_type_.size(); -} -inline void FileDescriptorProto::clear_message_type() { - message_type_.Clear(); -} -inline const ::google::protobuf::DescriptorProto& FileDescriptorProto::message_type(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.message_type) - return message_type_.Get(index); -} -inline ::google::protobuf::DescriptorProto* FileDescriptorProto::mutable_message_type(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.message_type) - return message_type_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto* FileDescriptorProto::add_message_type() { - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.message_type) - return message_type_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* -FileDescriptorProto::mutable_message_type() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.message_type) - return &message_type_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& -FileDescriptorProto::message_type() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.message_type) - return message_type_; -} - -// repeated .google.protobuf.EnumDescriptorProto enum_type = 5; -inline int FileDescriptorProto::enum_type_size() const { - return enum_type_.size(); -} -inline void FileDescriptorProto::clear_enum_type() { - enum_type_.Clear(); -} -inline const ::google::protobuf::EnumDescriptorProto& FileDescriptorProto::enum_type(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.enum_type) - return enum_type_.Get(index); -} -inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::mutable_enum_type(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.enum_type) - return enum_type_.Mutable(index); -} -inline ::google::protobuf::EnumDescriptorProto* FileDescriptorProto::add_enum_type() { - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.enum_type) - return enum_type_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* -FileDescriptorProto::mutable_enum_type() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.enum_type) - return &enum_type_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& -FileDescriptorProto::enum_type() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.enum_type) - return enum_type_; -} - -// repeated .google.protobuf.ServiceDescriptorProto service = 6; -inline int FileDescriptorProto::service_size() const { - return service_.size(); -} -inline void FileDescriptorProto::clear_service() { - service_.Clear(); -} -inline const ::google::protobuf::ServiceDescriptorProto& FileDescriptorProto::service(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.service) - return service_.Get(index); -} -inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::mutable_service(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.service) - return service_.Mutable(index); -} -inline ::google::protobuf::ServiceDescriptorProto* FileDescriptorProto::add_service() { - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.service) - return service_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >* -FileDescriptorProto::mutable_service() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.service) - return &service_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::ServiceDescriptorProto >& -FileDescriptorProto::service() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.service) - return service_; -} - -// repeated .google.protobuf.FieldDescriptorProto extension = 7; -inline int FileDescriptorProto::extension_size() const { - return extension_.size(); -} -inline void FileDescriptorProto::clear_extension() { - extension_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& FileDescriptorProto::extension(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.extension) - return extension_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::mutable_extension(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.extension) - return extension_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* FileDescriptorProto::add_extension() { - // @@protoc_insertion_point(field_add:google.protobuf.FileDescriptorProto.extension) - return extension_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -FileDescriptorProto::mutable_extension() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileDescriptorProto.extension) - return &extension_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -FileDescriptorProto::extension() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileDescriptorProto.extension) - return extension_; -} - -// optional .google.protobuf.FileOptions options = 8; -inline bool FileDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void FileDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000200u; -} -inline void FileDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000200u; -} -inline void FileDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FileOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FileOptions::internal_default_instance(); -} -inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::FileOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.options) - return options_; -} -inline ::google::protobuf::FileOptions* FileDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.options) - clear_has_options(); - ::google::protobuf::FileOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void FileDescriptorProto::set_allocated_options(::google::protobuf::FileOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.options) -} - -// optional .google.protobuf.SourceCodeInfo source_code_info = 9; -inline bool FileDescriptorProto::has_source_code_info() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void FileDescriptorProto::set_has_source_code_info() { - _has_bits_[0] |= 0x00000400u; -} -inline void FileDescriptorProto::clear_has_source_code_info() { - _has_bits_[0] &= ~0x00000400u; -} -inline void FileDescriptorProto::clear_source_code_info() { - if (source_code_info_ != NULL) source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); - clear_has_source_code_info(); -} -inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_ != NULL ? *source_code_info_ - : *::google::protobuf::SourceCodeInfo::internal_default_instance(); -} -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { - set_has_source_code_info(); - if (source_code_info_ == NULL) { - source_code_info_ = new ::google::protobuf::SourceCodeInfo; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_; -} -inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::release_source_code_info() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.source_code_info) - clear_has_source_code_info(); - ::google::protobuf::SourceCodeInfo* temp = source_code_info_; - source_code_info_ = NULL; - return temp; -} -inline void FileDescriptorProto::set_allocated_source_code_info(::google::protobuf::SourceCodeInfo* source_code_info) { - delete source_code_info_; - source_code_info_ = source_code_info; - if (source_code_info) { - set_has_source_code_info(); - } else { - clear_has_source_code_info(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.source_code_info) -} - -// optional string syntax = 12; -inline bool FileDescriptorProto::has_syntax() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void FileDescriptorProto::set_has_syntax() { - _has_bits_[0] |= 0x00000800u; -} -inline void FileDescriptorProto::clear_has_syntax() { - _has_bits_[0] &= ~0x00000800u; -} -inline void FileDescriptorProto::clear_syntax() { - syntax_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_syntax(); -} -inline const ::std::string& FileDescriptorProto::syntax() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.syntax) - return syntax_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_syntax(const ::std::string& value) { - set_has_syntax(); - syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileDescriptorProto.syntax) -} -inline void FileDescriptorProto::set_syntax(const char* value) { - set_has_syntax(); - syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.syntax) -} -inline void FileDescriptorProto::set_syntax(const char* value, size_t size) { - set_has_syntax(); - syntax_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileDescriptorProto.syntax) -} -inline ::std::string* FileDescriptorProto::mutable_syntax() { - set_has_syntax(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileDescriptorProto.syntax) - return syntax_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileDescriptorProto::release_syntax() { - // @@protoc_insertion_point(field_release:google.protobuf.FileDescriptorProto.syntax) - clear_has_syntax(); - return syntax_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { - if (syntax != NULL) { - set_has_syntax(); - } else { - clear_has_syntax(); - } - syntax_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), syntax); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileDescriptorProto.syntax) -} - -inline const FileDescriptorProto* FileDescriptorProto::internal_default_instance() { - return &FileDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// DescriptorProto_ExtensionRange - -// optional int32 start = 1; -inline bool DescriptorProto_ExtensionRange::has_start() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DescriptorProto_ExtensionRange::set_has_start() { - _has_bits_[0] |= 0x00000001u; -} -inline void DescriptorProto_ExtensionRange::clear_has_start() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DescriptorProto_ExtensionRange::clear_start() { - start_ = 0; - clear_has_start(); -} -inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::start() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.start) - return start_; -} -inline void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) { - set_has_start(); - start_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.start) -} - -// optional int32 end = 2; -inline bool DescriptorProto_ExtensionRange::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void DescriptorProto_ExtensionRange::set_has_end() { - _has_bits_[0] |= 0x00000002u; -} -inline void DescriptorProto_ExtensionRange::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; -} -inline void DescriptorProto_ExtensionRange::clear_end() { - end_ = 0; - clear_has_end(); -} -inline ::google::protobuf::int32 DescriptorProto_ExtensionRange::end() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.end) - return end_; -} -inline void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { - set_has_end(); - end_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end) -} - -inline const DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::internal_default_instance() { - return &DescriptorProto_ExtensionRange_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// DescriptorProto_ReservedRange - -// optional int32 start = 1; -inline bool DescriptorProto_ReservedRange::has_start() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DescriptorProto_ReservedRange::set_has_start() { - _has_bits_[0] |= 0x00000001u; -} -inline void DescriptorProto_ReservedRange::clear_has_start() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DescriptorProto_ReservedRange::clear_start() { - start_ = 0; - clear_has_start(); -} -inline ::google::protobuf::int32 DescriptorProto_ReservedRange::start() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ReservedRange.start) - return start_; -} -inline void DescriptorProto_ReservedRange::set_start(::google::protobuf::int32 value) { - set_has_start(); - start_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.start) -} - -// optional int32 end = 2; -inline bool DescriptorProto_ReservedRange::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void DescriptorProto_ReservedRange::set_has_end() { - _has_bits_[0] |= 0x00000002u; -} -inline void DescriptorProto_ReservedRange::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; -} -inline void DescriptorProto_ReservedRange::clear_end() { - end_ = 0; - clear_has_end(); -} -inline ::google::protobuf::int32 DescriptorProto_ReservedRange::end() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ReservedRange.end) - return end_; -} -inline void DescriptorProto_ReservedRange::set_end(::google::protobuf::int32 value) { - set_has_end(); - end_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ReservedRange.end) -} - -inline const DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::internal_default_instance() { - return &DescriptorProto_ReservedRange_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// DescriptorProto - -// optional string name = 1; -inline bool DescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void DescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void DescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void DescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& DescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.name) -} -inline void DescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.name) -} -inline void DescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.name) -} -inline ::std::string* DescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* DescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void DescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.name) -} - -// repeated .google.protobuf.FieldDescriptorProto field = 2; -inline int DescriptorProto::field_size() const { - return field_.size(); -} -inline void DescriptorProto::clear_field() { - field_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::field(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.field) - return field_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_field(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.field) - return field_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_field() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.field) - return field_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -DescriptorProto::mutable_field() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.field) - return &field_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -DescriptorProto::field() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.field) - return field_; -} - -// repeated .google.protobuf.FieldDescriptorProto extension = 6; -inline int DescriptorProto::extension_size() const { - return extension_.size(); -} -inline void DescriptorProto::clear_extension() { - extension_.Clear(); -} -inline const ::google::protobuf::FieldDescriptorProto& DescriptorProto::extension(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.extension) - return extension_.Get(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::mutable_extension(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.extension) - return extension_.Mutable(index); -} -inline ::google::protobuf::FieldDescriptorProto* DescriptorProto::add_extension() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.extension) - return extension_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >* -DescriptorProto::mutable_extension() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.extension) - return &extension_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::FieldDescriptorProto >& -DescriptorProto::extension() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.extension) - return extension_; -} - -// repeated .google.protobuf.DescriptorProto nested_type = 3; -inline int DescriptorProto::nested_type_size() const { - return nested_type_.size(); -} -inline void DescriptorProto::clear_nested_type() { - nested_type_.Clear(); -} -inline const ::google::protobuf::DescriptorProto& DescriptorProto::nested_type(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.nested_type) - return nested_type_.Get(index); -} -inline ::google::protobuf::DescriptorProto* DescriptorProto::mutable_nested_type(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.nested_type) - return nested_type_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto* DescriptorProto::add_nested_type() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.nested_type) - return nested_type_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >* -DescriptorProto::mutable_nested_type() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.nested_type) - return &nested_type_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto >& -DescriptorProto::nested_type() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.nested_type) - return nested_type_; -} - -// repeated .google.protobuf.EnumDescriptorProto enum_type = 4; -inline int DescriptorProto::enum_type_size() const { - return enum_type_.size(); -} -inline void DescriptorProto::clear_enum_type() { - enum_type_.Clear(); -} -inline const ::google::protobuf::EnumDescriptorProto& DescriptorProto::enum_type(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.enum_type) - return enum_type_.Get(index); -} -inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::mutable_enum_type(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.enum_type) - return enum_type_.Mutable(index); -} -inline ::google::protobuf::EnumDescriptorProto* DescriptorProto::add_enum_type() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.enum_type) - return enum_type_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >* -DescriptorProto::mutable_enum_type() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.enum_type) - return &enum_type_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumDescriptorProto >& -DescriptorProto::enum_type() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.enum_type) - return enum_type_; -} - -// repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; -inline int DescriptorProto::extension_range_size() const { - return extension_range_.size(); -} -inline void DescriptorProto::clear_extension_range() { - extension_range_.Clear(); -} -inline const ::google::protobuf::DescriptorProto_ExtensionRange& DescriptorProto::extension_range(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.extension_range) - return extension_range_.Get(index); -} -inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::mutable_extension_range(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.extension_range) - return extension_range_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto_ExtensionRange* DescriptorProto::add_extension_range() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.extension_range) - return extension_range_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >* -DescriptorProto::mutable_extension_range() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.extension_range) - return &extension_range_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ExtensionRange >& -DescriptorProto::extension_range() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.extension_range) - return extension_range_; -} - -// repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; -inline int DescriptorProto::oneof_decl_size() const { - return oneof_decl_.size(); -} -inline void DescriptorProto::clear_oneof_decl() { - oneof_decl_.Clear(); -} -inline const ::google::protobuf::OneofDescriptorProto& DescriptorProto::oneof_decl(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.oneof_decl) - return oneof_decl_.Get(index); -} -inline ::google::protobuf::OneofDescriptorProto* DescriptorProto::mutable_oneof_decl(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.oneof_decl) - return oneof_decl_.Mutable(index); -} -inline ::google::protobuf::OneofDescriptorProto* DescriptorProto::add_oneof_decl() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.oneof_decl) - return oneof_decl_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto >* -DescriptorProto::mutable_oneof_decl() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.oneof_decl) - return &oneof_decl_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::OneofDescriptorProto >& -DescriptorProto::oneof_decl() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.oneof_decl) - return oneof_decl_; -} - -// optional .google.protobuf.MessageOptions options = 7; -inline bool DescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void DescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000080u; -} -inline void DescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000080u; -} -inline void DescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MessageOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MessageOptions::internal_default_instance(); -} -inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::MessageOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.options) - return options_; -} -inline ::google::protobuf::MessageOptions* DescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.options) - clear_has_options(); - ::google::protobuf::MessageOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void DescriptorProto::set_allocated_options(::google::protobuf::MessageOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.options) -} - -// repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; -inline int DescriptorProto::reserved_range_size() const { - return reserved_range_.size(); -} -inline void DescriptorProto::clear_reserved_range() { - reserved_range_.Clear(); -} -inline const ::google::protobuf::DescriptorProto_ReservedRange& DescriptorProto::reserved_range(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.reserved_range) - return reserved_range_.Get(index); -} -inline ::google::protobuf::DescriptorProto_ReservedRange* DescriptorProto::mutable_reserved_range(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.reserved_range) - return reserved_range_.Mutable(index); -} -inline ::google::protobuf::DescriptorProto_ReservedRange* DescriptorProto::add_reserved_range() { - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_range) - return reserved_range_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange >* -DescriptorProto::mutable_reserved_range() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.reserved_range) - return &reserved_range_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::DescriptorProto_ReservedRange >& -DescriptorProto::reserved_range() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.reserved_range) - return reserved_range_; -} - -// repeated string reserved_name = 10; -inline int DescriptorProto::reserved_name_size() const { - return reserved_name_.size(); -} -inline void DescriptorProto::clear_reserved_name() { - reserved_name_.Clear(); -} -inline const ::std::string& DescriptorProto::reserved_name(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.reserved_name) - return reserved_name_.Get(index); -} -inline ::std::string* DescriptorProto::mutable_reserved_name(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.reserved_name) - return reserved_name_.Mutable(index); -} -inline void DescriptorProto::set_reserved_name(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.reserved_name) - reserved_name_.Mutable(index)->assign(value); -} -inline void DescriptorProto::set_reserved_name(int index, const char* value) { - reserved_name_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name) -} -inline void DescriptorProto::set_reserved_name(int index, const char* value, size_t size) { - reserved_name_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.DescriptorProto.reserved_name) -} -inline ::std::string* DescriptorProto::add_reserved_name() { - // @@protoc_insertion_point(field_add_mutable:google.protobuf.DescriptorProto.reserved_name) - return reserved_name_.Add(); -} -inline void DescriptorProto::add_reserved_name(const ::std::string& value) { - reserved_name_.Add()->assign(value); - // @@protoc_insertion_point(field_add:google.protobuf.DescriptorProto.reserved_name) -} -inline void DescriptorProto::add_reserved_name(const char* value) { - reserved_name_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name) -} -inline void DescriptorProto::add_reserved_name(const char* value, size_t size) { - reserved_name_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:google.protobuf.DescriptorProto.reserved_name) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -DescriptorProto::reserved_name() const { - // @@protoc_insertion_point(field_list:google.protobuf.DescriptorProto.reserved_name) - return reserved_name_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -DescriptorProto::mutable_reserved_name() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.DescriptorProto.reserved_name) - return &reserved_name_; -} - -inline const DescriptorProto* DescriptorProto::internal_default_instance() { - return &DescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// FieldDescriptorProto - -// optional string name = 1; -inline bool FieldDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FieldDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void FieldDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FieldDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& FieldDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.name) -} -inline void FieldDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.name) -} -inline void FieldDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.name) -} -inline ::std::string* FieldDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FieldDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.name) -} - -// optional int32 number = 3; -inline bool FieldDescriptorProto::has_number() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FieldDescriptorProto::set_has_number() { - _has_bits_[0] |= 0x00000002u; -} -inline void FieldDescriptorProto::clear_has_number() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FieldDescriptorProto::clear_number() { - number_ = 0; - clear_has_number(); -} -inline ::google::protobuf::int32 FieldDescriptorProto::number() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.number) - return number_; -} -inline void FieldDescriptorProto::set_number(::google::protobuf::int32 value) { - set_has_number(); - number_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.number) -} - -// optional .google.protobuf.FieldDescriptorProto.Label label = 4; -inline bool FieldDescriptorProto::has_label() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FieldDescriptorProto::set_has_label() { - _has_bits_[0] |= 0x00000004u; -} -inline void FieldDescriptorProto::clear_has_label() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FieldDescriptorProto::clear_label() { - label_ = 1; - clear_has_label(); -} -inline ::google::protobuf::FieldDescriptorProto_Label FieldDescriptorProto::label() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.label) - return static_cast< ::google::protobuf::FieldDescriptorProto_Label >(label_); -} -inline void FieldDescriptorProto::set_label(::google::protobuf::FieldDescriptorProto_Label value) { - assert(::google::protobuf::FieldDescriptorProto_Label_IsValid(value)); - set_has_label(); - label_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.label) -} - -// optional .google.protobuf.FieldDescriptorProto.Type type = 5; -inline bool FieldDescriptorProto::has_type() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FieldDescriptorProto::set_has_type() { - _has_bits_[0] |= 0x00000008u; -} -inline void FieldDescriptorProto::clear_has_type() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FieldDescriptorProto::clear_type() { - type_ = 1; - clear_has_type(); -} -inline ::google::protobuf::FieldDescriptorProto_Type FieldDescriptorProto::type() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.type) - return static_cast< ::google::protobuf::FieldDescriptorProto_Type >(type_); -} -inline void FieldDescriptorProto::set_type(::google::protobuf::FieldDescriptorProto_Type value) { - assert(::google::protobuf::FieldDescriptorProto_Type_IsValid(value)); - set_has_type(); - type_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.type) -} - -// optional string type_name = 6; -inline bool FieldDescriptorProto::has_type_name() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void FieldDescriptorProto::set_has_type_name() { - _has_bits_[0] |= 0x00000010u; -} -inline void FieldDescriptorProto::clear_has_type_name() { - _has_bits_[0] &= ~0x00000010u; -} -inline void FieldDescriptorProto::clear_type_name() { - type_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_type_name(); -} -inline const ::std::string& FieldDescriptorProto::type_name() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.type_name) - return type_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_type_name(const ::std::string& value) { - set_has_type_name(); - type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.type_name) -} -inline void FieldDescriptorProto::set_type_name(const char* value) { - set_has_type_name(); - type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.type_name) -} -inline void FieldDescriptorProto::set_type_name(const char* value, size_t size) { - set_has_type_name(); - type_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.type_name) -} -inline ::std::string* FieldDescriptorProto::mutable_type_name() { - set_has_type_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.type_name) - return type_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FieldDescriptorProto::release_type_name() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.type_name) - clear_has_type_name(); - return type_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_allocated_type_name(::std::string* type_name) { - if (type_name != NULL) { - set_has_type_name(); - } else { - clear_has_type_name(); - } - type_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), type_name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.type_name) -} - -// optional string extendee = 2; -inline bool FieldDescriptorProto::has_extendee() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void FieldDescriptorProto::set_has_extendee() { - _has_bits_[0] |= 0x00000020u; -} -inline void FieldDescriptorProto::clear_has_extendee() { - _has_bits_[0] &= ~0x00000020u; -} -inline void FieldDescriptorProto::clear_extendee() { - extendee_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_extendee(); -} -inline const ::std::string& FieldDescriptorProto::extendee() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.extendee) - return extendee_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_extendee(const ::std::string& value) { - set_has_extendee(); - extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.extendee) -} -inline void FieldDescriptorProto::set_extendee(const char* value) { - set_has_extendee(); - extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.extendee) -} -inline void FieldDescriptorProto::set_extendee(const char* value, size_t size) { - set_has_extendee(); - extendee_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.extendee) -} -inline ::std::string* FieldDescriptorProto::mutable_extendee() { - set_has_extendee(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.extendee) - return extendee_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FieldDescriptorProto::release_extendee() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.extendee) - clear_has_extendee(); - return extendee_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_allocated_extendee(::std::string* extendee) { - if (extendee != NULL) { - set_has_extendee(); - } else { - clear_has_extendee(); - } - extendee_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), extendee); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.extendee) -} - -// optional string default_value = 7; -inline bool FieldDescriptorProto::has_default_value() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void FieldDescriptorProto::set_has_default_value() { - _has_bits_[0] |= 0x00000040u; -} -inline void FieldDescriptorProto::clear_has_default_value() { - _has_bits_[0] &= ~0x00000040u; -} -inline void FieldDescriptorProto::clear_default_value() { - default_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_default_value(); -} -inline const ::std::string& FieldDescriptorProto::default_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.default_value) - return default_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_default_value(const ::std::string& value) { - set_has_default_value(); - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.default_value) -} -inline void FieldDescriptorProto::set_default_value(const char* value) { - set_has_default_value(); - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.default_value) -} -inline void FieldDescriptorProto::set_default_value(const char* value, size_t size) { - set_has_default_value(); - default_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.default_value) -} -inline ::std::string* FieldDescriptorProto::mutable_default_value() { - set_has_default_value(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.default_value) - return default_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FieldDescriptorProto::release_default_value() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.default_value) - clear_has_default_value(); - return default_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_allocated_default_value(::std::string* default_value) { - if (default_value != NULL) { - set_has_default_value(); - } else { - clear_has_default_value(); - } - default_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), default_value); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.default_value) -} - -// optional int32 oneof_index = 9; -inline bool FieldDescriptorProto::has_oneof_index() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void FieldDescriptorProto::set_has_oneof_index() { - _has_bits_[0] |= 0x00000080u; -} -inline void FieldDescriptorProto::clear_has_oneof_index() { - _has_bits_[0] &= ~0x00000080u; -} -inline void FieldDescriptorProto::clear_oneof_index() { - oneof_index_ = 0; - clear_has_oneof_index(); -} -inline ::google::protobuf::int32 FieldDescriptorProto::oneof_index() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.oneof_index) - return oneof_index_; -} -inline void FieldDescriptorProto::set_oneof_index(::google::protobuf::int32 value) { - set_has_oneof_index(); - oneof_index_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.oneof_index) -} - -// optional string json_name = 10; -inline bool FieldDescriptorProto::has_json_name() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void FieldDescriptorProto::set_has_json_name() { - _has_bits_[0] |= 0x00000100u; -} -inline void FieldDescriptorProto::clear_has_json_name() { - _has_bits_[0] &= ~0x00000100u; -} -inline void FieldDescriptorProto::clear_json_name() { - json_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_json_name(); -} -inline const ::std::string& FieldDescriptorProto::json_name() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.json_name) - return json_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_json_name(const ::std::string& value) { - set_has_json_name(); - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.json_name) -} -inline void FieldDescriptorProto::set_json_name(const char* value) { - set_has_json_name(); - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldDescriptorProto.json_name) -} -inline void FieldDescriptorProto::set_json_name(const char* value, size_t size) { - set_has_json_name(); - json_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldDescriptorProto.json_name) -} -inline ::std::string* FieldDescriptorProto::mutable_json_name() { - set_has_json_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.json_name) - return json_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FieldDescriptorProto::release_json_name() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.json_name) - clear_has_json_name(); - return json_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FieldDescriptorProto::set_allocated_json_name(::std::string* json_name) { - if (json_name != NULL) { - set_has_json_name(); - } else { - clear_has_json_name(); - } - json_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), json_name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.json_name) -} - -// optional .google.protobuf.FieldOptions options = 8; -inline bool FieldDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void FieldDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000200u; -} -inline void FieldDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000200u; -} -inline void FieldDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::FieldOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FieldOptions::internal_default_instance(); -} -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::FieldOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldDescriptorProto.options) - return options_; -} -inline ::google::protobuf::FieldOptions* FieldDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.FieldDescriptorProto.options) - clear_has_options(); - ::google::protobuf::FieldOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void FieldDescriptorProto::set_allocated_options(::google::protobuf::FieldOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FieldDescriptorProto.options) -} - -inline const FieldDescriptorProto* FieldDescriptorProto::internal_default_instance() { - return &FieldDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// OneofDescriptorProto - -// optional string name = 1; -inline bool OneofDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void OneofDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void OneofDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void OneofDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& OneofDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OneofDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.OneofDescriptorProto.name) -} -inline void OneofDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.OneofDescriptorProto.name) -} -inline void OneofDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.OneofDescriptorProto.name) -} -inline ::std::string* OneofDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.OneofDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* OneofDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void OneofDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.OneofDescriptorProto.name) -} - -// optional .google.protobuf.OneofOptions options = 2; -inline bool OneofDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void OneofDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000002u; -} -inline void OneofDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000002u; -} -inline void OneofDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::OneofOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::OneofOptions::internal_default_instance(); -} -inline ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::OneofOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.OneofDescriptorProto.options) - return options_; -} -inline ::google::protobuf::OneofOptions* OneofDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.OneofDescriptorProto.options) - clear_has_options(); - ::google::protobuf::OneofOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void OneofDescriptorProto::set_allocated_options(::google::protobuf::OneofOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.OneofDescriptorProto.options) -} - -inline const OneofDescriptorProto* OneofDescriptorProto::internal_default_instance() { - return &OneofDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// EnumDescriptorProto - -// optional string name = 1; -inline bool EnumDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& EnumDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void EnumDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.EnumDescriptorProto.name) -} -inline void EnumDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.name) -} -inline void EnumDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumDescriptorProto.name) -} -inline ::std::string* EnumDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* EnumDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void EnumDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumDescriptorProto.name) -} - -// repeated .google.protobuf.EnumValueDescriptorProto value = 2; -inline int EnumDescriptorProto::value_size() const { - return value_.size(); -} -inline void EnumDescriptorProto::clear_value() { - value_.Clear(); -} -inline const ::google::protobuf::EnumValueDescriptorProto& EnumDescriptorProto::value(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.value) - return value_.Get(index); -} -inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::mutable_value(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.value) - return value_.Mutable(index); -} -inline ::google::protobuf::EnumValueDescriptorProto* EnumDescriptorProto::add_value() { - // @@protoc_insertion_point(field_add:google.protobuf.EnumDescriptorProto.value) - return value_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >* -EnumDescriptorProto::mutable_value() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.EnumDescriptorProto.value) - return &value_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValueDescriptorProto >& -EnumDescriptorProto::value() const { - // @@protoc_insertion_point(field_list:google.protobuf.EnumDescriptorProto.value) - return value_; -} - -// optional .google.protobuf.EnumOptions options = 3; -inline bool EnumDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void EnumDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void EnumDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void EnumDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumOptions::internal_default_instance(); -} -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::EnumOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumDescriptorProto.options) - return options_; -} -inline ::google::protobuf::EnumOptions* EnumDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumDescriptorProto.options) - clear_has_options(); - ::google::protobuf::EnumOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void EnumDescriptorProto::set_allocated_options(::google::protobuf::EnumOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumDescriptorProto.options) -} - -inline const EnumDescriptorProto* EnumDescriptorProto::internal_default_instance() { - return &EnumDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// EnumValueDescriptorProto - -// optional string name = 1; -inline bool EnumValueDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumValueDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumValueDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumValueDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& EnumValueDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void EnumValueDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.EnumValueDescriptorProto.name) -} -inline void EnumValueDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.EnumValueDescriptorProto.name) -} -inline void EnumValueDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.EnumValueDescriptorProto.name) -} -inline ::std::string* EnumValueDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValueDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* EnumValueDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void EnumValueDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValueDescriptorProto.name) -} - -// optional int32 number = 2; -inline bool EnumValueDescriptorProto::has_number() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void EnumValueDescriptorProto::set_has_number() { - _has_bits_[0] |= 0x00000002u; -} -inline void EnumValueDescriptorProto::clear_has_number() { - _has_bits_[0] &= ~0x00000002u; -} -inline void EnumValueDescriptorProto::clear_number() { - number_ = 0; - clear_has_number(); -} -inline ::google::protobuf::int32 EnumValueDescriptorProto::number() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.number) - return number_; -} -inline void EnumValueDescriptorProto::set_number(::google::protobuf::int32 value) { - set_has_number(); - number_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.EnumValueDescriptorProto.number) -} - -// optional .google.protobuf.EnumValueOptions options = 3; -inline bool EnumValueDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void EnumValueDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void EnumValueDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void EnumValueDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::EnumValueOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumValueOptions::internal_default_instance(); -} -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::EnumValueOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValueDescriptorProto.options) - return options_; -} -inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.EnumValueDescriptorProto.options) - clear_has_options(); - ::google::protobuf::EnumValueOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void EnumValueDescriptorProto::set_allocated_options(::google::protobuf::EnumValueOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.EnumValueDescriptorProto.options) -} - -inline const EnumValueDescriptorProto* EnumValueDescriptorProto::internal_default_instance() { - return &EnumValueDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// ServiceDescriptorProto - -// optional string name = 1; -inline bool ServiceDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ServiceDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void ServiceDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ServiceDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& ServiceDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ServiceDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.ServiceDescriptorProto.name) -} -inline void ServiceDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.ServiceDescriptorProto.name) -} -inline void ServiceDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.ServiceDescriptorProto.name) -} -inline ::std::string* ServiceDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* ServiceDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void ServiceDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.ServiceDescriptorProto.name) -} - -// repeated .google.protobuf.MethodDescriptorProto method = 2; -inline int ServiceDescriptorProto::method_size() const { - return method_.size(); -} -inline void ServiceDescriptorProto::clear_method() { - method_.Clear(); -} -inline const ::google::protobuf::MethodDescriptorProto& ServiceDescriptorProto::method(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.method) - return method_.Get(index); -} -inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::mutable_method(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceDescriptorProto.method) - return method_.Mutable(index); -} -inline ::google::protobuf::MethodDescriptorProto* ServiceDescriptorProto::add_method() { - // @@protoc_insertion_point(field_add:google.protobuf.ServiceDescriptorProto.method) - return method_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >* -ServiceDescriptorProto::mutable_method() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.ServiceDescriptorProto.method) - return &method_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::MethodDescriptorProto >& -ServiceDescriptorProto::method() const { - // @@protoc_insertion_point(field_list:google.protobuf.ServiceDescriptorProto.method) - return method_; -} - -// optional .google.protobuf.ServiceOptions options = 3; -inline bool ServiceDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void ServiceDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000004u; -} -inline void ServiceDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000004u; -} -inline void ServiceDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::ServiceOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::ServiceOptions::internal_default_instance(); -} -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::ServiceOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceDescriptorProto.options) - return options_; -} -inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.ServiceDescriptorProto.options) - clear_has_options(); - ::google::protobuf::ServiceOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void ServiceDescriptorProto::set_allocated_options(::google::protobuf::ServiceOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.ServiceDescriptorProto.options) -} - -inline const ServiceDescriptorProto* ServiceDescriptorProto::internal_default_instance() { - return &ServiceDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// MethodDescriptorProto - -// optional string name = 1; -inline bool MethodDescriptorProto::has_name() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void MethodDescriptorProto::set_has_name() { - _has_bits_[0] |= 0x00000001u; -} -inline void MethodDescriptorProto::clear_has_name() { - _has_bits_[0] &= ~0x00000001u; -} -inline void MethodDescriptorProto::clear_name() { - name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name(); -} -inline const ::std::string& MethodDescriptorProto::name() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.name) - return name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_name(const ::std::string& value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.name) -} -inline void MethodDescriptorProto::set_name(const char* value) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.name) -} -inline void MethodDescriptorProto::set_name(const char* value, size_t size) { - set_has_name(); - name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.name) -} -inline ::std::string* MethodDescriptorProto::mutable_name() { - set_has_name(); - // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.name) - return name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* MethodDescriptorProto::release_name() { - // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.name) - clear_has_name(); - return name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_allocated_name(::std::string* name) { - if (name != NULL) { - set_has_name(); - } else { - clear_has_name(); - } - name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.name) -} - -// optional string input_type = 2; -inline bool MethodDescriptorProto::has_input_type() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void MethodDescriptorProto::set_has_input_type() { - _has_bits_[0] |= 0x00000002u; -} -inline void MethodDescriptorProto::clear_has_input_type() { - _has_bits_[0] &= ~0x00000002u; -} -inline void MethodDescriptorProto::clear_input_type() { - input_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_input_type(); -} -inline const ::std::string& MethodDescriptorProto::input_type() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.input_type) - return input_type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_input_type(const ::std::string& value) { - set_has_input_type(); - input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.input_type) -} -inline void MethodDescriptorProto::set_input_type(const char* value) { - set_has_input_type(); - input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.input_type) -} -inline void MethodDescriptorProto::set_input_type(const char* value, size_t size) { - set_has_input_type(); - input_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.input_type) -} -inline ::std::string* MethodDescriptorProto::mutable_input_type() { - set_has_input_type(); - // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.input_type) - return input_type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* MethodDescriptorProto::release_input_type() { - // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.input_type) - clear_has_input_type(); - return input_type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_allocated_input_type(::std::string* input_type) { - if (input_type != NULL) { - set_has_input_type(); - } else { - clear_has_input_type(); - } - input_type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), input_type); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.input_type) -} - -// optional string output_type = 3; -inline bool MethodDescriptorProto::has_output_type() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void MethodDescriptorProto::set_has_output_type() { - _has_bits_[0] |= 0x00000004u; -} -inline void MethodDescriptorProto::clear_has_output_type() { - _has_bits_[0] &= ~0x00000004u; -} -inline void MethodDescriptorProto::clear_output_type() { - output_type_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_output_type(); -} -inline const ::std::string& MethodDescriptorProto::output_type() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.output_type) - return output_type_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_output_type(const ::std::string& value) { - set_has_output_type(); - output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.output_type) -} -inline void MethodDescriptorProto::set_output_type(const char* value) { - set_has_output_type(); - output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.MethodDescriptorProto.output_type) -} -inline void MethodDescriptorProto::set_output_type(const char* value, size_t size) { - set_has_output_type(); - output_type_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.MethodDescriptorProto.output_type) -} -inline ::std::string* MethodDescriptorProto::mutable_output_type() { - set_has_output_type(); - // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.output_type) - return output_type_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* MethodDescriptorProto::release_output_type() { - // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.output_type) - clear_has_output_type(); - return output_type_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void MethodDescriptorProto::set_allocated_output_type(::std::string* output_type) { - if (output_type != NULL) { - set_has_output_type(); - } else { - clear_has_output_type(); - } - output_type_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), output_type); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.output_type) -} - -// optional .google.protobuf.MethodOptions options = 4; -inline bool MethodDescriptorProto::has_options() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void MethodDescriptorProto::set_has_options() { - _has_bits_[0] |= 0x00000008u; -} -inline void MethodDescriptorProto::clear_has_options() { - _has_bits_[0] &= ~0x00000008u; -} -inline void MethodDescriptorProto::clear_options() { - if (options_ != NULL) options_->::google::protobuf::MethodOptions::Clear(); - clear_has_options(); -} -inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MethodOptions::internal_default_instance(); -} -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { - set_has_options(); - if (options_ == NULL) { - options_ = new ::google::protobuf::MethodOptions; - } - // @@protoc_insertion_point(field_mutable:google.protobuf.MethodDescriptorProto.options) - return options_; -} -inline ::google::protobuf::MethodOptions* MethodDescriptorProto::release_options() { - // @@protoc_insertion_point(field_release:google.protobuf.MethodDescriptorProto.options) - clear_has_options(); - ::google::protobuf::MethodOptions* temp = options_; - options_ = NULL; - return temp; -} -inline void MethodDescriptorProto::set_allocated_options(::google::protobuf::MethodOptions* options) { - delete options_; - options_ = options; - if (options) { - set_has_options(); - } else { - clear_has_options(); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.MethodDescriptorProto.options) -} - -// optional bool client_streaming = 5 [default = false]; -inline bool MethodDescriptorProto::has_client_streaming() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void MethodDescriptorProto::set_has_client_streaming() { - _has_bits_[0] |= 0x00000010u; -} -inline void MethodDescriptorProto::clear_has_client_streaming() { - _has_bits_[0] &= ~0x00000010u; -} -inline void MethodDescriptorProto::clear_client_streaming() { - client_streaming_ = false; - clear_has_client_streaming(); -} -inline bool MethodDescriptorProto::client_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.client_streaming) - return client_streaming_; -} -inline void MethodDescriptorProto::set_client_streaming(bool value) { - set_has_client_streaming(); - client_streaming_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.client_streaming) -} - -// optional bool server_streaming = 6 [default = false]; -inline bool MethodDescriptorProto::has_server_streaming() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void MethodDescriptorProto::set_has_server_streaming() { - _has_bits_[0] |= 0x00000020u; -} -inline void MethodDescriptorProto::clear_has_server_streaming() { - _has_bits_[0] &= ~0x00000020u; -} -inline void MethodDescriptorProto::clear_server_streaming() { - server_streaming_ = false; - clear_has_server_streaming(); -} -inline bool MethodDescriptorProto::server_streaming() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.server_streaming) - return server_streaming_; -} -inline void MethodDescriptorProto::set_server_streaming(bool value) { - set_has_server_streaming(); - server_streaming_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MethodDescriptorProto.server_streaming) -} - -inline const MethodDescriptorProto* MethodDescriptorProto::internal_default_instance() { - return &MethodDescriptorProto_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// FileOptions - -// optional string java_package = 1; -inline bool FileOptions::has_java_package() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FileOptions::set_has_java_package() { - _has_bits_[0] |= 0x00000001u; -} -inline void FileOptions::clear_has_java_package() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FileOptions::clear_java_package() { - java_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_java_package(); -} -inline const ::std::string& FileOptions::java_package() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_package) - return java_package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_java_package(const ::std::string& value) { - set_has_java_package(); - java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_package) -} -inline void FileOptions::set_java_package(const char* value) { - set_has_java_package(); - java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_package) -} -inline void FileOptions::set_java_package(const char* value, size_t size) { - set_has_java_package(); - java_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.java_package) -} -inline ::std::string* FileOptions::mutable_java_package() { - set_has_java_package(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.java_package) - return java_package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileOptions::release_java_package() { - // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_package) - clear_has_java_package(); - return java_package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_allocated_java_package(::std::string* java_package) { - if (java_package != NULL) { - set_has_java_package(); - } else { - clear_has_java_package(); - } - java_package_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), java_package); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.java_package) -} - -// optional string java_outer_classname = 8; -inline bool FileOptions::has_java_outer_classname() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FileOptions::set_has_java_outer_classname() { - _has_bits_[0] |= 0x00000002u; -} -inline void FileOptions::clear_has_java_outer_classname() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FileOptions::clear_java_outer_classname() { - java_outer_classname_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_java_outer_classname(); -} -inline const ::std::string& FileOptions::java_outer_classname() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_outer_classname) - return java_outer_classname_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_java_outer_classname(const ::std::string& value) { - set_has_java_outer_classname(); - java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_outer_classname) -} -inline void FileOptions::set_java_outer_classname(const char* value) { - set_has_java_outer_classname(); - java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.java_outer_classname) -} -inline void FileOptions::set_java_outer_classname(const char* value, size_t size) { - set_has_java_outer_classname(); - java_outer_classname_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.java_outer_classname) -} -inline ::std::string* FileOptions::mutable_java_outer_classname() { - set_has_java_outer_classname(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.java_outer_classname) - return java_outer_classname_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileOptions::release_java_outer_classname() { - // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.java_outer_classname) - clear_has_java_outer_classname(); - return java_outer_classname_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_allocated_java_outer_classname(::std::string* java_outer_classname) { - if (java_outer_classname != NULL) { - set_has_java_outer_classname(); - } else { - clear_has_java_outer_classname(); - } - java_outer_classname_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), java_outer_classname); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.java_outer_classname) -} - -// optional bool java_multiple_files = 10 [default = false]; -inline bool FileOptions::has_java_multiple_files() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FileOptions::set_has_java_multiple_files() { - _has_bits_[0] |= 0x00000004u; -} -inline void FileOptions::clear_has_java_multiple_files() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FileOptions::clear_java_multiple_files() { - java_multiple_files_ = false; - clear_has_java_multiple_files(); -} -inline bool FileOptions::java_multiple_files() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_multiple_files) - return java_multiple_files_; -} -inline void FileOptions::set_java_multiple_files(bool value) { - set_has_java_multiple_files(); - java_multiple_files_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_multiple_files) -} - -// optional bool java_generate_equals_and_hash = 20 [deprecated = true]; -inline bool FileOptions::has_java_generate_equals_and_hash() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FileOptions::set_has_java_generate_equals_and_hash() { - _has_bits_[0] |= 0x00000008u; -} -inline void FileOptions::clear_has_java_generate_equals_and_hash() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FileOptions::clear_java_generate_equals_and_hash() { - java_generate_equals_and_hash_ = false; - clear_has_java_generate_equals_and_hash(); -} -inline bool FileOptions::java_generate_equals_and_hash() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_generate_equals_and_hash) - return java_generate_equals_and_hash_; -} -inline void FileOptions::set_java_generate_equals_and_hash(bool value) { - set_has_java_generate_equals_and_hash(); - java_generate_equals_and_hash_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_generate_equals_and_hash) -} - -// optional bool java_string_check_utf8 = 27 [default = false]; -inline bool FileOptions::has_java_string_check_utf8() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void FileOptions::set_has_java_string_check_utf8() { - _has_bits_[0] |= 0x00000010u; -} -inline void FileOptions::clear_has_java_string_check_utf8() { - _has_bits_[0] &= ~0x00000010u; -} -inline void FileOptions::clear_java_string_check_utf8() { - java_string_check_utf8_ = false; - clear_has_java_string_check_utf8(); -} -inline bool FileOptions::java_string_check_utf8() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_string_check_utf8) - return java_string_check_utf8_; -} -inline void FileOptions::set_java_string_check_utf8(bool value) { - set_has_java_string_check_utf8(); - java_string_check_utf8_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_string_check_utf8) -} - -// optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; -inline bool FileOptions::has_optimize_for() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void FileOptions::set_has_optimize_for() { - _has_bits_[0] |= 0x00000020u; -} -inline void FileOptions::clear_has_optimize_for() { - _has_bits_[0] &= ~0x00000020u; -} -inline void FileOptions::clear_optimize_for() { - optimize_for_ = 1; - clear_has_optimize_for(); -} -inline ::google::protobuf::FileOptions_OptimizeMode FileOptions::optimize_for() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.optimize_for) - return static_cast< ::google::protobuf::FileOptions_OptimizeMode >(optimize_for_); -} -inline void FileOptions::set_optimize_for(::google::protobuf::FileOptions_OptimizeMode value) { - assert(::google::protobuf::FileOptions_OptimizeMode_IsValid(value)); - set_has_optimize_for(); - optimize_for_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.optimize_for) -} - -// optional string go_package = 11; -inline bool FileOptions::has_go_package() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void FileOptions::set_has_go_package() { - _has_bits_[0] |= 0x00000040u; -} -inline void FileOptions::clear_has_go_package() { - _has_bits_[0] &= ~0x00000040u; -} -inline void FileOptions::clear_go_package() { - go_package_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_go_package(); -} -inline const ::std::string& FileOptions::go_package() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.go_package) - return go_package_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_go_package(const ::std::string& value) { - set_has_go_package(); - go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.go_package) -} -inline void FileOptions::set_go_package(const char* value) { - set_has_go_package(); - go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.go_package) -} -inline void FileOptions::set_go_package(const char* value, size_t size) { - set_has_go_package(); - go_package_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.go_package) -} -inline ::std::string* FileOptions::mutable_go_package() { - set_has_go_package(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.go_package) - return go_package_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileOptions::release_go_package() { - // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.go_package) - clear_has_go_package(); - return go_package_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_allocated_go_package(::std::string* go_package) { - if (go_package != NULL) { - set_has_go_package(); - } else { - clear_has_go_package(); - } - go_package_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), go_package); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.go_package) -} - -// optional bool cc_generic_services = 16 [default = false]; -inline bool FileOptions::has_cc_generic_services() const { - return (_has_bits_[0] & 0x00000080u) != 0; -} -inline void FileOptions::set_has_cc_generic_services() { - _has_bits_[0] |= 0x00000080u; -} -inline void FileOptions::clear_has_cc_generic_services() { - _has_bits_[0] &= ~0x00000080u; -} -inline void FileOptions::clear_cc_generic_services() { - cc_generic_services_ = false; - clear_has_cc_generic_services(); -} -inline bool FileOptions::cc_generic_services() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.cc_generic_services) - return cc_generic_services_; -} -inline void FileOptions::set_cc_generic_services(bool value) { - set_has_cc_generic_services(); - cc_generic_services_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.cc_generic_services) -} - -// optional bool java_generic_services = 17 [default = false]; -inline bool FileOptions::has_java_generic_services() const { - return (_has_bits_[0] & 0x00000100u) != 0; -} -inline void FileOptions::set_has_java_generic_services() { - _has_bits_[0] |= 0x00000100u; -} -inline void FileOptions::clear_has_java_generic_services() { - _has_bits_[0] &= ~0x00000100u; -} -inline void FileOptions::clear_java_generic_services() { - java_generic_services_ = false; - clear_has_java_generic_services(); -} -inline bool FileOptions::java_generic_services() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.java_generic_services) - return java_generic_services_; -} -inline void FileOptions::set_java_generic_services(bool value) { - set_has_java_generic_services(); - java_generic_services_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.java_generic_services) -} - -// optional bool py_generic_services = 18 [default = false]; -inline bool FileOptions::has_py_generic_services() const { - return (_has_bits_[0] & 0x00000200u) != 0; -} -inline void FileOptions::set_has_py_generic_services() { - _has_bits_[0] |= 0x00000200u; -} -inline void FileOptions::clear_has_py_generic_services() { - _has_bits_[0] &= ~0x00000200u; -} -inline void FileOptions::clear_py_generic_services() { - py_generic_services_ = false; - clear_has_py_generic_services(); -} -inline bool FileOptions::py_generic_services() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.py_generic_services) - return py_generic_services_; -} -inline void FileOptions::set_py_generic_services(bool value) { - set_has_py_generic_services(); - py_generic_services_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.py_generic_services) -} - -// optional bool deprecated = 23 [default = false]; -inline bool FileOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000400u) != 0; -} -inline void FileOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000400u; -} -inline void FileOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000400u; -} -inline void FileOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool FileOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.deprecated) - return deprecated_; -} -inline void FileOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.deprecated) -} - -// optional bool cc_enable_arenas = 31 [default = false]; -inline bool FileOptions::has_cc_enable_arenas() const { - return (_has_bits_[0] & 0x00000800u) != 0; -} -inline void FileOptions::set_has_cc_enable_arenas() { - _has_bits_[0] |= 0x00000800u; -} -inline void FileOptions::clear_has_cc_enable_arenas() { - _has_bits_[0] &= ~0x00000800u; -} -inline void FileOptions::clear_cc_enable_arenas() { - cc_enable_arenas_ = false; - clear_has_cc_enable_arenas(); -} -inline bool FileOptions::cc_enable_arenas() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.cc_enable_arenas) - return cc_enable_arenas_; -} -inline void FileOptions::set_cc_enable_arenas(bool value) { - set_has_cc_enable_arenas(); - cc_enable_arenas_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.cc_enable_arenas) -} - -// optional string objc_class_prefix = 36; -inline bool FileOptions::has_objc_class_prefix() const { - return (_has_bits_[0] & 0x00001000u) != 0; -} -inline void FileOptions::set_has_objc_class_prefix() { - _has_bits_[0] |= 0x00001000u; -} -inline void FileOptions::clear_has_objc_class_prefix() { - _has_bits_[0] &= ~0x00001000u; -} -inline void FileOptions::clear_objc_class_prefix() { - objc_class_prefix_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_objc_class_prefix(); -} -inline const ::std::string& FileOptions::objc_class_prefix() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.objc_class_prefix) - return objc_class_prefix_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_objc_class_prefix(const ::std::string& value) { - set_has_objc_class_prefix(); - objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.objc_class_prefix) -} -inline void FileOptions::set_objc_class_prefix(const char* value) { - set_has_objc_class_prefix(); - objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.objc_class_prefix) -} -inline void FileOptions::set_objc_class_prefix(const char* value, size_t size) { - set_has_objc_class_prefix(); - objc_class_prefix_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.objc_class_prefix) -} -inline ::std::string* FileOptions::mutable_objc_class_prefix() { - set_has_objc_class_prefix(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.objc_class_prefix) - return objc_class_prefix_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileOptions::release_objc_class_prefix() { - // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.objc_class_prefix) - clear_has_objc_class_prefix(); - return objc_class_prefix_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_allocated_objc_class_prefix(::std::string* objc_class_prefix) { - if (objc_class_prefix != NULL) { - set_has_objc_class_prefix(); - } else { - clear_has_objc_class_prefix(); - } - objc_class_prefix_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), objc_class_prefix); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.objc_class_prefix) -} - -// optional string csharp_namespace = 37; -inline bool FileOptions::has_csharp_namespace() const { - return (_has_bits_[0] & 0x00002000u) != 0; -} -inline void FileOptions::set_has_csharp_namespace() { - _has_bits_[0] |= 0x00002000u; -} -inline void FileOptions::clear_has_csharp_namespace() { - _has_bits_[0] &= ~0x00002000u; -} -inline void FileOptions::clear_csharp_namespace() { - csharp_namespace_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_csharp_namespace(); -} -inline const ::std::string& FileOptions::csharp_namespace() const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.csharp_namespace) - return csharp_namespace_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_csharp_namespace(const ::std::string& value) { - set_has_csharp_namespace(); - csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.FileOptions.csharp_namespace) -} -inline void FileOptions::set_csharp_namespace(const char* value) { - set_has_csharp_namespace(); - csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.FileOptions.csharp_namespace) -} -inline void FileOptions::set_csharp_namespace(const char* value, size_t size) { - set_has_csharp_namespace(); - csharp_namespace_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FileOptions.csharp_namespace) -} -inline ::std::string* FileOptions::mutable_csharp_namespace() { - set_has_csharp_namespace(); - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.csharp_namespace) - return csharp_namespace_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* FileOptions::release_csharp_namespace() { - // @@protoc_insertion_point(field_release:google.protobuf.FileOptions.csharp_namespace) - clear_has_csharp_namespace(); - return csharp_namespace_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void FileOptions::set_allocated_csharp_namespace(::std::string* csharp_namespace) { - if (csharp_namespace != NULL) { - set_has_csharp_namespace(); - } else { - clear_has_csharp_namespace(); - } - csharp_namespace_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), csharp_namespace); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.FileOptions.csharp_namespace) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int FileOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void FileOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& FileOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FileOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* FileOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FileOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* FileOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.FileOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -FileOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FileOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -FileOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.FileOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const FileOptions* FileOptions::internal_default_instance() { - return &FileOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// MessageOptions - -// optional bool message_set_wire_format = 1 [default = false]; -inline bool MessageOptions::has_message_set_wire_format() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void MessageOptions::set_has_message_set_wire_format() { - _has_bits_[0] |= 0x00000001u; -} -inline void MessageOptions::clear_has_message_set_wire_format() { - _has_bits_[0] &= ~0x00000001u; -} -inline void MessageOptions::clear_message_set_wire_format() { - message_set_wire_format_ = false; - clear_has_message_set_wire_format(); -} -inline bool MessageOptions::message_set_wire_format() const { - // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.message_set_wire_format) - return message_set_wire_format_; -} -inline void MessageOptions::set_message_set_wire_format(bool value) { - set_has_message_set_wire_format(); - message_set_wire_format_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.message_set_wire_format) -} - -// optional bool no_standard_descriptor_accessor = 2 [default = false]; -inline bool MessageOptions::has_no_standard_descriptor_accessor() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void MessageOptions::set_has_no_standard_descriptor_accessor() { - _has_bits_[0] |= 0x00000002u; -} -inline void MessageOptions::clear_has_no_standard_descriptor_accessor() { - _has_bits_[0] &= ~0x00000002u; -} -inline void MessageOptions::clear_no_standard_descriptor_accessor() { - no_standard_descriptor_accessor_ = false; - clear_has_no_standard_descriptor_accessor(); -} -inline bool MessageOptions::no_standard_descriptor_accessor() const { - // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.no_standard_descriptor_accessor) - return no_standard_descriptor_accessor_; -} -inline void MessageOptions::set_no_standard_descriptor_accessor(bool value) { - set_has_no_standard_descriptor_accessor(); - no_standard_descriptor_accessor_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.no_standard_descriptor_accessor) -} - -// optional bool deprecated = 3 [default = false]; -inline bool MessageOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void MessageOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000004u; -} -inline void MessageOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000004u; -} -inline void MessageOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool MessageOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.deprecated) - return deprecated_; -} -inline void MessageOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.deprecated) -} - -// optional bool map_entry = 7; -inline bool MessageOptions::has_map_entry() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void MessageOptions::set_has_map_entry() { - _has_bits_[0] |= 0x00000008u; -} -inline void MessageOptions::clear_has_map_entry() { - _has_bits_[0] &= ~0x00000008u; -} -inline void MessageOptions::clear_map_entry() { - map_entry_ = false; - clear_has_map_entry(); -} -inline bool MessageOptions::map_entry() const { - // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.map_entry) - return map_entry_; -} -inline void MessageOptions::set_map_entry(bool value) { - set_has_map_entry(); - map_entry_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MessageOptions.map_entry) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int MessageOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void MessageOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& MessageOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.MessageOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* MessageOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.MessageOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* MessageOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.MessageOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -MessageOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.MessageOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -MessageOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.MessageOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const MessageOptions* MessageOptions::internal_default_instance() { - return &MessageOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// FieldOptions - -// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; -inline bool FieldOptions::has_ctype() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void FieldOptions::set_has_ctype() { - _has_bits_[0] |= 0x00000001u; -} -inline void FieldOptions::clear_has_ctype() { - _has_bits_[0] &= ~0x00000001u; -} -inline void FieldOptions::clear_ctype() { - ctype_ = 0; - clear_has_ctype(); -} -inline ::google::protobuf::FieldOptions_CType FieldOptions::ctype() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.ctype) - return static_cast< ::google::protobuf::FieldOptions_CType >(ctype_); -} -inline void FieldOptions::set_ctype(::google::protobuf::FieldOptions_CType value) { - assert(::google::protobuf::FieldOptions_CType_IsValid(value)); - set_has_ctype(); - ctype_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.ctype) -} - -// optional bool packed = 2; -inline bool FieldOptions::has_packed() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void FieldOptions::set_has_packed() { - _has_bits_[0] |= 0x00000002u; -} -inline void FieldOptions::clear_has_packed() { - _has_bits_[0] &= ~0x00000002u; -} -inline void FieldOptions::clear_packed() { - packed_ = false; - clear_has_packed(); -} -inline bool FieldOptions::packed() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.packed) - return packed_; -} -inline void FieldOptions::set_packed(bool value) { - set_has_packed(); - packed_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.packed) -} - -// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; -inline bool FieldOptions::has_jstype() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void FieldOptions::set_has_jstype() { - _has_bits_[0] |= 0x00000004u; -} -inline void FieldOptions::clear_has_jstype() { - _has_bits_[0] &= ~0x00000004u; -} -inline void FieldOptions::clear_jstype() { - jstype_ = 0; - clear_has_jstype(); -} -inline ::google::protobuf::FieldOptions_JSType FieldOptions::jstype() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.jstype) - return static_cast< ::google::protobuf::FieldOptions_JSType >(jstype_); -} -inline void FieldOptions::set_jstype(::google::protobuf::FieldOptions_JSType value) { - assert(::google::protobuf::FieldOptions_JSType_IsValid(value)); - set_has_jstype(); - jstype_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.jstype) -} - -// optional bool lazy = 5 [default = false]; -inline bool FieldOptions::has_lazy() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void FieldOptions::set_has_lazy() { - _has_bits_[0] |= 0x00000008u; -} -inline void FieldOptions::clear_has_lazy() { - _has_bits_[0] &= ~0x00000008u; -} -inline void FieldOptions::clear_lazy() { - lazy_ = false; - clear_has_lazy(); -} -inline bool FieldOptions::lazy() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.lazy) - return lazy_; -} -inline void FieldOptions::set_lazy(bool value) { - set_has_lazy(); - lazy_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.lazy) -} - -// optional bool deprecated = 3 [default = false]; -inline bool FieldOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void FieldOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000010u; -} -inline void FieldOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000010u; -} -inline void FieldOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool FieldOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.deprecated) - return deprecated_; -} -inline void FieldOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.deprecated) -} - -// optional bool weak = 10 [default = false]; -inline bool FieldOptions::has_weak() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void FieldOptions::set_has_weak() { - _has_bits_[0] |= 0x00000020u; -} -inline void FieldOptions::clear_has_weak() { - _has_bits_[0] &= ~0x00000020u; -} -inline void FieldOptions::clear_weak() { - weak_ = false; - clear_has_weak(); -} -inline bool FieldOptions::weak() const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.weak) - return weak_; -} -inline void FieldOptions::set_weak(bool value) { - set_has_weak(); - weak_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.weak) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int FieldOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void FieldOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& FieldOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* FieldOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* FieldOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.FieldOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -FieldOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -FieldOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.FieldOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const FieldOptions* FieldOptions::internal_default_instance() { - return &FieldOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// OneofOptions - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int OneofOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void OneofOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& OneofOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.OneofOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* OneofOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.OneofOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* OneofOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.OneofOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -OneofOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.OneofOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -OneofOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.OneofOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const OneofOptions* OneofOptions::internal_default_instance() { - return &OneofOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// EnumOptions - -// optional bool allow_alias = 2; -inline bool EnumOptions::has_allow_alias() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumOptions::set_has_allow_alias() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumOptions::clear_has_allow_alias() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumOptions::clear_allow_alias() { - allow_alias_ = false; - clear_has_allow_alias(); -} -inline bool EnumOptions::allow_alias() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumOptions.allow_alias) - return allow_alias_; -} -inline void EnumOptions::set_allow_alias(bool value) { - set_has_allow_alias(); - allow_alias_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.EnumOptions.allow_alias) -} - -// optional bool deprecated = 3 [default = false]; -inline bool EnumOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void EnumOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000002u; -} -inline void EnumOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000002u; -} -inline void EnumOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool EnumOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumOptions.deprecated) - return deprecated_; -} -inline void EnumOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.EnumOptions.deprecated) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int EnumOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void EnumOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& EnumOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* EnumOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* EnumOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.EnumOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -EnumOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.EnumOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -EnumOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.EnumOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const EnumOptions* EnumOptions::internal_default_instance() { - return &EnumOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// EnumValueOptions - -// optional bool deprecated = 1 [default = false]; -inline bool EnumValueOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void EnumValueOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000001u; -} -inline void EnumValueOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000001u; -} -inline void EnumValueOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool EnumValueOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumValueOptions.deprecated) - return deprecated_; -} -inline void EnumValueOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.EnumValueOptions.deprecated) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int EnumValueOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void EnumValueOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& EnumValueOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.EnumValueOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* EnumValueOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.EnumValueOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* EnumValueOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.EnumValueOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -EnumValueOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.EnumValueOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -EnumValueOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.EnumValueOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const EnumValueOptions* EnumValueOptions::internal_default_instance() { - return &EnumValueOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// ServiceOptions - -// optional bool deprecated = 33 [default = false]; -inline bool ServiceOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void ServiceOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000001u; -} -inline void ServiceOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000001u; -} -inline void ServiceOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool ServiceOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.ServiceOptions.deprecated) - return deprecated_; -} -inline void ServiceOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.ServiceOptions.deprecated) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int ServiceOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void ServiceOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& ServiceOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.ServiceOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* ServiceOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.ServiceOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* ServiceOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.ServiceOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -ServiceOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.ServiceOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -ServiceOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.ServiceOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const ServiceOptions* ServiceOptions::internal_default_instance() { - return &ServiceOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// MethodOptions - -// optional bool deprecated = 33 [default = false]; -inline bool MethodOptions::has_deprecated() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void MethodOptions::set_has_deprecated() { - _has_bits_[0] |= 0x00000001u; -} -inline void MethodOptions::clear_has_deprecated() { - _has_bits_[0] &= ~0x00000001u; -} -inline void MethodOptions::clear_deprecated() { - deprecated_ = false; - clear_has_deprecated(); -} -inline bool MethodOptions::deprecated() const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.deprecated) - return deprecated_; -} -inline void MethodOptions::set_deprecated(bool value) { - set_has_deprecated(); - deprecated_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.deprecated) -} - -// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; -inline int MethodOptions::uninterpreted_option_size() const { - return uninterpreted_option_.size(); -} -inline void MethodOptions::clear_uninterpreted_option() { - uninterpreted_option_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption& MethodOptions::uninterpreted_option(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.uninterpreted_option) - return uninterpreted_option_.Get(index); -} -inline ::google::protobuf::UninterpretedOption* MethodOptions::mutable_uninterpreted_option(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.MethodOptions.uninterpreted_option) - return uninterpreted_option_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption* MethodOptions::add_uninterpreted_option() { - // @@protoc_insertion_point(field_add:google.protobuf.MethodOptions.uninterpreted_option) - return uninterpreted_option_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* -MethodOptions::mutable_uninterpreted_option() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.MethodOptions.uninterpreted_option) - return &uninterpreted_option_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& -MethodOptions::uninterpreted_option() const { - // @@protoc_insertion_point(field_list:google.protobuf.MethodOptions.uninterpreted_option) - return uninterpreted_option_; -} - -inline const MethodOptions* MethodOptions::internal_default_instance() { - return &MethodOptions_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// UninterpretedOption_NamePart - -// required string name_part = 1; -inline bool UninterpretedOption_NamePart::has_name_part() const { - return (_has_bits_[0] & 0x00000001u) != 0; -} -inline void UninterpretedOption_NamePart::set_has_name_part() { - _has_bits_[0] |= 0x00000001u; -} -inline void UninterpretedOption_NamePart::clear_has_name_part() { - _has_bits_[0] &= ~0x00000001u; -} -inline void UninterpretedOption_NamePart::clear_name_part() { - name_part_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_name_part(); -} -inline const ::std::string& UninterpretedOption_NamePart::name_part() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.NamePart.name_part) - return name_part_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption_NamePart::set_name_part(const ::std::string& value) { - set_has_name_part(); - name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.name_part) -} -inline void UninterpretedOption_NamePart::set_name_part(const char* value) { - set_has_name_part(); - name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.NamePart.name_part) -} -inline void UninterpretedOption_NamePart::set_name_part(const char* value, size_t size) { - set_has_name_part(); - name_part_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.NamePart.name_part) -} -inline ::std::string* UninterpretedOption_NamePart::mutable_name_part() { - set_has_name_part(); - // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.NamePart.name_part) - return name_part_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* UninterpretedOption_NamePart::release_name_part() { - // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.NamePart.name_part) - clear_has_name_part(); - return name_part_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption_NamePart::set_allocated_name_part(::std::string* name_part) { - if (name_part != NULL) { - set_has_name_part(); - } else { - clear_has_name_part(); - } - name_part_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), name_part); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.NamePart.name_part) -} - -// required bool is_extension = 2; -inline bool UninterpretedOption_NamePart::has_is_extension() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void UninterpretedOption_NamePart::set_has_is_extension() { - _has_bits_[0] |= 0x00000002u; -} -inline void UninterpretedOption_NamePart::clear_has_is_extension() { - _has_bits_[0] &= ~0x00000002u; -} -inline void UninterpretedOption_NamePart::clear_is_extension() { - is_extension_ = false; - clear_has_is_extension(); -} -inline bool UninterpretedOption_NamePart::is_extension() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.NamePart.is_extension) - return is_extension_; -} -inline void UninterpretedOption_NamePart::set_is_extension(bool value) { - set_has_is_extension(); - is_extension_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.NamePart.is_extension) -} - -inline const UninterpretedOption_NamePart* UninterpretedOption_NamePart::internal_default_instance() { - return &UninterpretedOption_NamePart_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// UninterpretedOption - -// repeated .google.protobuf.UninterpretedOption.NamePart name = 2; -inline int UninterpretedOption::name_size() const { - return name_.size(); -} -inline void UninterpretedOption::clear_name() { - name_.Clear(); -} -inline const ::google::protobuf::UninterpretedOption_NamePart& UninterpretedOption::name(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.name) - return name_.Get(index); -} -inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::mutable_name(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.name) - return name_.Mutable(index); -} -inline ::google::protobuf::UninterpretedOption_NamePart* UninterpretedOption::add_name() { - // @@protoc_insertion_point(field_add:google.protobuf.UninterpretedOption.name) - return name_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >* -UninterpretedOption::mutable_name() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.UninterpretedOption.name) - return &name_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption_NamePart >& -UninterpretedOption::name() const { - // @@protoc_insertion_point(field_list:google.protobuf.UninterpretedOption.name) - return name_; -} - -// optional string identifier_value = 3; -inline bool UninterpretedOption::has_identifier_value() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void UninterpretedOption::set_has_identifier_value() { - _has_bits_[0] |= 0x00000002u; -} -inline void UninterpretedOption::clear_has_identifier_value() { - _has_bits_[0] &= ~0x00000002u; -} -inline void UninterpretedOption::clear_identifier_value() { - identifier_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_identifier_value(); -} -inline const ::std::string& UninterpretedOption::identifier_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.identifier_value) - return identifier_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_identifier_value(const ::std::string& value) { - set_has_identifier_value(); - identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.identifier_value) -} -inline void UninterpretedOption::set_identifier_value(const char* value) { - set_has_identifier_value(); - identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.identifier_value) -} -inline void UninterpretedOption::set_identifier_value(const char* value, size_t size) { - set_has_identifier_value(); - identifier_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.identifier_value) -} -inline ::std::string* UninterpretedOption::mutable_identifier_value() { - set_has_identifier_value(); - // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.identifier_value) - return identifier_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* UninterpretedOption::release_identifier_value() { - // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.identifier_value) - clear_has_identifier_value(); - return identifier_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_allocated_identifier_value(::std::string* identifier_value) { - if (identifier_value != NULL) { - set_has_identifier_value(); - } else { - clear_has_identifier_value(); - } - identifier_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), identifier_value); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.identifier_value) -} - -// optional uint64 positive_int_value = 4; -inline bool UninterpretedOption::has_positive_int_value() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void UninterpretedOption::set_has_positive_int_value() { - _has_bits_[0] |= 0x00000004u; -} -inline void UninterpretedOption::clear_has_positive_int_value() { - _has_bits_[0] &= ~0x00000004u; -} -inline void UninterpretedOption::clear_positive_int_value() { - positive_int_value_ = GOOGLE_ULONGLONG(0); - clear_has_positive_int_value(); -} -inline ::google::protobuf::uint64 UninterpretedOption::positive_int_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.positive_int_value) - return positive_int_value_; -} -inline void UninterpretedOption::set_positive_int_value(::google::protobuf::uint64 value) { - set_has_positive_int_value(); - positive_int_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.positive_int_value) -} - -// optional int64 negative_int_value = 5; -inline bool UninterpretedOption::has_negative_int_value() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void UninterpretedOption::set_has_negative_int_value() { - _has_bits_[0] |= 0x00000008u; -} -inline void UninterpretedOption::clear_has_negative_int_value() { - _has_bits_[0] &= ~0x00000008u; -} -inline void UninterpretedOption::clear_negative_int_value() { - negative_int_value_ = GOOGLE_LONGLONG(0); - clear_has_negative_int_value(); -} -inline ::google::protobuf::int64 UninterpretedOption::negative_int_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.negative_int_value) - return negative_int_value_; -} -inline void UninterpretedOption::set_negative_int_value(::google::protobuf::int64 value) { - set_has_negative_int_value(); - negative_int_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.negative_int_value) -} - -// optional double double_value = 6; -inline bool UninterpretedOption::has_double_value() const { - return (_has_bits_[0] & 0x00000010u) != 0; -} -inline void UninterpretedOption::set_has_double_value() { - _has_bits_[0] |= 0x00000010u; -} -inline void UninterpretedOption::clear_has_double_value() { - _has_bits_[0] &= ~0x00000010u; -} -inline void UninterpretedOption::clear_double_value() { - double_value_ = 0; - clear_has_double_value(); -} -inline double UninterpretedOption::double_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.double_value) - return double_value_; -} -inline void UninterpretedOption::set_double_value(double value) { - set_has_double_value(); - double_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.double_value) -} - -// optional bytes string_value = 7; -inline bool UninterpretedOption::has_string_value() const { - return (_has_bits_[0] & 0x00000020u) != 0; -} -inline void UninterpretedOption::set_has_string_value() { - _has_bits_[0] |= 0x00000020u; -} -inline void UninterpretedOption::clear_has_string_value() { - _has_bits_[0] &= ~0x00000020u; -} -inline void UninterpretedOption::clear_string_value() { - string_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_string_value(); -} -inline const ::std::string& UninterpretedOption::string_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.string_value) - return string_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_string_value(const ::std::string& value) { - set_has_string_value(); - string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.string_value) -} -inline void UninterpretedOption::set_string_value(const char* value) { - set_has_string_value(); - string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.string_value) -} -inline void UninterpretedOption::set_string_value(const void* value, size_t size) { - set_has_string_value(); - string_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.string_value) -} -inline ::std::string* UninterpretedOption::mutable_string_value() { - set_has_string_value(); - // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.string_value) - return string_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* UninterpretedOption::release_string_value() { - // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.string_value) - clear_has_string_value(); - return string_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_allocated_string_value(::std::string* string_value) { - if (string_value != NULL) { - set_has_string_value(); - } else { - clear_has_string_value(); - } - string_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.string_value) -} - -// optional string aggregate_value = 8; -inline bool UninterpretedOption::has_aggregate_value() const { - return (_has_bits_[0] & 0x00000040u) != 0; -} -inline void UninterpretedOption::set_has_aggregate_value() { - _has_bits_[0] |= 0x00000040u; -} -inline void UninterpretedOption::clear_has_aggregate_value() { - _has_bits_[0] &= ~0x00000040u; -} -inline void UninterpretedOption::clear_aggregate_value() { - aggregate_value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_aggregate_value(); -} -inline const ::std::string& UninterpretedOption::aggregate_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.UninterpretedOption.aggregate_value) - return aggregate_value_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_aggregate_value(const ::std::string& value) { - set_has_aggregate_value(); - aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.UninterpretedOption.aggregate_value) -} -inline void UninterpretedOption::set_aggregate_value(const char* value) { - set_has_aggregate_value(); - aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.UninterpretedOption.aggregate_value) -} -inline void UninterpretedOption::set_aggregate_value(const char* value, size_t size) { - set_has_aggregate_value(); - aggregate_value_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.UninterpretedOption.aggregate_value) -} -inline ::std::string* UninterpretedOption::mutable_aggregate_value() { - set_has_aggregate_value(); - // @@protoc_insertion_point(field_mutable:google.protobuf.UninterpretedOption.aggregate_value) - return aggregate_value_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* UninterpretedOption::release_aggregate_value() { - // @@protoc_insertion_point(field_release:google.protobuf.UninterpretedOption.aggregate_value) - clear_has_aggregate_value(); - return aggregate_value_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void UninterpretedOption::set_allocated_aggregate_value(::std::string* aggregate_value) { - if (aggregate_value != NULL) { - set_has_aggregate_value(); - } else { - clear_has_aggregate_value(); - } - aggregate_value_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), aggregate_value); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.UninterpretedOption.aggregate_value) -} - -inline const UninterpretedOption* UninterpretedOption::internal_default_instance() { - return &UninterpretedOption_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// SourceCodeInfo_Location - -// repeated int32 path = 1 [packed = true]; -inline int SourceCodeInfo_Location::path_size() const { - return path_.size(); -} -inline void SourceCodeInfo_Location::clear_path() { - path_.Clear(); -} -inline ::google::protobuf::int32 SourceCodeInfo_Location::path(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.path) - return path_.Get(index); -} -inline void SourceCodeInfo_Location::set_path(int index, ::google::protobuf::int32 value) { - path_.Set(index, value); - // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.path) -} -inline void SourceCodeInfo_Location::add_path(::google::protobuf::int32 value) { - path_.Add(value); - // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.path) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -SourceCodeInfo_Location::path() const { - // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.path) - return path_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -SourceCodeInfo_Location::mutable_path() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.path) - return &path_; -} - -// repeated int32 span = 2 [packed = true]; -inline int SourceCodeInfo_Location::span_size() const { - return span_.size(); -} -inline void SourceCodeInfo_Location::clear_span() { - span_.Clear(); -} -inline ::google::protobuf::int32 SourceCodeInfo_Location::span(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.span) - return span_.Get(index); -} -inline void SourceCodeInfo_Location::set_span(int index, ::google::protobuf::int32 value) { - span_.Set(index, value); - // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.span) -} -inline void SourceCodeInfo_Location::add_span(::google::protobuf::int32 value) { - span_.Add(value); - // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.span) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -SourceCodeInfo_Location::span() const { - // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.span) - return span_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -SourceCodeInfo_Location::mutable_span() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.span) - return &span_; -} - -// optional string leading_comments = 3; -inline bool SourceCodeInfo_Location::has_leading_comments() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void SourceCodeInfo_Location::set_has_leading_comments() { - _has_bits_[0] |= 0x00000004u; -} -inline void SourceCodeInfo_Location::clear_has_leading_comments() { - _has_bits_[0] &= ~0x00000004u; -} -inline void SourceCodeInfo_Location::clear_leading_comments() { - leading_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_leading_comments(); -} -inline const ::std::string& SourceCodeInfo_Location::leading_comments() const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.leading_comments) - return leading_comments_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceCodeInfo_Location::set_leading_comments(const ::std::string& value) { - set_has_leading_comments(); - leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_comments) -} -inline void SourceCodeInfo_Location::set_leading_comments(const char* value) { - set_has_leading_comments(); - leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_comments) -} -inline void SourceCodeInfo_Location::set_leading_comments(const char* value, size_t size) { - set_has_leading_comments(); - leading_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_comments) -} -inline ::std::string* SourceCodeInfo_Location::mutable_leading_comments() { - set_has_leading_comments(); - // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.leading_comments) - return leading_comments_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* SourceCodeInfo_Location::release_leading_comments() { - // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.leading_comments) - clear_has_leading_comments(); - return leading_comments_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceCodeInfo_Location::set_allocated_leading_comments(::std::string* leading_comments) { - if (leading_comments != NULL) { - set_has_leading_comments(); - } else { - clear_has_leading_comments(); - } - leading_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), leading_comments); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.leading_comments) -} - -// optional string trailing_comments = 4; -inline bool SourceCodeInfo_Location::has_trailing_comments() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void SourceCodeInfo_Location::set_has_trailing_comments() { - _has_bits_[0] |= 0x00000008u; -} -inline void SourceCodeInfo_Location::clear_has_trailing_comments() { - _has_bits_[0] &= ~0x00000008u; -} -inline void SourceCodeInfo_Location::clear_trailing_comments() { - trailing_comments_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_trailing_comments(); -} -inline const ::std::string& SourceCodeInfo_Location::trailing_comments() const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.trailing_comments) - return trailing_comments_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceCodeInfo_Location::set_trailing_comments(const ::std::string& value) { - set_has_trailing_comments(); - trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.trailing_comments) -} -inline void SourceCodeInfo_Location::set_trailing_comments(const char* value) { - set_has_trailing_comments(); - trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.trailing_comments) -} -inline void SourceCodeInfo_Location::set_trailing_comments(const char* value, size_t size) { - set_has_trailing_comments(); - trailing_comments_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.trailing_comments) -} -inline ::std::string* SourceCodeInfo_Location::mutable_trailing_comments() { - set_has_trailing_comments(); - // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.trailing_comments) - return trailing_comments_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* SourceCodeInfo_Location::release_trailing_comments() { - // @@protoc_insertion_point(field_release:google.protobuf.SourceCodeInfo.Location.trailing_comments) - clear_has_trailing_comments(); - return trailing_comments_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceCodeInfo_Location::set_allocated_trailing_comments(::std::string* trailing_comments) { - if (trailing_comments != NULL) { - set_has_trailing_comments(); - } else { - clear_has_trailing_comments(); - } - trailing_comments_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), trailing_comments); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceCodeInfo.Location.trailing_comments) -} - -// repeated string leading_detached_comments = 6; -inline int SourceCodeInfo_Location::leading_detached_comments_size() const { - return leading_detached_comments_.size(); -} -inline void SourceCodeInfo_Location::clear_leading_detached_comments() { - leading_detached_comments_.Clear(); -} -inline const ::std::string& SourceCodeInfo_Location::leading_detached_comments(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - return leading_detached_comments_.Get(index); -} -inline ::std::string* SourceCodeInfo_Location::mutable_leading_detached_comments(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - return leading_detached_comments_.Mutable(index); -} -inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - leading_detached_comments_.Mutable(index)->assign(value); -} -inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value) { - leading_detached_comments_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) -} -inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, size_t size) { - leading_detached_comments_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) -} -inline ::std::string* SourceCodeInfo_Location::add_leading_detached_comments() { - // @@protoc_insertion_point(field_add_mutable:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - return leading_detached_comments_.Add(); -} -inline void SourceCodeInfo_Location::add_leading_detached_comments(const ::std::string& value) { - leading_detached_comments_.Add()->assign(value); - // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) -} -inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value) { - leading_detached_comments_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) -} -inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, size_t size) { - leading_detached_comments_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -SourceCodeInfo_Location::leading_detached_comments() const { - // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - return leading_detached_comments_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -SourceCodeInfo_Location::mutable_leading_detached_comments() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.Location.leading_detached_comments) - return &leading_detached_comments_; -} - -inline const SourceCodeInfo_Location* SourceCodeInfo_Location::internal_default_instance() { - return &SourceCodeInfo_Location_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// SourceCodeInfo - -// repeated .google.protobuf.SourceCodeInfo.Location location = 1; -inline int SourceCodeInfo::location_size() const { - return location_.size(); -} -inline void SourceCodeInfo::clear_location() { - location_.Clear(); -} -inline const ::google::protobuf::SourceCodeInfo_Location& SourceCodeInfo::location(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceCodeInfo.location) - return location_.Get(index); -} -inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::mutable_location(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.SourceCodeInfo.location) - return location_.Mutable(index); -} -inline ::google::protobuf::SourceCodeInfo_Location* SourceCodeInfo::add_location() { - // @@protoc_insertion_point(field_add:google.protobuf.SourceCodeInfo.location) - return location_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >* -SourceCodeInfo::mutable_location() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.SourceCodeInfo.location) - return &location_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::SourceCodeInfo_Location >& -SourceCodeInfo::location() const { - // @@protoc_insertion_point(field_list:google.protobuf.SourceCodeInfo.location) - return location_; -} - -inline const SourceCodeInfo* SourceCodeInfo::internal_default_instance() { - return &SourceCodeInfo_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// GeneratedCodeInfo_Annotation - -// repeated int32 path = 1 [packed = true]; -inline int GeneratedCodeInfo_Annotation::path_size() const { - return path_.size(); -} -inline void GeneratedCodeInfo_Annotation::clear_path() { - path_.Clear(); -} -inline ::google::protobuf::int32 GeneratedCodeInfo_Annotation::path(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.path) - return path_.Get(index); -} -inline void GeneratedCodeInfo_Annotation::set_path(int index, ::google::protobuf::int32 value) { - path_.Set(index, value); - // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.path) -} -inline void GeneratedCodeInfo_Annotation::add_path(::google::protobuf::int32 value) { - path_.Add(value); - // @@protoc_insertion_point(field_add:google.protobuf.GeneratedCodeInfo.Annotation.path) -} -inline const ::google::protobuf::RepeatedField< ::google::protobuf::int32 >& -GeneratedCodeInfo_Annotation::path() const { - // @@protoc_insertion_point(field_list:google.protobuf.GeneratedCodeInfo.Annotation.path) - return path_; -} -inline ::google::protobuf::RepeatedField< ::google::protobuf::int32 >* -GeneratedCodeInfo_Annotation::mutable_path() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.GeneratedCodeInfo.Annotation.path) - return &path_; -} - -// optional string source_file = 2; -inline bool GeneratedCodeInfo_Annotation::has_source_file() const { - return (_has_bits_[0] & 0x00000002u) != 0; -} -inline void GeneratedCodeInfo_Annotation::set_has_source_file() { - _has_bits_[0] |= 0x00000002u; -} -inline void GeneratedCodeInfo_Annotation::clear_has_source_file() { - _has_bits_[0] &= ~0x00000002u; -} -inline void GeneratedCodeInfo_Annotation::clear_source_file() { - source_file_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - clear_has_source_file(); -} -inline const ::std::string& GeneratedCodeInfo_Annotation::source_file() const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.source_file) - return source_file_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void GeneratedCodeInfo_Annotation::set_source_file(const ::std::string& value) { - set_has_source_file(); - source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.source_file) -} -inline void GeneratedCodeInfo_Annotation::set_source_file(const char* value) { - set_has_source_file(); - source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.GeneratedCodeInfo.Annotation.source_file) -} -inline void GeneratedCodeInfo_Annotation::set_source_file(const char* value, size_t size) { - set_has_source_file(); - source_file_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.GeneratedCodeInfo.Annotation.source_file) -} -inline ::std::string* GeneratedCodeInfo_Annotation::mutable_source_file() { - set_has_source_file(); - // @@protoc_insertion_point(field_mutable:google.protobuf.GeneratedCodeInfo.Annotation.source_file) - return source_file_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* GeneratedCodeInfo_Annotation::release_source_file() { - // @@protoc_insertion_point(field_release:google.protobuf.GeneratedCodeInfo.Annotation.source_file) - clear_has_source_file(); - return source_file_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void GeneratedCodeInfo_Annotation::set_allocated_source_file(::std::string* source_file) { - if (source_file != NULL) { - set_has_source_file(); - } else { - clear_has_source_file(); - } - source_file_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), source_file); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.GeneratedCodeInfo.Annotation.source_file) -} - -// optional int32 begin = 3; -inline bool GeneratedCodeInfo_Annotation::has_begin() const { - return (_has_bits_[0] & 0x00000004u) != 0; -} -inline void GeneratedCodeInfo_Annotation::set_has_begin() { - _has_bits_[0] |= 0x00000004u; -} -inline void GeneratedCodeInfo_Annotation::clear_has_begin() { - _has_bits_[0] &= ~0x00000004u; -} -inline void GeneratedCodeInfo_Annotation::clear_begin() { - begin_ = 0; - clear_has_begin(); -} -inline ::google::protobuf::int32 GeneratedCodeInfo_Annotation::begin() const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.begin) - return begin_; -} -inline void GeneratedCodeInfo_Annotation::set_begin(::google::protobuf::int32 value) { - set_has_begin(); - begin_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.begin) -} - -// optional int32 end = 4; -inline bool GeneratedCodeInfo_Annotation::has_end() const { - return (_has_bits_[0] & 0x00000008u) != 0; -} -inline void GeneratedCodeInfo_Annotation::set_has_end() { - _has_bits_[0] |= 0x00000008u; -} -inline void GeneratedCodeInfo_Annotation::clear_has_end() { - _has_bits_[0] &= ~0x00000008u; -} -inline void GeneratedCodeInfo_Annotation::clear_end() { - end_ = 0; - clear_has_end(); -} -inline ::google::protobuf::int32 GeneratedCodeInfo_Annotation::end() const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.end) - return end_; -} -inline void GeneratedCodeInfo_Annotation::set_end(::google::protobuf::int32 value) { - set_has_end(); - end_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.end) -} - -inline const GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::internal_default_instance() { - return &GeneratedCodeInfo_Annotation_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// GeneratedCodeInfo - -// repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; -inline int GeneratedCodeInfo::annotation_size() const { - return annotation_.size(); -} -inline void GeneratedCodeInfo::clear_annotation() { - annotation_.Clear(); -} -inline const ::google::protobuf::GeneratedCodeInfo_Annotation& GeneratedCodeInfo::annotation(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.annotation) - return annotation_.Get(index); -} -inline ::google::protobuf::GeneratedCodeInfo_Annotation* GeneratedCodeInfo::mutable_annotation(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.GeneratedCodeInfo.annotation) - return annotation_.Mutable(index); -} -inline ::google::protobuf::GeneratedCodeInfo_Annotation* GeneratedCodeInfo::add_annotation() { - // @@protoc_insertion_point(field_add:google.protobuf.GeneratedCodeInfo.annotation) - return annotation_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation >* -GeneratedCodeInfo::mutable_annotation() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.GeneratedCodeInfo.annotation) - return &annotation_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::GeneratedCodeInfo_Annotation >& -GeneratedCodeInfo::annotation() const { - // @@protoc_insertion_point(field_list:google.protobuf.GeneratedCodeInfo.annotation) - return annotation_; -} - -inline const GeneratedCodeInfo* GeneratedCodeInfo::internal_default_instance() { - return &GeneratedCodeInfo_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> struct is_proto_enum< ::google::protobuf::FieldDescriptorProto_Type> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Type>() { - return ::google::protobuf::FieldDescriptorProto_Type_descriptor(); -} -template <> struct is_proto_enum< ::google::protobuf::FieldDescriptorProto_Label> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldDescriptorProto_Label>() { - return ::google::protobuf::FieldDescriptorProto_Label_descriptor(); -} -template <> struct is_proto_enum< ::google::protobuf::FileOptions_OptimizeMode> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FileOptions_OptimizeMode>() { - return ::google::protobuf::FileOptions_OptimizeMode_descriptor(); -} -template <> struct is_proto_enum< ::google::protobuf::FieldOptions_CType> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldOptions_CType>() { - return ::google::protobuf::FieldOptions_CType_descriptor(); -} -template <> struct is_proto_enum< ::google::protobuf::FieldOptions_JSType> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::FieldOptions_JSType>() { - return ::google::protobuf::FieldOptions_JSType_descriptor(); -} - -} // namespace protobuf -} // namespace google -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fdescriptor_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/descriptor.proto b/app/src/main/cpp/google/protobuf/descriptor.proto deleted file mode 100644 index 558ae23..0000000 --- a/app/src/main/cpp/google/protobuf/descriptor.proto +++ /dev/null @@ -1,804 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// The messages in this file describe the definitions found in .proto files. -// A valid .proto file can be translated directly to a FileDescriptorProto -// without any other information (e.g. without reading its imports). - - -syntax = "proto2"; - -package google.protobuf; -option go_package = "descriptor"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "DescriptorProtos"; -option csharp_namespace = "Google.Protobuf.Reflection"; -option objc_class_prefix = "GPB"; - -// descriptor.proto must be optimized for speed because reflection-based -// algorithms don't work during bootstrapping. -option optimize_for = SPEED; - -// The protocol compiler can output a FileDescriptorSet containing the .proto -// files it parses. -message FileDescriptorSet { - repeated FileDescriptorProto file = 1; -} - -// Describes a complete .proto file. -message FileDescriptorProto { - optional string name = 1; // file name, relative to root of source tree - optional string package = 2; // e.g. "foo", "foo.bar", etc. - - // Names of files imported by this file. - repeated string dependency = 3; - // Indexes of the public imported files in the dependency list above. - repeated int32 public_dependency = 10; - // Indexes of the weak imported files in the dependency list. - // For Google-internal migration only. Do not use. - repeated int32 weak_dependency = 11; - - // All top-level definitions in this file. - repeated DescriptorProto message_type = 4; - repeated EnumDescriptorProto enum_type = 5; - repeated ServiceDescriptorProto service = 6; - repeated FieldDescriptorProto extension = 7; - - optional FileOptions options = 8; - - // This field contains optional information about the original source code. - // You may safely remove this entire field without harming runtime - // functionality of the descriptors -- the information is needed only by - // development tools. - optional SourceCodeInfo source_code_info = 9; - - // The syntax of the proto file. - // The supported values are "proto2" and "proto3". - optional string syntax = 12; -} - -// Describes a message type. -message DescriptorProto { - optional string name = 1; - - repeated FieldDescriptorProto field = 2; - repeated FieldDescriptorProto extension = 6; - - repeated DescriptorProto nested_type = 3; - repeated EnumDescriptorProto enum_type = 4; - - message ExtensionRange { - optional int32 start = 1; - optional int32 end = 2; - } - repeated ExtensionRange extension_range = 5; - - repeated OneofDescriptorProto oneof_decl = 8; - - optional MessageOptions options = 7; - - // Range of reserved tag numbers. Reserved tag numbers may not be used by - // fields or extension ranges in the same message. Reserved ranges may - // not overlap. - message ReservedRange { - optional int32 start = 1; // Inclusive. - optional int32 end = 2; // Exclusive. - } - repeated ReservedRange reserved_range = 9; - // Reserved field names, which may not be used by fields in the same message. - // A given name may only be reserved once. - repeated string reserved_name = 10; -} - -// Describes a field within a message. -message FieldDescriptorProto { - enum Type { - // 0 is reserved for errors. - // Order is weird for historical reasons. - TYPE_DOUBLE = 1; - TYPE_FLOAT = 2; - // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if - // negative values are likely. - TYPE_INT64 = 3; - TYPE_UINT64 = 4; - // Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if - // negative values are likely. - TYPE_INT32 = 5; - TYPE_FIXED64 = 6; - TYPE_FIXED32 = 7; - TYPE_BOOL = 8; - TYPE_STRING = 9; - TYPE_GROUP = 10; // Tag-delimited aggregate. - TYPE_MESSAGE = 11; // Length-delimited aggregate. - - // New in version 2. - TYPE_BYTES = 12; - TYPE_UINT32 = 13; - TYPE_ENUM = 14; - TYPE_SFIXED32 = 15; - TYPE_SFIXED64 = 16; - TYPE_SINT32 = 17; // Uses ZigZag encoding. - TYPE_SINT64 = 18; // Uses ZigZag encoding. - }; - - enum Label { - // 0 is reserved for errors - LABEL_OPTIONAL = 1; - LABEL_REQUIRED = 2; - LABEL_REPEATED = 3; - // TODO(sanjay): Should we add LABEL_MAP? - }; - - optional string name = 1; - optional int32 number = 3; - optional Label label = 4; - - // If type_name is set, this need not be set. If both this and type_name - // are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP. - optional Type type = 5; - - // For message and enum types, this is the name of the type. If the name - // starts with a '.', it is fully-qualified. Otherwise, C++-like scoping - // rules are used to find the type (i.e. first the nested types within this - // message are searched, then within the parent, on up to the root - // namespace). - optional string type_name = 6; - - // For extensions, this is the name of the type being extended. It is - // resolved in the same manner as type_name. - optional string extendee = 2; - - // For numeric types, contains the original text representation of the value. - // For booleans, "true" or "false". - // For strings, contains the default text contents (not escaped in any way). - // For bytes, contains the C escaped value. All bytes >= 128 are escaped. - // TODO(kenton): Base-64 encode? - optional string default_value = 7; - - // If set, gives the index of a oneof in the containing type's oneof_decl - // list. This field is a member of that oneof. - optional int32 oneof_index = 9; - - // JSON name of this field. The value is set by protocol compiler. If the - // user has set a "json_name" option on this field, that option's value - // will be used. Otherwise, it's deduced from the field's name by converting - // it to camelCase. - optional string json_name = 10; - - optional FieldOptions options = 8; -} - -// Describes a oneof. -message OneofDescriptorProto { - optional string name = 1; - optional OneofOptions options = 2; -} - -// Describes an enum type. -message EnumDescriptorProto { - optional string name = 1; - - repeated EnumValueDescriptorProto value = 2; - - optional EnumOptions options = 3; -} - -// Describes a value within an enum. -message EnumValueDescriptorProto { - optional string name = 1; - optional int32 number = 2; - - optional EnumValueOptions options = 3; -} - -// Describes a service. -message ServiceDescriptorProto { - optional string name = 1; - repeated MethodDescriptorProto method = 2; - - optional ServiceOptions options = 3; -} - -// Describes a method of a service. -message MethodDescriptorProto { - optional string name = 1; - - // Input and output type names. These are resolved in the same way as - // FieldDescriptorProto.type_name, but must refer to a message type. - optional string input_type = 2; - optional string output_type = 3; - - optional MethodOptions options = 4; - - // Identifies if client streams multiple client messages - optional bool client_streaming = 5 [default=false]; - // Identifies if server streams multiple server messages - optional bool server_streaming = 6 [default=false]; -} - - -// =================================================================== -// Options - -// Each of the definitions above may have "options" attached. These are -// just annotations which may cause code to be generated slightly differently -// or may contain hints for code that manipulates protocol messages. -// -// Clients may define custom options as extensions of the *Options messages. -// These extensions may not yet be known at parsing time, so the parser cannot -// store the values in them. Instead it stores them in a field in the *Options -// message called uninterpreted_option. This field must have the same name -// across all *Options messages. We then use this field to populate the -// extensions when we build a descriptor, at which point all protos have been -// parsed and so all extensions are known. -// -// Extension numbers for custom options may be chosen as follows: -// * For options which will only be used within a single application or -// organization, or for experimental options, use field numbers 50000 -// through 99999. It is up to you to ensure that you do not use the -// same number for multiple options. -// * For options which will be published and used publicly by multiple -// independent entities, e-mail protobuf-global-extension-registry@google.com -// to reserve extension numbers. Simply provide your project name (e.g. -// Objective-C plugin) and your project website (if available) -- there's no -// need to explain how you intend to use them. Usually you only need one -// extension number. You can declare multiple options with only one extension -// number by putting them in a sub-message. See the Custom Options section of -// the docs for examples: -// https://developers.google.com/protocol-buffers/docs/proto#options -// If this turns out to be popular, a web service will be set up -// to automatically assign option numbers. - - -message FileOptions { - - // Sets the Java package where classes generated from this .proto will be - // placed. By default, the proto package is used, but this is often - // inappropriate because proto packages do not normally start with backwards - // domain names. - optional string java_package = 1; - - - // If set, all the classes from the .proto file are wrapped in a single - // outer class with the given name. This applies to both Proto1 - // (equivalent to the old "--one_java_file" option) and Proto2 (where - // a .proto always translates to a single class, but you may want to - // explicitly choose the class name). - optional string java_outer_classname = 8; - - // If set true, then the Java code generator will generate a separate .java - // file for each top-level message, enum, and service defined in the .proto - // file. Thus, these types will *not* be nested inside the outer class - // named by java_outer_classname. However, the outer class will still be - // generated to contain the file's getDescriptor() method as well as any - // top-level extensions defined in the file. - optional bool java_multiple_files = 10 [default=false]; - - // This option does nothing. - optional bool java_generate_equals_and_hash = 20 [deprecated=true]; - - // If set true, then the Java2 code generator will generate code that - // throws an exception whenever an attempt is made to assign a non-UTF-8 - // byte sequence to a string field. - // Message reflection will do the same. - // However, an extension field still accepts non-UTF-8 byte sequences. - // This option has no effect on when used with the lite runtime. - optional bool java_string_check_utf8 = 27 [default=false]; - - - // Generated classes can be optimized for speed or code size. - enum OptimizeMode { - SPEED = 1; // Generate complete code for parsing, serialization, - // etc. - CODE_SIZE = 2; // Use ReflectionOps to implement these methods. - LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime. - } - optional OptimizeMode optimize_for = 9 [default=SPEED]; - - // Sets the Go package where structs generated from this .proto will be - // placed. If omitted, the Go package will be derived from the following: - // - The basename of the package import path, if provided. - // - Otherwise, the package statement in the .proto file, if present. - // - Otherwise, the basename of the .proto file, without extension. - optional string go_package = 11; - - - - // Should generic services be generated in each language? "Generic" services - // are not specific to any particular RPC system. They are generated by the - // main code generators in each language (without additional plugins). - // Generic services were the only kind of service generation supported by - // early versions of google.protobuf. - // - // Generic services are now considered deprecated in favor of using plugins - // that generate code specific to your particular RPC system. Therefore, - // these default to false. Old code which depends on generic services should - // explicitly set them to true. - optional bool cc_generic_services = 16 [default=false]; - optional bool java_generic_services = 17 [default=false]; - optional bool py_generic_services = 18 [default=false]; - - // Is this file deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for everything in the file, or it will be completely ignored; in the very - // least, this is a formalization for deprecating files. - optional bool deprecated = 23 [default=false]; - - // Enables the use of arenas for the proto messages in this file. This applies - // only to generated classes for C++. - optional bool cc_enable_arenas = 31 [default=false]; - - - // Sets the objective c class prefix which is prepended to all objective c - // generated classes from this .proto. There is no default. - optional string objc_class_prefix = 36; - - // Namespace for generated classes; defaults to the package. - optional string csharp_namespace = 37; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; - - reserved 38; -} - -message MessageOptions { - // Set true to use the old proto1 MessageSet wire format for extensions. - // This is provided for backwards-compatibility with the MessageSet wire - // format. You should not use this for any other reason: It's less - // efficient, has fewer features, and is more complicated. - // - // The message must be defined exactly as follows: - // message Foo { - // option message_set_wire_format = true; - // extensions 4 to max; - // } - // Note that the message cannot have any defined fields; MessageSets only - // have extensions. - // - // All extensions of your type must be singular messages; e.g. they cannot - // be int32s, enums, or repeated messages. - // - // Because this is an option, the above two restrictions are not enforced by - // the protocol compiler. - optional bool message_set_wire_format = 1 [default=false]; - - // Disables the generation of the standard "descriptor()" accessor, which can - // conflict with a field of the same name. This is meant to make migration - // from proto1 easier; new code should avoid fields named "descriptor". - optional bool no_standard_descriptor_accessor = 2 [default=false]; - - // Is this message deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for the message, or it will be completely ignored; in the very least, - // this is a formalization for deprecating messages. - optional bool deprecated = 3 [default=false]; - - // Whether the message is an automatically generated map entry type for the - // maps field. - // - // For maps fields: - // map map_field = 1; - // The parsed descriptor looks like: - // message MapFieldEntry { - // option map_entry = true; - // optional KeyType key = 1; - // optional ValueType value = 2; - // } - // repeated MapFieldEntry map_field = 1; - // - // Implementations may choose not to generate the map_entry=true message, but - // use a native map in the target language to hold the keys and values. - // The reflection APIs in such implementions still need to work as - // if the field is a repeated message field. - // - // NOTE: Do not set the option in .proto files. Always use the maps syntax - // instead. The option should only be implicitly set by the proto compiler - // parser. - optional bool map_entry = 7; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; - - reserved 8; // javalite_serializable -} - -message FieldOptions { - // The ctype option instructs the C++ code generator to use a different - // representation of the field than it normally would. See the specific - // options below. This option is not yet implemented in the open source - // release -- sorry, we'll try to include it in a future version! - optional CType ctype = 1 [default = STRING]; - enum CType { - // Default mode. - STRING = 0; - - CORD = 1; - - STRING_PIECE = 2; - } - // The packed option can be enabled for repeated primitive fields to enable - // a more efficient representation on the wire. Rather than repeatedly - // writing the tag and type for each element, the entire array is encoded as - // a single length-delimited blob. In proto3, only explicit setting it to - // false will avoid using packed encoding. - optional bool packed = 2; - - // The jstype option determines the JavaScript type used for values of the - // field. The option is permitted only for 64 bit integral and fixed types - // (int64, uint64, sint64, fixed64, sfixed64). By default these types are - // represented as JavaScript strings. This avoids loss of precision that can - // happen when a large value is converted to a floating point JavaScript - // numbers. Specifying JS_NUMBER for the jstype causes the generated - // JavaScript code to use the JavaScript "number" type instead of strings. - // This option is an enum to permit additional types to be added, - // e.g. goog.math.Integer. - optional JSType jstype = 6 [default = JS_NORMAL]; - enum JSType { - // Use the default type. - JS_NORMAL = 0; - - // Use JavaScript strings. - JS_STRING = 1; - - // Use JavaScript numbers. - JS_NUMBER = 2; - } - - // Should this field be parsed lazily? Lazy applies only to message-type - // fields. It means that when the outer message is initially parsed, the - // inner message's contents will not be parsed but instead stored in encoded - // form. The inner message will actually be parsed when it is first accessed. - // - // This is only a hint. Implementations are free to choose whether to use - // eager or lazy parsing regardless of the value of this option. However, - // setting this option true suggests that the protocol author believes that - // using lazy parsing on this field is worth the additional bookkeeping - // overhead typically needed to implement it. - // - // This option does not affect the public interface of any generated code; - // all method signatures remain the same. Furthermore, thread-safety of the - // interface is not affected by this option; const methods remain safe to - // call from multiple threads concurrently, while non-const methods continue - // to require exclusive access. - // - // - // Note that implementations may choose not to check required fields within - // a lazy sub-message. That is, calling IsInitialized() on the outer message - // may return true even if the inner message has missing required fields. - // This is necessary because otherwise the inner message would have to be - // parsed in order to perform the check, defeating the purpose of lazy - // parsing. An implementation which chooses not to check required fields - // must be consistent about it. That is, for any particular sub-message, the - // implementation must either *always* check its required fields, or *never* - // check its required fields, regardless of whether or not the message has - // been parsed. - optional bool lazy = 5 [default=false]; - - // Is this field deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for accessors, or it will be completely ignored; in the very least, this - // is a formalization for deprecating fields. - optional bool deprecated = 3 [default=false]; - - // For Google-internal migration only. Do not use. - optional bool weak = 10 [default=false]; - - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; - - reserved 4; // removed jtype -} - -message OneofOptions { - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message EnumOptions { - - // Set this option to true to allow mapping different tag names to the same - // value. - optional bool allow_alias = 2; - - // Is this enum deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for the enum, or it will be completely ignored; in the very least, this - // is a formalization for deprecating enums. - optional bool deprecated = 3 [default=false]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message EnumValueOptions { - // Is this enum value deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for the enum value, or it will be completely ignored; in the very least, - // this is a formalization for deprecating enum values. - optional bool deprecated = 1 [default=false]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message ServiceOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. - - // Is this service deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for the service, or it will be completely ignored; in the very least, - // this is a formalization for deprecating services. - optional bool deprecated = 33 [default=false]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - -message MethodOptions { - - // Note: Field numbers 1 through 32 are reserved for Google's internal RPC - // framework. We apologize for hoarding these numbers to ourselves, but - // we were already using them long before we decided to release Protocol - // Buffers. - - // Is this method deprecated? - // Depending on the target platform, this can emit Deprecated annotations - // for the method, or it will be completely ignored; in the very least, - // this is a formalization for deprecating methods. - optional bool deprecated = 33 [default=false]; - - // The parser stores options it doesn't recognize here. See above. - repeated UninterpretedOption uninterpreted_option = 999; - - // Clients can define custom options in extensions of this message. See above. - extensions 1000 to max; -} - - -// A message representing a option the parser does not recognize. This only -// appears in options protos created by the compiler::Parser class. -// DescriptorPool resolves these when building Descriptor objects. Therefore, -// options protos in descriptor objects (e.g. returned by Descriptor::options(), -// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions -// in them. -message UninterpretedOption { - // The name of the uninterpreted option. Each string represents a segment in - // a dot-separated name. is_extension is true iff a segment represents an - // extension (denoted with parentheses in options specs in .proto files). - // E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents - // "foo.(bar.baz).qux". - message NamePart { - required string name_part = 1; - required bool is_extension = 2; - } - repeated NamePart name = 2; - - // The value of the uninterpreted option, in whatever type the tokenizer - // identified it as during parsing. Exactly one of these should be set. - optional string identifier_value = 3; - optional uint64 positive_int_value = 4; - optional int64 negative_int_value = 5; - optional double double_value = 6; - optional bytes string_value = 7; - optional string aggregate_value = 8; -} - -// =================================================================== -// Optional source code info - -// Encapsulates information about the original source file from which a -// FileDescriptorProto was generated. -message SourceCodeInfo { - // A Location identifies a piece of source code in a .proto file which - // corresponds to a particular definition. This information is intended - // to be useful to IDEs, code indexers, documentation generators, and similar - // tools. - // - // For example, say we have a file like: - // message Foo { - // optional string foo = 1; - // } - // Let's look at just the field definition: - // optional string foo = 1; - // ^ ^^ ^^ ^ ^^^ - // a bc de f ghi - // We have the following locations: - // span path represents - // [a,i) [ 4, 0, 2, 0 ] The whole field definition. - // [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). - // [c,d) [ 4, 0, 2, 0, 5 ] The type (string). - // [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). - // [g,h) [ 4, 0, 2, 0, 3 ] The number (1). - // - // Notes: - // - A location may refer to a repeated field itself (i.e. not to any - // particular index within it). This is used whenever a set of elements are - // logically enclosed in a single code segment. For example, an entire - // extend block (possibly containing multiple extension definitions) will - // have an outer location whose path refers to the "extensions" repeated - // field without an index. - // - Multiple locations may have the same path. This happens when a single - // logical declaration is spread out across multiple places. The most - // obvious example is the "extend" block again -- there may be multiple - // extend blocks in the same scope, each of which will have the same path. - // - A location's span is not always a subset of its parent's span. For - // example, the "extendee" of an extension declaration appears at the - // beginning of the "extend" block and is shared by all extensions within - // the block. - // - Just because a location's span is a subset of some other location's span - // does not mean that it is a descendent. For example, a "group" defines - // both a type and a field in a single declaration. Thus, the locations - // corresponding to the type and field and their components will overlap. - // - Code which tries to interpret locations should probably be designed to - // ignore those that it doesn't understand, as more types of locations could - // be recorded in the future. - repeated Location location = 1; - message Location { - // Identifies which part of the FileDescriptorProto was defined at this - // location. - // - // Each element is a field number or an index. They form a path from - // the root FileDescriptorProto to the place where the definition. For - // example, this path: - // [ 4, 3, 2, 7, 1 ] - // refers to: - // file.message_type(3) // 4, 3 - // .field(7) // 2, 7 - // .name() // 1 - // This is because FileDescriptorProto.message_type has field number 4: - // repeated DescriptorProto message_type = 4; - // and DescriptorProto.field has field number 2: - // repeated FieldDescriptorProto field = 2; - // and FieldDescriptorProto.name has field number 1: - // optional string name = 1; - // - // Thus, the above path gives the location of a field name. If we removed - // the last element: - // [ 4, 3, 2, 7 ] - // this path refers to the whole field declaration (from the beginning - // of the label to the terminating semicolon). - repeated int32 path = 1 [packed=true]; - - // Always has exactly three or four elements: start line, start column, - // end line (optional, otherwise assumed same as start line), end column. - // These are packed into a single field for efficiency. Note that line - // and column numbers are zero-based -- typically you will want to add - // 1 to each before displaying to a user. - repeated int32 span = 2 [packed=true]; - - // If this SourceCodeInfo represents a complete declaration, these are any - // comments appearing before and after the declaration which appear to be - // attached to the declaration. - // - // A series of line comments appearing on consecutive lines, with no other - // tokens appearing on those lines, will be treated as a single comment. - // - // leading_detached_comments will keep paragraphs of comments that appear - // before (but not connected to) the current element. Each paragraph, - // separated by empty lines, will be one comment element in the repeated - // field. - // - // Only the comment content is provided; comment markers (e.g. //) are - // stripped out. For block comments, leading whitespace and an asterisk - // will be stripped from the beginning of each line other than the first. - // Newlines are included in the output. - // - // Examples: - // - // optional int32 foo = 1; // Comment attached to foo. - // // Comment attached to bar. - // optional int32 bar = 2; - // - // optional string baz = 3; - // // Comment attached to baz. - // // Another line attached to baz. - // - // // Comment attached to qux. - // // - // // Another line attached to qux. - // optional double qux = 4; - // - // // Detached comment for corge. This is not leading or trailing comments - // // to qux or corge because there are blank lines separating it from - // // both. - // - // // Detached comment for corge paragraph 2. - // - // optional string corge = 5; - // /* Block comment attached - // * to corge. Leading asterisks - // * will be removed. */ - // /* Block comment attached to - // * grault. */ - // optional int32 grault = 6; - // - // // ignored detached comments. - optional string leading_comments = 3; - optional string trailing_comments = 4; - repeated string leading_detached_comments = 6; - } -} - -// Describes the relationship between generated code and its original source -// file. A GeneratedCodeInfo message is associated with only one generated -// source file, but may contain references to different source .proto files. -message GeneratedCodeInfo { - // An Annotation connects some span of text in generated code to an element - // of its generating .proto file. - repeated Annotation annotation = 1; - message Annotation { - // Identifies the element in the original source .proto file. This field - // is formatted the same as SourceCodeInfo.Location.path. - repeated int32 path = 1 [packed=true]; - - // Identifies the filesystem path to the original source .proto. - optional string source_file = 2; - - // Identifies the starting offset in bytes in the generated code - // that relates to the identified object. - optional int32 begin = 3; - - // Identifies the ending offset in bytes in the generated code that - // relates to the identified offset. The end offset should be one past - // the last relevant byte (so the length of the text = end - begin). - optional int32 end = 4; - } -} diff --git a/app/src/main/cpp/google/protobuf/descriptor_database.h b/app/src/main/cpp/google/protobuf/descriptor_database.h deleted file mode 100644 index 86002d5..0000000 --- a/app/src/main/cpp/google/protobuf/descriptor_database.h +++ /dev/null @@ -1,369 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Interface for manipulating databases of descriptors. - -#ifndef GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ -#define GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ - -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { - -// Defined in this file. -class DescriptorDatabase; -class SimpleDescriptorDatabase; -class EncodedDescriptorDatabase; -class DescriptorPoolDatabase; -class MergedDescriptorDatabase; - -// Abstract interface for a database of descriptors. -// -// This is useful if you want to create a DescriptorPool which loads -// descriptors on-demand from some sort of large database. If the database -// is large, it may be inefficient to enumerate every .proto file inside it -// calling DescriptorPool::BuildFile() for each one. Instead, a DescriptorPool -// can be created which wraps a DescriptorDatabase and only builds particular -// descriptors when they are needed. -class LIBPROTOBUF_EXPORT DescriptorDatabase { - public: - inline DescriptorDatabase() {} - virtual ~DescriptorDatabase(); - - // Find a file by file name. Fills in in *output and returns true if found. - // Otherwise, returns false, leaving the contents of *output undefined. - virtual bool FindFileByName(const string& filename, - FileDescriptorProto* output) = 0; - - // Find the file that declares the given fully-qualified symbol name. - // If found, fills in *output and returns true, otherwise returns false - // and leaves *output undefined. - virtual bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output) = 0; - - // Find the file which defines an extension extending the given message type - // with the given field number. If found, fills in *output and returns true, - // otherwise returns false and leaves *output undefined. containing_type - // must be a fully-qualified type name. - virtual bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output) = 0; - - // Finds the tag numbers used by all known extensions of - // extendee_type, and appends them to output in an undefined - // order. This method is best-effort: it's not guaranteed that the - // database will find all extensions, and it's not guaranteed that - // FindFileContainingExtension will return true on all of the found - // numbers. Returns true if the search was successful, otherwise - // returns false and leaves output unchanged. - // - // This method has a default implementation that always returns - // false. - virtual bool FindAllExtensionNumbers(const string& /* extendee_type */, - vector* /* output */) { - return false; - } - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); -}; - -// A DescriptorDatabase into which you can insert files manually. -// -// FindFileContainingSymbol() is fully-implemented. When you add a file, its -// symbols will be indexed for this purpose. Note that the implementation -// may return false positives, but only if it isn't possible for the symbol -// to be defined in any other file. In particular, if a file defines a symbol -// "Foo", then searching for "Foo.[anything]" will match that file. This way, -// the database does not need to aggressively index all children of a symbol. -// -// FindFileContainingExtension() is mostly-implemented. It works if and only -// if the original FieldDescriptorProto defining the extension has a -// fully-qualified type name in its "extendee" field (i.e. starts with a '.'). -// If the extendee is a relative name, SimpleDescriptorDatabase will not -// attempt to resolve the type, so it will not know what type the extension is -// extending. Therefore, calling FindFileContainingExtension() with the -// extension's containing type will never actually find that extension. Note -// that this is an unlikely problem, as all FileDescriptorProtos created by the -// protocol compiler (as well as ones created by calling -// FileDescriptor::CopyTo()) will always use fully-qualified names for all -// types. You only need to worry if you are constructing FileDescriptorProtos -// yourself, or are calling compiler::Parser directly. -class LIBPROTOBUF_EXPORT SimpleDescriptorDatabase : public DescriptorDatabase { - public: - SimpleDescriptorDatabase(); - ~SimpleDescriptorDatabase(); - - // Adds the FileDescriptorProto to the database, making a copy. The object - // can be deleted after Add() returns. Returns false if the file conflicted - // with a file already in the database, in which case an error will have - // been written to GOOGLE_LOG(ERROR). - bool Add(const FileDescriptorProto& file); - - // Adds the FileDescriptorProto to the database and takes ownership of it. - bool AddAndOwn(const FileDescriptorProto* file); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - // So that it can use DescriptorIndex. - friend class EncodedDescriptorDatabase; - - // An index mapping file names, symbol names, and extension numbers to - // some sort of values. - template - class DescriptorIndex { - public: - // Helpers to recursively add particular descriptors and all their contents - // to the index. - bool AddFile(const FileDescriptorProto& file, - Value value); - bool AddSymbol(const string& name, Value value); - bool AddNestedExtensions(const DescriptorProto& message_type, - Value value); - bool AddExtension(const FieldDescriptorProto& field, - Value value); - - Value FindFile(const string& filename); - Value FindSymbol(const string& name); - Value FindExtension(const string& containing_type, int field_number); - bool FindAllExtensionNumbers(const string& containing_type, - vector* output); - - private: - map by_name_; - map by_symbol_; - map, Value> by_extension_; - - // Invariant: The by_symbol_ map does not contain any symbols which are - // prefixes of other symbols in the map. For example, "foo.bar" is a - // prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz"). - // - // This invariant is important because it means that given a symbol name, - // we can find a key in the map which is a prefix of the symbol in O(lg n) - // time, and we know that there is at most one such key. - // - // The prefix lookup algorithm works like so: - // 1) Find the last key in the map which is less than or equal to the - // search key. - // 2) If the found key is a prefix of the search key, then return it. - // Otherwise, there is no match. - // - // I am sure this algorithm has been described elsewhere, but since I - // wasn't able to find it quickly I will instead prove that it works - // myself. The key to the algorithm is that if a match exists, step (1) - // will find it. Proof: - // 1) Define the "search key" to be the key we are looking for, the "found - // key" to be the key found in step (1), and the "match key" to be the - // key which actually matches the serach key (i.e. the key we're trying - // to find). - // 2) The found key must be less than or equal to the search key by - // definition. - // 3) The match key must also be less than or equal to the search key - // (because it is a prefix). - // 4) The match key cannot be greater than the found key, because if it - // were, then step (1) of the algorithm would have returned the match - // key instead (since it finds the *greatest* key which is less than or - // equal to the search key). - // 5) Therefore, the found key must be between the match key and the search - // key, inclusive. - // 6) Since the search key must be a sub-symbol of the match key, if it is - // not equal to the match key, then search_key[match_key.size()] must - // be '.'. - // 7) Since '.' sorts before any other character that is valid in a symbol - // name, then if the found key is not equal to the match key, then - // found_key[match_key.size()] must also be '.', because any other value - // would make it sort after the search key. - // 8) Therefore, if the found key is not equal to the match key, then the - // found key must be a sub-symbol of the match key. However, this would - // contradict our map invariant which says that no symbol in the map is - // a sub-symbol of any other. - // 9) Therefore, the found key must match the match key. - // - // The above proof assumes the match key exists. In the case that the - // match key does not exist, then step (1) will return some other symbol. - // That symbol cannot be a super-symbol of the search key since if it were, - // then it would be a match, and we're assuming the match key doesn't exist. - // Therefore, step 2 will correctly return no match. - - // Find the last entry in the by_symbol_ map whose key is less than or - // equal to the given name. - typename map::iterator FindLastLessOrEqual( - const string& name); - - // True if either the arguments are equal or super_symbol identifies a - // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of - // "foo.bar.baz", but not a parent of "foo.barbaz"). - bool IsSubSymbol(const string& sub_symbol, const string& super_symbol); - - // Returns true if and only if all characters in the name are alphanumerics, - // underscores, or periods. - bool ValidateSymbolName(const string& name); - }; - - - DescriptorIndex index_; - vector files_to_delete_; - - // If file is non-NULL, copy it into *output and return true, otherwise - // return false. - bool MaybeCopy(const FileDescriptorProto* file, - FileDescriptorProto* output); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase); -}; - -// Very similar to SimpleDescriptorDatabase, but stores all the descriptors -// as raw bytes and generally tries to use as little memory as possible. -// -// The same caveats regarding FindFileContainingExtension() apply as with -// SimpleDescriptorDatabase. -class LIBPROTOBUF_EXPORT EncodedDescriptorDatabase : public DescriptorDatabase { - public: - EncodedDescriptorDatabase(); - ~EncodedDescriptorDatabase(); - - // Adds the FileDescriptorProto to the database. The descriptor is provided - // in encoded form. The database does not make a copy of the bytes, nor - // does it take ownership; it's up to the caller to make sure the bytes - // remain valid for the life of the database. Returns false and logs an error - // if the bytes are not a valid FileDescriptorProto or if the file conflicted - // with a file already in the database. - bool Add(const void* encoded_file_descriptor, int size); - - // Like Add(), but makes a copy of the data, so that the caller does not - // need to keep it around. - bool AddCopy(const void* encoded_file_descriptor, int size); - - // Like FindFileContainingSymbol but returns only the name of the file. - bool FindNameOfFileContainingSymbol(const string& symbol_name, - string* output); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - SimpleDescriptorDatabase::DescriptorIndex > index_; - vector files_to_delete_; - - // If encoded_file.first is non-NULL, parse the data into *output and return - // true, otherwise return false. - bool MaybeParse(pair encoded_file, - FileDescriptorProto* output); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase); -}; - -// A DescriptorDatabase that fetches files from a given pool. -class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { - public: - explicit DescriptorPoolDatabase(const DescriptorPool& pool); - ~DescriptorPoolDatabase(); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - private: - const DescriptorPool& pool_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase); -}; - -// A DescriptorDatabase that wraps two or more others. It first searches the -// first database and, if that fails, tries the second, and so on. -class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { - public: - // Merge just two databases. The sources remain property of the caller. - MergedDescriptorDatabase(DescriptorDatabase* source1, - DescriptorDatabase* source2); - // Merge more than two databases. The sources remain property of the caller. - // The vector may be deleted after the constructor returns but the - // DescriptorDatabases need to stick around. - explicit MergedDescriptorDatabase(const vector& sources); - ~MergedDescriptorDatabase(); - - // implements DescriptorDatabase ----------------------------------- - bool FindFileByName(const string& filename, - FileDescriptorProto* output); - bool FindFileContainingSymbol(const string& symbol_name, - FileDescriptorProto* output); - bool FindFileContainingExtension(const string& containing_type, - int field_number, - FileDescriptorProto* output); - // Merges the results of calling all databases. Returns true iff any - // of the databases returned true. - bool FindAllExtensionNumbers(const string& extendee_type, - vector* output); - - - private: - vector sources_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ diff --git a/app/src/main/cpp/google/protobuf/duration.pb.h b/app/src/main/cpp/google/protobuf/duration.pb.h deleted file mode 100644 index 3ed1a6d..0000000 --- a/app/src/main/cpp/google/protobuf/duration.pb.h +++ /dev/null @@ -1,197 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/duration.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fduration_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fduration_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto(); - -class Duration; - -// =================================================================== - -class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Duration) */ { - public: - Duration(); - virtual ~Duration(); - - Duration(const Duration& from); - - inline Duration& operator=(const Duration& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Duration& default_instance(); - - static const Duration* internal_default_instance(); - - void UnsafeArenaSwap(Duration* other); - void Swap(Duration* other); - - // implements Message ---------------------------------------------- - - inline Duration* New() const { return New(NULL); } - - Duration* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Duration& from); - void MergeFrom(const Duration& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Duration* other); - void UnsafeMergeFrom(const Duration& from); - protected: - explicit Duration(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int64 seconds = 1; - void clear_seconds(); - static const int kSecondsFieldNumber = 1; - ::google::protobuf::int64 seconds() const; - void set_seconds(::google::protobuf::int64 value); - - // optional int32 nanos = 2; - void clear_nanos(); - static const int kNanosFieldNumber = 2; - ::google::protobuf::int32 nanos() const; - void set_nanos(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Duration) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::int64 seconds_; - ::google::protobuf::int32 nanos_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fduration_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fduration_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fduration_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fduration_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Duration_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Duration - -// optional int64 seconds = 1; -inline void Duration::clear_seconds() { - seconds_ = GOOGLE_LONGLONG(0); -} -inline ::google::protobuf::int64 Duration::seconds() const { - // @@protoc_insertion_point(field_get:google.protobuf.Duration.seconds) - return seconds_; -} -inline void Duration::set_seconds(::google::protobuf::int64 value) { - - seconds_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Duration.seconds) -} - -// optional int32 nanos = 2; -inline void Duration::clear_nanos() { - nanos_ = 0; -} -inline ::google::protobuf::int32 Duration::nanos() const { - // @@protoc_insertion_point(field_get:google.protobuf.Duration.nanos) - return nanos_; -} -inline void Duration::set_nanos(::google::protobuf::int32 value) { - - nanos_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos) -} - -inline const Duration* Duration::internal_default_instance() { - return &Duration_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fduration_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/duration.proto b/app/src/main/cpp/google/protobuf/duration.proto deleted file mode 100644 index 7f461f4..0000000 --- a/app/src/main/cpp/google/protobuf/duration.proto +++ /dev/null @@ -1,104 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/duration"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "DurationProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// A Duration represents a signed, fixed-length span of time represented -// as a count of seconds and fractions of seconds at nanosecond -// resolution. It is independent of any calendar and concepts like "day" -// or "month". It is related to Timestamp in that the difference between -// two Timestamp values is a Duration and it can be added or subtracted -// from a Timestamp. Range is approximately +-10,000 years. -// -// Example 1: Compute Duration from two Timestamps in pseudo code. -// -// Timestamp start = ...; -// Timestamp end = ...; -// Duration duration = ...; -// -// duration.seconds = end.seconds - start.seconds; -// duration.nanos = end.nanos - start.nanos; -// -// if (duration.seconds < 0 && duration.nanos > 0) { -// duration.seconds += 1; -// duration.nanos -= 1000000000; -// } else if (durations.seconds > 0 && duration.nanos < 0) { -// duration.seconds -= 1; -// duration.nanos += 1000000000; -// } -// -// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. -// -// Timestamp start = ...; -// Duration duration = ...; -// Timestamp end = ...; -// -// end.seconds = start.seconds + duration.seconds; -// end.nanos = start.nanos + duration.nanos; -// -// if (end.nanos < 0) { -// end.seconds -= 1; -// end.nanos += 1000000000; -// } else if (end.nanos >= 1000000000) { -// end.seconds += 1; -// end.nanos -= 1000000000; -// } -// -// Example 3: Compute Duration from datetime.timedelta in Python. -// -// td = datetime.timedelta(days=3, minutes=10) -// duration = Duration() -// duration.FromTimedelta(td) -// -// -message Duration { - - // Signed seconds of the span of time. Must be from -315,576,000,000 - // to +315,576,000,000 inclusive. - int64 seconds = 1; - - // Signed fractions of a second at nanosecond resolution of the span - // of time. Durations less than one second are represented with a 0 - // `seconds` field and a positive or negative `nanos` field. For durations - // of one second or more, a non-zero value for the `nanos` field must be - // of the same sign as the `seconds` field. Must be from -999,999,999 - // to +999,999,999 inclusive. - int32 nanos = 2; -} diff --git a/app/src/main/cpp/google/protobuf/dynamic_message.h b/app/src/main/cpp/google/protobuf/dynamic_message.h deleted file mode 100644 index f74cd7d..0000000 --- a/app/src/main/cpp/google/protobuf/dynamic_message.h +++ /dev/null @@ -1,152 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines an implementation of Message which can emulate types which are not -// known at compile-time. - -#ifndef GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ -#define GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ - -#include -#ifndef _SHARED_PTR_H -#include -#endif - -#include -#include -#include - -namespace google { -namespace protobuf { - -// Defined in other files. -class Descriptor; // descriptor.h -class DescriptorPool; // descriptor.h - -// Constructs implementations of Message which can emulate types which are not -// known at compile-time. -// -// Sometimes you want to be able to manipulate protocol types that you don't -// know about at compile time. It would be nice to be able to construct -// a Message object which implements the message type given by any arbitrary -// Descriptor. DynamicMessage provides this. -// -// As it turns out, a DynamicMessage needs to construct extra -// information about its type in order to operate. Most of this information -// can be shared between all DynamicMessages of the same type. But, caching -// this information in some sort of global map would be a bad idea, since -// the cached information for a particular descriptor could outlive the -// descriptor itself. To avoid this problem, DynamicMessageFactory -// encapsulates this "cache". All DynamicMessages of the same type created -// from the same factory will share the same support data. Any Descriptors -// used with a particular factory must outlive the factory. -class LIBPROTOBUF_EXPORT DynamicMessageFactory : public MessageFactory { - public: - // Construct a DynamicMessageFactory that will search for extensions in - // the DescriptorPool in which the extendee is defined. - DynamicMessageFactory(); - - // Construct a DynamicMessageFactory that will search for extensions in - // the given DescriptorPool. - // - // DEPRECATED: Use CodedInputStream::SetExtensionRegistry() to tell the - // parser to look for extensions in an alternate pool. However, note that - // this is almost never what you want to do. Almost all users should use - // the zero-arg constructor. - DynamicMessageFactory(const DescriptorPool* pool); - - ~DynamicMessageFactory(); - - // Call this to tell the DynamicMessageFactory that if it is given a - // Descriptor d for which: - // d->file()->pool() == DescriptorPool::generated_pool(), - // then it should delegate to MessageFactory::generated_factory() instead - // of constructing a dynamic implementation of the message. In theory there - // is no down side to doing this, so it may become the default in the future. - void SetDelegateToGeneratedFactory(bool enable) { - delegate_to_generated_factory_ = enable; - } - - // implements MessageFactory --------------------------------------- - - // Given a Descriptor, constructs the default (prototype) Message of that - // type. You can then call that message's New() method to construct a - // mutable message of that type. - // - // Calling this method twice with the same Descriptor returns the same - // object. The returned object remains property of the factory and will - // be destroyed when the factory is destroyed. Also, any objects created - // by calling the prototype's New() method share some data with the - // prototype, so these must be destroyed before the DynamicMessageFactory - // is destroyed. - // - // The given descriptor must outlive the returned message, and hence must - // outlive the DynamicMessageFactory. - // - // The method is thread-safe. - const Message* GetPrototype(const Descriptor* type); - - private: - const DescriptorPool* pool_; - bool delegate_to_generated_factory_; - - // This struct just contains a hash_map. We can't #include from - // this header due to hacks needed for hash_map portability in the open source - // release. Namely, stubs/hash.h, which defines hash_map portably, is not a - // public header (for good reason), but dynamic_message.h is, and public - // headers may only #include other public headers. - struct PrototypeMap; - google::protobuf::scoped_ptr prototypes_; - mutable Mutex prototypes_mutex_; - - friend class DynamicMessage; - const Message* GetPrototypeNoLock(const Descriptor* type); - - // Construct default oneof instance for reflection usage if oneof - // is defined. - static void ConstructDefaultOneofInstance(const Descriptor* type, - const int offsets[], - void* default_oneof_instance); - // Delete default oneof instance. Called by ~DynamicMessageFactory. - static void DeleteDefaultOneofInstance(const Descriptor* type, - const int offsets[], - void* default_oneof_instance); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessageFactory); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_DYNAMIC_MESSAGE_H__ diff --git a/app/src/main/cpp/google/protobuf/empty.pb.h b/app/src/main/cpp/google/protobuf/empty.pb.h deleted file mode 100644 index 2930936..0000000 --- a/app/src/main/cpp/google/protobuf/empty.pb.h +++ /dev/null @@ -1,155 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/empty.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fempty_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fempty_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto(); - -class Empty; - -// =================================================================== - -class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Empty) */ { - public: - Empty(); - virtual ~Empty(); - - Empty(const Empty& from); - - inline Empty& operator=(const Empty& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Empty& default_instance(); - - static const Empty* internal_default_instance(); - - void UnsafeArenaSwap(Empty* other); - void Swap(Empty* other); - - // implements Message ---------------------------------------------- - - inline Empty* New() const { return New(NULL); } - - Empty* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Empty& from); - void MergeFrom(const Empty& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Empty* other); - void UnsafeMergeFrom(const Empty& from); - protected: - explicit Empty(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // @@protoc_insertion_point(class_scope:google.protobuf.Empty) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fempty_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fempty_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fempty_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fempty_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Empty_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Empty - -inline const Empty* Empty::internal_default_instance() { - return &Empty_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fempty_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/empty.proto b/app/src/main/cpp/google/protobuf/empty.proto deleted file mode 100644 index 03cacd2..0000000 --- a/app/src/main/cpp/google/protobuf/empty.proto +++ /dev/null @@ -1,52 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option go_package = "github.com/golang/protobuf/ptypes/empty"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "EmptyProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; -option cc_enable_arenas = true; - -// A generic empty message that you can re-use to avoid defining duplicated -// empty messages in your APIs. A typical example is to use it as the request -// or the response type of an API method. For instance: -// -// service Foo { -// rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); -// } -// -// The JSON representation for `Empty` is empty JSON object `{}`. -message Empty {} diff --git a/app/src/main/cpp/google/protobuf/extension_set.h b/app/src/main/cpp/google/protobuf/extension_set.h deleted file mode 100644 index f5aa8de..0000000 --- a/app/src/main/cpp/google/protobuf/extension_set.h +++ /dev/null @@ -1,1318 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_EXTENSION_SET_H__ -#define GOOGLE_PROTOBUF_EXTENSION_SET_H__ - -#include -#include -#include -#include - - -#include -#include -#include - -#include - -namespace google { - -namespace protobuf { - class Arena; - class Descriptor; // descriptor.h - class FieldDescriptor; // descriptor.h - class DescriptorPool; // descriptor.h - class MessageLite; // message_lite.h - class Message; // message.h - class MessageFactory; // message.h - class UnknownFieldSet; // unknown_field_set.h - namespace io { - class CodedInputStream; // coded_stream.h - class CodedOutputStream; // coded_stream.h - } - namespace internal { - class FieldSkipper; // wire_format_lite.h - } -} - -namespace protobuf { -namespace internal { - -// Used to store values of type WireFormatLite::FieldType without having to -// #include wire_format_lite.h. Also, ensures that we use only one byte to -// store these values, which is important to keep the layout of -// ExtensionSet::Extension small. -typedef uint8 FieldType; - -// A function which, given an integer value, returns true if the number -// matches one of the defined values for the corresponding enum type. This -// is used with RegisterEnumExtension, below. -typedef bool EnumValidityFunc(int number); - -// Version of the above which takes an argument. This is needed to deal with -// extensions that are not compiled in. -typedef bool EnumValidityFuncWithArg(const void* arg, int number); - -// Information about a registered extension. -struct ExtensionInfo { - inline ExtensionInfo() {} - inline ExtensionInfo(FieldType type_param, bool isrepeated, bool ispacked) - : type(type_param), is_repeated(isrepeated), is_packed(ispacked), - descriptor(NULL) {} - - FieldType type; - bool is_repeated; - bool is_packed; - - struct EnumValidityCheck { - EnumValidityFuncWithArg* func; - const void* arg; - }; - - union { - EnumValidityCheck enum_validity_check; - const MessageLite* message_prototype; - }; - - // The descriptor for this extension, if one exists and is known. May be - // NULL. Must not be NULL if the descriptor for the extension does not - // live in the same pool as the descriptor for the containing type. - const FieldDescriptor* descriptor; -}; - -// Abstract interface for an object which looks up extension definitions. Used -// when parsing. -class LIBPROTOBUF_EXPORT ExtensionFinder { - public: - virtual ~ExtensionFinder(); - - // Find the extension with the given containing type and number. - virtual bool Find(int number, ExtensionInfo* output) = 0; -}; - -// Implementation of ExtensionFinder which finds extensions defined in .proto -// files which have been compiled into the binary. -class LIBPROTOBUF_EXPORT GeneratedExtensionFinder : public ExtensionFinder { - public: - GeneratedExtensionFinder(const MessageLite* containing_type) - : containing_type_(containing_type) {} - virtual ~GeneratedExtensionFinder() {} - - // Returns true and fills in *output if found, otherwise returns false. - virtual bool Find(int number, ExtensionInfo* output); - - private: - const MessageLite* containing_type_; -}; - -// A FieldSkipper used for parsing MessageSet. -class MessageSetFieldSkipper; - -// Note: extension_set_heavy.cc defines DescriptorPoolExtensionFinder for -// finding extensions from a DescriptorPool. - -// This is an internal helper class intended for use within the protocol buffer -// library and generated classes. Clients should not use it directly. Instead, -// use the generated accessors such as GetExtension() of the class being -// extended. -// -// This class manages extensions for a protocol message object. The -// message's HasExtension(), GetExtension(), MutableExtension(), and -// ClearExtension() methods are just thin wrappers around the embedded -// ExtensionSet. When parsing, if a tag number is encountered which is -// inside one of the message type's extension ranges, the tag is passed -// off to the ExtensionSet for parsing. Etc. -class LIBPROTOBUF_EXPORT ExtensionSet { - public: - ExtensionSet(); - explicit ExtensionSet(::google::protobuf::Arena* arena); - ~ExtensionSet(); - - // These are called at startup by protocol-compiler-generated code to - // register known extensions. The registrations are used by ParseField() - // to look up extensions for parsed field numbers. Note that dynamic parsing - // does not use ParseField(); only protocol-compiler-generated parsing - // methods do. - static void RegisterExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed); - static void RegisterEnumExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed, - EnumValidityFunc* is_valid); - static void RegisterMessageExtension(const MessageLite* containing_type, - int number, FieldType type, - bool is_repeated, bool is_packed, - const MessageLite* prototype); - - // ================================================================= - - // Add all fields which are currently present to the given vector. This - // is useful to implement Reflection::ListFields(). - void AppendToList(const Descriptor* containing_type, - const DescriptorPool* pool, - std::vector* output) const; - - // ================================================================= - // Accessors - // - // Generated message classes include type-safe templated wrappers around - // these methods. Generally you should use those rather than call these - // directly, unless you are doing low-level memory management. - // - // When calling any of these accessors, the extension number requested - // MUST exist in the DescriptorPool provided to the constructor. Otherwise, - // the method will fail an assert. Normally, though, you would not call - // these directly; you would either call the generated accessors of your - // message class (e.g. GetExtension()) or you would call the accessors - // of the reflection interface. In both cases, it is impossible to - // trigger this assert failure: the generated accessors only accept - // linked-in extension types as parameters, while the Reflection interface - // requires you to provide the FieldDescriptor describing the extension. - // - // When calling any of these accessors, a protocol-compiler-generated - // implementation of the extension corresponding to the number MUST - // be linked in, and the FieldDescriptor used to refer to it MUST be - // the one generated by that linked-in code. Otherwise, the method will - // die on an assert failure. The message objects returned by the message - // accessors are guaranteed to be of the correct linked-in type. - // - // These methods pretty much match Reflection except that: - // - They're not virtual. - // - They identify fields by number rather than FieldDescriptors. - // - They identify enum values using integers rather than descriptors. - // - Strings provide Mutable() in addition to Set() accessors. - - bool Has(int number) const; - int ExtensionSize(int number) const; // Size of a repeated extension. - int NumExtensions() const; // The number of extensions - FieldType ExtensionType(int number) const; - void ClearExtension(int number); - - // singular fields ------------------------------------------------- - - int32 GetInt32 (int number, int32 default_value) const; - int64 GetInt64 (int number, int64 default_value) const; - uint32 GetUInt32(int number, uint32 default_value) const; - uint64 GetUInt64(int number, uint64 default_value) const; - float GetFloat (int number, float default_value) const; - double GetDouble(int number, double default_value) const; - bool GetBool (int number, bool default_value) const; - int GetEnum (int number, int default_value) const; - const string & GetString (int number, const string& default_value) const; - const MessageLite& GetMessage(int number, - const MessageLite& default_value) const; - const MessageLite& GetMessage(int number, const Descriptor* message_type, - MessageFactory* factory) const; - - // |descriptor| may be NULL so long as it is known that the descriptor for - // the extension lives in the same pool as the descriptor for the containing - // type. -#define desc const FieldDescriptor* descriptor // avoid line wrapping - void SetInt32 (int number, FieldType type, int32 value, desc); - void SetInt64 (int number, FieldType type, int64 value, desc); - void SetUInt32(int number, FieldType type, uint32 value, desc); - void SetUInt64(int number, FieldType type, uint64 value, desc); - void SetFloat (int number, FieldType type, float value, desc); - void SetDouble(int number, FieldType type, double value, desc); - void SetBool (int number, FieldType type, bool value, desc); - void SetEnum (int number, FieldType type, int value, desc); - void SetString(int number, FieldType type, const string& value, desc); - string * MutableString (int number, FieldType type, desc); - MessageLite* MutableMessage(int number, FieldType type, - const MessageLite& prototype, desc); - MessageLite* MutableMessage(const FieldDescriptor* decsriptor, - MessageFactory* factory); - // Adds the given message to the ExtensionSet, taking ownership of the - // message object. Existing message with the same number will be deleted. - // If "message" is NULL, this is equivalent to "ClearExtension(number)". - void SetAllocatedMessage(int number, FieldType type, - const FieldDescriptor* descriptor, - MessageLite* message); - void UnsafeArenaSetAllocatedMessage(int number, FieldType type, - const FieldDescriptor* descriptor, - MessageLite* message); - MessageLite* ReleaseMessage(int number, const MessageLite& prototype); - MessageLite* UnsafeArenaReleaseMessage( - int number, const MessageLite& prototype); - - MessageLite* ReleaseMessage(const FieldDescriptor* descriptor, - MessageFactory* factory); - MessageLite* UnsafeArenaReleaseMessage(const FieldDescriptor* descriptor, - MessageFactory* factory); -#undef desc - ::google::protobuf::Arena* GetArenaNoVirtual() const { return arena_; } - - // repeated fields ------------------------------------------------- - - // Fetches a RepeatedField extension by number; returns |default_value| - // if no such extension exists. User should not touch this directly; it is - // used by the GetRepeatedExtension() method. - const void* GetRawRepeatedField(int number, const void* default_value) const; - // Fetches a mutable version of a RepeatedField extension by number, - // instantiating one if none exists. Similar to above, user should not use - // this directly; it underlies MutableRepeatedExtension(). - void* MutableRawRepeatedField(int number, FieldType field_type, - bool packed, const FieldDescriptor* desc); - - // This is an overload of MutableRawRepeatedField to maintain compatibility - // with old code using a previous API. This version of - // MutableRawRepeatedField() will GOOGLE_CHECK-fail on a missing extension. - // (E.g.: borg/clients/internal/proto1/proto2_reflection.cc.) - void* MutableRawRepeatedField(int number); - - int32 GetRepeatedInt32 (int number, int index) const; - int64 GetRepeatedInt64 (int number, int index) const; - uint32 GetRepeatedUInt32(int number, int index) const; - uint64 GetRepeatedUInt64(int number, int index) const; - float GetRepeatedFloat (int number, int index) const; - double GetRepeatedDouble(int number, int index) const; - bool GetRepeatedBool (int number, int index) const; - int GetRepeatedEnum (int number, int index) const; - const string & GetRepeatedString (int number, int index) const; - const MessageLite& GetRepeatedMessage(int number, int index) const; - - void SetRepeatedInt32 (int number, int index, int32 value); - void SetRepeatedInt64 (int number, int index, int64 value); - void SetRepeatedUInt32(int number, int index, uint32 value); - void SetRepeatedUInt64(int number, int index, uint64 value); - void SetRepeatedFloat (int number, int index, float value); - void SetRepeatedDouble(int number, int index, double value); - void SetRepeatedBool (int number, int index, bool value); - void SetRepeatedEnum (int number, int index, int value); - void SetRepeatedString(int number, int index, const string& value); - string * MutableRepeatedString (int number, int index); - MessageLite* MutableRepeatedMessage(int number, int index); - -#define desc const FieldDescriptor* descriptor // avoid line wrapping - void AddInt32 (int number, FieldType type, bool packed, int32 value, desc); - void AddInt64 (int number, FieldType type, bool packed, int64 value, desc); - void AddUInt32(int number, FieldType type, bool packed, uint32 value, desc); - void AddUInt64(int number, FieldType type, bool packed, uint64 value, desc); - void AddFloat (int number, FieldType type, bool packed, float value, desc); - void AddDouble(int number, FieldType type, bool packed, double value, desc); - void AddBool (int number, FieldType type, bool packed, bool value, desc); - void AddEnum (int number, FieldType type, bool packed, int value, desc); - void AddString(int number, FieldType type, const string& value, desc); - string * AddString (int number, FieldType type, desc); - MessageLite* AddMessage(int number, FieldType type, - const MessageLite& prototype, desc); - MessageLite* AddMessage(const FieldDescriptor* descriptor, - MessageFactory* factory); - void AddAllocatedMessage(const FieldDescriptor* descriptor, - MessageLite* new_entry); -#undef desc - - void RemoveLast(int number); - MessageLite* ReleaseLast(int number); - void SwapElements(int number, int index1, int index2); - - // ----------------------------------------------------------------- - // TODO(kenton): Hardcore memory management accessors - - // ================================================================= - // convenience methods for implementing methods of Message - // - // These could all be implemented in terms of the other methods of this - // class, but providing them here helps keep the generated code size down. - - void Clear(); - void MergeFrom(const ExtensionSet& other); - void Swap(ExtensionSet* other); - void SwapExtension(ExtensionSet* other, int number); - bool IsInitialized() const; - - // Parses a single extension from the input. The input should start out - // positioned immediately after the tag. - bool ParseField(uint32 tag, io::CodedInputStream* input, - ExtensionFinder* extension_finder, - FieldSkipper* field_skipper); - - // Specific versions for lite or full messages (constructs the appropriate - // FieldSkipper automatically). |containing_type| is the default - // instance for the containing message; it is used only to look up the - // extension by number. See RegisterExtension(), above. Unlike the other - // methods of ExtensionSet, this only works for generated message types -- - // it looks up extensions registered using RegisterExtension(). - bool ParseField(uint32 tag, io::CodedInputStream* input, - const MessageLite* containing_type); - bool ParseField(uint32 tag, io::CodedInputStream* input, - const Message* containing_type, - UnknownFieldSet* unknown_fields); - bool ParseField(uint32 tag, io::CodedInputStream* input, - const MessageLite* containing_type, - io::CodedOutputStream* unknown_fields); - - // Parse an entire message in MessageSet format. Such messages have no - // fields, only extensions. - bool ParseMessageSet(io::CodedInputStream* input, - ExtensionFinder* extension_finder, - MessageSetFieldSkipper* field_skipper); - - // Specific versions for lite or full messages (constructs the appropriate - // FieldSkipper automatically). - bool ParseMessageSet(io::CodedInputStream* input, - const MessageLite* containing_type); - bool ParseMessageSet(io::CodedInputStream* input, - const Message* containing_type, - UnknownFieldSet* unknown_fields); - - // Write all extension fields with field numbers in the range - // [start_field_number, end_field_number) - // to the output stream, using the cached sizes computed when ByteSize() was - // last called. Note that the range bounds are inclusive-exclusive. - void SerializeWithCachedSizes(int start_field_number, - int end_field_number, - io::CodedOutputStream* output) const; - - // Same as SerializeWithCachedSizes, but without any bounds checking. - // The caller must ensure that target has sufficient capacity for the - // serialized extensions. - // - // Returns a pointer past the last written byte. - uint8* InternalSerializeWithCachedSizesToArray(int start_field_number, - int end_field_number, - bool deterministic, - uint8* target) const; - - // Like above but serializes in MessageSet format. - void SerializeMessageSetWithCachedSizes(io::CodedOutputStream* output) const; - uint8* InternalSerializeMessageSetWithCachedSizesToArray(bool deterministic, - uint8* target) const; - - // For backward-compatibility, versions of two of the above methods that - // are never forced to serialize deterministically. - uint8* SerializeWithCachedSizesToArray(int start_field_number, - int end_field_number, - uint8* target) const; - uint8* SerializeMessageSetWithCachedSizesToArray(uint8* target) const; - - // Returns the total serialized size of all the extensions. - size_t ByteSize() const; - - // Like ByteSize() but uses MessageSet format. - size_t MessageSetByteSize() const; - - // Returns (an estimate of) the total number of bytes used for storing the - // extensions in memory, excluding sizeof(*this). If the ExtensionSet is - // for a lite message (and thus possibly contains lite messages), the results - // are undefined (might work, might crash, might corrupt data, might not even - // be linked in). It's up to the protocol compiler to avoid calling this on - // such ExtensionSets (easy enough since lite messages don't implement - // SpaceUsed()). - int SpaceUsedExcludingSelf() const; - - private: - - // Interface of a lazily parsed singular message extension. - class LIBPROTOBUF_EXPORT LazyMessageExtension { - public: - LazyMessageExtension() {} - virtual ~LazyMessageExtension() {} - - virtual LazyMessageExtension* New(::google::protobuf::Arena* arena) const = 0; - virtual const MessageLite& GetMessage( - const MessageLite& prototype) const = 0; - virtual MessageLite* MutableMessage(const MessageLite& prototype) = 0; - virtual void SetAllocatedMessage(MessageLite *message) = 0; - virtual void UnsafeArenaSetAllocatedMessage(MessageLite *message) = 0; - virtual MessageLite* ReleaseMessage(const MessageLite& prototype) = 0; - virtual MessageLite* UnsafeArenaReleaseMessage( - const MessageLite& prototype) = 0; - - virtual bool IsInitialized() const = 0; - virtual int ByteSize() const = 0; - virtual int SpaceUsed() const = 0; - - virtual void MergeFrom(const LazyMessageExtension& other) = 0; - virtual void Clear() = 0; - - virtual bool ReadMessage(const MessageLite& prototype, - io::CodedInputStream* input) = 0; - virtual void WriteMessage(int number, - io::CodedOutputStream* output) const = 0; - virtual uint8* WriteMessageToArray(int number, uint8* target) const = 0; - virtual uint8* InternalWriteMessageToArray(int number, bool, - uint8* target) const { - // TODO(gpike): make this pure virtual. This is a placeholder because we - // need to update third_party/upb, for example. - return WriteMessageToArray(number, target); - } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyMessageExtension); - }; - struct Extension { - // The order of these fields packs Extension into 24 bytes when using 8 - // byte alignment. Consider this when adding or removing fields here. - union { - int32 int32_value; - int64 int64_value; - uint32 uint32_value; - uint64 uint64_value; - float float_value; - double double_value; - bool bool_value; - int enum_value; - string* string_value; - MessageLite* message_value; - LazyMessageExtension* lazymessage_value; - - RepeatedField * repeated_int32_value; - RepeatedField * repeated_int64_value; - RepeatedField * repeated_uint32_value; - RepeatedField * repeated_uint64_value; - RepeatedField * repeated_float_value; - RepeatedField * repeated_double_value; - RepeatedField * repeated_bool_value; - RepeatedField * repeated_enum_value; - RepeatedPtrField* repeated_string_value; - RepeatedPtrField* repeated_message_value; - }; - - FieldType type; - bool is_repeated; - - // For singular types, indicates if the extension is "cleared". This - // happens when an extension is set and then later cleared by the caller. - // We want to keep the Extension object around for reuse, so instead of - // removing it from the map, we just set is_cleared = true. This has no - // meaning for repeated types; for those, the size of the RepeatedField - // simply becomes zero when cleared. - bool is_cleared : 4; - - // For singular message types, indicates whether lazy parsing is enabled - // for this extension. This field is only valid when type == TYPE_MESSAGE - // and !is_repeated because we only support lazy parsing for singular - // message types currently. If is_lazy = true, the extension is stored in - // lazymessage_value. Otherwise, the extension will be message_value. - bool is_lazy : 4; - - // For repeated types, this indicates if the [packed=true] option is set. - bool is_packed; - - // For packed fields, the size of the packed data is recorded here when - // ByteSize() is called then used during serialization. - // TODO(kenton): Use atomic when C++ supports it. - mutable int cached_size; - - // The descriptor for this extension, if one exists and is known. May be - // NULL. Must not be NULL if the descriptor for the extension does not - // live in the same pool as the descriptor for the containing type. - const FieldDescriptor* descriptor; - - // Some helper methods for operations on a single Extension. - void SerializeFieldWithCachedSizes( - int number, - io::CodedOutputStream* output) const; - uint8* InternalSerializeFieldWithCachedSizesToArray( - int number, - bool deterministic, - uint8* target) const; - void SerializeMessageSetItemWithCachedSizes( - int number, - io::CodedOutputStream* output) const; - uint8* InternalSerializeMessageSetItemWithCachedSizesToArray( - int number, - bool deterministic, - uint8* target) const; - size_t ByteSize(int number) const; - size_t MessageSetItemByteSize(int number) const; - void Clear(); - int GetSize() const; - void Free(); - int SpaceUsedExcludingSelf() const; - }; - typedef std::map ExtensionMap; - - - // Merges existing Extension from other_extension - void InternalExtensionMergeFrom(int number, const Extension& other_extension); - - // Returns true and fills field_number and extension if extension is found. - // Note to support packed repeated field compatibility, it also fills whether - // the tag on wire is packed, which can be different from - // extension->is_packed (whether packed=true is specified). - bool FindExtensionInfoFromTag(uint32 tag, ExtensionFinder* extension_finder, - int* field_number, ExtensionInfo* extension, - bool* was_packed_on_wire); - - // Returns true and fills extension if extension is found. - // Note to support packed repeated field compatibility, it also fills whether - // the tag on wire is packed, which can be different from - // extension->is_packed (whether packed=true is specified). - bool FindExtensionInfoFromFieldNumber(int wire_type, int field_number, - ExtensionFinder* extension_finder, - ExtensionInfo* extension, - bool* was_packed_on_wire); - - // Parses a single extension from the input. The input should start out - // positioned immediately after the wire tag. This method is called in - // ParseField() after field number and was_packed_on_wire is extracted from - // the wire tag and ExtensionInfo is found by the field number. - bool ParseFieldWithExtensionInfo(int field_number, - bool was_packed_on_wire, - const ExtensionInfo& extension, - io::CodedInputStream* input, - FieldSkipper* field_skipper); - - // Like ParseField(), but this method may parse singular message extensions - // lazily depending on the value of FLAGS_eagerly_parse_message_sets. - bool ParseFieldMaybeLazily(int wire_type, int field_number, - io::CodedInputStream* input, - ExtensionFinder* extension_finder, - MessageSetFieldSkipper* field_skipper); - - // Gets the extension with the given number, creating it if it does not - // already exist. Returns true if the extension did not already exist. - bool MaybeNewExtension(int number, const FieldDescriptor* descriptor, - Extension** result); - - // Gets the repeated extension for the given descriptor, creating it if - // it does not exist. - Extension* MaybeNewRepeatedExtension(const FieldDescriptor* descriptor); - - // Parse a single MessageSet item -- called just after the item group start - // tag has been read. - bool ParseMessageSetItem(io::CodedInputStream* input, - ExtensionFinder* extension_finder, - MessageSetFieldSkipper* field_skipper); - - // Hack: RepeatedPtrFieldBase declares ExtensionSet as a friend. This - // friendship should automatically extend to ExtensionSet::Extension, but - // unfortunately some older compilers (e.g. GCC 3.4.4) do not implement this - // correctly. So, we must provide helpers for calling methods of that - // class. - - // Defined in extension_set_heavy.cc. - static inline int RepeatedMessage_SpaceUsedExcludingSelf( - RepeatedPtrFieldBase* field); - - // The Extension struct is small enough to be passed by value, so we use it - // directly as the value type in the map rather than use pointers. We use - // a map rather than hash_map here because we expect most ExtensionSets will - // only contain a small number of extensions whereas hash_map is optimized - // for 100 elements or more. Also, we want AppendToList() to order fields - // by field number. - ExtensionMap extensions_; - ::google::protobuf::Arena* arena_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ExtensionSet); -}; - -// These are just for convenience... -inline void ExtensionSet::SetString(int number, FieldType type, - const string& value, - const FieldDescriptor* descriptor) { - MutableString(number, type, descriptor)->assign(value); -} -inline void ExtensionSet::SetRepeatedString(int number, int index, - const string& value) { - MutableRepeatedString(number, index)->assign(value); -} -inline void ExtensionSet::AddString(int number, FieldType type, - const string& value, - const FieldDescriptor* descriptor) { - AddString(number, type, descriptor)->assign(value); -} - -// =================================================================== -// Glue for generated extension accessors - -// ------------------------------------------------------------------- -// Template magic - -// First we have a set of classes representing "type traits" for different -// field types. A type traits class knows how to implement basic accessors -// for extensions of a particular type given an ExtensionSet. The signature -// for a type traits class looks like this: -// -// class TypeTraits { -// public: -// typedef ? ConstType; -// typedef ? MutableType; -// // TypeTraits for singular fields and repeated fields will define the -// // symbol "Singular" or "Repeated" respectively. These two symbols will -// // be used in extension accessors to distinguish between singular -// // extensions and repeated extensions. If the TypeTraits for the passed -// // in extension doesn't have the expected symbol defined, it means the -// // user is passing a repeated extension to a singular accessor, or the -// // opposite. In that case the C++ compiler will generate an error -// // message "no matching member function" to inform the user. -// typedef ? Singular -// typedef ? Repeated -// -// static inline ConstType Get(int number, const ExtensionSet& set); -// static inline void Set(int number, ConstType value, ExtensionSet* set); -// static inline MutableType Mutable(int number, ExtensionSet* set); -// -// // Variants for repeated fields. -// static inline ConstType Get(int number, const ExtensionSet& set, -// int index); -// static inline void Set(int number, int index, -// ConstType value, ExtensionSet* set); -// static inline MutableType Mutable(int number, int index, -// ExtensionSet* set); -// static inline void Add(int number, ConstType value, ExtensionSet* set); -// static inline MutableType Add(int number, ExtensionSet* set); -// }; -// -// Not all of these methods make sense for all field types. For example, the -// "Mutable" methods only make sense for strings and messages, and the -// repeated methods only make sense for repeated types. So, each type -// traits class implements only the set of methods from this signature that it -// actually supports. This will cause a compiler error if the user tries to -// access an extension using a method that doesn't make sense for its type. -// For example, if "foo" is an extension of type "optional int32", then if you -// try to write code like: -// my_message.MutableExtension(foo) -// you will get a compile error because PrimitiveTypeTraits does not -// have a "Mutable()" method. - -// ------------------------------------------------------------------- -// PrimitiveTypeTraits - -// Since the ExtensionSet has different methods for each primitive type, -// we must explicitly define the methods of the type traits class for each -// known type. -template -class PrimitiveTypeTraits { - public: - typedef Type ConstType; - typedef Type MutableType; - typedef PrimitiveTypeTraits Singular; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value); - static inline void Set(int number, FieldType field_type, - ConstType value, ExtensionSet* set); -}; - -template -class RepeatedPrimitiveTypeTraits { - public: - typedef Type ConstType; - typedef Type MutableType; - typedef RepeatedPrimitiveTypeTraits Repeated; - - typedef RepeatedField RepeatedFieldType; - - static inline Type Get(int number, const ExtensionSet& set, int index); - static inline void Set(int number, int index, Type value, ExtensionSet* set); - static inline void Add(int number, FieldType field_type, - bool is_packed, Type value, ExtensionSet* set); - - static inline const RepeatedField& - GetRepeated(int number, const ExtensionSet& set); - static inline RepeatedField* - MutableRepeated(int number, FieldType field_type, - bool is_packed, ExtensionSet* set); - - static const RepeatedFieldType* GetDefaultRepeatedField(); -}; - -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_primitive_generic_type_traits_once_init_; - -class LIBPROTOBUF_EXPORT RepeatedPrimitiveGenericTypeTraits { - private: - template friend class RepeatedPrimitiveTypeTraits; - static void InitializeDefaultRepeatedFields(); - static void DestroyDefaultRepeatedFields(); - static const RepeatedField* default_repeated_field_int32_; - static const RepeatedField* default_repeated_field_int64_; - static const RepeatedField* default_repeated_field_uint32_; - static const RepeatedField* default_repeated_field_uint64_; - static const RepeatedField* default_repeated_field_double_; - static const RepeatedField* default_repeated_field_float_; - static const RepeatedField* default_repeated_field_bool_; -}; - -#define PROTOBUF_DEFINE_PRIMITIVE_TYPE(TYPE, METHOD) \ -template<> inline TYPE PrimitiveTypeTraits::Get( \ - int number, const ExtensionSet& set, TYPE default_value) { \ - return set.Get##METHOD(number, default_value); \ -} \ -template<> inline void PrimitiveTypeTraits::Set( \ - int number, FieldType field_type, TYPE value, ExtensionSet* set) { \ - set->Set##METHOD(number, field_type, value, NULL); \ -} \ - \ -template<> inline TYPE RepeatedPrimitiveTypeTraits::Get( \ - int number, const ExtensionSet& set, int index) { \ - return set.GetRepeated##METHOD(number, index); \ -} \ -template<> inline void RepeatedPrimitiveTypeTraits::Set( \ - int number, int index, TYPE value, ExtensionSet* set) { \ - set->SetRepeated##METHOD(number, index, value); \ -} \ -template<> inline void RepeatedPrimitiveTypeTraits::Add( \ - int number, FieldType field_type, bool is_packed, \ - TYPE value, ExtensionSet* set) { \ - set->Add##METHOD(number, field_type, is_packed, value, NULL); \ -} \ -template<> inline const RepeatedField* \ - RepeatedPrimitiveTypeTraits::GetDefaultRepeatedField() { \ - ::google::protobuf::GoogleOnceInit( \ - &repeated_primitive_generic_type_traits_once_init_, \ - &RepeatedPrimitiveGenericTypeTraits::InitializeDefaultRepeatedFields); \ - return RepeatedPrimitiveGenericTypeTraits:: \ - default_repeated_field_##TYPE##_; \ -} \ -template<> inline const RepeatedField& \ - RepeatedPrimitiveTypeTraits::GetRepeated(int number, \ - const ExtensionSet& set) { \ - return *reinterpret_cast*>( \ - set.GetRawRepeatedField( \ - number, GetDefaultRepeatedField())); \ -} \ -template<> inline RepeatedField* \ - RepeatedPrimitiveTypeTraits::MutableRepeated(int number, \ - FieldType field_type, \ - bool is_packed, \ - ExtensionSet* set) { \ - return reinterpret_cast*>( \ - set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); \ -} - -PROTOBUF_DEFINE_PRIMITIVE_TYPE( int32, Int32) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( int64, Int64) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint32, UInt32) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(uint64, UInt64) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( float, Float) -PROTOBUF_DEFINE_PRIMITIVE_TYPE(double, Double) -PROTOBUF_DEFINE_PRIMITIVE_TYPE( bool, Bool) - -#undef PROTOBUF_DEFINE_PRIMITIVE_TYPE - -// ------------------------------------------------------------------- -// StringTypeTraits - -// Strings support both Set() and Mutable(). -class LIBPROTOBUF_EXPORT StringTypeTraits { - public: - typedef const string& ConstType; - typedef string* MutableType; - typedef StringTypeTraits Singular; - - static inline const string& Get(int number, const ExtensionSet& set, - ConstType default_value) { - return set.GetString(number, default_value); - } - static inline void Set(int number, FieldType field_type, - const string& value, ExtensionSet* set) { - set->SetString(number, field_type, value, NULL); - } - static inline string* Mutable(int number, FieldType field_type, - ExtensionSet* set) { - return set->MutableString(number, field_type, NULL); - } -}; - -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_string_type_traits_once_init_; - -class LIBPROTOBUF_EXPORT RepeatedStringTypeTraits { - public: - typedef const string& ConstType; - typedef string* MutableType; - typedef RepeatedStringTypeTraits Repeated; - - typedef RepeatedPtrField RepeatedFieldType; - - static inline const string& Get(int number, const ExtensionSet& set, - int index) { - return set.GetRepeatedString(number, index); - } - static inline void Set(int number, int index, - const string& value, ExtensionSet* set) { - set->SetRepeatedString(number, index, value); - } - static inline string* Mutable(int number, int index, ExtensionSet* set) { - return set->MutableRepeatedString(number, index); - } - static inline void Add(int number, FieldType field_type, - bool /*is_packed*/, const string& value, - ExtensionSet* set) { - set->AddString(number, field_type, value, NULL); - } - static inline string* Add(int number, FieldType field_type, - ExtensionSet* set) { - return set->AddString(number, field_type, NULL); - } - static inline const RepeatedPtrField& - GetRepeated(int number, const ExtensionSet& set) { - return *reinterpret_cast*>( - set.GetRawRepeatedField(number, GetDefaultRepeatedField())); - } - - static inline RepeatedPtrField* - MutableRepeated(int number, FieldType field_type, - bool is_packed, ExtensionSet* set) { - return reinterpret_cast*>( - set->MutableRawRepeatedField(number, field_type, - is_packed, NULL)); - } - - static const RepeatedFieldType* GetDefaultRepeatedField() { - ::google::protobuf::GoogleOnceInit(&repeated_string_type_traits_once_init_, - &InitializeDefaultRepeatedFields); - return default_repeated_field_; - } - - private: - static void InitializeDefaultRepeatedFields(); - static void DestroyDefaultRepeatedFields(); - static const RepeatedFieldType *default_repeated_field_; -}; - -// ------------------------------------------------------------------- -// EnumTypeTraits - -// ExtensionSet represents enums using integers internally, so we have to -// static_cast around. -template -class EnumTypeTraits { - public: - typedef Type ConstType; - typedef Type MutableType; - typedef EnumTypeTraits Singular; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value) { - return static_cast(set.GetEnum(number, default_value)); - } - static inline void Set(int number, FieldType field_type, - ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->SetEnum(number, field_type, value, NULL); - } -}; - -template -class RepeatedEnumTypeTraits { - public: - typedef Type ConstType; - typedef Type MutableType; - typedef RepeatedEnumTypeTraits Repeated; - - typedef RepeatedField RepeatedFieldType; - - static inline ConstType Get(int number, const ExtensionSet& set, int index) { - return static_cast(set.GetRepeatedEnum(number, index)); - } - static inline void Set(int number, int index, - ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->SetRepeatedEnum(number, index, value); - } - static inline void Add(int number, FieldType field_type, - bool is_packed, ConstType value, ExtensionSet* set) { - GOOGLE_DCHECK(IsValid(value)); - set->AddEnum(number, field_type, is_packed, value, NULL); - } - static inline const RepeatedField& GetRepeated(int number, - const ExtensionSet& - set) { - // Hack: the `Extension` struct stores a RepeatedField for enums. - // RepeatedField cannot implicitly convert to RepeatedField - // so we need to do some casting magic. See message.h for similar - // contortions for non-extension fields. - return *reinterpret_cast*>( - set.GetRawRepeatedField(number, GetDefaultRepeatedField())); - } - - static inline RepeatedField* MutableRepeated(int number, - FieldType field_type, - bool is_packed, - ExtensionSet* set) { - return reinterpret_cast*>( - set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); - } - - static const RepeatedFieldType* GetDefaultRepeatedField() { - // Hack: as noted above, repeated enum fields are internally stored as a - // RepeatedField. We need to be able to instantiate global static - // objects to return as default (empty) repeated fields on non-existent - // extensions. We would not be able to know a-priori all of the enum types - // (values of |Type|) to instantiate all of these, so we just re-use int32's - // default repeated field object. - return reinterpret_cast*>( - RepeatedPrimitiveTypeTraits::GetDefaultRepeatedField()); - } -}; - -// ------------------------------------------------------------------- -// MessageTypeTraits - -// ExtensionSet guarantees that when manipulating extensions with message -// types, the implementation used will be the compiled-in class representing -// that type. So, we can static_cast down to the exact type we expect. -template -class MessageTypeTraits { - public: - typedef const Type& ConstType; - typedef Type* MutableType; - typedef MessageTypeTraits Singular; - - static inline ConstType Get(int number, const ExtensionSet& set, - ConstType default_value) { - return static_cast( - set.GetMessage(number, default_value)); - } - static inline MutableType Mutable(int number, FieldType field_type, - ExtensionSet* set) { - return static_cast( - set->MutableMessage(number, field_type, Type::default_instance(), NULL)); - } - static inline void SetAllocated(int number, FieldType field_type, - MutableType message, ExtensionSet* set) { - set->SetAllocatedMessage(number, field_type, NULL, message); - } - static inline void UnsafeArenaSetAllocated(int number, FieldType field_type, - MutableType message, - ExtensionSet* set) { - set->UnsafeArenaSetAllocatedMessage(number, field_type, NULL, message); - } - static inline MutableType Release(int number, FieldType /* field_type */, - ExtensionSet* set) { - return static_cast(set->ReleaseMessage( - number, Type::default_instance())); - } - static inline MutableType UnsafeArenaRelease(int number, - FieldType /* field_type */, - ExtensionSet* set) { - return static_cast(set->UnsafeArenaReleaseMessage( - number, Type::default_instance())); - } -}; - -// forward declaration -class RepeatedMessageGenericTypeTraits; - -template -class RepeatedMessageTypeTraits { - public: - typedef const Type& ConstType; - typedef Type* MutableType; - typedef RepeatedMessageTypeTraits Repeated; - - typedef RepeatedPtrField RepeatedFieldType; - - static inline ConstType Get(int number, const ExtensionSet& set, int index) { - return static_cast(set.GetRepeatedMessage(number, index)); - } - static inline MutableType Mutable(int number, int index, ExtensionSet* set) { - return static_cast(set->MutableRepeatedMessage(number, index)); - } - static inline MutableType Add(int number, FieldType field_type, - ExtensionSet* set) { - return static_cast( - set->AddMessage(number, field_type, Type::default_instance(), NULL)); - } - static inline const RepeatedPtrField& GetRepeated(int number, - const ExtensionSet& - set) { - // See notes above in RepeatedEnumTypeTraits::GetRepeated(): same - // casting hack applies here, because a RepeatedPtrField - // cannot naturally become a RepeatedPtrType even though Type is - // presumably a message. google::protobuf::Message goes through similar contortions - // with a reinterpret_cast<>. - return *reinterpret_cast*>( - set.GetRawRepeatedField(number, GetDefaultRepeatedField())); - } - static inline RepeatedPtrField* MutableRepeated(int number, - FieldType field_type, - bool is_packed, - ExtensionSet* set) { - return reinterpret_cast*>( - set->MutableRawRepeatedField(number, field_type, is_packed, NULL)); - } - - static const RepeatedFieldType* GetDefaultRepeatedField(); -}; - -LIBPROTOBUF_EXPORT extern ProtobufOnceType repeated_message_generic_type_traits_once_init_; - -// This class exists only to hold a generic default empty repeated field for all -// message-type repeated field extensions. -class LIBPROTOBUF_EXPORT RepeatedMessageGenericTypeTraits { - public: - typedef RepeatedPtrField< ::google::protobuf::MessageLite*> RepeatedFieldType; - private: - template friend class RepeatedMessageTypeTraits; - static void InitializeDefaultRepeatedFields(); - static void DestroyDefaultRepeatedFields(); - static const RepeatedFieldType* default_repeated_field_; -}; - -template inline - const typename RepeatedMessageTypeTraits::RepeatedFieldType* - RepeatedMessageTypeTraits::GetDefaultRepeatedField() { - ::google::protobuf::GoogleOnceInit( - &repeated_message_generic_type_traits_once_init_, - &RepeatedMessageGenericTypeTraits::InitializeDefaultRepeatedFields); - return reinterpret_cast( - RepeatedMessageGenericTypeTraits::default_repeated_field_); -} - -// ------------------------------------------------------------------- -// ExtensionIdentifier - -// This is the type of actual extension objects. E.g. if you have: -// extends Foo with optional int32 bar = 1234; -// then "bar" will be defined in C++ as: -// ExtensionIdentifier, 1, false> bar(1234); -// -// Note that we could, in theory, supply the field number as a template -// parameter, and thus make an instance of ExtensionIdentifier have no -// actual contents. However, if we did that, then using at extension -// identifier would not necessarily cause the compiler to output any sort -// of reference to any simple defined in the extension's .pb.o file. Some -// linkers will actually drop object files that are not explicitly referenced, -// but that would be bad because it would cause this extension to not be -// registered at static initialization, and therefore using it would crash. - -template -class ExtensionIdentifier { - public: - typedef TypeTraitsType TypeTraits; - typedef ExtendeeType Extendee; - - ExtensionIdentifier(int number, typename TypeTraits::ConstType default_value) - : number_(number), default_value_(default_value) {} - inline int number() const { return number_; } - typename TypeTraits::ConstType default_value() const { - return default_value_; - } - - private: - const int number_; - typename TypeTraits::ConstType default_value_; -}; - -// ------------------------------------------------------------------- -// Generated accessors - -// This macro should be expanded in the context of a generated type which -// has extensions. -// -// We use "_proto_TypeTraits" as a type name below because "TypeTraits" -// causes problems if the class has a nested message or enum type with that -// name and "_TypeTraits" is technically reserved for the C++ library since -// it starts with an underscore followed by a capital letter. -// -// For similar reason, we use "_field_type" and "_is_packed" as parameter names -// below, so that "field_type" and "is_packed" can be used as field names. -#define GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(CLASSNAME) \ - /* Has, Size, Clear */ \ - template \ - inline bool HasExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \ - return _extensions_.Has(id.number()); \ - } \ - \ - template \ - inline void ClearExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \ - _extensions_.ClearExtension(id.number()); \ - } \ - \ - template \ - inline int ExtensionSize( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \ - return _extensions_.ExtensionSize(id.number()); \ - } \ - \ - /* Singular accessors */ \ - template \ - inline typename _proto_TypeTraits::Singular::ConstType GetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) const { \ - return _proto_TypeTraits::Get(id.number(), _extensions_, \ - id.default_value()); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::Singular::MutableType MutableExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \ - return _proto_TypeTraits::Mutable(id.number(), _field_type, \ - &_extensions_); \ - } \ - \ - template \ - inline void SetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - typename _proto_TypeTraits::Singular::ConstType value) { \ - _proto_TypeTraits::Set(id.number(), _field_type, value, &_extensions_); \ - } \ - \ - template \ - inline void SetAllocatedExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - typename _proto_TypeTraits::Singular::MutableType value) { \ - _proto_TypeTraits::SetAllocated(id.number(), _field_type, \ - value, &_extensions_); \ - } \ - template \ - inline void UnsafeArenaSetAllocatedExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - typename _proto_TypeTraits::Singular::MutableType value) { \ - _proto_TypeTraits::UnsafeArenaSetAllocated(id.number(), _field_type, \ - value, &_extensions_); \ - } \ - template \ - inline typename _proto_TypeTraits::Singular::MutableType ReleaseExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \ - return _proto_TypeTraits::Release(id.number(), _field_type, \ - &_extensions_); \ - } \ - template \ - inline typename _proto_TypeTraits::Singular::MutableType \ - UnsafeArenaReleaseExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \ - return _proto_TypeTraits::UnsafeArenaRelease(id.number(), _field_type, \ - &_extensions_); \ - } \ - \ - /* Repeated accessors */ \ - template \ - inline typename _proto_TypeTraits::Repeated::ConstType GetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - int index) const { \ - return _proto_TypeTraits::Get(id.number(), _extensions_, index); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::Repeated::MutableType MutableExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - int index) { \ - return _proto_TypeTraits::Mutable(id.number(), index, &_extensions_); \ - } \ - \ - template \ - inline void SetExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - int index, typename _proto_TypeTraits::Repeated::ConstType value) { \ - _proto_TypeTraits::Set(id.number(), index, value, &_extensions_); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::Repeated::MutableType AddExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id) { \ - return _proto_TypeTraits::Add(id.number(), _field_type, &_extensions_); \ - } \ - \ - template \ - inline void AddExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, _is_packed>& id, \ - typename _proto_TypeTraits::Repeated::ConstType value) { \ - _proto_TypeTraits::Add(id.number(), _field_type, _is_packed, \ - value, &_extensions_); \ - } \ - \ - template \ - inline const typename _proto_TypeTraits::Repeated::RepeatedFieldType& \ - GetRepeatedExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, \ - _is_packed>& id) const { \ - return _proto_TypeTraits::GetRepeated(id.number(), _extensions_); \ - } \ - \ - template \ - inline typename _proto_TypeTraits::Repeated::RepeatedFieldType* \ - MutableRepeatedExtension( \ - const ::google::protobuf::internal::ExtensionIdentifier< \ - CLASSNAME, _proto_TypeTraits, _field_type, \ - _is_packed>& id) { \ - return _proto_TypeTraits::MutableRepeated(id.number(), _field_type, \ - _is_packed, &_extensions_); \ - } - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_EXTENSION_SET_H__ diff --git a/app/src/main/cpp/google/protobuf/field_mask.pb.h b/app/src/main/cpp/google/protobuf/field_mask.pb.h deleted file mode 100644 index 17cb6bb..0000000 --- a/app/src/main/cpp/google/protobuf/field_mask.pb.h +++ /dev/null @@ -1,214 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/field_mask.proto - -#ifndef PROTOBUF_google_2fprotobuf_2ffield_5fmask_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2ffield_5fmask_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto(); - -class FieldMask; - -// =================================================================== - -class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldMask) */ { - public: - FieldMask(); - virtual ~FieldMask(); - - FieldMask(const FieldMask& from); - - inline FieldMask& operator=(const FieldMask& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const FieldMask& default_instance(); - - static const FieldMask* internal_default_instance(); - - void Swap(FieldMask* other); - - // implements Message ---------------------------------------------- - - inline FieldMask* New() const { return New(NULL); } - - FieldMask* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const FieldMask& from); - void MergeFrom(const FieldMask& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(FieldMask* other); - void UnsafeMergeFrom(const FieldMask& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated string paths = 1; - int paths_size() const; - void clear_paths(); - static const int kPathsFieldNumber = 1; - const ::std::string& paths(int index) const; - ::std::string* mutable_paths(int index); - void set_paths(int index, const ::std::string& value); - void set_paths(int index, const char* value); - void set_paths(int index, const char* value, size_t size); - ::std::string* add_paths(); - void add_paths(const ::std::string& value); - void add_paths(const char* value); - void add_paths(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& paths() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_paths(); - - // @@protoc_insertion_point(class_scope:google.protobuf.FieldMask) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::RepeatedPtrField< ::std::string> paths_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ffield_5fmask_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ffield_5fmask_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ffield_5fmask_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ffield_5fmask_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed FieldMask_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// FieldMask - -// repeated string paths = 1; -inline int FieldMask::paths_size() const { - return paths_.size(); -} -inline void FieldMask::clear_paths() { - paths_.Clear(); -} -inline const ::std::string& FieldMask::paths(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.FieldMask.paths) - return paths_.Get(index); -} -inline ::std::string* FieldMask::mutable_paths(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.FieldMask.paths) - return paths_.Mutable(index); -} -inline void FieldMask::set_paths(int index, const ::std::string& value) { - // @@protoc_insertion_point(field_set:google.protobuf.FieldMask.paths) - paths_.Mutable(index)->assign(value); -} -inline void FieldMask::set_paths(int index, const char* value) { - paths_.Mutable(index)->assign(value); - // @@protoc_insertion_point(field_set_char:google.protobuf.FieldMask.paths) -} -inline void FieldMask::set_paths(int index, const char* value, size_t size) { - paths_.Mutable(index)->assign( - reinterpret_cast(value), size); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.FieldMask.paths) -} -inline ::std::string* FieldMask::add_paths() { - // @@protoc_insertion_point(field_add_mutable:google.protobuf.FieldMask.paths) - return paths_.Add(); -} -inline void FieldMask::add_paths(const ::std::string& value) { - paths_.Add()->assign(value); - // @@protoc_insertion_point(field_add:google.protobuf.FieldMask.paths) -} -inline void FieldMask::add_paths(const char* value) { - paths_.Add()->assign(value); - // @@protoc_insertion_point(field_add_char:google.protobuf.FieldMask.paths) -} -inline void FieldMask::add_paths(const char* value, size_t size) { - paths_.Add()->assign(reinterpret_cast(value), size); - // @@protoc_insertion_point(field_add_pointer:google.protobuf.FieldMask.paths) -} -inline const ::google::protobuf::RepeatedPtrField< ::std::string>& -FieldMask::paths() const { - // @@protoc_insertion_point(field_list:google.protobuf.FieldMask.paths) - return paths_; -} -inline ::google::protobuf::RepeatedPtrField< ::std::string>* -FieldMask::mutable_paths() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.FieldMask.paths) - return &paths_; -} - -inline const FieldMask* FieldMask::internal_default_instance() { - return &FieldMask_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2ffield_5fmask_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/field_mask.proto b/app/src/main/cpp/google/protobuf/field_mask.proto deleted file mode 100644 index b6d32a7..0000000 --- a/app/src/main/cpp/google/protobuf/field_mask.proto +++ /dev/null @@ -1,245 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "FieldMaskProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// `FieldMask` represents a set of symbolic field paths, for example: -// -// paths: "f.a" -// paths: "f.b.d" -// -// Here `f` represents a field in some root message, `a` and `b` -// fields in the message found in `f`, and `d` a field found in the -// message in `f.b`. -// -// Field masks are used to specify a subset of fields that should be -// returned by a get operation or modified by an update operation. -// Field masks also have a custom JSON encoding (see below). -// -// # Field Masks in Projections -// -// When used in the context of a projection, a response message or -// sub-message is filtered by the API to only contain those fields as -// specified in the mask. For example, if the mask in the previous -// example is applied to a response message as follows: -// -// f { -// a : 22 -// b { -// d : 1 -// x : 2 -// } -// y : 13 -// } -// z: 8 -// -// The result will not contain specific values for fields x,y and z -// (their value will be set to the default, and omitted in proto text -// output): -// -// -// f { -// a : 22 -// b { -// d : 1 -// } -// } -// -// A repeated field is not allowed except at the last position of a -// paths string. -// -// If a FieldMask object is not present in a get operation, the -// operation applies to all fields (as if a FieldMask of all fields -// had been specified). -// -// Note that a field mask does not necessarily apply to the -// top-level response message. In case of a REST get operation, the -// field mask applies directly to the response, but in case of a REST -// list operation, the mask instead applies to each individual message -// in the returned resource list. In case of a REST custom method, -// other definitions may be used. Where the mask applies will be -// clearly documented together with its declaration in the API. In -// any case, the effect on the returned resource/resources is required -// behavior for APIs. -// -// # Field Masks in Update Operations -// -// A field mask in update operations specifies which fields of the -// targeted resource are going to be updated. The API is required -// to only change the values of the fields as specified in the mask -// and leave the others untouched. If a resource is passed in to -// describe the updated values, the API ignores the values of all -// fields not covered by the mask. -// -// If a repeated field is specified for an update operation, the existing -// repeated values in the target resource will be overwritten by the new values. -// Note that a repeated field is only allowed in the last position of a `paths` -// string. -// -// If a sub-message is specified in the last position of the field mask for an -// update operation, then the existing sub-message in the target resource is -// overwritten. Given the target message: -// -// f { -// b { -// d : 1 -// x : 2 -// } -// c : 1 -// } -// -// And an update message: -// -// f { -// b { -// d : 10 -// } -// } -// -// then if the field mask is: -// -// paths: "f.b" -// -// then the result will be: -// -// f { -// b { -// d : 10 -// } -// c : 1 -// } -// -// However, if the update mask was: -// -// paths: "f.b.d" -// -// then the result would be: -// -// f { -// b { -// d : 10 -// x : 2 -// } -// c : 1 -// } -// -// In order to reset a field's value to the default, the field must -// be in the mask and set to the default value in the provided resource. -// Hence, in order to reset all fields of a resource, provide a default -// instance of the resource and set all fields in the mask, or do -// not provide a mask as described below. -// -// If a field mask is not present on update, the operation applies to -// all fields (as if a field mask of all fields has been specified). -// Note that in the presence of schema evolution, this may mean that -// fields the client does not know and has therefore not filled into -// the request will be reset to their default. If this is unwanted -// behavior, a specific service may require a client to always specify -// a field mask, producing an error if not. -// -// As with get operations, the location of the resource which -// describes the updated values in the request message depends on the -// operation kind. In any case, the effect of the field mask is -// required to be honored by the API. -// -// ## Considerations for HTTP REST -// -// The HTTP kind of an update operation which uses a field mask must -// be set to PATCH instead of PUT in order to satisfy HTTP semantics -// (PUT must only be used for full updates). -// -// # JSON Encoding of Field Masks -// -// In JSON, a field mask is encoded as a single string where paths are -// separated by a comma. Fields name in each path are converted -// to/from lower-camel naming conventions. -// -// As an example, consider the following message declarations: -// -// message Profile { -// User user = 1; -// Photo photo = 2; -// } -// message User { -// string display_name = 1; -// string address = 2; -// } -// -// In proto a field mask for `Profile` may look as such: -// -// mask { -// paths: "user.display_name" -// paths: "photo" -// } -// -// In JSON, the same mask is represented as below: -// -// { -// mask: "user.displayName,photo" -// } -// -// # Field Masks and Oneof Fields -// -// Field masks treat fields in oneofs just as regular fields. Consider the -// following message: -// -// message SampleMessage { -// oneof test_oneof { -// string name = 4; -// SubMessage sub_message = 9; -// } -// } -// -// The field mask can be: -// -// mask { -// paths: "name" -// } -// -// Or: -// -// mask { -// paths: "sub_message" -// } -// -// Note that oneof type names ("test_oneof" in this case) cannot be used in -// paths. -message FieldMask { - // The set of field mask paths. - repeated string paths = 1; -} diff --git a/app/src/main/cpp/google/protobuf/generated_enum_reflection.h b/app/src/main/cpp/google/protobuf/generated_enum_reflection.h deleted file mode 100644 index fdcdc27..0000000 --- a/app/src/main/cpp/google/protobuf/generated_enum_reflection.h +++ /dev/null @@ -1,88 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: jasonh@google.com (Jason Hsueh) -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. -// It provides reflection support for generated enums, and is included in -// generated .pb.h files and should have minimal dependencies. The methods are -// implemented in generated_message_reflection.cc. - -#ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ -#define GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ - -#include - -#include -#include - -namespace google { -namespace protobuf { - class EnumDescriptor; -} // namespace protobuf - -namespace protobuf { - -// Returns the EnumDescriptor for enum type E, which must be a -// proto-declared enum type. Code generated by the protocol compiler -// will include specializations of this template for each enum type declared. -template -const EnumDescriptor* GetEnumDescriptor(); - -namespace internal { - -// Helper for EnumType_Parse functions: try to parse the string 'name' as an -// enum name of the given type, returning true and filling in value on success, -// or returning false and leaving value unchanged on failure. -LIBPROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, - const string& name, - int* value); - -template -bool ParseNamedEnum(const EnumDescriptor* descriptor, - const string& name, - EnumType* value) { - int tmp; - if (!ParseNamedEnum(descriptor, name, &tmp)) return false; - *value = static_cast(tmp); - return true; -} - -// Just a wrapper around printing the name of a value. The main point of this -// function is not to be inlined, so that you can do this without including -// descriptor.h. -LIBPROTOBUF_EXPORT const string& NameOfEnum(const EnumDescriptor* descriptor, int value); - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ diff --git a/app/src/main/cpp/google/protobuf/generated_enum_util.h b/app/src/main/cpp/google/protobuf/generated_enum_util.h deleted file mode 100644 index e424205..0000000 --- a/app/src/main/cpp/google/protobuf/generated_enum_util.h +++ /dev/null @@ -1,46 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__ -#define GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__ - -#include - -namespace google { -namespace protobuf { - -// This type trait can be used to cause templates to only match proto2 enum -// types. -template struct is_proto_enum : ::google::protobuf::internal::false_type {}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_ENUM_UTIL_H__ diff --git a/app/src/main/cpp/google/protobuf/generated_message_reflection.h b/app/src/main/cpp/google/protobuf/generated_message_reflection.h deleted file mode 100644 index 1413b11..0000000 --- a/app/src/main/cpp/google/protobuf/generated_message_reflection.h +++ /dev/null @@ -1,671 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ - -#include -#include -#include -#include -// TODO(jasonh): Remove this once the compiler change to directly include this -// is released to components. -#include -#include -#include -#include - - -namespace google { -namespace upb { -namespace google_opensource { -class GMR_Handlers; -} // namespace google_opensource -} // namespace upb - -namespace protobuf { -class DescriptorPool; -class MapKey; -class MapValueRef; -} - -namespace protobuf { -namespace internal { -class DefaultEmptyOneof; - -// Defined in this file. -class GeneratedMessageReflection; - -// Defined in other files. -class ExtensionSet; // extension_set.h - -// THIS CLASS IS NOT INTENDED FOR DIRECT USE. It is intended for use -// by generated code. This class is just a big hack that reduces code -// size. -// -// A GeneratedMessageReflection is an implementation of Reflection -// which expects all fields to be backed by simple variables located in -// memory. The locations are given using a base pointer and a set of -// offsets. -// -// It is required that the user represents fields of each type in a standard -// way, so that GeneratedMessageReflection can cast the void* pointer to -// the appropriate type. For primitive fields and string fields, each field -// should be represented using the obvious C++ primitive type. Enums and -// Messages are different: -// - Singular Message fields are stored as a pointer to a Message. These -// should start out NULL, except for in the default instance where they -// should start out pointing to other default instances. -// - Enum fields are stored as an int. This int must always contain -// a valid value, such that EnumDescriptor::FindValueByNumber() would -// not return NULL. -// - Repeated fields are stored as RepeatedFields or RepeatedPtrFields -// of whatever type the individual field would be. Strings and -// Messages use RepeatedPtrFields while everything else uses -// RepeatedFields. -class LIBPROTOBUF_EXPORT GeneratedMessageReflection : public Reflection { - public: - // Constructs a GeneratedMessageReflection. - // Parameters: - // descriptor: The descriptor for the message type being implemented. - // default_instance: The default instance of the message. This is only - // used to obtain pointers to default instances of embedded - // messages, which GetMessage() will return if the particular - // sub-message has not been initialized yet. (Thus, all - // embedded message fields *must* have non-NULL pointers - // in the default instance.) - // offsets: An array of ints giving the byte offsets, relative to - // the start of the message object, of each field. These can - // be computed at compile time using the - // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro, defined - // below. - // has_bits_offset: Offset in the message of an array of uint32s of size - // descriptor->field_count()/32, rounded up. This is a - // bitfield where each bit indicates whether or not the - // corresponding field of the message has been initialized. - // The bit for field index i is obtained by the expression: - // has_bits[i / 32] & (1 << (i % 32)) - // unknown_fields_offset: Offset in the message of the UnknownFieldSet for - // the message. - // extensions_offset: Offset in the message of the ExtensionSet for the - // message, or -1 if the message type has no extension - // ranges. - // pool: DescriptorPool to search for extension definitions. Only - // used by FindKnownExtensionByName() and - // FindKnownExtensionByNumber(). - // factory: MessageFactory to use to construct extension messages. - // object_size: The size of a message object of this type, as measured - // by sizeof(). - GeneratedMessageReflection(const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], int has_bits_offset, - int unknown_fields_offset, int extensions_offset, - const DescriptorPool* pool, - MessageFactory* factory, int object_size, - int arena_offset); - - // Similar with the construction above. Call this construction if the - // message has oneof definition. - // Parameters: - // offsets: An array of ints giving the byte offsets. - // For each oneof field, the offset is relative to the - // default_oneof_instance. These can be computed at compile - // time using the - // PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET() macro. - // For each none oneof field, the offset is related to - // the start of the message object. These can be computed - // at compile time using the - // GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET() macro. - // Besides offsets for all fields, this array also contains - // offsets for oneof unions. The offset of the i-th oneof - // union is offsets[descriptor->field_count() + i]. - // default_oneof_instance: The default instance of the oneofs. It is a - // struct holding the default value of all oneof fields - // for this message. It is only used to obtain pointers - // to default instances of oneof fields, which Get - // methods will return if the field is not set. - // oneof_case_offset: Offset in the message of an array of uint32s of - // size descriptor->oneof_decl_count(). Each uint32 - // indicates what field is set for each oneof. - // other parameters are the same with the construction above. - GeneratedMessageReflection(const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], int has_bits_offset, - int unknown_fields_offset, int extensions_offset, - const void* default_oneof_instance, - int oneof_case_offset, const DescriptorPool* pool, - MessageFactory* factory, int object_size, - int arena_offset); - ~GeneratedMessageReflection(); - - // Shorter-to-call helpers for the above two constructions that work if the - // pool and factory are the usual, namely, DescriptorPool::generated_pool() - // and MessageFactory::generated_factory(). - - static GeneratedMessageReflection* NewGeneratedMessageReflection( - const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, - const void* default_oneof_instance, - int oneof_case_offset, - int object_size, - int arena_offset, - int is_default_instance_offset = -1); - - static GeneratedMessageReflection* NewGeneratedMessageReflection( - const Descriptor* descriptor, - const Message* default_instance, - const int offsets[], - int has_bits_offset, - int unknown_fields_offset, - int extensions_offset, - int object_size, - int arena_offset, - int is_default_instance_offset = -1); - - // implements Reflection ------------------------------------------- - - const UnknownFieldSet& GetUnknownFields(const Message& message) const; - UnknownFieldSet* MutableUnknownFields(Message* message) const; - - int SpaceUsed(const Message& message) const; - - bool HasField(const Message& message, const FieldDescriptor* field) const; - int FieldSize(const Message& message, const FieldDescriptor* field) const; - void ClearField(Message* message, const FieldDescriptor* field) const; - bool HasOneof(const Message& message, - const OneofDescriptor* oneof_descriptor) const; - void ClearOneof(Message* message, const OneofDescriptor* field) const; - void RemoveLast(Message* message, const FieldDescriptor* field) const; - Message* ReleaseLast(Message* message, const FieldDescriptor* field) const; - void Swap(Message* message1, Message* message2) const; - void SwapFields(Message* message1, Message* message2, - const std::vector& fields) const; - void SwapElements(Message* message, const FieldDescriptor* field, - int index1, int index2) const; - void ListFields(const Message& message, - std::vector* output) const; - - int32 GetInt32 (const Message& message, - const FieldDescriptor* field) const; - int64 GetInt64 (const Message& message, - const FieldDescriptor* field) const; - uint32 GetUInt32(const Message& message, - const FieldDescriptor* field) const; - uint64 GetUInt64(const Message& message, - const FieldDescriptor* field) const; - float GetFloat (const Message& message, - const FieldDescriptor* field) const; - double GetDouble(const Message& message, - const FieldDescriptor* field) const; - bool GetBool (const Message& message, - const FieldDescriptor* field) const; - string GetString(const Message& message, - const FieldDescriptor* field) const; - const string& GetStringReference(const Message& message, - const FieldDescriptor* field, - string* scratch) const; - const EnumValueDescriptor* GetEnum(const Message& message, - const FieldDescriptor* field) const; - int GetEnumValue(const Message& message, - const FieldDescriptor* field) const; - const Message& GetMessage(const Message& message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - const FieldDescriptor* GetOneofFieldDescriptor( - const Message& message, - const OneofDescriptor* oneof_descriptor) const; - - private: - bool ContainsMapKey(const Message& message, - const FieldDescriptor* field, - const MapKey& key) const; - bool InsertOrLookupMapValue(Message* message, - const FieldDescriptor* field, - const MapKey& key, - MapValueRef* val) const; - bool DeleteMapValue(Message* message, - const FieldDescriptor* field, - const MapKey& key) const; - MapIterator MapBegin( - Message* message, - const FieldDescriptor* field) const; - MapIterator MapEnd( - Message* message, - const FieldDescriptor* field) const; - int MapSize(const Message& message, const FieldDescriptor* field) const; - - public: - void SetInt32 (Message* message, - const FieldDescriptor* field, int32 value) const; - void SetInt64 (Message* message, - const FieldDescriptor* field, int64 value) const; - void SetUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const; - void SetUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const; - void SetFloat (Message* message, - const FieldDescriptor* field, float value) const; - void SetDouble(Message* message, - const FieldDescriptor* field, double value) const; - void SetBool (Message* message, - const FieldDescriptor* field, bool value) const; - void SetString(Message* message, - const FieldDescriptor* field, - const string& value) const; - void SetEnum (Message* message, const FieldDescriptor* field, - const EnumValueDescriptor* value) const; - void SetEnumValue(Message* message, const FieldDescriptor* field, - int value) const; - Message* MutableMessage(Message* message, const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - void SetAllocatedMessage(Message* message, - Message* sub_message, - const FieldDescriptor* field) const; - Message* ReleaseMessage(Message* message, const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - int32 GetRepeatedInt32 (const Message& message, - const FieldDescriptor* field, int index) const; - int64 GetRepeatedInt64 (const Message& message, - const FieldDescriptor* field, int index) const; - uint32 GetRepeatedUInt32(const Message& message, - const FieldDescriptor* field, int index) const; - uint64 GetRepeatedUInt64(const Message& message, - const FieldDescriptor* field, int index) const; - float GetRepeatedFloat (const Message& message, - const FieldDescriptor* field, int index) const; - double GetRepeatedDouble(const Message& message, - const FieldDescriptor* field, int index) const; - bool GetRepeatedBool (const Message& message, - const FieldDescriptor* field, int index) const; - string GetRepeatedString(const Message& message, - const FieldDescriptor* field, int index) const; - const string& GetRepeatedStringReference(const Message& message, - const FieldDescriptor* field, - int index, string* scratch) const; - const EnumValueDescriptor* GetRepeatedEnum(const Message& message, - const FieldDescriptor* field, - int index) const; - int GetRepeatedEnumValue(const Message& message, - const FieldDescriptor* field, - int index) const; - const Message& GetRepeatedMessage(const Message& message, - const FieldDescriptor* field, - int index) const; - - // Set the value of a field. - void SetRepeatedInt32 (Message* message, - const FieldDescriptor* field, int index, int32 value) const; - void SetRepeatedInt64 (Message* message, - const FieldDescriptor* field, int index, int64 value) const; - void SetRepeatedUInt32(Message* message, - const FieldDescriptor* field, int index, uint32 value) const; - void SetRepeatedUInt64(Message* message, - const FieldDescriptor* field, int index, uint64 value) const; - void SetRepeatedFloat (Message* message, - const FieldDescriptor* field, int index, float value) const; - void SetRepeatedDouble(Message* message, - const FieldDescriptor* field, int index, double value) const; - void SetRepeatedBool (Message* message, - const FieldDescriptor* field, int index, bool value) const; - void SetRepeatedString(Message* message, - const FieldDescriptor* field, int index, - const string& value) const; - void SetRepeatedEnum(Message* message, const FieldDescriptor* field, - int index, const EnumValueDescriptor* value) const; - void SetRepeatedEnumValue(Message* message, const FieldDescriptor* field, - int index, int value) const; - // Get a mutable pointer to a field with a message type. - Message* MutableRepeatedMessage(Message* message, - const FieldDescriptor* field, - int index) const; - - void AddInt32 (Message* message, - const FieldDescriptor* field, int32 value) const; - void AddInt64 (Message* message, - const FieldDescriptor* field, int64 value) const; - void AddUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const; - void AddUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const; - void AddFloat (Message* message, - const FieldDescriptor* field, float value) const; - void AddDouble(Message* message, - const FieldDescriptor* field, double value) const; - void AddBool (Message* message, - const FieldDescriptor* field, bool value) const; - void AddString(Message* message, - const FieldDescriptor* field, const string& value) const; - void AddEnum(Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const; - void AddEnumValue(Message* message, - const FieldDescriptor* field, - int value) const; - Message* AddMessage(Message* message, const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - void AddAllocatedMessage( - Message* message, const FieldDescriptor* field, - Message* new_entry) const; - - const FieldDescriptor* FindKnownExtensionByName(const string& name) const; - const FieldDescriptor* FindKnownExtensionByNumber(int number) const; - - bool SupportsUnknownEnumValues() const; - - // This value for arena_offset_ indicates that there is no arena pointer in - // this message (e.g., old generated code). - static const int kNoArenaPointer = -1; - - // This value for unknown_field_offset_ indicates that there is no - // UnknownFieldSet in this message, and that instead, we are using the - // Zero-Overhead Arena Pointer trick. When this is the case, arena_offset_ - // actually indexes to an InternalMetadataWithArena instance, which can return - // either an arena pointer or an UnknownFieldSet or both. It is never the case - // that unknown_field_offset_ == kUnknownFieldSetInMetadata && arena_offset_ - // == kNoArenaPointer. - static const int kUnknownFieldSetInMetadata = -1; - - protected: - void* MutableRawRepeatedField( - Message* message, const FieldDescriptor* field, FieldDescriptor::CppType, - int ctype, const Descriptor* desc) const; - - const void* GetRawRepeatedField( - const Message& message, const FieldDescriptor* field, - FieldDescriptor::CppType, int ctype, - const Descriptor* desc) const; - - virtual MessageFactory* GetMessageFactory() const; - - virtual void* RepeatedFieldData( - Message* message, const FieldDescriptor* field, - FieldDescriptor::CppType cpp_type, - const Descriptor* message_type) const; - - private: - friend class GeneratedMessage; - - // To parse directly into a proto2 generated class, the class GMR_Handlers - // needs access to member offsets and hasbits. - friend class upb::google_opensource::GMR_Handlers; - - const Descriptor* descriptor_; - const Message* default_instance_; - const void* default_oneof_instance_; - const int* offsets_; - - int has_bits_offset_; - int oneof_case_offset_; - int unknown_fields_offset_; - int extensions_offset_; - int arena_offset_; - int object_size_; - - const DescriptorPool* descriptor_pool_; - MessageFactory* message_factory_; - - template - inline const Type& GetRaw(const Message& message, - const FieldDescriptor* field) const; - template - inline Type* MutableRaw(Message* message, - const FieldDescriptor* field) const; - template - inline const Type& DefaultRaw(const FieldDescriptor* field) const; - template - inline const Type& DefaultOneofRaw(const FieldDescriptor* field) const; - - inline const uint32* GetHasBits(const Message& message) const; - inline uint32* MutableHasBits(Message* message) const; - inline uint32 GetOneofCase( - const Message& message, - const OneofDescriptor* oneof_descriptor) const; - inline uint32* MutableOneofCase( - Message* message, - const OneofDescriptor* oneof_descriptor) const; - inline const ExtensionSet& GetExtensionSet(const Message& message) const; - inline ExtensionSet* MutableExtensionSet(Message* message) const; - inline Arena* GetArena(Message* message) const; - inline const internal::InternalMetadataWithArena& - GetInternalMetadataWithArena(const Message& message) const; - inline internal::InternalMetadataWithArena* - MutableInternalMetadataWithArena(Message* message) const; - - inline bool GetIsDefaultInstance(const Message& message) const; - - inline bool HasBit(const Message& message, - const FieldDescriptor* field) const; - inline void SetBit(Message* message, - const FieldDescriptor* field) const; - inline void ClearBit(Message* message, - const FieldDescriptor* field) const; - inline void SwapBit(Message* message1, - Message* message2, - const FieldDescriptor* field) const; - - // This function only swaps the field. Should swap corresponding has_bit - // before or after using this function. - void SwapField(Message* message1, - Message* message2, - const FieldDescriptor* field) const; - - void SwapOneofField(Message* message1, - Message* message2, - const OneofDescriptor* oneof_descriptor) const; - - inline bool HasOneofField(const Message& message, - const FieldDescriptor* field) const; - inline void SetOneofCase(Message* message, - const FieldDescriptor* field) const; - inline void ClearOneofField(Message* message, - const FieldDescriptor* field) const; - - template - inline const Type& GetField(const Message& message, - const FieldDescriptor* field) const; - template - inline void SetField(Message* message, - const FieldDescriptor* field, const Type& value) const; - template - inline Type* MutableField(Message* message, - const FieldDescriptor* field) const; - template - inline const Type& GetRepeatedField(const Message& message, - const FieldDescriptor* field, - int index) const; - template - inline const Type& GetRepeatedPtrField(const Message& message, - const FieldDescriptor* field, - int index) const; - template - inline void SetRepeatedField(Message* message, - const FieldDescriptor* field, int index, - Type value) const; - template - inline Type* MutableRepeatedField(Message* message, - const FieldDescriptor* field, - int index) const; - template - inline void AddField(Message* message, - const FieldDescriptor* field, const Type& value) const; - template - inline Type* AddField(Message* message, - const FieldDescriptor* field) const; - - int GetExtensionNumberOrDie(const Descriptor* type) const; - - // Internal versions of EnumValue API perform no checking. Called after checks - // by public methods. - void SetEnumValueInternal(Message* message, - const FieldDescriptor* field, - int value) const; - void SetRepeatedEnumValueInternal(Message* message, - const FieldDescriptor* field, - int index, - int value) const; - void AddEnumValueInternal(Message* message, - const FieldDescriptor* field, - int value) const; - - - Message* UnsafeArenaReleaseMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const; - - void UnsafeArenaSetAllocatedMessage(Message* message, - Message* sub_message, - const FieldDescriptor* field) const; - - internal::MapFieldBase* MapData( - Message* message, const FieldDescriptor* field) const; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratedMessageReflection); -}; - -// Returns the offset of the given field within the given aggregate type. -// This is equivalent to the ANSI C offsetof() macro. However, according -// to the C++ standard, offsetof() only works on POD types, and GCC -// enforces this requirement with a warning. In practice, this rule is -// unnecessarily strict; there is probably no compiler or platform on -// which the offsets of the direct fields of a class are non-constant. -// Fields inherited from superclasses *can* have non-constant offsets, -// but that's not what this macro will be used for. -#if defined(__clang__) -// For Clang we use __builtin_offsetof() and suppress the warning, -// to avoid Control Flow Integrity and UBSan vptr sanitizers from -// crashing while trying to validate the invalid reinterpet_casts. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Winvalid-offsetof\"") \ - __builtin_offsetof(TYPE, FIELD) \ - _Pragma("clang diagnostic pop") -#else -// Note that we calculate relative to the pointer value 16 here since if we -// just use zero, GCC complains about dereferencing a NULL pointer. We -// choose 16 rather than some other number just in case the compiler would -// be confused by an unaligned pointer. -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(TYPE, FIELD) \ - static_cast( \ - reinterpret_cast( \ - &reinterpret_cast(16)->FIELD) - \ - reinterpret_cast(16)) -#endif - -#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ - static_cast( \ - reinterpret_cast(&(ONEOF->FIELD)) \ - - reinterpret_cast(ONEOF)) - -// There are some places in proto2 where dynamic_cast would be useful as an -// optimization. For example, take Message::MergeFrom(const Message& other). -// For a given generated message FooMessage, we generate these two methods: -// void MergeFrom(const FooMessage& other); -// void MergeFrom(const Message& other); -// The former method can be implemented directly in terms of FooMessage's -// inline accessors, but the latter method must work with the reflection -// interface. However, if the parameter to the latter method is actually of -// type FooMessage, then we'd like to be able to just call the other method -// as an optimization. So, we use dynamic_cast to check this. -// -// That said, dynamic_cast requires RTTI, which many people like to disable -// for performance and code size reasons. When RTTI is not available, we -// still need to produce correct results. So, in this case we have to fall -// back to using reflection, which is what we would have done anyway if the -// objects were not of the exact same class. -// -// dynamic_cast_if_available() implements this logic. If RTTI is -// enabled, it does a dynamic_cast. If RTTI is disabled, it just returns -// NULL. -// -// If you need to compile without RTTI, simply #define GOOGLE_PROTOBUF_NO_RTTI. -// On MSVC, this should be detected automatically. -template -inline To dynamic_cast_if_available(From from) { -#if defined(GOOGLE_PROTOBUF_NO_RTTI) || (defined(_MSC_VER)&&!defined(_CPPRTTI)) - return NULL; -#else - return dynamic_cast(from); -#endif -} - -// Tries to downcast this message to a generated message type. -// Returns NULL if this class is not an instance of T. -// -// This is like dynamic_cast_if_available, except it works even when -// dynamic_cast is not available by using Reflection. However it only works -// with Message objects. -// -// TODO(haberman): can we remove dynamic_cast_if_available in favor of this? -template -T* DynamicCastToGenerated(const Message* from) { - // Compile-time assert that T is a generated type that has a - // default_instance() accessor, but avoid actually calling it. - const T&(*get_default_instance)() = &T::default_instance; - (void)get_default_instance; - - // Compile-time assert that T is a subclass of google::protobuf::Message. - const Message* unused = static_cast(NULL); - (void)unused; - -#if defined(GOOGLE_PROTOBUF_NO_RTTI) || \ - (defined(_MSC_VER) && !defined(_CPPRTTI)) - bool ok = &T::default_instance() == - from->GetReflection()->GetMessageFactory()->GetPrototype( - from->GetDescriptor()); - return ok ? down_cast(from) : NULL; -#else - return dynamic_cast(from); -#endif -} - -template -T* DynamicCastToGenerated(Message* from) { - const Message* message_const = from; - return const_cast(DynamicCastToGenerated(message_const)); -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_REFLECTION_H__ diff --git a/app/src/main/cpp/google/protobuf/generated_message_util.h b/app/src/main/cpp/google/protobuf/generated_message_util.h deleted file mode 100644 index 8dc64c4..0000000 --- a/app/src/main/cpp/google/protobuf/generated_message_util.h +++ /dev/null @@ -1,169 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains miscellaneous helper code used by generated code -- -// including lite types -- but which should not be used directly by users. - -#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ -#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ - -#include -#include - -#include -#include -#include - -namespace google { - -namespace protobuf { - -class Arena; -namespace io { class CodedInputStream; } - -namespace internal { - - -// Annotation for the compiler to emit a deprecation message if a field marked -// with option 'deprecated=true' is used in the code, or for other things in -// generated code which are deprecated. -// -// For internal use in the pb.cc files, deprecation warnings are suppressed -// there. -#undef DEPRECATED_PROTOBUF_FIELD -#define PROTOBUF_DEPRECATED - -#define GOOGLE_PROTOBUF_DEPRECATED_ATTR - - -// Constants for special floating point values. -LIBPROTOBUF_EXPORT double Infinity(); -LIBPROTOBUF_EXPORT double NaN(); - -// This type is used to define a global variable, without it's constructor -// and destructor run on start and end of the program lifetime. This circumvents -// the initial construction order fiasco, while keeping the address of the -// empty string a compile time constant. -template -class ExplicitlyConstructed { - public: - void DefaultConstruct() { - new (&union_) T(); - init_ = true; - } - - bool IsInitialized() { return init_; } - void Shutdown() { - if (init_) { - init_ = false; - get_mutable()->~T(); - } - } - - const T& get() const { return reinterpret_cast(union_); } - T* get_mutable() { return reinterpret_cast(&union_); } - - private: - // Prefer c++14 aligned_storage, but for compatibility this will do. - union AlignedUnion { - char space[sizeof(T)]; - int64 align_to_int64; - void* align_to_ptr; - } union_; - bool init_; // false by linker -}; - -// TODO(jieluo): Change to template. We have tried to use template, -// but it causes net/rpc/python:rpcutil_test fail (the empty string will -// init twice). It may related to swig. Change to template after we -// found the solution. - -// Default empty string object. Don't use this directly. Instead, call -// GetEmptyString() to get the reference. -extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; -LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; -LIBPROTOBUF_EXPORT void InitEmptyString(); - - -LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() { - return fixed_address_empty_string.get(); -} - -LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { - ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString); - return GetEmptyStringAlreadyInited(); -} - -LIBPROTOBUF_EXPORT int StringSpaceUsedExcludingSelf(const string& str); - - -// True if IsInitialized() is true for all elements of t. Type is expected -// to be a RepeatedPtrField. It's useful to have this -// helper here to keep the protobuf compiler from ever having to emit loops in -// IsInitialized() methods. We want the C++ compiler to inline this or not -// as it sees fit. -template bool AllAreInitialized(const Type& t) { - for (int i = t.size(); --i >= 0; ) { - if (!t.Get(i).IsInitialized()) return false; - } - return true; -} - -// Helper function to crash on merge failure. -// Moved out of generated code to reduce binary size. -LIBPROTOBUF_EXPORT void MergeFromFail(const char* file, int line) GOOGLE_ATTRIBUTE_NORETURN; - -// We compute sizes as size_t but cache them as int. This function converts a -// computed size to a cached size. Since we don't proceed with serialization if -// the total size was > INT_MAX, it is not important what this function returns -// for inputs > INT_MAX. -inline int ToCachedSize(size_t size) { - return static_cast(size); -} - -// We mainly calculate sizes in terms of size_t, but some functions that compute -// sizes return "int". These int sizes are expected to always be positive. -// This function is more efficient than casting an int to size_t directly on -// 64-bit platforms because it avoids making the compiler emit a sign extending -// instruction, which we don't want and don't want to pay for. -inline size_t FromIntSize(int size) { - // Convert to unsigned before widening so sign extension is not necessary. - return static_cast(size); -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_UTIL_H__ diff --git a/app/src/main/cpp/google/protobuf/has_bits.h b/app/src/main/cpp/google/protobuf/has_bits.h deleted file mode 100644 index 133bc02..0000000 --- a/app/src/main/cpp/google/protobuf/has_bits.h +++ /dev/null @@ -1,72 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_HAS_BITS_H__ -#define GOOGLE_PROTOBUF_HAS_BITS_H__ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -template -class HasBits { - public: - HasBits() GOOGLE_ATTRIBUTE_ALWAYS_INLINE { Clear(); } - - void Clear() GOOGLE_ATTRIBUTE_ALWAYS_INLINE { - memset(has_bits_, 0, sizeof(has_bits_)); - } - - ::google::protobuf::uint32& operator[](int index) GOOGLE_ATTRIBUTE_ALWAYS_INLINE { - return has_bits_[index]; - } - - const ::google::protobuf::uint32& operator[](int index) const GOOGLE_ATTRIBUTE_ALWAYS_INLINE { - return has_bits_[index]; - } - - bool operator==(const HasBits& rhs) const { - return memcmp(has_bits_, rhs.has_bits_, sizeof(has_bits_)) == 0; - } - - bool operator!=(const HasBits& rhs) const { - return !(*this == rhs); - } - private: - ::google::protobuf::uint32 has_bits_[doublewords]; -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_HAS_BITS_H__ diff --git a/app/src/main/cpp/google/protobuf/io/coded_stream.h b/app/src/main/cpp/google/protobuf/io/coded_stream.h deleted file mode 100644 index 1402cc1..0000000 --- a/app/src/main/cpp/google/protobuf/io/coded_stream.h +++ /dev/null @@ -1,1367 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains the CodedInputStream and CodedOutputStream classes, -// which wrap a ZeroCopyInputStream or ZeroCopyOutputStream, respectively, -// and allow you to read or write individual pieces of data in various -// formats. In particular, these implement the varint encoding for -// integers, a simple variable-length encoding in which smaller numbers -// take fewer bytes. -// -// Typically these classes will only be used internally by the protocol -// buffer library in order to encode and decode protocol buffers. Clients -// of the library only need to know about this class if they wish to write -// custom message parsing or serialization procedures. -// -// CodedOutputStream example: -// // Write some data to "myfile". First we write a 4-byte "magic number" -// // to identify the file type, then write a length-delimited string. The -// // string is composed of a varint giving the length followed by the raw -// // bytes. -// int fd = open("myfile", O_CREAT | O_WRONLY); -// ZeroCopyOutputStream* raw_output = new FileOutputStream(fd); -// CodedOutputStream* coded_output = new CodedOutputStream(raw_output); -// -// int magic_number = 1234; -// char text[] = "Hello world!"; -// coded_output->WriteLittleEndian32(magic_number); -// coded_output->WriteVarint32(strlen(text)); -// coded_output->WriteRaw(text, strlen(text)); -// -// delete coded_output; -// delete raw_output; -// close(fd); -// -// CodedInputStream example: -// // Read a file created by the above code. -// int fd = open("myfile", O_RDONLY); -// ZeroCopyInputStream* raw_input = new FileInputStream(fd); -// CodedInputStream coded_input = new CodedInputStream(raw_input); -// -// coded_input->ReadLittleEndian32(&magic_number); -// if (magic_number != 1234) { -// cerr << "File not in expected format." << endl; -// return; -// } -// -// uint32 size; -// coded_input->ReadVarint32(&size); -// -// char* text = new char[size + 1]; -// coded_input->ReadRaw(buffer, size); -// text[size] = '\0'; -// -// delete coded_input; -// delete raw_input; -// close(fd); -// -// cout << "Text is: " << text << endl; -// delete [] text; -// -// For those who are interested, varint encoding is defined as follows: -// -// The encoding operates on unsigned integers of up to 64 bits in length. -// Each byte of the encoded value has the format: -// * bits 0-6: Seven bits of the number being encoded. -// * bit 7: Zero if this is the last byte in the encoding (in which -// case all remaining bits of the number are zero) or 1 if -// more bytes follow. -// The first byte contains the least-significant 7 bits of the number, the -// second byte (if present) contains the next-least-significant 7 bits, -// and so on. So, the binary number 1011000101011 would be encoded in two -// bytes as "10101011 00101100". -// -// In theory, varint could be used to encode integers of any length. -// However, for practicality we set a limit at 64 bits. The maximum encoded -// length of a number is thus 10 bytes. - -#ifndef GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ - -#include -#include -#include -#ifdef _MSC_VER - // Assuming windows is always little-endian. - #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif - #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) - // If MSVC has "/RTCc" set, it will complain about truncating casts at - // runtime. This file contains some intentional truncating casts. - #pragma runtime_checks("c", off) - #endif -#else - #include // __BYTE_ORDER - #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \ - !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif -#endif -#include - -namespace google { - -namespace protobuf { - -class DescriptorPool; -class MessageFactory; - -namespace io { - -// Defined in this file. -class CodedInputStream; -class CodedOutputStream; - -// Defined in other files. -class ZeroCopyInputStream; // zero_copy_stream.h -class ZeroCopyOutputStream; // zero_copy_stream.h - -// Class which reads and decodes binary data which is composed of varint- -// encoded integers and fixed-width pieces. Wraps a ZeroCopyInputStream. -// Most users will not need to deal with CodedInputStream. -// -// Most methods of CodedInputStream that return a bool return false if an -// underlying I/O error occurs or if the data is malformed. Once such a -// failure occurs, the CodedInputStream is broken and is no longer useful. -class LIBPROTOBUF_EXPORT CodedInputStream { - public: - // Create a CodedInputStream that reads from the given ZeroCopyInputStream. - explicit CodedInputStream(ZeroCopyInputStream* input); - - // Create a CodedInputStream that reads from the given flat array. This is - // faster than using an ArrayInputStream. PushLimit(size) is implied by - // this constructor. - explicit CodedInputStream(const uint8* buffer, int size); - - // Destroy the CodedInputStream and position the underlying - // ZeroCopyInputStream at the first unread byte. If an error occurred while - // reading (causing a method to return false), then the exact position of - // the input stream may be anywhere between the last value that was read - // successfully and the stream's byte limit. - ~CodedInputStream(); - - // Return true if this CodedInputStream reads from a flat array instead of - // a ZeroCopyInputStream. - inline bool IsFlat() const; - - // Skips a number of bytes. Returns false if an underlying read error - // occurs. - bool Skip(int count); - - // Sets *data to point directly at the unread part of the CodedInputStream's - // underlying buffer, and *size to the size of that buffer, but does not - // advance the stream's current position. This will always either produce - // a non-empty buffer or return false. If the caller consumes any of - // this data, it should then call Skip() to skip over the consumed bytes. - // This may be useful for implementing external fast parsing routines for - // types of data not covered by the CodedInputStream interface. - bool GetDirectBufferPointer(const void** data, int* size); - - // Like GetDirectBufferPointer, but this method is inlined, and does not - // attempt to Refresh() if the buffer is currently empty. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void GetDirectBufferPointerInline(const void** data, - int* size); - - // Read raw bytes, copying them into the given buffer. - bool ReadRaw(void* buffer, int size); - - // Like the above, with inlined optimizations. This should only be used - // by the protobuf implementation. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadRawInline(void* buffer, int size); - - // Like ReadRaw, but reads into a string. - // - // Implementation Note: ReadString() grows the string gradually as it - // reads in the data, rather than allocating the entire requested size - // upfront. This prevents denial-of-service attacks in which a client - // could claim that a string is going to be MAX_INT bytes long in order to - // crash the server because it can't allocate this much space at once. - bool ReadString(string* buffer, int size); - // Like the above, with inlined optimizations. This should only be used - // by the protobuf implementation. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool InternalReadStringInline(string* buffer, - int size); - - - // Read a 32-bit little-endian integer. - bool ReadLittleEndian32(uint32* value); - // Read a 64-bit little-endian integer. - bool ReadLittleEndian64(uint64* value); - - // These methods read from an externally provided buffer. The caller is - // responsible for ensuring that the buffer has sufficient space. - // Read a 32-bit little-endian integer. - static const uint8* ReadLittleEndian32FromArray(const uint8* buffer, - uint32* value); - // Read a 64-bit little-endian integer. - static const uint8* ReadLittleEndian64FromArray(const uint8* buffer, - uint64* value); - - // Read an unsigned integer with Varint encoding, truncating to 32 bits. - // Reading a 32-bit value is equivalent to reading a 64-bit one and casting - // it to uint32, but may be more efficient. - bool ReadVarint32(uint32* value); - // Read an unsigned integer with Varint encoding. - bool ReadVarint64(uint64* value); - - // Reads a varint off the wire into an "int". This should be used for reading - // sizes off the wire (sizes of strings, submessages, bytes fields, etc). - // - // The value from the wire is interpreted as unsigned. If its value exceeds - // the representable value of an integer on this platform, instead of - // truncating we return false. Truncating (as performed by ReadVarint32() - // above) is an acceptable approach for fields representing an integer, but - // when we are parsing a size from the wire, truncating the value would result - // in us misparsing the payload. - bool ReadVarintSizeAsInt(int* value); - - // Read a tag. This calls ReadVarint32() and returns the result, or returns - // zero (which is not a valid tag) if ReadVarint32() fails. Also, it updates - // the last tag value, which can be checked with LastTagWas(). - // Always inline because this is only called in one place per parse loop - // but it is called for every iteration of said loop, so it should be fast. - // GCC doesn't want to inline this by default. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag(); - - // This usually a faster alternative to ReadTag() when cutoff is a manifest - // constant. It does particularly well for cutoff >= 127. The first part - // of the return value is the tag that was read, though it can also be 0 in - // the cases where ReadTag() would return 0. If the second part is true - // then the tag is known to be in [0, cutoff]. If not, the tag either is - // above cutoff or is 0. (There's intentional wiggle room when tag is 0, - // because that can arise in several ways, and for best performance we want - // to avoid an extra "is tag == 0?" check here.) - GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair ReadTagWithCutoff( - uint32 cutoff); - - // Usually returns true if calling ReadVarint32() now would produce the given - // value. Will always return false if ReadVarint32() would not return the - // given value. If ExpectTag() returns true, it also advances past - // the varint. For best performance, use a compile-time constant as the - // parameter. - // Always inline because this collapses to a small number of instructions - // when given a constant parameter, but GCC doesn't want to inline by default. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool ExpectTag(uint32 expected); - - // Like above, except this reads from the specified buffer. The caller is - // responsible for ensuring that the buffer is large enough to read a varint - // of the expected size. For best performance, use a compile-time constant as - // the expected tag parameter. - // - // Returns a pointer beyond the expected tag if it was found, or NULL if it - // was not. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static const uint8* ExpectTagFromArray( - const uint8* buffer, - uint32 expected); - - // Usually returns true if no more bytes can be read. Always returns false - // if more bytes can be read. If ExpectAtEnd() returns true, a subsequent - // call to LastTagWas() will act as if ReadTag() had been called and returned - // zero, and ConsumedEntireMessage() will return true. - bool ExpectAtEnd(); - - // If the last call to ReadTag() or ReadTagWithCutoff() returned the - // given value, returns true. Otherwise, returns false; - // - // This is needed because parsers for some types of embedded messages - // (with field type TYPE_GROUP) don't actually know that they've reached the - // end of a message until they see an ENDGROUP tag, which was actually part - // of the enclosing message. The enclosing message would like to check that - // tag to make sure it had the right number, so it calls LastTagWas() on - // return from the embedded parser to check. - bool LastTagWas(uint32 expected); - - // When parsing message (but NOT a group), this method must be called - // immediately after MergeFromCodedStream() returns (if it returns true) - // to further verify that the message ended in a legitimate way. For - // example, this verifies that parsing did not end on an end-group tag. - // It also checks for some cases where, due to optimizations, - // MergeFromCodedStream() can incorrectly return true. - bool ConsumedEntireMessage(); - - // Limits ---------------------------------------------------------- - // Limits are used when parsing length-delimited embedded messages. - // After the message's length is read, PushLimit() is used to prevent - // the CodedInputStream from reading beyond that length. Once the - // embedded message has been parsed, PopLimit() is called to undo the - // limit. - - // Opaque type used with PushLimit() and PopLimit(). Do not modify - // values of this type yourself. The only reason that this isn't a - // struct with private internals is for efficiency. - typedef int Limit; - - // Places a limit on the number of bytes that the stream may read, - // starting from the current position. Once the stream hits this limit, - // it will act like the end of the input has been reached until PopLimit() - // is called. - // - // As the names imply, the stream conceptually has a stack of limits. The - // shortest limit on the stack is always enforced, even if it is not the - // top limit. - // - // The value returned by PushLimit() is opaque to the caller, and must - // be passed unchanged to the corresponding call to PopLimit(). - Limit PushLimit(int byte_limit); - - // Pops the last limit pushed by PushLimit(). The input must be the value - // returned by that call to PushLimit(). - void PopLimit(Limit limit); - - // Returns the number of bytes left until the nearest limit on the - // stack is hit, or -1 if no limits are in place. - int BytesUntilLimit() const; - - // Returns current position relative to the beginning of the input stream. - int CurrentPosition() const; - - // Total Bytes Limit ----------------------------------------------- - // To prevent malicious users from sending excessively large messages - // and causing integer overflows or memory exhaustion, CodedInputStream - // imposes a hard limit on the total number of bytes it will read. - - // Sets the maximum number of bytes that this CodedInputStream will read - // before refusing to continue. To prevent integer overflows in the - // protocol buffers implementation, as well as to prevent servers from - // allocating enormous amounts of memory to hold parsed messages, the - // maximum message length should be limited to the shortest length that - // will not harm usability. The theoretical shortest message that could - // cause integer overflows is 512MB. The default limit is 64MB. Apps - // should set shorter limits if possible. If warning_threshold is not -1, - // a warning will be printed to stderr after warning_threshold bytes are - // read. For backwards compatibility all negative values get squashed to -1, - // as other negative values might have special internal meanings. - // An error will always be printed to stderr if the limit is reached. - // - // This is unrelated to PushLimit()/PopLimit(). - // - // Hint: If you are reading this because your program is printing a - // warning about dangerously large protocol messages, you may be - // confused about what to do next. The best option is to change your - // design such that excessively large messages are not necessary. - // For example, try to design file formats to consist of many small - // messages rather than a single large one. If this is infeasible, - // you will need to increase the limit. Chances are, though, that - // your code never constructs a CodedInputStream on which the limit - // can be set. You probably parse messages by calling things like - // Message::ParseFromString(). In this case, you will need to change - // your code to instead construct some sort of ZeroCopyInputStream - // (e.g. an ArrayInputStream), construct a CodedInputStream around - // that, then call Message::ParseFromCodedStream() instead. Then - // you can adjust the limit. Yes, it's more work, but you're doing - // something unusual. - void SetTotalBytesLimit(int total_bytes_limit, int warning_threshold); - - // The Total Bytes Limit minus the Current Position, or -1 if there - // is no Total Bytes Limit. - int BytesUntilTotalBytesLimit() const; - - // Recursion Limit ------------------------------------------------- - // To prevent corrupt or malicious messages from causing stack overflows, - // we must keep track of the depth of recursion when parsing embedded - // messages and groups. CodedInputStream keeps track of this because it - // is the only object that is passed down the stack during parsing. - - // Sets the maximum recursion depth. The default is 100. - void SetRecursionLimit(int limit); - - - // Increments the current recursion depth. Returns true if the depth is - // under the limit, false if it has gone over. - bool IncrementRecursionDepth(); - - // Decrements the recursion depth if possible. - void DecrementRecursionDepth(); - - // Decrements the recursion depth blindly. This is faster than - // DecrementRecursionDepth(). It should be used only if all previous - // increments to recursion depth were successful. - void UnsafeDecrementRecursionDepth(); - - // Shorthand for make_pair(PushLimit(byte_limit), --recursion_budget_). - // Using this can reduce code size and complexity in some cases. The caller - // is expected to check that the second part of the result is non-negative (to - // bail out if the depth of recursion is too high) and, if all is well, to - // later pass the first part of the result to PopLimit() or similar. - std::pair IncrementRecursionDepthAndPushLimit( - int byte_limit); - - // Shorthand for PushLimit(ReadVarint32(&length) ? length : 0). - Limit ReadLengthAndPushLimit(); - - // Helper that is equivalent to: { - // bool result = ConsumedEntireMessage(); - // PopLimit(limit); - // UnsafeDecrementRecursionDepth(); - // return result; } - // Using this can reduce code size and complexity in some cases. - // Do not use unless the current recursion depth is greater than zero. - bool DecrementRecursionDepthAndPopLimit(Limit limit); - - // Helper that is equivalent to: { - // bool result = ConsumedEntireMessage(); - // PopLimit(limit); - // return result; } - // Using this can reduce code size and complexity in some cases. - bool CheckEntireMessageConsumedAndPopLimit(Limit limit); - - // Extension Registry ---------------------------------------------- - // ADVANCED USAGE: 99.9% of people can ignore this section. - // - // By default, when parsing extensions, the parser looks for extension - // definitions in the pool which owns the outer message's Descriptor. - // However, you may call SetExtensionRegistry() to provide an alternative - // pool instead. This makes it possible, for example, to parse a message - // using a generated class, but represent some extensions using - // DynamicMessage. - - // Set the pool used to look up extensions. Most users do not need to call - // this as the correct pool will be chosen automatically. - // - // WARNING: It is very easy to misuse this. Carefully read the requirements - // below. Do not use this unless you are sure you need it. Almost no one - // does. - // - // Let's say you are parsing a message into message object m, and you want - // to take advantage of SetExtensionRegistry(). You must follow these - // requirements: - // - // The given DescriptorPool must contain m->GetDescriptor(). It is not - // sufficient for it to simply contain a descriptor that has the same name - // and content -- it must be the *exact object*. In other words: - // assert(pool->FindMessageTypeByName(m->GetDescriptor()->full_name()) == - // m->GetDescriptor()); - // There are two ways to satisfy this requirement: - // 1) Use m->GetDescriptor()->pool() as the pool. This is generally useless - // because this is the pool that would be used anyway if you didn't call - // SetExtensionRegistry() at all. - // 2) Use a DescriptorPool which has m->GetDescriptor()->pool() as an - // "underlay". Read the documentation for DescriptorPool for more - // information about underlays. - // - // You must also provide a MessageFactory. This factory will be used to - // construct Message objects representing extensions. The factory's - // GetPrototype() MUST return non-NULL for any Descriptor which can be found - // through the provided pool. - // - // If the provided factory might return instances of protocol-compiler- - // generated (i.e. compiled-in) types, or if the outer message object m is - // a generated type, then the given factory MUST have this property: If - // GetPrototype() is given a Descriptor which resides in - // DescriptorPool::generated_pool(), the factory MUST return the same - // prototype which MessageFactory::generated_factory() would return. That - // is, given a descriptor for a generated type, the factory must return an - // instance of the generated class (NOT DynamicMessage). However, when - // given a descriptor for a type that is NOT in generated_pool, the factory - // is free to return any implementation. - // - // The reason for this requirement is that generated sub-objects may be - // accessed via the standard (non-reflection) extension accessor methods, - // and these methods will down-cast the object to the generated class type. - // If the object is not actually of that type, the results would be undefined. - // On the other hand, if an extension is not compiled in, then there is no - // way the code could end up accessing it via the standard accessors -- the - // only way to access the extension is via reflection. When using reflection, - // DynamicMessage and generated messages are indistinguishable, so it's fine - // if these objects are represented using DynamicMessage. - // - // Using DynamicMessageFactory on which you have called - // SetDelegateToGeneratedFactory(true) should be sufficient to satisfy the - // above requirement. - // - // If either pool or factory is NULL, both must be NULL. - // - // Note that this feature is ignored when parsing "lite" messages as they do - // not have descriptors. - void SetExtensionRegistry(const DescriptorPool* pool, - MessageFactory* factory); - - // Get the DescriptorPool set via SetExtensionRegistry(), or NULL if no pool - // has been provided. - const DescriptorPool* GetExtensionPool(); - - // Get the MessageFactory set via SetExtensionRegistry(), or NULL if no - // factory has been provided. - MessageFactory* GetExtensionFactory(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedInputStream); - - const uint8* buffer_; - const uint8* buffer_end_; // pointer to the end of the buffer. - ZeroCopyInputStream* input_; - int total_bytes_read_; // total bytes read from input_, including - // the current buffer - - // If total_bytes_read_ surpasses INT_MAX, we record the extra bytes here - // so that we can BackUp() on destruction. - int overflow_bytes_; - - // LastTagWas() stuff. - uint32 last_tag_; // result of last ReadTag() or ReadTagWithCutoff(). - - // This is set true by ReadTag{Fallback/Slow}() if it is called when exactly - // at EOF, or by ExpectAtEnd() when it returns true. This happens when we - // reach the end of a message and attempt to read another tag. - bool legitimate_message_end_; - - // See EnableAliasing(). - bool aliasing_enabled_; - - // Limits - Limit current_limit_; // if position = -1, no limit is applied - - // For simplicity, if the current buffer crosses a limit (either a normal - // limit created by PushLimit() or the total bytes limit), buffer_size_ - // only tracks the number of bytes before that limit. This field - // contains the number of bytes after it. Note that this implies that if - // buffer_size_ == 0 and buffer_size_after_limit_ > 0, we know we've - // hit a limit. However, if both are zero, it doesn't necessarily mean - // we aren't at a limit -- the buffer may have ended exactly at the limit. - int buffer_size_after_limit_; - - // Maximum number of bytes to read, period. This is unrelated to - // current_limit_. Set using SetTotalBytesLimit(). - int total_bytes_limit_; - - // If positive/0: Limit for bytes read after which a warning due to size - // should be logged. - // If -1: Printing of warning disabled. Can be set by client. - // If -2: Internal: Limit has been reached, print full size when destructing. - int total_bytes_warning_threshold_; - - // Current recursion budget, controlled by IncrementRecursionDepth() and - // similar. Starts at recursion_limit_ and goes down: if this reaches - // -1 we are over budget. - int recursion_budget_; - // Recursion depth limit, set by SetRecursionLimit(). - int recursion_limit_; - - // See SetExtensionRegistry(). - const DescriptorPool* extension_pool_; - MessageFactory* extension_factory_; - - // Private member functions. - - // Advance the buffer by a given number of bytes. - void Advance(int amount); - - // Back up input_ to the current buffer position. - void BackUpInputToCurrentPosition(); - - // Recomputes the value of buffer_size_after_limit_. Must be called after - // current_limit_ or total_bytes_limit_ changes. - void RecomputeBufferLimits(); - - // Writes an error message saying that we hit total_bytes_limit_. - void PrintTotalBytesLimitError(); - - // Called when the buffer runs out to request more data. Implies an - // Advance(BufferSize()). - bool Refresh(); - - // When parsing varints, we optimize for the common case of small values, and - // then optimize for the case when the varint fits within the current buffer - // piece. The Fallback method is used when we can't use the one-byte - // optimization. The Slow method is yet another fallback when the buffer is - // not large enough. Making the slow path out-of-line speeds up the common - // case by 10-15%. The slow path is fairly uncommon: it only triggers when a - // message crosses multiple buffers. Note: ReadVarint32Fallback() and - // ReadVarint64Fallback() are called frequently and generally not inlined, so - // they have been optimized to avoid "out" parameters. The former returns -1 - // if it fails and the uint32 it read otherwise. The latter has a bool - // indicating success or failure as part of its return type. - int64 ReadVarint32Fallback(uint32 first_byte_or_zero); - int ReadVarintSizeAsIntFallback(); - std::pair ReadVarint64Fallback(); - bool ReadVarint32Slow(uint32* value); - bool ReadVarint64Slow(uint64* value); - int ReadVarintSizeAsIntSlow(); - bool ReadLittleEndian32Fallback(uint32* value); - bool ReadLittleEndian64Fallback(uint64* value); - // Fallback/slow methods for reading tags. These do not update last_tag_, - // but will set legitimate_message_end_ if we are at the end of the input - // stream. - uint32 ReadTagFallback(uint32 first_byte_or_zero); - uint32 ReadTagSlow(); - bool ReadStringFallback(string* buffer, int size); - - // Return the size of the buffer. - int BufferSize() const; - - static const int kDefaultTotalBytesLimit = 64 << 20; // 64MB - - static const int kDefaultTotalBytesWarningThreshold = 32 << 20; // 32MB - - static int default_recursion_limit_; // 100 by default. -}; - -// Class which encodes and writes binary data which is composed of varint- -// encoded integers and fixed-width pieces. Wraps a ZeroCopyOutputStream. -// Most users will not need to deal with CodedOutputStream. -// -// Most methods of CodedOutputStream which return a bool return false if an -// underlying I/O error occurs. Once such a failure occurs, the -// CodedOutputStream is broken and is no longer useful. The Write* methods do -// not return the stream status, but will invalidate the stream if an error -// occurs. The client can probe HadError() to determine the status. -// -// Note that every method of CodedOutputStream which writes some data has -// a corresponding static "ToArray" version. These versions write directly -// to the provided buffer, returning a pointer past the last written byte. -// They require that the buffer has sufficient capacity for the encoded data. -// This allows an optimization where we check if an output stream has enough -// space for an entire message before we start writing and, if there is, we -// call only the ToArray methods to avoid doing bound checks for each -// individual value. -// i.e., in the example above: -// -// CodedOutputStream coded_output = new CodedOutputStream(raw_output); -// int magic_number = 1234; -// char text[] = "Hello world!"; -// -// int coded_size = sizeof(magic_number) + -// CodedOutputStream::VarintSize32(strlen(text)) + -// strlen(text); -// -// uint8* buffer = -// coded_output->GetDirectBufferForNBytesAndAdvance(coded_size); -// if (buffer != NULL) { -// // The output stream has enough space in the buffer: write directly to -// // the array. -// buffer = CodedOutputStream::WriteLittleEndian32ToArray(magic_number, -// buffer); -// buffer = CodedOutputStream::WriteVarint32ToArray(strlen(text), buffer); -// buffer = CodedOutputStream::WriteRawToArray(text, strlen(text), buffer); -// } else { -// // Make bound-checked writes, which will ask the underlying stream for -// // more space as needed. -// coded_output->WriteLittleEndian32(magic_number); -// coded_output->WriteVarint32(strlen(text)); -// coded_output->WriteRaw(text, strlen(text)); -// } -// -// delete coded_output; -class LIBPROTOBUF_EXPORT CodedOutputStream { - public: - // Create an CodedOutputStream that writes to the given ZeroCopyOutputStream. - explicit CodedOutputStream(ZeroCopyOutputStream* output); - CodedOutputStream(ZeroCopyOutputStream* output, bool do_eager_refresh); - - // Destroy the CodedOutputStream and position the underlying - // ZeroCopyOutputStream immediately after the last byte written. - ~CodedOutputStream(); - - // Trims any unused space in the underlying buffer so that its size matches - // the number of bytes written by this stream. The underlying buffer will - // automatically be trimmed when this stream is destroyed; this call is only - // necessary if the underlying buffer is accessed *before* the stream is - // destroyed. - void Trim(); - - // Skips a number of bytes, leaving the bytes unmodified in the underlying - // buffer. Returns false if an underlying write error occurs. This is - // mainly useful with GetDirectBufferPointer(). - bool Skip(int count); - - // Sets *data to point directly at the unwritten part of the - // CodedOutputStream's underlying buffer, and *size to the size of that - // buffer, but does not advance the stream's current position. This will - // always either produce a non-empty buffer or return false. If the caller - // writes any data to this buffer, it should then call Skip() to skip over - // the consumed bytes. This may be useful for implementing external fast - // serialization routines for types of data not covered by the - // CodedOutputStream interface. - bool GetDirectBufferPointer(void** data, int* size); - - // If there are at least "size" bytes available in the current buffer, - // returns a pointer directly into the buffer and advances over these bytes. - // The caller may then write directly into this buffer (e.g. using the - // *ToArray static methods) rather than go through CodedOutputStream. If - // there are not enough bytes available, returns NULL. The return pointer is - // invalidated as soon as any other non-const method of CodedOutputStream - // is called. - inline uint8* GetDirectBufferForNBytesAndAdvance(int size); - - // Write raw bytes, copying them from the given buffer. - void WriteRaw(const void* buffer, int size); - // Like WriteRaw() but will try to write aliased data if aliasing is - // turned on. - void WriteRawMaybeAliased(const void* data, int size); - // Like WriteRaw() but writing directly to the target array. - // This is _not_ inlined, as the compiler often optimizes memcpy into inline - // copy loops. Since this gets called by every field with string or bytes - // type, inlining may lead to a significant amount of code bloat, with only a - // minor performance gain. - static uint8* WriteRawToArray(const void* buffer, int size, uint8* target); - - // Equivalent to WriteRaw(str.data(), str.size()). - void WriteString(const string& str); - // Like WriteString() but writing directly to the target array. - static uint8* WriteStringToArray(const string& str, uint8* target); - // Write the varint-encoded size of str followed by str. - static uint8* WriteStringWithSizeToArray(const string& str, uint8* target); - - - // Instructs the CodedOutputStream to allow the underlying - // ZeroCopyOutputStream to hold pointers to the original structure instead of - // copying, if it supports it (i.e. output->AllowsAliasing() is true). If the - // underlying stream does not support aliasing, then enabling it has no - // affect. For now, this only affects the behavior of - // WriteRawMaybeAliased(). - // - // NOTE: It is caller's responsibility to ensure that the chunk of memory - // remains live until all of the data has been consumed from the stream. - void EnableAliasing(bool enabled); - - // Write a 32-bit little-endian integer. - void WriteLittleEndian32(uint32 value); - // Like WriteLittleEndian32() but writing directly to the target array. - static uint8* WriteLittleEndian32ToArray(uint32 value, uint8* target); - // Write a 64-bit little-endian integer. - void WriteLittleEndian64(uint64 value); - // Like WriteLittleEndian64() but writing directly to the target array. - static uint8* WriteLittleEndian64ToArray(uint64 value, uint8* target); - - // Write an unsigned integer with Varint encoding. Writing a 32-bit value - // is equivalent to casting it to uint64 and writing it as a 64-bit value, - // but may be more efficient. - void WriteVarint32(uint32 value); - // Like WriteVarint32() but writing directly to the target array. - static uint8* WriteVarint32ToArray(uint32 value, uint8* target); - // Write an unsigned integer with Varint encoding. - void WriteVarint64(uint64 value); - // Like WriteVarint64() but writing directly to the target array. - static uint8* WriteVarint64ToArray(uint64 value, uint8* target); - - // Equivalent to WriteVarint32() except when the value is negative, - // in which case it must be sign-extended to a full 10 bytes. - void WriteVarint32SignExtended(int32 value); - // Like WriteVarint32SignExtended() but writing directly to the target array. - static uint8* WriteVarint32SignExtendedToArray(int32 value, uint8* target); - - // This is identical to WriteVarint32(), but optimized for writing tags. - // In particular, if the input is a compile-time constant, this method - // compiles down to a couple instructions. - // Always inline because otherwise the aformentioned optimization can't work, - // but GCC by default doesn't want to inline this. - void WriteTag(uint32 value); - // Like WriteTag() but writing directly to the target array. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteTagToArray(uint32 value, - uint8* target); - - // Returns the number of bytes needed to encode the given value as a varint. - static size_t VarintSize32(uint32 value); - // Returns the number of bytes needed to encode the given value as a varint. - static size_t VarintSize64(uint64 value); - - // If negative, 10 bytes. Otheriwse, same as VarintSize32(). - static size_t VarintSize32SignExtended(int32 value); - - // Compile-time equivalent of VarintSize32(). - template - struct StaticVarintSize32 { - static const size_t value = - (Value < (1 << 7)) - ? 1 - : (Value < (1 << 14)) - ? 2 - : (Value < (1 << 21)) - ? 3 - : (Value < (1 << 28)) - ? 4 - : 5; - }; - - // Returns the total number of bytes written since this object was created. - inline int ByteCount() const; - - // Returns true if there was an underlying I/O error since this object was - // created. - bool HadError() const { return had_error_; } - - // Deterministic serialization, if requested, guarantees that for a given - // binary, equal messages will always be serialized to the same bytes. This - // implies: - // . repeated serialization of a message will return the same bytes - // . different processes of the same binary (which may be executing on - // different machines) will serialize equal messages to the same bytes. - // - // Note the deterministic serialization is NOT canonical across languages; it - // is also unstable across different builds with schema changes due to unknown - // fields. Users who need canonical serialization, e.g., persistent storage in - // a canonical form, fingerprinting, etc., should define their own - // canonicalization specification and implement the serializer using - // reflection APIs rather than relying on this API. - // - // If determinisitc serialization is requested, the serializer will - // sort map entries by keys in lexicographical order or numerical order. - // (This is an implementation detail and may subject to change.) - // - // There are two ways to determine whether serialization should be - // deterministic for this CodedOutputStream. If SetSerializationDeterministic - // has not yet been called, then the default comes from the global default, - // which is false, until SetDefaultSerializationDeterministic has been called. - // Otherwise, SetSerializationDeterministic has been called, and the last - // value passed to it is all that matters. - void SetSerializationDeterministic(bool value) { - serialization_deterministic_is_overridden_ = true; - serialization_deterministic_override_ = value; - } - // See above. Also, note that users of this CodedOutputStream may need to - // call IsSerializationDeterminstic() to serialize in the intended way. This - // CodedOutputStream cannot enforce a desire for deterministic serialization - // by itself. - bool IsSerializationDeterminstic() const { - return serialization_deterministic_is_overridden_ ? - serialization_deterministic_override_ : - default_serialization_deterministic_; - } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CodedOutputStream); - - ZeroCopyOutputStream* output_; - uint8* buffer_; - int buffer_size_; - int total_bytes_; // Sum of sizes of all buffers seen so far. - bool had_error_; // Whether an error occurred during output. - bool aliasing_enabled_; // See EnableAliasing(). - // See SetSerializationDeterministic() regarding these three fields. - bool serialization_deterministic_is_overridden_; - bool serialization_deterministic_override_; - static bool default_serialization_deterministic_; - - // Advance the buffer by a given number of bytes. - void Advance(int amount); - - // Called when the buffer runs out to request more data. Implies an - // Advance(buffer_size_). - bool Refresh(); - - // Like WriteRaw() but may avoid copying if the underlying - // ZeroCopyOutputStream supports it. - void WriteAliasedRaw(const void* buffer, int size); - - // If this write might cross the end of the buffer, we compose the bytes first - // then use WriteRaw(). - void WriteVarint32SlowPath(uint32 value); - - // Always-inlined versions of WriteVarint* functions so that code can be - // reused, while still controlling size. For instance, WriteVarint32ToArray() - // should not directly call this: since it is inlined itself, doing so - // would greatly increase the size of generated code. Instead, it should call - // WriteVarint32FallbackToArray. Meanwhile, WriteVarint32() is already - // out-of-line, so it should just invoke this directly to avoid any extra - // function call overhead. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE static uint8* WriteVarint64ToArrayInline( - uint64 value, uint8* target); - - static size_t VarintSize32Fallback(uint32 value); - - // See above. Other projects may use "friend" to allow them to call this. - static void SetDefaultSerializationDeterministic() { - default_serialization_deterministic_ = true; - } -}; - -// inline methods ==================================================== -// The vast majority of varints are only one byte. These inline -// methods optimize for that case. - -inline bool CodedInputStream::ReadVarint32(uint32* value) { - uint32 v = 0; - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) { - v = *buffer_; - if (v < 0x80) { - *value = v; - Advance(1); - return true; - } - } - int64 result = ReadVarint32Fallback(v); - *value = static_cast(result); - return result >= 0; -} - -inline bool CodedInputStream::ReadVarint64(uint64* value) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && *buffer_ < 0x80) { - *value = *buffer_; - Advance(1); - return true; - } - std::pair p = ReadVarint64Fallback(); - *value = p.first; - return p.second; -} - -inline bool CodedInputStream::ReadVarintSizeAsInt(int* value) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) { - int v = *buffer_; - if (v < 0x80) { - *value = v; - Advance(1); - return true; - } - } - *value = ReadVarintSizeAsIntFallback(); - return *value >= 0; -} - -// static -inline const uint8* CodedInputStream::ReadLittleEndian32FromArray( - const uint8* buffer, - uint32* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(value, buffer, sizeof(*value)); - return buffer + sizeof(*value); -#else - *value = (static_cast(buffer[0]) ) | - (static_cast(buffer[1]) << 8) | - (static_cast(buffer[2]) << 16) | - (static_cast(buffer[3]) << 24); - return buffer + sizeof(*value); -#endif -} -// static -inline const uint8* CodedInputStream::ReadLittleEndian64FromArray( - const uint8* buffer, - uint64* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(value, buffer, sizeof(*value)); - return buffer + sizeof(*value); -#else - uint32 part0 = (static_cast(buffer[0]) ) | - (static_cast(buffer[1]) << 8) | - (static_cast(buffer[2]) << 16) | - (static_cast(buffer[3]) << 24); - uint32 part1 = (static_cast(buffer[4]) ) | - (static_cast(buffer[5]) << 8) | - (static_cast(buffer[6]) << 16) | - (static_cast(buffer[7]) << 24); - *value = static_cast(part0) | - (static_cast(part1) << 32); - return buffer + sizeof(*value); -#endif -} - -inline bool CodedInputStream::ReadLittleEndian32(uint32* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); - return true; - } else { - return ReadLittleEndian32Fallback(value); - } -#else - return ReadLittleEndian32Fallback(value); -#endif -} - -inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - if (GOOGLE_PREDICT_TRUE(BufferSize() >= static_cast(sizeof(*value)))) { - memcpy(value, buffer_, sizeof(*value)); - Advance(sizeof(*value)); - return true; - } else { - return ReadLittleEndian64Fallback(value); - } -#else - return ReadLittleEndian64Fallback(value); -#endif -} - -inline uint32 CodedInputStream::ReadTag() { - uint32 v = 0; - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) { - v = *buffer_; - if (v < 0x80) { - last_tag_ = v; - Advance(1); - return v; - } - } - last_tag_ = ReadTagFallback(v); - return last_tag_; -} - -inline std::pair CodedInputStream::ReadTagWithCutoff( - uint32 cutoff) { - // In performance-sensitive code we can expect cutoff to be a compile-time - // constant, and things like "cutoff >= kMax1ByteVarint" to be evaluated at - // compile time. - uint32 first_byte_or_zero = 0; - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) { - // Hot case: buffer_ non_empty, buffer_[0] in [1, 128). - // TODO(gpike): Is it worth rearranging this? E.g., if the number of fields - // is large enough then is it better to check for the two-byte case first? - first_byte_or_zero = buffer_[0]; - if (static_cast(buffer_[0]) > 0) { - const uint32 kMax1ByteVarint = 0x7f; - uint32 tag = last_tag_ = buffer_[0]; - Advance(1); - return std::make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff); - } - // Other hot case: cutoff >= 0x80, buffer_ has at least two bytes available, - // and tag is two bytes. The latter is tested by bitwise-and-not of the - // first byte and the second byte. - if (cutoff >= 0x80 && - GOOGLE_PREDICT_TRUE(buffer_ + 1 < buffer_end_) && - GOOGLE_PREDICT_TRUE((buffer_[0] & ~buffer_[1]) >= 0x80)) { - const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f; - uint32 tag = last_tag_ = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80); - Advance(2); - // It might make sense to test for tag == 0 now, but it is so rare that - // that we don't bother. A varint-encoded 0 should be one byte unless - // the encoder lost its mind. The second part of the return value of - // this function is allowed to be either true or false if the tag is 0, - // so we don't have to check for tag == 0. We may need to check whether - // it exceeds cutoff. - bool at_or_below_cutoff = cutoff >= kMax2ByteVarint || tag <= cutoff; - return std::make_pair(tag, at_or_below_cutoff); - } - } - // Slow path - last_tag_ = ReadTagFallback(first_byte_or_zero); - return std::make_pair(last_tag_, static_cast(last_tag_ - 1) < cutoff); -} - -inline bool CodedInputStream::LastTagWas(uint32 expected) { - return last_tag_ == expected; -} - -inline bool CodedInputStream::ConsumedEntireMessage() { - return legitimate_message_end_; -} - -inline bool CodedInputStream::ExpectTag(uint32 expected) { - if (expected < (1 << 7)) { - if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_) && buffer_[0] == expected) { - Advance(1); - return true; - } else { - return false; - } - } else if (expected < (1 << 14)) { - if (GOOGLE_PREDICT_TRUE(BufferSize() >= 2) && - buffer_[0] == static_cast(expected | 0x80) && - buffer_[1] == static_cast(expected >> 7)) { - Advance(2); - return true; - } else { - return false; - } - } else { - // Don't bother optimizing for larger values. - return false; - } -} - -inline const uint8* CodedInputStream::ExpectTagFromArray( - const uint8* buffer, uint32 expected) { - if (expected < (1 << 7)) { - if (buffer[0] == expected) { - return buffer + 1; - } - } else if (expected < (1 << 14)) { - if (buffer[0] == static_cast(expected | 0x80) && - buffer[1] == static_cast(expected >> 7)) { - return buffer + 2; - } - } - return NULL; -} - -inline void CodedInputStream::GetDirectBufferPointerInline(const void** data, - int* size) { - *data = buffer_; - *size = static_cast(buffer_end_ - buffer_); -} - -inline bool CodedInputStream::ExpectAtEnd() { - // If we are at a limit we know no more bytes can be read. Otherwise, it's - // hard to say without calling Refresh(), and we'd rather not do that. - - if (buffer_ == buffer_end_ && - ((buffer_size_after_limit_ != 0) || - (total_bytes_read_ == current_limit_))) { - last_tag_ = 0; // Pretend we called ReadTag()... - legitimate_message_end_ = true; // ... and it hit EOF. - return true; - } else { - return false; - } -} - -inline int CodedInputStream::CurrentPosition() const { - return total_bytes_read_ - (BufferSize() + buffer_size_after_limit_); -} - -inline uint8* CodedOutputStream::GetDirectBufferForNBytesAndAdvance(int size) { - if (buffer_size_ < size) { - return NULL; - } else { - uint8* result = buffer_; - Advance(size); - return result; - } -} - -inline uint8* CodedOutputStream::WriteVarint32ToArray(uint32 value, - uint8* target) { - while (value >= 0x80) { - *target = static_cast(value | 0x80); - value >>= 7; - ++target; - } - *target = static_cast(value); - return target + 1; -} - -inline void CodedOutputStream::WriteVarint32SignExtended(int32 value) { - if (value < 0) { - WriteVarint64(static_cast(value)); - } else { - WriteVarint32(static_cast(value)); - } -} - -inline uint8* CodedOutputStream::WriteVarint32SignExtendedToArray( - int32 value, uint8* target) { - if (value < 0) { - return WriteVarint64ToArray(static_cast(value), target); - } else { - return WriteVarint32ToArray(static_cast(value), target); - } -} - -inline uint8* CodedOutputStream::WriteLittleEndian32ToArray(uint32 value, - uint8* target) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(target, &value, sizeof(value)); -#else - target[0] = static_cast(value); - target[1] = static_cast(value >> 8); - target[2] = static_cast(value >> 16); - target[3] = static_cast(value >> 24); -#endif - return target + sizeof(value); -} - -inline uint8* CodedOutputStream::WriteLittleEndian64ToArray(uint64 value, - uint8* target) { -#if defined(PROTOBUF_LITTLE_ENDIAN) - memcpy(target, &value, sizeof(value)); -#else - uint32 part0 = static_cast(value); - uint32 part1 = static_cast(value >> 32); - - target[0] = static_cast(part0); - target[1] = static_cast(part0 >> 8); - target[2] = static_cast(part0 >> 16); - target[3] = static_cast(part0 >> 24); - target[4] = static_cast(part1); - target[5] = static_cast(part1 >> 8); - target[6] = static_cast(part1 >> 16); - target[7] = static_cast(part1 >> 24); -#endif - return target + sizeof(value); -} - -inline void CodedOutputStream::WriteVarint32(uint32 value) { - if (buffer_size_ >= 5) { - // Fast path: We have enough bytes left in the buffer to guarantee that - // this write won't cross the end, so we can skip the checks. - uint8* target = buffer_; - uint8* end = WriteVarint32ToArray(value, target); - int size = static_cast(end - target); - Advance(size); - } else { - WriteVarint32SlowPath(value); - } -} - -inline void CodedOutputStream::WriteTag(uint32 value) { - WriteVarint32(value); -} - -inline uint8* CodedOutputStream::WriteTagToArray( - uint32 value, uint8* target) { - return WriteVarint32ToArray(value, target); -} - -inline size_t CodedOutputStream::VarintSize32(uint32 value) { - if (value < (1 << 7)) { - return 1; - } else { - return VarintSize32Fallback(value); - } -} - -inline size_t CodedOutputStream::VarintSize32SignExtended(int32 value) { - if (value < 0) { - return 10; // TODO(kenton): Make this a symbolic constant. - } else { - return VarintSize32(static_cast(value)); - } -} - -inline void CodedOutputStream::WriteString(const string& str) { - WriteRaw(str.data(), static_cast(str.size())); -} - -inline void CodedOutputStream::WriteRawMaybeAliased( - const void* data, int size) { - if (aliasing_enabled_) { - WriteAliasedRaw(data, size); - } else { - WriteRaw(data, size); - } -} - -inline uint8* CodedOutputStream::WriteStringToArray( - const string& str, uint8* target) { - return WriteRawToArray(str.data(), static_cast(str.size()), target); -} - -inline int CodedOutputStream::ByteCount() const { - return total_bytes_ - buffer_size_; -} - -inline void CodedInputStream::Advance(int amount) { - buffer_ += amount; -} - -inline void CodedOutputStream::Advance(int amount) { - buffer_ += amount; - buffer_size_ -= amount; -} - -inline void CodedInputStream::SetRecursionLimit(int limit) { - recursion_budget_ += limit - recursion_limit_; - recursion_limit_ = limit; -} - -inline bool CodedInputStream::IncrementRecursionDepth() { - --recursion_budget_; - return recursion_budget_ >= 0; -} - -inline void CodedInputStream::DecrementRecursionDepth() { - if (recursion_budget_ < recursion_limit_) ++recursion_budget_; -} - -inline void CodedInputStream::UnsafeDecrementRecursionDepth() { - assert(recursion_budget_ < recursion_limit_); - ++recursion_budget_; -} - -inline void CodedInputStream::SetExtensionRegistry(const DescriptorPool* pool, - MessageFactory* factory) { - extension_pool_ = pool; - extension_factory_ = factory; -} - -inline const DescriptorPool* CodedInputStream::GetExtensionPool() { - return extension_pool_; -} - -inline MessageFactory* CodedInputStream::GetExtensionFactory() { - return extension_factory_; -} - -inline int CodedInputStream::BufferSize() const { - return static_cast(buffer_end_ - buffer_); -} - -inline CodedInputStream::CodedInputStream(ZeroCopyInputStream* input) - : buffer_(NULL), - buffer_end_(NULL), - input_(input), - total_bytes_read_(0), - overflow_bytes_(0), - last_tag_(0), - legitimate_message_end_(false), - aliasing_enabled_(false), - current_limit_(kint32max), - buffer_size_after_limit_(0), - total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), - recursion_budget_(default_recursion_limit_), - recursion_limit_(default_recursion_limit_), - extension_pool_(NULL), - extension_factory_(NULL) { - // Eagerly Refresh() so buffer space is immediately available. - Refresh(); -} - -inline CodedInputStream::CodedInputStream(const uint8* buffer, int size) - : buffer_(buffer), - buffer_end_(buffer + size), - input_(NULL), - total_bytes_read_(size), - overflow_bytes_(0), - last_tag_(0), - legitimate_message_end_(false), - aliasing_enabled_(false), - current_limit_(size), - buffer_size_after_limit_(0), - total_bytes_limit_(kDefaultTotalBytesLimit), - total_bytes_warning_threshold_(kDefaultTotalBytesWarningThreshold), - recursion_budget_(default_recursion_limit_), - recursion_limit_(default_recursion_limit_), - extension_pool_(NULL), - extension_factory_(NULL) { - // Note that setting current_limit_ == size is important to prevent some - // code paths from trying to access input_ and segfaulting. -} - -inline bool CodedInputStream::IsFlat() const { - return input_ == NULL; -} - -} // namespace io -} // namespace protobuf - - -#if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) - #pragma runtime_checks("c", restore) -#endif // _MSC_VER && !defined(__INTEL_COMPILER) - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_CODED_STREAM_H__ diff --git a/app/src/main/cpp/google/protobuf/io/gzip_stream.h b/app/src/main/cpp/google/protobuf/io/gzip_stream.h deleted file mode 100644 index 15b02fe..0000000 --- a/app/src/main/cpp/google/protobuf/io/gzip_stream.h +++ /dev/null @@ -1,209 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: brianolson@google.com (Brian Olson) -// -// This file contains the definition for classes GzipInputStream and -// GzipOutputStream. -// -// GzipInputStream decompresses data from an underlying -// ZeroCopyInputStream and provides the decompressed data as a -// ZeroCopyInputStream. -// -// GzipOutputStream is an ZeroCopyOutputStream that compresses data to -// an underlying ZeroCopyOutputStream. - -#ifndef GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -// A ZeroCopyInputStream that reads compressed data through zlib -class LIBPROTOBUF_EXPORT GzipInputStream : public ZeroCopyInputStream { - public: - // Format key for constructor - enum Format { - // zlib will autodetect gzip header or deflate stream - AUTO = 0, - - // GZIP streams have some extra header data for file attributes. - GZIP = 1, - - // Simpler zlib stream format. - ZLIB = 2, - }; - - // buffer_size and format may be -1 for default of 64kB and GZIP format - explicit GzipInputStream( - ZeroCopyInputStream* sub_stream, - Format format = AUTO, - int buffer_size = -1); - virtual ~GzipInputStream(); - - // Return last error message or NULL if no error. - inline const char* ZlibErrorMessage() const { - return zcontext_.msg; - } - inline int ZlibErrorCode() const { - return zerror_; - } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - Format format_; - - ZeroCopyInputStream* sub_stream_; - - z_stream zcontext_; - int zerror_; - - void* output_buffer_; - void* output_position_; - size_t output_buffer_length_; - int64 byte_count_; - - int Inflate(int flush); - void DoNextOutput(const void** data, int* size); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipInputStream); -}; - - -class LIBPROTOBUF_EXPORT GzipOutputStream : public ZeroCopyOutputStream { - public: - // Format key for constructor - enum Format { - // GZIP streams have some extra header data for file attributes. - GZIP = 1, - - // Simpler zlib stream format. - ZLIB = 2, - }; - - struct Options { - // Defaults to GZIP. - Format format; - - // What size buffer to use internally. Defaults to 64kB. - int buffer_size; - - // A number between 0 and 9, where 0 is no compression and 9 is best - // compression. Defaults to Z_DEFAULT_COMPRESSION (see zlib.h). - int compression_level; - - // Defaults to Z_DEFAULT_STRATEGY. Can also be set to Z_FILTERED, - // Z_HUFFMAN_ONLY, or Z_RLE. See the documentation for deflateInit2 in - // zlib.h for definitions of these constants. - int compression_strategy; - - Options(); // Initializes with default values. - }; - - // Create a GzipOutputStream with default options. - explicit GzipOutputStream(ZeroCopyOutputStream* sub_stream); - - // Create a GzipOutputStream with the given options. - GzipOutputStream( - ZeroCopyOutputStream* sub_stream, - const Options& options); - - virtual ~GzipOutputStream(); - - // Return last error message or NULL if no error. - inline const char* ZlibErrorMessage() const { - return zcontext_.msg; - } - inline int ZlibErrorCode() const { - return zerror_; - } - - // Flushes data written so far to zipped data in the underlying stream. - // It is the caller's responsibility to flush the underlying stream if - // necessary. - // Compression may be less efficient stopping and starting around flushes. - // Returns true if no error. - // - // Please ensure that block size is > 6. Here is an excerpt from the zlib - // doc that explains why: - // - // In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that avail_out - // is greater than six to avoid repeated flush markers due to - // avail_out == 0 on return. - bool Flush(); - - // Writes out all data and closes the gzip stream. - // It is the caller's responsibility to close the underlying stream if - // necessary. - // Returns true if no error. - bool Close(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - ZeroCopyOutputStream* sub_stream_; - // Result from calling Next() on sub_stream_ - void* sub_data_; - int sub_data_size_; - - z_stream zcontext_; - int zerror_; - void* input_buffer_; - size_t input_buffer_length_; - - // Shared constructor code. - void Init(ZeroCopyOutputStream* sub_stream, const Options& options); - - // Do some compression. - // Takes zlib flush mode. - // Returns zlib error code. - int Deflate(int flush); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GzipOutputStream); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_GZIP_STREAM_H__ diff --git a/app/src/main/cpp/google/protobuf/io/printer.h b/app/src/main/cpp/google/protobuf/io/printer.h deleted file mode 100644 index e78e2ef..0000000 --- a/app/src/main/cpp/google/protobuf/io/printer.h +++ /dev/null @@ -1,353 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Utility class for writing text to a ZeroCopyOutputStream. - -#ifndef GOOGLE_PROTOBUF_IO_PRINTER_H__ -#define GOOGLE_PROTOBUF_IO_PRINTER_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -class ZeroCopyOutputStream; // zero_copy_stream.h - -// Records annotations about a Printer's output. -class LIBPROTOBUF_EXPORT AnnotationCollector { - public: - // Records that the bytes in file_path beginning with begin_offset and ending - // before end_offset are associated with the SourceCodeInfo-style path. - virtual void AddAnnotation(size_t begin_offset, size_t end_offset, - const string& file_path, - const vector& path) = 0; - - virtual ~AnnotationCollector() {} -}; - -// Records annotations about a Printer's output to the given protocol buffer, -// assuming that the buffer has an ::Annotation message exposing path, -// source_file, begin and end fields. -template -class AnnotationProtoCollector : public AnnotationCollector { - public: - // annotation_proto is the protocol buffer to which new Annotations should be - // added. It is not owned by the AnnotationProtoCollector. - explicit AnnotationProtoCollector(AnnotationProto* annotation_proto) - : annotation_proto_(annotation_proto) {} - - // Override for AnnotationCollector::AddAnnotation. - virtual void AddAnnotation(size_t begin_offset, size_t end_offset, - const string& file_path, const vector& path) { - typename AnnotationProto::Annotation* annotation = - annotation_proto_->add_annotation(); - for (int i = 0; i < path.size(); ++i) { - annotation->add_path(path[i]); - } - annotation->set_source_file(file_path); - annotation->set_begin(begin_offset); - annotation->set_end(end_offset); - } - - private: - // The protocol buffer to which new annotations should be added. - AnnotationProto* const annotation_proto_; -}; - -// This simple utility class assists in code generation. It basically -// allows the caller to define a set of variables and then output some -// text with variable substitutions. Example usage: -// -// Printer printer(output, '$'); -// map vars; -// vars["name"] = "Bob"; -// printer.Print(vars, "My name is $name$."); -// -// The above writes "My name is Bob." to the output stream. -// -// Printer aggressively enforces correct usage, crashing (with assert failures) -// in the case of undefined variables in debug builds. This helps greatly in -// debugging code which uses it. -// -// If a Printer is constructed with an AnnotationCollector, it will provide it -// with annotations that connect the Printer's output to paths that can identify -// various descriptors. In the above example, if person_ is a descriptor that -// identifies Bob, we can associate the output string "My name is Bob." with -// a source path pointing to that descriptor with: -// -// printer.Annotate("name", person_); -// -// The AnnotationCollector will be sent an annotation linking the output range -// covering "Bob" to the logical path provided by person_. Tools may use -// this association to (for example) link "Bob" in the output back to the -// source file that defined the person_ descriptor identifying Bob. -// -// Annotate can only examine variables substituted during the last call to -// Print. It is invalid to refer to a variable that was used multiple times -// in a single Print call. -// -// In full generality, one may specify a range of output text using a beginning -// substitution variable and an ending variable. The resulting annotation will -// span from the first character of the substituted value for the beginning -// variable to the last character of the substituted value for the ending -// variable. For example, the Annotate call above is equivalent to this one: -// -// printer.Annotate("name", "name", person_); -// -// This is useful if multiple variables combine to form a single span of output -// that should be annotated with the same source path. For example: -// -// Printer printer(output, '$'); -// map vars; -// vars["first"] = "Alice"; -// vars["last"] = "Smith"; -// printer.Print(vars, "My name is $first$ $last$."); -// printer.Annotate("first", "last", person_); -// -// This code would associate the span covering "Alice Smith" in the output with -// the person_ descriptor. -// -// Note that the beginning variable must come before (or overlap with, in the -// case of zero-sized substitution values) the ending variable. -// -// It is also sometimes useful to use variables with zero-sized values as -// markers. This avoids issues with multiple references to the same variable -// and also allows annotation ranges to span literal text from the Print -// templates: -// -// Printer printer(output, '$'); -// map vars; -// vars["foo"] = "bar"; -// vars["function"] = "call"; -// vars["mark"] = ""; -// printer.Print(vars, "$function$($foo$,$foo$)$mark$"); -// printer.Annotate("function", "rmark", call_); -// -// This code associates the span covering "call(bar,bar)" in the output with the -// call_ descriptor. - -class LIBPROTOBUF_EXPORT Printer { - public: - // Create a printer that writes text to the given output stream. Use the - // given character as the delimiter for variables. - Printer(ZeroCopyOutputStream* output, char variable_delimiter); - - // Create a printer that writes text to the given output stream. Use the - // given character as the delimiter for variables. If annotation_collector - // is not null, Printer will provide it with annotations about code written - // to the stream. annotation_collector is not owned by Printer. - Printer(ZeroCopyOutputStream* output, char variable_delimiter, - AnnotationCollector* annotation_collector); - - ~Printer(); - - // Link a subsitution variable emitted by the last call to Print to the object - // described by descriptor. - template - void Annotate(const char* varname, const SomeDescriptor* descriptor) { - Annotate(varname, varname, descriptor); - } - - // Link the output range defined by the substitution variables as emitted by - // the last call to Print to the object described by descriptor. The range - // begins at begin_varname's value and ends after the last character of the - // value substituted for end_varname. - template - void Annotate(const char* begin_varname, const char* end_varname, - const SomeDescriptor* descriptor) { - if (annotation_collector_ == NULL) { - // Annotations aren't turned on for this Printer, so don't pay the cost - // of building the location path. - return; - } - vector path; - descriptor->GetLocationPath(&path); - Annotate(begin_varname, end_varname, descriptor->file()->name(), path); - } - - // Link a subsitution variable emitted by the last call to Print to the file - // with path file_name. - void Annotate(const char* varname, const string& file_name) { - Annotate(varname, varname, file_name); - } - - // Link the output range defined by the substitution variables as emitted by - // the last call to Print to the file with path file_name. The range begins - // at begin_varname's value and ends after the last character of the value - // substituted for end_varname. - void Annotate(const char* begin_varname, const char* end_varname, - const string& file_name) { - if (annotation_collector_ == NULL) { - // Annotations aren't turned on for this Printer. - return; - } - vector empty_path; - Annotate(begin_varname, end_varname, file_name, empty_path); - } - - // Print some text after applying variable substitutions. If a particular - // variable in the text is not defined, this will crash. Variables to be - // substituted are identified by their names surrounded by delimiter - // characters (as given to the constructor). The variable bindings are - // defined by the given map. - void Print(const map& variables, const char* text); - - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable, const string& value); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3, - const char* variable4, const string& value4); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3, - const char* variable4, const string& value4, - const char* variable5, const string& value5); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3, - const char* variable4, const string& value4, - const char* variable5, const string& value5, - const char* variable6, const string& value6); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3, - const char* variable4, const string& value4, - const char* variable5, const string& value5, - const char* variable6, const string& value6, - const char* variable7, const string& value7); - // Like the first Print(), except the substitutions are given as parameters. - void Print(const char* text, const char* variable1, const string& value1, - const char* variable2, const string& value2, - const char* variable3, const string& value3, - const char* variable4, const string& value4, - const char* variable5, const string& value5, - const char* variable6, const string& value6, - const char* variable7, const string& value7, - const char* variable8, const string& value8); - - // Indent text by two spaces. After calling Indent(), two spaces will be - // inserted at the beginning of each line of text. Indent() may be called - // multiple times to produce deeper indents. - void Indent(); - - // Reduces the current indent level by two spaces, or crashes if the indent - // level is zero. - void Outdent(); - - // Write a string to the output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const string& data); - - // Write a zero-delimited string to output buffer. - // This method does not look for newlines to add indentation. - void PrintRaw(const char* data); - - // Write some bytes to the output buffer. - // This method does not look for newlines to add indentation. - void WriteRaw(const char* data, int size); - - // True if any write to the underlying stream failed. (We don't just - // crash in this case because this is an I/O failure, not a programming - // error.) - bool failed() const { return failed_; } - - private: - // Link the output range defined by the substitution variables as emitted by - // the last call to Print to the object found at the SourceCodeInfo-style path - // in a file with path file_path. The range begins at the start of - // begin_varname's value and ends after the last character of the value - // substituted for end_varname. Note that begin_varname and end_varname - // may refer to the same variable. - void Annotate(const char* begin_varname, const char* end_varname, - const string& file_path, const vector& path); - - const char variable_delimiter_; - - ZeroCopyOutputStream* const output_; - char* buffer_; - int buffer_size_; - // The current position, in bytes, in the output stream. This is equivalent - // to the total number of bytes that have been written so far. This value is - // used to calculate annotation ranges in the substitutions_ map below. - size_t offset_; - - string indent_; - bool at_start_of_line_; - bool failed_; - - // A map from variable name to [start, end) offsets in the output buffer. - // These refer to the offsets used for a variable after the last call to - // Print. If a variable was used more than once, the entry used in - // this map is set to a negative-length span. For singly-used variables, the - // start offset is the beginning of the substitution; the end offset is the - // last byte of the substitution plus one (such that (end - start) is the - // length of the substituted string). - map > substitutions_; - - // Returns true and sets range to the substitution range in the output for - // varname if varname was used once in the last call to Print. If varname - // was not used, or if it was used multiple times, returns false (and - // fails a debug assertion). - bool GetSubstitutionRange(const char* varname, pair* range); - - // If non-null, annotation_collector_ is used to store annotations about - // generated code. - AnnotationCollector* const annotation_collector_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Printer); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_PRINTER_H__ diff --git a/app/src/main/cpp/google/protobuf/io/strtod.h b/app/src/main/cpp/google/protobuf/io/strtod.h deleted file mode 100644 index f56e41c..0000000 --- a/app/src/main/cpp/google/protobuf/io/strtod.h +++ /dev/null @@ -1,55 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// A locale-independent version of strtod(), used to parse floating -// point default values in .proto files, where the decimal separator -// is always a dot. - -#ifndef GOOGLE_PROTOBUF_IO_STRTOD_H__ -#define GOOGLE_PROTOBUF_IO_STRTOD_H__ - -namespace google { -namespace protobuf { -namespace io { - -// A locale-independent version of the standard strtod(), which always -// uses a dot as the decimal separator. -double NoLocaleStrtod(const char* str, char** endptr); - -// Casts a double value to a float value. If the value is outside of the -// representable range of float, it will be converted to positive or negative -// infinity. -float SafeDoubleToFloat(double value); - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_STRTOD_H__ diff --git a/app/src/main/cpp/google/protobuf/io/tokenizer.h b/app/src/main/cpp/google/protobuf/io/tokenizer.h deleted file mode 100644 index 77a873b..0000000 --- a/app/src/main/cpp/google/protobuf/io/tokenizer.h +++ /dev/null @@ -1,411 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Class for parsing tokenized text from a ZeroCopyInputStream. - -#ifndef GOOGLE_PROTOBUF_IO_TOKENIZER_H__ -#define GOOGLE_PROTOBUF_IO_TOKENIZER_H__ - -#include -#include -#include -#include - -namespace google { -namespace protobuf { -namespace io { - -class ZeroCopyInputStream; // zero_copy_stream.h - -// Defined in this file. -class ErrorCollector; -class Tokenizer; - -// By "column number", the proto compiler refers to a count of the number -// of bytes before a given byte, except that a tab character advances to -// the next multiple of 8 bytes. Note in particular that column numbers -// are zero-based, while many user interfaces use one-based column numbers. -typedef int ColumnNumber; - -// Abstract interface for an object which collects the errors that occur -// during parsing. A typical implementation might simply print the errors -// to stdout. -class LIBPROTOBUF_EXPORT ErrorCollector { - public: - inline ErrorCollector() {} - virtual ~ErrorCollector(); - - // Indicates that there was an error in the input at the given line and - // column numbers. The numbers are zero-based, so you may want to add - // 1 to each before printing them. - virtual void AddError(int line, ColumnNumber column, - const string& message) = 0; - - // Indicates that there was a warning in the input at the given line and - // column numbers. The numbers are zero-based, so you may want to add - // 1 to each before printing them. - virtual void AddWarning(int line, ColumnNumber column, - const string& message) { } - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ErrorCollector); -}; - -// This class converts a stream of raw text into a stream of tokens for -// the protocol definition parser to parse. The tokens recognized are -// similar to those that make up the C language; see the TokenType enum for -// precise descriptions. Whitespace and comments are skipped. By default, -// C- and C++-style comments are recognized, but other styles can be used by -// calling set_comment_style(). -class LIBPROTOBUF_EXPORT Tokenizer { - public: - // Construct a Tokenizer that reads and tokenizes text from the given - // input stream and writes errors to the given error_collector. - // The caller keeps ownership of input and error_collector. - Tokenizer(ZeroCopyInputStream* input, ErrorCollector* error_collector); - ~Tokenizer(); - - enum TokenType { - TYPE_START, // Next() has not yet been called. - TYPE_END, // End of input reached. "text" is empty. - - TYPE_IDENTIFIER, // A sequence of letters, digits, and underscores, not - // starting with a digit. It is an error for a number - // to be followed by an identifier with no space in - // between. - TYPE_INTEGER, // A sequence of digits representing an integer. Normally - // the digits are decimal, but a prefix of "0x" indicates - // a hex number and a leading zero indicates octal, just - // like with C numeric literals. A leading negative sign - // is NOT included in the token; it's up to the parser to - // interpret the unary minus operator on its own. - TYPE_FLOAT, // A floating point literal, with a fractional part and/or - // an exponent. Always in decimal. Again, never - // negative. - TYPE_STRING, // A quoted sequence of escaped characters. Either single - // or double quotes can be used, but they must match. - // A string literal cannot cross a line break. - TYPE_SYMBOL, // Any other printable character, like '!' or '+'. - // Symbols are always a single character, so "!+$%" is - // four tokens. - }; - - // Structure representing a token read from the token stream. - struct Token { - TokenType type; - string text; // The exact text of the token as it appeared in - // the input. e.g. tokens of TYPE_STRING will still - // be escaped and in quotes. - - // "line" and "column" specify the position of the first character of - // the token within the input stream. They are zero-based. - int line; - ColumnNumber column; - ColumnNumber end_column; - }; - - // Get the current token. This is updated when Next() is called. Before - // the first call to Next(), current() has type TYPE_START and no contents. - const Token& current(); - - // Return the previous token -- i.e. what current() returned before the - // previous call to Next(). - const Token& previous(); - - // Advance to the next token. Returns false if the end of the input is - // reached. - bool Next(); - - // Like Next(), but also collects comments which appear between the previous - // and next tokens. - // - // Comments which appear to be attached to the previous token are stored - // in *prev_tailing_comments. Comments which appear to be attached to the - // next token are stored in *next_leading_comments. Comments appearing in - // between which do not appear to be attached to either will be added to - // detached_comments. Any of these parameters can be NULL to simply discard - // the comments. - // - // A series of line comments appearing on consecutive lines, with no other - // tokens appearing on those lines, will be treated as a single comment. - // - // Only the comment content is returned; comment markers (e.g. //) are - // stripped out. For block comments, leading whitespace and an asterisk will - // be stripped from the beginning of each line other than the first. Newlines - // are included in the output. - // - // Examples: - // - // optional int32 foo = 1; // Comment attached to foo. - // // Comment attached to bar. - // optional int32 bar = 2; - // - // optional string baz = 3; - // // Comment attached to baz. - // // Another line attached to baz. - // - // // Comment attached to qux. - // // - // // Another line attached to qux. - // optional double qux = 4; - // - // // Detached comment. This is not attached to qux or corge - // // because there are blank lines separating it from both. - // - // optional string corge = 5; - // /* Block comment attached - // * to corge. Leading asterisks - // * will be removed. */ - // /* Block comment attached to - // * grault. */ - // optional int32 grault = 6; - bool NextWithComments(string* prev_trailing_comments, - vector* detached_comments, - string* next_leading_comments); - - // Parse helpers --------------------------------------------------- - - // Parses a TYPE_FLOAT token. This never fails, so long as the text actually - // comes from a TYPE_FLOAT token parsed by Tokenizer. If it doesn't, the - // result is undefined (possibly an assert failure). - static double ParseFloat(const string& text); - - // Parses a TYPE_STRING token. This never fails, so long as the text actually - // comes from a TYPE_STRING token parsed by Tokenizer. If it doesn't, the - // result is undefined (possibly an assert failure). - static void ParseString(const string& text, string* output); - - // Identical to ParseString, but appends to output. - static void ParseStringAppend(const string& text, string* output); - - // Parses a TYPE_INTEGER token. Returns false if the result would be - // greater than max_value. Otherwise, returns true and sets *output to the - // result. If the text is not from a Token of type TYPE_INTEGER originally - // parsed by a Tokenizer, the result is undefined (possibly an assert - // failure). - static bool ParseInteger(const string& text, uint64 max_value, - uint64* output); - - // Options --------------------------------------------------------- - - // Set true to allow floats to be suffixed with the letter 'f'. Tokens - // which would otherwise be integers but which have the 'f' suffix will be - // forced to be interpreted as floats. For all other purposes, the 'f' is - // ignored. - void set_allow_f_after_float(bool value) { allow_f_after_float_ = value; } - - // Valid values for set_comment_style(). - enum CommentStyle { - // Line comments begin with "//", block comments are delimited by "/*" and - // "*/". - CPP_COMMENT_STYLE, - // Line comments begin with "#". No way to write block comments. - SH_COMMENT_STYLE - }; - - // Sets the comment style. - void set_comment_style(CommentStyle style) { comment_style_ = style; } - - // Whether to require whitespace between a number and a field name. - // Default is true. Do not use this; for Google-internal cleanup only. - void set_require_space_after_number(bool require) { - require_space_after_number_ = require; - } - - // Whether to allow string literals to span multiple lines. Default is false. - // Do not use this; for Google-internal cleanup only. - void set_allow_multiline_strings(bool allow) { - allow_multiline_strings_ = allow; - } - - // External helper: validate an identifier. - static bool IsIdentifier(const string& text); - - // ----------------------------------------------------------------- - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Tokenizer); - - Token current_; // Returned by current(). - Token previous_; // Returned by previous(). - - ZeroCopyInputStream* input_; - ErrorCollector* error_collector_; - - char current_char_; // == buffer_[buffer_pos_], updated by NextChar(). - const char* buffer_; // Current buffer returned from input_. - int buffer_size_; // Size of buffer_. - int buffer_pos_; // Current position within the buffer. - bool read_error_; // Did we previously encounter a read error? - - // Line and column number of current_char_ within the whole input stream. - int line_; - ColumnNumber column_; - - // String to which text should be appended as we advance through it. - // Call RecordTo(&str) to start recording and StopRecording() to stop. - // E.g. StartToken() calls RecordTo(¤t_.text). record_start_ is the - // position within the current buffer where recording started. - string* record_target_; - int record_start_; - - // Options. - bool allow_f_after_float_; - CommentStyle comment_style_; - bool require_space_after_number_; - bool allow_multiline_strings_; - - // Since we count columns we need to interpret tabs somehow. We'll take - // the standard 8-character definition for lack of any way to do better. - // This must match the documentation of ColumnNumber. - static const int kTabWidth = 8; - - // ----------------------------------------------------------------- - // Helper methods. - - // Consume this character and advance to the next one. - void NextChar(); - - // Read a new buffer from the input. - void Refresh(); - - inline void RecordTo(string* target); - inline void StopRecording(); - - // Called when the current character is the first character of a new - // token (not including whitespace or comments). - inline void StartToken(); - // Called when the current character is the first character after the - // end of the last token. After this returns, current_.text will - // contain all text consumed since StartToken() was called. - inline void EndToken(); - - // Convenience method to add an error at the current line and column. - void AddError(const string& message) { - error_collector_->AddError(line_, column_, message); - } - - // ----------------------------------------------------------------- - // The following four methods are used to consume tokens of specific - // types. They are actually used to consume all characters *after* - // the first, since the calling function consumes the first character - // in order to decide what kind of token is being read. - - // Read and consume a string, ending when the given delimiter is - // consumed. - void ConsumeString(char delimiter); - - // Read and consume a number, returning TYPE_FLOAT or TYPE_INTEGER - // depending on what was read. This needs to know if the first - // character was a zero in order to correctly recognize hex and octal - // numbers. - // It also needs to know if the first character was a . to parse floating - // point correctly. - TokenType ConsumeNumber(bool started_with_zero, bool started_with_dot); - - // Consume the rest of a line. - void ConsumeLineComment(string* content); - // Consume until "*/". - void ConsumeBlockComment(string* content); - - enum NextCommentStatus { - // Started a line comment. - LINE_COMMENT, - - // Started a block comment. - BLOCK_COMMENT, - - // Consumed a slash, then realized it wasn't a comment. current_ has - // been filled in with a slash token. The caller should return it. - SLASH_NOT_COMMENT, - - // We do not appear to be starting a comment here. - NO_COMMENT - }; - - // If we're at the start of a new comment, consume it and return what kind - // of comment it is. - NextCommentStatus TryConsumeCommentStart(); - - // ----------------------------------------------------------------- - // These helper methods make the parsing code more readable. The - // "character classes" referred to are defined at the top of the .cc file. - // Basically it is a C++ class with one method: - // static bool InClass(char c); - // The method returns true if c is a member of this "class", like "Letter" - // or "Digit". - - // Returns true if the current character is of the given character - // class, but does not consume anything. - template - inline bool LookingAt(); - - // If the current character is in the given class, consume it and return - // true. Otherwise return false. - // e.g. TryConsumeOne() - template - inline bool TryConsumeOne(); - - // Like above, but try to consume the specific character indicated. - inline bool TryConsume(char c); - - // Consume zero or more of the given character class. - template - inline void ConsumeZeroOrMore(); - - // Consume one or more of the given character class or log the given - // error message. - // e.g. ConsumeOneOrMore("Expected digits."); - template - inline void ConsumeOneOrMore(const char* error); -}; - -// inline methods ==================================================== -inline const Tokenizer::Token& Tokenizer::current() { - return current_; -} - -inline const Tokenizer::Token& Tokenizer::previous() { - return previous_; -} - -inline void Tokenizer::ParseString(const string& text, string* output) { - output->clear(); - ParseStringAppend(text, output); -} - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_TOKENIZER_H__ diff --git a/app/src/main/cpp/google/protobuf/io/zero_copy_stream.h b/app/src/main/cpp/google/protobuf/io/zero_copy_stream.h deleted file mode 100644 index 52650fc..0000000 --- a/app/src/main/cpp/google/protobuf/io/zero_copy_stream.h +++ /dev/null @@ -1,248 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains the ZeroCopyInputStream and ZeroCopyOutputStream -// interfaces, which represent abstract I/O streams to and from which -// protocol buffers can be read and written. For a few simple -// implementations of these interfaces, see zero_copy_stream_impl.h. -// -// These interfaces are different from classic I/O streams in that they -// try to minimize the amount of data copying that needs to be done. -// To accomplish this, responsibility for allocating buffers is moved to -// the stream object, rather than being the responsibility of the caller. -// So, the stream can return a buffer which actually points directly into -// the final data structure where the bytes are to be stored, and the caller -// can interact directly with that buffer, eliminating an intermediate copy -// operation. -// -// As an example, consider the common case in which you are reading bytes -// from an array that is already in memory (or perhaps an mmap()ed file). -// With classic I/O streams, you would do something like: -// char buffer[BUFFER_SIZE]; -// input->Read(buffer, BUFFER_SIZE); -// DoSomething(buffer, BUFFER_SIZE); -// Then, the stream basically just calls memcpy() to copy the data from -// the array into your buffer. With a ZeroCopyInputStream, you would do -// this instead: -// const void* buffer; -// int size; -// input->Next(&buffer, &size); -// DoSomething(buffer, size); -// Here, no copy is performed. The input stream returns a pointer directly -// into the backing array, and the caller ends up reading directly from it. -// -// If you want to be able to read the old-fashion way, you can create -// a CodedInputStream or CodedOutputStream wrapping these objects and use -// their ReadRaw()/WriteRaw() methods. These will, of course, add a copy -// step, but Coded*Stream will handle buffering so at least it will be -// reasonably efficient. -// -// ZeroCopyInputStream example: -// // Read in a file and print its contents to stdout. -// int fd = open("myfile", O_RDONLY); -// ZeroCopyInputStream* input = new FileInputStream(fd); -// -// const void* buffer; -// int size; -// while (input->Next(&buffer, &size)) { -// cout.write(buffer, size); -// } -// -// delete input; -// close(fd); -// -// ZeroCopyOutputStream example: -// // Copy the contents of "infile" to "outfile", using plain read() for -// // "infile" but a ZeroCopyOutputStream for "outfile". -// int infd = open("infile", O_RDONLY); -// int outfd = open("outfile", O_WRONLY); -// ZeroCopyOutputStream* output = new FileOutputStream(outfd); -// -// void* buffer; -// int size; -// while (output->Next(&buffer, &size)) { -// int bytes = read(infd, buffer, size); -// if (bytes < size) { -// // Reached EOF. -// output->BackUp(size - bytes); -// break; -// } -// } -// -// delete output; -// close(infd); -// close(outfd); - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ - -#include -#include - -namespace google { - -namespace protobuf { -namespace io { - -// Defined in this file. -class ZeroCopyInputStream; -class ZeroCopyOutputStream; - -// Abstract interface similar to an input stream but designed to minimize -// copying. -class LIBPROTOBUF_EXPORT ZeroCopyInputStream { - public: - inline ZeroCopyInputStream() {} - virtual ~ZeroCopyInputStream(); - - // Obtains a chunk of data from the stream. - // - // Preconditions: - // * "size" and "data" are not NULL. - // - // Postconditions: - // * If the returned value is false, there is no more data to return or - // an error occurred. All errors are permanent. - // * Otherwise, "size" points to the actual number of bytes read and "data" - // points to a pointer to a buffer containing these bytes. - // * Ownership of this buffer remains with the stream, and the buffer - // remains valid only until some other method of the stream is called - // or the stream is destroyed. - // * It is legal for the returned buffer to have zero size, as long - // as repeatedly calling Next() eventually yields a buffer with non-zero - // size. - virtual bool Next(const void** data, int* size) = 0; - - // Backs up a number of bytes, so that the next call to Next() returns - // data again that was already returned by the last call to Next(). This - // is useful when writing procedures that are only supposed to read up - // to a certain point in the input, then return. If Next() returns a - // buffer that goes beyond what you wanted to read, you can use BackUp() - // to return to the point where you intended to finish. - // - // Preconditions: - // * The last method called must have been Next(). - // * count must be less than or equal to the size of the last buffer - // returned by Next(). - // - // Postconditions: - // * The last "count" bytes of the last buffer returned by Next() will be - // pushed back into the stream. Subsequent calls to Next() will return - // the same data again before producing new data. - virtual void BackUp(int count) = 0; - - // Skips a number of bytes. Returns false if the end of the stream is - // reached or some input error occurred. In the end-of-stream case, the - // stream is advanced to the end of the stream (so ByteCount() will return - // the total size of the stream). - virtual bool Skip(int count) = 0; - - // Returns the total number of bytes read since this object was created. - virtual int64 ByteCount() const = 0; - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyInputStream); -}; - -// Abstract interface similar to an output stream but designed to minimize -// copying. -class LIBPROTOBUF_EXPORT ZeroCopyOutputStream { - public: - inline ZeroCopyOutputStream() {} - virtual ~ZeroCopyOutputStream(); - - // Obtains a buffer into which data can be written. Any data written - // into this buffer will eventually (maybe instantly, maybe later on) - // be written to the output. - // - // Preconditions: - // * "size" and "data" are not NULL. - // - // Postconditions: - // * If the returned value is false, an error occurred. All errors are - // permanent. - // * Otherwise, "size" points to the actual number of bytes in the buffer - // and "data" points to the buffer. - // * Ownership of this buffer remains with the stream, and the buffer - // remains valid only until some other method of the stream is called - // or the stream is destroyed. - // * Any data which the caller stores in this buffer will eventually be - // written to the output (unless BackUp() is called). - // * It is legal for the returned buffer to have zero size, as long - // as repeatedly calling Next() eventually yields a buffer with non-zero - // size. - virtual bool Next(void** data, int* size) = 0; - - // Backs up a number of bytes, so that the end of the last buffer returned - // by Next() is not actually written. This is needed when you finish - // writing all the data you want to write, but the last buffer was bigger - // than you needed. You don't want to write a bunch of garbage after the - // end of your data, so you use BackUp() to back up. - // - // Preconditions: - // * The last method called must have been Next(). - // * count must be less than or equal to the size of the last buffer - // returned by Next(). - // * The caller must not have written anything to the last "count" bytes - // of that buffer. - // - // Postconditions: - // * The last "count" bytes of the last buffer returned by Next() will be - // ignored. - virtual void BackUp(int count) = 0; - - // Returns the total number of bytes written since this object was created. - virtual int64 ByteCount() const = 0; - - // Write a given chunk of data to the output. Some output streams may - // implement this in a way that avoids copying. Check AllowsAliasing() before - // calling WriteAliasedRaw(). It will GOOGLE_CHECK fail if WriteAliasedRaw() is - // called on a stream that does not allow aliasing. - // - // NOTE: It is caller's responsibility to ensure that the chunk of memory - // remains live until all of the data has been consumed from the stream. - virtual bool WriteAliasedRaw(const void* data, int size); - virtual bool AllowsAliasing() const { return false; } - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ZeroCopyOutputStream); -}; - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_H__ diff --git a/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl.h b/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl.h deleted file mode 100644 index 3365790..0000000 --- a/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl.h +++ /dev/null @@ -1,358 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains common implementations of the interfaces defined in -// zero_copy_stream.h which are only included in the full (non-lite) -// protobuf library. These implementations include Unix file descriptors -// and C++ iostreams. See also: zero_copy_stream_impl_lite.h - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ - -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -namespace io { - - -// =================================================================== - -// A ZeroCopyInputStream which reads from a file descriptor. -// -// FileInputStream is preferred over using an ifstream with IstreamInputStream. -// The latter will introduce an extra layer of buffering, harming performance. -// Also, it's conceivable that FileInputStream could someday be enhanced -// to use zero-copy file descriptors on OSs which support them. -class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given Unix file descriptor. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. - explicit FileInputStream(int file_descriptor, int block_size = -1); - ~FileInputStream(); - - // Flushes any buffers and closes the underlying file. Returns false if - // an error occurs during the process; use GetErrno() to examine the error. - // Even if an error occurs, the file descriptor is closed when this returns. - bool Close(); - - // By default, the file descriptor is not closed when the stream is - // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: - // This leaves no way for the caller to detect if close() fails. If - // detecting close() errors is important to you, you should arrange - // to close the descriptor yourself. - void SetCloseOnDelete(bool value) { copying_input_.SetCloseOnDelete(value); } - - // If an I/O error has occurred on this file descriptor, this is the - // errno from that error. Otherwise, this is zero. Once an error - // occurs, the stream is broken and all subsequent operations will - // fail. - int GetErrno() { return copying_input_.GetErrno(); } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingFileInputStream : public CopyingInputStream { - public: - CopyingFileInputStream(int file_descriptor); - ~CopyingFileInputStream(); - - bool Close(); - void SetCloseOnDelete(bool value) { close_on_delete_ = value; } - int GetErrno() { return errno_; } - - // implements CopyingInputStream --------------------------------- - int Read(void* buffer, int size); - int Skip(int count); - - private: - // The file descriptor. - const int file_; - bool close_on_delete_; - bool is_closed_; - - // The errno of the I/O error, if one has occurred. Otherwise, zero. - int errno_; - - // Did we try to seek once and fail? If so, we assume this file descriptor - // doesn't support seeking and won't try again. - bool previous_seek_failed_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileInputStream); - }; - - CopyingFileInputStream copying_input_; - CopyingInputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which writes to a file descriptor. -// -// FileOutputStream is preferred over using an ofstream with -// OstreamOutputStream. The latter will introduce an extra layer of buffering, -// harming performance. Also, it's conceivable that FileOutputStream could -// someday be enhanced to use zero-copy file descriptors on OSs which -// support them. -class LIBPROTOBUF_EXPORT FileOutputStream : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given Unix file descriptor. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit FileOutputStream(int file_descriptor, int block_size = -1); - ~FileOutputStream(); - - // Flushes any buffers and closes the underlying file. Returns false if - // an error occurs during the process; use GetErrno() to examine the error. - // Even if an error occurs, the file descriptor is closed when this returns. - bool Close(); - - // Flushes FileOutputStream's buffers but does not close the - // underlying file. No special measures are taken to ensure that - // underlying operating system file object is synchronized to disk. - bool Flush(); - - // By default, the file descriptor is not closed when the stream is - // destroyed. Call SetCloseOnDelete(true) to change that. WARNING: - // This leaves no way for the caller to detect if close() fails. If - // detecting close() errors is important to you, you should arrange - // to close the descriptor yourself. - void SetCloseOnDelete(bool value) { copying_output_.SetCloseOnDelete(value); } - - // If an I/O error has occurred on this file descriptor, this is the - // errno from that error. Otherwise, this is zero. Once an error - // occurs, the stream is broken and all subsequent operations will - // fail. - int GetErrno() { return copying_output_.GetErrno(); } - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingFileOutputStream : public CopyingOutputStream { - public: - CopyingFileOutputStream(int file_descriptor); - ~CopyingFileOutputStream(); - - bool Close(); - void SetCloseOnDelete(bool value) { close_on_delete_ = value; } - int GetErrno() { return errno_; } - - // implements CopyingOutputStream -------------------------------- - bool Write(const void* buffer, int size); - - private: - // The file descriptor. - const int file_; - bool close_on_delete_; - bool is_closed_; - - // The errno of the I/O error, if one has occurred. Otherwise, zero. - int errno_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingFileOutputStream); - }; - - CopyingFileOutputStream copying_output_; - CopyingOutputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileOutputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which reads from a C++ istream. -// -// Note that for reading files (or anything represented by a file descriptor), -// FileInputStream is more efficient. -class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given C++ istream. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. - explicit IstreamInputStream(std::istream* stream, int block_size = -1); - ~IstreamInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingIstreamInputStream : public CopyingInputStream { - public: - CopyingIstreamInputStream(std::istream* input); - ~CopyingIstreamInputStream(); - - // implements CopyingInputStream --------------------------------- - int Read(void* buffer, int size); - // (We use the default implementation of Skip().) - - private: - // The stream. - std::istream* input_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingIstreamInputStream); - }; - - CopyingIstreamInputStream copying_input_; - CopyingInputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(IstreamInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which writes to a C++ ostream. -// -// Note that for writing files (or anything represented by a file descriptor), -// FileOutputStream is more efficient. -class LIBPROTOBUF_EXPORT OstreamOutputStream : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given C++ ostream. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit OstreamOutputStream(std::ostream* stream, int block_size = -1); - ~OstreamOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - class LIBPROTOBUF_EXPORT CopyingOstreamOutputStream : public CopyingOutputStream { - public: - CopyingOstreamOutputStream(std::ostream* output); - ~CopyingOstreamOutputStream(); - - // implements CopyingOutputStream -------------------------------- - bool Write(const void* buffer, int size); - - private: - // The stream. - std::ostream* output_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOstreamOutputStream); - }; - - CopyingOstreamOutputStream copying_output_; - CopyingOutputStreamAdaptor impl_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(OstreamOutputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which reads from several other streams in sequence. -// ConcatenatingInputStream is unable to distinguish between end-of-stream -// and read errors in the underlying streams, so it assumes any errors mean -// end-of-stream. So, if the underlying streams fail for any other reason, -// ConcatenatingInputStream may do odd things. It is suggested that you do -// not use ConcatenatingInputStream on streams that might produce read errors -// other than end-of-stream. -class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { - public: - // All streams passed in as well as the array itself must remain valid - // until the ConcatenatingInputStream is destroyed. - ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count); - ~ConcatenatingInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - // As streams are retired, streams_ is incremented and count_ is - // decremented. - ZeroCopyInputStream* const* streams_; - int stream_count_; - int64 bytes_retired_; // Bytes read from previous streams. - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ConcatenatingInputStream); -}; - -// =================================================================== - -// A ZeroCopyInputStream which wraps some other stream and limits it to -// a particular byte count. -class LIBPROTOBUF_EXPORT LimitingInputStream : public ZeroCopyInputStream { - public: - LimitingInputStream(ZeroCopyInputStream* input, int64 limit); - ~LimitingInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - ZeroCopyInputStream* input_; - int64 limit_; // Decreases as we go, becomes negative if we overshoot. - int64 prior_bytes_read_; // Bytes read on underlying stream at construction - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LimitingInputStream); -}; - -// =================================================================== - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_H__ diff --git a/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl_lite.h b/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl_lite.h deleted file mode 100644 index e4d6a02..0000000 --- a/app/src/main/cpp/google/protobuf/io/zero_copy_stream_impl_lite.h +++ /dev/null @@ -1,410 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This file contains common implementations of the interfaces defined in -// zero_copy_stream.h which are included in the "lite" protobuf library. -// These implementations cover I/O on raw arrays and strings, as well as -// adaptors which make it easy to implement streams based on traditional -// streams. Of course, many users will probably want to write their own -// implementations of these interfaces specific to the particular I/O -// abstractions they prefer to use, but these should cover the most common -// cases. - -#ifndef GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ -#define GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ - -#include -#ifndef _SHARED_PTR_H -#include -#endif -#include -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -namespace io { - -// =================================================================== - -// A ZeroCopyInputStream backed by an in-memory array of bytes. -class LIBPROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream { - public: - // Create an InputStream that returns the bytes pointed to by "data". - // "data" remains the property of the caller but must remain valid until - // the stream is destroyed. If a block_size is given, calls to Next() - // will return data blocks no larger than the given size. Otherwise, the - // first call to Next() returns the entire array. block_size is mainly - // useful for testing; in production you would probably never want to set - // it. - ArrayInputStream(const void* data, int size, int block_size = -1); - ~ArrayInputStream(); - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - - private: - const uint8* const data_; // The byte array. - const int size_; // Total size of the array. - const int block_size_; // How many bytes to return at a time. - - int position_; - int last_returned_size_; // How many bytes we returned last time Next() - // was called (used for error checking only). - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayInputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream backed by an in-memory array of bytes. -class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream { - public: - // Create an OutputStream that writes to the bytes pointed to by "data". - // "data" remains the property of the caller but must remain valid until - // the stream is destroyed. If a block_size is given, calls to Next() - // will return data blocks no larger than the given size. Otherwise, the - // first call to Next() returns the entire array. block_size is mainly - // useful for testing; in production you would probably never want to set - // it. - ArrayOutputStream(void* data, int size, int block_size = -1); - ~ArrayOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - uint8* const data_; // The byte array. - const int size_; // Total size of the array. - const int block_size_; // How many bytes to return at a time. - - int position_; - int last_returned_size_; // How many bytes we returned last time Next() - // was called (used for error checking only). - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayOutputStream); -}; - -// =================================================================== - -// A ZeroCopyOutputStream which appends bytes to a string. -class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { - public: - // Create a StringOutputStream which appends bytes to the given string. - // The string remains property of the caller, but it is mutated in arbitrary - // ways and MUST NOT be accessed in any way until you're done with the - // stream. Either be sure there's no further usage, or (safest) destroy the - // stream before using the contents. - // - // Hint: If you call target->reserve(n) before creating the stream, - // the first call to Next() will return at least n bytes of buffer - // space. - explicit StringOutputStream(string* target); - ~StringOutputStream(); - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - protected: - void SetString(string* target); - - private: - static const int kMinimumSize = 16; - - string* target_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringOutputStream); -}; - -// LazyStringOutputStream is a StringOutputStream with lazy acquisition of -// the output string from a callback. The string is owned externally, and not -// deleted in the stream destructor. -class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream { - public: - // Callback should be permanent (non-self-deleting). Ownership is transferred - // to the LazyStringOutputStream. - explicit LazyStringOutputStream(ResultCallback* callback); - ~LazyStringOutputStream(); - - // implements ZeroCopyOutputStream, overriding StringOutputStream ----------- - bool Next(void** data, int* size); - int64 ByteCount() const; - - private: - const google::protobuf::scoped_ptr > callback_; - bool string_is_set_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(LazyStringOutputStream); -}; - -// Note: There is no StringInputStream. Instead, just create an -// ArrayInputStream as follows: -// ArrayInputStream input(str.data(), str.size()); - -// =================================================================== - -// A generic traditional input stream interface. -// -// Lots of traditional input streams (e.g. file descriptors, C stdio -// streams, and C++ iostreams) expose an interface where every read -// involves copying bytes into a buffer. If you want to take such an -// interface and make a ZeroCopyInputStream based on it, simply implement -// CopyingInputStream and then use CopyingInputStreamAdaptor. -// -// CopyingInputStream implementations should avoid buffering if possible. -// CopyingInputStreamAdaptor does its own buffering and will read data -// in large blocks. -class LIBPROTOBUF_EXPORT CopyingInputStream { - public: - virtual ~CopyingInputStream(); - - // Reads up to "size" bytes into the given buffer. Returns the number of - // bytes read. Read() waits until at least one byte is available, or - // returns zero if no bytes will ever become available (EOF), or -1 if a - // permanent read error occurred. - virtual int Read(void* buffer, int size) = 0; - - // Skips the next "count" bytes of input. Returns the number of bytes - // actually skipped. This will always be exactly equal to "count" unless - // EOF was reached or a permanent read error occurred. - // - // The default implementation just repeatedly calls Read() into a scratch - // buffer. - virtual int Skip(int count); -}; - -// A ZeroCopyInputStream which reads from a CopyingInputStream. This is -// useful for implementing ZeroCopyInputStreams that read from traditional -// streams. Note that this class is not really zero-copy. -// -// If you want to read from file descriptors or C++ istreams, this is -// already implemented for you: use FileInputStream or IstreamInputStream -// respectively. -class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream { - public: - // Creates a stream that reads from the given CopyingInputStream. - // If a block_size is given, it specifies the number of bytes that - // should be read and returned with each call to Next(). Otherwise, - // a reasonable default is used. The caller retains ownership of - // copying_stream unless SetOwnsCopyingStream(true) is called. - explicit CopyingInputStreamAdaptor(CopyingInputStream* copying_stream, - int block_size = -1); - ~CopyingInputStreamAdaptor(); - - // Call SetOwnsCopyingStream(true) to tell the CopyingInputStreamAdaptor to - // delete the underlying CopyingInputStream when it is destroyed. - void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } - - // implements ZeroCopyInputStream ---------------------------------- - bool Next(const void** data, int* size); - void BackUp(int count); - bool Skip(int count); - int64 ByteCount() const; - - private: - // Insures that buffer_ is not NULL. - void AllocateBufferIfNeeded(); - // Frees the buffer and resets buffer_used_. - void FreeBuffer(); - - // The underlying copying stream. - CopyingInputStream* copying_stream_; - bool owns_copying_stream_; - - // True if we have seen a permenant error from the underlying stream. - bool failed_; - - // The current position of copying_stream_, relative to the point where - // we started reading. - int64 position_; - - // Data is read into this buffer. It may be NULL if no buffer is currently - // in use. Otherwise, it points to an array of size buffer_size_. - google::protobuf::scoped_array buffer_; - const int buffer_size_; - - // Number of valid bytes currently in the buffer (i.e. the size last - // returned by Next()). 0 <= buffer_used_ <= buffer_size_. - int buffer_used_; - - // Number of bytes in the buffer which were backed up over by a call to - // BackUp(). These need to be returned again. - // 0 <= backup_bytes_ <= buffer_used_ - int backup_bytes_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingInputStreamAdaptor); -}; - -// =================================================================== - -// A generic traditional output stream interface. -// -// Lots of traditional output streams (e.g. file descriptors, C stdio -// streams, and C++ iostreams) expose an interface where every write -// involves copying bytes from a buffer. If you want to take such an -// interface and make a ZeroCopyOutputStream based on it, simply implement -// CopyingOutputStream and then use CopyingOutputStreamAdaptor. -// -// CopyingOutputStream implementations should avoid buffering if possible. -// CopyingOutputStreamAdaptor does its own buffering and will write data -// in large blocks. -class LIBPROTOBUF_EXPORT CopyingOutputStream { - public: - virtual ~CopyingOutputStream(); - - // Writes "size" bytes from the given buffer to the output. Returns true - // if successful, false on a write error. - virtual bool Write(const void* buffer, int size) = 0; -}; - -// A ZeroCopyOutputStream which writes to a CopyingOutputStream. This is -// useful for implementing ZeroCopyOutputStreams that write to traditional -// streams. Note that this class is not really zero-copy. -// -// If you want to write to file descriptors or C++ ostreams, this is -// already implemented for you: use FileOutputStream or OstreamOutputStream -// respectively. -class LIBPROTOBUF_EXPORT CopyingOutputStreamAdaptor : public ZeroCopyOutputStream { - public: - // Creates a stream that writes to the given Unix file descriptor. - // If a block_size is given, it specifies the size of the buffers - // that should be returned by Next(). Otherwise, a reasonable default - // is used. - explicit CopyingOutputStreamAdaptor(CopyingOutputStream* copying_stream, - int block_size = -1); - ~CopyingOutputStreamAdaptor(); - - // Writes all pending data to the underlying stream. Returns false if a - // write error occurred on the underlying stream. (The underlying - // stream itself is not necessarily flushed.) - bool Flush(); - - // Call SetOwnsCopyingStream(true) to tell the CopyingOutputStreamAdaptor to - // delete the underlying CopyingOutputStream when it is destroyed. - void SetOwnsCopyingStream(bool value) { owns_copying_stream_ = value; } - - // implements ZeroCopyOutputStream --------------------------------- - bool Next(void** data, int* size); - void BackUp(int count); - int64 ByteCount() const; - - private: - // Write the current buffer, if it is present. - bool WriteBuffer(); - // Insures that buffer_ is not NULL. - void AllocateBufferIfNeeded(); - // Frees the buffer. - void FreeBuffer(); - - // The underlying copying stream. - CopyingOutputStream* copying_stream_; - bool owns_copying_stream_; - - // True if we have seen a permenant error from the underlying stream. - bool failed_; - - // The current position of copying_stream_, relative to the point where - // we started writing. - int64 position_; - - // Data is written from this buffer. It may be NULL if no buffer is - // currently in use. Otherwise, it points to an array of size buffer_size_. - google::protobuf::scoped_array buffer_; - const int buffer_size_; - - // Number of valid bytes currently in the buffer (i.e. the size last - // returned by Next()). When BackUp() is called, we just reduce this. - // 0 <= buffer_used_ <= buffer_size_. - int buffer_used_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CopyingOutputStreamAdaptor); -}; - -// =================================================================== - -// mutable_string_data() and as_string_data() are workarounds to improve -// the performance of writing new data to an existing string. Unfortunately -// the methods provided by the string class are suboptimal, and using memcpy() -// is mildly annoying because it requires its pointer args to be non-NULL even -// if we ask it to copy 0 bytes. Furthermore, string_as_array() has the -// property that it always returns NULL if its arg is the empty string, exactly -// what we want to avoid if we're using it in conjunction with memcpy()! -// With C++11, the desired memcpy() boils down to memcpy(..., &(*s)[0], size), -// where s is a string*. Without C++11, &(*s)[0] is not guaranteed to be safe, -// so we use string_as_array(), and live with the extra logic that tests whether -// *s is empty. - -// Return a pointer to mutable characters underlying the given string. The -// return value is valid until the next time the string is resized. We -// trust the caller to treat the return value as an array of length s->size(). -inline char* mutable_string_data(string* s) { -#ifdef LANG_CXX11 - // This should be simpler & faster than string_as_array() because the latter - // is guaranteed to return NULL when *s is empty, so it has to check for that. - return &(*s)[0]; -#else - return string_as_array(s); -#endif -} - -// as_string_data(s) is equivalent to -// ({ char* p = mutable_string_data(s); make_pair(p, p != NULL); }) -// Sometimes it's faster: in some scenarios p cannot be NULL, and then the -// code can avoid that check. -inline std::pair as_string_data(string* s) { - char *p = mutable_string_data(s); -#ifdef LANG_CXX11 - return std::make_pair(p, true); -#else - return make_pair(p, p != NULL); -#endif -} - -} // namespace io -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_IO_ZERO_COPY_STREAM_IMPL_LITE_H__ diff --git a/app/src/main/cpp/google/protobuf/map.h b/app/src/main/cpp/google/protobuf/map.h deleted file mode 100644 index 2d29551..0000000 --- a/app/src/main/cpp/google/protobuf/map.h +++ /dev/null @@ -1,1749 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file defines the map container and its helpers to support protobuf maps. -// -// The Map and MapIterator types are provided by this header file. -// Please avoid using other types defined here, unless they are public -// types within Map or MapIterator, such as Map::value_type. - -#ifndef GOOGLE_PROTOBUF_MAP_H__ -#define GOOGLE_PROTOBUF_MAP_H__ - -#include -#include -#include // To support Visual Studio 2008 -#include -#include - -#include -#include -#include -#include -#include -#include -#if __cpp_exceptions && LANG_CXX11 -#include -#endif - -namespace google { -namespace protobuf { - -template -class Map; - -class MapIterator; - -template struct is_proto_enum; - -namespace internal { -template -class MapFieldLite; - -template -class MapField; - -template -class TypeDefinedMapFieldBase; - -class DynamicMapField; - -class GeneratedMessageReflection; -} // namespace internal - -#define TYPE_CHECK(EXPECTEDTYPE, METHOD) \ - if (type() != EXPECTEDTYPE) { \ - GOOGLE_LOG(FATAL) \ - << "Protocol Buffer map usage error:\n" \ - << METHOD << " type does not match\n" \ - << " Expected : " \ - << FieldDescriptor::CppTypeName(EXPECTEDTYPE) << "\n" \ - << " Actual : " \ - << FieldDescriptor::CppTypeName(type()); \ - } - -// MapKey is an union type for representing any possible -// map key. -class LIBPROTOBUF_EXPORT MapKey { - public: - MapKey() : type_(0) { - } - MapKey(const MapKey& other) : type_(0) { - CopyFrom(other); - } - - ~MapKey() { - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - delete val_.string_value_; - } - } - - FieldDescriptor::CppType type() const { - if (type_ == 0) { - GOOGLE_LOG(FATAL) - << "Protocol Buffer map usage error:\n" - << "MapKey::type MapKey is not initialized. " - << "Call set methods to initialize MapKey."; - } - return (FieldDescriptor::CppType)type_; - } - - void SetInt64Value(int64 value) { - SetType(FieldDescriptor::CPPTYPE_INT64); - val_.int64_value_ = value; - } - void SetUInt64Value(uint64 value) { - SetType(FieldDescriptor::CPPTYPE_UINT64); - val_.uint64_value_ = value; - } - void SetInt32Value(int32 value) { - SetType(FieldDescriptor::CPPTYPE_INT32); - val_.int32_value_ = value; - } - void SetUInt32Value(uint32 value) { - SetType(FieldDescriptor::CPPTYPE_UINT32); - val_.uint32_value_ = value; - } - void SetBoolValue(bool value) { - SetType(FieldDescriptor::CPPTYPE_BOOL); - val_.bool_value_ = value; - } - void SetStringValue(const string& val) { - SetType(FieldDescriptor::CPPTYPE_STRING); - *val_.string_value_ = val; - } - - int64 GetInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapKey::GetInt64Value"); - return val_.int64_value_; - } - uint64 GetUInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapKey::GetUInt64Value"); - return val_.uint64_value_; - } - int32 GetInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapKey::GetInt32Value"); - return val_.int32_value_; - } - uint32 GetUInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapKey::GetUInt32Value"); - return val_.uint32_value_; - } - bool GetBoolValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapKey::GetBoolValue"); - return val_.bool_value_; - } - const string& GetStringValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapKey::GetStringValue"); - return *val_.string_value_; - } - - bool operator<(const MapKey& other) const { - if (type_ != other.type_) { - // We could define a total order that handles this case, but - // there currently no need. So, for now, fail. - GOOGLE_LOG(FATAL) << "Unsupported: type mismatch"; - } - switch (type()) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - return false; - case FieldDescriptor::CPPTYPE_STRING: - return *val_.string_value_ < *other.val_.string_value_; - case FieldDescriptor::CPPTYPE_INT64: - return val_.int64_value_ < other.val_.int64_value_; - case FieldDescriptor::CPPTYPE_INT32: - return val_.int32_value_ < other.val_.int32_value_; - case FieldDescriptor::CPPTYPE_UINT64: - return val_.uint64_value_ < other.val_.uint64_value_; - case FieldDescriptor::CPPTYPE_UINT32: - return val_.uint32_value_ < other.val_.uint32_value_; - case FieldDescriptor::CPPTYPE_BOOL: - return val_.bool_value_ < other.val_.bool_value_; - } - return false; - } - - bool operator==(const MapKey& other) const { - if (type_ != other.type_) { - // To be consistent with operator<, we don't allow this either. - GOOGLE_LOG(FATAL) << "Unsupported: type mismatch"; - } - switch (type()) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case FieldDescriptor::CPPTYPE_STRING: - return *val_.string_value_ == *other.val_.string_value_; - case FieldDescriptor::CPPTYPE_INT64: - return val_.int64_value_ == other.val_.int64_value_; - case FieldDescriptor::CPPTYPE_INT32: - return val_.int32_value_ == other.val_.int32_value_; - case FieldDescriptor::CPPTYPE_UINT64: - return val_.uint64_value_ == other.val_.uint64_value_; - case FieldDescriptor::CPPTYPE_UINT32: - return val_.uint32_value_ == other.val_.uint32_value_; - case FieldDescriptor::CPPTYPE_BOOL: - return val_.bool_value_ == other.val_.bool_value_; - } - GOOGLE_LOG(FATAL) << "Can't get here."; - return false; - } - - void CopyFrom(const MapKey& other) { - SetType(other.type()); - switch (type_) { - case FieldDescriptor::CPPTYPE_DOUBLE: - case FieldDescriptor::CPPTYPE_FLOAT: - case FieldDescriptor::CPPTYPE_ENUM: - case FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case FieldDescriptor::CPPTYPE_STRING: - *val_.string_value_ = *other.val_.string_value_; - break; - case FieldDescriptor::CPPTYPE_INT64: - val_.int64_value_ = other.val_.int64_value_; - break; - case FieldDescriptor::CPPTYPE_INT32: - val_.int32_value_ = other.val_.int32_value_; - break; - case FieldDescriptor::CPPTYPE_UINT64: - val_.uint64_value_ = other.val_.uint64_value_; - break; - case FieldDescriptor::CPPTYPE_UINT32: - val_.uint32_value_ = other.val_.uint32_value_; - break; - case FieldDescriptor::CPPTYPE_BOOL: - val_.bool_value_ = other.val_.bool_value_; - break; - } - } - - private: - template - friend class internal::TypeDefinedMapFieldBase; - friend class MapIterator; - friend class internal::DynamicMapField; - - union KeyValue { - KeyValue() {} - string* string_value_; - int64 int64_value_; - int32 int32_value_; - uint64 uint64_value_; - uint32 uint32_value_; - bool bool_value_; - } val_; - - void SetType(FieldDescriptor::CppType type) { - if (type_ == type) return; - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - delete val_.string_value_; - } - type_ = type; - if (type_ == FieldDescriptor::CPPTYPE_STRING) { - val_.string_value_ = new string; - } - } - - // type_ is 0 or a valid FieldDescriptor::CppType. - int type_; -}; - -// MapValueRef points to a map value. -class LIBPROTOBUF_EXPORT MapValueRef { - public: - MapValueRef() : data_(NULL), type_(0) {} - - void SetInt64Value(int64 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapValueRef::SetInt64Value"); - *reinterpret_cast(data_) = value; - } - void SetUInt64Value(uint64 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapValueRef::SetUInt64Value"); - *reinterpret_cast(data_) = value; - } - void SetInt32Value(int32 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapValueRef::SetInt32Value"); - *reinterpret_cast(data_) = value; - } - void SetUInt32Value(uint32 value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapValueRef::SetUInt32Value"); - *reinterpret_cast(data_) = value; - } - void SetBoolValue(bool value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapValueRef::SetBoolValue"); - *reinterpret_cast(data_) = value; - } - // TODO(jieluo) - Checks that enum is member. - void SetEnumValue(int value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, - "MapValueRef::SetEnumValue"); - *reinterpret_cast(data_) = value; - } - void SetStringValue(const string& value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapValueRef::SetStringValue"); - *reinterpret_cast(data_) = value; - } - void SetFloatValue(float value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, - "MapValueRef::SetFloatValue"); - *reinterpret_cast(data_) = value; - } - void SetDoubleValue(double value) { - TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, - "MapValueRef::SetDoubleValue"); - *reinterpret_cast(data_) = value; - } - - int64 GetInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT64, - "MapValueRef::GetInt64Value"); - return *reinterpret_cast(data_); - } - uint64 GetUInt64Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT64, - "MapValueRef::GetUInt64Value"); - return *reinterpret_cast(data_); - } - int32 GetInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_INT32, - "MapValueRef::GetInt32Value"); - return *reinterpret_cast(data_); - } - uint32 GetUInt32Value() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_UINT32, - "MapValueRef::GetUInt32Value"); - return *reinterpret_cast(data_); - } - bool GetBoolValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_BOOL, - "MapValueRef::GetBoolValue"); - return *reinterpret_cast(data_); - } - int GetEnumValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_ENUM, - "MapValueRef::GetEnumValue"); - return *reinterpret_cast(data_); - } - const string& GetStringValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_STRING, - "MapValueRef::GetStringValue"); - return *reinterpret_cast(data_); - } - float GetFloatValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_FLOAT, - "MapValueRef::GetFloatValue"); - return *reinterpret_cast(data_); - } - double GetDoubleValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_DOUBLE, - "MapValueRef::GetDoubleValue"); - return *reinterpret_cast(data_); - } - - const Message& GetMessageValue() const { - TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, - "MapValueRef::GetMessageValue"); - return *reinterpret_cast(data_); - } - - Message* MutableMessageValue() { - TYPE_CHECK(FieldDescriptor::CPPTYPE_MESSAGE, - "MapValueRef::MutableMessageValue"); - return reinterpret_cast(data_); - } - - private: - template - friend class internal::MapField; - template - friend class internal::TypeDefinedMapFieldBase; - friend class MapIterator; - friend class internal::GeneratedMessageReflection; - friend class internal::DynamicMapField; - - void SetType(FieldDescriptor::CppType type) { - type_ = type; - } - - FieldDescriptor::CppType type() const { - if (type_ == 0 || data_ == NULL) { - GOOGLE_LOG(FATAL) - << "Protocol Buffer map usage error:\n" - << "MapValueRef::type MapValueRef is not initialized."; - } - return (FieldDescriptor::CppType)type_; - } - void SetValue(const void* val) { - data_ = const_cast(val); - } - void CopyFrom(const MapValueRef& other) { - type_ = other.type_; - data_ = other.data_; - } - // Only used in DynamicMapField - void DeleteData() { - switch (type_) { -#define HANDLE_TYPE(CPPTYPE, TYPE) \ - case google::protobuf::FieldDescriptor::CPPTYPE_##CPPTYPE: { \ - delete reinterpret_cast(data_); \ - break; \ - } - HANDLE_TYPE(INT32, int32); - HANDLE_TYPE(INT64, int64); - HANDLE_TYPE(UINT32, uint32); - HANDLE_TYPE(UINT64, uint64); - HANDLE_TYPE(DOUBLE, double); - HANDLE_TYPE(FLOAT, float); - HANDLE_TYPE(BOOL, bool); - HANDLE_TYPE(STRING, string); - HANDLE_TYPE(ENUM, int32); - HANDLE_TYPE(MESSAGE, Message); -#undef HANDLE_TYPE - } - } - // data_ point to a map value. MapValueRef does not - // own this value. - void* data_; - // type_ is 0 or a valid FieldDescriptor::CppType. - int type_; -}; - -#undef TYPE_CHECK - -// This is the class for google::protobuf::Map's internal value_type. Instead of using -// std::pair as value_type, we use this class which provides us more control of -// its process of construction and destruction. -template -class MapPair { - public: - typedef const Key first_type; - typedef T second_type; - - MapPair(const Key& other_first, const T& other_second) - : first(other_first), second(other_second) {} - explicit MapPair(const Key& other_first) : first(other_first), second() {} - MapPair(const MapPair& other) - : first(other.first), second(other.second) {} - - ~MapPair() {} - - // Implicitly convertible to std::pair of compatible types. - template - operator std::pair() const { - return std::pair(first, second); - } - - const Key first; - T second; - - private: - friend class ::google::protobuf::Arena; - friend class Map; -}; - -// google::protobuf::Map is an associative container type used to store protobuf map -// fields. Each Map instance may or may not use a different hash function, a -// different iteration order, and so on. E.g., please don't examine -// implementation details to decide if the following would work: -// Map m0, m1; -// m0[0] = m1[0] = m0[1] = m1[1] = 0; -// assert(m0.begin()->first == m1.begin()->first); // Bug! -// -// Map's interface is similar to std::unordered_map, except that Map is not -// designed to play well with exceptions. -template -class Map { - public: - typedef Key key_type; - typedef T mapped_type; - typedef MapPair value_type; - - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - - typedef size_t size_type; - typedef hash hasher; - - explicit Map(bool old_style = true) - : arena_(NULL), - default_enum_value_(0), - old_style_(old_style) { - Init(); - } - explicit Map(Arena* arena, bool old_style = true) - : arena_(arena), - default_enum_value_(0), - old_style_(old_style) { - Init(); - } - Map(const Map& other) - : arena_(NULL), - default_enum_value_(other.default_enum_value_), - old_style_(other.old_style_) { - Init(); - insert(other.begin(), other.end()); - } - template - Map(const InputIt& first, const InputIt& last, bool old_style = true) - : arena_(NULL), - default_enum_value_(0), - old_style_(old_style) { - Init(); - insert(first, last); - } - - ~Map() { - clear(); - if (arena_ == NULL) { - if (old_style_) - delete deprecated_elements_; - else - delete elements_; - } - } - - private: - void Init() { - if (old_style_) - deprecated_elements_ = Arena::Create( - arena_, 0, hasher(), std::equal_to(), - MapAllocator*> >(arena_)); - else - elements_ = - Arena::Create(arena_, 0, hasher(), Allocator(arena_)); - } - - // re-implement std::allocator to use arena allocator for memory allocation. - // Used for google::protobuf::Map implementation. Users should not use this class - // directly. - template - class MapAllocator { - public: - typedef U value_type; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - - MapAllocator() : arena_(NULL) {} - explicit MapAllocator(Arena* arena) : arena_(arena) {} - template - MapAllocator(const MapAllocator& allocator) - : arena_(allocator.arena()) {} - - pointer allocate(size_type n, const_pointer hint = 0) { - // If arena is not given, malloc needs to be called which doesn't - // construct element object. - if (arena_ == NULL) { - return static_cast(::operator new(n * sizeof(value_type))); - } else { - return reinterpret_cast( - Arena::CreateArray(arena_, n * sizeof(value_type))); - } - } - - void deallocate(pointer p, size_type n) { - if (arena_ == NULL) { -#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) - ::operator delete(p, n * sizeof(value_type)); -#else - ::operator delete(p); -#endif - } - } - -#if __cplusplus >= 201103L && !defined(GOOGLE_PROTOBUF_OS_APPLE) && \ - !defined(GOOGLE_PROTOBUF_OS_NACL) && \ - !defined(GOOGLE_PROTOBUF_OS_ANDROID) && \ - !defined(GOOGLE_PROTOBUF_OS_EMSCRIPTEN) - template - void construct(NodeType* p, Args&&... args) { - // Clang 3.6 doesn't compile static casting to void* directly. (Issue - // #1266) According C++ standard 5.2.9/1: "The static_cast operator shall - // not cast away constness". So first the maybe const pointer is casted to - // const void* and after the const void* is const casted. - new (const_cast(static_cast(p))) - NodeType(std::forward(args)...); - } - - template - void destroy(NodeType* p) { - p->~NodeType(); - } -#else - void construct(pointer p, const_reference t) { new (p) value_type(t); } - - void destroy(pointer p) { p->~value_type(); } -#endif - - template - struct rebind { - typedef MapAllocator other; - }; - - template - bool operator==(const MapAllocator& other) const { - return arena_ == other.arena_; - } - - template - bool operator!=(const MapAllocator& other) const { - return arena_ != other.arena_; - } - - // To support Visual Studio 2008 - size_type max_size() const { - return std::numeric_limits::max(); - } - - // To support gcc-4.4, which does not properly - // support templated friend classes - Arena* arena() const { - return arena_; - } - - private: - typedef void DestructorSkippable_; - Arena* const arena_; - }; - - // InnerMap's key type is Key and its value type is value_type*. We use a - // custom class here and for Node, below, to ensure that k_ is at offset 0, - // allowing safe conversion from pointer to Node to pointer to Key, and vice - // versa when appropriate. - class KeyValuePair { - public: - KeyValuePair(const Key& k, value_type* v) : k_(k), v_(v) {} - - const Key& key() const { return k_; } - Key& key() { return k_; } - value_type* const value() const { return v_; } - value_type*& value() { return v_; } - - private: - Key k_; - value_type* v_; - }; - - typedef MapAllocator Allocator; - - // InnerMap is a generic hash-based map. It doesn't contain any - // protocol-buffer-specific logic. It is a chaining hash map with the - // additional feature that some buckets can be converted to use an ordered - // container. This ensures O(lg n) bounds on find, insert, and erase, while - // avoiding the overheads of ordered containers most of the time. - // - // The implementation doesn't need the full generality of unordered_map, - // and it doesn't have it. More bells and whistles can be added as needed. - // Some implementation details: - // 1. The hash function has type hasher and the equality function - // equal_to. We inherit from hasher to save space - // (empty-base-class optimization). - // 2. The number of buckets is a power of two. - // 3. Buckets are converted to trees in pairs: if we convert bucket b then - // buckets b and b^1 will share a tree. Invariant: buckets b and b^1 have - // the same non-NULL value iff they are sharing a tree. (An alternative - // implementation strategy would be to have a tag bit per bucket.) - // 4. As is typical for hash_map and such, the Keys and Values are always - // stored in linked list nodes. Pointers to elements are never invalidated - // until the element is deleted. - // 5. The trees' payload type is pointer to linked-list node. Tree-converting - // a bucket doesn't copy Key-Value pairs. - // 6. Once we've tree-converted a bucket, it is never converted back. However, - // the items a tree contains may wind up assigned to trees or lists upon a - // rehash. - // 7. The code requires no C++ features from C++11 or later. - // 8. Mutations to a map do not invalidate the map's iterators, pointers to - // elements, or references to elements. - // 9. Except for erase(iterator), any non-const method can reorder iterators. - class InnerMap : private hasher { - public: - typedef value_type* Value; - - InnerMap(size_type n, hasher h, Allocator alloc) - : hasher(h), - num_elements_(0), - seed_(Seed()), - table_(NULL), - alloc_(alloc) { - n = TableSize(n); - table_ = CreateEmptyTable(n); - num_buckets_ = index_of_first_non_null_ = n; - } - - ~InnerMap() { - if (table_ != NULL) { - clear(); - Dealloc(table_, num_buckets_); - } - } - - private: - enum { kMinTableSize = 8 }; - - // Linked-list nodes, as one would expect for a chaining hash table. - struct Node { - KeyValuePair kv; - Node* next; - }; - - // This is safe only if the given pointer is known to point to a Key that is - // part of a Node. - static Node* NodePtrFromKeyPtr(Key* k) { - return reinterpret_cast(k); - } - - static Key* KeyPtrFromNodePtr(Node* node) { return &node->kv.key(); } - - // Trees. The payload type is pointer to Key, so that we can query the tree - // with Keys that are not in any particular data structure. When we insert, - // though, the pointer is always pointing to a Key that is inside a Node. - struct KeyCompare { - bool operator()(const Key* n0, const Key* n1) const { return *n0 < *n1; } - }; - typedef typename Allocator::template rebind::other KeyPtrAllocator; - typedef std::set Tree; - - // iterator and const_iterator are instantiations of iterator_base. - template - class iterator_base { - public: - typedef KeyValueType& reference; - typedef KeyValueType* pointer; - typedef typename Tree::iterator TreeIterator; - - // Invariants: - // node_ is always correct. This is handy because the most common - // operations are operator* and operator-> and they only use node_. - // When node_ is set to a non-NULL value, all the other non-const fields - // are updated to be correct also, but those fields can become stale - // if the underlying map is modified. When those fields are needed they - // are rechecked, and updated if necessary. - iterator_base() : node_(NULL) {} - - explicit iterator_base(const InnerMap* m) : m_(m) { - SearchFrom(m->index_of_first_non_null_); - } - - // Any iterator_base can convert to any other. This is overkill, and we - // rely on the enclosing class to use it wisely. The standard "iterator - // can convert to const_iterator" is OK but the reverse direction is not. - template - explicit iterator_base(const iterator_base& it) - : node_(it.node_), - m_(it.m_), - bucket_index_(it.bucket_index_), - tree_it_(it.tree_it_) {} - - iterator_base(Node* n, const InnerMap* m, size_type index) - : node_(n), - m_(m), - bucket_index_(index) {} - - iterator_base(TreeIterator tree_it, const InnerMap* m, size_type index) - : node_(NodePtrFromKeyPtr(*tree_it)), - m_(m), - bucket_index_(index), - tree_it_(tree_it) { - // Invariant: iterators that use tree_it_ have an even bucket_index_. - GOOGLE_DCHECK_EQ(bucket_index_ % 2, 0); - } - - // Advance through buckets, looking for the first that isn't empty. - // If nothing non-empty is found then leave node_ == NULL. - void SearchFrom(size_type start_bucket) { - GOOGLE_DCHECK(m_->index_of_first_non_null_ == m_->num_buckets_ || - m_->table_[m_->index_of_first_non_null_] != NULL); - node_ = NULL; - for (bucket_index_ = start_bucket; bucket_index_ < m_->num_buckets_; - bucket_index_++) { - if (m_->TableEntryIsNonEmptyList(bucket_index_)) { - node_ = static_cast(m_->table_[bucket_index_]); - break; - } else if (m_->TableEntryIsTree(bucket_index_)) { - Tree* tree = static_cast(m_->table_[bucket_index_]); - GOOGLE_DCHECK(!tree->empty()); - tree_it_ = tree->begin(); - node_ = NodePtrFromKeyPtr(*tree_it_); - break; - } - } - } - - reference operator*() const { return node_->kv; } - pointer operator->() const { return &(operator*()); } - - friend bool operator==(const iterator_base& a, const iterator_base& b) { - return a.node_ == b.node_; - } - friend bool operator!=(const iterator_base& a, const iterator_base& b) { - return a.node_ != b.node_; - } - - iterator_base& operator++() { - if (node_->next == NULL) { - const bool is_list = revalidate_if_necessary(); - if (is_list) { - SearchFrom(bucket_index_ + 1); - } else { - GOOGLE_DCHECK_EQ(bucket_index_ & 1, 0); - Tree* tree = static_cast(m_->table_[bucket_index_]); - if (++tree_it_ == tree->end()) { - SearchFrom(bucket_index_ + 2); - } else { - node_ = NodePtrFromKeyPtr(*tree_it_); - } - } - } else { - node_ = node_->next; - } - return *this; - } - - iterator_base operator++(int /* unused */) { - iterator_base tmp = *this; - ++*this; - return tmp; - } - - // Assumes node_ and m_ are correct and non-NULL, but other fields may be - // stale. Fix them as needed. Then return true iff node_ points to a - // Node in a list. - bool revalidate_if_necessary() { - GOOGLE_DCHECK(node_ != NULL && m_ != NULL); - // Force bucket_index_ to be in range. - bucket_index_ &= (m_->num_buckets_ - 1); - // Common case: the bucket we think is relevant points to node_. - if (m_->table_[bucket_index_] == static_cast(node_)) - return true; - // Less common: the bucket is a linked list with node_ somewhere in it, - // but not at the head. - if (m_->TableEntryIsNonEmptyList(bucket_index_)) { - Node* l = static_cast(m_->table_[bucket_index_]); - while ((l = l->next) != NULL) { - if (l == node_) { - return true; - } - } - } - // Well, bucket_index_ still might be correct, but probably - // not. Revalidate just to be sure. This case is rare enough that we - // don't worry about potential optimizations, such as having a custom - // find-like method that compares Node* instead of const Key&. - iterator_base i(m_->find(*KeyPtrFromNodePtr(node_))); - bucket_index_ = i.bucket_index_; - tree_it_ = i.tree_it_; - return m_->TableEntryIsList(bucket_index_); - } - - Node* node_; - const InnerMap* m_; - size_type bucket_index_; - TreeIterator tree_it_; - }; - - public: - typedef iterator_base iterator; - typedef iterator_base const_iterator; - - iterator begin() { return iterator(this); } - iterator end() { return iterator(); } - const_iterator begin() const { return const_iterator(this); } - const_iterator end() const { return const_iterator(); } - - void clear() { - for (size_type b = 0; b < num_buckets_; b++) { - if (TableEntryIsNonEmptyList(b)) { - Node* node = static_cast(table_[b]); - table_[b] = NULL; - do { - Node* next = node->next; - DestroyNode(node); - node = next; - } while (node != NULL); - } else if (TableEntryIsTree(b)) { - Tree* tree = static_cast(table_[b]); - GOOGLE_DCHECK(table_[b] == table_[b + 1] && (b & 1) == 0); - table_[b] = table_[b + 1] = NULL; - typename Tree::iterator tree_it = tree->begin(); - do { - Node* node = NodePtrFromKeyPtr(*tree_it); - typename Tree::iterator next = tree_it; - ++next; - tree->erase(tree_it); - DestroyNode(node); - tree_it = next; - } while (tree_it != tree->end()); - DestroyTree(tree); - b++; - } - } - num_elements_ = 0; - index_of_first_non_null_ = num_buckets_; - } - - const hasher& hash_function() const { return *this; } - - static size_type max_size() { - return static_cast(1) << (sizeof(void**) >= 8 ? 60 : 28); - } - size_type size() const { return num_elements_; } - bool empty() const { return size() == 0; } - - iterator find(const Key& k) { return iterator(FindHelper(k).first); } - const_iterator find(const Key& k) const { return FindHelper(k).first; } - - // In traditional C++ style, this performs "insert if not present." - std::pair insert(const KeyValuePair& kv) { - std::pair p = FindHelper(kv.key()); - // Case 1: key was already present. - if (p.first.node_ != NULL) - return std::make_pair(iterator(p.first), false); - // Case 2: insert. - if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) { - p = FindHelper(kv.key()); - } - const size_type b = p.second; // bucket number - Node* node = Alloc(1); - alloc_.construct(&node->kv, kv); - iterator result = InsertUnique(b, node); - ++num_elements_; - return std::make_pair(result, true); - } - - // The same, but if an insertion is necessary then the value portion of the - // inserted key-value pair is left uninitialized. - std::pair insert(const Key& k) { - std::pair p = FindHelper(k); - // Case 1: key was already present. - if (p.first.node_ != NULL) - return std::make_pair(iterator(p.first), false); - // Case 2: insert. - if (ResizeIfLoadIsOutOfRange(num_elements_ + 1)) { - p = FindHelper(k); - } - const size_type b = p.second; // bucket number - Node* node = Alloc(1); - typedef typename Allocator::template rebind::other KeyAllocator; - KeyAllocator(alloc_).construct(&node->kv.key(), k); - iterator result = InsertUnique(b, node); - ++num_elements_; - return std::make_pair(result, true); - } - - Value& operator[](const Key& k) { - KeyValuePair kv(k, Value()); - return insert(kv).first->value(); - } - - void erase(iterator it) { - GOOGLE_DCHECK_EQ(it.m_, this); - const bool is_list = it.revalidate_if_necessary(); - size_type b = it.bucket_index_; - Node* const item = it.node_; - if (is_list) { - GOOGLE_DCHECK(TableEntryIsNonEmptyList(b)); - Node* head = static_cast(table_[b]); - head = EraseFromLinkedList(item, head); - table_[b] = static_cast(head); - } else { - GOOGLE_DCHECK(TableEntryIsTree(b)); - Tree* tree = static_cast(table_[b]); - tree->erase(it.tree_it_); - if (tree->empty()) { - // Force b to be the minimum of b and b ^ 1. This is important - // only because we want index_of_first_non_null_ to be correct. - b &= ~static_cast(1); - DestroyTree(tree); - table_[b] = table_[b + 1] = NULL; - } - } - DestroyNode(item); - --num_elements_; - if (GOOGLE_PREDICT_FALSE(b == index_of_first_non_null_)) { - while (index_of_first_non_null_ < num_buckets_ && - table_[index_of_first_non_null_] == NULL) { - ++index_of_first_non_null_; - } - } - } - - private: - std::pair FindHelper(const Key& k) const { - size_type b = BucketNumber(k); - if (TableEntryIsNonEmptyList(b)) { - Node* node = static_cast(table_[b]); - do { - if (IsMatch(*KeyPtrFromNodePtr(node), k)) { - return std::make_pair(const_iterator(node, this, b), b); - } else { - node = node->next; - } - } while (node != NULL); - } else if (TableEntryIsTree(b)) { - GOOGLE_DCHECK_EQ(table_[b], table_[b ^ 1]); - b &= ~static_cast(1); - Tree* tree = static_cast(table_[b]); - Key* key = const_cast(&k); - typename Tree::iterator tree_it = tree->find(key); - if (tree_it != tree->end()) { - return std::make_pair(const_iterator(tree_it, this, b), b); - } - } - return std::make_pair(end(), b); - } - - // Insert the given Node in bucket b. If that would make bucket b too big, - // and bucket b is not a tree, create a tree for buckets b and b^1 to share. - // Requires count(*KeyPtrFromNodePtr(node)) == 0 and that b is the correct - // bucket. num_elements_ is not modified. - iterator InsertUnique(size_type b, Node* node) { - GOOGLE_DCHECK(index_of_first_non_null_ == num_buckets_ || - table_[index_of_first_non_null_] != NULL); - // In practice, the code that led to this point may have already - // determined whether we are inserting into an empty list, a short list, - // or whatever. But it's probably cheap enough to recompute that here; - // it's likely that we're inserting into an empty or short list. - iterator result; - GOOGLE_DCHECK(find(*KeyPtrFromNodePtr(node)) == end()); - if (TableEntryIsEmpty(b)) { - result = InsertUniqueInList(b, node); - } else if (TableEntryIsNonEmptyList(b)) { - if (GOOGLE_PREDICT_FALSE(TableEntryIsTooLong(b))) { - TreeConvert(b); - result = InsertUniqueInTree(b, node); - GOOGLE_DCHECK_EQ(result.bucket_index_, b & ~static_cast(1)); - } else { - // Insert into a pre-existing list. This case cannot modify - // index_of_first_non_null_, so we skip the code to update it. - return InsertUniqueInList(b, node); - } - } else { - // Insert into a pre-existing tree. This case cannot modify - // index_of_first_non_null_, so we skip the code to update it. - return InsertUniqueInTree(b, node); - } - index_of_first_non_null_ = - std::min(index_of_first_non_null_, result.bucket_index_); - return result; - } - - // Helper for InsertUnique. Handles the case where bucket b is a - // not-too-long linked list. - iterator InsertUniqueInList(size_type b, Node* node) { - node->next = static_cast(table_[b]); - table_[b] = static_cast(node); - return iterator(node, this, b); - } - - // Helper for InsertUnique. Handles the case where bucket b points to a - // Tree. - iterator InsertUniqueInTree(size_type b, Node* node) { - GOOGLE_DCHECK_EQ(table_[b], table_[b ^ 1]); - // Maintain the invariant that node->next is NULL for all Nodes in Trees. - node->next = NULL; - return iterator(static_cast(table_[b]) - ->insert(KeyPtrFromNodePtr(node)) - .first, - this, b & ~static_cast(1)); - } - - // Returns whether it did resize. Currently this is only used when - // num_elements_ increases, though it could be used in other situations. - // It checks for load too low as well as load too high: because any number - // of erases can occur between inserts, the load could be as low as 0 here. - // Resizing to a lower size is not always helpful, but failing to do so can - // destroy the expected big-O bounds for some operations. By having the - // policy that sometimes we resize down as well as up, clients can easily - // keep O(size()) = O(number of buckets) if they want that. - bool ResizeIfLoadIsOutOfRange(size_type new_size) { - const size_type kMaxMapLoadTimes16 = 12; // controls RAM vs CPU tradeoff - const size_type hi_cutoff = num_buckets_ * kMaxMapLoadTimes16 / 16; - const size_type lo_cutoff = hi_cutoff / 4; - // We don't care how many elements are in trees. If a lot are, - // we may resize even though there are many empty buckets. In - // practice, this seems fine. - if (GOOGLE_PREDICT_FALSE(new_size >= hi_cutoff)) { - if (num_buckets_ <= max_size() / 2) { - Resize(num_buckets_ * 2); - return true; - } - } else if (GOOGLE_PREDICT_FALSE(new_size <= lo_cutoff && - num_buckets_ > kMinTableSize)) { - size_type lg2_of_size_reduction_factor = 1; - // It's possible we want to shrink a lot here... size() could even be 0. - // So, estimate how much to shrink by making sure we don't shrink so - // much that we would need to grow the table after a few inserts. - const size_type hypothetical_size = new_size * 5 / 4 + 1; - while ((hypothetical_size << lg2_of_size_reduction_factor) < - hi_cutoff) { - ++lg2_of_size_reduction_factor; - } - size_type new_num_buckets = std::max( - kMinTableSize, num_buckets_ >> lg2_of_size_reduction_factor); - if (new_num_buckets != num_buckets_) { - Resize(new_num_buckets); - return true; - } - } - return false; - } - - // Resize to the given number of buckets. - void Resize(size_t new_num_buckets) { - GOOGLE_DCHECK_GE(new_num_buckets, kMinTableSize); - void** const old_table = table_; - const size_type old_table_size = num_buckets_; - num_buckets_ = new_num_buckets; - table_ = CreateEmptyTable(num_buckets_); - const size_type start = index_of_first_non_null_; - index_of_first_non_null_ = num_buckets_; - for (size_type i = start; i < old_table_size; i++) { - if (TableEntryIsNonEmptyList(old_table, i)) { - TransferList(old_table, i); - } else if (TableEntryIsTree(old_table, i)) { - TransferTree(old_table, i++); - } - } - Dealloc(old_table, old_table_size); - } - - void TransferList(void* const* table, size_type index) { - Node* node = static_cast(table[index]); - do { - Node* next = node->next; - InsertUnique(BucketNumber(*KeyPtrFromNodePtr(node)), node); - node = next; - } while (node != NULL); - } - - void TransferTree(void* const* table, size_type index) { - Tree* tree = static_cast(table[index]); - typename Tree::iterator tree_it = tree->begin(); - do { - Node* node = NodePtrFromKeyPtr(*tree_it); - InsertUnique(BucketNumber(**tree_it), node); - } while (++tree_it != tree->end()); - DestroyTree(tree); - } - - Node* EraseFromLinkedList(Node* item, Node* head) { - if (head == item) { - return head->next; - } else { - head->next = EraseFromLinkedList(item, head->next); - return head; - } - } - - bool TableEntryIsEmpty(size_type b) const { - return TableEntryIsEmpty(table_, b); - } - bool TableEntryIsNonEmptyList(size_type b) const { - return TableEntryIsNonEmptyList(table_, b); - } - bool TableEntryIsTree(size_type b) const { - return TableEntryIsTree(table_, b); - } - bool TableEntryIsList(size_type b) const { - return TableEntryIsList(table_, b); - } - static bool TableEntryIsEmpty(void* const* table, size_type b) { - return table[b] == NULL; - } - static bool TableEntryIsNonEmptyList(void* const* table, size_type b) { - return table[b] != NULL && table[b] != table[b ^ 1]; - } - static bool TableEntryIsTree(void* const* table, size_type b) { - return !TableEntryIsEmpty(table, b) && - !TableEntryIsNonEmptyList(table, b); - } - static bool TableEntryIsList(void* const* table, size_type b) { - return !TableEntryIsTree(table, b); - } - - void TreeConvert(size_type b) { - GOOGLE_DCHECK(!TableEntryIsTree(b) && !TableEntryIsTree(b ^ 1)); - typename Allocator::template rebind::other tree_allocator(alloc_); - Tree* tree = tree_allocator.allocate(1); - // We want to use the three-arg form of construct, if it exists, but we - // create a temporary and use the two-arg construct that's known to exist. - // It's clunky, but the compiler should be able to generate more-or-less - // the same code. - tree_allocator.construct(tree, - Tree(KeyCompare(), KeyPtrAllocator(alloc_))); - // Now the tree is ready to use. - size_type count = CopyListToTree(b, tree) + CopyListToTree(b ^ 1, tree); - GOOGLE_DCHECK_EQ(count, tree->size()); - table_[b] = table_[b ^ 1] = static_cast(tree); - } - - // Copy a linked list in the given bucket to a tree. - // Returns the number of things it copied. - size_type CopyListToTree(size_type b, Tree* tree) { - size_type count = 0; - Node* node = static_cast(table_[b]); - while (node != NULL) { - tree->insert(KeyPtrFromNodePtr(node)); - ++count; - Node* next = node->next; - node->next = NULL; - node = next; - } - return count; - } - - // Return whether table_[b] is a linked list that seems awfully long. - // Requires table_[b] to point to a non-empty linked list. - bool TableEntryIsTooLong(size_type b) { - const size_type kMaxLength = 8; - size_type count = 0; - Node* node = static_cast(table_[b]); - do { - ++count; - node = node->next; - } while (node != NULL); - // Invariant: no linked list ever is more than kMaxLength in length. - GOOGLE_DCHECK_LE(count, kMaxLength); - return count >= kMaxLength; - } - - size_type BucketNumber(const Key& k) const { - // We inherit from hasher, so one-arg operator() provides a hash function. - size_type h = (*const_cast(this))(k); - // To help prevent people from making assumptions about the hash function, - // we use the seed differently depending on NDEBUG. The default hash - // function, the seeding, etc., are all likely to change in the future. -#ifndef NDEBUG - return (h * (seed_ | 1)) & (num_buckets_ - 1); -#else - return (h + seed_) & (num_buckets_ - 1); -#endif - } - - bool IsMatch(const Key& k0, const Key& k1) const { - return std::equal_to()(k0, k1); - } - - // Return a power of two no less than max(kMinTableSize, n). - // Assumes either n < kMinTableSize or n is a power of two. - size_type TableSize(size_type n) { - return n < kMinTableSize ? kMinTableSize : n; - } - - // Use alloc_ to allocate an array of n objects of type U. - template - U* Alloc(size_type n) { - typedef typename Allocator::template rebind::other alloc_type; - return alloc_type(alloc_).allocate(n); - } - - // Use alloc_ to deallocate an array of n objects of type U. - template - void Dealloc(U* t, size_type n) { - typedef typename Allocator::template rebind::other alloc_type; - alloc_type(alloc_).deallocate(t, n); - } - - void DestroyNode(Node* node) { - alloc_.destroy(&node->kv); - Dealloc(node, 1); - } - - void DestroyTree(Tree* tree) { - typename Allocator::template rebind::other tree_allocator(alloc_); - tree_allocator.destroy(tree); - tree_allocator.deallocate(tree, 1); - } - - void** CreateEmptyTable(size_type n) { - GOOGLE_DCHECK(n >= kMinTableSize); - GOOGLE_DCHECK_EQ(n & (n - 1), 0); - void** result = Alloc(n); - memset(result, 0, n * sizeof(result[0])); - return result; - } - - // Return a randomish value. - size_type Seed() const { - // random_device can throw, so avoid it unless we are compiling with - // exceptions enabled. -#if __cpp_exceptions && LANG_CXX11 - try { - std::random_device rd; - std::knuth_b knuth(rd()); - std::uniform_int_distribution u; - return u(knuth); - } catch (...) { } -#endif - size_type s = static_cast(reinterpret_cast(this)); -#if defined(__x86_64__) && defined(__GNUC__) - uint32 hi, lo; - asm("rdtsc" : "=a" (lo), "=d" (hi)); - s += ((static_cast(hi) << 32) | lo); -#endif - return s; - } - - size_type num_elements_; - size_type num_buckets_; - size_type seed_; - size_type index_of_first_non_null_; - void** table_; // an array with num_buckets_ entries - Allocator alloc_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(InnerMap); - }; // end of class InnerMap - - typedef hash_map, std::equal_to, - MapAllocator*> > > - DeprecatedInnerMap; - - public: - // Iterators - class iterator_base { - public: - // We support "old style" and "new style" iterators for now. This is - // temporary. Also, for "iterator()" we have an unknown category. - // TODO(gpike): get rid of this. - enum IteratorStyle { kUnknown, kOld, kNew }; - explicit iterator_base(IteratorStyle style) : iterator_style_(style) {} - - bool OldStyle() const { - GOOGLE_DCHECK_NE(iterator_style_, kUnknown); - return iterator_style_ == kOld; - } - bool UnknownStyle() const { - return iterator_style_ == kUnknown; - } - bool SameStyle(const iterator_base& other) const { - return iterator_style_ == other.iterator_style_; - } - - private: - IteratorStyle iterator_style_; - }; - - class const_iterator - : private iterator_base, - public std::iterator { - typedef typename InnerMap::const_iterator InnerIt; - typedef typename DeprecatedInnerMap::const_iterator DeprecatedInnerIt; - - public: - const_iterator() : iterator_base(iterator_base::kUnknown) {} - explicit const_iterator(const DeprecatedInnerIt& dit) - : iterator_base(iterator_base::kOld), dit_(dit) {} - explicit const_iterator(const InnerIt& it) - : iterator_base(iterator_base::kNew), it_(it) {} - - const_iterator(const const_iterator& other) - : iterator_base(other), it_(other.it_), dit_(other.dit_) {} - - const_reference operator*() const { - return this->OldStyle() ? *dit_->second : *it_->value(); - } - const_pointer operator->() const { return &(operator*()); } - - const_iterator& operator++() { - if (this->OldStyle()) - ++dit_; - else - ++it_; - return *this; - } - const_iterator operator++(int) { - return this->OldStyle() ? const_iterator(dit_++) : const_iterator(it_++); - } - - friend bool operator==(const const_iterator& a, const const_iterator& b) { - if (!a.SameStyle(b)) return false; - if (a.UnknownStyle()) return true; - return a.OldStyle() ? (a.dit_ == b.dit_) : (a.it_ == b.it_); - } - friend bool operator!=(const const_iterator& a, const const_iterator& b) { - return !(a == b); - } - - private: - InnerIt it_; - DeprecatedInnerIt dit_; - }; - - class iterator : private iterator_base, - public std::iterator { - typedef typename InnerMap::iterator InnerIt; - typedef typename DeprecatedInnerMap::iterator DeprecatedInnerIt; - - public: - iterator() : iterator_base(iterator_base::kUnknown) {} - explicit iterator(const DeprecatedInnerIt& dit) - : iterator_base(iterator_base::kOld), dit_(dit) {} - explicit iterator(const InnerIt& it) - : iterator_base(iterator_base::kNew), it_(it) {} - - reference operator*() const { - return this->OldStyle() ? *dit_->second : *it_->value(); - } - pointer operator->() const { return &(operator*()); } - - iterator& operator++() { - if (this->OldStyle()) - ++dit_; - else - ++it_; - return *this; - } - iterator operator++(int) { - return this->OldStyle() ? iterator(dit_++) : iterator(it_++); - } - - // Allow implicit conversion to const_iterator. - operator const_iterator() const { - return this->OldStyle() ? - const_iterator(typename DeprecatedInnerMap::const_iterator(dit_)) : - const_iterator(typename InnerMap::const_iterator(it_)); - } - - friend bool operator==(const iterator& a, const iterator& b) { - if (!a.SameStyle(b)) return false; - if (a.UnknownStyle()) return true; - return a.OldStyle() ? a.dit_ == b.dit_ : a.it_ == b.it_; - } - friend bool operator!=(const iterator& a, const iterator& b) { - return !(a == b); - } - - private: - friend class Map; - - InnerIt it_; - DeprecatedInnerIt dit_; - }; - - iterator begin() { - return old_style_ ? iterator(deprecated_elements_->begin()) - : iterator(elements_->begin()); - } - iterator end() { - return old_style_ ? iterator(deprecated_elements_->end()) - : iterator(elements_->end()); - } - const_iterator begin() const { - return old_style_ ? const_iterator(deprecated_elements_->begin()) - : const_iterator(iterator(elements_->begin())); - } - const_iterator end() const { - return old_style_ ? const_iterator(deprecated_elements_->end()) - : const_iterator(iterator(elements_->end())); - } - const_iterator cbegin() const { return begin(); } - const_iterator cend() const { return end(); } - - // Capacity - size_type size() const { - return old_style_ ? deprecated_elements_->size() : elements_->size(); - } - bool empty() const { return size() == 0; } - - // Element access - T& operator[](const key_type& key) { - value_type** value = - old_style_ ? &(*deprecated_elements_)[key] : &(*elements_)[key]; - if (*value == NULL) { - *value = CreateValueTypeInternal(key); - internal::MapValueInitializer::value, - T>::Initialize((*value)->second, - default_enum_value_); - } - return (*value)->second; - } - const T& at(const key_type& key) const { - const_iterator it = find(key); - GOOGLE_CHECK(it != end()); - return it->second; - } - T& at(const key_type& key) { - iterator it = find(key); - GOOGLE_CHECK(it != end()); - return it->second; - } - - // Lookup - size_type count(const key_type& key) const { - if (find(key) != end()) assert(key == find(key)->first); - return find(key) == end() ? 0 : 1; - } - const_iterator find(const key_type& key) const { - return old_style_ ? const_iterator(deprecated_elements_->find(key)) - : const_iterator(iterator(elements_->find(key))); - } - iterator find(const key_type& key) { - return old_style_ ? iterator(deprecated_elements_->find(key)) - : iterator(elements_->find(key)); - } - std::pair equal_range( - const key_type& key) const { - const_iterator it = find(key); - if (it == end()) { - return std::pair(it, it); - } else { - const_iterator begin = it++; - return std::pair(begin, it); - } - } - std::pair equal_range(const key_type& key) { - iterator it = find(key); - if (it == end()) { - return std::pair(it, it); - } else { - iterator begin = it++; - return std::pair(begin, it); - } - } - - // insert - std::pair insert(const value_type& value) { - if (old_style_) { - iterator it = find(value.first); - if (it != end()) { - return std::pair(it, false); - } else { - return std::pair( - iterator(deprecated_elements_->insert(std::pair( - value.first, CreateValueTypeInternal(value))).first), true); - } - } else { - std::pair p = - elements_->insert(value.first); - if (p.second) { - p.first->value() = CreateValueTypeInternal(value); - } - return std::pair(iterator(p.first), p.second); - } - } - template - void insert(InputIt first, InputIt last) { - for (InputIt it = first; it != last; ++it) { - iterator exist_it = find(it->first); - if (exist_it == end()) { - operator[](it->first) = it->second; - } - } - } - - // Erase and clear - size_type erase(const key_type& key) { - iterator it = find(key); - if (it == end()) { - return 0; - } else { - erase(it); - return 1; - } - } - iterator erase(iterator pos) { - if (arena_ == NULL) delete pos.operator->(); - iterator i = pos++; - if (old_style_) - deprecated_elements_->erase(i.dit_); - else - elements_->erase(i.it_); - return pos; - } - void erase(iterator first, iterator last) { - while (first != last) { - first = erase(first); - } - } - void clear() { erase(begin(), end()); } - - // Assign - Map& operator=(const Map& other) { - if (this != &other) { - clear(); - insert(other.begin(), other.end()); - } - return *this; - } - - void swap(Map& other) { - if (arena_ == other.arena_ && old_style_ == other.old_style_) { - std::swap(default_enum_value_, other.default_enum_value_); - if (old_style_) { - std::swap(deprecated_elements_, other.deprecated_elements_); - } else { - std::swap(elements_, other.elements_); - } - } else { - // TODO(zuguang): optimize this. The temporary copy can be allocated - // in the same arena as the other message, and the "other = copy" can - // be replaced with the fast-path swap above. - Map copy = *this; - *this = other; - other = copy; - } - } - - // Access to hasher. Currently this returns a copy, but it may - // be modified to return a const reference in the future. - hasher hash_function() const { - return old_style_ ? deprecated_elements_->hash_function() - : elements_->hash_function(); - } - - private: - // Set default enum value only for proto2 map field whose value is enum type. - void SetDefaultEnumValue(int default_enum_value) { - default_enum_value_ = default_enum_value; - } - - value_type* CreateValueTypeInternal(const Key& key) { - if (arena_ == NULL) { - return new value_type(key); - } else { - value_type* value = reinterpret_cast( - Arena::CreateArray(arena_, sizeof(value_type))); - Arena::CreateInArenaStorage(const_cast(&value->first), arena_); - Arena::CreateInArenaStorage(&value->second, arena_); - const_cast(value->first) = key; - return value; - } - } - - value_type* CreateValueTypeInternal(const value_type& value) { - if (arena_ == NULL) { - return new value_type(value); - } else { - value_type* p = reinterpret_cast( - Arena::CreateArray(arena_, sizeof(value_type))); - Arena::CreateInArenaStorage(const_cast(&p->first), arena_); - Arena::CreateInArenaStorage(&p->second, arena_); - const_cast(p->first) = value.first; - p->second = value.second; - return p; - } - } - - Arena* arena_; - int default_enum_value_; - // The following is a tagged union because we support two map styles - // for now. - // TODO(gpike): get rid of the old style. - const bool old_style_; - union { - InnerMap* elements_; - DeprecatedInnerMap* deprecated_elements_; - }; - - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - template - friend class internal::MapFieldLite; -}; - -} // namespace protobuf -} // namespace google - -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START -template<> -struct hash { - size_t - operator()(const google::protobuf::MapKey& map_key) const { - switch (map_key.type()) { - case google::protobuf::FieldDescriptor::CPPTYPE_DOUBLE: - case google::protobuf::FieldDescriptor::CPPTYPE_FLOAT: - case google::protobuf::FieldDescriptor::CPPTYPE_ENUM: - case google::protobuf::FieldDescriptor::CPPTYPE_MESSAGE: - GOOGLE_LOG(FATAL) << "Unsupported"; - break; - case google::protobuf::FieldDescriptor::CPPTYPE_STRING: - return hash()(map_key.GetStringValue()); - case google::protobuf::FieldDescriptor::CPPTYPE_INT64: - return hash< ::google::protobuf::int64>()(map_key.GetInt64Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_INT32: - return hash< ::google::protobuf::int32>()(map_key.GetInt32Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: - return hash< ::google::protobuf::uint64>()(map_key.GetUInt64Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: - return hash< ::google::protobuf::uint32>()(map_key.GetUInt32Value()); - case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: - return hash()(map_key.GetBoolValue()); - } - GOOGLE_LOG(FATAL) << "Can't get here."; - return 0; - } - bool - operator()(const google::protobuf::MapKey& map_key1, - const google::protobuf::MapKey& map_key2) const { - return map_key1 < map_key2; - } -}; -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END - -#endif // GOOGLE_PROTOBUF_MAP_H__ diff --git a/app/src/main/cpp/google/protobuf/map_entry.h b/app/src/main/cpp/google/protobuf/map_entry.h deleted file mode 100644 index abcd452..0000000 --- a/app/src/main/cpp/google/protobuf/map_entry.h +++ /dev/null @@ -1,310 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MAP_ENTRY_H__ -#define GOOGLE_PROTOBUF_MAP_ENTRY_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace google { -namespace protobuf { -class Arena; -namespace internal { -template -class MapField; -} -} - -namespace protobuf { -namespace internal { - -// Register all MapEntry default instances so we can delete them in -// ShutdownProtobufLibrary(). -void LIBPROTOBUF_EXPORT RegisterMapEntryDefaultInstance( - MessageLite* default_instance); - -// This is the common base class for MapEntry. It is used by MapFieldBase in -// reflection api, in which the static type of key and value is unknown. -class LIBPROTOBUF_EXPORT MapEntryBase : public Message { - public: - ::google::protobuf::Metadata GetMetadata() const { - ::google::protobuf::Metadata metadata; - metadata.descriptor = descriptor_; - metadata.reflection = reflection_; - return metadata; - } - - protected: - MapEntryBase() : descriptor_(NULL), reflection_(NULL) { } - virtual ~MapEntryBase() {} - - const Descriptor* descriptor_; - const Reflection* reflection_; -}; - -// MapEntry is the returned google::protobuf::Message when calling AddMessage of -// google::protobuf::Reflection. In order to let it work with generated message -// reflection, its in-memory type is the same as generated message with the same -// fields. However, in order to decide the in-memory type of key/value, we need -// to know both their cpp type in generated api and proto type. In -// implementation, all in-memory types have related wire format functions to -// support except ArenaStringPtr. Therefore, we need to define another type with -// supporting wire format functions. Since this type is only used as return type -// of MapEntry accessors, it's named MapEntry accessor type. -// -// cpp type: the type visible to users in public API. -// proto type: WireFormatLite::FieldType of the field. -// in-memory type: type of the data member used to stored this field. -// MapEntry accessor type: type used in MapEntry getters/mutators to access the -// field. -// -// cpp type | proto type | in-memory type | MapEntry accessor type -// int32 TYPE_INT32 int32 int32 -// int32 TYPE_FIXED32 int32 int32 -// string TYPE_STRING ArenaStringPtr string -// FooEnum TYPE_ENUM int int -// FooMessage TYPE_MESSAGE FooMessage* FooMessage -// -// The in-memory types of primitive types can be inferred from its proto type, -// while we need to explicitly specify the cpp type if proto type is -// TYPE_MESSAGE to infer the in-memory type. Moreover, default_enum_value is -// used to initialize enum field in proto2. -template -class MapEntry : public MapEntryBase { - // Provide utilities to parse/serialize key/value. Provide utilities to - // manipulate internal stored type. - typedef MapTypeHandler KeyTypeHandler; - typedef MapTypeHandler ValueTypeHandler; - - // Enum type cannot be used for MapTypeHandler::Read. Define a type - // which will replace Enum with int. - typedef typename KeyTypeHandler::MapEntryAccessorType KeyMapEntryAccessorType; - typedef typename ValueTypeHandler::MapEntryAccessorType - ValueMapEntryAccessorType; - - // Abbreviation for MapEntry - typedef typename google::protobuf::internal::MapEntry< - Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> EntryType; - - // Abbreviation for MapEntryLite - typedef typename google::protobuf::internal::MapEntryLite< - Key, Value, kKeyFieldType, kValueFieldType, default_enum_value> - EntryLiteType; - - public: - ~MapEntry() { - if (this == default_instance_) { - delete reflection_; - } - } - - // accessors ====================================================== - - virtual inline const KeyMapEntryAccessorType& key() const { - return entry_lite_.key(); - } - inline KeyMapEntryAccessorType* mutable_key() { - return entry_lite_.mutable_key(); - } - virtual inline const ValueMapEntryAccessorType& value() const { - return entry_lite_.value(); - } - inline ValueMapEntryAccessorType* mutable_value() { - return entry_lite_.mutable_value(); - } - - // implements Message ============================================= - - bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { - return entry_lite_.MergePartialFromCodedStream(input); - } - - size_t ByteSizeLong() const { - return entry_lite_.ByteSizeLong(); - } - - void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const { - entry_lite_.SerializeWithCachedSizes(output); - } - - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - ::google::protobuf::uint8* output) const { - return entry_lite_.InternalSerializeWithCachedSizesToArray(deterministic, - output); - } - - int GetCachedSize() const { - return entry_lite_.GetCachedSize(); - } - - bool IsInitialized() const { - return entry_lite_.IsInitialized(); - } - - Message* New() const { - MapEntry* entry = new MapEntry; - entry->descriptor_ = descriptor_; - entry->reflection_ = reflection_; - entry->set_default_instance(default_instance_); - return entry; - } - - Message* New(Arena* arena) const { - MapEntry* entry = Arena::CreateMessage(arena); - entry->descriptor_ = descriptor_; - entry->reflection_ = reflection_; - entry->set_default_instance(default_instance_); - return entry; - } - - int SpaceUsed() const { - int size = sizeof(MapEntry); - size += entry_lite_.SpaceUsed(); - return size; - } - - void CopyFrom(const ::google::protobuf::Message& from) { - Clear(); - MergeFrom(from); - } - - void MergeFrom(const ::google::protobuf::Message& from) { - GOOGLE_CHECK_NE(&from, this); - const MapEntry* source = dynamic_cast_if_available(&from); - if (source == NULL) { - ReflectionOps::Merge(from, this); - } else { - MergeFrom(*source); - } - } - - void CopyFrom(const MapEntry& from) { - Clear(); - MergeFrom(from); - } - - void MergeFrom(const MapEntry& from) { - entry_lite_.MergeFrom(from.entry_lite_); - } - - void Clear() { - entry_lite_.Clear(); - } - - void InitAsDefaultInstance() { - entry_lite_.InitAsDefaultInstance(); - } - - Arena* GetArena() const { - return entry_lite_.GetArena(); - } - - // Create default MapEntry instance for given descriptor. Descriptor has to be - // given when creating default MapEntry instance because different map field - // may have the same type and MapEntry class. The given descriptor is needed - // to distinguish instances of the same MapEntry class. - static MapEntry* CreateDefaultInstance(const Descriptor* descriptor) { - MapEntry* entry = new MapEntry; - const Reflection* reflection = new GeneratedMessageReflection( - descriptor, entry, offsets_, - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_._has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _unknown_fields_), -1, - DescriptorPool::generated_pool(), - ::google::protobuf::MessageFactory::generated_factory(), - sizeof(MapEntry), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_)); - entry->descriptor_ = descriptor; - entry->reflection_ = reflection; - entry->set_default_instance(entry); - entry->InitAsDefaultInstance(); - RegisterMapEntryDefaultInstance(entry); - return entry; - } - - private: - MapEntry() - : _internal_metadata_(NULL), default_instance_(NULL), entry_lite_() {} - - explicit MapEntry(Arena* arena) - : _internal_metadata_(arena), - default_instance_(NULL), - entry_lite_(arena) {} - - inline Arena* GetArenaNoVirtual() const { - return entry_lite_.GetArenaNoVirtual(); - } - - void set_default_instance(MapEntry* default_instance) { - default_instance_ = default_instance; - entry_lite_.set_default_instance(&default_instance->entry_lite_); - } - - static int offsets_[2]; - UnknownFieldSet _unknown_fields_; - InternalMetadataWithArena _internal_metadata_; - MapEntry* default_instance_; - EntryLiteType entry_lite_; - - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - template - friend class internal::MapField; - friend class internal::GeneratedMessageReflection; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntry); -}; - -template -int MapEntry::offsets_[2] = { - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.key_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, entry_lite_.value_), -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MAP_ENTRY_H__ diff --git a/app/src/main/cpp/google/protobuf/map_entry_lite.h b/app/src/main/cpp/google/protobuf/map_entry_lite.h deleted file mode 100644 index 3fb5822..0000000 --- a/app/src/main/cpp/google/protobuf/map_entry_lite.h +++ /dev/null @@ -1,568 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ -#define GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -class Arena; -namespace internal { -template -class MapEntry; -template -class MapFieldLite; -} // namespace internal -} // namespace protobuf - -namespace protobuf { -namespace internal { - -// MoveHelper::Move is used to set *dest. It copies *src, or moves it (in -// the C++11 sense), or swaps it. *src is left in a sane state for -// subsequent destruction, but shouldn't be used for anything. -template -struct MoveHelper { // primitives - static void Move(T* src, T* dest) { *dest = *src; } -}; - -template -struct MoveHelper { // enums - static void Move(T* src, T* dest) { *dest = *src; } - // T is an enum here, so allow conversions to and from int. - static void Move(T* src, int* dest) { *dest = static_cast(*src); } - static void Move(int* src, T* dest) { *dest = static_cast(*src); } -}; - -template -struct MoveHelper { // messages - static void Move(T* src, T* dest) { dest->Swap(src); } -}; - -template -struct MoveHelper { // strings and similar - static void Move(T* src, T* dest) { -#if __cplusplus >= 201103L - *dest = std::move(*src); -#else - dest->swap(*src); -#endif - } -}; - -// MapEntryLite is used to implement parsing and serialization of map for lite -// runtime. -template -class MapEntryLite : public MessageLite { - // Provide utilities to parse/serialize key/value. Provide utilities to - // manipulate internal stored type. - typedef MapTypeHandler KeyTypeHandler; - typedef MapTypeHandler ValueTypeHandler; - - // Define internal memory layout. Strings and messages are stored as - // pointers, while other types are stored as values. - typedef typename KeyTypeHandler::TypeOnMemory KeyOnMemory; - typedef typename ValueTypeHandler::TypeOnMemory ValueOnMemory; - - // Enum type cannot be used for MapTypeHandler::Read. Define a type - // which will replace Enum with int. - typedef typename KeyTypeHandler::MapEntryAccessorType KeyMapEntryAccessorType; - typedef typename ValueTypeHandler::MapEntryAccessorType - ValueMapEntryAccessorType; - - // Constants for field number. - static const int kKeyFieldNumber = 1; - static const int kValueFieldNumber = 2; - - // Constants for field tag. - static const uint8 kKeyTag = GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG( - kKeyFieldNumber, KeyTypeHandler::kWireType); - static const uint8 kValueTag = GOOGLE_PROTOBUF_WIRE_FORMAT_MAKE_TAG( - kValueFieldNumber, ValueTypeHandler::kWireType); - static const size_t kTagSize = 1; - - public: - ~MapEntryLite() { - if (this != default_instance_) { - if (GetArenaNoVirtual() != NULL) return; - KeyTypeHandler::DeleteNoArena(key_); - ValueTypeHandler::DeleteNoArena(value_); - } - } - - // accessors ====================================================== - - virtual inline const KeyMapEntryAccessorType& key() const { - return KeyTypeHandler::GetExternalReference(key_); - } - virtual inline const ValueMapEntryAccessorType& value() const { - GOOGLE_CHECK(default_instance_ != NULL); - return ValueTypeHandler::DefaultIfNotInitialized(value_, - default_instance_->value_); - } - inline KeyMapEntryAccessorType* mutable_key() { - set_has_key(); - return KeyTypeHandler::EnsureMutable(&key_, GetArenaNoVirtual()); - } - inline ValueMapEntryAccessorType* mutable_value() { - set_has_value(); - return ValueTypeHandler::EnsureMutable(&value_, GetArenaNoVirtual()); - } - - // implements MessageLite ========================================= - - // MapEntryLite is for implementation only and this function isn't called - // anywhere. Just provide a fake implementation here for MessageLite. - string GetTypeName() const { return ""; } - - void CheckTypeAndMergeFrom(const MessageLite& other) { - MergeFrom(*::google::protobuf::down_cast(&other)); - } - - bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { - uint32 tag; - - for (;;) { - // 1) corrupted data: return false; - // 2) unknown field: skip without putting into unknown field set; - // 3) unknown enum value: keep it in parsing. In proto2, caller should - // check the value and put this entry into containing message's unknown - // field set if the value is an unknown enum. In proto3, caller doesn't - // need to care whether the value is unknown enum; - // 4) missing key/value: missed key/value will have default value. caller - // should take this entry as if key/value is set to default value. - tag = input->ReadTag(); - switch (tag) { - case kKeyTag: - if (!KeyTypeHandler::Read(input, mutable_key())) { - return false; - } - set_has_key(); - if (!input->ExpectTag(kValueTag)) break; - GOOGLE_FALLTHROUGH_INTENDED; - - case kValueTag: - if (!ValueTypeHandler::Read(input, mutable_value())) { - return false; - } - set_has_value(); - if (input->ExpectAtEnd()) return true; - break; - - default: - if (tag == 0 || - WireFormatLite::GetTagWireType(tag) == - WireFormatLite::WIRETYPE_END_GROUP) { - return true; - } - if (!WireFormatLite::SkipField(input, tag)) return false; - break; - } - } - } - - size_t ByteSizeLong() const { - size_t size = 0; - size += has_key() ? kTagSize + KeyTypeHandler::ByteSize(key()) : 0; - size += has_value() ? kTagSize + ValueTypeHandler::ByteSize(value()) : 0; - return size; - } - - void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream* output) const { - KeyTypeHandler::Write(kKeyFieldNumber, key(), output); - ValueTypeHandler::Write(kValueFieldNumber, value(), output); - } - - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - ::google::protobuf::uint8* output) const { - output = KeyTypeHandler::InternalWriteToArray(kKeyFieldNumber, key(), - deterministic, output); - output = ValueTypeHandler::InternalWriteToArray(kValueFieldNumber, value(), - deterministic, output); - return output; - } - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - - int GetCachedSize() const { - int size = 0; - size += has_key() - ? kTagSize + KeyTypeHandler::GetCachedSize(key()) - : 0; - size += has_value() - ? kTagSize + ValueTypeHandler::GetCachedSize( - value()) - : 0; - return size; - } - - bool IsInitialized() const { return ValueTypeHandler::IsInitialized(value_); } - - MessageLite* New() const { - MapEntryLite* entry = new MapEntryLite; - entry->default_instance_ = default_instance_; - return entry; - } - - MessageLite* New(Arena* arena) const { - MapEntryLite* entry = Arena::CreateMessage(arena); - entry->default_instance_ = default_instance_; - return entry; - } - - int SpaceUsed() const { - int size = sizeof(MapEntryLite); - size += KeyTypeHandler::SpaceUsedInMapEntry(key_); - size += ValueTypeHandler::SpaceUsedInMapEntry(value_); - return size; - } - - void MergeFrom(const MapEntryLite& from) { - if (from._has_bits_[0]) { - if (from.has_key()) { - KeyTypeHandler::EnsureMutable(&key_, GetArenaNoVirtual()); - KeyTypeHandler::Merge(from.key(), &key_, GetArenaNoVirtual()); - set_has_key(); - } - if (from.has_value()) { - ValueTypeHandler::EnsureMutable(&value_, GetArenaNoVirtual()); - ValueTypeHandler::Merge(from.value(), &value_, GetArenaNoVirtual()); - set_has_value(); - } - } - } - - void Clear() { - KeyTypeHandler::Clear(&key_, GetArenaNoVirtual()); - ValueTypeHandler::ClearMaybeByDefaultEnum( - &value_, GetArenaNoVirtual(), default_enum_value); - clear_has_key(); - clear_has_value(); - } - - void InitAsDefaultInstance() { - KeyTypeHandler::AssignDefaultValue(&key_); - ValueTypeHandler::AssignDefaultValue(&value_); - } - - Arena* GetArena() const { - return GetArenaNoVirtual(); - } - - // Create a MapEntryLite for given key and value from google::protobuf::Map in - // serialization. This function is only called when value is enum. Enum is - // treated differently because its type in MapEntry is int and its type in - // google::protobuf::Map is enum. We cannot create a reference to int from an enum. - static MapEntryLite* EnumWrap(const Key& key, const Value value, - Arena* arena) { - return Arena::CreateMessage >( - arena, key, value); - } - - // Like above, but for all the other types. This avoids value copy to create - // MapEntryLite from google::protobuf::Map in serialization. - static MapEntryLite* Wrap(const Key& key, const Value& value, Arena* arena) { - return Arena::CreateMessage >( - arena, key, value); - } - - // Parsing using MergePartialFromCodedStream, above, is not as - // efficient as it could be. This helper class provides a speedier way. - template - class Parser { - public: - explicit Parser(MapField* mf) : mf_(mf), map_(mf->MutableMap()) {} - - // This does what the typical MergePartialFromCodedStream() is expected to - // do, with the additional side-effect that if successful (i.e., if true is - // going to be its return value) it inserts the key-value pair into map_. - bool MergePartialFromCodedStream(::google::protobuf::io::CodedInputStream* input) { - // Look for the expected thing: a key and then a value. If it fails, - // invoke the enclosing class's MergePartialFromCodedStream, or return - // false if that would be pointless. - if (input->ExpectTag(kKeyTag)) { - if (!KeyTypeHandler::Read(input, &key_)) { - return false; - } - // Peek at the next byte to see if it is kValueTag. If not, bail out. - const void* data; - int size; - input->GetDirectBufferPointerInline(&data, &size); - // We could use memcmp here, but we don't bother. The tag is one byte. - assert(kTagSize == 1); - if (size > 0 && *reinterpret_cast(data) == kValueTag) { - typename Map::size_type size = map_->size(); - value_ptr_ = &(*map_)[key_]; - if (GOOGLE_PREDICT_TRUE(size != map_->size())) { - // We created a new key-value pair. Fill in the value. - typedef - typename MapIf::type T; - input->Skip(kTagSize); // Skip kValueTag. - if (!ValueTypeHandler::Read(input, - reinterpret_cast(value_ptr_))) { - map_->erase(key_); // Failure! Undo insertion. - return false; - } - if (input->ExpectAtEnd()) return true; - return ReadBeyondKeyValuePair(input); - } - } - } else { - key_ = Key(); - } - - entry_.reset(mf_->NewEntry()); - *entry_->mutable_key() = key_; - if (!entry_->MergePartialFromCodedStream(input)) return false; - return UseKeyAndValueFromEntry(); - } - - const Key& key() const { return key_; } - const Value& value() const { return *value_ptr_; } - - private: - bool UseKeyAndValueFromEntry() GOOGLE_ATTRIBUTE_COLD { - // Update key_ in case we need it later (because key() is called). - // This is potentially inefficient, especially if the key is - // expensive to copy (e.g., a long string), but this is a cold - // path, so it's not a big deal. - key_ = entry_->key(); - value_ptr_ = &(*map_)[key_]; - MoveHelper::Move(entry_->mutable_value(), value_ptr_); - if (entry_->GetArena() != NULL) entry_.release(); - return true; - } - - // After reading a key and value successfully, and inserting that data - // into map_, we are not at the end of the input. This is unusual, but - // allowed by the spec. - bool ReadBeyondKeyValuePair(::google::protobuf::io::CodedInputStream* input) - GOOGLE_ATTRIBUTE_COLD { - typedef MoveHelper KeyMover; - typedef MoveHelper ValueMover; - entry_.reset(mf_->NewEntry()); - ValueMover::Move(value_ptr_, entry_->mutable_value()); - map_->erase(key_); - KeyMover::Move(&key_, entry_->mutable_key()); - if (!entry_->MergePartialFromCodedStream(input)) return false; - return UseKeyAndValueFromEntry(); - } - - MapField* const mf_; - Map* const map_; - Key key_; - Value* value_ptr_; - // On the fast path entry_ is not used. - google::protobuf::scoped_ptr entry_; - }; - - protected: - void set_has_key() { _has_bits_[0] |= 0x00000001u; } - bool has_key() const { return (_has_bits_[0] & 0x00000001u) != 0; } - void clear_has_key() { _has_bits_[0] &= ~0x00000001u; } - void set_has_value() { _has_bits_[0] |= 0x00000002u; } - bool has_value() const { return (_has_bits_[0] & 0x00000002u) != 0; } - void clear_has_value() { _has_bits_[0] &= ~0x00000002u; } - - private: - // Serializing a generated message containing map field involves serializing - // key-value pairs from google::protobuf::Map. The wire format of each key-value pair - // after serialization should be the same as that of a MapEntry message - // containing the same key and value inside it. However, google::protobuf::Map doesn't - // store key and value as MapEntry message, which disables us to use existing - // code to serialize message. In order to use existing code to serialize - // message, we need to construct a MapEntry from key-value pair. But it - // involves copy of key and value to construct a MapEntry. In order to avoid - // this copy in constructing a MapEntry, we need the following class which - // only takes references of given key and value. - template - class MapEntryWrapper - : public MapEntryLite { - typedef MapEntryLite Base; - typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType; - typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType; - - public: - MapEntryWrapper(Arena* arena, const K& key, const V& value) - : MapEntryLite(arena), - key_(key), - value_(value) { - Base::set_has_key(); - Base::set_has_value(); - } - inline const KeyMapEntryAccessorType& key() const { return key_; } - inline const ValueMapEntryAccessorType& value() const { return value_; } - - private: - const Key& key_; - const Value& value_; - - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - }; - - // Like above, but for enum value only, which stores value instead of - // reference of value field inside. This is needed because the type of value - // field in constructor is an enum, while we need to store it as an int. If we - // initialize a reference to int with a reference to enum, compiler will - // generate a temporary int from enum and initialize the reference to int with - // the temporary. - template - class MapEnumEntryWrapper - : public MapEntryLite { - typedef MapEntryLite Base; - typedef typename Base::KeyMapEntryAccessorType KeyMapEntryAccessorType; - typedef typename Base::ValueMapEntryAccessorType ValueMapEntryAccessorType; - - public: - MapEnumEntryWrapper(Arena* arena, const K& key, const V& value) - : MapEntryLite(arena), - key_(key), - value_(value) { - Base::set_has_key(); - Base::set_has_value(); - } - inline const KeyMapEntryAccessorType& key() const { return key_; } - inline const ValueMapEntryAccessorType& value() const { return value_; } - - private: - const KeyMapEntryAccessorType& key_; - const ValueMapEntryAccessorType value_; - - friend class google::protobuf::Arena; - typedef void DestructorSkippable_; - }; - - MapEntryLite() : default_instance_(NULL), arena_(NULL) { - KeyTypeHandler::Initialize(&key_, NULL); - ValueTypeHandler::InitializeMaybeByDefaultEnum( - &value_, default_enum_value, NULL); - _has_bits_[0] = 0; - } - - explicit MapEntryLite(Arena* arena) - : default_instance_(NULL), arena_(arena) { - KeyTypeHandler::Initialize(&key_, arena); - ValueTypeHandler::InitializeMaybeByDefaultEnum( - &value_, default_enum_value, arena); - _has_bits_[0] = 0; - } - - inline Arena* GetArenaNoVirtual() const { - return arena_; - } - - void set_default_instance(MapEntryLite* default_instance) { - default_instance_ = default_instance; - } - - MapEntryLite* default_instance_; - - KeyOnMemory key_; - ValueOnMemory value_; - Arena* arena_; - uint32 _has_bits_[1]; - - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - template - friend class internal::MapEntry; - template - friend class internal::MapFieldLite; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); -}; - -// Helpers for deterministic serialization ============================= - -// This struct can be used with any generic sorting algorithm. If the Key -// type is relatively small and easy to copy then copying Keys into an -// array of SortItems can be beneficial. Then all the data the sorting -// algorithm needs to touch is in that one array. -template struct SortItem { - SortItem() {} - explicit SortItem(PtrToKeyValuePair p) : first(p->first), second(p) {} - - Key first; - PtrToKeyValuePair second; -}; - -template struct CompareByFirstField { - bool operator()(const T& a, const T& b) const { - return a.first < b.first; - } -}; - -template struct CompareByDerefFirst { - bool operator()(const T& a, const T& b) const { - return a->first < b->first; - } -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MAP_ENTRY_LITE_H__ diff --git a/app/src/main/cpp/google/protobuf/map_field.h b/app/src/main/cpp/google/protobuf/map_field.h deleted file mode 100644 index d6af853..0000000 --- a/app/src/main/cpp/google/protobuf/map_field.h +++ /dev/null @@ -1,397 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MAP_FIELD_H__ -#define GOOGLE_PROTOBUF_MAP_FIELD_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace google { -namespace protobuf { -class DynamicMessage; -class MapKey; -namespace internal { - -class ContendedMapCleanTest; -class GeneratedMessageReflection; -class MapFieldAccessor; - -// This class provides access to map field using reflection, which is the same -// as those provided for RepeatedPtrField. It is used for internal -// reflection implentation only. Users should never use this directly. -class LIBPROTOBUF_EXPORT MapFieldBase { - public: - MapFieldBase() - : arena_(NULL), - repeated_field_(NULL), - entry_descriptor_(NULL), - assign_descriptor_callback_(NULL), - state_(STATE_MODIFIED_MAP) {} - explicit MapFieldBase(Arena* arena) - : arena_(arena), - repeated_field_(NULL), - entry_descriptor_(NULL), - assign_descriptor_callback_(NULL), - state_(STATE_MODIFIED_MAP) { - // Mutex's destructor needs to be called explicitly to release resources - // acquired in its constructor. - arena->OwnDestructor(&mutex_); - } - virtual ~MapFieldBase(); - - // Returns reference to internal repeated field. Data written using - // google::protobuf::Map's api prior to calling this function is guarantted to be - // included in repeated field. - const RepeatedPtrFieldBase& GetRepeatedField() const; - - // Like above. Returns mutable pointer to the internal repeated field. - RepeatedPtrFieldBase* MutableRepeatedField(); - - // Pure virtual map APIs for Map Reflection. - virtual bool ContainsMapKey(const MapKey& map_key) const = 0; - virtual bool InsertOrLookupMapValue( - const MapKey& map_key, MapValueRef* val) = 0; - virtual bool DeleteMapValue(const MapKey& map_key) = 0; - virtual bool EqualIterator(const MapIterator& a, - const MapIterator& b) const = 0; - virtual void MapBegin(MapIterator* map_iter) const = 0; - virtual void MapEnd(MapIterator* map_iter) const = 0; - // Sync Map with repeated field and returns the size of map. - virtual int size() const = 0; - - // Returns the number of bytes used by the repeated field, excluding - // sizeof(*this) - int SpaceUsedExcludingSelf() const; - - protected: - // Gets the size of space used by map field. - virtual int SpaceUsedExcludingSelfNoLock() const; - - // Synchronizes the content in Map to RepeatedPtrField if there is any change - // to Map after last synchronization. - void SyncRepeatedFieldWithMap() const; - virtual void SyncRepeatedFieldWithMapNoLock() const; - - // Synchronizes the content in RepeatedPtrField to Map if there is any change - // to RepeatedPtrField after last synchronization. - void SyncMapWithRepeatedField() const; - virtual void SyncMapWithRepeatedFieldNoLock() const {} - - // Tells MapFieldBase that there is new change to Map. - void SetMapDirty(); - - // Tells MapFieldBase that there is new change to RepeatedPTrField. - void SetRepeatedDirty(); - - // Provides derived class the access to repeated field. - void* MutableRepeatedPtrField() const; - - // Creates descriptor for only one time. - void InitMetadataOnce() const; - - enum State { - STATE_MODIFIED_MAP = 0, // map has newly added data that has not been - // synchronized to repeated field - STATE_MODIFIED_REPEATED = 1, // repeated field has newly added data that - // has not been synchronized to map - CLEAN = 2, // data in map and repeated field are same - }; - - Arena* arena_; - mutable RepeatedPtrField* repeated_field_; - // MapEntry can only be created from MapField. To create MapEntry, MapField - // needs to know its descriptor, because MapEntry is not generated class which - // cannot initialize its own descriptor by calling generated - // descriptor-assign-function. Thus, we need to register a callback to - // initialize MapEntry's descriptor. - const Descriptor** entry_descriptor_; - void (*assign_descriptor_callback_)(); - - mutable Mutex mutex_; // The thread to synchronize map and repeated field - // needs to get lock first; - mutable volatile Atomic32 state_; // 0: STATE_MODIFIED_MAP - // 1: STATE_MODIFIED_REPEATED - // 2: CLEAN - - private: - friend class ContendedMapCleanTest; - friend class GeneratedMessageReflection; - friend class MapFieldAccessor; - friend class ::google::protobuf::DynamicMessage; - - // Virtual helper methods for MapIterator. MapIterator doesn't have the - // type helper for key and value. Call these help methods to deal with - // different types. Real helper methods are implemented in - // TypeDefinedMapFieldBase. - friend class ::google::protobuf::MapIterator; - // Allocate map<...>::iterator for MapIterator. - virtual void InitializeIterator(MapIterator* map_iter) const = 0; - - // DeleteIterator() is called by the destructor of MapIterator only. - // It deletes map<...>::iterator for MapIterator. - virtual void DeleteIterator(MapIterator* map_iter) const = 0; - - // Copy the map<...>::iterator from other_iterator to - // this_iterator. - virtual void CopyIterator(MapIterator* this_iterator, - const MapIterator& other_iterator) const = 0; - - // IncreaseIterator() is called by operator++() of MapIterator only. - // It implements the ++ operator of MapIterator. - virtual void IncreaseIterator(MapIterator* map_iter) const = 0; -}; - -// This class provides common Map Reflection implementations for generated -// message and dynamic message. -template -class TypeDefinedMapFieldBase : public MapFieldBase { - public: - TypeDefinedMapFieldBase() {} - explicit TypeDefinedMapFieldBase(Arena* arena) : MapFieldBase(arena) {} - ~TypeDefinedMapFieldBase() {} - void MapBegin(MapIterator* map_iter) const; - void MapEnd(MapIterator* map_iter) const; - bool EqualIterator(const MapIterator& a, const MapIterator& b) const; - - virtual const Map& GetMap() const = 0; - virtual Map* MutableMap() = 0; - - protected: - typename Map::const_iterator& InternalGetIterator( - const MapIterator* map_iter) const; - - private: - void InitializeIterator(MapIterator* map_iter) const; - void DeleteIterator(MapIterator* map_iter) const; - void CopyIterator(MapIterator* this_iteratorm, - const MapIterator& that_iterator) const; - void IncreaseIterator(MapIterator* map_iter) const; - - virtual void SetMapIteratorValue(MapIterator* map_iter) const = 0; -}; - -// This class provides access to map field using generated api. It is used for -// internal generated message implentation only. Users should never use this -// directly. -template -class MapField : public TypeDefinedMapFieldBase, - public MapFieldLite { - // Provide utilities to parse/serialize key/value. Provide utilities to - // manipulate internal stored type. - typedef MapTypeHandler KeyTypeHandler; - typedef MapTypeHandler ValueTypeHandler; - - // Define message type for internal repeated field. - typedef MapEntry - EntryType; - typedef MapEntryLite EntryLiteType; - - // Define abbreviation for parent MapFieldLite - typedef MapFieldLite MapFieldLiteType; - - // Enum needs to be handled differently from other types because it has - // different exposed type in google::protobuf::Map's api and repeated field's api. For - // details see the comment in the implementation of - // SyncMapWithRepeatedFieldNoLock. - static const bool kIsValueEnum = ValueTypeHandler::kIsEnum; - typedef typename MapIf::type CastValueType; - - public: - MapField(); - explicit MapField(Arena* arena); - // MapField doesn't own the default_entry, which means default_entry must - // outlive the lifetime of MapField. - MapField(const Message* default_entry); - // For tests only. - MapField(Arena* arena, const Message* default_entry); - ~MapField(); - - // Implement MapFieldBase - bool ContainsMapKey(const MapKey& map_key) const; - bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val); - bool DeleteMapValue(const MapKey& map_key); - - // Accessors - const Map& GetMap() const; - Map* MutableMap(); - - // Convenient methods for generated message implementation. - int size() const; - void Clear(); - void MergeFrom(const MapFieldLiteType& other); - void Swap(MapFieldLiteType* other); - - // Allocates metadata only if this MapField is part of a generated message. - void SetEntryDescriptor(const Descriptor** descriptor); - void SetAssignDescriptorCallback(void (*callback)()); - - private: - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - - // MapField needs MapEntry's default instance to create new MapEntry. - void InitDefaultEntryOnce() const; - - // Manually set default entry instance. For test only. - void SetDefaultEntryOnce(const EntryType* default_entry) const; - - // Convenient methods to get internal google::protobuf::Map - const Map& GetInternalMap() const; - Map* MutableInternalMap(); - - // Implements MapFieldBase - void SyncRepeatedFieldWithMapNoLock() const; - void SyncMapWithRepeatedFieldNoLock() const; - int SpaceUsedExcludingSelfNoLock() const; - - void SetMapIteratorValue(MapIterator* map_iter) const; - - mutable const EntryType* default_entry_; - - friend class ::google::protobuf::Arena; -}; - -class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase { - public: - explicit DynamicMapField(const Message* default_entry); - DynamicMapField(const Message* default_entry, Arena* arena); - ~DynamicMapField(); - - // Implement MapFieldBase - bool ContainsMapKey(const MapKey& map_key) const; - bool InsertOrLookupMapValue(const MapKey& map_key, MapValueRef* val); - bool DeleteMapValue(const MapKey& map_key); - - const Map& GetMap() const; - Map* MutableMap(); - - int size() const; - - private: - Map map_; - const Message* default_entry_; - - // Implements MapFieldBase - void SyncRepeatedFieldWithMapNoLock() const; - void SyncMapWithRepeatedFieldNoLock() const; - int SpaceUsedExcludingSelfNoLock() const; - void SetMapIteratorValue(MapIterator* map_iter) const; -}; - -} // namespace internal - -class LIBPROTOBUF_EXPORT MapIterator { - public: - MapIterator(Message* message, const FieldDescriptor* field) { - const Reflection* reflection = message->GetReflection(); - map_ = reflection->MapData(message, field); - key_.SetType(field->message_type()->FindFieldByName("key")->cpp_type()); - value_.SetType(field->message_type()->FindFieldByName("value")->cpp_type()); - map_->InitializeIterator(this); - } - MapIterator(const MapIterator& other) { - map_ = other.map_; - map_->InitializeIterator(this); - map_->CopyIterator(this, other); - } - ~MapIterator() { - map_->DeleteIterator(this); - } - friend bool operator==(const MapIterator& a, const MapIterator& b) { - return a.map_->EqualIterator(a, b); - } - friend bool operator!=(const MapIterator& a, const MapIterator& b) { - return !a.map_->EqualIterator(a, b); - } - MapIterator& operator++() { - map_->IncreaseIterator(this); - return *this; - } - MapIterator operator++(int) { - // iter_ is copied from Map<...>::iterator, no need to - // copy from its self again. Use the same implementation - // with operator++() - map_->IncreaseIterator(this); - return *this; - } - const MapKey& GetKey() { - return key_; - } - const MapValueRef& GetValueRef() { - return value_; - } - MapValueRef* MutableValueRef() { - map_->SetMapDirty(); - return &value_; - } - - private: - template - friend class internal::TypeDefinedMapFieldBase; - friend class internal::DynamicMapField; - template - friend class internal::MapField; - - // reinterpret_cast from heap-allocated Map<...>::iterator*. MapIterator owns - // the iterator. It is allocated by MapField<...>::InitializeIterator() called - // in constructor and deleted by MapField<...>::DeleteIterator() called in - // destructor. - void* iter_; - // Point to a MapField to call helper methods implemented in MapField. - // MapIterator does not own this object. - internal::MapFieldBase* map_; - MapKey key_; - MapValueRef value_; -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MAP_FIELD_H__ diff --git a/app/src/main/cpp/google/protobuf/map_field_inl.h b/app/src/main/cpp/google/protobuf/map_field_inl.h deleted file mode 100644 index 01c9b89..0000000 --- a/app/src/main/cpp/google/protobuf/map_field_inl.h +++ /dev/null @@ -1,489 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MAP_FIELD_INL_H__ -#define GOOGLE_PROTOBUF_MAP_FIELD_INL_H__ - -#include -#ifndef _SHARED_PTR_H -#include -#endif - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace internal { -// UnwrapMapKey template -template -T UnwrapMapKey(const MapKey& map_key); -template<> -inline int32 UnwrapMapKey(const MapKey& map_key) { - return map_key.GetInt32Value(); -} -template<> -inline uint32 UnwrapMapKey(const MapKey& map_key) { - return map_key.GetUInt32Value(); -} -template<> -inline int64 UnwrapMapKey(const MapKey& map_key) { - return map_key.GetInt64Value(); -} -template<> -inline uint64 UnwrapMapKey(const MapKey& map_key) { - return map_key.GetUInt64Value(); -} -template<> -inline bool UnwrapMapKey(const MapKey& map_key) { - return map_key.GetBoolValue(); -} -template<> -inline string UnwrapMapKey(const MapKey& map_key) { - return map_key.GetStringValue(); -} - -// SetMapKey template -template -inline void SetMapKey(MapKey* map_key, const T& value); -template<> -inline void SetMapKey(MapKey* map_key, const int32& value) { - map_key->SetInt32Value(value); -} -template<> -inline void SetMapKey(MapKey* map_key, const uint32& value) { - map_key->SetUInt32Value(value); -} -template<> -inline void SetMapKey(MapKey* map_key, const int64& value) { - map_key->SetInt64Value(value); -} -template<> -inline void SetMapKey(MapKey* map_key, const uint64& value) { - map_key->SetUInt64Value(value); -} -template<> -inline void SetMapKey(MapKey* map_key, const bool& value) { - map_key->SetBoolValue(value); -} -template<> -inline void SetMapKey(MapKey* map_key, const string& value) { - map_key->SetStringValue(value); -} - -// ------------------------TypeDefinedMapFieldBase--------------- -template -typename Map::const_iterator& -TypeDefinedMapFieldBase::InternalGetIterator( - const MapIterator* map_iter) const { - return *reinterpret_cast::const_iterator *>( - map_iter->iter_); -} - -template -void TypeDefinedMapFieldBase::MapBegin(MapIterator* map_iter) const { - InternalGetIterator(map_iter) = GetMap().begin(); - SetMapIteratorValue(map_iter); -} - -template -void TypeDefinedMapFieldBase::MapEnd(MapIterator* map_iter) const { - InternalGetIterator(map_iter) = GetMap().end(); -} - -template -bool TypeDefinedMapFieldBase::EqualIterator(const MapIterator& a, - const MapIterator& b) - const { - return InternalGetIterator(&a) == InternalGetIterator(&b); -} - -template -void TypeDefinedMapFieldBase::IncreaseIterator(MapIterator* map_iter) - const { - ++InternalGetIterator(map_iter); - SetMapIteratorValue(map_iter); -} - -template -void TypeDefinedMapFieldBase::InitializeIterator( - MapIterator* map_iter) const { - map_iter->iter_ = new typename Map::const_iterator; - GOOGLE_CHECK(map_iter->iter_ != NULL); -} - -template -void TypeDefinedMapFieldBase::DeleteIterator(MapIterator* map_iter) - const { - delete reinterpret_cast::const_iterator *>( - map_iter->iter_); -} - -template -void TypeDefinedMapFieldBase::CopyIterator( - MapIterator* this_iter, - const MapIterator& that_iter) const { - InternalGetIterator(this_iter) = InternalGetIterator(&that_iter); - this_iter->key_.SetType(that_iter.key_.type()); - // MapValueRef::type() fails when containing data is null. However, if - // this_iter points to MapEnd, data can be null. - this_iter->value_.SetType( - static_cast(that_iter.value_.type_)); - SetMapIteratorValue(this_iter); -} - -// ---------------------------------------------------------------------- - -template -MapField::MapField() - : default_entry_(NULL) {} - -template -MapField::MapField( - Arena* arena) - : TypeDefinedMapFieldBase(arena), - MapFieldLite( - arena), - default_entry_(NULL) {} - -template -MapField::MapField( - const Message* default_entry) - : default_entry_(down_cast(default_entry)) {} - -template -MapField::MapField( - Arena* arena, const Message* default_entry) - : TypeDefinedMapFieldBase(arena), - MapFieldLite( - arena), - default_entry_(down_cast(default_entry)) {} - -template -MapField::~MapField() {} - -template -int -MapField::size() const { - MapFieldBase::SyncMapWithRepeatedField(); - return MapFieldLiteType::GetInternalMap().size(); -} - -template -void -MapField::Clear() { - MapFieldBase::SyncMapWithRepeatedField(); - MapFieldLiteType::MutableInternalMap()->clear(); - MapFieldBase::SetMapDirty(); -} - -template -void MapField::SetMapIteratorValue( - MapIterator* map_iter) const { - const Map& map = GetMap(); - typename Map::const_iterator iter = - TypeDefinedMapFieldBase::InternalGetIterator(map_iter); - if (iter == map.end()) return; - SetMapKey(&map_iter->key_, iter->first); - map_iter->value_.SetValue(&iter->second); -} - -template -bool MapField::ContainsMapKey( - const MapKey& map_key) const { - const Map& map = GetMap(); - const Key& key = UnwrapMapKey(map_key); - typename Map::const_iterator iter = map.find(key); - return iter != map.end(); -} - -template -bool MapField::InsertOrLookupMapValue( - const MapKey& map_key, - MapValueRef* val) { - // Always use mutable map because users may change the map value by - // MapValueRef. - Map* map = MutableMap(); - const Key& key = UnwrapMapKey(map_key); - typename Map::iterator iter = map->find(key); - if (map->end() == iter) { - val->SetValue(&((*map)[key])); - return true; - } - // Key is already in the map. Make sure (*map)[key] is not called. - // [] may reorder the map and iterators. - val->SetValue(&(iter->second)); - return false; -} - -template -bool MapField::DeleteMapValue( - const MapKey& map_key) { - const Key& key = UnwrapMapKey(map_key); - return MutableMap()->erase(key); -} - -template -const Map& -MapField::GetMap() const { - MapFieldBase::SyncMapWithRepeatedField(); - return MapFieldLiteType::GetInternalMap(); -} - -template -Map* -MapField::MutableMap() { - MapFieldBase::SyncMapWithRepeatedField(); - Map* result = MapFieldLiteType::MutableInternalMap(); - MapFieldBase::SetMapDirty(); - return result; -} - -template -void -MapField::MergeFrom( - const MapFieldLiteType& other) { - const MapField& down_other = down_cast(other); - MapFieldBase::SyncMapWithRepeatedField(); - down_other.SyncMapWithRepeatedField(); - MapFieldLiteType::MergeFrom(other); - MapFieldBase::SetMapDirty(); -} - -template -void -MapField::Swap( - MapFieldLiteType* other) { - MapField* down_other = down_cast(other); - std::swap(MapFieldBase::repeated_field_, down_other->repeated_field_); - MapFieldLiteType::Swap(other); - std::swap(MapFieldBase::state_, down_other->state_); -} - -template -void -MapField::SetEntryDescriptor( - const Descriptor** descriptor) { - MapFieldBase::entry_descriptor_ = descriptor; -} - -template -void -MapField::SetAssignDescriptorCallback(void (*callback)()) { - MapFieldBase::assign_descriptor_callback_ = callback; -} - -template -const Map& -MapField::GetInternalMap() const { - return MapFieldLiteType::GetInternalMap(); -} - -template -Map* -MapField::MutableInternalMap() { - return MapFieldLiteType::MutableInternalMap(); -} - -template -void -MapField::SyncRepeatedFieldWithMapNoLock() const { - if (MapFieldBase::repeated_field_ == NULL) { - if (MapFieldBase::arena_ == NULL) { - MapFieldBase::repeated_field_ = new RepeatedPtrField(); - } else { - MapFieldBase::repeated_field_ = - Arena::CreateMessage >( - MapFieldBase::arena_); - } - } - const Map& map = GetInternalMap(); - RepeatedPtrField* repeated_field = - reinterpret_cast*>( - MapFieldBase::repeated_field_); - - repeated_field->Clear(); - - for (typename Map::const_iterator it = map.begin(); - it != map.end(); ++it) { - InitDefaultEntryOnce(); - GOOGLE_CHECK(default_entry_ != NULL); - EntryType* new_entry = - down_cast(default_entry_->New(MapFieldBase::arena_)); - repeated_field->AddAllocated(new_entry); - (*new_entry->mutable_key()) = it->first; - (*new_entry->mutable_value()) = it->second; - } -} - -template -void -MapField::SyncMapWithRepeatedFieldNoLock() const { - Map* map = const_cast(this)->MutableInternalMap(); - RepeatedPtrField* repeated_field = - reinterpret_cast*>( - MapFieldBase::repeated_field_); - GOOGLE_CHECK(MapFieldBase::repeated_field_ != NULL); - map->clear(); - for (typename RepeatedPtrField::iterator it = - repeated_field->begin(); it != repeated_field->end(); ++it) { - // Cast is needed because Map's api and internal storage is different when - // value is enum. For enum, we cannot cast an int to enum. Thus, we have to - // copy value. For other types, they have same exposed api type and internal - // stored type. We should not introduce value copy for them. We achieve this - // by casting to value for enum while casting to reference for other types. - (*map)[it->key()] = static_cast(it->value()); - } -} - -template -int -MapField::SpaceUsedExcludingSelfNoLock() const { - int size = 0; - if (MapFieldBase::repeated_field_ != NULL) { - size += MapFieldBase::repeated_field_->SpaceUsedExcludingSelf(); - } - Map* map = const_cast(this)->MutableInternalMap(); - size += sizeof(*map); - for (typename Map::iterator it = map->begin(); - it != map->end(); ++it) { - size += KeyTypeHandler::SpaceUsedInMap(it->first); - size += ValueTypeHandler::SpaceUsedInMap(it->second); - } - return size; -} - -template -void -MapField::InitDefaultEntryOnce() - const { - if (default_entry_ == NULL) { - MapFieldBase::InitMetadataOnce(); - GOOGLE_CHECK(*MapFieldBase::entry_descriptor_ != NULL); - default_entry_ = down_cast( - MessageFactory::generated_factory()->GetPrototype( - *MapFieldBase::entry_descriptor_)); - } -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MAP_FIELD_INL_H__ diff --git a/app/src/main/cpp/google/protobuf/map_field_lite.h b/app/src/main/cpp/google/protobuf/map_field_lite.h deleted file mode 100644 index a9f30f5..0000000 --- a/app/src/main/cpp/google/protobuf/map_field_lite.h +++ /dev/null @@ -1,278 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__ -#define GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// This class provides access to map field using generated api. It is used for -// internal generated message implentation only. Users should never use this -// directly. -template -class MapFieldLite { - // Define message type for internal repeated field. - typedef MapEntryLite EntryType; - - public: - MapFieldLite(); - explicit MapFieldLite(Arena* arena); - virtual ~MapFieldLite(); - - // Accessors - virtual const Map& GetMap() const; - virtual Map* MutableMap(); - - // Convenient methods for generated message implementation. - virtual int size() const; - virtual void Clear(); - virtual void MergeFrom(const MapFieldLite& other); - virtual void Swap(MapFieldLite* other); - - // Set default enum value only for proto2 map field whose value is enum type. - void SetDefaultEnumValue(); - - // Used in the implementation of parsing. Caller should take the ownership. - EntryType* NewEntry() const; - // Used in the implementation of serializing enum value type. Caller should - // take the ownership. - EntryType* NewEnumEntryWrapper(const Key& key, const T t) const; - // Used in the implementation of serializing other value types. Caller should - // take the ownership. - EntryType* NewEntryWrapper(const Key& key, const T& t) const; - - protected: - // Convenient methods to get internal google::protobuf::Map - virtual const Map& GetInternalMap() const; - virtual Map* MutableInternalMap(); - - private: - typedef void DestructorSkippable_; - - Arena* arena_; - Map* map_; - - friend class ::google::protobuf::Arena; -}; - -template -MapFieldLite::MapFieldLite() - : arena_(NULL) { - map_ = new Map; - SetDefaultEnumValue(); -} - -template -MapFieldLite::MapFieldLite(Arena* arena) - : arena_(arena) { - map_ = Arena::CreateMessage >(arena); - SetDefaultEnumValue(); -} - -template -MapFieldLite::~MapFieldLite() { - delete map_; -} - -template -const Map& -MapFieldLite::GetMap() const { - return *map_; -} - -template -Map* -MapFieldLite::MutableMap() { - return map_; -} - -template -int -MapFieldLite::size() const { - return map_->size(); -} - -template -void -MapFieldLite::Clear() { - map_->clear(); -} - -template -void -MapFieldLite::MergeFrom( - const MapFieldLite& other) { - for (typename Map::const_iterator it = other.map_->begin(); - it != other.map_->end(); ++it) { - (*map_)[it->first] = it->second; - } -} - -template -void -MapFieldLite::Swap( - MapFieldLite* other) { - std::swap(map_, other->map_); -} - -template -void -MapFieldLite::SetDefaultEnumValue() { - MutableInternalMap()->SetDefaultEnumValue(default_enum_value); -} - -template -const Map& -MapFieldLite::GetInternalMap() const { - return *map_; -} - -template -Map* -MapFieldLite::MutableInternalMap() { - return map_; -} - -#define EntryType \ - MapEntryLite - -template -EntryType* -MapFieldLite::NewEntry() const { - if (arena_ == NULL) { - return new EntryType(); - } else { - return Arena::CreateMessage(arena_); - } -} - -template -EntryType* -MapFieldLite::NewEnumEntryWrapper(const Key& key, - const T t) const { - return EntryType::EnumWrap(key, t, arena_); -} - -template -EntryType* -MapFieldLite::NewEntryWrapper(const Key& key, - const T& t) const { - return EntryType::Wrap(key, t, arena_); -} - -#undef EntryType - -// True if IsInitialized() is true for value field in all elements of t. T is -// expected to be message. It's useful to have this helper here to keep the -// protobuf compiler from ever having to emit loops in IsInitialized() methods. -// We want the C++ compiler to inline this or not as it sees fit. -template -bool AllAreInitialized(const Map& t) { - for (typename Map::const_iterator it = t.begin(); it != t.end(); - ++it) { - if (!it->second.IsInitialized()) return false; - } - return true; -} - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MAP_FIELD_LITE_H__ diff --git a/app/src/main/cpp/google/protobuf/map_type_handler.h b/app/src/main/cpp/google/protobuf/map_type_handler.h deleted file mode 100644 index a21c92d..0000000 --- a/app/src/main/cpp/google/protobuf/map_type_handler.h +++ /dev/null @@ -1,743 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_TYPE_HANDLER_H__ -#define GOOGLE_PROTOBUF_TYPE_HANDLER_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Used for compile time type selection. MapIf::type will be TrueType if Flag is -// true and FalseType otherwise. -template -struct MapIf; - -template -struct MapIf { - typedef TrueType type; -}; - -template -struct MapIf { - typedef FalseType type; -}; - -// In proto2 Map, enum needs to be initialized to given default value, while -// other types' default value can be inferred from the type. -template -class MapValueInitializer { - public: - static inline void Initialize(Type& type, int default_enum_value); -}; - -template -class MapValueInitializer { - public: - static inline void Initialize(Type& value, int default_enum_value) { - value = static_cast(default_enum_value); - } -}; - -template -class MapValueInitializer { - public: - static inline void Initialize(Type& value, int default_enum_value) {} -}; - -template -class MapArenaMessageCreator { - public: - // Use arena to create message if Type is arena constructable. Otherwise, - // create the message on heap. - static inline Type* CreateMessage(Arena* arena); -}; -template -class MapArenaMessageCreator { - public: - static inline Type* CreateMessage(Arena* arena) { - return Arena::CreateMessage(arena); - } -}; -template -class MapArenaMessageCreator { - public: - static inline Type* CreateMessage(Arena* arena) { - return Arena::Create(arena); - } -}; - -// Define constants for given wire field type -template -class MapWireFieldTypeTraits {}; - -#define TYPE_TRAITS(FieldType, CType, WireFormatType, IsMessage, IsEnum) \ - template \ - class MapWireFieldTypeTraits { \ - public: \ - static const bool kIsMessage = IsMessage; \ - static const bool kIsEnum = IsEnum; \ - typedef typename MapIf::type TypeOnMemory; \ - typedef typename MapIf::type MapEntryAccessorType; \ - static const WireFormatLite::WireType kWireType = \ - WireFormatLite::WIRETYPE_##WireFormatType; \ - }; - -TYPE_TRAITS(MESSAGE , Type, LENGTH_DELIMITED, true, false) -TYPE_TRAITS(STRING , ArenaStringPtr, LENGTH_DELIMITED, false, false) -TYPE_TRAITS(BYTES , ArenaStringPtr , LENGTH_DELIMITED, false, false) -TYPE_TRAITS(INT64 , int64 , VARINT , false, false) -TYPE_TRAITS(UINT64 , uint64 , VARINT , false, false) -TYPE_TRAITS(INT32 , int32 , VARINT , false, false) -TYPE_TRAITS(UINT32 , uint32 , VARINT , false, false) -TYPE_TRAITS(SINT64 , int64 , VARINT , false, false) -TYPE_TRAITS(SINT32 , int32 , VARINT , false, false) -TYPE_TRAITS(ENUM , int , VARINT , false, true ) -TYPE_TRAITS(DOUBLE , double , FIXED64, false, false) -TYPE_TRAITS(FLOAT , float , FIXED32, false, false) -TYPE_TRAITS(FIXED64 , uint64 , FIXED64, false, false) -TYPE_TRAITS(FIXED32 , uint32 , FIXED32, false, false) -TYPE_TRAITS(SFIXED64, int64 , FIXED64, false, false) -TYPE_TRAITS(SFIXED32, int32 , FIXED32, false, false) -TYPE_TRAITS(BOOL , bool , VARINT , false, false) - -#undef TYPE_TRAITS - -template -class MapTypeHandler {}; - -template -class MapTypeHandler { - public: - // Enum type cannot be used for MapTypeHandler::Read. Define a type which will - // replace Enum with int. - typedef typename MapWireFieldTypeTraits::MapEntryAccessorType MapEntryAccessorType; - // Internal stored type in MapEntryLite for given wire field type. - typedef typename MapWireFieldTypeTraits::TypeOnMemory TypeOnMemory; - // Corresponding wire type for field type. - static const WireFormatLite::WireType kWireType = - MapWireFieldTypeTraits::kWireType; - // Whether wire type is for message. - static const bool kIsMessage = - MapWireFieldTypeTraits::kIsMessage; - // Whether wire type is for enum. - static const bool kIsEnum = - MapWireFieldTypeTraits::kIsEnum; - - // Functions used in parsing and serialization. =================== - static inline size_t ByteSize(const MapEntryAccessorType& value); - static inline int GetCachedSize(const MapEntryAccessorType& value); - static inline bool Read(io::CodedInputStream* input, - MapEntryAccessorType* value); - static inline void Write(int field, const MapEntryAccessorType& value, - io::CodedOutputStream* output); - static inline uint8* InternalWriteToArray(int field, - const MapEntryAccessorType& value, - bool deterministic, uint8* target); - static inline uint8* WriteToArray(int field, - const MapEntryAccessorType& value, - uint8* target); - - // Functions to manipulate data on memory. ======================== - static inline const Type& GetExternalReference(const Type* value); - static inline void DeleteNoArena(const Type* x); - static inline void Merge(const Type& from, Type** to, Arena* arena); - static inline void Clear(Type** value, Arena* arena); - static inline void ClearMaybeByDefaultEnum(Type** value, Arena* arena, - int default_enum_value); - static inline void Initialize(Type** x, Arena* arena); - - static inline void InitializeMaybeByDefaultEnum(Type** x, - int default_enum_value, - Arena* arena); - static inline Type* EnsureMutable(Type** value, Arena* arena); - // SpaceUsedInMapEntry: Return bytes used by value in MapEntry, excluding - // those already calculate in sizeof(MapField). - static inline int SpaceUsedInMapEntry(const Type* value); - // Return bytes used by value in Map. - static inline int SpaceUsedInMap(const Type& value); - // Assign default value to given instance. - static inline void AssignDefaultValue(Type** value); - // Return default instance if value is not initialized when calling const - // reference accessor. - static inline const Type& DefaultIfNotInitialized( - const Type* value, const Type* default_value); - // Check if all required fields have values set. - static inline bool IsInitialized(Type* value); -}; - -#define MAP_HANDLER(FieldType) \ - template \ - class MapTypeHandler { \ - public: \ - typedef typename MapWireFieldTypeTraits::MapEntryAccessorType \ - MapEntryAccessorType; \ - typedef typename MapWireFieldTypeTraits::TypeOnMemory TypeOnMemory; \ - static const WireFormatLite::WireType kWireType = \ - MapWireFieldTypeTraits::kWireType; \ - static const bool kIsMessage = \ - MapWireFieldTypeTraits::kIsMessage; \ - static const bool kIsEnum = \ - MapWireFieldTypeTraits::kIsEnum; \ - static inline int ByteSize(const MapEntryAccessorType& value); \ - static inline int GetCachedSize(const MapEntryAccessorType& value); \ - static inline bool Read(io::CodedInputStream* input, \ - MapEntryAccessorType* value); \ - static inline void Write(int field, const MapEntryAccessorType& value, \ - io::CodedOutputStream* output); \ - static inline uint8* InternalWriteToArray( \ - int field, \ - const MapEntryAccessorType& value, \ - bool deterministic, \ - uint8* target); \ - static inline uint8* WriteToArray(int field, \ - const MapEntryAccessorType& value, \ - uint8* target) { \ - return InternalWriteToArray(field, value, false, target); \ - } \ - static inline const MapEntryAccessorType& GetExternalReference( \ - const TypeOnMemory& value); \ - static inline void DeleteNoArena(const TypeOnMemory& x); \ - static inline void Merge(const MapEntryAccessorType& from, \ - TypeOnMemory* to, Arena* arena); \ - static inline void Clear(TypeOnMemory* value, Arena* arena); \ - static inline void ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum); \ - static inline int SpaceUsedInMapEntry(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const TypeOnMemory& value); \ - static inline int SpaceUsedInMap(const string& value); \ - static inline void AssignDefaultValue(TypeOnMemory* value); \ - static inline const MapEntryAccessorType& DefaultIfNotInitialized( \ - const TypeOnMemory& value, const TypeOnMemory& default_value); \ - static inline bool IsInitialized(const TypeOnMemory& value); \ - static void DeleteNoArena(TypeOnMemory& value); \ - static inline void Initialize(TypeOnMemory* value, Arena* arena); \ - static inline void InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena); \ - static inline MapEntryAccessorType* EnsureMutable(TypeOnMemory* value, \ - Arena* arena); \ - }; -MAP_HANDLER(STRING) -MAP_HANDLER(BYTES) -MAP_HANDLER(INT64) -MAP_HANDLER(UINT64) -MAP_HANDLER(INT32) -MAP_HANDLER(UINT32) -MAP_HANDLER(SINT64) -MAP_HANDLER(SINT32) -MAP_HANDLER(ENUM) -MAP_HANDLER(DOUBLE) -MAP_HANDLER(FLOAT) -MAP_HANDLER(FIXED64) -MAP_HANDLER(FIXED32) -MAP_HANDLER(SFIXED64) -MAP_HANDLER(SFIXED32) -MAP_HANDLER(BOOL) -#undef MAP_HANDLER - -template -inline size_t -MapTypeHandler::ByteSize( - const MapEntryAccessorType& value) { - return WireFormatLite::MessageSizeNoVirtual(value); -} - -#define GOOGLE_PROTOBUF_BYTE_SIZE(FieldType, DeclaredType) \ - template \ - inline int MapTypeHandler::ByteSize( \ - const MapEntryAccessorType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ - } - -GOOGLE_PROTOBUF_BYTE_SIZE(STRING, String) -GOOGLE_PROTOBUF_BYTE_SIZE(BYTES , Bytes) -GOOGLE_PROTOBUF_BYTE_SIZE(INT64 , Int64) -GOOGLE_PROTOBUF_BYTE_SIZE(UINT64, UInt64) -GOOGLE_PROTOBUF_BYTE_SIZE(INT32 , Int32) -GOOGLE_PROTOBUF_BYTE_SIZE(UINT32, UInt32) -GOOGLE_PROTOBUF_BYTE_SIZE(SINT64, SInt64) -GOOGLE_PROTOBUF_BYTE_SIZE(SINT32, SInt32) -GOOGLE_PROTOBUF_BYTE_SIZE(ENUM , Enum) - -#undef GOOGLE_PROTOBUF_BYTE_SIZE - -#define FIXED_BYTE_SIZE(FieldType, DeclaredType) \ - template \ - inline int MapTypeHandler::ByteSize( \ - const MapEntryAccessorType& value) { \ - return WireFormatLite::k##DeclaredType##Size; \ - } - -FIXED_BYTE_SIZE(DOUBLE , Double) -FIXED_BYTE_SIZE(FLOAT , Float) -FIXED_BYTE_SIZE(FIXED64 , Fixed64) -FIXED_BYTE_SIZE(FIXED32 , Fixed32) -FIXED_BYTE_SIZE(SFIXED64, SFixed64) -FIXED_BYTE_SIZE(SFIXED32, SFixed32) -FIXED_BYTE_SIZE(BOOL , Bool) - -#undef FIXED_BYTE_SIZE - -template -inline int -MapTypeHandler::GetCachedSize( - const MapEntryAccessorType& value) { - return WireFormatLite::LengthDelimitedSize(value.GetCachedSize()); -} - -#define GET_CACHED_SIZE(FieldType, DeclaredType) \ - template \ - inline int \ - MapTypeHandler::GetCachedSize( \ - const MapEntryAccessorType& value) { \ - return WireFormatLite::DeclaredType##Size(value); \ - } - -GET_CACHED_SIZE(STRING, String) -GET_CACHED_SIZE(BYTES , Bytes) -GET_CACHED_SIZE(INT64 , Int64) -GET_CACHED_SIZE(UINT64, UInt64) -GET_CACHED_SIZE(INT32 , Int32) -GET_CACHED_SIZE(UINT32, UInt32) -GET_CACHED_SIZE(SINT64, SInt64) -GET_CACHED_SIZE(SINT32, SInt32) -GET_CACHED_SIZE(ENUM , Enum) - -#undef GET_CACHED_SIZE - -#define GET_FIXED_CACHED_SIZE(FieldType, DeclaredType) \ - template \ - inline int \ - MapTypeHandler::GetCachedSize( \ - const MapEntryAccessorType& value) { \ - return WireFormatLite::k##DeclaredType##Size; \ - } - -GET_FIXED_CACHED_SIZE(DOUBLE , Double) -GET_FIXED_CACHED_SIZE(FLOAT , Float) -GET_FIXED_CACHED_SIZE(FIXED64 , Fixed64) -GET_FIXED_CACHED_SIZE(FIXED32 , Fixed32) -GET_FIXED_CACHED_SIZE(SFIXED64, SFixed64) -GET_FIXED_CACHED_SIZE(SFIXED32, SFixed32) -GET_FIXED_CACHED_SIZE(BOOL , Bool) - -#undef GET_FIXED_CACHED_SIZE - -template -inline void MapTypeHandler::Write( - int field, const MapEntryAccessorType& value, - io::CodedOutputStream* output) { - WireFormatLite::WriteMessageMaybeToArray(field, value, output); -} - -template -inline uint8* -MapTypeHandler::InternalWriteToArray( - int field, const MapEntryAccessorType& value, bool deterministic, - uint8* target) { - return WireFormatLite::InternalWriteMessageToArray(field, value, - deterministic, target); -} - -#define WRITE_METHOD(FieldType, DeclaredType) \ - template \ - inline void MapTypeHandler::Write( \ - int field, const MapEntryAccessorType& value, \ - io::CodedOutputStream* output) { \ - return WireFormatLite::Write##DeclaredType(field, value, output); \ - } \ - template \ - inline uint8* \ - MapTypeHandler::InternalWriteToArray( \ - int field, const MapEntryAccessorType& value, bool, uint8* target) { \ - return WireFormatLite::Write##DeclaredType##ToArray(field, value, target); \ - } - -WRITE_METHOD(STRING , String) -WRITE_METHOD(BYTES , Bytes) -WRITE_METHOD(INT64 , Int64) -WRITE_METHOD(UINT64 , UInt64) -WRITE_METHOD(INT32 , Int32) -WRITE_METHOD(UINT32 , UInt32) -WRITE_METHOD(SINT64 , SInt64) -WRITE_METHOD(SINT32 , SInt32) -WRITE_METHOD(ENUM , Enum) -WRITE_METHOD(DOUBLE , Double) -WRITE_METHOD(FLOAT , Float) -WRITE_METHOD(FIXED64 , Fixed64) -WRITE_METHOD(FIXED32 , Fixed32) -WRITE_METHOD(SFIXED64, SFixed64) -WRITE_METHOD(SFIXED32, SFixed32) -WRITE_METHOD(BOOL , Bool) - -#undef WRITE_METHOD - -template -inline bool MapTypeHandler::Read( - io::CodedInputStream* input, MapEntryAccessorType* value) { - return WireFormatLite::ReadMessageNoVirtual(input, value); -} - -template -inline bool MapTypeHandler::Read( - io::CodedInputStream* input, MapEntryAccessorType* value) { - return WireFormatLite::ReadString(input, value); -} - -template -inline bool MapTypeHandler::Read( - io::CodedInputStream* input, MapEntryAccessorType* value) { - return WireFormatLite::ReadBytes(input, value); -} - -#define READ_METHOD(FieldType) \ - template \ - inline bool MapTypeHandler::Read( \ - io::CodedInputStream* input, MapEntryAccessorType* value) { \ - return WireFormatLite::ReadPrimitive( \ - input, value); \ - } - -READ_METHOD(INT64) -READ_METHOD(UINT64) -READ_METHOD(INT32) -READ_METHOD(UINT32) -READ_METHOD(SINT64) -READ_METHOD(SINT32) -READ_METHOD(ENUM) -READ_METHOD(DOUBLE) -READ_METHOD(FLOAT) -READ_METHOD(FIXED64) -READ_METHOD(FIXED32) -READ_METHOD(SFIXED64) -READ_METHOD(SFIXED32) -READ_METHOD(BOOL) - -#undef READ_METHOD - -// Definition for message handler - -template -inline const Type& -MapTypeHandler::GetExternalReference(const Type* value) { - return *value; -} - -template -inline int -MapTypeHandler::SpaceUsedInMapEntry(const Type* value) { - return value->SpaceUsed(); -} - -template -int MapTypeHandler::SpaceUsedInMap( - const Type& value) { - return value.SpaceUsed(); -} - -template -inline void MapTypeHandler::Clear( - Type** value, Arena* arena) { - if (*value != NULL) (*value)->Clear(); -} -template -inline void -MapTypeHandler::ClearMaybeByDefaultEnum(Type** value, - Arena* arena, - int default_enum_value) { - if (*value != NULL) (*value)->Clear(); -} -template -inline void MapTypeHandler::Merge( - const Type& from, Type** to, Arena* arena) { - (*to)->MergeFrom(from); -} - -template -void MapTypeHandler::DeleteNoArena( - const Type* ptr) { - delete ptr; -} - -template -inline void MapTypeHandler::AssignDefaultValue(Type** value) { - *value = const_cast(&Type::default_instance()); -} - -template -inline void MapTypeHandler::Initialize(Type** x, - Arena* arena) { - *x = NULL; -} - -template -inline void MapTypeHandler:: - InitializeMaybeByDefaultEnum(Type** x, int default_enum_value, - Arena* arena) { - *x = NULL; -} - -template -inline Type* MapTypeHandler::EnsureMutable(Type** value, - Arena* arena) { - if (*value == NULL) { - *value = - MapArenaMessageCreator:: - type::value>::CreateMessage(arena); - } - return *value; -} - -template -inline const Type& MapTypeHandler:: - DefaultIfNotInitialized(const Type* value, const Type* default_value) { - return value != NULL ? *value : *default_value; -} - -template -inline bool MapTypeHandler::IsInitialized(Type* value) { - return value->IsInitialized(); -} - -// Definition for string/bytes handler - -#define STRING_OR_BYTES_HANDLER_FUNCTIONS(FieldType) \ - template \ - inline const typename MapTypeHandler::MapEntryAccessorType& \ - MapTypeHandler::GetExternalReference(const TypeOnMemory& value) { \ - return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ - } \ - template \ - inline int \ - MapTypeHandler::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ - return sizeof(value); \ - } \ - template \ - inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ - return sizeof(value); \ - } \ - template \ - inline int MapTypeHandler::SpaceUsedInMap(const string& value) { \ - return sizeof(value); \ - } \ - template \ - inline void MapTypeHandler::Clear( \ - TypeOnMemory* value, Arena* arena) { \ - value->ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), \ - arena); \ - } \ - template \ - inline void \ - MapTypeHandler::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum) { \ - Clear(value, arena); \ - } \ - template \ - inline void MapTypeHandler::Merge( \ - const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ - to->Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from, arena); \ - } \ - template \ - void MapTypeHandler::DeleteNoArena( \ - TypeOnMemory& value) { \ - value.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ - } \ - template \ - inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ - template \ - inline void \ - MapTypeHandler::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ - value->UnsafeSetDefault( \ - &::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ - } \ - template \ - inline void \ - MapTypeHandler::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena) { \ - Initialize(value, arena); \ - } \ - template \ - inline typename MapTypeHandler::MapEntryAccessorType* \ - MapTypeHandler::EnsureMutable( \ - TypeOnMemory* value, Arena* arena) { \ - return value->Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), \ - arena); \ - } \ - template \ - inline const typename MapTypeHandler::MapEntryAccessorType& \ - MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ - const TypeOnMemory& \ - default_value) { \ - return value.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); \ - } \ - template \ - inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ - return true; \ - } -STRING_OR_BYTES_HANDLER_FUNCTIONS(STRING) -STRING_OR_BYTES_HANDLER_FUNCTIONS(BYTES) -#undef STRING_OR_BYTES_HANDLER_FUNCTIONS - -#define PRIMITIVE_HANDLER_FUNCTIONS(FieldType) \ - template \ - inline const typename MapTypeHandler::MapEntryAccessorType& \ - MapTypeHandler::GetExternalReference(const TypeOnMemory& value) { \ - return value; \ - } \ - template \ - inline int \ - MapTypeHandler::SpaceUsedInMapEntry( \ - const TypeOnMemory& value) { \ - return 0; \ - } \ - template \ - inline int MapTypeHandler::SpaceUsedInMap(const TypeOnMemory& value) { \ - return sizeof(Type); \ - } \ - template \ - inline void MapTypeHandler::Clear( \ - TypeOnMemory* value, Arena* arena) { \ - *value = 0; \ - } \ - template \ - inline void \ - MapTypeHandler::ClearMaybeByDefaultEnum(TypeOnMemory* value, \ - Arena* arena, \ - int default_enum_value) { \ - *value = static_cast(default_enum_value); \ - } \ - template \ - inline void MapTypeHandler::Merge( \ - const MapEntryAccessorType& from, TypeOnMemory* to, Arena* arena) { \ - *to = from; \ - } \ - template \ - inline void MapTypeHandler::DeleteNoArena(TypeOnMemory& x) {} \ - template \ - inline void MapTypeHandler::AssignDefaultValue(TypeOnMemory* value) {} \ - template \ - inline void \ - MapTypeHandler::Initialize( \ - TypeOnMemory* value, Arena* arena) { \ - *value = 0; \ - } \ - template \ - inline void \ - MapTypeHandler::InitializeMaybeByDefaultEnum(TypeOnMemory* value, \ - int default_enum_value, \ - Arena* arena) { \ - *value = static_cast(default_enum_value); \ - } \ - template \ - inline typename MapTypeHandler::MapEntryAccessorType* \ - MapTypeHandler::EnsureMutable( \ - TypeOnMemory* value, Arena* arena) { \ - return value; \ - } \ - template \ - inline const typename MapTypeHandler::MapEntryAccessorType& \ - MapTypeHandler::DefaultIfNotInitialized(const TypeOnMemory& value, \ - const TypeOnMemory& \ - default_value) { \ - return value; \ - } \ - template \ - inline bool MapTypeHandler::IsInitialized(const TypeOnMemory& value) { \ - return true; \ - } -PRIMITIVE_HANDLER_FUNCTIONS(INT64) -PRIMITIVE_HANDLER_FUNCTIONS(UINT64) -PRIMITIVE_HANDLER_FUNCTIONS(INT32) -PRIMITIVE_HANDLER_FUNCTIONS(UINT32) -PRIMITIVE_HANDLER_FUNCTIONS(SINT64) -PRIMITIVE_HANDLER_FUNCTIONS(SINT32) -PRIMITIVE_HANDLER_FUNCTIONS(ENUM) -PRIMITIVE_HANDLER_FUNCTIONS(DOUBLE) -PRIMITIVE_HANDLER_FUNCTIONS(FLOAT) -PRIMITIVE_HANDLER_FUNCTIONS(FIXED64) -PRIMITIVE_HANDLER_FUNCTIONS(FIXED32) -PRIMITIVE_HANDLER_FUNCTIONS(SFIXED64) -PRIMITIVE_HANDLER_FUNCTIONS(SFIXED32) -PRIMITIVE_HANDLER_FUNCTIONS(BOOL) -#undef PRIMITIVE_HANDLER_FUNCTIONS - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_TYPE_HANDLER_H__ diff --git a/app/src/main/cpp/google/protobuf/message.h b/app/src/main/cpp/google/protobuf/message.h deleted file mode 100644 index bee25f7..0000000 --- a/app/src/main/cpp/google/protobuf/message.h +++ /dev/null @@ -1,1150 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines Message, the abstract interface implemented by non-lite -// protocol message objects. Although it's possible to implement this -// interface manually, most users will use the protocol compiler to -// generate implementations. -// -// Example usage: -// -// Say you have a message defined as: -// -// message Foo { -// optional string text = 1; -// repeated int32 numbers = 2; -// } -// -// Then, if you used the protocol compiler to generate a class from the above -// definition, you could use it like so: -// -// string data; // Will store a serialized version of the message. -// -// { -// // Create a message and serialize it. -// Foo foo; -// foo.set_text("Hello World!"); -// foo.add_numbers(1); -// foo.add_numbers(5); -// foo.add_numbers(42); -// -// foo.SerializeToString(&data); -// } -// -// { -// // Parse the serialized message and check that it contains the -// // correct data. -// Foo foo; -// foo.ParseFromString(data); -// -// assert(foo.text() == "Hello World!"); -// assert(foo.numbers_size() == 3); -// assert(foo.numbers(0) == 1); -// assert(foo.numbers(1) == 5); -// assert(foo.numbers(2) == 42); -// } -// -// { -// // Same as the last block, but do it dynamically via the Message -// // reflection interface. -// Message* foo = new Foo; -// const Descriptor* descriptor = foo->GetDescriptor(); -// -// // Get the descriptors for the fields we're interested in and verify -// // their types. -// const FieldDescriptor* text_field = descriptor->FindFieldByName("text"); -// assert(text_field != NULL); -// assert(text_field->type() == FieldDescriptor::TYPE_STRING); -// assert(text_field->label() == FieldDescriptor::LABEL_OPTIONAL); -// const FieldDescriptor* numbers_field = descriptor-> -// FindFieldByName("numbers"); -// assert(numbers_field != NULL); -// assert(numbers_field->type() == FieldDescriptor::TYPE_INT32); -// assert(numbers_field->label() == FieldDescriptor::LABEL_REPEATED); -// -// // Parse the message. -// foo->ParseFromString(data); -// -// // Use the reflection interface to examine the contents. -// const Reflection* reflection = foo->GetReflection(); -// assert(reflection->GetString(*foo, text_field) == "Hello World!"); -// assert(reflection->FieldSize(*foo, numbers_field) == 3); -// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 0) == 1); -// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 1) == 5); -// assert(reflection->GetRepeatedInt32(*foo, numbers_field, 2) == 42); -// -// delete foo; -// } - -#ifndef GOOGLE_PROTOBUF_MESSAGE_H__ -#define GOOGLE_PROTOBUF_MESSAGE_H__ - -#include -#include -#include -#include - -#include -#include - -#include -#include - - -#define GOOGLE_PROTOBUF_HAS_ONEOF -#define GOOGLE_PROTOBUF_HAS_ARENAS - -namespace google { -namespace protobuf { - -// Defined in this file. -class Message; -class Reflection; -class MessageFactory; - -// Defined in other files. -class MapKey; -class MapValueRef; -class MapIterator; -class MapReflectionTester; - -namespace internal { -class MapFieldBase; -} -class UnknownFieldSet; // unknown_field_set.h -namespace io { -class ZeroCopyInputStream; // zero_copy_stream.h -class ZeroCopyOutputStream; // zero_copy_stream.h -class CodedInputStream; // coded_stream.h -class CodedOutputStream; // coded_stream.h -} -namespace python { -class MapReflectionFriend; // scalar_map_container.h -} - - -template -class RepeatedField; // repeated_field.h - -template -class RepeatedPtrField; // repeated_field.h - -// A container to hold message metadata. -struct Metadata { - const Descriptor* descriptor; - const Reflection* reflection; -}; - -// Abstract interface for protocol messages. -// -// See also MessageLite, which contains most every-day operations. Message -// adds descriptors and reflection on top of that. -// -// The methods of this class that are virtual but not pure-virtual have -// default implementations based on reflection. Message classes which are -// optimized for speed will want to override these with faster implementations, -// but classes optimized for code size may be happy with keeping them. See -// the optimize_for option in descriptor.proto. -class LIBPROTOBUF_EXPORT Message : public MessageLite { - public: - inline Message() {} - virtual ~Message() {} - - // Basic Operations ------------------------------------------------ - - // Construct a new instance of the same type. Ownership is passed to the - // caller. (This is also defined in MessageLite, but is defined again here - // for return-type covariance.) - virtual Message* New() const = 0; - - // Construct a new instance on the arena. Ownership is passed to the caller - // if arena is a NULL. Default implementation allows for API compatibility - // during the Arena transition. - virtual Message* New(::google::protobuf::Arena* arena) const { - Message* message = New(); - if (arena != NULL) { - arena->Own(message); - } - return message; - } - - // Make this message into a copy of the given message. The given message - // must have the same descriptor, but need not necessarily be the same class. - // By default this is just implemented as "Clear(); MergeFrom(from);". - virtual void CopyFrom(const Message& from); - - // Merge the fields from the given message into this message. Singular - // fields will be overwritten, if specified in from, except for embedded - // messages which will be merged. Repeated fields will be concatenated. - // The given message must be of the same type as this message (i.e. the - // exact same class). - virtual void MergeFrom(const Message& from); - - // Verifies that IsInitialized() returns true. GOOGLE_CHECK-fails otherwise, with - // a nice error message. - void CheckInitialized() const; - - // Slowly build a list of all required fields that are not set. - // This is much, much slower than IsInitialized() as it is implemented - // purely via reflection. Generally, you should not call this unless you - // have already determined that an error exists by calling IsInitialized(). - void FindInitializationErrors(std::vector* errors) const; - - // Like FindInitializationErrors, but joins all the strings, delimited by - // commas, and returns them. - string InitializationErrorString() const; - - // Clears all unknown fields from this message and all embedded messages. - // Normally, if unknown tag numbers are encountered when parsing a message, - // the tag and value are stored in the message's UnknownFieldSet and - // then written back out when the message is serialized. This allows servers - // which simply route messages to other servers to pass through messages - // that have new field definitions which they don't yet know about. However, - // this behavior can have security implications. To avoid it, call this - // method after parsing. - // - // See Reflection::GetUnknownFields() for more on unknown fields. - virtual void DiscardUnknownFields(); - - // Computes (an estimate of) the total number of bytes currently used for - // storing the message in memory. The default implementation calls the - // Reflection object's SpaceUsed() method. - // - // SpaceUsed() is noticeably slower than ByteSize(), as it is implemented - // using reflection (rather than the generated code implementation for - // ByteSize()). Like ByteSize(), its CPU time is linear in the number of - // fields defined for the proto. - virtual int SpaceUsed() const; - - // Debugging & Testing---------------------------------------------- - - // Generates a human readable form of this message, useful for debugging - // and other purposes. - string DebugString() const; - // Like DebugString(), but with less whitespace. - string ShortDebugString() const; - // Like DebugString(), but do not escape UTF-8 byte sequences. - string Utf8DebugString() const; - // Convenience function useful in GDB. Prints DebugString() to stdout. - void PrintDebugString() const; - - // Heavy I/O ------------------------------------------------------- - // Additional parsing and serialization methods not implemented by - // MessageLite because they are not supported by the lite library. - - // Parse a protocol buffer from a file descriptor. If successful, the entire - // input will be consumed. - bool ParseFromFileDescriptor(int file_descriptor); - // Like ParseFromFileDescriptor(), but accepts messages that are missing - // required fields. - bool ParsePartialFromFileDescriptor(int file_descriptor); - // Parse a protocol buffer from a C++ istream. If successful, the entire - // input will be consumed. - bool ParseFromIstream(std::istream* input); - // Like ParseFromIstream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromIstream(std::istream* input); - - // Serialize the message and write it to the given file descriptor. All - // required fields must be set. - bool SerializeToFileDescriptor(int file_descriptor) const; - // Like SerializeToFileDescriptor(), but allows missing required fields. - bool SerializePartialToFileDescriptor(int file_descriptor) const; - // Serialize the message and write it to the given C++ ostream. All - // required fields must be set. - bool SerializeToOstream(std::ostream* output) const; - // Like SerializeToOstream(), but allows missing required fields. - bool SerializePartialToOstream(std::ostream* output) const; - - - // Reflection-based methods ---------------------------------------- - // These methods are pure-virtual in MessageLite, but Message provides - // reflection-based default implementations. - - virtual string GetTypeName() const; - virtual void Clear(); - virtual bool IsInitialized() const; - virtual void CheckTypeAndMergeFrom(const MessageLite& other); - virtual bool MergePartialFromCodedStream(io::CodedInputStream* input); - virtual size_t ByteSizeLong() const; - virtual void SerializeWithCachedSizes(io::CodedOutputStream* output) const; - - private: - // This is called only by the default implementation of ByteSize(), to - // update the cached size. If you override ByteSize(), you do not need - // to override this. If you do not override ByteSize(), you MUST override - // this; the default implementation will crash. - // - // The method is private because subclasses should never call it; only - // override it. Yes, C++ lets you do that. Crazy, huh? - virtual void SetCachedSize(int size) const; - - public: - - // Introspection --------------------------------------------------- - - // Typedef for backwards-compatibility. - typedef google::protobuf::Reflection Reflection; - - // Get a Descriptor for this message's type. This describes what - // fields the message contains, the types of those fields, etc. - const Descriptor* GetDescriptor() const { return GetMetadata().descriptor; } - - // Get the Reflection interface for this Message, which can be used to - // read and modify the fields of the Message dynamically (in other words, - // without knowing the message type at compile time). This object remains - // property of the Message. - // - // This method remains virtual in case a subclass does not implement - // reflection and wants to override the default behavior. - virtual const Reflection* GetReflection() const { - return GetMetadata().reflection; - } - - protected: - // Get a struct containing the metadata for the Message. Most subclasses only - // need to implement this method, rather than the GetDescriptor() and - // GetReflection() wrappers. - virtual Metadata GetMetadata() const = 0; - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Message); -}; - -namespace internal { -// Forward-declare interfaces used to implement RepeatedFieldRef. -// These are protobuf internals that users shouldn't care about. -class RepeatedFieldAccessor; -} // namespace internal - -// Forward-declare RepeatedFieldRef templates. The second type parameter is -// used for SFINAE tricks. Users should ignore it. -template -class RepeatedFieldRef; - -template -class MutableRepeatedFieldRef; - -// This interface contains methods that can be used to dynamically access -// and modify the fields of a protocol message. Their semantics are -// similar to the accessors the protocol compiler generates. -// -// To get the Reflection for a given Message, call Message::GetReflection(). -// -// This interface is separate from Message only for efficiency reasons; -// the vast majority of implementations of Message will share the same -// implementation of Reflection (GeneratedMessageReflection, -// defined in generated_message.h), and all Messages of a particular class -// should share the same Reflection object (though you should not rely on -// the latter fact). -// -// There are several ways that these methods can be used incorrectly. For -// example, any of the following conditions will lead to undefined -// results (probably assertion failures): -// - The FieldDescriptor is not a field of this message type. -// - The method called is not appropriate for the field's type. For -// each field type in FieldDescriptor::TYPE_*, there is only one -// Get*() method, one Set*() method, and one Add*() method that is -// valid for that type. It should be obvious which (except maybe -// for TYPE_BYTES, which are represented using strings in C++). -// - A Get*() or Set*() method for singular fields is called on a repeated -// field. -// - GetRepeated*(), SetRepeated*(), or Add*() is called on a non-repeated -// field. -// - The Message object passed to any method is not of the right type for -// this Reflection object (i.e. message.GetReflection() != reflection). -// -// You might wonder why there is not any abstract representation for a field -// of arbitrary type. E.g., why isn't there just a "GetField()" method that -// returns "const Field&", where "Field" is some class with accessors like -// "GetInt32Value()". The problem is that someone would have to deal with -// allocating these Field objects. For generated message classes, having to -// allocate space for an additional object to wrap every field would at least -// double the message's memory footprint, probably worse. Allocating the -// objects on-demand, on the other hand, would be expensive and prone to -// memory leaks. So, instead we ended up with this flat interface. -// -// TODO(kenton): Create a utility class which callers can use to read and -// write fields from a Reflection without paying attention to the type. -class LIBPROTOBUF_EXPORT Reflection { - public: - inline Reflection() {} - virtual ~Reflection(); - - // Get the UnknownFieldSet for the message. This contains fields which - // were seen when the Message was parsed but were not recognized according - // to the Message's definition. For proto3 protos, this method will always - // return an empty UnknownFieldSet. - virtual const UnknownFieldSet& GetUnknownFields( - const Message& message) const = 0; - // Get a mutable pointer to the UnknownFieldSet for the message. This - // contains fields which were seen when the Message was parsed but were not - // recognized according to the Message's definition. For proto3 protos, this - // method will return a valid mutable UnknownFieldSet pointer but modifying - // it won't affect the serialized bytes of the message. - virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0; - - // Estimate the amount of memory used by the message object. - virtual int SpaceUsed(const Message& message) const = 0; - - // Check if the given non-repeated field is set. - virtual bool HasField(const Message& message, - const FieldDescriptor* field) const = 0; - - // Get the number of elements of a repeated field. - virtual int FieldSize(const Message& message, - const FieldDescriptor* field) const = 0; - - // Clear the value of a field, so that HasField() returns false or - // FieldSize() returns zero. - virtual void ClearField(Message* message, - const FieldDescriptor* field) const = 0; - - // Check if the oneof is set. Returns true if any field in oneof - // is set, false otherwise. - // TODO(jieluo) - make it pure virtual after updating all - // the subclasses. - virtual bool HasOneof(const Message& /*message*/, - const OneofDescriptor* /*oneof_descriptor*/) const { - return false; - } - - virtual void ClearOneof(Message* /*message*/, - const OneofDescriptor* /*oneof_descriptor*/) const {} - - // Returns the field descriptor if the oneof is set. NULL otherwise. - // TODO(jieluo) - make it pure virtual. - virtual const FieldDescriptor* GetOneofFieldDescriptor( - const Message& /*message*/, - const OneofDescriptor* /*oneof_descriptor*/) const { - return NULL; - } - - // Removes the last element of a repeated field. - // We don't provide a way to remove any element other than the last - // because it invites inefficient use, such as O(n^2) filtering loops - // that should have been O(n). If you want to remove an element other - // than the last, the best way to do it is to re-arrange the elements - // (using Swap()) so that the one you want removed is at the end, then - // call RemoveLast(). - virtual void RemoveLast(Message* message, - const FieldDescriptor* field) const = 0; - // Removes the last element of a repeated message field, and returns the - // pointer to the caller. Caller takes ownership of the returned pointer. - virtual Message* ReleaseLast(Message* message, - const FieldDescriptor* field) const = 0; - - // Swap the complete contents of two messages. - virtual void Swap(Message* message1, Message* message2) const = 0; - - // Swap fields listed in fields vector of two messages. - virtual void SwapFields(Message* message1, - Message* message2, - const std::vector& fields) - const = 0; - - // Swap two elements of a repeated field. - virtual void SwapElements(Message* message, - const FieldDescriptor* field, - int index1, - int index2) const = 0; - - // List all fields of the message which are currently set. This includes - // extensions. Singular fields will only be listed if HasField(field) would - // return true and repeated fields will only be listed if FieldSize(field) - // would return non-zero. Fields (both normal fields and extension fields) - // will be listed ordered by field number. - virtual void ListFields( - const Message& message, - std::vector* output) const = 0; - - // Singular field getters ------------------------------------------ - // These get the value of a non-repeated field. They return the default - // value for fields that aren't set. - - virtual int32 GetInt32 (const Message& message, - const FieldDescriptor* field) const = 0; - virtual int64 GetInt64 (const Message& message, - const FieldDescriptor* field) const = 0; - virtual uint32 GetUInt32(const Message& message, - const FieldDescriptor* field) const = 0; - virtual uint64 GetUInt64(const Message& message, - const FieldDescriptor* field) const = 0; - virtual float GetFloat (const Message& message, - const FieldDescriptor* field) const = 0; - virtual double GetDouble(const Message& message, - const FieldDescriptor* field) const = 0; - virtual bool GetBool (const Message& message, - const FieldDescriptor* field) const = 0; - virtual string GetString(const Message& message, - const FieldDescriptor* field) const = 0; - virtual const EnumValueDescriptor* GetEnum( - const Message& message, const FieldDescriptor* field) const = 0; - - // GetEnumValue() returns an enum field's value as an integer rather than - // an EnumValueDescriptor*. If the integer value does not correspond to a - // known value descriptor, a new value descriptor is created. (Such a value - // will only be present when the new unknown-enum-value semantics are enabled - // for a message.) - virtual int GetEnumValue( - const Message& message, const FieldDescriptor* field) const; - - // See MutableMessage() for the meaning of the "factory" parameter. - virtual const Message& GetMessage(const Message& message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - // Get a string value without copying, if possible. - // - // GetString() necessarily returns a copy of the string. This can be - // inefficient when the string is already stored in a string object in the - // underlying message. GetStringReference() will return a reference to the - // underlying string in this case. Otherwise, it will copy the string into - // *scratch and return that. - // - // Note: It is perfectly reasonable and useful to write code like: - // str = reflection->GetStringReference(field, &str); - // This line would ensure that only one copy of the string is made - // regardless of the field's underlying representation. When initializing - // a newly-constructed string, though, it's just as fast and more readable - // to use code like: - // string str = reflection->GetString(message, field); - virtual const string& GetStringReference(const Message& message, - const FieldDescriptor* field, - string* scratch) const = 0; - - - // Singular field mutators ----------------------------------------- - // These mutate the value of a non-repeated field. - - virtual void SetInt32 (Message* message, - const FieldDescriptor* field, int32 value) const = 0; - virtual void SetInt64 (Message* message, - const FieldDescriptor* field, int64 value) const = 0; - virtual void SetUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const = 0; - virtual void SetUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const = 0; - virtual void SetFloat (Message* message, - const FieldDescriptor* field, float value) const = 0; - virtual void SetDouble(Message* message, - const FieldDescriptor* field, double value) const = 0; - virtual void SetBool (Message* message, - const FieldDescriptor* field, bool value) const = 0; - virtual void SetString(Message* message, - const FieldDescriptor* field, - const string& value) const = 0; - virtual void SetEnum (Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const = 0; - // Set an enum field's value with an integer rather than EnumValueDescriptor. - // If the value does not correspond to a known enum value, either behavior is - // undefined (for proto2 messages), or the value is accepted silently for - // messages with new unknown-enum-value semantics. - virtual void SetEnumValue(Message* message, - const FieldDescriptor* field, - int value) const; - - // Get a mutable pointer to a field with a message type. If a MessageFactory - // is provided, it will be used to construct instances of the sub-message; - // otherwise, the default factory is used. If the field is an extension that - // does not live in the same pool as the containing message's descriptor (e.g. - // it lives in an overlay pool), then a MessageFactory must be provided. - // If you have no idea what that meant, then you probably don't need to worry - // about it (don't provide a MessageFactory). WARNING: If the - // FieldDescriptor is for a compiled-in extension, then - // factory->GetPrototype(field->message_type()) MUST return an instance of - // the compiled-in class for this type, NOT DynamicMessage. - virtual Message* MutableMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - // Replaces the message specified by 'field' with the already-allocated object - // sub_message, passing ownership to the message. If the field contained a - // message, that message is deleted. If sub_message is NULL, the field is - // cleared. - virtual void SetAllocatedMessage(Message* message, - Message* sub_message, - const FieldDescriptor* field) const = 0; - // Releases the message specified by 'field' and returns the pointer, - // ReleaseMessage() will return the message the message object if it exists. - // Otherwise, it may or may not return NULL. In any case, if the return value - // is non-NULL, the caller takes ownership of the pointer. - // If the field existed (HasField() is true), then the returned pointer will - // be the same as the pointer returned by MutableMessage(). - // This function has the same effect as ClearField(). - virtual Message* ReleaseMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - - // Repeated field getters ------------------------------------------ - // These get the value of one element of a repeated field. - - virtual int32 GetRepeatedInt32 (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual int64 GetRepeatedInt64 (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual uint32 GetRepeatedUInt32(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual uint64 GetRepeatedUInt64(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual float GetRepeatedFloat (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual double GetRepeatedDouble(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual bool GetRepeatedBool (const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual string GetRepeatedString(const Message& message, - const FieldDescriptor* field, - int index) const = 0; - virtual const EnumValueDescriptor* GetRepeatedEnum( - const Message& message, - const FieldDescriptor* field, int index) const = 0; - // GetRepeatedEnumValue() returns an enum field's value as an integer rather - // than an EnumValueDescriptor*. If the integer value does not correspond to a - // known value descriptor, a new value descriptor is created. (Such a value - // will only be present when the new unknown-enum-value semantics are enabled - // for a message.) - virtual int GetRepeatedEnumValue( - const Message& message, - const FieldDescriptor* field, int index) const; - virtual const Message& GetRepeatedMessage( - const Message& message, - const FieldDescriptor* field, int index) const = 0; - - // See GetStringReference(), above. - virtual const string& GetRepeatedStringReference( - const Message& message, const FieldDescriptor* field, - int index, string* scratch) const = 0; - - - // Repeated field mutators ----------------------------------------- - // These mutate the value of one element of a repeated field. - - virtual void SetRepeatedInt32 (Message* message, - const FieldDescriptor* field, - int index, int32 value) const = 0; - virtual void SetRepeatedInt64 (Message* message, - const FieldDescriptor* field, - int index, int64 value) const = 0; - virtual void SetRepeatedUInt32(Message* message, - const FieldDescriptor* field, - int index, uint32 value) const = 0; - virtual void SetRepeatedUInt64(Message* message, - const FieldDescriptor* field, - int index, uint64 value) const = 0; - virtual void SetRepeatedFloat (Message* message, - const FieldDescriptor* field, - int index, float value) const = 0; - virtual void SetRepeatedDouble(Message* message, - const FieldDescriptor* field, - int index, double value) const = 0; - virtual void SetRepeatedBool (Message* message, - const FieldDescriptor* field, - int index, bool value) const = 0; - virtual void SetRepeatedString(Message* message, - const FieldDescriptor* field, - int index, const string& value) const = 0; - virtual void SetRepeatedEnum(Message* message, - const FieldDescriptor* field, int index, - const EnumValueDescriptor* value) const = 0; - // Set an enum field's value with an integer rather than EnumValueDescriptor. - // If the value does not correspond to a known enum value, either behavior is - // undefined (for proto2 messages), or the value is accepted silently for - // messages with new unknown-enum-value semantics. - virtual void SetRepeatedEnumValue(Message* message, - const FieldDescriptor* field, int index, - int value) const; - // Get a mutable pointer to an element of a repeated field with a message - // type. - virtual Message* MutableRepeatedMessage( - Message* message, const FieldDescriptor* field, int index) const = 0; - - - // Repeated field adders ------------------------------------------- - // These add an element to a repeated field. - - virtual void AddInt32 (Message* message, - const FieldDescriptor* field, int32 value) const = 0; - virtual void AddInt64 (Message* message, - const FieldDescriptor* field, int64 value) const = 0; - virtual void AddUInt32(Message* message, - const FieldDescriptor* field, uint32 value) const = 0; - virtual void AddUInt64(Message* message, - const FieldDescriptor* field, uint64 value) const = 0; - virtual void AddFloat (Message* message, - const FieldDescriptor* field, float value) const = 0; - virtual void AddDouble(Message* message, - const FieldDescriptor* field, double value) const = 0; - virtual void AddBool (Message* message, - const FieldDescriptor* field, bool value) const = 0; - virtual void AddString(Message* message, - const FieldDescriptor* field, - const string& value) const = 0; - virtual void AddEnum (Message* message, - const FieldDescriptor* field, - const EnumValueDescriptor* value) const = 0; - // Set an enum field's value with an integer rather than EnumValueDescriptor. - // If the value does not correspond to a known enum value, either behavior is - // undefined (for proto2 messages), or the value is accepted silently for - // messages with new unknown-enum-value semantics. - virtual void AddEnumValue(Message* message, - const FieldDescriptor* field, - int value) const; - // See MutableMessage() for comments on the "factory" parameter. - virtual Message* AddMessage(Message* message, - const FieldDescriptor* field, - MessageFactory* factory = NULL) const = 0; - - // Appends an already-allocated object 'new_entry' to the repeated field - // specifyed by 'field' passing ownership to the message. - // TODO(tmarek): Make virtual after all subclasses have been - // updated. - virtual void AddAllocatedMessage(Message* /* message */, - const FieldDescriptor* /*field */, - Message* /* new_entry */) const {} - - - // Get a RepeatedFieldRef object that can be used to read the underlying - // repeated field. The type parameter T must be set according to the - // field's cpp type. The following table shows the mapping from cpp type - // to acceptable T. - // - // field->cpp_type() T - // CPPTYPE_INT32 int32 - // CPPTYPE_UINT32 uint32 - // CPPTYPE_INT64 int64 - // CPPTYPE_UINT64 uint64 - // CPPTYPE_DOUBLE double - // CPPTYPE_FLOAT float - // CPPTYPE_BOOL bool - // CPPTYPE_ENUM generated enum type or int32 - // CPPTYPE_STRING string - // CPPTYPE_MESSAGE generated message type or google::protobuf::Message - // - // A RepeatedFieldRef object can be copied and the resulted object will point - // to the same repeated field in the same message. The object can be used as - // long as the message is not destroyed. - // - // Note that to use this method users need to include the header file - // "google/protobuf/reflection.h" (which defines the RepeatedFieldRef - // class templates). - template - RepeatedFieldRef GetRepeatedFieldRef( - const Message& message, const FieldDescriptor* field) const; - - // Like GetRepeatedFieldRef() but return an object that can also be used - // manipulate the underlying repeated field. - template - MutableRepeatedFieldRef GetMutableRepeatedFieldRef( - Message* message, const FieldDescriptor* field) const; - - // DEPRECATED. Please use Get(Mutable)RepeatedFieldRef() for repeated field - // access. The following repeated field accesors will be removed in the - // future. - // - // Repeated field accessors ------------------------------------------------- - // The methods above, e.g. GetRepeatedInt32(msg, fd, index), provide singular - // access to the data in a RepeatedField. The methods below provide aggregate - // access by exposing the RepeatedField object itself with the Message. - // Applying these templates to inappropriate types will lead to an undefined - // reference at link time (e.g. GetRepeatedField<***double>), or possibly a - // template matching error at compile time (e.g. GetRepeatedPtrField). - // - // Usage example: my_doubs = refl->GetRepeatedField(msg, fd); - - // DEPRECATED. Please use GetRepeatedFieldRef(). - // - // for T = Cord and all protobuf scalar types except enums. - template - const RepeatedField& GetRepeatedField( - const Message&, const FieldDescriptor*) const; - - // DEPRECATED. Please use GetMutableRepeatedFieldRef(). - // - // for T = Cord and all protobuf scalar types except enums. - template - RepeatedField* MutableRepeatedField( - Message*, const FieldDescriptor*) const; - - // DEPRECATED. Please use GetRepeatedFieldRef(). - // - // for T = string, google::protobuf::internal::StringPieceField - // google::protobuf::Message & descendants. - template - const RepeatedPtrField& GetRepeatedPtrField( - const Message&, const FieldDescriptor*) const; - - // DEPRECATED. Please use GetMutableRepeatedFieldRef(). - // - // for T = string, google::protobuf::internal::StringPieceField - // google::protobuf::Message & descendants. - template - RepeatedPtrField* MutableRepeatedPtrField( - Message*, const FieldDescriptor*) const; - - // Extensions ---------------------------------------------------------------- - - // Try to find an extension of this message type by fully-qualified field - // name. Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindKnownExtensionByName( - const string& name) const = 0; - - // Try to find an extension of this message type by field number. - // Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindKnownExtensionByNumber( - int number) const = 0; - - // Feature Flags ------------------------------------------------------------- - - // Does this message support storing arbitrary integer values in enum fields? - // If |true|, GetEnumValue/SetEnumValue and associated repeated-field versions - // take arbitrary integer values, and the legacy GetEnum() getter will - // dynamically create an EnumValueDescriptor for any integer value without - // one. If |false|, setting an unknown enum value via the integer-based - // setters results in undefined behavior (in practice, GOOGLE_DCHECK-fails). - // - // Generic code that uses reflection to handle messages with enum fields - // should check this flag before using the integer-based setter, and either - // downgrade to a compatible value or use the UnknownFieldSet if not. For - // example: - // - // int new_value = GetValueFromApplicationLogic(); - // if (reflection->SupportsUnknownEnumValues()) { - // reflection->SetEnumValue(message, field, new_value); - // } else { - // if (field_descriptor->enum_type()-> - // FindValueByNumver(new_value) != NULL) { - // reflection->SetEnumValue(message, field, new_value); - // } else if (emit_unknown_enum_values) { - // reflection->MutableUnknownFields(message)->AddVarint( - // field->number(), - // new_value); - // } else { - // // convert value to a compatible/default value. - // new_value = CompatibleDowngrade(new_value); - // reflection->SetEnumValue(message, field, new_value); - // } - // } - virtual bool SupportsUnknownEnumValues() const { return false; } - - // Returns the MessageFactory associated with this message. This can be - // useful for determining if a message is a generated message or not, for - // example: - // - // if (message->GetReflection()->GetMessageFactory() == - // google::protobuf::MessageFactory::generated_factory()) { - // // This is a generated message. - // } - // - // It can also be used to create more messages of this type, though - // Message::New() is an easier way to accomplish this. - virtual MessageFactory* GetMessageFactory() const; - - // --------------------------------------------------------------------------- - - protected: - // Obtain a pointer to a Repeated Field Structure and do some type checking: - // on field->cpp_type(), - // on field->field_option().ctype() (if ctype >= 0) - // of field->message_type() (if message_type != NULL). - // We use 2 routine rather than 4 (const vs mutable) x (scalar vs pointer). - virtual void* MutableRawRepeatedField( - Message* message, const FieldDescriptor* field, FieldDescriptor::CppType, - int ctype, const Descriptor* message_type) const = 0; - - // TODO(jieluo) - make it pure virtual after updating all the subclasses. - virtual const void* GetRawRepeatedField( - const Message& message, const FieldDescriptor* field, - FieldDescriptor::CppType cpptype, int ctype, - const Descriptor* message_type) const { - return MutableRawRepeatedField( - const_cast(&message), field, cpptype, ctype, message_type); - } - - // The following methods are used to implement (Mutable)RepeatedFieldRef. - // A Ref object will store a raw pointer to the repeated field data (obtained - // from RepeatedFieldData()) and a pointer to a Accessor (obtained from - // RepeatedFieldAccessor) which will be used to access the raw data. - // - // TODO(xiaofeng): Make these methods pure-virtual. - - // Returns a raw pointer to the repeated field - // - // "cpp_type" and "message_type" are decuded from the type parameter T passed - // to Get(Mutable)RepeatedFieldRef. If T is a generated message type, - // "message_type" should be set to its descriptor. Otherwise "message_type" - // should be set to NULL. Implementations of this method should check whether - // "cpp_type"/"message_type" is consistent with the actual type of the field. - // We use 1 routine rather than 2 (const vs mutable) because it is protected - // and it doesn't change the message. - virtual void* RepeatedFieldData( - Message* message, const FieldDescriptor* field, - FieldDescriptor::CppType cpp_type, - const Descriptor* message_type) const; - - // The returned pointer should point to a singleton instance which implements - // the RepeatedFieldAccessor interface. - virtual const internal::RepeatedFieldAccessor* RepeatedFieldAccessor( - const FieldDescriptor* field) const; - - private: - template - friend class RepeatedFieldRef; - template - friend class MutableRepeatedFieldRef; - friend class ::google::protobuf::python::MapReflectionFriend; - - // Special version for specialized implementations of string. We can't call - // MutableRawRepeatedField directly here because we don't have access to - // FieldOptions::* which are defined in descriptor.pb.h. Including that - // file here is not possible because it would cause a circular include cycle. - // We use 1 routine rather than 2 (const vs mutable) because it is private - // and mutable a repeated string field doesn't change the message. - void* MutableRawRepeatedString( - Message* message, const FieldDescriptor* field, bool is_string) const; - - friend class MapReflectionTester; - // TODO(jieluo) - make the map APIs pure virtual after updating - // all the subclasses. - // Returns true if key is in map. Returns false if key is not in map field. - virtual bool ContainsMapKey(const Message& /* message*/, - const FieldDescriptor* /* field */, - const MapKey& /* key */) const { - return false; - } - - // If key is in map field: Saves the value pointer to val and returns - // false. If key in not in map field: Insert the key into map, saves - // value pointer to val and retuns true. - virtual bool InsertOrLookupMapValue(Message* /* message */, - const FieldDescriptor* /* field */, - const MapKey& /* key */, - MapValueRef* /* val */) const { - return false; - } - - // Delete and returns true if key is in the map field. Returns false - // otherwise. - virtual bool DeleteMapValue(Message* /* mesage */, - const FieldDescriptor* /* field */, - const MapKey& /* key */) const { - return false; - } - - // Returns a MapIterator referring to the first element in the map field. - // If the map field is empty, this function returns the same as - // reflection::MapEnd. Mutation to the field may invalidate the iterator. - virtual MapIterator MapBegin( - Message* message, - const FieldDescriptor* field) const; - - // Returns a MapIterator referring to the theoretical element that would - // follow the last element in the map field. It does not point to any - // real element. Mutation to the field may invalidate the iterator. - virtual MapIterator MapEnd( - Message* message, - const FieldDescriptor* field) const; - - // Get the number of pair of a map field. The result may be - // different from FieldSize which can have duplicate keys. - virtual int MapSize(const Message& /* message */, - const FieldDescriptor* /* field */) const { - return 0; - } - - // Help method for MapIterator. - friend class MapIterator; - virtual internal::MapFieldBase* MapData( - Message* /* message */, const FieldDescriptor* /* field */) const { - return NULL; - } - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Reflection); -}; - -// Abstract interface for a factory for message objects. -class LIBPROTOBUF_EXPORT MessageFactory { - public: - inline MessageFactory() {} - virtual ~MessageFactory(); - - // Given a Descriptor, gets or constructs the default (prototype) Message - // of that type. You can then call that message's New() method to construct - // a mutable message of that type. - // - // Calling this method twice with the same Descriptor returns the same - // object. The returned object remains property of the factory. Also, any - // objects created by calling the prototype's New() method share some data - // with the prototype, so these must be destroyed before the MessageFactory - // is destroyed. - // - // The given descriptor must outlive the returned message, and hence must - // outlive the MessageFactory. - // - // Some implementations do not support all types. GetPrototype() will - // return NULL if the descriptor passed in is not supported. - // - // This method may or may not be thread-safe depending on the implementation. - // Each implementation should document its own degree thread-safety. - virtual const Message* GetPrototype(const Descriptor* type) = 0; - - // Gets a MessageFactory which supports all generated, compiled-in messages. - // In other words, for any compiled-in type FooMessage, the following is true: - // MessageFactory::generated_factory()->GetPrototype( - // FooMessage::descriptor()) == FooMessage::default_instance() - // This factory supports all types which are found in - // DescriptorPool::generated_pool(). If given a descriptor from any other - // pool, GetPrototype() will return NULL. (You can also check if a - // descriptor is for a generated message by checking if - // descriptor->file()->pool() == DescriptorPool::generated_pool().) - // - // This factory is 100% thread-safe; calling GetPrototype() does not modify - // any shared data. - // - // This factory is a singleton. The caller must not delete the object. - static MessageFactory* generated_factory(); - - // For internal use only: Registers a .proto file at static initialization - // time, to be placed in generated_factory. The first time GetPrototype() - // is called with a descriptor from this file, |register_messages| will be - // called, with the file name as the parameter. It must call - // InternalRegisterGeneratedMessage() (below) to register each message type - // in the file. This strange mechanism is necessary because descriptors are - // built lazily, so we can't register types by their descriptor until we - // know that the descriptor exists. |filename| must be a permanent string. - static void InternalRegisterGeneratedFile( - const char* filename, void (*register_messages)(const string&)); - - // For internal use only: Registers a message type. Called only by the - // functions which are registered with InternalRegisterGeneratedFile(), - // above. - static void InternalRegisterGeneratedMessage(const Descriptor* descriptor, - const Message* prototype); - - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFactory); -}; - -#define DECLARE_GET_REPEATED_FIELD(TYPE) \ -template<> \ -LIBPROTOBUF_EXPORT \ -const RepeatedField& Reflection::GetRepeatedField( \ - const Message& message, const FieldDescriptor* field) const; \ - \ -template<> \ -LIBPROTOBUF_EXPORT \ -RepeatedField* Reflection::MutableRepeatedField( \ - Message* message, const FieldDescriptor* field) const; - -DECLARE_GET_REPEATED_FIELD(int32) -DECLARE_GET_REPEATED_FIELD(int64) -DECLARE_GET_REPEATED_FIELD(uint32) -DECLARE_GET_REPEATED_FIELD(uint64) -DECLARE_GET_REPEATED_FIELD(float) -DECLARE_GET_REPEATED_FIELD(double) -DECLARE_GET_REPEATED_FIELD(bool) - -#undef DECLARE_GET_REPEATED_FIELD - -// ============================================================================= -// Implementation details for {Get,Mutable}RawRepeatedPtrField. We provide -// specializations for , and and handle -// everything else with the default template which will match any type having -// a method with signature "static const google::protobuf::Descriptor* descriptor()". -// Such a type presumably is a descendant of google::protobuf::Message. - -template<> -inline const RepeatedPtrField& Reflection::GetRepeatedPtrField( - const Message& message, const FieldDescriptor* field) const { - return *static_cast* >( - MutableRawRepeatedString(const_cast(&message), field, true)); -} - -template<> -inline RepeatedPtrField* Reflection::MutableRepeatedPtrField( - Message* message, const FieldDescriptor* field) const { - return static_cast* >( - MutableRawRepeatedString(message, field, true)); -} - - -// ----- - -template<> -inline const RepeatedPtrField& Reflection::GetRepeatedPtrField( - const Message& message, const FieldDescriptor* field) const { - return *static_cast* >( - GetRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE, - -1, NULL)); -} - -template<> -inline RepeatedPtrField* Reflection::MutableRepeatedPtrField( - Message* message, const FieldDescriptor* field) const { - return static_cast* >( - MutableRawRepeatedField(message, field, - FieldDescriptor::CPPTYPE_MESSAGE, -1, - NULL)); -} - -template -inline const RepeatedPtrField& Reflection::GetRepeatedPtrField( - const Message& message, const FieldDescriptor* field) const { - return *static_cast* >( - GetRawRepeatedField(message, field, FieldDescriptor::CPPTYPE_MESSAGE, - -1, PB::default_instance().GetDescriptor())); -} - -template -inline RepeatedPtrField* Reflection::MutableRepeatedPtrField( - Message* message, const FieldDescriptor* field) const { - return static_cast* >( - MutableRawRepeatedField(message, field, - FieldDescriptor::CPPTYPE_MESSAGE, -1, - PB::default_instance().GetDescriptor())); -} -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MESSAGE_H__ diff --git a/app/src/main/cpp/google/protobuf/message_lite.h b/app/src/main/cpp/google/protobuf/message_lite.h deleted file mode 100644 index d3c3b1f..0000000 --- a/app/src/main/cpp/google/protobuf/message_lite.h +++ /dev/null @@ -1,297 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Authors: wink@google.com (Wink Saville), -// kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Defines MessageLite, the abstract interface implemented by all (lite -// and non-lite) protocol message objects. - -#ifndef GOOGLE_PROTOBUF_MESSAGE_LITE_H__ -#define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ - -#include - - -namespace google { -namespace protobuf { - class Arena; -namespace io { - class CodedInputStream; - class CodedOutputStream; - class ZeroCopyInputStream; - class ZeroCopyOutputStream; -} -namespace internal { - class WireFormatLite; -} - -// Interface to light weight protocol messages. -// -// This interface is implemented by all protocol message objects. Non-lite -// messages additionally implement the Message interface, which is a -// subclass of MessageLite. Use MessageLite instead when you only need -// the subset of features which it supports -- namely, nothing that uses -// descriptors or reflection. You can instruct the protocol compiler -// to generate classes which implement only MessageLite, not the full -// Message interface, by adding the following line to the .proto file: -// -// option optimize_for = LITE_RUNTIME; -// -// This is particularly useful on resource-constrained systems where -// the full protocol buffers runtime library is too big. -// -// Note that on non-constrained systems (e.g. servers) when you need -// to link in lots of protocol definitions, a better way to reduce -// total code footprint is to use optimize_for = CODE_SIZE. This -// will make the generated code smaller while still supporting all the -// same features (at the expense of speed). optimize_for = LITE_RUNTIME -// is best when you only have a small number of message types linked -// into your binary, in which case the size of the protocol buffers -// runtime itself is the biggest problem. -class LIBPROTOBUF_EXPORT MessageLite { - public: - inline MessageLite() {} - virtual ~MessageLite() {} - - // Basic Operations ------------------------------------------------ - - // Get the name of this message type, e.g. "foo.bar.BazProto". - virtual string GetTypeName() const = 0; - - // Construct a new instance of the same type. Ownership is passed to the - // caller. - virtual MessageLite* New() const = 0; - - // Construct a new instance on the arena. Ownership is passed to the caller - // if arena is a NULL. Default implementation for backwards compatibility. - virtual MessageLite* New(::google::protobuf::Arena* arena) const; - - // Get the arena, if any, associated with this message. Virtual method - // required for generic operations but most arena-related operations should - // use the GetArenaNoVirtual() generated-code method. Default implementation - // to reduce code size by avoiding the need for per-type implementations when - // types do not implement arena support. - virtual ::google::protobuf::Arena* GetArena() const { return NULL; } - - // Get a pointer that may be equal to this message's arena, or may not be. If - // the value returned by this method is equal to some arena pointer, then this - // message is on that arena; however, if this message is on some arena, this - // method may or may not return that arena's pointer. As a tradeoff, this - // method may be more efficient than GetArena(). The intent is to allow - // underlying representations that use e.g. tagged pointers to sometimes store - // the arena pointer directly, and sometimes in a more indirect way, and allow - // a fastpath comparison against the arena pointer when it's easy to obtain. - virtual void* GetMaybeArenaPointer() const { return GetArena(); } - - // Clear all fields of the message and set them to their default values. - // Clear() avoids freeing memory, assuming that any memory allocated - // to hold parts of the message will be needed again to hold the next - // message. If you actually want to free the memory used by a Message, - // you must delete it. - virtual void Clear() = 0; - - // Quickly check if all required fields have values set. - virtual bool IsInitialized() const = 0; - - // This is not implemented for Lite messages -- it just returns "(cannot - // determine missing fields for lite message)". However, it is implemented - // for full messages. See message.h. - virtual string InitializationErrorString() const; - - // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, - // results are undefined (probably crash). - virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; - - // Parsing --------------------------------------------------------- - // Methods for parsing in protocol buffer format. Most of these are - // just simple wrappers around MergeFromCodedStream(). Clear() will be called - // before merging the input. - - // Fill the message with a protocol buffer parsed from the given input stream. - // Returns false on a read error or if the input is in the wrong format. A - // successful return does not indicate the entire input is consumed, ensure - // you call ConsumedEntireMessage() to check that if applicable. - bool ParseFromCodedStream(io::CodedInputStream* input); - // Like ParseFromCodedStream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromCodedStream(io::CodedInputStream* input); - // Read a protocol buffer from the given zero-copy input stream. If - // successful, the entire input will be consumed. - bool ParseFromZeroCopyStream(io::ZeroCopyInputStream* input); - // Like ParseFromZeroCopyStream(), but accepts messages that are missing - // required fields. - bool ParsePartialFromZeroCopyStream(io::ZeroCopyInputStream* input); - // Read a protocol buffer from the given zero-copy input stream, expecting - // the message to be exactly "size" bytes long. If successful, exactly - // this many bytes will have been consumed from the input. - bool ParseFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, int size); - // Like ParseFromBoundedZeroCopyStream(), but accepts messages that are - // missing required fields. - bool ParsePartialFromBoundedZeroCopyStream(io::ZeroCopyInputStream* input, - int size); - // Parses a protocol buffer contained in a string. Returns true on success. - // This function takes a string in the (non-human-readable) binary wire - // format, matching the encoding output by MessageLite::SerializeToString(). - // If you'd like to convert a human-readable string into a protocol buffer - // object, see google::protobuf::TextFormat::ParseFromString(). - bool ParseFromString(const string& data); - // Like ParseFromString(), but accepts messages that are missing - // required fields. - bool ParsePartialFromString(const string& data); - // Parse a protocol buffer contained in an array of bytes. - bool ParseFromArray(const void* data, int size); - // Like ParseFromArray(), but accepts messages that are missing - // required fields. - bool ParsePartialFromArray(const void* data, int size); - - - // Reads a protocol buffer from the stream and merges it into this - // Message. Singular fields read from the input overwrite what is - // already in the Message and repeated fields are appended to those - // already present. - // - // It is the responsibility of the caller to call input->LastTagWas() - // (for groups) or input->ConsumedEntireMessage() (for non-groups) after - // this returns to verify that the message's end was delimited correctly. - // - // ParsefromCodedStream() is implemented as Clear() followed by - // MergeFromCodedStream(). - bool MergeFromCodedStream(io::CodedInputStream* input); - - // Like MergeFromCodedStream(), but succeeds even if required fields are - // missing in the input. - // - // MergeFromCodedStream() is just implemented as MergePartialFromCodedStream() - // followed by IsInitialized(). - virtual bool MergePartialFromCodedStream(io::CodedInputStream* input) = 0; - - - // Serialization --------------------------------------------------- - // Methods for serializing in protocol buffer format. Most of these - // are just simple wrappers around ByteSize() and SerializeWithCachedSizes(). - - // Write a protocol buffer of this message to the given output. Returns - // false on a write error. If the message is missing required fields, - // this may GOOGLE_CHECK-fail. - bool SerializeToCodedStream(io::CodedOutputStream* output) const; - // Like SerializeToCodedStream(), but allows missing required fields. - bool SerializePartialToCodedStream(io::CodedOutputStream* output) const; - // Write the message to the given zero-copy output stream. All required - // fields must be set. - bool SerializeToZeroCopyStream(io::ZeroCopyOutputStream* output) const; - // Like SerializeToZeroCopyStream(), but allows missing required fields. - bool SerializePartialToZeroCopyStream(io::ZeroCopyOutputStream* output) const; - // Serialize the message and store it in the given string. All required - // fields must be set. - bool SerializeToString(string* output) const; - // Like SerializeToString(), but allows missing required fields. - bool SerializePartialToString(string* output) const; - // Serialize the message and store it in the given byte array. All required - // fields must be set. - bool SerializeToArray(void* data, int size) const; - // Like SerializeToArray(), but allows missing required fields. - bool SerializePartialToArray(void* data, int size) const; - - // Make a string encoding the message. Is equivalent to calling - // SerializeToString() on a string and using that. Returns the empty - // string if SerializeToString() would have returned an error. - // Note: If you intend to generate many such strings, you may - // reduce heap fragmentation by instead re-using the same string - // object with calls to SerializeToString(). - string SerializeAsString() const; - // Like SerializeAsString(), but allows missing required fields. - string SerializePartialAsString() const; - - // Like SerializeToString(), but appends to the data to the string's existing - // contents. All required fields must be set. - bool AppendToString(string* output) const; - // Like AppendToString(), but allows missing required fields. - bool AppendPartialToString(string* output) const; - - // Computes the serialized size of the message. This recursively calls - // ByteSize() on all embedded messages. Subclasses MUST override either - // ByteSize() or ByteSizeLong() (overriding both is fine). - // - // ByteSize() is generally linear in the number of fields defined for the - // proto. - virtual int ByteSize() const { return ByteSizeLong(); } - virtual size_t ByteSizeLong() const; - - // Serializes the message without recomputing the size. The message must - // not have changed since the last call to ByteSize(); if it has, the results - // are undefined. - virtual void SerializeWithCachedSizes( - io::CodedOutputStream* output) const = 0; - - // A version of SerializeWithCachedSizesToArray, below, that does - // not guarantee deterministic serialization. - virtual uint8* SerializeWithCachedSizesToArray(uint8* target) const { - return InternalSerializeWithCachedSizesToArray(false, target); - } - - // Returns the result of the last call to ByteSize(). An embedded message's - // size is needed both to serialize it (because embedded messages are - // length-delimited) and to compute the outer message's size. Caching - // the size avoids computing it multiple times. - // - // ByteSize() does not automatically use the cached size when available - // because this would require invalidating it every time the message was - // modified, which would be too hard and expensive. (E.g. if a deeply-nested - // sub-message is changed, all of its parents' cached sizes would need to be - // invalidated, which is too much work for an otherwise inlined setter - // method.) - virtual int GetCachedSize() const = 0; - - // Functions below here are not part of the public interface. It isn't - // enforced, but they should be treated as private, and will be private - // at some future time. Unfortunately the implementation of the "friend" - // keyword in GCC is broken at the moment, but we expect it will be fixed. - - // Like SerializeWithCachedSizes, but writes directly to *target, returning - // a pointer to the byte immediately after the last byte written. "target" - // must point at a byte array of at least ByteSize() bytes. If deterministic - // is true then we use deterministic serialization, e.g., map keys are sorted. - // FOR INTERNAL USE ONLY! - virtual uint8* InternalSerializeWithCachedSizesToArray(bool deterministic, - uint8* target) const; - - private: - friend class internal::WireFormatLite; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_MESSAGE_LITE_H__ diff --git a/app/src/main/cpp/google/protobuf/metadata.h b/app/src/main/cpp/google/protobuf/metadata.h deleted file mode 100644 index 6e3eef6..0000000 --- a/app/src/main/cpp/google/protobuf/metadata.h +++ /dev/null @@ -1,159 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This header file defines an internal class that encapsulates internal message -// metadata (Unknown-field set, Arena pointer, ...) and allows its -// representation to be made more space-efficient via various optimizations. -// -// Note that this is distinct from google::protobuf::Metadata, which encapsulates -// Descriptor and Reflection pointers. - -#ifndef GOOGLE_PROTOBUF_METADATA_H__ -#define GOOGLE_PROTOBUF_METADATA_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// This is the representation for messages that support arena allocation. It -// uses a tagged pointer to either store the Arena pointer, if there are no -// unknown fields, or a pointer to a block of memory with both the Arena pointer -// and the UnknownFieldSet, if there are unknown fields. This optimization -// allows for "zero-overhead" storage of the Arena pointer, relative to the -// above baseline implementation. -// -// The tagged pointer uses the LSB to disambiguate cases, and uses bit 0 == 0 to -// indicate an arena pointer and bit 0 == 1 to indicate a UFS+Arena-container -// pointer. -class LIBPROTOBUF_EXPORT InternalMetadataWithArena { - public: - InternalMetadataWithArena() : ptr_(NULL) {} - explicit InternalMetadataWithArena(Arena* arena) - : ptr_ (arena) {} - - ~InternalMetadataWithArena() { - if (have_unknown_fields() && arena() == NULL) { - delete PtrValue(); - } - ptr_ = NULL; - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE const UnknownFieldSet& unknown_fields() const { - if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { - return PtrValue()->unknown_fields_; - } else { - return *UnknownFieldSet::default_instance(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE UnknownFieldSet* mutable_unknown_fields() { - if (GOOGLE_PREDICT_TRUE(have_unknown_fields())) { - return &PtrValue()->unknown_fields_; - } else { - return mutable_unknown_fields_slow(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE Arena* arena() const { - if (GOOGLE_PREDICT_FALSE(have_unknown_fields())) { - return PtrValue()->arena_; - } else { - return PtrValue(); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE bool have_unknown_fields() const { - return PtrTag() == kTagContainer; - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(InternalMetadataWithArena* other) { - // Semantics here are that we swap only the unknown fields, not the arena - // pointer. We cannot simply swap ptr_ with other->ptr_ because we need to - // maintain our own arena ptr. Also, our ptr_ and other's ptr_ may be in - // different states (direct arena pointer vs. container with UFS) so we - // cannot simply swap ptr_ and then restore the arena pointers. We reuse - // UFS's swap implementation instead. - if (have_unknown_fields() || other->have_unknown_fields()) { - mutable_unknown_fields()->Swap(other->mutable_unknown_fields()); - } - } - - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* raw_arena_ptr() const { - return ptr_; - } - - private: - void* ptr_; - - // Tagged pointer implementation. - enum { - // ptr_ is an Arena*. - kTagArena = 0, - // ptr_ is a Container*. - kTagContainer = 1, - }; - static const intptr_t kPtrTagMask = 1; - static const intptr_t kPtrValueMask = ~kPtrTagMask; - - // Accessors for pointer tag and pointer value. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE int PtrTag() const { - return reinterpret_cast(ptr_) & kPtrTagMask; - } - - template T* PtrValue() const { - return reinterpret_cast( - reinterpret_cast(ptr_) & kPtrValueMask); - } - - // If ptr_'s tag is kTagContainer, it points to an instance of this struct. - struct Container { - UnknownFieldSet unknown_fields_; - Arena* arena_; - }; - - GOOGLE_ATTRIBUTE_NOINLINE UnknownFieldSet* mutable_unknown_fields_slow() { - Arena* my_arena = arena(); - Container* container = Arena::Create(my_arena); - ptr_ = reinterpret_cast( - reinterpret_cast(container) | kTagContainer); - container->arena_ = my_arena; - return &(container->unknown_fields_); - } -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_METADATA_H__ diff --git a/app/src/main/cpp/google/protobuf/reflection.h b/app/src/main/cpp/google/protobuf/reflection.h deleted file mode 100644 index d5a6653..0000000 --- a/app/src/main/cpp/google/protobuf/reflection.h +++ /dev/null @@ -1,613 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This header defines the RepeatedFieldRef class template used to access -// repeated fields with protobuf reflection API. -#ifndef GOOGLE_PROTOBUF_REFLECTION_H__ -#define GOOGLE_PROTOBUF_REFLECTION_H__ - -#include -#ifndef _SHARED_PTR_H -#include -#endif - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { -template -struct RefTypeTraits; -} // namespace internal - -template -RepeatedFieldRef Reflection::GetRepeatedFieldRef( - const Message& message, const FieldDescriptor* field) const { - return RepeatedFieldRef(message, field); -} - -template -MutableRepeatedFieldRef Reflection::GetMutableRepeatedFieldRef( - Message* message, const FieldDescriptor* field) const { - return MutableRepeatedFieldRef(message, field); -} - -// RepeatedFieldRef definition for non-message types. -template -class RepeatedFieldRef< - T, typename internal::enable_if::value>::type> { - typedef typename internal::RefTypeTraits::iterator IteratorType; - typedef typename internal::RefTypeTraits::AccessorType AccessorType; - - public: - bool empty() const { - return accessor_->IsEmpty(data_); - } - int size() const { - return accessor_->Size(data_); - } - T Get(int index) const { - return accessor_->template Get(data_, index); - } - - typedef IteratorType iterator; - typedef IteratorType const_iterator; - typedef T value_type; - typedef T& reference; - typedef const T& const_reference; - typedef int size_type; - typedef ptrdiff_t difference_type; - - iterator begin() const { - return iterator(data_, accessor_, true); - } - iterator end() const { - return iterator(data_, accessor_, false); - } - - private: - friend class Reflection; - RepeatedFieldRef( - const Message& message, - const FieldDescriptor* field) { - const Reflection* reflection = message.GetReflection(); - data_ = reflection->RepeatedFieldData( - const_cast(&message), field, - internal::RefTypeTraits::cpp_type, NULL); - accessor_ = reflection->RepeatedFieldAccessor(field); - } - - const void* data_; - const AccessorType* accessor_; -}; - -// MutableRepeatedFieldRef definition for non-message types. -template -class MutableRepeatedFieldRef< - T, typename internal::enable_if::value>::type> { - typedef typename internal::RefTypeTraits::AccessorType AccessorType; - - public: - bool empty() const { - return accessor_->IsEmpty(data_); - } - int size() const { - return accessor_->Size(data_); - } - T Get(int index) const { - return accessor_->template Get(data_, index); - } - - void Set(int index, const T& value) const { - accessor_->template Set(data_, index, value); - } - void Add(const T& value) const { - accessor_->template Add(data_, value); - } - void RemoveLast() const { - accessor_->RemoveLast(data_); - } - void SwapElements(int index1, int index2) const { - accessor_->SwapElements(data_, index1, index2); - } - void Clear() const { - accessor_->Clear(data_); - } - - void Swap(const MutableRepeatedFieldRef& other) const { - accessor_->Swap(data_, other.accessor_, other.data_); - } - - template - void MergeFrom(const Container& container) const { - typedef typename Container::const_iterator Iterator; - for (Iterator it = container.begin(); it != container.end(); ++it) { - Add(*it); - } - } - template - void CopyFrom(const Container& container) const { - Clear(); - MergeFrom(container); - } - - private: - friend class Reflection; - MutableRepeatedFieldRef( - Message* message, - const FieldDescriptor* field) { - const Reflection* reflection = message->GetReflection(); - data_ = reflection->RepeatedFieldData( - message, field, internal::RefTypeTraits::cpp_type, NULL); - accessor_ = reflection->RepeatedFieldAccessor(field); - } - - void* data_; - const AccessorType* accessor_; -}; - -// RepeatedFieldRef definition for message types. -template -class RepeatedFieldRef< - T, typename internal::enable_if::value>::type> { - typedef typename internal::RefTypeTraits::iterator IteratorType; - typedef typename internal::RefTypeTraits::AccessorType AccessorType; - - public: - bool empty() const { - return accessor_->IsEmpty(data_); - } - int size() const { - return accessor_->Size(data_); - } - // This method returns a reference to the underlying message object if it - // exists. If a message object doesn't exist (e.g., data stored in serialized - // form), scratch_space will be filled with the data and a reference to it - // will be returned. - // - // Example: - // RepeatedFieldRef h = ... - // unique_ptr scratch_space(h.NewMessage()); - // const Message& item = h.Get(index, scratch_space.get()); - const T& Get(int index, T* scratch_space) const { - return *static_cast(accessor_->Get(data_, index, scratch_space)); - } - // Create a new message of the same type as the messages stored in this - // repeated field. Caller takes ownership of the returned object. - T* NewMessage() const { - return static_cast(default_instance_->New()); - } - - typedef IteratorType iterator; - typedef IteratorType const_iterator; - typedef T value_type; - typedef T& reference; - typedef const T& const_reference; - typedef int size_type; - typedef ptrdiff_t difference_type; - - iterator begin() const { - return iterator(data_, accessor_, true, NewMessage()); - } - iterator end() const { - // The end iterator must not be dereferenced, no need for scratch space. - return iterator(data_, accessor_, false, NULL); - } - - private: - friend class Reflection; - RepeatedFieldRef( - const Message& message, - const FieldDescriptor* field) { - const Reflection* reflection = message.GetReflection(); - data_ = reflection->RepeatedFieldData( - const_cast(&message), field, - internal::RefTypeTraits::cpp_type, - internal::RefTypeTraits::GetMessageFieldDescriptor()); - accessor_ = reflection->RepeatedFieldAccessor(field); - default_instance_ = - reflection->GetMessageFactory()->GetPrototype(field->message_type()); - } - - const void* data_; - const AccessorType* accessor_; - const Message* default_instance_; -}; - -// MutableRepeatedFieldRef definition for message types. -template -class MutableRepeatedFieldRef< - T, typename internal::enable_if::value>::type> { - typedef typename internal::RefTypeTraits::AccessorType AccessorType; - - public: - bool empty() const { - return accessor_->IsEmpty(data_); - } - int size() const { - return accessor_->Size(data_); - } - // See comments for RepeatedFieldRef::Get() - const T& Get(int index, T* scratch_space) const { - return *static_cast(accessor_->Get(data_, index, scratch_space)); - } - // Create a new message of the same type as the messages stored in this - // repeated field. Caller takes ownership of the returned object. - T* NewMessage() const { - return static_cast(default_instance_->New()); - } - - void Set(int index, const T& value) const { - accessor_->Set(data_, index, &value); - } - void Add(const T& value) const { - accessor_->Add(data_, &value); - } - void RemoveLast() const { - accessor_->RemoveLast(data_); - } - void SwapElements(int index1, int index2) const { - accessor_->SwapElements(data_, index1, index2); - } - void Clear() const { - accessor_->Clear(data_); - } - - void Swap(const MutableRepeatedFieldRef& other) const { - accessor_->Swap(data_, other.accessor_, other.data_); - } - - template - void MergeFrom(const Container& container) const { - typedef typename Container::const_iterator Iterator; - for (Iterator it = container.begin(); it != container.end(); ++it) { - Add(*it); - } - } - template - void CopyFrom(const Container& container) const { - Clear(); - MergeFrom(container); - } - - private: - friend class Reflection; - MutableRepeatedFieldRef( - Message* message, - const FieldDescriptor* field) { - const Reflection* reflection = message->GetReflection(); - data_ = reflection->RepeatedFieldData( - message, field, internal::RefTypeTraits::cpp_type, - internal::RefTypeTraits::GetMessageFieldDescriptor()); - accessor_ = reflection->RepeatedFieldAccessor(field); - default_instance_ = - reflection->GetMessageFactory()->GetPrototype(field->message_type()); - } - - void* data_; - const AccessorType* accessor_; - const Message* default_instance_; -}; - -namespace internal { -// Interfaces used to implement reflection RepeatedFieldRef API. -// Reflection::GetRepeatedAccessor() should return a pointer to an singleton -// object that implements the below interface. -// -// This interface passes/returns values using void pointers. The actual type -// of the value depends on the field's cpp_type. Following is a mapping from -// cpp_type to the type that should be used in this interface: -// -// field->cpp_type() T Actual type of void* -// CPPTYPE_INT32 int32 int32 -// CPPTYPE_UINT32 uint32 uint32 -// CPPTYPE_INT64 int64 int64 -// CPPTYPE_UINT64 uint64 uint64 -// CPPTYPE_DOUBLE double double -// CPPTYPE_FLOAT float float -// CPPTYPE_BOOL bool bool -// CPPTYPE_ENUM generated enum type int32 -// CPPTYPE_STRING string string -// CPPTYPE_MESSAGE generated message type google::protobuf::Message -// or google::protobuf::Message -// -// Note that for enums we use int32 in the interface. -// -// You can map from T to the actual type using RefTypeTraits: -// typedef RefTypeTraits::AccessorValueType ActualType; -class LIBPROTOBUF_EXPORT RepeatedFieldAccessor { - public: - // Typedefs for clarity. - typedef void Field; - typedef void Value; - typedef void Iterator; - - virtual ~RepeatedFieldAccessor(); - virtual bool IsEmpty(const Field* data) const = 0; - virtual int Size(const Field* data) const = 0; - // Depends on the underlying representation of the repeated field, this - // method can return a pointer to the underlying object if such an object - // exists, or fill the data into scratch_space and return scratch_space. - // Callers of this method must ensure scratch_space is a valid pointer - // to a mutable object of the correct type. - virtual const Value* Get( - const Field* data, int index, Value* scratch_space) const = 0; - - virtual void Clear(Field* data) const = 0; - virtual void Set(Field* data, int index, const Value* value) const = 0; - virtual void Add(Field* data, const Value* value) const = 0; - virtual void RemoveLast(Field* data) const = 0; - virtual void SwapElements(Field* data, int index1, int index2) const = 0; - virtual void Swap(Field* data, const RepeatedFieldAccessor* other_mutator, - Field* other_data) const = 0; - - // Create an iterator that points at the beginning of the repeated field. - virtual Iterator* BeginIterator(const Field* data) const = 0; - // Create an iterator that points at the end of the repeated field. - virtual Iterator* EndIterator(const Field* data) const = 0; - // Make a copy of an iterator and return the new copy. - virtual Iterator* CopyIterator(const Field* data, - const Iterator* iterator) const = 0; - // Move an iterator to point to the next element. - virtual Iterator* AdvanceIterator(const Field* data, - Iterator* iterator) const = 0; - // Compare whether two iterators point to the same element. - virtual bool EqualsIterator(const Field* data, const Iterator* a, - const Iterator* b) const = 0; - // Delete an iterator created by BeginIterator(), EndIterator() and - // CopyIterator(). - virtual void DeleteIterator(const Field* data, Iterator* iterator) const = 0; - // Like Get() but for iterators. - virtual const Value* GetIteratorValue(const Field* data, - const Iterator* iterator, - Value* scratch_space) const = 0; - - // Templated methods that make using this interface easier for non-message - // types. - template - T Get(const Field* data, int index) const { - typedef typename RefTypeTraits::AccessorValueType ActualType; - ActualType scratch_space; - return static_cast( - *reinterpret_cast( - Get(data, index, static_cast(&scratch_space)))); - } - - template - void Set(Field* data, int index, const ValueType& value) const { - typedef typename RefTypeTraits::AccessorValueType ActualType; - // In this RepeatedFieldAccessor interface we pass/return data using - // raw pointers. Type of the data these raw pointers point to should - // be ActualType. Here we have a ValueType object and want a ActualType - // pointer. We can't cast a ValueType pointer to an ActualType pointer - // directly because their type might be different (for enums ValueType - // may be a generated enum type while ActualType is int32). To be safe - // we make a copy to get a temporary ActualType object and use it. - ActualType tmp = static_cast(value); - Set(data, index, static_cast(&tmp)); - } - - template - void Add(Field* data, const ValueType& value) const { - typedef typename RefTypeTraits::AccessorValueType ActualType; - // In this RepeatedFieldAccessor interface we pass/return data using - // raw pointers. Type of the data these raw pointers point to should - // be ActualType. Here we have a ValueType object and want a ActualType - // pointer. We can't cast a ValueType pointer to an ActualType pointer - // directly because their type might be different (for enums ValueType - // may be a generated enum type while ActualType is int32). To be safe - // we make a copy to get a temporary ActualType object and use it. - ActualType tmp = static_cast(value); - Add(data, static_cast(&tmp)); - } -}; - -// Implement (Mutable)RepeatedFieldRef::iterator -template -class RepeatedFieldRefIterator - : public std::iterator { - typedef typename RefTypeTraits::AccessorValueType AccessorValueType; - typedef typename RefTypeTraits::IteratorValueType IteratorValueType; - typedef typename RefTypeTraits::IteratorPointerType IteratorPointerType; - - public: - // Constructor for non-message fields. - RepeatedFieldRefIterator(const void* data, - const RepeatedFieldAccessor* accessor, bool begin) - : data_(data), - accessor_(accessor), - iterator_(begin ? accessor->BeginIterator(data) - : accessor->EndIterator(data)), - // The end iterator must not be dereferenced, no need for scratch space. - scratch_space_(begin ? new AccessorValueType : NULL) {} - // Constructor for message fields. - RepeatedFieldRefIterator(const void* data, - const RepeatedFieldAccessor* accessor, - bool begin, - AccessorValueType* scratch_space) - : data_(data), accessor_(accessor), - iterator_(begin ? accessor->BeginIterator(data) : - accessor->EndIterator(data)), - scratch_space_(scratch_space) { - } - ~RepeatedFieldRefIterator() { - accessor_->DeleteIterator(data_, iterator_); - } - RepeatedFieldRefIterator operator++(int) { - RepeatedFieldRefIterator tmp(*this); - iterator_ = accessor_->AdvanceIterator(data_, iterator_); - return tmp; - } - RepeatedFieldRefIterator& operator++() { - iterator_ = accessor_->AdvanceIterator(data_, iterator_); - return *this; - } - IteratorValueType operator*() const { - return static_cast( - *static_cast( - accessor_->GetIteratorValue( - data_, iterator_, scratch_space_.get()))); - } - IteratorPointerType operator->() const { - return static_cast( - accessor_->GetIteratorValue( - data_, iterator_, scratch_space_.get())); - } - bool operator!=(const RepeatedFieldRefIterator& other) const { - assert(data_ == other.data_); - assert(accessor_ == other.accessor_); - return !accessor_->EqualsIterator(data_, iterator_, other.iterator_); - } - bool operator==(const RepeatedFieldRefIterator& other) const { - return !this->operator!=(other); - } - - RepeatedFieldRefIterator(const RepeatedFieldRefIterator& other) - : data_(other.data_), accessor_(other.accessor_), - iterator_(accessor_->CopyIterator(data_, other.iterator_)) { - } - RepeatedFieldRefIterator& operator=(const RepeatedFieldRefIterator& other) { - if (this != &other) { - accessor_->DeleteIterator(data_, iterator_); - data_ = other.data_; - accessor_ = other.accessor_; - iterator_ = accessor_->CopyIterator(data_, other.iterator_); - } - return *this; - } - - protected: - const void* data_; - const RepeatedFieldAccessor* accessor_; - void* iterator_; - google::protobuf::scoped_ptr scratch_space_; -}; - -// TypeTraits that maps the type parameter T of RepeatedFieldRef or -// MutableRepeatedFieldRef to corresponding iterator type, -// RepeatedFieldAccessor type, etc. -template -struct PrimitiveTraits { - static const bool is_primitive = false; -}; -#define DEFINE_PRIMITIVE(TYPE, type) \ - template<> struct PrimitiveTraits { \ - static const bool is_primitive = true; \ - static const FieldDescriptor::CppType cpp_type = \ - FieldDescriptor::CPPTYPE_ ## TYPE; \ - }; -DEFINE_PRIMITIVE(INT32, int32) -DEFINE_PRIMITIVE(UINT32, uint32) -DEFINE_PRIMITIVE(INT64, int64) -DEFINE_PRIMITIVE(UINT64, uint64) -DEFINE_PRIMITIVE(FLOAT, float) -DEFINE_PRIMITIVE(DOUBLE, double) -DEFINE_PRIMITIVE(BOOL, bool) -#undef DEFINE_PRIMITIVE - -template -struct RefTypeTraits< - T, typename internal::enable_if::is_primitive>::type> { - typedef RepeatedFieldRefIterator iterator; - typedef RepeatedFieldAccessor AccessorType; - typedef T AccessorValueType; - typedef T IteratorValueType; - typedef T* IteratorPointerType; - static const FieldDescriptor::CppType cpp_type = - PrimitiveTraits::cpp_type; - static const Descriptor* GetMessageFieldDescriptor() { - return NULL; - } -}; - -template -struct RefTypeTraits< - T, typename internal::enable_if::value>::type> { - typedef RepeatedFieldRefIterator iterator; - typedef RepeatedFieldAccessor AccessorType; - // We use int32 for repeated enums in RepeatedFieldAccessor. - typedef int32 AccessorValueType; - typedef T IteratorValueType; - typedef int32* IteratorPointerType; - static const FieldDescriptor::CppType cpp_type = - FieldDescriptor::CPPTYPE_ENUM; - static const Descriptor* GetMessageFieldDescriptor() { - return NULL; - } -}; - -template -struct RefTypeTraits< - T, typename internal::enable_if< ::google::protobuf::internal::is_same::value>::type> { - typedef RepeatedFieldRefIterator iterator; - typedef RepeatedFieldAccessor AccessorType; - typedef string AccessorValueType; - typedef string IteratorValueType; - typedef string* IteratorPointerType; - static const FieldDescriptor::CppType cpp_type = - FieldDescriptor::CPPTYPE_STRING; - static const Descriptor* GetMessageFieldDescriptor() { - return NULL; - } -}; - -template -struct MessageDescriptorGetter { - static const Descriptor* get() { - return T::default_instance().GetDescriptor(); - } -}; -template<> -struct MessageDescriptorGetter { - static const Descriptor* get() { - return NULL; - } -}; - -template -struct RefTypeTraits< - T, typename internal::enable_if::value>::type> { - typedef RepeatedFieldRefIterator iterator; - typedef RepeatedFieldAccessor AccessorType; - typedef Message AccessorValueType; - typedef const T& IteratorValueType; - typedef const T* IteratorPointerType; - static const FieldDescriptor::CppType cpp_type = - FieldDescriptor::CPPTYPE_MESSAGE; - static const Descriptor* GetMessageFieldDescriptor() { - return MessageDescriptorGetter::get(); - } -}; -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_REFLECTION_H__ diff --git a/app/src/main/cpp/google/protobuf/reflection_ops.h b/app/src/main/cpp/google/protobuf/reflection_ops.h deleted file mode 100644 index 45d8c65..0000000 --- a/app/src/main/cpp/google/protobuf/reflection_ops.h +++ /dev/null @@ -1,81 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// This header is logically internal, but is made public because it is used -// from protocol-compiler-generated code, which may reside in other components. - -#ifndef GOOGLE_PROTOBUF_REFLECTION_OPS_H__ -#define GOOGLE_PROTOBUF_REFLECTION_OPS_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Basic operations that can be performed using reflection. -// These can be used as a cheap way to implement the corresponding -// methods of the Message interface, though they are likely to be -// slower than implementations tailored for the specific message type. -// -// This class should stay limited to operations needed to implement -// the Message interface. -// -// This class is really a namespace that contains only static methods. -class LIBPROTOBUF_EXPORT ReflectionOps { - public: - static void Copy(const Message& from, Message* to); - static void Merge(const Message& from, Message* to); - static void Clear(Message* message); - static bool IsInitialized(const Message& message); - static void DiscardUnknownFields(Message* message); - - // Finds all unset required fields in the message and adds their full - // paths (e.g. "foo.bar[5].baz") to *names. "prefix" will be attached to - // the front of each name. - static void FindInitializationErrors(const Message& message, - const string& prefix, - std::vector* errors); - - private: - // All methods are static. No need to construct. - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ReflectionOps); -}; - -} // namespace internal -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_REFLECTION_OPS_H__ diff --git a/app/src/main/cpp/google/protobuf/repeated_field.h b/app/src/main/cpp/google/protobuf/repeated_field.h deleted file mode 100644 index 0a41495..0000000 --- a/app/src/main/cpp/google/protobuf/repeated_field.h +++ /dev/null @@ -1,2504 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// RepeatedField and RepeatedPtrField are used by generated protocol message -// classes to manipulate repeated fields. These classes are very similar to -// STL's vector, but include a number of optimizations found to be useful -// specifically in the case of Protocol Buffers. RepeatedPtrField is -// particularly different from STL vector as it manages ownership of the -// pointers that it contains. -// -// Typically, clients should not need to access RepeatedField objects directly, -// but should instead use the accessor functions generated automatically by the -// protocol compiler. - -#ifndef GOOGLE_PROTOBUF_REPEATED_FIELD_H__ -#define GOOGLE_PROTOBUF_REPEATED_FIELD_H__ - -#ifdef _MSC_VER -// This is required for min/max on VS2013 only. -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace google { - -namespace upb { -namespace google_opensource { -class GMR_Handlers; -} // namespace google_opensource -} // namespace upb - -namespace protobuf { - -class Message; - -namespace internal { - -static const int kMinRepeatedFieldAllocationSize = 4; - -// A utility function for logging that doesn't need any template types. -void LogIndexOutOfBounds(int index, int size); - -template -inline int CalculateReserve(Iter begin, Iter end, std::forward_iterator_tag) { - return std::distance(begin, end); -} - -template -inline int CalculateReserve(Iter /*begin*/, Iter /*end*/, - std::input_iterator_tag /*unused*/) { - return -1; -} - -template -inline int CalculateReserve(Iter begin, Iter end) { - typedef typename std::iterator_traits::iterator_category Category; - return CalculateReserve(begin, end, Category()); -} -} // namespace internal - - -// RepeatedField is used to represent repeated fields of a primitive type (in -// other words, everything except strings and nested Messages). Most users will -// not ever use a RepeatedField directly; they will use the get-by-index, -// set-by-index, and add accessors that are generated for all repeated fields. -template -class RepeatedField { - public: - RepeatedField(); - explicit RepeatedField(Arena* arena); - RepeatedField(const RepeatedField& other); - template - RepeatedField(Iter begin, const Iter& end); - ~RepeatedField(); - - RepeatedField& operator=(const RepeatedField& other); - - bool empty() const; - int size() const; - - const Element& Get(int index) const; - Element* Mutable(int index); - - const Element& operator[](int index) const { return Get(index); } - Element& operator[](int index) { return *Mutable(index); } - - void Set(int index, const Element& value); - void Add(const Element& value); - Element* Add(); - // Remove the last element in the array. - void RemoveLast(); - - // Extract elements with indices in "[start .. start+num-1]". - // Copy them into "elements[0 .. num-1]" if "elements" is not NULL. - // Caution: implementation also moves elements with indices [start+num ..]. - // Calling this routine inside a loop can cause quadratic behavior. - void ExtractSubrange(int start, int num, Element* elements); - - void Clear(); - void MergeFrom(const RepeatedField& other); - void UnsafeMergeFrom(const RepeatedField& other); - void CopyFrom(const RepeatedField& other); - - // Reserve space to expand the field to at least the given size. If the - // array is grown, it will always be at least doubled in size. - void Reserve(int new_size); - - // Resize the RepeatedField to a new, smaller size. This is O(1). - void Truncate(int new_size); - - void AddAlreadyReserved(const Element& value); - Element* AddAlreadyReserved(); - int Capacity() const; - - // Like STL resize. Uses value to fill appended elements. - // Like Truncate() if new_size <= size(), otherwise this is - // O(new_size - size()). - void Resize(int new_size, const Element& value); - - // Gets the underlying array. This pointer is possibly invalidated by - // any add or remove operation. - Element* mutable_data(); - const Element* data() const; - - // Swap entire contents with "other". If they are separate arenas then, copies - // data between each other. - void Swap(RepeatedField* other); - - // Swap entire contents with "other". Should be called only if the caller can - // guarantee that both repeated fields are on the same arena or are on the - // heap. Swapping between different arenas is disallowed and caught by a - // GOOGLE_DCHECK (see API docs for details). - void UnsafeArenaSwap(RepeatedField* other); - - // Swap two elements. - void SwapElements(int index1, int index2); - - // STL-like iterator support - typedef Element* iterator; - typedef const Element* const_iterator; - typedef Element value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef int size_type; - typedef ptrdiff_t difference_type; - - iterator begin(); - const_iterator begin() const; - const_iterator cbegin() const; - iterator end(); - const_iterator end() const; - const_iterator cend() const; - - // Reverse iterator support - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; - reverse_iterator rbegin() { - return reverse_iterator(end()); - } - const_reverse_iterator rbegin() const { - return const_reverse_iterator(end()); - } - reverse_iterator rend() { - return reverse_iterator(begin()); - } - const_reverse_iterator rend() const { - return const_reverse_iterator(begin()); - } - - // Returns the number of bytes used by the repeated field, excluding - // sizeof(*this) - int SpaceUsedExcludingSelf() const; - - // Removes the element referenced by position. - // - // Returns an iterator to the element immediately following the removed - // element. - // - // Invalidates all iterators at or after the removed element, including end(). - iterator erase(const_iterator position); - - // Removes the elements in the range [first, last). - // - // Returns an iterator to the element immediately following the removed range. - // - // Invalidates all iterators at or after the removed range, including end(). - iterator erase(const_iterator first, const_iterator last); - - // Get the Arena on which this RepeatedField stores its elements. - ::google::protobuf::Arena* GetArena() const { - return GetArenaNoVirtual(); - } - - private: - static const int kInitialSize = 0; - // A note on the representation here (see also comment below for - // RepeatedPtrFieldBase's struct Rep): - // - // We maintain the same sizeof(RepeatedField) as before we added arena support - // so that we do not degrade performance by bloating memory usage. Directly - // adding an arena_ element to RepeatedField is quite costly. By using - // indirection in this way, we keep the same size when the RepeatedField is - // empty (common case), and add only an 8-byte header to the elements array - // when non-empty. We make sure to place the size fields directly in the - // RepeatedField class to avoid costly cache misses due to the indirection. - int current_size_; - int total_size_; - struct Rep { - Arena* arena; - Element elements[1]; - }; - // We can not use sizeof(Rep) - sizeof(Element) due to the trailing padding on - // the struct. We can not use sizeof(Arena*) as well because there might be - // a "gap" after the field arena and before the field elements (e.g., when - // Element is double and pointer is 32bit). - static const size_t kRepHeaderSize; - // Contains arena ptr and the elements array. We also keep the invariant that - // if rep_ is NULL, then arena is NULL. - Rep* rep_; - - friend class Arena; - typedef void InternalArenaConstructable_; - - // Move the contents of |from| into |to|, possibly clobbering |from| in the - // process. For primitive types this is just a memcpy(), but it could be - // specialized for non-primitive types to, say, swap each element instead. - void MoveArray(Element* to, Element* from, int size); - - // Copy the elements of |from| into |to|. - void CopyArray(Element* to, const Element* from, int size); - - inline void InternalSwap(RepeatedField* other); - - // Internal helper expected by Arena methods. - inline Arena* GetArenaNoVirtual() const { - return (rep_ == NULL) ? NULL : rep_->arena; - } - - // Internal helper to delete all elements and deallocate the storage. - // If Element has a trivial destructor (for example, if it's a fundamental - // type, like int32), the loop will be removed by the optimizer. - void InternalDeallocate(Rep* rep, int size) { - if (rep != NULL) { - Element* e = &rep->elements[0]; - Element* limit = &rep->elements[size]; - for (; e < limit; e++) { - e->Element::~Element(); - } - if (rep->arena == NULL) { -#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) - const size_t bytes = size * sizeof(*e) + kRepHeaderSize; - ::operator delete(static_cast(rep), bytes); -#else - ::operator delete(static_cast(rep)); -#endif - } - } - } -}; - -template -const size_t RepeatedField::kRepHeaderSize = - reinterpret_cast(&reinterpret_cast(16)->elements[0]) - 16; - -namespace internal { -template class RepeatedPtrIterator; -template class RepeatedPtrOverPtrsIterator; -} // namespace internal - -namespace internal { - -// This is a helper template to copy an array of elements effeciently when they -// have a trivial copy constructor, and correctly otherwise. This really -// shouldn't be necessary, but our compiler doesn't optimize std::copy very -// effectively. -template ::value> -struct ElementCopier { - void operator()(Element* to, const Element* from, int array_size); -}; - -} // namespace internal - -namespace internal { - -// type-traits helper for RepeatedPtrFieldBase: we only want to invoke -// arena-related "copy if on different arena" behavior if the necessary methods -// exist on the contained type. In particular, we rely on MergeFrom() existing -// as a general proxy for the fact that a copy will work, and we also provide a -// specific override for string*. -template -struct TypeImplementsMergeBehavior { - typedef char HasMerge; - typedef long HasNoMerge; - - // We accept either of: - // - void MergeFrom(const T& other) - // - bool MergeFrom(const T& other) - // - // We mangle these names a bit to avoid compatibility issues in 'unclean' - // include environments that may have, e.g., "#define test ..." (yes, this - // exists). - template - struct CheckType; - template static HasMerge Check( - CheckType*); - template static HasMerge Check( - CheckType*); - template static HasNoMerge Check(...); - - // Resovles to either google::protobuf::internal::true_type or google::protobuf::internal::false_type. - typedef google::protobuf::internal::integral_constant(0)) == sizeof(HasMerge))> type; -}; - -template<> -struct TypeImplementsMergeBehavior< ::std::string > { - typedef google::protobuf::internal::true_type type; -}; - -// This is the common base class for RepeatedPtrFields. It deals only in void* -// pointers. Users should not use this interface directly. -// -// The methods of this interface correspond to the methods of RepeatedPtrField, -// but may have a template argument called TypeHandler. Its signature is: -// class TypeHandler { -// public: -// typedef MyType Type; -// static Type* New(); -// static void Delete(Type*); -// static void Clear(Type*); -// static void Merge(const Type& from, Type* to); -// -// // Only needs to be implemented if SpaceUsedExcludingSelf() is called. -// static int SpaceUsed(const Type&); -// }; -class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { - protected: - // The reflection implementation needs to call protected methods directly, - // reinterpreting pointers as being to Message instead of a specific Message - // subclass. - friend class GeneratedMessageReflection; - - // ExtensionSet stores repeated message extensions as - // RepeatedPtrField, but non-lite ExtensionSets need to - // implement SpaceUsed(), and thus need to call SpaceUsedExcludingSelf() - // reinterpreting MessageLite as Message. ExtensionSet also needs to make - // use of AddFromCleared(), which is not part of the public interface. - friend class ExtensionSet; - - // The MapFieldBase implementation needs to call protected methods directly, - // reinterpreting pointers as being to Message instead of a specific Message - // subclass. - friend class MapFieldBase; - - // To parse directly into a proto2 generated class, the upb class GMR_Handlers - // needs to be able to modify a RepeatedPtrFieldBase directly. - friend class upb::google_opensource::GMR_Handlers; - - RepeatedPtrFieldBase(); - explicit RepeatedPtrFieldBase(::google::protobuf::Arena* arena); - ~RepeatedPtrFieldBase() {} - - // Must be called from destructor. - template - void Destroy(); - - bool empty() const; - int size() const; - - template - const typename TypeHandler::Type& Get(int index) const; - template - typename TypeHandler::Type* Mutable(int index); - template - void Delete(int index); - template - typename TypeHandler::Type* Add(typename TypeHandler::Type* prototype = NULL); - - template - void RemoveLast(); - template - void Clear(); - template - void MergeFrom(const RepeatedPtrFieldBase& other); - template - void CopyFrom(const RepeatedPtrFieldBase& other); - - void CloseGap(int start, int num); - - void Reserve(int new_size); - - int Capacity() const; - - // Used for constructing iterators. - void* const* raw_data() const; - void** raw_mutable_data() const; - - template - typename TypeHandler::Type** mutable_data(); - template - const typename TypeHandler::Type* const* data() const; - - template - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void Swap(RepeatedPtrFieldBase* other); - - void SwapElements(int index1, int index2); - - template - int SpaceUsedExcludingSelf() const; - - - // Advanced memory management -------------------------------------- - - // Like Add(), but if there are no cleared objects to use, returns NULL. - template - typename TypeHandler::Type* AddFromCleared(); - - template - void AddAllocated(typename TypeHandler::Type* value) { - typename TypeImplementsMergeBehavior::type t; - AddAllocatedInternal(value, t); - } - - template - void UnsafeArenaAddAllocated(typename TypeHandler::Type* value); - - template - typename TypeHandler::Type* ReleaseLast() { - typename TypeImplementsMergeBehavior::type t; - return ReleaseLastInternal(t); - } - - // Releases last element and returns it, but does not do out-of-arena copy. - // And just returns the raw pointer to the contained element in the arena. - template - typename TypeHandler::Type* UnsafeArenaReleaseLast(); - - int ClearedCount() const; - template - void AddCleared(typename TypeHandler::Type* value); - template - typename TypeHandler::Type* ReleaseCleared(); - - protected: - inline void InternalSwap(RepeatedPtrFieldBase* other); - - template - void AddAllocatedInternal(typename TypeHandler::Type* value, - google::protobuf::internal::true_type); - template - void AddAllocatedInternal(typename TypeHandler::Type* value, - google::protobuf::internal::false_type); - - template GOOGLE_ATTRIBUTE_NOINLINE - void AddAllocatedSlowWithCopy(typename TypeHandler::Type* value, - Arena* value_arena, - Arena* my_arena); - template GOOGLE_ATTRIBUTE_NOINLINE - void AddAllocatedSlowWithoutCopy(typename TypeHandler::Type* value); - - template - typename TypeHandler::Type* ReleaseLastInternal(google::protobuf::internal::true_type); - template - typename TypeHandler::Type* ReleaseLastInternal(google::protobuf::internal::false_type); - - template GOOGLE_ATTRIBUTE_NOINLINE - void SwapFallback(RepeatedPtrFieldBase* other); - - inline Arena* GetArenaNoVirtual() const { - return arena_; - } - - private: - static const int kInitialSize = 0; - // A few notes on internal representation: - // - // We use an indirected approach, with struct Rep, to keep - // sizeof(RepeatedPtrFieldBase) equivalent to what it was before arena support - // was added, namely, 3 8-byte machine words on x86-64. An instance of Rep is - // allocated only when the repeated field is non-empty, and it is a - // dynamically-sized struct (the header is directly followed by elements[]). - // We place arena_ and current_size_ directly in the object to avoid cache - // misses due to the indirection, because these fields are checked frequently. - // Placing all fields directly in the RepeatedPtrFieldBase instance costs - // significant performance for memory-sensitive workloads. - Arena* arena_; - int current_size_; - int total_size_; - struct Rep { - int allocated_size; - void* elements[1]; - }; - static const size_t kRepHeaderSize = sizeof(Rep) - sizeof(void*); - // Contains arena ptr and the elements array. We also keep the invariant that - // if rep_ is NULL, then arena is NULL. - Rep* rep_; - - template - static inline typename TypeHandler::Type* cast(void* element) { - return reinterpret_cast(element); - } - template - static inline const typename TypeHandler::Type* cast(const void* element) { - return reinterpret_cast(element); - } - - // Non-templated inner function to avoid code duplication. Takes a function - // pointer to the type-specific (templated) inner allocate/merge loop. - void MergeFromInternal( - const RepeatedPtrFieldBase& other, - void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)); - - template - void MergeFromInnerLoop( - void** our_elems, void** other_elems, int length, int already_allocated); - - // Internal helper: extend array space if necessary to contain |extend_amount| - // more elements, and return a pointer to the element immediately following - // the old list of elements. This interface factors out common behavior from - // Reserve() and MergeFrom() to reduce code size. |extend_amount| must be > 0. - void** InternalExtend(int extend_amount); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase); -}; - -template -class GenericTypeHandler { - public: - typedef GenericType Type; - static inline GenericType* New(Arena* arena) { - return ::google::protobuf::Arena::CreateMaybeMessage( - arena, static_cast(0)); - } - // We force NewFromPrototype() to be non-inline to reduce code size: - // else, several other methods get inlined copies of message types' - // constructors. - GOOGLE_ATTRIBUTE_NOINLINE static GenericType* NewFromPrototype( - const GenericType* prototype, ::google::protobuf::Arena* arena = NULL); - static inline void Delete(GenericType* value, Arena* arena) { - if (arena == NULL) { - delete value; - } - } - static inline ::google::protobuf::Arena* GetArena(GenericType* value) { - return ::google::protobuf::Arena::GetArena(value); - } - static inline void* GetMaybeArenaPointer(GenericType* value) { - return ::google::protobuf::Arena::GetArena(value); - } - - static inline void Clear(GenericType* value) { value->Clear(); } - GOOGLE_ATTRIBUTE_NOINLINE static void Merge(const GenericType& from, - GenericType* to); - static inline int SpaceUsed(const GenericType& value) { - return value.SpaceUsed(); - } - static inline const Type& default_instance() { - return Type::default_instance(); - } -}; - -template -GenericType* GenericTypeHandler::NewFromPrototype( - const GenericType* /* prototype */, ::google::protobuf::Arena* arena) { - return New(arena); -} -template -void GenericTypeHandler::Merge(const GenericType& from, - GenericType* to) { - to->MergeFrom(from); -} - -// NewFromPrototype() and Merge() cannot be defined here; if they're declared -// inline the compiler will complain about not matching GOOGLE_ATTRIBUTE_NOINLINE -// above, and if not, compilation will result in multiple definitions. These -// are therefore declared as specializations here and defined in -// message_lite.cc. -template<> -MessageLite* GenericTypeHandler::NewFromPrototype( - const MessageLite* prototype, google::protobuf::Arena* arena); -template<> -inline google::protobuf::Arena* GenericTypeHandler::GetArena( - MessageLite* value) { - return value->GetArena(); -} -template<> -inline void* GenericTypeHandler::GetMaybeArenaPointer( - MessageLite* value) { - return value->GetMaybeArenaPointer(); -} -template <> -void GenericTypeHandler::Merge(const MessageLite& from, - MessageLite* to); -template<> -inline void GenericTypeHandler::Clear(string* value) { - value->clear(); -} -template<> -void GenericTypeHandler::Merge(const string& from, - string* to); - -// Declarations of the specialization as we cannot define them here, as the -// header that defines ProtocolMessage depends on types defined in this header. -#define DECLARE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(TypeName) \ - template<> \ - TypeName* GenericTypeHandler::NewFromPrototype( \ - const TypeName* prototype, google::protobuf::Arena* arena); \ - template<> \ - google::protobuf::Arena* GenericTypeHandler::GetArena( \ - TypeName* value); \ - template<> \ - void* GenericTypeHandler::GetMaybeArenaPointer( \ - TypeName* value); - -// Message specialization bodies defined in message.cc. This split is necessary -// to allow proto2-lite (which includes this header) to be independent of -// Message. -DECLARE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES(Message) - - -#undef DECLARE_SPECIALIZATIONS_FOR_BASE_PROTO_TYPES - -template <> -inline const MessageLite& GenericTypeHandler::default_instance() { - // Yes, the behavior of the code is undefined, but this function is only - // called when we're already deep into the world of undefined, because the - // caller called Get(index) out of bounds. - MessageLite* null = NULL; - return *null; -} - -template <> -inline const Message& GenericTypeHandler::default_instance() { - // Yes, the behavior of the code is undefined, but this function is only - // called when we're already deep into the world of undefined, because the - // caller called Get(index) out of bounds. - Message* null = NULL; - return *null; -} - - -// HACK: If a class is declared as DLL-exported in MSVC, it insists on -// generating copies of all its methods -- even inline ones -- to include -// in the DLL. But SpaceUsed() calls StringSpaceUsedExcludingSelf() which -// isn't in the lite library, therefore the lite library cannot link if -// StringTypeHandler is exported. So, we factor out StringTypeHandlerBase, -// export that, then make StringTypeHandler be a subclass which is NOT -// exported. -// TODO(kenton): Now that StringSpaceUsedExcludingSelf() is in the lite -// library, this can be cleaned up. -class LIBPROTOBUF_EXPORT StringTypeHandlerBase { - public: - typedef string Type; - - static inline string* New(Arena* arena) { - return Arena::Create(arena); - } - static inline string* NewFromPrototype(const string*, - ::google::protobuf::Arena* arena) { - return New(arena); - } - static inline ::google::protobuf::Arena* GetArena(string*) { - return NULL; - } - static inline void* GetMaybeArenaPointer(string* /* value */) { - return NULL; - } - static inline void Delete(string* value, Arena* arena) { - if (arena == NULL) { - delete value; - } - } - static inline void Clear(string* value) { value->clear(); } - static inline void Merge(const string& from, string* to) { *to = from; } - static inline const Type& default_instance() { - return ::google::protobuf::internal::GetEmptyString(); - } -}; - -class StringTypeHandler : public StringTypeHandlerBase { - public: - static int SpaceUsed(const string& value) { - return static_cast(sizeof(value)) + StringSpaceUsedExcludingSelf(value); - } -}; - - -} // namespace internal - -// RepeatedPtrField is like RepeatedField, but used for repeated strings or -// Messages. -template -class RepeatedPtrField : public internal::RepeatedPtrFieldBase { - public: - RepeatedPtrField(); - explicit RepeatedPtrField(::google::protobuf::Arena* arena); - - RepeatedPtrField(const RepeatedPtrField& other); - template - RepeatedPtrField(Iter begin, const Iter& end); - ~RepeatedPtrField(); - - RepeatedPtrField& operator=(const RepeatedPtrField& other); - - bool empty() const; - int size() const; - - const Element& Get(int index) const; - Element* Mutable(int index); - Element* Add(); - - const Element& operator[](int index) const { return Get(index); } - Element& operator[](int index) { return *Mutable(index); } - - // Remove the last element in the array. - // Ownership of the element is retained by the array. - void RemoveLast(); - - // Delete elements with indices in the range [start .. start+num-1]. - // Caution: implementation moves all elements with indices [start+num .. ]. - // Calling this routine inside a loop can cause quadratic behavior. - void DeleteSubrange(int start, int num); - - void Clear(); - void MergeFrom(const RepeatedPtrField& other); - void UnsafeMergeFrom(const RepeatedPtrField& other) { MergeFrom(other); } - void CopyFrom(const RepeatedPtrField& other); - - // Reserve space to expand the field to at least the given size. This only - // resizes the pointer array; it doesn't allocate any objects. If the - // array is grown, it will always be at least doubled in size. - void Reserve(int new_size); - - int Capacity() const; - - // Gets the underlying array. This pointer is possibly invalidated by - // any add or remove operation. - Element** mutable_data(); - const Element* const* data() const; - - // Swap entire contents with "other". If they are on separate arenas, then - // copies data. - void Swap(RepeatedPtrField* other); - - // Swap entire contents with "other". Caller should guarantee that either both - // fields are on the same arena or both are on the heap. Swapping between - // different arenas with this function is disallowed and is caught via - // GOOGLE_DCHECK. - void UnsafeArenaSwap(RepeatedPtrField* other); - - // Swap two elements. - void SwapElements(int index1, int index2); - - // STL-like iterator support - typedef internal::RepeatedPtrIterator iterator; - typedef internal::RepeatedPtrIterator const_iterator; - typedef Element value_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; - typedef int size_type; - typedef ptrdiff_t difference_type; - - iterator begin(); - const_iterator begin() const; - const_iterator cbegin() const; - iterator end(); - const_iterator end() const; - const_iterator cend() const; - - // Reverse iterator support - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; - reverse_iterator rbegin() { - return reverse_iterator(end()); - } - const_reverse_iterator rbegin() const { - return const_reverse_iterator(end()); - } - reverse_iterator rend() { - return reverse_iterator(begin()); - } - const_reverse_iterator rend() const { - return const_reverse_iterator(begin()); - } - - // Custom STL-like iterator that iterates over and returns the underlying - // pointers to Element rather than Element itself. - typedef internal::RepeatedPtrOverPtrsIterator - pointer_iterator; - typedef internal::RepeatedPtrOverPtrsIterator - const_pointer_iterator; - pointer_iterator pointer_begin(); - const_pointer_iterator pointer_begin() const; - pointer_iterator pointer_end(); - const_pointer_iterator pointer_end() const; - - // Returns (an estimate of) the number of bytes used by the repeated field, - // excluding sizeof(*this). - int SpaceUsedExcludingSelf() const; - - // Advanced memory management -------------------------------------- - // When hardcore memory management becomes necessary -- as it sometimes - // does here at Google -- the following methods may be useful. - - // Add an already-allocated object, passing ownership to the - // RepeatedPtrField. - // - // Note that some special behavior occurs with respect to arenas: - // - // (i) if this field holds submessages, the new submessage will be copied if - // the original is in an arena and this RepeatedPtrField is either in a - // different arena, or on the heap. - // (ii) if this field holds strings, the passed-in string *must* be - // heap-allocated, not arena-allocated. There is no way to dynamically check - // this at runtime, so User Beware. - void AddAllocated(Element* value); - - // Remove the last element and return it, passing ownership to the caller. - // Requires: size() > 0 - // - // If this RepeatedPtrField is on an arena, an object copy is required to pass - // ownership back to the user (for compatible semantics). Use - // UnsafeArenaReleaseLast() if this behavior is undesired. - Element* ReleaseLast(); - - // Add an already-allocated object, skipping arena-ownership checks. The user - // must guarantee that the given object is in the same arena as this - // RepeatedPtrField. - // It is also useful in legacy code that uses temporary ownership to avoid - // copies. Example: - // RepeatedPtrField temp_field; - // temp_field.AddAllocated(new T); - // ... // Do something with temp_field - // temp_field.ExtractSubrange(0, temp_field.size(), NULL); - // If you put temp_field on the arena this fails, because the ownership - // transfers to the arena at the "AddAllocated" call and is not released - // anymore causing a double delete. UnsafeArenaAddAllocated prevents this. - void UnsafeArenaAddAllocated(Element* value); - - // Remove the last element and return it. Works only when operating on an - // arena. The returned pointer is to the original object in the arena, hence - // has the arena's lifetime. - // Requires: current_size_ > 0 - Element* UnsafeArenaReleaseLast(); - - // Extract elements with indices in the range "[start .. start+num-1]". - // The caller assumes ownership of the extracted elements and is responsible - // for deleting them when they are no longer needed. - // If "elements" is non-NULL, then pointers to the extracted elements - // are stored in "elements[0 .. num-1]" for the convenience of the caller. - // If "elements" is NULL, then the caller must use some other mechanism - // to perform any further operations (like deletion) on these elements. - // Caution: implementation also moves elements with indices [start+num ..]. - // Calling this routine inside a loop can cause quadratic behavior. - // - // Memory copying behavior is identical to ReleaseLast(), described above: if - // this RepeatedPtrField is on an arena, an object copy is performed for each - // returned element, so that all returned element pointers are to - // heap-allocated copies. If this copy is not desired, the user should call - // UnsafeArenaExtractSubrange(). - void ExtractSubrange(int start, int num, Element** elements); - - // Identical to ExtractSubrange() described above, except that when this - // repeated field is on an arena, no object copies are performed. Instead, the - // raw object pointers are returned. Thus, if on an arena, the returned - // objects must not be freed, because they will not be heap-allocated objects. - void UnsafeArenaExtractSubrange(int start, int num, Element** elements); - - // When elements are removed by calls to RemoveLast() or Clear(), they - // are not actually freed. Instead, they are cleared and kept so that - // they can be reused later. This can save lots of CPU time when - // repeatedly reusing a protocol message for similar purposes. - // - // Hardcore programs may choose to manipulate these cleared objects - // to better optimize memory management using the following routines. - - // Get the number of cleared objects that are currently being kept - // around for reuse. - int ClearedCount() const; - // Add an element to the pool of cleared objects, passing ownership to - // the RepeatedPtrField. The element must be cleared prior to calling - // this method. - // - // This method cannot be called when the repeated field is on an arena or when - // |value| is; both cases will trigger a GOOGLE_DCHECK-failure. - void AddCleared(Element* value); - // Remove a single element from the cleared pool and return it, passing - // ownership to the caller. The element is guaranteed to be cleared. - // Requires: ClearedCount() > 0 - // - // - // This method cannot be called when the repeated field is on an arena; doing - // so will trigger a GOOGLE_DCHECK-failure. - Element* ReleaseCleared(); - - // Removes the element referenced by position. - // - // Returns an iterator to the element immediately following the removed - // element. - // - // Invalidates all iterators at or after the removed element, including end(). - iterator erase(const_iterator position); - - // Removes the elements in the range [first, last). - // - // Returns an iterator to the element immediately following the removed range. - // - // Invalidates all iterators at or after the removed range, including end(). - iterator erase(const_iterator first, const_iterator last); - - // Gets the arena on which this RepeatedPtrField stores its elements. - ::google::protobuf::Arena* GetArena() const { - return GetArenaNoVirtual(); - } - - protected: - // Note: RepeatedPtrField SHOULD NOT be subclassed by users. We only - // subclass it in one place as a hack for compatibility with proto1. The - // subclass needs to know about TypeHandler in order to call protected - // methods on RepeatedPtrFieldBase. - class TypeHandler; - - // Internal arena accessor expected by helpers in Arena. - inline Arena* GetArenaNoVirtual() const; - - private: - // Implementations for ExtractSubrange(). The copying behavior must be - // included only if the type supports the necessary operations (e.g., - // MergeFrom()), so we must resolve this at compile time. ExtractSubrange() - // uses SFINAE to choose one of the below implementations. - void ExtractSubrangeInternal(int start, int num, Element** elements, - google::protobuf::internal::true_type); - void ExtractSubrangeInternal(int start, int num, Element** elements, - google::protobuf::internal::false_type); - - friend class Arena; - typedef void InternalArenaConstructable_; - -}; - -// implementation ==================================================== - -template -inline RepeatedField::RepeatedField() - : current_size_(0), - total_size_(0), - rep_(NULL) { -} - -template -inline RepeatedField::RepeatedField(Arena* arena) - : current_size_(0), - total_size_(0), - rep_(NULL) { - // In case arena is NULL, then we do not create rep_, as code has an invariant - // `rep_ == NULL then arena == NULL`. - if (arena != NULL) { - rep_ = reinterpret_cast( - ::google::protobuf::Arena::CreateArray(arena, kRepHeaderSize)); - rep_->arena = arena; - } -} - -template -inline RepeatedField::RepeatedField(const RepeatedField& other) - : current_size_(0), - total_size_(0), - rep_(NULL) { - CopyFrom(other); -} - -template -template -RepeatedField::RepeatedField(Iter begin, const Iter& end) - : current_size_(0), - total_size_(0), - rep_(NULL) { - int reserve = internal::CalculateReserve(begin, end); - if (reserve != -1) { - Reserve(reserve); - for (; begin != end; ++begin) { - AddAlreadyReserved(*begin); - } - } else { - for (; begin != end; ++begin) { - Add(*begin); - } - } -} - -template -RepeatedField::~RepeatedField() { - // See explanation in Reserve(): we need to invoke destructors here for the - // case that Element has a non-trivial destructor. - InternalDeallocate(rep_, total_size_); -} - -template -inline RepeatedField& -RepeatedField::operator=(const RepeatedField& other) { - if (this != &other) - CopyFrom(other); - return *this; -} - -template -inline bool RepeatedField::empty() const { - return current_size_ == 0; -} - -template -inline int RepeatedField::size() const { - return current_size_; -} - -template -inline int RepeatedField::Capacity() const { - return total_size_; -} - -template -inline void RepeatedField::AddAlreadyReserved(const Element& value) { - GOOGLE_DCHECK_LT(current_size_, total_size_); - rep_->elements[current_size_++] = value; -} - -template -inline Element* RepeatedField::AddAlreadyReserved() { - GOOGLE_DCHECK_LT(current_size_, total_size_); - return &rep_->elements[current_size_++]; -} - -template -inline void RepeatedField::Resize(int new_size, const Element& value) { - GOOGLE_DCHECK_GE(new_size, 0); - if (new_size > current_size_) { - Reserve(new_size); - std::fill(&rep_->elements[current_size_], - &rep_->elements[new_size], value); - } - current_size_ = new_size; -} - -template -inline const Element& RepeatedField::Get(int index) const { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - return rep_->elements[index]; -} - -template -inline Element* RepeatedField::Mutable(int index) { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - return &rep_->elements[index]; -} - -template -inline void RepeatedField::Set(int index, const Element& value) { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - rep_->elements[index] = value; -} - -template -inline void RepeatedField::Add(const Element& value) { - if (current_size_ == total_size_) Reserve(total_size_ + 1); - rep_->elements[current_size_++] = value; -} - -template -inline Element* RepeatedField::Add() { - if (current_size_ == total_size_) Reserve(total_size_ + 1); - return &rep_->elements[current_size_++]; -} - -template -inline void RepeatedField::RemoveLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - current_size_--; -} - -template -void RepeatedField::ExtractSubrange( - int start, int num, Element* elements) { - GOOGLE_DCHECK_GE(start, 0); - GOOGLE_DCHECK_GE(num, 0); - GOOGLE_DCHECK_LE(start + num, this->current_size_); - - // Save the values of the removed elements if requested. - if (elements != NULL) { - for (int i = 0; i < num; ++i) - elements[i] = this->Get(i + start); - } - - // Slide remaining elements down to fill the gap. - if (num > 0) { - for (int i = start + num; i < this->current_size_; ++i) - this->Set(i - num, this->Get(i)); - this->Truncate(this->current_size_ - num); - } -} - -template -inline void RepeatedField::Clear() { - current_size_ = 0; -} - -template -inline void RepeatedField::UnsafeMergeFrom(const RepeatedField& other) { - if (other.current_size_ != 0) { - Reserve(current_size_ + other.current_size_); - CopyArray(rep_->elements + current_size_, - other.rep_->elements, other.current_size_); - current_size_ += other.current_size_; - } -} - -template -inline void RepeatedField::MergeFrom(const RepeatedField& other) { - GOOGLE_CHECK_NE(&other, this); - UnsafeMergeFrom(other); -} - -template -inline void RepeatedField::CopyFrom(const RepeatedField& other) { - if (&other == this) return; - Clear(); - MergeFrom(other); -} - -template -inline typename RepeatedField::iterator RepeatedField::erase( - const_iterator position) { - return erase(position, position + 1); -} - -template -inline typename RepeatedField::iterator RepeatedField::erase( - const_iterator first, const_iterator last) { - size_type first_offset = first - cbegin(); - if (first != last) { - Truncate(std::copy(last, cend(), begin() + first_offset) - cbegin()); - } - return begin() + first_offset; -} - -template -inline Element* RepeatedField::mutable_data() { - return rep_ ? rep_->elements : NULL; -} - -template -inline const Element* RepeatedField::data() const { - return rep_ ? rep_->elements : NULL; -} - - -template -inline void RepeatedField::InternalSwap(RepeatedField* other) { - std::swap(rep_, other->rep_); - std::swap(current_size_, other->current_size_); - std::swap(total_size_, other->total_size_); -} - -template -void RepeatedField::Swap(RepeatedField* other) { - if (this == other) return; - if (GetArenaNoVirtual() == other->GetArenaNoVirtual()) { - InternalSwap(other); - } else { - RepeatedField temp(other->GetArenaNoVirtual()); - temp.MergeFrom(*this); - CopyFrom(*other); - other->UnsafeArenaSwap(&temp); - } -} - -template -void RepeatedField::UnsafeArenaSwap(RepeatedField* other) { - if (this == other) return; - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - InternalSwap(other); -} - -template -void RepeatedField::SwapElements(int index1, int index2) { - using std::swap; // enable ADL with fallback - swap(rep_->elements[index1], rep_->elements[index2]); -} - -template -inline typename RepeatedField::iterator -RepeatedField::begin() { - return rep_ ? rep_->elements : NULL; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::begin() const { - return rep_ ? rep_->elements : NULL; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::cbegin() const { - return rep_ ? rep_->elements : NULL; -} -template -inline typename RepeatedField::iterator -RepeatedField::end() { - return rep_ ? rep_->elements + current_size_ : NULL; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::end() const { - return rep_ ? rep_->elements + current_size_ : NULL; -} -template -inline typename RepeatedField::const_iterator -RepeatedField::cend() const { - return rep_ ? rep_->elements + current_size_ : NULL; -} - -template -inline int RepeatedField::SpaceUsedExcludingSelf() const { - return rep_ ? - (total_size_ * sizeof(Element) + kRepHeaderSize) : 0; -} - -// Avoid inlining of Reserve(): new, copy, and delete[] lead to a significant -// amount of code bloat. -template -void RepeatedField::Reserve(int new_size) { - if (total_size_ >= new_size) return; - Rep* old_rep = rep_; - Arena* arena = GetArenaNoVirtual(); - new_size = std::max(google::protobuf::internal::kMinRepeatedFieldAllocationSize, - std::max(total_size_ * 2, new_size)); - GOOGLE_CHECK_LE(static_cast(new_size), - (std::numeric_limits::max() - kRepHeaderSize) / - sizeof(Element)) - << "Requested size is too large to fit into size_t."; - size_t bytes = kRepHeaderSize + sizeof(Element) * new_size; - if (arena == NULL) { - rep_ = static_cast(::operator new(bytes)); - } else { - rep_ = reinterpret_cast( - ::google::protobuf::Arena::CreateArray(arena, bytes)); - } - rep_->arena = arena; - int old_total_size = total_size_; - total_size_ = new_size; - // Invoke placement-new on newly allocated elements. We shouldn't have to do - // this, since Element is supposed to be POD, but a previous version of this - // code allocated storage with "new Element[size]" and some code uses - // RepeatedField with non-POD types, relying on constructor invocation. If - // Element has a trivial constructor (e.g., int32), gcc (tested with -O2) - // completely removes this loop because the loop body is empty, so this has no - // effect unless its side-effects are required for correctness. - // Note that we do this before MoveArray() below because Element's copy - // assignment implementation will want an initialized instance first. - Element* e = &rep_->elements[0]; - Element* limit = &rep_->elements[total_size_]; - for (; e < limit; e++) { - new (e) Element(); - } - if (current_size_ > 0) { - MoveArray(rep_->elements, old_rep->elements, current_size_); - } - - // Likewise, we need to invoke destructors on the old array. - InternalDeallocate(old_rep, old_total_size); - -} - -template -inline void RepeatedField::Truncate(int new_size) { - GOOGLE_DCHECK_LE(new_size, current_size_); - if (current_size_ > 0) { - current_size_ = new_size; - } -} - -template -inline void RepeatedField::MoveArray( - Element* to, Element* from, int array_size) { - CopyArray(to, from, array_size); -} - -template -inline void RepeatedField::CopyArray( - Element* to, const Element* from, int array_size) { - internal::ElementCopier()(to, from, array_size); -} - -namespace internal { - -template -void ElementCopier::operator()( - Element* to, const Element* from, int array_size) { - std::copy(from, from + array_size, to); -} - -template -struct ElementCopier { - void operator()(Element* to, const Element* from, int array_size) { - memcpy(to, from, array_size * sizeof(Element)); - } -}; - -} // namespace internal - - -// ------------------------------------------------------------------- - -namespace internal { - -inline RepeatedPtrFieldBase::RepeatedPtrFieldBase() - : arena_(NULL), - current_size_(0), - total_size_(0), - rep_(NULL) { -} - -inline RepeatedPtrFieldBase::RepeatedPtrFieldBase(::google::protobuf::Arena* arena) - : arena_(arena), - current_size_(0), - total_size_(0), - rep_(NULL) { -} - -template -void RepeatedPtrFieldBase::Destroy() { - if (rep_ != NULL && arena_ == NULL) { - int n = rep_->allocated_size; - void* const* elements = rep_->elements; - for (int i = 0; i < n; i++) { - TypeHandler::Delete(cast(elements[i]), NULL); - } -#if defined(__GXX_DELETE_WITH_SIZE__) || defined(__cpp_sized_deallocation) - const size_t size = total_size_ * sizeof(elements[0]) + kRepHeaderSize; - ::operator delete(static_cast(rep_), size); -#else - ::operator delete(static_cast(rep_)); -#endif - } - rep_ = NULL; -} - -template -inline void RepeatedPtrFieldBase::Swap(RepeatedPtrFieldBase* other) { - if (other->GetArenaNoVirtual() == GetArenaNoVirtual()) { - InternalSwap(other); - } else { - SwapFallback(other); - } -} - -template -void RepeatedPtrFieldBase::SwapFallback(RepeatedPtrFieldBase* other) { - GOOGLE_DCHECK(other->GetArenaNoVirtual() != GetArenaNoVirtual()); - - // Copy semantics in this case. We try to improve efficiency by placing the - // temporary on |other|'s arena so that messages are copied cross-arena only - // once, not twice. - RepeatedPtrFieldBase temp(other->GetArenaNoVirtual()); - temp.MergeFrom(*this); - this->Clear(); - this->MergeFrom(*other); - other->Clear(); - other->InternalSwap(&temp); - temp.Destroy(); // Frees rep_ if `other` had no arena. -} - -inline bool RepeatedPtrFieldBase::empty() const { - return current_size_ == 0; -} - -inline int RepeatedPtrFieldBase::size() const { - return current_size_; -} - -template -inline const typename TypeHandler::Type& -RepeatedPtrFieldBase::Get(int index) const { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - return *cast(rep_->elements[index]); -} - - -template -inline typename TypeHandler::Type* -RepeatedPtrFieldBase::Mutable(int index) { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - return cast(rep_->elements[index]); -} - -template -inline void RepeatedPtrFieldBase::Delete(int index) { - GOOGLE_DCHECK_GE(index, 0); - GOOGLE_DCHECK_LT(index, current_size_); - TypeHandler::Delete(cast(rep_->elements[index]), arena_); -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::Add( - typename TypeHandler::Type* prototype) { - if (rep_ != NULL && current_size_ < rep_->allocated_size) { - return cast(rep_->elements[current_size_++]); - } - if (!rep_ || rep_->allocated_size == total_size_) { - Reserve(total_size_ + 1); - } - ++rep_->allocated_size; - typename TypeHandler::Type* result = - TypeHandler::NewFromPrototype(prototype, arena_); - rep_->elements[current_size_++] = result; - return result; -} - -template -inline void RepeatedPtrFieldBase::RemoveLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - TypeHandler::Clear(cast(rep_->elements[--current_size_])); -} - -template -void RepeatedPtrFieldBase::Clear() { - const int n = current_size_; - GOOGLE_DCHECK_GE(n, 0); - if (n > 0) { - void* const* elements = rep_->elements; - int i = 0; - do { - TypeHandler::Clear(cast(elements[i++])); - } while (i < n); - current_size_ = 0; - } -} - -// To avoid unnecessary code duplication and reduce binary size, we use a -// layered approach to implementing MergeFrom(). The toplevel method is -// templated, so we get a small thunk per concrete message type in the binary. -// This calls a shared implementation with most of the logic, passing a function -// pointer to another type-specific piece of code that calls the object-allocate -// and merge handlers. -template -inline void RepeatedPtrFieldBase::MergeFrom(const RepeatedPtrFieldBase& other) { - GOOGLE_DCHECK_NE(&other, this); - if (other.current_size_ == 0) return; - MergeFromInternal( - other, &RepeatedPtrFieldBase::MergeFromInnerLoop); -} - -inline void RepeatedPtrFieldBase::MergeFromInternal( - const RepeatedPtrFieldBase& other, - void (RepeatedPtrFieldBase::*inner_loop)(void**, void**, int, int)) { - // Note: wrapper has already guaranteed that other.rep_ != NULL here. - int other_size = other.current_size_; - void** other_elements = other.rep_->elements; - void** new_elements = InternalExtend(other_size); - int allocated_elems = rep_->allocated_size - current_size_; - (this->*inner_loop)(new_elements, other_elements, - other_size, allocated_elems); - current_size_ += other_size; - if (rep_->allocated_size < current_size_) { - rep_->allocated_size = current_size_; - } -} - -// Merges other_elems to our_elems. -template -void RepeatedPtrFieldBase::MergeFromInnerLoop( - void** our_elems, void** other_elems, int length, int already_allocated) { - // Split into two loops, over ranges [0, allocated) and [allocated, length), - // to avoid a branch within the loop. - for (int i = 0; i < already_allocated && i < length; i++) { - // Already allocated: use existing element. - typename TypeHandler::Type* other_elem = - reinterpret_cast(other_elems[i]); - typename TypeHandler::Type* new_elem = - reinterpret_cast(our_elems[i]); - TypeHandler::Merge(*other_elem, new_elem); - } - Arena* arena = GetArenaNoVirtual(); - for (int i = already_allocated; i < length; i++) { - // Not allocated: alloc a new element first, then merge it. - typename TypeHandler::Type* other_elem = - reinterpret_cast(other_elems[i]); - typename TypeHandler::Type* new_elem = - TypeHandler::NewFromPrototype(other_elem, arena); - TypeHandler::Merge(*other_elem, new_elem); - our_elems[i] = new_elem; - } -} - -template -inline void RepeatedPtrFieldBase::CopyFrom(const RepeatedPtrFieldBase& other) { - if (&other == this) return; - RepeatedPtrFieldBase::Clear(); - RepeatedPtrFieldBase::MergeFrom(other); -} - -inline int RepeatedPtrFieldBase::Capacity() const { - return total_size_; -} - -inline void* const* RepeatedPtrFieldBase::raw_data() const { - return rep_ ? rep_->elements : NULL; -} - -inline void** RepeatedPtrFieldBase::raw_mutable_data() const { - return rep_ ? const_cast(rep_->elements) : NULL; -} - -template -inline typename TypeHandler::Type** RepeatedPtrFieldBase::mutable_data() { - // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this - // method entirely. - return reinterpret_cast(raw_mutable_data()); -} - -template -inline const typename TypeHandler::Type* const* -RepeatedPtrFieldBase::data() const { - // TODO(kenton): Breaks C++ aliasing rules. We should probably remove this - // method entirely. - return reinterpret_cast(raw_data()); -} - -inline void RepeatedPtrFieldBase::SwapElements(int index1, int index2) { - using std::swap; // enable ADL with fallback - swap(rep_->elements[index1], rep_->elements[index2]); -} - -template -inline int RepeatedPtrFieldBase::SpaceUsedExcludingSelf() const { - int allocated_bytes = total_size_ * sizeof(void*); - if (rep_ != NULL) { - for (int i = 0; i < rep_->allocated_size; ++i) { - allocated_bytes += TypeHandler::SpaceUsed( - *cast(rep_->elements[i])); - } - allocated_bytes += kRepHeaderSize; - } - return allocated_bytes; -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::AddFromCleared() { - if (rep_ != NULL && current_size_ < rep_->allocated_size) { - return cast(rep_->elements[current_size_++]); - } else { - return NULL; - } -} - -// AddAllocated version that implements arena-safe copying behavior. -template -void RepeatedPtrFieldBase::AddAllocatedInternal( - typename TypeHandler::Type* value, - google::protobuf::internal::true_type) { - Arena* element_arena = reinterpret_cast( - TypeHandler::GetMaybeArenaPointer(value)); - Arena* arena = GetArenaNoVirtual(); - if (arena == element_arena && rep_ && - rep_->allocated_size < total_size_) { - // Fast path: underlying arena representation (tagged pointer) is equal to - // our arena pointer, and we can add to array without resizing it (at least - // one slot that is not allocated). - void** elems = rep_->elements; - if (current_size_ < rep_->allocated_size) { - // Make space at [current] by moving first allocated element to end of - // allocated list. - elems[rep_->allocated_size] = elems[current_size_]; - } - elems[current_size_] = value; - current_size_ = current_size_ + 1; - rep_->allocated_size = rep_->allocated_size + 1; - return; - } else { - AddAllocatedSlowWithCopy( - value, TypeHandler::GetArena(value), arena); - } -} - -// Slowpath handles all cases, copying if necessary. -template -void RepeatedPtrFieldBase::AddAllocatedSlowWithCopy( - // Pass value_arena and my_arena to avoid duplicate virtual call (value) or - // load (mine). - typename TypeHandler::Type* value, Arena* value_arena, Arena* my_arena) { - // Ensure that either the value is in the same arena, or if not, we do the - // appropriate thing: Own() it (if it's on heap and we're in an arena) or copy - // it to our arena/heap (otherwise). - if (my_arena != NULL && value_arena == NULL) { - my_arena->Own(value); - } else if (my_arena != value_arena) { - typename TypeHandler::Type* new_value = - TypeHandler::NewFromPrototype(value, my_arena); - TypeHandler::Merge(*value, new_value); - TypeHandler::Delete(value, value_arena); - value = new_value; - } - - UnsafeArenaAddAllocated(value); -} - -// AddAllocated version that does not implement arena-safe copying behavior. -template -void RepeatedPtrFieldBase::AddAllocatedInternal( - typename TypeHandler::Type* value, - google::protobuf::internal::false_type) { - if (rep_ && rep_->allocated_size < total_size_) { - // Fast path: underlying arena representation (tagged pointer) is equal to - // our arena pointer, and we can add to array without resizing it (at least - // one slot that is not allocated). - void** elems = rep_->elements; - if (current_size_ < rep_->allocated_size) { - // Make space at [current] by moving first allocated element to end of - // allocated list. - elems[rep_->allocated_size] = elems[current_size_]; - } - elems[current_size_] = value; - current_size_ = current_size_ + 1; - ++rep_->allocated_size; - return; - } else { - UnsafeArenaAddAllocated(value); - } -} - -template -void RepeatedPtrFieldBase::UnsafeArenaAddAllocated( - typename TypeHandler::Type* value) { - // Make room for the new pointer. - if (!rep_ || current_size_ == total_size_) { - // The array is completely full with no cleared objects, so grow it. - Reserve(total_size_ + 1); - ++rep_->allocated_size; - } else if (rep_->allocated_size == total_size_) { - // There is no more space in the pointer array because it contains some - // cleared objects awaiting reuse. We don't want to grow the array in this - // case because otherwise a loop calling AddAllocated() followed by Clear() - // would leak memory. - TypeHandler::Delete( - cast(rep_->elements[current_size_]), arena_); - } else if (current_size_ < rep_->allocated_size) { - // We have some cleared objects. We don't care about their order, so we - // can just move the first one to the end to make space. - rep_->elements[rep_->allocated_size] = rep_->elements[current_size_]; - ++rep_->allocated_size; - } else { - // There are no cleared objects. - ++rep_->allocated_size; - } - - rep_->elements[current_size_++] = value; -} - -// ReleaseLast() for types that implement merge/copy behavior. -template -inline typename TypeHandler::Type* -RepeatedPtrFieldBase::ReleaseLastInternal(google::protobuf::internal::true_type) { - // First, release an element. - typename TypeHandler::Type* result = UnsafeArenaReleaseLast(); - // Now perform a copy if we're on an arena. - Arena* arena = GetArenaNoVirtual(); - if (arena == NULL) { - return result; - } else { - typename TypeHandler::Type* new_result = - TypeHandler::NewFromPrototype(result, NULL); - TypeHandler::Merge(*result, new_result); - return new_result; - } -} - -// ReleaseLast() for types that *do not* implement merge/copy behavior -- this -// is the same as UnsafeArenaReleaseLast(). Note that we GOOGLE_DCHECK-fail if we're on -// an arena, since the user really should implement the copy operation in this -// case. -template -inline typename TypeHandler::Type* -RepeatedPtrFieldBase::ReleaseLastInternal(google::protobuf::internal::false_type) { - GOOGLE_DCHECK(GetArenaNoVirtual() == NULL) - << "ReleaseLast() called on a RepeatedPtrField that is on an arena, " - << "with a type that does not implement MergeFrom. This is unsafe; " - << "please implement MergeFrom for your type."; - return UnsafeArenaReleaseLast(); -} - -template -inline typename TypeHandler::Type* - RepeatedPtrFieldBase::UnsafeArenaReleaseLast() { - GOOGLE_DCHECK_GT(current_size_, 0); - typename TypeHandler::Type* result = - cast(rep_->elements[--current_size_]); - --rep_->allocated_size; - if (current_size_ < rep_->allocated_size) { - // There are cleared elements on the end; replace the removed element - // with the last allocated element. - rep_->elements[current_size_] = rep_->elements[rep_->allocated_size]; - } - return result; -} - -inline int RepeatedPtrFieldBase::ClearedCount() const { - return rep_ ? (rep_->allocated_size - current_size_) : 0; -} - -template -inline void RepeatedPtrFieldBase::AddCleared( - typename TypeHandler::Type* value) { - GOOGLE_DCHECK(GetArenaNoVirtual() == NULL) - << "AddCleared() can only be used on a RepeatedPtrField not on an arena."; - GOOGLE_DCHECK(TypeHandler::GetArena(value) == NULL) - << "AddCleared() can only accept values not on an arena."; - if (!rep_ || rep_->allocated_size == total_size_) { - Reserve(total_size_ + 1); - } - rep_->elements[rep_->allocated_size++] = value; -} - -template -inline typename TypeHandler::Type* RepeatedPtrFieldBase::ReleaseCleared() { - GOOGLE_DCHECK(GetArenaNoVirtual() == NULL) - << "ReleaseCleared() can only be used on a RepeatedPtrField not on " - << "an arena."; - GOOGLE_DCHECK(GetArenaNoVirtual() == NULL); - GOOGLE_DCHECK(rep_ != NULL); - GOOGLE_DCHECK_GT(rep_->allocated_size, current_size_); - return cast(rep_->elements[--rep_->allocated_size]); -} - -} // namespace internal - -// ------------------------------------------------------------------- - -template -class RepeatedPtrField::TypeHandler - : public internal::GenericTypeHandler { -}; - -template <> -class RepeatedPtrField::TypeHandler - : public internal::StringTypeHandler { -}; - - -template -inline RepeatedPtrField::RepeatedPtrField() - : RepeatedPtrFieldBase() {} - -template -inline RepeatedPtrField::RepeatedPtrField(::google::protobuf::Arena* arena) : - RepeatedPtrFieldBase(arena) {} - -template -inline RepeatedPtrField::RepeatedPtrField( - const RepeatedPtrField& other) - : RepeatedPtrFieldBase() { - CopyFrom(other); -} - -template -template -inline RepeatedPtrField::RepeatedPtrField( - Iter begin, const Iter& end) { - int reserve = internal::CalculateReserve(begin, end); - if (reserve != -1) { - Reserve(reserve); - } - for (; begin != end; ++begin) { - *Add() = *begin; - } -} - -template -RepeatedPtrField::~RepeatedPtrField() { - Destroy(); -} - -template -inline RepeatedPtrField& RepeatedPtrField::operator=( - const RepeatedPtrField& other) { - if (this != &other) - CopyFrom(other); - return *this; -} - -template -inline bool RepeatedPtrField::empty() const { - return RepeatedPtrFieldBase::empty(); -} - -template -inline int RepeatedPtrField::size() const { - return RepeatedPtrFieldBase::size(); -} - -template -inline const Element& RepeatedPtrField::Get(int index) const { - return RepeatedPtrFieldBase::Get(index); -} - - -template -inline Element* RepeatedPtrField::Mutable(int index) { - return RepeatedPtrFieldBase::Mutable(index); -} - -template -inline Element* RepeatedPtrField::Add() { - return RepeatedPtrFieldBase::Add(); -} - -template -inline void RepeatedPtrField::RemoveLast() { - RepeatedPtrFieldBase::RemoveLast(); -} - -template -inline void RepeatedPtrField::DeleteSubrange(int start, int num) { - GOOGLE_DCHECK_GE(start, 0); - GOOGLE_DCHECK_GE(num, 0); - GOOGLE_DCHECK_LE(start + num, size()); - for (int i = 0; i < num; ++i) { - RepeatedPtrFieldBase::Delete(start + i); - } - ExtractSubrange(start, num, NULL); -} - -template -inline void RepeatedPtrField::ExtractSubrange( - int start, int num, Element** elements) { - typename internal::TypeImplementsMergeBehavior< - typename TypeHandler::Type>::type t; - ExtractSubrangeInternal(start, num, elements, t); -} - -// ExtractSubrange() implementation for types that implement merge/copy -// behavior. -template -inline void RepeatedPtrField::ExtractSubrangeInternal( - int start, int num, Element** elements, google::protobuf::internal::true_type) { - GOOGLE_DCHECK_GE(start, 0); - GOOGLE_DCHECK_GE(num, 0); - GOOGLE_DCHECK_LE(start + num, size()); - - if (num > 0) { - // Save the values of the removed elements if requested. - if (elements != NULL) { - if (GetArenaNoVirtual() != NULL) { - // If we're on an arena, we perform a copy for each element so that the - // returned elements are heap-allocated. - for (int i = 0; i < num; ++i) { - Element* element = RepeatedPtrFieldBase:: - Mutable(i + start); - typename TypeHandler::Type* new_value = - TypeHandler::NewFromPrototype(element, NULL); - TypeHandler::Merge(*element, new_value); - elements[i] = new_value; - } - } else { - for (int i = 0; i < num; ++i) { - elements[i] = RepeatedPtrFieldBase::Mutable(i + start); - } - } - } - CloseGap(start, num); - } -} - -// ExtractSubrange() implementation for types that do not implement merge/copy -// behavior. -template -inline void RepeatedPtrField::ExtractSubrangeInternal( - int start, int num, Element** elements, google::protobuf::internal::false_type) { - // This case is identical to UnsafeArenaExtractSubrange(). However, since - // ExtractSubrange() must return heap-allocated objects by contract, and we - // cannot fulfill this contract if we are an on arena, we must GOOGLE_DCHECK() that - // we are not on an arena. - GOOGLE_DCHECK(GetArenaNoVirtual() == NULL) - << "ExtractSubrange() when arena is non-NULL is only supported when " - << "the Element type supplies a MergeFrom() operation to make copies."; - UnsafeArenaExtractSubrange(start, num, elements); -} - -template -inline void RepeatedPtrField::UnsafeArenaExtractSubrange( - int start, int num, Element** elements) { - GOOGLE_DCHECK_GE(start, 0); - GOOGLE_DCHECK_GE(num, 0); - GOOGLE_DCHECK_LE(start + num, size()); - - if (num > 0) { - // Save the values of the removed elements if requested. - if (elements != NULL) { - for (int i = 0; i < num; ++i) { - elements[i] = RepeatedPtrFieldBase::Mutable(i + start); - } - } - CloseGap(start, num); - } -} - -template -inline void RepeatedPtrField::Clear() { - RepeatedPtrFieldBase::Clear(); -} - -template -inline void RepeatedPtrField::MergeFrom( - const RepeatedPtrField& other) { - RepeatedPtrFieldBase::MergeFrom(other); -} - -template -inline void RepeatedPtrField::CopyFrom( - const RepeatedPtrField& other) { - RepeatedPtrFieldBase::CopyFrom(other); -} - -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::erase(const_iterator position) { - return erase(position, position + 1); -} - -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::erase(const_iterator first, const_iterator last) { - size_type pos_offset = std::distance(cbegin(), first); - size_type last_offset = std::distance(cbegin(), last); - DeleteSubrange(pos_offset, last_offset - pos_offset); - return begin() + pos_offset; -} - -template -inline Element** RepeatedPtrField::mutable_data() { - return RepeatedPtrFieldBase::mutable_data(); -} - -template -inline const Element* const* RepeatedPtrField::data() const { - return RepeatedPtrFieldBase::data(); -} - -template -inline void RepeatedPtrField::Swap(RepeatedPtrField* other) { - if (this == other) - return; - RepeatedPtrFieldBase::Swap(other); -} - -template -inline void RepeatedPtrField::UnsafeArenaSwap( - RepeatedPtrField* other) { - GOOGLE_DCHECK(GetArenaNoVirtual() == other->GetArenaNoVirtual()); - if (this == other) - return; - RepeatedPtrFieldBase::InternalSwap(other); -} - -template -inline void RepeatedPtrField::SwapElements(int index1, int index2) { - RepeatedPtrFieldBase::SwapElements(index1, index2); -} - -template -inline Arena* RepeatedPtrField::GetArenaNoVirtual() const { - return RepeatedPtrFieldBase::GetArenaNoVirtual(); -} - -template -inline int RepeatedPtrField::SpaceUsedExcludingSelf() const { - return RepeatedPtrFieldBase::SpaceUsedExcludingSelf(); -} - -template -inline void RepeatedPtrField::AddAllocated(Element* value) { - RepeatedPtrFieldBase::AddAllocated(value); -} - -template -inline void RepeatedPtrField::UnsafeArenaAddAllocated(Element* value) { - RepeatedPtrFieldBase::UnsafeArenaAddAllocated(value); -} - -template -inline Element* RepeatedPtrField::ReleaseLast() { - return RepeatedPtrFieldBase::ReleaseLast(); -} - -template -inline Element* RepeatedPtrField::UnsafeArenaReleaseLast() { - return RepeatedPtrFieldBase::UnsafeArenaReleaseLast(); -} - -template -inline int RepeatedPtrField::ClearedCount() const { - return RepeatedPtrFieldBase::ClearedCount(); -} - -template -inline void RepeatedPtrField::AddCleared(Element* value) { - return RepeatedPtrFieldBase::AddCleared(value); -} - -template -inline Element* RepeatedPtrField::ReleaseCleared() { - return RepeatedPtrFieldBase::ReleaseCleared(); -} - -template -inline void RepeatedPtrField::Reserve(int new_size) { - return RepeatedPtrFieldBase::Reserve(new_size); -} - -template -inline int RepeatedPtrField::Capacity() const { - return RepeatedPtrFieldBase::Capacity(); -} - -// ------------------------------------------------------------------- - -namespace internal { - -// STL-like iterator implementation for RepeatedPtrField. You should not -// refer to this class directly; use RepeatedPtrField::iterator instead. -// -// The iterator for RepeatedPtrField, RepeatedPtrIterator, is -// very similar to iterator_ptr in util/gtl/iterator_adaptors.h, -// but adds random-access operators and is modified to wrap a void** base -// iterator (since RepeatedPtrField stores its array as a void* array and -// casting void** to T** would violate C++ aliasing rules). -// -// This code based on net/proto/proto-array-internal.h by Jeffrey Yasskin -// (jyasskin@google.com). -template -class RepeatedPtrIterator - : public std::iterator< - std::random_access_iterator_tag, Element> { - public: - typedef RepeatedPtrIterator iterator; - typedef std::iterator< - std::random_access_iterator_tag, Element> superclass; - - // Shadow the value_type in std::iterator<> because const_iterator::value_type - // needs to be T, not const T. - typedef typename remove_const::type value_type; - - // Let the compiler know that these are type names, so we don't have to - // write "typename" in front of them everywhere. - typedef typename superclass::reference reference; - typedef typename superclass::pointer pointer; - typedef typename superclass::difference_type difference_type; - - RepeatedPtrIterator() : it_(NULL) {} - explicit RepeatedPtrIterator(void* const* it) : it_(it) {} - - // Allow "upcasting" from RepeatedPtrIterator to - // RepeatedPtrIterator. - template - RepeatedPtrIterator(const RepeatedPtrIterator& other) - : it_(other.it_) { - // Force a compiler error if the other type is not convertible to ours. - if (false) { - implicit_cast(0); - } - } - - // dereferenceable - reference operator*() const { return *reinterpret_cast(*it_); } - pointer operator->() const { return &(operator*()); } - - // {inc,dec}rementable - iterator& operator++() { ++it_; return *this; } - iterator operator++(int) { return iterator(it_++); } - iterator& operator--() { --it_; return *this; } - iterator operator--(int) { return iterator(it_--); } - - // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } - - // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } - - // addable, subtractable - iterator& operator+=(difference_type d) { - it_ += d; - return *this; - } - friend iterator operator+(iterator it, const difference_type d) { - it += d; - return it; - } - friend iterator operator+(const difference_type d, iterator it) { - it += d; - return it; - } - iterator& operator-=(difference_type d) { - it_ -= d; - return *this; - } - friend iterator operator-(iterator it, difference_type d) { - it -= d; - return it; - } - - // indexable - reference operator[](difference_type d) const { return *(*this + d); } - - // random access iterator - difference_type operator-(const iterator& x) const { return it_ - x.it_; } - - private: - template - friend class RepeatedPtrIterator; - - // The internal iterator. - void* const* it_; -}; - -// Provide an iterator that operates on pointers to the underlying objects -// rather than the objects themselves as RepeatedPtrIterator does. -// Consider using this when working with stl algorithms that change -// the array. -// The VoidPtr template parameter holds the type-agnostic pointer value -// referenced by the iterator. It should either be "void *" for a mutable -// iterator, or "const void *" for a constant iterator. -template -class RepeatedPtrOverPtrsIterator - : public std::iterator { - public: - typedef RepeatedPtrOverPtrsIterator iterator; - typedef std::iterator< - std::random_access_iterator_tag, Element*> superclass; - - // Shadow the value_type in std::iterator<> because const_iterator::value_type - // needs to be T, not const T. - typedef typename remove_const::type value_type; - - // Let the compiler know that these are type names, so we don't have to - // write "typename" in front of them everywhere. - typedef typename superclass::reference reference; - typedef typename superclass::pointer pointer; - typedef typename superclass::difference_type difference_type; - - RepeatedPtrOverPtrsIterator() : it_(NULL) {} - explicit RepeatedPtrOverPtrsIterator(VoidPtr* it) : it_(it) {} - - // dereferenceable - reference operator*() const { return *reinterpret_cast(it_); } - pointer operator->() const { return &(operator*()); } - - // {inc,dec}rementable - iterator& operator++() { ++it_; return *this; } - iterator operator++(int) { return iterator(it_++); } - iterator& operator--() { --it_; return *this; } - iterator operator--(int) { return iterator(it_--); } - - // equality_comparable - bool operator==(const iterator& x) const { return it_ == x.it_; } - bool operator!=(const iterator& x) const { return it_ != x.it_; } - - // less_than_comparable - bool operator<(const iterator& x) const { return it_ < x.it_; } - bool operator<=(const iterator& x) const { return it_ <= x.it_; } - bool operator>(const iterator& x) const { return it_ > x.it_; } - bool operator>=(const iterator& x) const { return it_ >= x.it_; } - - // addable, subtractable - iterator& operator+=(difference_type d) { - it_ += d; - return *this; - } - friend iterator operator+(iterator it, difference_type d) { - it += d; - return it; - } - friend iterator operator+(difference_type d, iterator it) { - it += d; - return it; - } - iterator& operator-=(difference_type d) { - it_ -= d; - return *this; - } - friend iterator operator-(iterator it, difference_type d) { - it -= d; - return it; - } - - // indexable - reference operator[](difference_type d) const { return *(*this + d); } - - // random access iterator - difference_type operator-(const iterator& x) const { return it_ - x.it_; } - - private: - template - friend class RepeatedPtrIterator; - - // The internal iterator. - VoidPtr* it_; -}; - -void RepeatedPtrFieldBase::InternalSwap(RepeatedPtrFieldBase* other) { - std::swap(rep_, other->rep_); - std::swap(current_size_, other->current_size_); - std::swap(total_size_, other->total_size_); -} - -} // namespace internal - -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::begin() { - return iterator(raw_data()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::begin() const { - return iterator(raw_data()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::cbegin() const { - return begin(); -} -template -inline typename RepeatedPtrField::iterator -RepeatedPtrField::end() { - return iterator(raw_data() + size()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::end() const { - return iterator(raw_data() + size()); -} -template -inline typename RepeatedPtrField::const_iterator -RepeatedPtrField::cend() const { - return end(); -} - -template -inline typename RepeatedPtrField::pointer_iterator -RepeatedPtrField::pointer_begin() { - return pointer_iterator(raw_mutable_data()); -} -template -inline typename RepeatedPtrField::const_pointer_iterator -RepeatedPtrField::pointer_begin() const { - return const_pointer_iterator(const_cast(raw_mutable_data())); -} -template -inline typename RepeatedPtrField::pointer_iterator -RepeatedPtrField::pointer_end() { - return pointer_iterator(raw_mutable_data() + size()); -} -template -inline typename RepeatedPtrField::const_pointer_iterator -RepeatedPtrField::pointer_end() const { - return const_pointer_iterator( - const_cast(raw_mutable_data() + size())); -} - - -// Iterators and helper functions that follow the spirit of the STL -// std::back_insert_iterator and std::back_inserter but are tailor-made -// for RepeatedField and RepeatedPtrField. Typical usage would be: -// -// std::copy(some_sequence.begin(), some_sequence.end(), -// google::protobuf::RepeatedFieldBackInserter(proto.mutable_sequence())); -// -// Ported by johannes from util/gtl/proto-array-iterators.h - -namespace internal { -// A back inserter for RepeatedField objects. -template class RepeatedFieldBackInsertIterator - : public std::iterator { - public: - explicit RepeatedFieldBackInsertIterator( - RepeatedField* const mutable_field) - : field_(mutable_field) { - } - RepeatedFieldBackInsertIterator& operator=(const T& value) { - field_->Add(value); - return *this; - } - RepeatedFieldBackInsertIterator& operator*() { - return *this; - } - RepeatedFieldBackInsertIterator& operator++() { - return *this; - } - RepeatedFieldBackInsertIterator& operator++(int /* unused */) { - return *this; - } - - private: - RepeatedField* field_; -}; - -// A back inserter for RepeatedPtrField objects. -template class RepeatedPtrFieldBackInsertIterator - : public std::iterator { - public: - RepeatedPtrFieldBackInsertIterator( - RepeatedPtrField* const mutable_field) - : field_(mutable_field) { - } - RepeatedPtrFieldBackInsertIterator& operator=(const T& value) { - *field_->Add() = value; - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator=( - const T* const ptr_to_value) { - *field_->Add() = *ptr_to_value; - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator*() { - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator++() { - return *this; - } - RepeatedPtrFieldBackInsertIterator& operator++(int /* unused */) { - return *this; - } - - private: - RepeatedPtrField* field_; -}; - -// A back inserter for RepeatedPtrFields that inserts by transferring ownership -// of a pointer. -template class AllocatedRepeatedPtrFieldBackInsertIterator - : public std::iterator { - public: - explicit AllocatedRepeatedPtrFieldBackInsertIterator( - RepeatedPtrField* const mutable_field) - : field_(mutable_field) { - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator=( - T* const ptr_to_value) { - field_->AddAllocated(ptr_to_value); - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator*() { - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator++() { - return *this; - } - AllocatedRepeatedPtrFieldBackInsertIterator& operator++( - int /* unused */) { - return *this; - } - - private: - RepeatedPtrField* field_; -}; - -// Almost identical to AllocatedRepeatedPtrFieldBackInsertIterator. This one -// uses the UnsafeArenaAddAllocated instead. -template -class UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator - : public std::iterator { - public: - explicit UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator( - ::google::protobuf::RepeatedPtrField* const mutable_field) - : field_(mutable_field) { - } - UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator& operator=( - T const* const ptr_to_value) { - field_->UnsafeArenaAddAllocated(const_cast(ptr_to_value)); - return *this; - } - UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator& operator*() { - return *this; - } - UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator& operator++() { - return *this; - } - UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator& operator++( - int /* unused */) { - return *this; - } - - private: - ::google::protobuf::RepeatedPtrField* field_; -}; - -} // namespace internal - -// Provides a back insert iterator for RepeatedField instances, -// similar to std::back_inserter(). -template internal::RepeatedFieldBackInsertIterator -RepeatedFieldBackInserter(RepeatedField* const mutable_field) { - return internal::RepeatedFieldBackInsertIterator(mutable_field); -} - -// Provides a back insert iterator for RepeatedPtrField instances, -// similar to std::back_inserter(). -template internal::RepeatedPtrFieldBackInsertIterator -RepeatedPtrFieldBackInserter(RepeatedPtrField* const mutable_field) { - return internal::RepeatedPtrFieldBackInsertIterator(mutable_field); -} - -// Special back insert iterator for RepeatedPtrField instances, just in -// case someone wants to write generic template code that can access both -// RepeatedFields and RepeatedPtrFields using a common name. -template internal::RepeatedPtrFieldBackInsertIterator -RepeatedFieldBackInserter(RepeatedPtrField* const mutable_field) { - return internal::RepeatedPtrFieldBackInsertIterator(mutable_field); -} - -// Provides a back insert iterator for RepeatedPtrField instances -// similar to std::back_inserter() which transfers the ownership while -// copying elements. -template internal::AllocatedRepeatedPtrFieldBackInsertIterator -AllocatedRepeatedPtrFieldBackInserter( - RepeatedPtrField* const mutable_field) { - return internal::AllocatedRepeatedPtrFieldBackInsertIterator( - mutable_field); -} - -// Similar to AllocatedRepeatedPtrFieldBackInserter, using -// UnsafeArenaAddAllocated instead of AddAllocated. -// This is slightly faster if that matters. It is also useful in legacy code -// that uses temporary ownership to avoid copies. Example: -// RepeatedPtrField temp_field; -// temp_field.AddAllocated(new T); -// ... // Do something with temp_field -// temp_field.ExtractSubrange(0, temp_field.size(), NULL); -// If you put temp_field on the arena this fails, because the ownership -// transfers to the arena at the "AddAllocated" call and is not released anymore -// causing a double delete. Using UnsafeArenaAddAllocated prevents this. -template -internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator -UnsafeArenaAllocatedRepeatedPtrFieldBackInserter( - ::google::protobuf::RepeatedPtrField* const mutable_field) { - return internal::UnsafeArenaAllocatedRepeatedPtrFieldBackInsertIterator( - mutable_field); -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_REPEATED_FIELD_H__ diff --git a/app/src/main/cpp/google/protobuf/service.h b/app/src/main/cpp/google/protobuf/service.h deleted file mode 100644 index ad6f968..0000000 --- a/app/src/main/cpp/google/protobuf/service.h +++ /dev/null @@ -1,292 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// DEPRECATED: This module declares the abstract interfaces underlying proto2 -// RPC services. These are intented to be independent of any particular RPC -// implementation, so that proto2 services can be used on top of a variety -// of implementations. Starting with version 2.3.0, RPC implementations should -// not try to build on these, but should instead provide code generator plugins -// which generate code specific to the particular RPC implementation. This way -// the generated code can be more appropriate for the implementation in use -// and can avoid unnecessary layers of indirection. -// -// -// When you use the protocol compiler to compile a service definition, it -// generates two classes: An abstract interface for the service (with -// methods matching the service definition) and a "stub" implementation. -// A stub is just a type-safe wrapper around an RpcChannel which emulates a -// local implementation of the service. -// -// For example, the service definition: -// service MyService { -// rpc Foo(MyRequest) returns(MyResponse); -// } -// will generate abstract interface "MyService" and class "MyService::Stub". -// You could implement a MyService as follows: -// class MyServiceImpl : public MyService { -// public: -// MyServiceImpl() {} -// ~MyServiceImpl() {} -// -// // implements MyService --------------------------------------- -// -// void Foo(google::protobuf::RpcController* controller, -// const MyRequest* request, -// MyResponse* response, -// Closure* done) { -// // ... read request and fill in response ... -// done->Run(); -// } -// }; -// You would then register an instance of MyServiceImpl with your RPC server -// implementation. (How to do that depends on the implementation.) -// -// To call a remote MyServiceImpl, first you need an RpcChannel connected to it. -// How to construct a channel depends, again, on your RPC implementation. -// Here we use a hypothetical "MyRpcChannel" as an example: -// MyRpcChannel channel("rpc:hostname:1234/myservice"); -// MyRpcController controller; -// MyServiceImpl::Stub stub(&channel); -// FooRequest request; -// FooResponse response; -// -// // ... fill in request ... -// -// stub.Foo(&controller, request, &response, NewCallback(HandleResponse)); -// -// On Thread-Safety: -// -// Different RPC implementations may make different guarantees about what -// threads they may run callbacks on, and what threads the application is -// allowed to use to call the RPC system. Portable software should be ready -// for callbacks to be called on any thread, but should not try to call the -// RPC system from any thread except for the ones on which it received the -// callbacks. Realistically, though, simple software will probably want to -// use a single-threaded RPC system while high-end software will want to -// use multiple threads. RPC implementations should provide multiple -// choices. - -#ifndef GOOGLE_PROTOBUF_SERVICE_H__ -#define GOOGLE_PROTOBUF_SERVICE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - -// Defined in this file. -class Service; -class RpcController; -class RpcChannel; - -// Defined in other files. -class Descriptor; // descriptor.h -class ServiceDescriptor; // descriptor.h -class MethodDescriptor; // descriptor.h -class Message; // message.h - -// Abstract base interface for protocol-buffer-based RPC services. Services -// themselves are abstract interfaces (implemented either by servers or as -// stubs), but they subclass this base interface. The methods of this -// interface can be used to call the methods of the Service without knowing -// its exact type at compile time (analogous to Reflection). -class LIBPROTOBUF_EXPORT Service { - public: - inline Service() {} - virtual ~Service(); - - // When constructing a stub, you may pass STUB_OWNS_CHANNEL as the second - // parameter to the constructor to tell it to delete its RpcChannel when - // destroyed. - enum ChannelOwnership { - STUB_OWNS_CHANNEL, - STUB_DOESNT_OWN_CHANNEL - }; - - // Get the ServiceDescriptor describing this service and its methods. - virtual const ServiceDescriptor* GetDescriptor() = 0; - - // Call a method of the service specified by MethodDescriptor. This is - // normally implemented as a simple switch() that calls the standard - // definitions of the service's methods. - // - // Preconditions: - // * method->service() == GetDescriptor() - // * request and response are of the exact same classes as the objects - // returned by GetRequestPrototype(method) and - // GetResponsePrototype(method). - // * After the call has started, the request must not be modified and the - // response must not be accessed at all until "done" is called. - // * "controller" is of the correct type for the RPC implementation being - // used by this Service. For stubs, the "correct type" depends on the - // RpcChannel which the stub is using. Server-side Service - // implementations are expected to accept whatever type of RpcController - // the server-side RPC implementation uses. - // - // Postconditions: - // * "done" will be called when the method is complete. This may be - // before CallMethod() returns or it may be at some point in the future. - // * If the RPC succeeded, "response" contains the response returned by - // the server. - // * If the RPC failed, "response"'s contents are undefined. The - // RpcController can be queried to determine if an error occurred and - // possibly to get more information about the error. - virtual void CallMethod(const MethodDescriptor* method, - RpcController* controller, - const Message* request, - Message* response, - Closure* done) = 0; - - // CallMethod() requires that the request and response passed in are of a - // particular subclass of Message. GetRequestPrototype() and - // GetResponsePrototype() get the default instances of these required types. - // You can then call Message::New() on these instances to construct mutable - // objects which you can then pass to CallMethod(). - // - // Example: - // const MethodDescriptor* method = - // service->GetDescriptor()->FindMethodByName("Foo"); - // Message* request = stub->GetRequestPrototype (method)->New(); - // Message* response = stub->GetResponsePrototype(method)->New(); - // request->ParseFromString(input); - // service->CallMethod(method, *request, response, callback); - virtual const Message& GetRequestPrototype( - const MethodDescriptor* method) const = 0; - virtual const Message& GetResponsePrototype( - const MethodDescriptor* method) const = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Service); -}; - -// An RpcController mediates a single method call. The primary purpose of -// the controller is to provide a way to manipulate settings specific to the -// RPC implementation and to find out about RPC-level errors. -// -// The methods provided by the RpcController interface are intended to be a -// "least common denominator" set of features which we expect all -// implementations to support. Specific implementations may provide more -// advanced features (e.g. deadline propagation). -class LIBPROTOBUF_EXPORT RpcController { - public: - inline RpcController() {} - virtual ~RpcController(); - - // Client-side methods --------------------------------------------- - // These calls may be made from the client side only. Their results - // are undefined on the server side (may crash). - - // Resets the RpcController to its initial state so that it may be reused in - // a new call. Must not be called while an RPC is in progress. - virtual void Reset() = 0; - - // After a call has finished, returns true if the call failed. The possible - // reasons for failure depend on the RPC implementation. Failed() must not - // be called before a call has finished. If Failed() returns true, the - // contents of the response message are undefined. - virtual bool Failed() const = 0; - - // If Failed() is true, returns a human-readable description of the error. - virtual string ErrorText() const = 0; - - // Advises the RPC system that the caller desires that the RPC call be - // canceled. The RPC system may cancel it immediately, may wait awhile and - // then cancel it, or may not even cancel the call at all. If the call is - // canceled, the "done" callback will still be called and the RpcController - // will indicate that the call failed at that time. - virtual void StartCancel() = 0; - - // Server-side methods --------------------------------------------- - // These calls may be made from the server side only. Their results - // are undefined on the client side (may crash). - - // Causes Failed() to return true on the client side. "reason" will be - // incorporated into the message returned by ErrorText(). If you find - // you need to return machine-readable information about failures, you - // should incorporate it into your response protocol buffer and should - // NOT call SetFailed(). - virtual void SetFailed(const string& reason) = 0; - - // If true, indicates that the client canceled the RPC, so the server may - // as well give up on replying to it. The server should still call the - // final "done" callback. - virtual bool IsCanceled() const = 0; - - // Asks that the given callback be called when the RPC is canceled. The - // callback will always be called exactly once. If the RPC completes without - // being canceled, the callback will be called after completion. If the RPC - // has already been canceled when NotifyOnCancel() is called, the callback - // will be called immediately. - // - // NotifyOnCancel() must be called no more than once per request. - virtual void NotifyOnCancel(Closure* callback) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcController); -}; - -// Abstract interface for an RPC channel. An RpcChannel represents a -// communication line to a Service which can be used to call that Service's -// methods. The Service may be running on another machine. Normally, you -// should not call an RpcChannel directly, but instead construct a stub Service -// wrapping it. Example: -// RpcChannel* channel = new MyRpcChannel("remotehost.example.com:1234"); -// MyService* service = new MyService::Stub(channel); -// service->MyMethod(request, &response, callback); -class LIBPROTOBUF_EXPORT RpcChannel { - public: - inline RpcChannel() {} - virtual ~RpcChannel(); - - // Call the given method of the remote service. The signature of this - // procedure looks the same as Service::CallMethod(), but the requirements - // are less strict in one important way: the request and response objects - // need not be of any specific class as long as their descriptors are - // method->input_type() and method->output_type(). - virtual void CallMethod(const MethodDescriptor* method, - RpcController* controller, - const Message* request, - Message* response, - Closure* done) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RpcChannel); -}; - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_SERVICE_H__ diff --git a/app/src/main/cpp/google/protobuf/source_context.pb.h b/app/src/main/cpp/google/protobuf/source_context.pb.h deleted file mode 100644 index 18a5694..0000000 --- a/app/src/main/cpp/google/protobuf/source_context.pb.h +++ /dev/null @@ -1,198 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/source_context.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fsource_5fcontext_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fsource_5fcontext_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto(); - -class SourceContext; - -// =================================================================== - -class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.SourceContext) */ { - public: - SourceContext(); - virtual ~SourceContext(); - - SourceContext(const SourceContext& from); - - inline SourceContext& operator=(const SourceContext& from) { - CopyFrom(from); - return *this; - } - - static const ::google::protobuf::Descriptor* descriptor(); - static const SourceContext& default_instance(); - - static const SourceContext* internal_default_instance(); - - void Swap(SourceContext* other); - - // implements Message ---------------------------------------------- - - inline SourceContext* New() const { return New(NULL); } - - SourceContext* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const SourceContext& from); - void MergeFrom(const SourceContext& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(SourceContext* other); - void UnsafeMergeFrom(const SourceContext& from); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string file_name = 1; - void clear_file_name(); - static const int kFileNameFieldNumber = 1; - const ::std::string& file_name() const; - void set_file_name(const ::std::string& value); - void set_file_name(const char* value); - void set_file_name(const char* value, size_t size); - ::std::string* mutable_file_name(); - ::std::string* release_file_name(); - void set_allocated_file_name(::std::string* file_name); - - // @@protoc_insertion_point(class_scope:google.protobuf.SourceContext) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - ::google::protobuf::internal::ArenaStringPtr file_name_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fsource_5fcontext_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fsource_5fcontext_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fsource_5fcontext_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fsource_5fcontext_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed SourceContext_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// SourceContext - -// optional string file_name = 1; -inline void SourceContext::clear_file_name() { - file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline const ::std::string& SourceContext::file_name() const { - // @@protoc_insertion_point(field_get:google.protobuf.SourceContext.file_name) - return file_name_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceContext::set_file_name(const ::std::string& value) { - - file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value); - // @@protoc_insertion_point(field_set:google.protobuf.SourceContext.file_name) -} -inline void SourceContext::set_file_name(const char* value) { - - file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value)); - // @@protoc_insertion_point(field_set_char:google.protobuf.SourceContext.file_name) -} -inline void SourceContext::set_file_name(const char* value, size_t size) { - - file_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(reinterpret_cast(value), size)); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.SourceContext.file_name) -} -inline ::std::string* SourceContext::mutable_file_name() { - - // @@protoc_insertion_point(field_mutable:google.protobuf.SourceContext.file_name) - return file_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline ::std::string* SourceContext::release_file_name() { - // @@protoc_insertion_point(field_release:google.protobuf.SourceContext.file_name) - - return file_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); -} -inline void SourceContext::set_allocated_file_name(::std::string* file_name) { - if (file_name != NULL) { - - } else { - - } - file_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), file_name); - // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name) -} - -inline const SourceContext* SourceContext::internal_default_instance() { - return &SourceContext_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fsource_5fcontext_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/source_context.proto b/app/src/main/cpp/google/protobuf/source_context.proto deleted file mode 100644 index 79137ce..0000000 --- a/app/src/main/cpp/google/protobuf/source_context.proto +++ /dev/null @@ -1,47 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "SourceContextProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// `SourceContext` represents information about the source of a -// protobuf element, like the file in which it is defined. -message SourceContext { - // The path-qualified name of the .proto file that contained the associated - // protobuf element. For example: `"google/protobuf/source_context.proto"`. - string file_name = 1; -} diff --git a/app/src/main/cpp/google/protobuf/struct.pb.h b/app/src/main/cpp/google/protobuf/struct.pb.h deleted file mode 100644 index ff77bb4..0000000 --- a/app/src/main/cpp/google/protobuf/struct.pb.h +++ /dev/null @@ -1,971 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/struct.proto - -#ifndef PROTOBUF_google_2fprotobuf_2fstruct_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2fstruct_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); - -class ListValue; -class Struct; -class Value; - -enum NullValue { - NULL_VALUE = 0, - NullValue_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, - NullValue_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max -}; -LIBPROTOBUF_EXPORT bool NullValue_IsValid(int value); -const NullValue NullValue_MIN = NULL_VALUE; -const NullValue NullValue_MAX = NULL_VALUE; -const int NullValue_ARRAYSIZE = NullValue_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* NullValue_descriptor(); -inline const ::std::string& NullValue_Name(NullValue value) { - return ::google::protobuf::internal::NameOfEnum( - NullValue_descriptor(), value); -} -inline bool NullValue_Parse( - const ::std::string& name, NullValue* value) { - return ::google::protobuf::internal::ParseNamedEnum( - NullValue_descriptor(), name, value); -} -// =================================================================== - -class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Struct) */ { - public: - Struct(); - virtual ~Struct(); - - Struct(const Struct& from); - - inline Struct& operator=(const Struct& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Struct& default_instance(); - - static const Struct* internal_default_instance(); - - void UnsafeArenaSwap(Struct* other); - void Swap(Struct* other); - - // implements Message ---------------------------------------------- - - inline Struct* New() const { return New(NULL); } - - Struct* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Struct& from); - void MergeFrom(const Struct& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Struct* other); - void UnsafeMergeFrom(const Struct& from); - protected: - explicit Struct(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - - // accessors ------------------------------------------------------- - - // map fields = 1; - int fields_size() const; - void clear_fields(); - static const int kFieldsFieldNumber = 1; - const ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >& - fields() const; - ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >* - mutable_fields(); - - // @@protoc_insertion_point(class_scope:google.protobuf.Struct) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - typedef ::google::protobuf::internal::MapEntryLite< - ::std::string, ::google::protobuf::Value, - ::google::protobuf::internal::WireFormatLite::TYPE_STRING, - ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, - 0 > - Struct_FieldsEntry; - ::google::protobuf::internal::MapField< - ::std::string, ::google::protobuf::Value, - ::google::protobuf::internal::WireFormatLite::TYPE_STRING, - ::google::protobuf::internal::WireFormatLite::TYPE_MESSAGE, - 0 > fields_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Struct_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Value) */ { - public: - Value(); - virtual ~Value(); - - Value(const Value& from); - - inline Value& operator=(const Value& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Value& default_instance(); - - enum KindCase { - kNullValue = 1, - kNumberValue = 2, - kStringValue = 3, - kBoolValue = 4, - kStructValue = 5, - kListValue = 6, - KIND_NOT_SET = 0, - }; - - static const Value* internal_default_instance(); - - void UnsafeArenaSwap(Value* other); - void Swap(Value* other); - - // implements Message ---------------------------------------------- - - inline Value* New() const { return New(NULL); } - - Value* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Value& from); - void MergeFrom(const Value& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Value* other); - void UnsafeMergeFrom(const Value& from); - protected: - explicit Value(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional .google.protobuf.NullValue null_value = 1; - private: - bool has_null_value() const; - public: - void clear_null_value(); - static const int kNullValueFieldNumber = 1; - ::google::protobuf::NullValue null_value() const; - void set_null_value(::google::protobuf::NullValue value); - - // optional double number_value = 2; - private: - bool has_number_value() const; - public: - void clear_number_value(); - static const int kNumberValueFieldNumber = 2; - double number_value() const; - void set_number_value(double value); - - // optional string string_value = 3; - private: - bool has_string_value() const; - public: - void clear_string_value(); - static const int kStringValueFieldNumber = 3; - const ::std::string& string_value() const; - void set_string_value(const ::std::string& value); - void set_string_value(const char* value); - void set_string_value(const char* value, size_t size); - ::std::string* mutable_string_value(); - ::std::string* release_string_value(); - void set_allocated_string_value(::std::string* string_value); - ::std::string* unsafe_arena_release_string_value(); - void unsafe_arena_set_allocated_string_value( - ::std::string* string_value); - - // optional bool bool_value = 4; - private: - bool has_bool_value() const; - public: - void clear_bool_value(); - static const int kBoolValueFieldNumber = 4; - bool bool_value() const; - void set_bool_value(bool value); - - // optional .google.protobuf.Struct struct_value = 5; - bool has_struct_value() const; - void clear_struct_value(); - static const int kStructValueFieldNumber = 5; - private: - void _slow_mutable_struct_value(); - void _slow_set_allocated_struct_value( - ::google::protobuf::Arena* message_arena, ::google::protobuf::Struct** struct_value); - ::google::protobuf::Struct* _slow_release_struct_value(); - public: - const ::google::protobuf::Struct& struct_value() const; - ::google::protobuf::Struct* mutable_struct_value(); - ::google::protobuf::Struct* release_struct_value(); - void set_allocated_struct_value(::google::protobuf::Struct* struct_value); - ::google::protobuf::Struct* unsafe_arena_release_struct_value(); - void unsafe_arena_set_allocated_struct_value( - ::google::protobuf::Struct* struct_value); - - // optional .google.protobuf.ListValue list_value = 6; - bool has_list_value() const; - void clear_list_value(); - static const int kListValueFieldNumber = 6; - private: - void _slow_mutable_list_value(); - void _slow_set_allocated_list_value( - ::google::protobuf::Arena* message_arena, ::google::protobuf::ListValue** list_value); - ::google::protobuf::ListValue* _slow_release_list_value(); - public: - const ::google::protobuf::ListValue& list_value() const; - ::google::protobuf::ListValue* mutable_list_value(); - ::google::protobuf::ListValue* release_list_value(); - void set_allocated_list_value(::google::protobuf::ListValue* list_value); - ::google::protobuf::ListValue* unsafe_arena_release_list_value(); - void unsafe_arena_set_allocated_list_value( - ::google::protobuf::ListValue* list_value); - - KindCase kind_case() const; - // @@protoc_insertion_point(class_scope:google.protobuf.Value) - private: - inline void set_has_null_value(); - inline void set_has_number_value(); - inline void set_has_string_value(); - inline void set_has_bool_value(); - inline void set_has_struct_value(); - inline void set_has_list_value(); - - inline bool has_kind() const; - void clear_kind(); - inline void clear_has_kind(); - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - union KindUnion { - KindUnion() {} - int null_value_; - double number_value_; - ::google::protobuf::internal::ArenaStringPtr string_value_; - bool bool_value_; - ::google::protobuf::Struct* struct_value_; - ::google::protobuf::ListValue* list_value_; - } kind_; - mutable int _cached_size_; - ::google::protobuf::uint32 _oneof_case_[1]; - - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Value_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ListValue) */ { - public: - ListValue(); - virtual ~ListValue(); - - ListValue(const ListValue& from); - - inline ListValue& operator=(const ListValue& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const ListValue& default_instance(); - - static const ListValue* internal_default_instance(); - - void UnsafeArenaSwap(ListValue* other); - void Swap(ListValue* other); - - // implements Message ---------------------------------------------- - - inline ListValue* New() const { return New(NULL); } - - ListValue* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const ListValue& from); - void MergeFrom(const ListValue& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(ListValue* other); - void UnsafeMergeFrom(const ListValue& from); - protected: - explicit ListValue(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // repeated .google.protobuf.Value values = 1; - int values_size() const; - void clear_values(); - static const int kValuesFieldNumber = 1; - const ::google::protobuf::Value& values(int index) const; - ::google::protobuf::Value* mutable_values(int index); - ::google::protobuf::Value* add_values(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value >* - mutable_values(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value >& - values() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.ListValue) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value > values_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2fstruct_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2fstruct_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2fstruct_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed ListValue_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Struct - -// map fields = 1; -inline int Struct::fields_size() const { - return fields_.size(); -} -inline void Struct::clear_fields() { - fields_.Clear(); -} -inline const ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >& -Struct::fields() const { - // @@protoc_insertion_point(field_map:google.protobuf.Struct.fields) - return fields_.GetMap(); -} -inline ::google::protobuf::Map< ::std::string, ::google::protobuf::Value >* -Struct::mutable_fields() { - // @@protoc_insertion_point(field_mutable_map:google.protobuf.Struct.fields) - return fields_.MutableMap(); -} - -inline const Struct* Struct::internal_default_instance() { - return &Struct_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// Value - -// optional .google.protobuf.NullValue null_value = 1; -inline bool Value::has_null_value() const { - return kind_case() == kNullValue; -} -inline void Value::set_has_null_value() { - _oneof_case_[0] = kNullValue; -} -inline void Value::clear_null_value() { - if (has_null_value()) { - kind_.null_value_ = 0; - clear_has_kind(); - } -} -inline ::google::protobuf::NullValue Value::null_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.null_value) - if (has_null_value()) { - return static_cast< ::google::protobuf::NullValue >(kind_.null_value_); - } - return static_cast< ::google::protobuf::NullValue >(0); -} -inline void Value::set_null_value(::google::protobuf::NullValue value) { - if (!has_null_value()) { - clear_kind(); - set_has_null_value(); - } - kind_.null_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Value.null_value) -} - -// optional double number_value = 2; -inline bool Value::has_number_value() const { - return kind_case() == kNumberValue; -} -inline void Value::set_has_number_value() { - _oneof_case_[0] = kNumberValue; -} -inline void Value::clear_number_value() { - if (has_number_value()) { - kind_.number_value_ = 0; - clear_has_kind(); - } -} -inline double Value::number_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.number_value) - if (has_number_value()) { - return kind_.number_value_; - } - return 0; -} -inline void Value::set_number_value(double value) { - if (!has_number_value()) { - clear_kind(); - set_has_number_value(); - } - kind_.number_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Value.number_value) -} - -// optional string string_value = 3; -inline bool Value::has_string_value() const { - return kind_case() == kStringValue; -} -inline void Value::set_has_string_value() { - _oneof_case_[0] = kStringValue; -} -inline void Value::clear_string_value() { - if (has_string_value()) { - kind_.string_value_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); - clear_has_kind(); - } -} -inline const ::std::string& Value::string_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.string_value) - if (has_string_value()) { - return kind_.string_value_.Get(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - return *&::google::protobuf::internal::GetEmptyStringAlreadyInited(); -} -inline void Value::set_string_value(const ::std::string& value) { - if (!has_string_value()) { - clear_kind(); - set_has_string_value(); - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, - GetArenaNoVirtual()); - // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) -} -inline void Value::set_string_value(const char* value) { - if (!has_string_value()) { - clear_kind(); - set_has_string_value(); - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - ::std::string(value), GetArenaNoVirtual()); - // @@protoc_insertion_point(field_set_char:google.protobuf.Value.string_value) -} -inline void Value::set_string_value(const char* value, - size_t size) { - if (!has_string_value()) { - clear_kind(); - set_has_string_value(); - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - kind_.string_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), - GetArenaNoVirtual()); - // @@protoc_insertion_point(field_set_pointer:google.protobuf.Value.string_value) -} -inline ::std::string* Value::mutable_string_value() { - if (!has_string_value()) { - clear_kind(); - set_has_string_value(); - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - return kind_.string_value_.Mutable(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); - // @@protoc_insertion_point(field_mutable:google.protobuf.Value.string_value) -} -inline ::std::string* Value::release_string_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Value.string_value) - if (has_string_value()) { - clear_has_kind(); - return kind_.string_value_.Release(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), - GetArenaNoVirtual()); - } else { - return NULL; - } -} -inline ::std::string* Value::unsafe_arena_release_string_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.string_value) - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - if (has_string_value()) { - clear_has_kind(); - return kind_.string_value_.UnsafeArenaRelease( - &::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); - } else { - return NULL; - } -} -inline void Value::set_allocated_string_value(::std::string* string_value) { - if (!has_string_value()) { - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - clear_kind(); - if (string_value != NULL) { - set_has_string_value(); - kind_.string_value_.SetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, - GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.string_value) -} -inline void Value::unsafe_arena_set_allocated_string_value(::std::string* string_value) { - GOOGLE_DCHECK(GetArenaNoVirtual() != NULL); - if (!has_string_value()) { - kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - } - clear_kind(); - if (string_value) { - set_has_string_value(); - kind_.string_value_.UnsafeArenaSetAllocated(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), string_value, GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.string_value) -} - -// optional bool bool_value = 4; -inline bool Value::has_bool_value() const { - return kind_case() == kBoolValue; -} -inline void Value::set_has_bool_value() { - _oneof_case_[0] = kBoolValue; -} -inline void Value::clear_bool_value() { - if (has_bool_value()) { - kind_.bool_value_ = false; - clear_has_kind(); - } -} -inline bool Value::bool_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.bool_value) - if (has_bool_value()) { - return kind_.bool_value_; - } - return false; -} -inline void Value::set_bool_value(bool value) { - if (!has_bool_value()) { - clear_kind(); - set_has_bool_value(); - } - kind_.bool_value_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Value.bool_value) -} - -// optional .google.protobuf.Struct struct_value = 5; -inline bool Value::has_struct_value() const { - return kind_case() == kStructValue; -} -inline void Value::set_has_struct_value() { - _oneof_case_[0] = kStructValue; -} -inline void Value::clear_struct_value() { - if (has_struct_value()) { - if (GetArenaNoVirtual() == NULL) { - delete kind_.struct_value_; - } - clear_has_kind(); - } -} -inline const ::google::protobuf::Struct& Value::struct_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.struct_value) - return has_struct_value() - ? *kind_.struct_value_ - : ::google::protobuf::Struct::default_instance(); -} -inline ::google::protobuf::Struct* Value::mutable_struct_value() { - if (!has_struct_value()) { - clear_kind(); - set_has_struct_value(); - kind_.struct_value_ = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( - GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_mutable:google.protobuf.Value.struct_value) - return kind_.struct_value_; -} -inline ::google::protobuf::Struct* Value::release_struct_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Value.struct_value) - if (has_struct_value()) { - clear_has_kind(); - if (GetArenaNoVirtual() != NULL) { - ::google::protobuf::Struct* temp = new ::google::protobuf::Struct(*kind_.struct_value_); - kind_.struct_value_ = NULL; - return temp; - } else { - ::google::protobuf::Struct* temp = kind_.struct_value_; - kind_.struct_value_ = NULL; - return temp; - } - } else { - return NULL; - } -} -inline void Value::set_allocated_struct_value(::google::protobuf::Struct* struct_value) { - clear_kind(); - if (struct_value) { - if (GetArenaNoVirtual() != NULL && - ::google::protobuf::Arena::GetArena(struct_value) == NULL) { - GetArenaNoVirtual()->Own(struct_value); - } else if (GetArenaNoVirtual() != - ::google::protobuf::Arena::GetArena(struct_value)) { - ::google::protobuf::Struct* new_struct_value = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::Struct >( - GetArenaNoVirtual()); - new_struct_value->CopyFrom(*struct_value); - struct_value = new_struct_value; - } - set_has_struct_value(); - kind_.struct_value_ = struct_value; - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.struct_value) -} -inline ::google::protobuf::Struct* Value::unsafe_arena_release_struct_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.struct_value) - if (has_struct_value()) { - clear_has_kind(); - ::google::protobuf::Struct* temp = kind_.struct_value_; - kind_.struct_value_ = NULL; - return temp; - } else { - return NULL; - } -} -inline void Value::unsafe_arena_set_allocated_struct_value(::google::protobuf::Struct* struct_value) { - clear_kind(); - if (struct_value) { - set_has_struct_value(); - kind_.struct_value_ = struct_value; - } - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.struct_value) -} - -// optional .google.protobuf.ListValue list_value = 6; -inline bool Value::has_list_value() const { - return kind_case() == kListValue; -} -inline void Value::set_has_list_value() { - _oneof_case_[0] = kListValue; -} -inline void Value::clear_list_value() { - if (has_list_value()) { - if (GetArenaNoVirtual() == NULL) { - delete kind_.list_value_; - } - clear_has_kind(); - } -} -inline const ::google::protobuf::ListValue& Value::list_value() const { - // @@protoc_insertion_point(field_get:google.protobuf.Value.list_value) - return has_list_value() - ? *kind_.list_value_ - : ::google::protobuf::ListValue::default_instance(); -} -inline ::google::protobuf::ListValue* Value::mutable_list_value() { - if (!has_list_value()) { - clear_kind(); - set_has_list_value(); - kind_.list_value_ = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( - GetArenaNoVirtual()); - } - // @@protoc_insertion_point(field_mutable:google.protobuf.Value.list_value) - return kind_.list_value_; -} -inline ::google::protobuf::ListValue* Value::release_list_value() { - // @@protoc_insertion_point(field_release:google.protobuf.Value.list_value) - if (has_list_value()) { - clear_has_kind(); - if (GetArenaNoVirtual() != NULL) { - ::google::protobuf::ListValue* temp = new ::google::protobuf::ListValue(*kind_.list_value_); - kind_.list_value_ = NULL; - return temp; - } else { - ::google::protobuf::ListValue* temp = kind_.list_value_; - kind_.list_value_ = NULL; - return temp; - } - } else { - return NULL; - } -} -inline void Value::set_allocated_list_value(::google::protobuf::ListValue* list_value) { - clear_kind(); - if (list_value) { - if (GetArenaNoVirtual() != NULL && - ::google::protobuf::Arena::GetArena(list_value) == NULL) { - GetArenaNoVirtual()->Own(list_value); - } else if (GetArenaNoVirtual() != - ::google::protobuf::Arena::GetArena(list_value)) { - ::google::protobuf::ListValue* new_list_value = - ::google::protobuf::Arena::CreateMessage< ::google::protobuf::ListValue >( - GetArenaNoVirtual()); - new_list_value->CopyFrom(*list_value); - list_value = new_list_value; - } - set_has_list_value(); - kind_.list_value_ = list_value; - } - // @@protoc_insertion_point(field_set_allocated:google.protobuf.Value.list_value) -} -inline ::google::protobuf::ListValue* Value::unsafe_arena_release_list_value() { - // @@protoc_insertion_point(field_unsafe_arena_release:google.protobuf.Value.list_value) - if (has_list_value()) { - clear_has_kind(); - ::google::protobuf::ListValue* temp = kind_.list_value_; - kind_.list_value_ = NULL; - return temp; - } else { - return NULL; - } -} -inline void Value::unsafe_arena_set_allocated_list_value(::google::protobuf::ListValue* list_value) { - clear_kind(); - if (list_value) { - set_has_list_value(); - kind_.list_value_ = list_value; - } - // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.Value.list_value) -} - -inline bool Value::has_kind() const { - return kind_case() != KIND_NOT_SET; -} -inline void Value::clear_has_kind() { - _oneof_case_[0] = KIND_NOT_SET; -} -inline Value::KindCase Value::kind_case() const { - return Value::KindCase(_oneof_case_[0]); -} -inline const Value* Value::internal_default_instance() { - return &Value_default_instance_.get(); -} -// ------------------------------------------------------------------- - -// ListValue - -// repeated .google.protobuf.Value values = 1; -inline int ListValue::values_size() const { - return values_.size(); -} -inline void ListValue::clear_values() { - values_.Clear(); -} -inline const ::google::protobuf::Value& ListValue::values(int index) const { - // @@protoc_insertion_point(field_get:google.protobuf.ListValue.values) - return values_.Get(index); -} -inline ::google::protobuf::Value* ListValue::mutable_values(int index) { - // @@protoc_insertion_point(field_mutable:google.protobuf.ListValue.values) - return values_.Mutable(index); -} -inline ::google::protobuf::Value* ListValue::add_values() { - // @@protoc_insertion_point(field_add:google.protobuf.ListValue.values) - return values_.Add(); -} -inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value >* -ListValue::mutable_values() { - // @@protoc_insertion_point(field_mutable_list:google.protobuf.ListValue.values) - return &values_; -} -inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value >& -ListValue::values() const { - // @@protoc_insertion_point(field_list:google.protobuf.ListValue.values) - return values_; -} - -inline const ListValue* ListValue::internal_default_instance() { - return &ListValue_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -#ifndef SWIG -namespace google { -namespace protobuf { - -template <> struct is_proto_enum< ::google::protobuf::NullValue> : ::google::protobuf::internal::true_type {}; -template <> -inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::NullValue>() { - return ::google::protobuf::NullValue_descriptor(); -} - -} // namespace protobuf -} // namespace google -#endif // SWIG - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2fstruct_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/struct.proto b/app/src/main/cpp/google/protobuf/struct.proto deleted file mode 100644 index 7d7808e..0000000 --- a/app/src/main/cpp/google/protobuf/struct.proto +++ /dev/null @@ -1,96 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/struct;structpb"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "StructProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - - -// `Struct` represents a structured data value, consisting of fields -// which map to dynamically typed values. In some languages, `Struct` -// might be supported by a native representation. For example, in -// scripting languages like JS a struct is represented as an -// object. The details of that representation are described together -// with the proto support for the language. -// -// The JSON representation for `Struct` is JSON object. -message Struct { - // Unordered map of dynamically typed values. - map fields = 1; -} - -// `Value` represents a dynamically typed value which can be either -// null, a number, a string, a boolean, a recursive struct value, or a -// list of values. A producer of value is expected to set one of that -// variants, absence of any variant indicates an error. -// -// The JSON representation for `Value` is JSON value. -message Value { - // The kind of value. - oneof kind { - // Represents a null value. - NullValue null_value = 1; - // Represents a double value. - double number_value = 2; - // Represents a string value. - string string_value = 3; - // Represents a boolean value. - bool bool_value = 4; - // Represents a structured value. - Struct struct_value = 5; - // Represents a repeated `Value`. - ListValue list_value = 6; - } -} - -// `NullValue` is a singleton enumeration to represent the null value for the -// `Value` type union. -// -// The JSON representation for `NullValue` is JSON `null`. -enum NullValue { - // Null value. - NULL_VALUE = 0; -} - -// `ListValue` is a wrapper around a repeated field of values. -// -// The JSON representation for `ListValue` is JSON array. -message ListValue { - // Repeated field of dynamically typed values. - repeated Value values = 1; -} diff --git a/app/src/main/cpp/google/protobuf/stubs/atomic_sequence_num.h b/app/src/main/cpp/google/protobuf/stubs/atomic_sequence_num.h deleted file mode 100644 index bb20942..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomic_sequence_num.h +++ /dev/null @@ -1,54 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef GOOGLE_PROTOBUF_ATOMIC_SEQUENCE_NUM_H_ -#define GOOGLE_PROTOBUF_ATOMIC_SEQUENCE_NUM_H_ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -class SequenceNumber { - public: - SequenceNumber() : word_(0) {} - - AtomicWord GetNext() { - return NoBarrier_AtomicIncrement(&word_, 1) - 1; - } - private: - AtomicWord word_; -}; - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMIC_SEQUENCE_NUM_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops.h b/app/src/main/cpp/google/protobuf/stubs/atomicops.h deleted file mode 100644 index 9b3d1e6..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops.h +++ /dev/null @@ -1,246 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// The routines exported by this module are subtle. If you use them, even if -// you get the code right, it will depend on careful reasoning about atomicity -// and memory ordering; it will be less readable, and harder to maintain. If -// you plan to use these routines, you should have a good reason, such as solid -// evidence that performance would otherwise suffer, or there being no -// alternative. You should assume only properties explicitly guaranteed by the -// specifications in this file. You are almost certainly _not_ writing code -// just for the x86; if you assume x86 semantics, x86 hardware bugs and -// implementations on other archtectures will cause your code to break. If you -// do not know what you are doing, avoid these routines, and use a Mutex. -// -// It is incorrect to make direct assignments to/from an atomic variable. -// You should use one of the Load or Store routines. The NoBarrier -// versions are provided when no barriers are needed: -// NoBarrier_Store() -// NoBarrier_Load() -// Although there are currently no compiler enforcement, you are encouraged -// to use these. - -// This header and the implementations for each platform (located in -// atomicops_internals_*) must be kept in sync with the upstream code (V8). - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_H_ - -// Don't include this file for people not concerned about thread safety. -#ifndef GOOGLE_PROTOBUF_NO_THREAD_SAFETY - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -#if defined(GOOGLE_PROTOBUF_ARCH_POWER) -#if defined(_LP64) || defined(__LP64__) -typedef int32 Atomic32; -typedef intptr_t Atomic64; -#else -typedef intptr_t Atomic32; -typedef int64 Atomic64; -#endif -#else -typedef int32 Atomic32; -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT -// We need to be able to go between Atomic64 and AtomicWord implicitly. This -// means Atomic64 and AtomicWord should be the same type on 64-bit. -#if defined(__ILP32__) || defined(GOOGLE_PROTOBUF_OS_NACL) -// NaCl's intptr_t is not actually 64-bits on 64-bit! -// http://code.google.com/p/nativeclient/issues/detail?id=1162 -// sparcv9's pointer type is 32bits -typedef int64 Atomic64; -#else -typedef intptr_t Atomic64; -#endif -#endif -#endif - -// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or -// Atomic64 routines below, depending on your architecture. -typedef intptr_t AtomicWord; - -// Atomically execute: -// result = *ptr; -// if (*ptr == old_value) -// *ptr = new_value; -// return result; -// -// I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value". -// Always return the old value of "*ptr" -// -// This routine implies no memory barriers. -Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value); - -// Atomically store new_value into *ptr, returning the previous value held in -// *ptr. This routine implies no memory barriers. -Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, Atomic32 new_value); - -// Atomically increment *ptr by "increment". Returns the new value of -// *ptr with the increment applied. This routine implies no memory barriers. -Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, Atomic32 increment); - -Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment); - -// These following lower-level operations are typically useful only to people -// implementing higher-level synchronization operations like spinlocks, -// mutexes, and condition-variables. They combine CompareAndSwap(), a load, or -// a store with appropriate memory-ordering instructions. "Acquire" operations -// ensure that no later memory access can be reordered ahead of the operation. -// "Release" operations ensure that no previous memory access can be reordered -// after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. -Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value); -Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value); - -#if defined(__MINGW32__) && defined(MemoryBarrier) -#undef MemoryBarrier -#endif -void MemoryBarrier(); -void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value); -void Acquire_Store(volatile Atomic32* ptr, Atomic32 value); -void Release_Store(volatile Atomic32* ptr, Atomic32 value); - -Atomic32 NoBarrier_Load(volatile const Atomic32* ptr); -Atomic32 Acquire_Load(volatile const Atomic32* ptr); -Atomic32 Release_Load(volatile const Atomic32* ptr); - -// 64-bit atomic operations (only available on 64-bit processors). -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT -Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value); -Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value); -Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment); -Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment); - -Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value); -Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value); -void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value); -void Acquire_Store(volatile Atomic64* ptr, Atomic64 value); -void Release_Store(volatile Atomic64* ptr, Atomic64 value); -Atomic64 NoBarrier_Load(volatile const Atomic64* ptr); -Atomic64 Acquire_Load(volatile const Atomic64* ptr); -Atomic64 Release_Load(volatile const Atomic64* ptr); -#endif // GOOGLE_PROTOBUF_ARCH_64_BIT - -} // namespace internal -} // namespace protobuf -} // namespace google - -// Include our platform specific implementation. -#define GOOGLE_PROTOBUF_ATOMICOPS_ERROR \ -"Atomic operations are not supported on your platform" - -// ThreadSanitizer, http://clang.llvm.org/docs/ThreadSanitizer.html. -#if defined(THREAD_SANITIZER) -#include -// MSVC. -#elif defined(_MSC_VER) -#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) -#include -#else -#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR -#endif - -// Solaris -#elif defined(GOOGLE_PROTOBUF_OS_SOLARIS) -#include - -// AIX -#elif defined(GOOGLE_PROTOBUF_OS_AIX) -#include - -// Apple. -#elif defined(GOOGLE_PROTOBUF_OS_APPLE) -#include - -// GCC. -#elif defined(__GNUC__) -#if defined(GOOGLE_PROTOBUF_ARCH_IA32) || defined(GOOGLE_PROTOBUF_ARCH_X64) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_ARM) && defined(__linux__) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_AARCH64) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_ARM_QNX) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_MIPS) || defined(GOOGLE_PROTOBUF_ARCH_MIPS64) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_POWER) -#include -#elif defined(__native_client__) -#include -#elif defined(GOOGLE_PROTOBUF_ARCH_PPC) -#include -#elif (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) -#include -#elif defined(__clang__) -#if __has_extension(c_atomic) -#include -#else -#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR -#endif -#else -#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR -#endif - -// Unknown. -#else -#error GOOGLE_PROTOBUF_ATOMICOPS_ERROR -#endif - -// On some platforms we need additional declarations to make AtomicWord -// compatible with our other Atomic* types. -#if defined(GOOGLE_PROTOBUF_OS_APPLE) -#include -#endif - -#undef GOOGLE_PROTOBUF_ATOMICOPS_ERROR - -#endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm64_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm64_gcc.h deleted file mode 100644 index 0a2d2b8..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +++ /dev/null @@ -1,325 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM64_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM64_GCC_H_ - -namespace google { -namespace protobuf { -namespace internal { - -inline void MemoryBarrier() { - __asm__ __volatile__ ("dmb ish" ::: "memory"); // NOLINT -} - -// NoBarrier versions of the operation include "memory" in the clobber list. -// This is not required for direct usage of the NoBarrier versions of the -// operations. However this is required for correctness when they are used as -// part of the Acquire or Release versions, to ensure that nothing from outside -// the call is reordered between the operation and the memory barrier. This does -// not change the code generated, so has no or minimal impact on the -// NoBarrier operations. - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %w[prev], %[ptr] \n\t" // Load the previous value. - "cmp %w[prev], %w[old_value] \n\t" - "bne 1f \n\t" - "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value. - "cbnz %w[temp], 0b \n\t" // Retry if it did not work. - "1: \n\t" - : [prev]"=&r" (prev), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [old_value]"IJr" (old_value), - [new_value]"r" (new_value) - : "cc", "memory" - ); // NOLINT - - return prev; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 result; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %w[result], %[ptr] \n\t" // Load the previous value. - "stxr %w[temp], %w[new_value], %[ptr] \n\t" // Try to store the new value. - "cbnz %w[temp], 0b \n\t" // Retry if it did not work. - : [result]"=&r" (result), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [new_value]"r" (new_value) - : "memory" - ); // NOLINT - - return result; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 result; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %w[result], %[ptr] \n\t" // Load the previous value. - "add %w[result], %w[result], %w[increment]\n\t" - "stxr %w[temp], %w[result], %[ptr] \n\t" // Try to store the result. - "cbnz %w[temp], 0b \n\t" // Retry on failure. - : [result]"=&r" (result), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [increment]"IJr" (increment) - : "memory" - ); // NOLINT - - return result; -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - MemoryBarrier(); - Atomic32 result = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); - - return result; -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - - return prev; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - MemoryBarrier(); - Atomic32 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - - return prev; -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - __asm__ __volatile__ ( // NOLINT - "stlr %w[value], %[ptr] \n\t" - : [ptr]"=Q" (*ptr) - : [value]"r" (value) - : "memory" - ); // NOLINT -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value; - - __asm__ __volatile__ ( // NOLINT - "ldar %w[value], %[ptr] \n\t" - : [value]"=r" (value) - : [ptr]"Q" (*ptr) - : "memory" - ); // NOLINT - - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -// 64-bit versions of the operations. -// See the 32-bit versions for comments. - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %[prev], %[ptr] \n\t" - "cmp %[prev], %[old_value] \n\t" - "bne 1f \n\t" - "stxr %w[temp], %[new_value], %[ptr] \n\t" - "cbnz %w[temp], 0b \n\t" - "1: \n\t" - : [prev]"=&r" (prev), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [old_value]"IJr" (old_value), - [new_value]"r" (new_value) - : "cc", "memory" - ); // NOLINT - - return prev; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - Atomic64 result; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %[result], %[ptr] \n\t" - "stxr %w[temp], %[new_value], %[ptr] \n\t" - "cbnz %w[temp], 0b \n\t" - : [result]"=&r" (result), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [new_value]"r" (new_value) - : "memory" - ); // NOLINT - - return result; -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - Atomic64 result; - int32_t temp; - - __asm__ __volatile__ ( // NOLINT - "0: \n\t" - "ldxr %[result], %[ptr] \n\t" - "add %[result], %[result], %[increment] \n\t" - "stxr %w[temp], %[result], %[ptr] \n\t" - "cbnz %w[temp], 0b \n\t" - : [result]"=&r" (result), - [temp]"=&r" (temp), - [ptr]"+Q" (*ptr) - : [increment]"IJr" (increment) - : "memory" - ); // NOLINT - - return result; -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - MemoryBarrier(); - Atomic64 result = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); - - return result; -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - - return prev; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - MemoryBarrier(); - Atomic64 prev = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - - return prev; -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - __asm__ __volatile__ ( // NOLINT - "stlr %x[value], %[ptr] \n\t" - : [ptr]"=Q" (*ptr) - : [value]"r" (value) - : "memory" - ); // NOLINT -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 value; - - __asm__ __volatile__ ( // NOLINT - "ldar %x[value], %[ptr] \n\t" - : [value]"=r" (value) - : [ptr]"Q" (*ptr) - : "memory" - ); // NOLINT - - return value; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return *ptr; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM64_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_gcc.h deleted file mode 100644 index 90e727b..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_gcc.h +++ /dev/null @@ -1,151 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. -// -// LinuxKernelCmpxchg and Barrier_AtomicIncrement are from Google Gears. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_GCC_H_ - -namespace google { -namespace protobuf { -namespace internal { - -// 0xffff0fc0 is the hard coded address of a function provided by -// the kernel which implements an atomic compare-exchange. On older -// ARM architecture revisions (pre-v6) this may be implemented using -// a syscall. This address is stable, and in active use (hard coded) -// by at least glibc-2.7 and the Android C library. -typedef Atomic32 (*LinuxKernelCmpxchgFunc)(Atomic32 old_value, - Atomic32 new_value, - volatile Atomic32* ptr); -LinuxKernelCmpxchgFunc pLinuxKernelCmpxchg __attribute__((weak)) = - (LinuxKernelCmpxchgFunc) 0xffff0fc0; - -typedef void (*LinuxKernelMemoryBarrierFunc)(void); -LinuxKernelMemoryBarrierFunc pLinuxKernelMemoryBarrier __attribute__((weak)) = - (LinuxKernelMemoryBarrierFunc) 0xffff0fa0; - - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev_value = *ptr; - do { - if (!pLinuxKernelCmpxchg(old_value, new_value, - const_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 old_value; - do { - old_value = *ptr; - } while (pLinuxKernelCmpxchg(old_value, new_value, - const_cast(ptr))); - return old_value; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return Barrier_AtomicIncrement(ptr, increment); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - for (;;) { - // Atomic exchange the old value with an incremented one. - Atomic32 old_value = *ptr; - Atomic32 new_value = old_value + increment; - if (pLinuxKernelCmpxchg(old_value, new_value, - const_cast(ptr)) == 0) { - // The exchange took place as expected. - return new_value; - } - // Otherwise, *ptr changed mid-loop and we need to retry. - } -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void MemoryBarrier() { - pLinuxKernelMemoryBarrier(); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_qnx.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_qnx.h deleted file mode 100644 index 17dfaa5..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_arm_qnx.h +++ /dev/null @@ -1,146 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_ - -// For _smp_cmpxchg() -#include - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 QNXCmpxchg(Atomic32 old_value, - Atomic32 new_value, - volatile Atomic32* ptr) { - return static_cast( - _smp_cmpxchg((volatile unsigned *)ptr, - (unsigned)old_value, - (unsigned)new_value)); -} - - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev_value = *ptr; - do { - if (!QNXCmpxchg(old_value, new_value, - const_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 old_value; - do { - old_value = *ptr; - } while (QNXCmpxchg(old_value, new_value, - const_cast(ptr))); - return old_value; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return Barrier_AtomicIncrement(ptr, increment); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - for (;;) { - // Atomic exchange the old value with an incremented one. - Atomic32 old_value = *ptr; - Atomic32 new_value = old_value + increment; - if (QNXCmpxchg(old_value, new_value, - const_cast(ptr)) == 0) { - // The exchange took place as expected. - return new_value; - } - // Otherwise, *ptr changed mid-loop and we need to retry. - } -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void MemoryBarrier() { - __sync_synchronize(); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ARM_QNX_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_atomicword_compat.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_atomicword_compat.h deleted file mode 100644 index eb198ff..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +++ /dev/null @@ -1,122 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ - -// AtomicWord is a synonym for intptr_t, and Atomic32 is a synonym for int32, -// which in turn means int. On some LP32 platforms, intptr_t is an int, but -// on others, it's a long. When AtomicWord and Atomic32 are based on different -// fundamental types, their pointers are incompatible. -// -// This file defines function overloads to allow both AtomicWord and Atomic32 -// data to be used with this interface. -// -// On LP64 platforms, AtomicWord and Atomic64 are both always long, -// so this problem doesn't occur. - -#if !defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -namespace google { -namespace protobuf { -namespace internal { - -inline AtomicWord NoBarrier_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return NoBarrier_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline AtomicWord NoBarrier_AtomicExchange(volatile AtomicWord* ptr, - AtomicWord new_value) { - return NoBarrier_AtomicExchange( - reinterpret_cast(ptr), new_value); -} - -inline AtomicWord NoBarrier_AtomicIncrement(volatile AtomicWord* ptr, - AtomicWord increment) { - return NoBarrier_AtomicIncrement( - reinterpret_cast(ptr), increment); -} - -inline AtomicWord Barrier_AtomicIncrement(volatile AtomicWord* ptr, - AtomicWord increment) { - return Barrier_AtomicIncrement( - reinterpret_cast(ptr), increment); -} - -inline AtomicWord Acquire_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return Acquire_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline AtomicWord Release_CompareAndSwap(volatile AtomicWord* ptr, - AtomicWord old_value, - AtomicWord new_value) { - return Release_CompareAndSwap( - reinterpret_cast(ptr), old_value, new_value); -} - -inline void NoBarrier_Store(volatile AtomicWord *ptr, AtomicWord value) { - NoBarrier_Store(reinterpret_cast(ptr), value); -} - -inline void Acquire_Store(volatile AtomicWord* ptr, AtomicWord value) { - return Acquire_Store(reinterpret_cast(ptr), value); -} - -inline void Release_Store(volatile AtomicWord* ptr, AtomicWord value) { - return Release_Store(reinterpret_cast(ptr), value); -} - -inline AtomicWord NoBarrier_Load(volatile const AtomicWord *ptr) { - return NoBarrier_Load(reinterpret_cast(ptr)); -} - -inline AtomicWord Acquire_Load(volatile const AtomicWord* ptr) { - return Acquire_Load(reinterpret_cast(ptr)); -} - -inline AtomicWord Release_Load(volatile const AtomicWord* ptr) { - return Release_Load(reinterpret_cast(ptr)); -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // !defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_ATOMICWORD_COMPAT_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_generic_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_generic_gcc.h deleted file mode 100644 index 7314ee4..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_generic_gcc.h +++ /dev/null @@ -1,155 +0,0 @@ -// Copyright 2013 Red Hat Inc. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Red Hat Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_ - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, - __ATOMIC_RELAXED, __ATOMIC_RELAXED); - return old_value; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - return __atomic_exchange_n(ptr, new_value, __ATOMIC_RELAXED); -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return __atomic_add_fetch(ptr, increment, __ATOMIC_SEQ_CST); -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, - __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); - return old_value; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, - __ATOMIC_RELEASE, __ATOMIC_ACQUIRE); - return old_value; -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - __atomic_store_n(ptr, value, __ATOMIC_RELAXED); -} - -inline void MemoryBarrier() { - __sync_synchronize(); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - __atomic_store_n(ptr, value, __ATOMIC_SEQ_CST); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - __atomic_store_n(ptr, value, __ATOMIC_RELEASE); -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return __atomic_load_n(ptr, __ATOMIC_RELAXED); -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - return __atomic_load_n(ptr, __ATOMIC_SEQ_CST); -} - -#ifdef __LP64__ - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - __atomic_store_n(ptr, value, __ATOMIC_RELEASE); -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - return __atomic_load_n(ptr, __ATOMIC_ACQUIRE); -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, - __ATOMIC_ACQUIRE, __ATOMIC_ACQUIRE); - return old_value; -} - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - __atomic_compare_exchange_n(ptr, &old_value, new_value, true, - __ATOMIC_RELAXED, __ATOMIC_RELAXED); - return old_value; -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return __atomic_add_fetch(ptr, increment, __ATOMIC_RELAXED); -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - __atomic_store_n(ptr, value, __ATOMIC_RELAXED); -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - return __atomic_exchange_n(ptr, new_value, __ATOMIC_RELAXED); -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return __atomic_load_n(ptr, __ATOMIC_RELAXED); -} - -#endif // defined(__LP64__) - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_GENERIC_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_macosx.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_macosx.h deleted file mode 100644 index 7963324..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_macosx.h +++ /dev/null @@ -1,225 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev_value; - do { - if (OSAtomicCompareAndSwap32(old_value, new_value, - const_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 old_value; - do { - old_value = *ptr; - } while (!OSAtomicCompareAndSwap32(old_value, new_value, - const_cast(ptr))); - return old_value; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return OSAtomicAdd32(increment, const_cast(ptr)); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return OSAtomicAdd32Barrier(increment, const_cast(ptr)); -} - -inline void MemoryBarrier() { - OSMemoryBarrier(); -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev_value; - do { - if (OSAtomicCompareAndSwap32Barrier(old_value, new_value, - const_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return Acquire_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -#ifdef __LP64__ - -// 64-bit implementation on 64-bit platform - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev_value; - do { - if (OSAtomicCompareAndSwap64(old_value, new_value, - reinterpret_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - Atomic64 old_value; - do { - old_value = *ptr; - } while (!OSAtomicCompareAndSwap64(old_value, new_value, - reinterpret_cast(ptr))); - return old_value; -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return OSAtomicAdd64(increment, reinterpret_cast(ptr)); -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return OSAtomicAdd64Barrier(increment, - reinterpret_cast(ptr)); -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev_value; - do { - if (OSAtomicCompareAndSwap64Barrier( - old_value, new_value, reinterpret_cast(ptr))) { - return old_value; - } - prev_value = *ptr; - } while (prev_value == old_value); - return prev_value; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - // The lib kern interface does not distinguish between - // Acquire and Release memory barriers; they are equivalent. - return Acquire_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return *ptr; -} - -#endif // defined(__LP64__) - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MACOSX_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_mips_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_mips_gcc.h deleted file mode 100644 index f5837c9..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_mips_gcc.h +++ /dev/null @@ -1,313 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MIPS_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MIPS_GCC_H_ - -#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") - -namespace google { -namespace protobuf { -namespace internal { - -// Atomically execute: -// result = *ptr; -// if (*ptr == old_value) -// *ptr = new_value; -// return result; -// -// I.e., replace "*ptr" with "new_value" if "*ptr" used to be "old_value". -// Always return the old value of "*ptr" -// -// This routine implies no memory barriers. -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev, tmp; - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "ll %0, %5\n" // prev = *ptr - "bne %0, %3, 2f\n" // if (prev != old_value) goto 2 - "move %2, %4\n" // tmp = new_value - "sc %2, %1\n" // *ptr = tmp (with atomic check) - "beqz %2, 1b\n" // start again on atomic error - "nop\n" // delay slot nop - "2:\n" - ".set pop\n" - : "=&r" (prev), "=m" (*ptr), "=&r" (tmp) - : "r" (old_value), "r" (new_value), "m" (*ptr) - : "memory"); - return prev; -} - -// Atomically store new_value into *ptr, returning the previous value held in -// *ptr. This routine implies no memory barriers. -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 temp, old; - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "ll %1, %4\n" // old = *ptr - "move %0, %3\n" // temp = new_value - "sc %0, %2\n" // *ptr = temp (with atomic check) - "beqz %0, 1b\n" // start again on atomic error - "nop\n" // delay slot nop - ".set pop\n" - : "=&r" (temp), "=&r" (old), "=m" (*ptr) - : "r" (new_value), "m" (*ptr) - : "memory"); - - return old; -} - -// Atomically increment *ptr by "increment". Returns the new value of -// *ptr with the increment applied. This routine implies no memory barriers. -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 temp, temp2; - - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "ll %0, %4\n" // temp = *ptr - "addu %1, %0, %3\n" // temp2 = temp + increment - "sc %1, %2\n" // *ptr = temp2 (with atomic check) - "beqz %1, 1b\n" // start again on atomic error - "addu %1, %0, %3\n" // temp2 = temp + increment - ".set pop\n" - : "=&r" (temp), "=&r" (temp2), "=m" (*ptr) - : "Ir" (increment), "m" (*ptr) - : "memory"); - // temp2 now holds the final value. - return temp2; -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - ATOMICOPS_COMPILER_BARRIER(); - Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); - ATOMICOPS_COMPILER_BARRIER(); - return res; -} - -// "Acquire" operations -// ensure that no later memory access can be reordered ahead of the operation. -// "Release" operations ensure that no previous memory access can be reordered -// after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - ATOMICOPS_COMPILER_BARRIER(); - Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - ATOMICOPS_COMPILER_BARRIER(); - return res; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - ATOMICOPS_COMPILER_BARRIER(); - Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - ATOMICOPS_COMPILER_BARRIER(); - return res; -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void MemoryBarrier() { - __asm__ __volatile__("sync" : : : "memory"); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -#if defined(__LP64__) -// 64-bit versions of the atomic ops. - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev, tmp; - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "lld %0, %5\n" // prev = *ptr - "bne %0, %3, 2f\n" // if (prev != old_value) goto 2 - "move %2, %4\n" // tmp = new_value - "scd %2, %1\n" // *ptr = tmp (with atomic check) - "beqz %2, 1b\n" // start again on atomic error - "nop\n" // delay slot nop - "2:\n" - ".set pop\n" - : "=&r" (prev), "=m" (*ptr), "=&r" (tmp) - : "r" (old_value), "r" (new_value), "m" (*ptr) - : "memory"); - return prev; -} - -// Atomically store new_value into *ptr, returning the previous value held in -// *ptr. This routine implies no memory barriers. -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - Atomic64 temp, old; - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "lld %1, %4\n" // old = *ptr - "move %0, %3\n" // temp = new_value - "scd %0, %2\n" // *ptr = temp (with atomic check) - "beqz %0, 1b\n" // start again on atomic error - "nop\n" // delay slot nop - ".set pop\n" - : "=&r" (temp), "=&r" (old), "=m" (*ptr) - : "r" (new_value), "m" (*ptr) - : "memory"); - - return old; -} - -// Atomically increment *ptr by "increment". Returns the new value of -// *ptr with the increment applied. This routine implies no memory barriers. -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - Atomic64 temp, temp2; - - __asm__ __volatile__(".set push\n" - ".set noreorder\n" - "1:\n" - "lld %0, %4\n" // temp = *ptr - "daddu %1, %0, %3\n" // temp2 = temp + increment - "scd %1, %2\n" // *ptr = temp2 (with atomic check) - "beqz %1, 1b\n" // start again on atomic error - "daddu %1, %0, %3\n" // temp2 = temp + increment - ".set pop\n" - : "=&r" (temp), "=&r" (temp2), "=m" (*ptr) - : "Ir" (increment), "m" (*ptr) - : "memory"); - // temp2 now holds the final value. - return temp2; -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - MemoryBarrier(); - Atomic64 res = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); - return res; -} - -// "Acquire" operations -// ensure that no later memory access can be reordered ahead of the operation. -// "Release" operations ensure that no previous memory access can be reordered -// after the operation. "Barrier" operations have both "Acquire" and "Release" -// semantics. A MemoryBarrier() has "Barrier" semantics, but does no memory -// access. -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - return res; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - MemoryBarrier(); - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return *ptr; -} -#endif - -} // namespace internal -} // namespace protobuf -} // namespace google - -#undef ATOMICOPS_COMPILER_BARRIER - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_MIPS_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_pnacl.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_pnacl.h deleted file mode 100644 index 3b314fd..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_pnacl.h +++ /dev/null @@ -1,231 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -// This implementation is transitional and maintains the original API for -// atomicops.h. This requires casting memory locations to the atomic types, and -// assumes that the API and the C++11 implementation are layout-compatible, -// which isn't true for all implementations or hardware platforms. The static -// assertion should detect this issue, were it to fire then this header -// shouldn't be used. -// -// TODO(jfb) If this header manages to stay committed then the API should be -// modified, and all call sites updated. -typedef volatile std::atomic* AtomicLocation32; -static_assert(sizeof(*(AtomicLocation32) nullptr) == sizeof(Atomic32), - "incompatible 32-bit atomic layout"); - -inline void MemoryBarrier() { -#if defined(__GLIBCXX__) - // Work around libstdc++ bug 51038 where atomic_thread_fence was declared but - // not defined, leading to the linker complaining about undefined references. - __atomic_thread_fence(std::memory_order_seq_cst); -#else - std::atomic_thread_fence(std::memory_order_seq_cst); -#endif -} - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - ((AtomicLocation32)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_relaxed, - std::memory_order_relaxed); - return old_value; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - return ((AtomicLocation32)ptr) - ->exchange(new_value, std::memory_order_relaxed); -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return increment + - ((AtomicLocation32)ptr) - ->fetch_add(increment, std::memory_order_relaxed); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return increment + ((AtomicLocation32)ptr)->fetch_add(increment); -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - ((AtomicLocation32)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_acquire, - std::memory_order_acquire); - return old_value; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - ((AtomicLocation32)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_release, - std::memory_order_relaxed); - return old_value; -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - ((AtomicLocation32)ptr)->store(value, std::memory_order_relaxed); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - ((AtomicLocation32)ptr)->store(value, std::memory_order_relaxed); - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - ((AtomicLocation32)ptr)->store(value, std::memory_order_release); -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return ((AtomicLocation32)ptr)->load(std::memory_order_relaxed); -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - return ((AtomicLocation32)ptr)->load(std::memory_order_acquire); -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return ((AtomicLocation32)ptr)->load(std::memory_order_relaxed); -} - -#if defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -typedef volatile std::atomic* AtomicLocation64; -static_assert(sizeof(*(AtomicLocation64) nullptr) == sizeof(Atomic64), - "incompatible 64-bit atomic layout"); - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - ((AtomicLocation64)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_relaxed, - std::memory_order_relaxed); - return old_value; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - return ((AtomicLocation64)ptr) - ->exchange(new_value, std::memory_order_relaxed); -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return increment + - ((AtomicLocation64)ptr) - ->fetch_add(increment, std::memory_order_relaxed); -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return increment + ((AtomicLocation64)ptr)->fetch_add(increment); -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - ((AtomicLocation64)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_acquire, - std::memory_order_acquire); - return old_value; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - ((AtomicLocation64)ptr) - ->compare_exchange_strong(old_value, - new_value, - std::memory_order_release, - std::memory_order_relaxed); - return old_value; -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - ((AtomicLocation64)ptr)->store(value, std::memory_order_relaxed); -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - ((AtomicLocation64)ptr)->store(value, std::memory_order_relaxed); - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - ((AtomicLocation64)ptr)->store(value, std::memory_order_release); -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed); -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - return ((AtomicLocation64)ptr)->load(std::memory_order_acquire); -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return ((AtomicLocation64)ptr)->load(std::memory_order_relaxed); -} - -#endif // defined(GOOGLE_PROTOBUF_ARCH_64_BIT) - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PNACL_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_power.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_power.h deleted file mode 100644 index b8a42f2..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_power.h +++ /dev/null @@ -1,440 +0,0 @@ -// Copyright 2014 Bloomberg Finance LP. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Bloomberg Finance LP. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_AIX_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_AIX_H_ - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 result; - - asm volatile ( - "1: lwarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpw %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - " stwcx. %[val], %[zero], %[obj] \n\t" // store new value - " bne- 1b \n\t" - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - Atomic32 result; - - asm volatile ( - "1: lwarx %[res], %[zero], %[obj] \n\t" - " stwcx. %[val], %[zero], %[obj] \n\t" - " bne- 1b \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 result; - - asm volatile ( - "1: lwarx %[res], %[zero], %[obj] \n\t" // load and reserve - " add %[res], %[val], %[res] \n\t" // add the operand - " stwcx. %[res], %[zero], %[obj] \n\t" // store old value - // if still reserved - " bne- 1b \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (increment), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline void MemoryBarrier(void) { - asm volatile ( - " lwsync \n\t" - " isync \n\t" - : - : - : "memory"); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 result; - - asm volatile ( - " lwsync \n\t" - - "1: lwarx %[res], %[zero], %[obj] \n\t" // load and reserve - " add %[res], %[val], %[res] \n\t" // add the operand - " stwcx. %[res], %[zero], %[obj] \n\t" // store old value - // if still reserved - " bne- 1b \n\t" - " isync \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (increment), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 result; - - asm volatile ( - "1: lwarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpw %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - " stwcx. %[val], %[zero], %[obj] \n\t" // store new value - " bne- 1b \n\t" - - " isync \n\t" - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 result; - - asm volatile ( - " lwsync \n\t" - - "1: lwarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpw %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - " stwcx. %[val], %[zero], %[obj] \n\t" // store new value - " bne- 1b \n\t" - - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - asm volatile ( - " stw %[val], %[obj] \n\t" - " isync \n\t" - : [obj] "=m" (*ptr) - : [val] "b" (value)); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - asm volatile ( - " lwsync \n\t" - " stw %[val], %[obj] \n\t" - : [obj] "=m" (*ptr) - : [val] "b" (value)); -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 result; - - asm volatile ( - "1: lwz %[res], %[obj] \n\t" - " cmpw %[res], %[res] \n\t" // create data - // dependency for - // load/load ordering - " bne- 1b \n\t" // never taken - - " isync \n\t" - : [res] "=b" (result) - : [obj] "m" (*ptr), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - Atomic32 result; - - asm volatile ( - " lwsync \n\t" - - "1: lwz %[res], %[obj] \n\t" - " cmpw %[res], %[res] \n\t" // create data - // dependency for - // load/load ordering - " bne- 1b \n\t" // never taken - : [res] "=b" (result) - : [obj] "m" (*ptr), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 result; - - asm volatile ( - "1: ldarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpd %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - - " stdcx. %[val], %[zero], %[obj] \n\t" // store the new value - " bne- 1b \n\t" - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - Atomic64 result; - - asm volatile ( - "1: ldarx %[res], %[zero], %[obj] \n\t" - " stdcx. %[val], %[zero], %[obj] \n\t" - " bne- 1b \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - Atomic64 result; - - asm volatile ( - "1: ldarx %[res], %[zero], %[obj] \n\t" // load and reserve - " add %[res], %[res], %[val] \n\t" // add the operand - " stdcx. %[res], %[zero], %[obj] \n\t" // store old value if - // still reserved - - " bne- 1b \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (increment), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - - Atomic64 result; - - asm volatile ( - " lwsync \n\t" - - "1: ldarx %[res], %[zero], %[obj] \n\t" // load and reserve - " add %[res], %[res], %[val] \n\t" // add the operand - " stdcx. %[res], %[zero], %[obj] \n\t" // store old value if - // still reserved - - " bne- 1b \n\t" - - " isync \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [val] "b" (increment), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 result; - - asm volatile ( - "1: ldarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpd %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - - " stdcx. %[val], %[zero], %[obj] \n\t" // store the new value - " bne- 1b \n\t" - " isync \n\t" - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 result; - - asm volatile ( - " lwsync \n\t" - - "1: ldarx %[res], %[zero], %[obj] \n\t" // load and reserve - " cmpd %[cmp], %[res] \n\t" // compare values - " bne- 2f \n\t" - - " stdcx. %[val], %[zero], %[obj] \n\t" // store the new value - " bne- 1b \n\t" - "2: \n\t" - : [res] "=&b" (result) - : [obj] "b" (ptr), - [cmp] "b" (old_value), - [val] "b" (new_value), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - asm volatile ( - " std %[val], %[obj] \n\t" - " isync \n\t" - : [obj] "=m" (*ptr) - : [val] "b" (value)); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - asm volatile ( - " lwsync \n\t" - " std %[val], %[obj] \n\t" - : [obj] "=m" (*ptr) - : [val] "b" (value)); -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 result; - - asm volatile ( - "1: ld %[res], %[obj] \n\t" - " cmpd %[res], %[res] \n\t" // create data - // dependency for - // load/load ordering - " bne- 1b \n\t" // never taken - - " isync \n\t" - : [res] "=b" (result) - : [obj] "m" (*ptr), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - Atomic64 result; - - asm volatile ( - " lwsync \n\t" - - "1: ld %[res], %[obj] \n\t" - " cmpd %[res], %[res] \n\t" // create data - // dependency for - // load/load ordering - " bne- 1b \n\t" // never taken - : [res] "=b" (result) - : [obj] "m" (*ptr), - [zero] "i" (0) - : "cr0", "ctr"); - - return result; -} -#endif - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_ppc_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_ppc_gcc.h deleted file mode 100644 index 8231a57..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_ppc_gcc.h +++ /dev/null @@ -1,155 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2015 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: ogabbay@advaoptical.com (Oded Gabbay) -// Cleaned up by: bsilver16384@gmail.com (Brian Silverman) -// -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ - -#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev; - - __asm__ __volatile__( - "0: \n\t" - "lwarx %[prev],0,%[ptr] \n\t" - "cmpw 0,%[prev],%[old_value] \n\t" - "bne- 1f \n\t" - "stwcx. %[new_value],0,%[ptr] \n\t" - "bne- 0b \n\t" - "1: \n\t" - : [prev] "=&r"(prev), "+m"(*ptr) - : [ptr] "r"(ptr), [old_value] "r"(old_value), [new_value] "r"(new_value) - : "cc", "memory"); - - return prev; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr, - Atomic32 new_value) { - Atomic32 old; - - __asm__ __volatile__( - "0: \n\t" - "lwarx %[old],0,%[ptr] \n\t" - "stwcx. %[new_value],0,%[ptr] \n\t" - "bne- 0b \n\t" - : [old] "=&r"(old), "+m"(*ptr) - : [ptr] "r"(ptr), [new_value] "r"(new_value) - : "cc", "memory"); - - return old; -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, - Atomic32 increment) { - Atomic32 temp; - - __asm__ __volatile__( - "0: \n\t" - "lwarx %[temp],0,%[ptr] \n\t" - "add %[temp],%[increment],%[temp] \n\t" - "stwcx. %[temp],0,%[ptr] \n\t" - "bne- 0b \n\t" - : [temp] "=&r"(temp) - : [increment] "r"(increment), [ptr] "r"(ptr) - : "cc", "memory"); - - return temp; -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, - Atomic32 increment) { - MemoryBarrier(); - Atomic32 res = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); - return res; -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, Atomic32 new_value) { - Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - return res; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, Atomic32 new_value) { - MemoryBarrier(); - Atomic32 res = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - return res; -} - -inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) { - *ptr = value; -} - -inline void MemoryBarrier() { __asm__ __volatile__("sync" : : : "memory"); } - -inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) { - MemoryBarrier(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { return *ptr; } - -inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) { - Atomic32 value = *ptr; - MemoryBarrier(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32 *ptr) { - MemoryBarrier(); - return *ptr; -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#undef ATOMICOPS_COMPILER_BARRIER - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_PPC_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_solaris.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_solaris.h deleted file mode 100644 index d8057ec..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_solaris.h +++ /dev/null @@ -1,188 +0,0 @@ -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_ - -#include - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return (Atomic32)atomic_cas_32((volatile uint32_t*)ptr, (uint32_t)old_value, (uint32_t)new_value); -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - return (Atomic32)atomic_swap_32((volatile uint32_t*)ptr, (uint32_t)new_value); -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return (Atomic32)atomic_add_32_nv((volatile uint32_t*)ptr, (uint32_t)increment); -} - -inline void MemoryBarrier(void) { - membar_producer(); - membar_consumer(); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - MemoryBarrier(); - Atomic32 ret = NoBarrier_AtomicIncrement(ptr, increment); - MemoryBarrier(); - - return ret; -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - - return ret; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - MemoryBarrier(); - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - membar_producer(); -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - membar_consumer(); - *ptr = value; -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 val = *ptr; - membar_consumer(); - return val; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - membar_producer(); - return *ptr; -} - -#ifdef GOOGLE_PROTOBUF_ARCH_64_BIT -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - return atomic_cas_64((volatile uint64_t*)ptr, (uint64_t)old_value, (uint64_t)new_value); -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, Atomic64 new_value) { - return atomic_swap_64((volatile uint64_t*)ptr, (uint64_t)new_value); -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) { - return atomic_add_64_nv((volatile uint64_t*)ptr, increment); -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, Atomic64 increment) { - MemoryBarrier(); - Atomic64 ret = atomic_add_64_nv((volatile uint64_t*)ptr, increment); - MemoryBarrier(); - return ret; -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 ret = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - MemoryBarrier(); - return ret; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - MemoryBarrier(); - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; - membar_producer(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - membar_consumer(); - *ptr = value; -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 ret = *ptr; - membar_consumer(); - return ret; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - membar_producer(); - return *ptr; -} -#endif - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_SPARC_GCC_H_ - diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_tsan.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_tsan.h deleted file mode 100644 index 0c90354..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_tsan.h +++ /dev/null @@ -1,219 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2013 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation for compiler-based -// ThreadSanitizer (http://clang.llvm.org/docs/ThreadSanitizer.html). -// Use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_TSAN_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_TSAN_H_ - -#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") - -#include - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 cmp = old_value; - __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_relaxed, __tsan_memory_order_relaxed); - return cmp; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32 *ptr, - Atomic32 new_value) { - return __tsan_atomic32_exchange(ptr, new_value, - __tsan_memory_order_relaxed); -} - -inline Atomic32 Acquire_AtomicExchange(volatile Atomic32 *ptr, - Atomic32 new_value) { - return __tsan_atomic32_exchange(ptr, new_value, - __tsan_memory_order_acquire); -} - -inline Atomic32 Release_AtomicExchange(volatile Atomic32 *ptr, - Atomic32 new_value) { - return __tsan_atomic32_exchange(ptr, new_value, - __tsan_memory_order_release); -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32 *ptr, - Atomic32 increment) { - return increment + __tsan_atomic32_fetch_add(ptr, increment, - __tsan_memory_order_relaxed); -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32 *ptr, - Atomic32 increment) { - return increment + __tsan_atomic32_fetch_add(ptr, increment, - __tsan_memory_order_acq_rel); -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 cmp = old_value; - __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_acquire, __tsan_memory_order_acquire); - return cmp; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32 *ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 cmp = old_value; - __tsan_atomic32_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_release, __tsan_memory_order_relaxed); - return cmp; -} - -inline void NoBarrier_Store(volatile Atomic32 *ptr, Atomic32 value) { - __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed); -} - -inline void Acquire_Store(volatile Atomic32 *ptr, Atomic32 value) { - __tsan_atomic32_store(ptr, value, __tsan_memory_order_relaxed); - __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); -} - -inline void Release_Store(volatile Atomic32 *ptr, Atomic32 value) { - __tsan_atomic32_store(ptr, value, __tsan_memory_order_release); -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32 *ptr) { - return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed); -} - -inline Atomic32 Acquire_Load(volatile const Atomic32 *ptr) { - return __tsan_atomic32_load(ptr, __tsan_memory_order_acquire); -} - -inline Atomic32 Release_Load(volatile const Atomic32 *ptr) { - __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); - return __tsan_atomic32_load(ptr, __tsan_memory_order_relaxed); -} - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64 *ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 cmp = old_value; - __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_relaxed, __tsan_memory_order_relaxed); - return cmp; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64 *ptr, - Atomic64 new_value) { - return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_relaxed); -} - -inline Atomic64 Acquire_AtomicExchange(volatile Atomic64 *ptr, - Atomic64 new_value) { - return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_acquire); -} - -inline Atomic64 Release_AtomicExchange(volatile Atomic64 *ptr, - Atomic64 new_value) { - return __tsan_atomic64_exchange(ptr, new_value, __tsan_memory_order_release); -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64 *ptr, - Atomic64 increment) { - return increment + __tsan_atomic64_fetch_add(ptr, increment, - __tsan_memory_order_relaxed); -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64 *ptr, - Atomic64 increment) { - return increment + __tsan_atomic64_fetch_add(ptr, increment, - __tsan_memory_order_acq_rel); -} - -inline void NoBarrier_Store(volatile Atomic64 *ptr, Atomic64 value) { - __tsan_atomic64_store(ptr, value, __tsan_memory_order_relaxed); -} - -inline void Acquire_Store(volatile Atomic64 *ptr, Atomic64 value) { - __tsan_atomic64_store(ptr, value, __tsan_memory_order_relaxed); - __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); -} - -inline void Release_Store(volatile Atomic64 *ptr, Atomic64 value) { - __tsan_atomic64_store(ptr, value, __tsan_memory_order_release); -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64 *ptr) { - return __tsan_atomic64_load(ptr, __tsan_memory_order_relaxed); -} - -inline Atomic64 Acquire_Load(volatile const Atomic64 *ptr) { - return __tsan_atomic64_load(ptr, __tsan_memory_order_acquire); -} - -inline Atomic64 Release_Load(volatile const Atomic64 *ptr) { - __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); - return __tsan_atomic64_load(ptr, __tsan_memory_order_relaxed); -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64 *ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 cmp = old_value; - __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_acquire, __tsan_memory_order_acquire); - return cmp; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64 *ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 cmp = old_value; - __tsan_atomic64_compare_exchange_strong(ptr, &cmp, new_value, - __tsan_memory_order_release, __tsan_memory_order_relaxed); - return cmp; -} - -inline void MemoryBarrier() { - __tsan_atomic_thread_fence(__tsan_memory_order_seq_cst); -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#undef ATOMICOPS_COMPILER_BARRIER - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_TSAN_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_gcc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_gcc.h deleted file mode 100644 index edccc59..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_gcc.h +++ /dev/null @@ -1,293 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_ - -namespace google { -namespace protobuf { -namespace internal { - -// This struct is not part of the public API of this module; clients may not -// use it. -// Features of this x86. Values may not be correct before main() is run, -// but are set conservatively. -struct AtomicOps_x86CPUFeatureStruct { - bool has_amd_lock_mb_bug; // Processor has AMD memory-barrier bug; do lfence - // after acquire compare-and-swap. - bool has_sse2; // Processor has SSE2. -}; -extern struct AtomicOps_x86CPUFeatureStruct AtomicOps_Internalx86CPUFeatures; - -#define ATOMICOPS_COMPILER_BARRIER() __asm__ __volatile__("" : : : "memory") - -// 32-bit low-level operations on any platform. - -inline Atomic32 NoBarrier_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 prev; - __asm__ __volatile__("lock; cmpxchgl %1,%2" - : "=a" (prev) - : "q" (new_value), "m" (*ptr), "0" (old_value) - : "memory"); - return prev; -} - -inline Atomic32 NoBarrier_AtomicExchange(volatile Atomic32* ptr, - Atomic32 new_value) { - __asm__ __volatile__("xchgl %1,%0" // The lock prefix is implicit for xchg. - : "=r" (new_value) - : "m" (*ptr), "0" (new_value) - : "memory"); - return new_value; // Now it's the previous value. -} - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 temp = increment; - __asm__ __volatile__("lock; xaddl %0,%1" - : "+r" (temp), "+m" (*ptr) - : : "memory"); - // temp now holds the old value of *ptr - return temp + increment; -} - -inline Atomic32 Barrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - Atomic32 temp = increment; - __asm__ __volatile__("lock; xaddl %0,%1" - : "+r" (temp), "+m" (*ptr) - : : "memory"); - // temp now holds the old value of *ptr - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) { - __asm__ __volatile__("lfence" : : : "memory"); - } - return temp + increment; -} - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - Atomic32 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) { - __asm__ __volatile__("lfence" : : : "memory"); - } - return x; -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -#if defined(__x86_64__) - -// 64-bit implementations of memory barrier can be simpler, because it -// "mfence" is guaranteed to exist. -inline void MemoryBarrier() { - __asm__ __volatile__("mfence" : : : "memory"); -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; - MemoryBarrier(); -} - -#else - -inline void MemoryBarrier() { - if (AtomicOps_Internalx86CPUFeatures.has_sse2) { - __asm__ __volatile__("mfence" : : : "memory"); - } else { // mfence is faster but not present on PIII - Atomic32 x = 0; - NoBarrier_AtomicExchange(&x, 0); // acts as a barrier on PIII - } -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - if (AtomicOps_Internalx86CPUFeatures.has_sse2) { - *ptr = value; - __asm__ __volatile__("mfence" : : : "memory"); - } else { - NoBarrier_AtomicExchange(ptr, value); - // acts as a barrier on PIII - } -} -#endif - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - ATOMICOPS_COMPILER_BARRIER(); - *ptr = value; // An x86 store acts as a release barrier. - // See comments in Atomic64 version of Release_Store(), below. -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; // An x86 load acts as a acquire barrier. - // See comments in Atomic64 version of Release_Store(), below. - ATOMICOPS_COMPILER_BARRIER(); - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -#if defined(__x86_64__) - -// 64-bit low-level operations on 64-bit platform. - -inline Atomic64 NoBarrier_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 prev; - __asm__ __volatile__("lock; cmpxchgq %1,%2" - : "=a" (prev) - : "q" (new_value), "m" (*ptr), "0" (old_value) - : "memory"); - return prev; -} - -inline Atomic64 NoBarrier_AtomicExchange(volatile Atomic64* ptr, - Atomic64 new_value) { - __asm__ __volatile__("xchgq %1,%0" // The lock prefix is implicit for xchg. - : "=r" (new_value) - : "m" (*ptr), "0" (new_value) - : "memory"); - return new_value; // Now it's the previous value. -} - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - Atomic64 temp = increment; - __asm__ __volatile__("lock; xaddq %0,%1" - : "+r" (temp), "+m" (*ptr) - : : "memory"); - // temp now contains the previous value of *ptr - return temp + increment; -} - -inline Atomic64 Barrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - Atomic64 temp = increment; - __asm__ __volatile__("lock; xaddq %0,%1" - : "+r" (temp), "+m" (*ptr) - : : "memory"); - // temp now contains the previous value of *ptr - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) { - __asm__ __volatile__("lfence" : : : "memory"); - } - return temp + increment; -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; - MemoryBarrier(); -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - ATOMICOPS_COMPILER_BARRIER(); - - *ptr = value; // An x86 store acts as a release barrier - // for current AMD/Intel chips as of Jan 2008. - // See also Acquire_Load(), below. - - // When new chips come out, check: - // IA-32 Intel Architecture Software Developer's Manual, Volume 3: - // System Programming Guide, Chatper 7: Multiple-processor management, - // Section 7.2, Memory Ordering. - // Last seen at: - // http://developer.intel.com/design/pentium4/manuals/index_new.htm - // - // x86 stores/loads fail to act as barriers for a few instructions (clflush - // maskmovdqu maskmovq movntdq movnti movntpd movntps movntq) but these are - // not generated by the compiler, and are rare. Users of these instructions - // need to know about cache behaviour in any case since all of these involve - // either flushing cache lines or non-temporal cache hints. -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 value = *ptr; // An x86 load acts as a acquire barrier, - // for current AMD/Intel chips as of Jan 2008. - // See also Release_Store(), above. - ATOMICOPS_COMPILER_BARRIER(); - return value; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return *ptr; -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - Atomic64 x = NoBarrier_CompareAndSwap(ptr, old_value, new_value); - if (AtomicOps_Internalx86CPUFeatures.has_amd_lock_mb_bug) { - __asm__ __volatile__("lfence" : : : "memory"); - } - return x; -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -#endif // defined(__x86_64__) - -} // namespace internal -} // namespace protobuf -} // namespace google - -#undef ATOMICOPS_COMPILER_BARRIER - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_GCC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_msvc.h b/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_msvc.h deleted file mode 100644 index e53a641..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/atomicops_internals_x86_msvc.h +++ /dev/null @@ -1,150 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file is an internal atomic implementation, use atomicops.h instead. - -#ifndef GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_ -#define GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_ - -namespace google { -namespace protobuf { -namespace internal { - -inline Atomic32 NoBarrier_AtomicIncrement(volatile Atomic32* ptr, - Atomic32 increment) { - return Barrier_AtomicIncrement(ptr, increment); -} - -#if !(defined(_MSC_VER) && _MSC_VER >= 1400) -#error "We require at least vs2005 for MemoryBarrier" -#endif - -inline Atomic32 Acquire_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline Atomic32 Release_CompareAndSwap(volatile Atomic32* ptr, - Atomic32 old_value, - Atomic32 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline void NoBarrier_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic32* ptr, Atomic32 value) { - NoBarrier_AtomicExchange(ptr, value); - // acts as a barrier in this implementation -} - -inline void Release_Store(volatile Atomic32* ptr, Atomic32 value) { - *ptr = value; // works w/o barrier for current Intel chips as of June 2005 - // See comments in Atomic64 version of Release_Store() below. -} - -inline Atomic32 NoBarrier_Load(volatile const Atomic32* ptr) { - return *ptr; -} - -inline Atomic32 Acquire_Load(volatile const Atomic32* ptr) { - Atomic32 value = *ptr; - return value; -} - -inline Atomic32 Release_Load(volatile const Atomic32* ptr) { - MemoryBarrier(); - return *ptr; -} - -#if defined(_WIN64) - -// 64-bit low-level operations on 64-bit platform. - -inline Atomic64 NoBarrier_AtomicIncrement(volatile Atomic64* ptr, - Atomic64 increment) { - return Barrier_AtomicIncrement(ptr, increment); -} - -inline void NoBarrier_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; -} - -inline void Acquire_Store(volatile Atomic64* ptr, Atomic64 value) { - NoBarrier_AtomicExchange(ptr, value); - // acts as a barrier in this implementation -} - -inline void Release_Store(volatile Atomic64* ptr, Atomic64 value) { - *ptr = value; // works w/o barrier for current Intel chips as of June 2005 - - // When new chips come out, check: - // IA-32 Intel Architecture Software Developer's Manual, Volume 3: - // System Programming Guide, Chatper 7: Multiple-processor management, - // Section 7.2, Memory Ordering. - // Last seen at: - // http://developer.intel.com/design/pentium4/manuals/index_new.htm -} - -inline Atomic64 NoBarrier_Load(volatile const Atomic64* ptr) { - return *ptr; -} - -inline Atomic64 Acquire_Load(volatile const Atomic64* ptr) { - Atomic64 value = *ptr; - return value; -} - -inline Atomic64 Release_Load(volatile const Atomic64* ptr) { - MemoryBarrier(); - return *ptr; -} - -inline Atomic64 Acquire_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -inline Atomic64 Release_CompareAndSwap(volatile Atomic64* ptr, - Atomic64 old_value, - Atomic64 new_value) { - return NoBarrier_CompareAndSwap(ptr, old_value, new_value); -} - -#endif // defined(_WIN64) - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_ATOMICOPS_INTERNALS_X86_MSVC_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/bytestream.h b/app/src/main/cpp/google/protobuf/stubs/bytestream.h deleted file mode 100644 index 07604e1..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/bytestream.h +++ /dev/null @@ -1,348 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// This file declares the ByteSink and ByteSource abstract interfaces. These -// interfaces represent objects that consume (ByteSink) or produce (ByteSource) -// a sequence of bytes. Using these abstract interfaces in your APIs can help -// make your code work with a variety of input and output types. -// -// This file also declares the following commonly used implementations of these -// interfaces. -// -// ByteSink: -// UncheckedArrayByteSink Writes to an array, without bounds checking -// CheckedArrayByteSink Writes to an array, with bounds checking -// GrowingArrayByteSink Allocates and writes to a growable buffer -// StringByteSink Writes to an STL string -// NullByteSink Consumes a never-ending stream of bytes -// -// ByteSource: -// ArrayByteSource Reads from an array or string/StringPiece -// LimitedByteSource Limits the number of bytes read from an - -#ifndef GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ -#define GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ - -#include -#include - -#include -#include - -class CordByteSink; -class MemBlock; - -namespace google { -namespace protobuf { -namespace strings { - -// An abstract interface for an object that consumes a sequence of bytes. This -// interface offers 3 different ways to append data, and a Flush() function. -// -// Example: -// -// string my_data; -// ... -// ByteSink* sink = ... -// sink->Append(my_data.data(), my_data.size()); -// sink->Flush(); -// -class LIBPROTOBUF_EXPORT ByteSink { - public: - ByteSink() {} - virtual ~ByteSink() {} - - // Appends the "n" bytes starting at "bytes". - virtual void Append(const char* bytes, size_t n) = 0; - - // Flushes internal buffers. The default implemenation does nothing. ByteSink - // subclasses may use internal buffers that require calling Flush() at the end - // of the stream. - virtual void Flush(); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSink); -}; - -// An abstract interface for an object that produces a fixed-size sequence of -// bytes. -// -// Example: -// -// ByteSource* source = ... -// while (source->Available() > 0) { -// StringPiece data = source->Peek(); -// ... do something with "data" ... -// source->Skip(data.length()); -// } -// -class LIBPROTOBUF_EXPORT ByteSource { - public: - ByteSource() {} - virtual ~ByteSource() {} - - // Returns the number of bytes left to read from the source. Available() - // should decrease by N each time Skip(N) is called. Available() may not - // increase. Available() returning 0 indicates that the ByteSource is - // exhausted. - // - // Note: Size() may have been a more appropriate name as it's more - // indicative of the fixed-size nature of a ByteSource. - virtual size_t Available() const = 0; - - // Returns a StringPiece of the next contiguous region of the source. Does not - // reposition the source. The returned region is empty iff Available() == 0. - // - // The returned region is valid until the next call to Skip() or until this - // object is destroyed, whichever occurs first. - // - // The length of the returned StringPiece will be <= Available(). - virtual StringPiece Peek() = 0; - - // Skips the next n bytes. Invalidates any StringPiece returned by a previous - // call to Peek(). - // - // REQUIRES: Available() >= n - virtual void Skip(size_t n) = 0; - - // Writes the next n bytes in this ByteSource to the given ByteSink, and - // advances this ByteSource past the copied bytes. The default implementation - // of this method just copies the bytes normally, but subclasses might - // override CopyTo to optimize certain cases. - // - // REQUIRES: Available() >= n - virtual void CopyTo(ByteSink* sink, size_t n); - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ByteSource); -}; - -// -// Some commonly used implementations of ByteSink -// - -// Implementation of ByteSink that writes to an unsized byte array. No -// bounds-checking is performed--it is the caller's responsibility to ensure -// that the destination array is large enough. -// -// Example: -// -// char buf[10]; -// UncheckedArrayByteSink sink(buf); -// sink.Append("hi", 2); // OK -// sink.Append(data, 100); // WOOPS! Overflows buf[10]. -// -class LIBPROTOBUF_EXPORT UncheckedArrayByteSink : public ByteSink { - public: - explicit UncheckedArrayByteSink(char* dest) : dest_(dest) {} - virtual void Append(const char* data, size_t n); - - // Returns the current output pointer so that a caller can see how many bytes - // were produced. - // - // Note: this method is not part of the ByteSink interface. - char* CurrentDestination() const { return dest_; } - - private: - char* dest_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(UncheckedArrayByteSink); -}; - -// Implementation of ByteSink that writes to a sized byte array. This sink will -// not write more than "capacity" bytes to outbuf. Once "capacity" bytes are -// appended, subsequent bytes will be ignored and Overflowed() will return true. -// Overflowed() does not cause a runtime error (i.e., it does not CHECK fail). -// -// Example: -// -// char buf[10]; -// CheckedArrayByteSink sink(buf, 10); -// sink.Append("hi", 2); // OK -// sink.Append(data, 100); // Will only write 8 more bytes -// -class LIBPROTOBUF_EXPORT CheckedArrayByteSink : public ByteSink { - public: - CheckedArrayByteSink(char* outbuf, size_t capacity); - virtual void Append(const char* bytes, size_t n); - - // Returns the number of bytes actually written to the sink. - size_t NumberOfBytesWritten() const { return size_; } - - // Returns true if any bytes were discarded, i.e., if there was an - // attempt to write more than 'capacity' bytes. - bool Overflowed() const { return overflowed_; } - - private: - char* outbuf_; - const size_t capacity_; - size_t size_; - bool overflowed_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CheckedArrayByteSink); -}; - -// Implementation of ByteSink that allocates an internal buffer (a char array) -// and expands it as needed to accommodate appended data (similar to a string), -// and allows the caller to take ownership of the internal buffer via the -// GetBuffer() method. The buffer returned from GetBuffer() must be deleted by -// the caller with delete[]. GetBuffer() also sets the internal buffer to be -// empty, and subsequent appends to the sink will create a new buffer. The -// destructor will free the internal buffer if GetBuffer() was not called. -// -// Example: -// -// GrowingArrayByteSink sink(10); -// sink.Append("hi", 2); -// sink.Append(data, n); -// const char* buf = sink.GetBuffer(); // Ownership transferred -// delete[] buf; -// -class LIBPROTOBUF_EXPORT GrowingArrayByteSink : public strings::ByteSink { - public: - explicit GrowingArrayByteSink(size_t estimated_size); - virtual ~GrowingArrayByteSink(); - virtual void Append(const char* bytes, size_t n); - - // Returns the allocated buffer, and sets nbytes to its size. The caller takes - // ownership of the buffer and must delete it with delete[]. - char* GetBuffer(size_t* nbytes); - - private: - void Expand(size_t amount); - void ShrinkToFit(); - - size_t capacity_; - char* buf_; - size_t size_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GrowingArrayByteSink); -}; - -// Implementation of ByteSink that appends to the given string. -// Existing contents of "dest" are not modified; new data is appended. -// -// Example: -// -// string dest = "Hello "; -// StringByteSink sink(&dest); -// sink.Append("World", 5); -// assert(dest == "Hello World"); -// -class LIBPROTOBUF_EXPORT StringByteSink : public ByteSink { - public: - explicit StringByteSink(string* dest) : dest_(dest) {} - virtual void Append(const char* data, size_t n); - - private: - string* dest_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(StringByteSink); -}; - -// Implementation of ByteSink that discards all data. -// -// Example: -// -// NullByteSink sink; -// sink.Append(data, data.size()); // All data ignored. -// -class LIBPROTOBUF_EXPORT NullByteSink : public ByteSink { - public: - NullByteSink() {} - virtual void Append(const char *data, size_t n) {} - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(NullByteSink); -}; - -// -// Some commonly used implementations of ByteSource -// - -// Implementation of ByteSource that reads from a StringPiece. -// -// Example: -// -// string data = "Hello"; -// ArrayByteSource source(data); -// assert(source.Available() == 5); -// assert(source.Peek() == "Hello"); -// -class LIBPROTOBUF_EXPORT ArrayByteSource : public ByteSource { - public: - explicit ArrayByteSource(StringPiece s) : input_(s) {} - - virtual size_t Available() const; - virtual StringPiece Peek(); - virtual void Skip(size_t n); - - private: - StringPiece input_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArrayByteSource); -}; - -// Implementation of ByteSource that wraps another ByteSource, limiting the -// number of bytes returned. -// -// The caller maintains ownership of the underlying source, and may not use the -// underlying source while using the LimitByteSource object. The underlying -// source's pointer is advanced by n bytes every time this LimitByteSource -// object is advanced by n. -// -// Example: -// -// string data = "Hello World"; -// ArrayByteSource abs(data); -// assert(abs.Available() == data.size()); -// -// LimitByteSource limit(abs, 5); -// assert(limit.Available() == 5); -// assert(limit.Peek() == "Hello"); -// -class LIBPROTOBUF_EXPORT LimitByteSource : public ByteSource { - public: - // Returns at most "limit" bytes from "source". - LimitByteSource(ByteSource* source, size_t limit); - - virtual size_t Available() const; - virtual StringPiece Peek(); - virtual void Skip(size_t n); - - // We override CopyTo so that we can forward to the underlying source, in - // case it has an efficient implementation of CopyTo. - virtual void CopyTo(ByteSink* sink, size_t n); - - private: - ByteSource* source_; - size_t limit_; -}; - -} // namespace strings -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_BYTESTREAM_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/callback.h b/app/src/main/cpp/google/protobuf/stubs/callback.h deleted file mode 100644 index bbd507a..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/callback.h +++ /dev/null @@ -1,546 +0,0 @@ -#ifndef GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ -#define GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ - -#include -#include - -// =================================================================== -// emulates google3/base/callback.h - -namespace google { -namespace protobuf { - -// Abstract interface for a callback. When calling an RPC, you must provide -// a Closure to call when the procedure completes. See the Service interface -// in service.h. -// -// To automatically construct a Closure which calls a particular function or -// method with a particular set of parameters, use the NewCallback() function. -// Example: -// void FooDone(const FooResponse* response) { -// ... -// } -// -// void CallFoo() { -// ... -// // When done, call FooDone() and pass it a pointer to the response. -// Closure* callback = NewCallback(&FooDone, response); -// // Make the call. -// service->Foo(controller, request, response, callback); -// } -// -// Example that calls a method: -// class Handler { -// public: -// ... -// -// void FooDone(const FooResponse* response) { -// ... -// } -// -// void CallFoo() { -// ... -// // When done, call FooDone() and pass it a pointer to the response. -// Closure* callback = NewCallback(this, &Handler::FooDone, response); -// // Make the call. -// service->Foo(controller, request, response, callback); -// } -// }; -// -// Currently NewCallback() supports binding zero, one, or two arguments. -// -// Callbacks created with NewCallback() automatically delete themselves when -// executed. They should be used when a callback is to be called exactly -// once (usually the case with RPC callbacks). If a callback may be called -// a different number of times (including zero), create it with -// NewPermanentCallback() instead. You are then responsible for deleting the -// callback (using the "delete" keyword as normal). -// -// Note that NewCallback() is a bit touchy regarding argument types. Generally, -// the values you provide for the parameter bindings must exactly match the -// types accepted by the callback function. For example: -// void Foo(string s); -// NewCallback(&Foo, "foo"); // WON'T WORK: const char* != string -// NewCallback(&Foo, string("foo")); // WORKS -// Also note that the arguments cannot be references: -// void Foo(const string& s); -// string my_str; -// NewCallback(&Foo, my_str); // WON'T WORK: Can't use referecnes. -// However, correctly-typed pointers will work just fine. -class LIBPROTOBUF_EXPORT Closure { - public: - Closure() {} - virtual ~Closure(); - - virtual void Run() = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure); -}; - -template -class ResultCallback { - public: - ResultCallback() {} - virtual ~ResultCallback() {} - - virtual R Run() = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback); -}; - -template -class LIBPROTOBUF_EXPORT ResultCallback1 { - public: - ResultCallback1() {} - virtual ~ResultCallback1() {} - - virtual R Run(A1) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback1); -}; - -template -class LIBPROTOBUF_EXPORT ResultCallback2 { - public: - ResultCallback2() {} - virtual ~ResultCallback2() {} - - virtual R Run(A1,A2) = 0; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ResultCallback2); -}; - -namespace internal { - -class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure { - public: - typedef void (*FunctionType)(); - - FunctionClosure0(FunctionType function, bool self_deleting) - : function_(function), self_deleting_(self_deleting) {} - ~FunctionClosure0(); - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; -}; - -template -class MethodClosure0 : public Closure { - public: - typedef void (Class::*MethodType)(); - - MethodClosure0(Class* object, MethodType method, bool self_deleting) - : object_(object), method_(method), self_deleting_(self_deleting) {} - ~MethodClosure0() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; -}; - -template -class FunctionClosure1 : public Closure { - public: - typedef void (*FunctionType)(Arg1 arg1); - - FunctionClosure1(FunctionType function, bool self_deleting, - Arg1 arg1) - : function_(function), self_deleting_(self_deleting), - arg1_(arg1) {} - ~FunctionClosure1() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(arg1_); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; - Arg1 arg1_; -}; - -template -class MethodClosure1 : public Closure { - public: - typedef void (Class::*MethodType)(Arg1 arg1); - - MethodClosure1(Class* object, MethodType method, bool self_deleting, - Arg1 arg1) - : object_(object), method_(method), self_deleting_(self_deleting), - arg1_(arg1) {} - ~MethodClosure1() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(arg1_); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; - Arg1 arg1_; -}; - -template -class FunctionClosure2 : public Closure { - public: - typedef void (*FunctionType)(Arg1 arg1, Arg2 arg2); - - FunctionClosure2(FunctionType function, bool self_deleting, - Arg1 arg1, Arg2 arg2) - : function_(function), self_deleting_(self_deleting), - arg1_(arg1), arg2_(arg2) {} - ~FunctionClosure2() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - function_(arg1_, arg2_); - if (needs_delete) delete this; - } - - private: - FunctionType function_; - bool self_deleting_; - Arg1 arg1_; - Arg2 arg2_; -}; - -template -class MethodClosure2 : public Closure { - public: - typedef void (Class::*MethodType)(Arg1 arg1, Arg2 arg2); - - MethodClosure2(Class* object, MethodType method, bool self_deleting, - Arg1 arg1, Arg2 arg2) - : object_(object), method_(method), self_deleting_(self_deleting), - arg1_(arg1), arg2_(arg2) {} - ~MethodClosure2() {} - - void Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - (object_->*method_)(arg1_, arg2_); - if (needs_delete) delete this; - } - - private: - Class* object_; - MethodType method_; - bool self_deleting_; - Arg1 arg1_; - Arg2 arg2_; -}; - -template -class FunctionResultCallback_0_0 : public ResultCallback { - public: - typedef R (*FunctionType)(); - - FunctionResultCallback_0_0(FunctionType function, bool self_deleting) - : function_(function), self_deleting_(self_deleting) {} - ~FunctionResultCallback_0_0() {} - - R Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - R result = function_(); - if (needs_delete) delete this; - return result; - } - - private: - FunctionType function_; - bool self_deleting_; -}; - -template -class FunctionResultCallback_1_0 : public ResultCallback { - public: - typedef R (*FunctionType)(P1); - - FunctionResultCallback_1_0(FunctionType function, bool self_deleting, - P1 p1) - : function_(function), self_deleting_(self_deleting), p1_(p1) {} - ~FunctionResultCallback_1_0() {} - - R Run() { - bool needs_delete = self_deleting_; // read in case callback deletes - R result = function_(p1_); - if (needs_delete) delete this; - return result; - } - - private: - FunctionType function_; - bool self_deleting_; - P1 p1_; -}; - -template -class FunctionResultCallback_0_1 : public ResultCallback1 { - public: - typedef R (*FunctionType)(Arg1 arg1); - - FunctionResultCallback_0_1(FunctionType function, bool self_deleting) - : function_(function), self_deleting_(self_deleting) {} - ~FunctionResultCallback_0_1() {} - - R Run(Arg1 a1) { - bool needs_delete = self_deleting_; // read in case callback deletes - R result = function_(a1); - if (needs_delete) delete this; - return result; - } - - private: - FunctionType function_; - bool self_deleting_; -}; - -template -class FunctionResultCallback_1_1 : public ResultCallback1 { - public: - typedef R (*FunctionType)(P1, A1); - - FunctionResultCallback_1_1(FunctionType function, bool self_deleting, - P1 p1) - : function_(function), self_deleting_(self_deleting), p1_(p1) {} - ~FunctionResultCallback_1_1() {} - - R Run(A1 a1) { - bool needs_delete = self_deleting_; // read in case callback deletes - R result = function_(p1_, a1); - if (needs_delete) delete this; - return result; - } - - private: - FunctionType function_; - bool self_deleting_; - P1 p1_; -}; - -template -struct InternalConstRef { - typedef typename remove_reference::type base_type; - typedef const base_type& type; -}; - -template -class MethodResultCallback_5_2 : public ResultCallback2 { - public: - typedef R (T::*MethodType)(P1, P2, P3, P4, P5, A1, A2); - MethodResultCallback_5_2(T* object, MethodType method, bool self_deleting, - P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) - : object_(object), - method_(method), - self_deleting_(self_deleting), - p1_(p1), - p2_(p2), - p3_(p3), - p4_(p4), - p5_(p5) {} - ~MethodResultCallback_5_2() {} - - R Run(A1 a1, A2 a2) { - bool needs_delete = self_deleting_; - R result = (object_->*method_)(p1_, p2_, p3_, p4_, p5_, a1, a2); - if (needs_delete) delete this; - return result; - } - - private: - T* object_; - MethodType method_; - bool self_deleting_; - typename remove_reference::type p1_; - typename remove_reference::type p2_; - typename remove_reference::type p3_; - typename remove_reference::type p4_; - typename remove_reference::type p5_; -}; - -} // namespace internal - -// See Closure. -inline Closure* NewCallback(void (*function)()) { - return new internal::FunctionClosure0(function, true); -} - -// See Closure. -inline Closure* NewPermanentCallback(void (*function)()) { - return new internal::FunctionClosure0(function, false); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)()) { - return new internal::MethodClosure0(object, method, true); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(Class* object, void (Class::*method)()) { - return new internal::MethodClosure0(object, method, false); -} - -// See Closure. -template -inline Closure* NewCallback(void (*function)(Arg1), - Arg1 arg1) { - return new internal::FunctionClosure1(function, true, arg1); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(void (*function)(Arg1), - Arg1 arg1) { - return new internal::FunctionClosure1(function, false, arg1); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1), - Arg1 arg1) { - return new internal::MethodClosure1(object, method, true, arg1); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(Class* object, void (Class::*method)(Arg1), - Arg1 arg1) { - return new internal::MethodClosure1(object, method, false, arg1); -} - -// See Closure. -template -inline Closure* NewCallback(void (*function)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::FunctionClosure2( - function, true, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewPermanentCallback(void (*function)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::FunctionClosure2( - function, false, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::MethodClosure2( - object, method, true, arg1, arg2); -} - -// See Closure. -template -inline Closure* NewPermanentCallback( - Class* object, void (Class::*method)(Arg1, Arg2), - Arg1 arg1, Arg2 arg2) { - return new internal::MethodClosure2( - object, method, false, arg1, arg2); -} - -// See ResultCallback -template -inline ResultCallback* NewCallback(R (*function)()) { - return new internal::FunctionResultCallback_0_0(function, true); -} - -// See ResultCallback -template -inline ResultCallback* NewPermanentCallback(R (*function)()) { - return new internal::FunctionResultCallback_0_0(function, false); -} - -// See ResultCallback -template -inline ResultCallback* NewCallback(R (*function)(P1), P1 p1) { - return new internal::FunctionResultCallback_1_0( - function, true, p1); -} - -// See ResultCallback -template -inline ResultCallback* NewPermanentCallback( - R (*function)(P1), P1 p1) { - return new internal::FunctionResultCallback_1_0( - function, false, p1); -} - -// See ResultCallback1 -template -inline ResultCallback1* NewCallback(R (*function)(A1)) { - return new internal::FunctionResultCallback_0_1(function, true); -} - -// See ResultCallback1 -template -inline ResultCallback1* NewPermanentCallback(R (*function)(A1)) { - return new internal::FunctionResultCallback_0_1(function, false); -} - -// See ResultCallback1 -template -inline ResultCallback1* NewCallback(R (*function)(P1, A1), P1 p1) { - return new internal::FunctionResultCallback_1_1( - function, true, p1); -} - -// See ResultCallback1 -template -inline ResultCallback1* NewPermanentCallback( - R (*function)(P1, A1), P1 p1) { - return new internal::FunctionResultCallback_1_1( - function, false, p1); -} - -// See MethodResultCallback_5_2 -template -inline ResultCallback2* NewPermanentCallback( - T* object, R (T::*function)(P1, P2, P3, P4, P5, A1, A2), - typename internal::InternalConstRef::type p1, - typename internal::InternalConstRef::type p2, - typename internal::InternalConstRef::type p3, - typename internal::InternalConstRef::type p4, - typename internal::InternalConstRef::type p5) { - return new internal::MethodResultCallback_5_2(object, function, false, p1, - p2, p3, p4, p5); -} - -// A function which does nothing. Useful for creating no-op callbacks, e.g.: -// Closure* nothing = NewCallback(&DoNothing); -void LIBPROTOBUF_EXPORT DoNothing(); - - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_CALLBACK_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/casts.h b/app/src/main/cpp/google/protobuf/stubs/casts.h deleted file mode 100644 index be65284..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/casts.h +++ /dev/null @@ -1,133 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_CASTS_H__ -#define GOOGLE_PROTOBUF_CASTS_H__ - -#include -#include - -namespace google { -namespace protobuf { -namespace internal { -// Use implicit_cast as a safe version of static_cast or const_cast -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to -// a const pointer to Foo). -// When you use implicit_cast, the compiler checks that the cast is safe. -// Such explicit implicit_casts are necessary in surprisingly many -// situations where C++ demands an exact type match instead of an -// argument type convertable to a target type. -// -// The From type can be inferred, so the preferred syntax for using -// implicit_cast is the same as for static_cast etc.: -// -// implicit_cast(expr) -// -// implicit_cast would have been part of the C++ standard library, -// but the proposal was submitted too late. It will probably make -// its way into the language in the future. -template -inline To implicit_cast(From const &f) { - return f; -} - -// When you upcast (that is, cast a pointer from type Foo to type -// SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts -// always succeed. When you downcast (that is, cast a pointer from -// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because -// how do you know the pointer is really of type SubclassOfFoo? It -// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, -// when you downcast, you should use this macro. In debug mode, we -// use dynamic_cast<> to double-check the downcast is legal (we die -// if it's not). In normal mode, we do the efficient static_cast<> -// instead. Thus, it's important to test in debug mode to make sure -// the cast is legal! -// This is the only place in the code we should use dynamic_cast<>. -// In particular, you SHOULDN'T be using dynamic_cast<> in order to -// do RTTI (eg code like this: -// if (dynamic_cast(foo)) HandleASubclass1Object(foo); -// if (dynamic_cast(foo)) HandleASubclass2Object(foo); -// You should design the code some other way not to need this. - -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - if (false) { - implicit_cast(0); - } - -#if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI) - assert(f == NULL || dynamic_cast(f) != NULL); // RTTI: debug mode only! -#endif - return static_cast(f); -} - -template // use like this: down_cast(foo); -inline To down_cast(From& f) { - typedef typename remove_reference::type* ToAsPointer; - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away - // completely. - if (false) { - implicit_cast(0); - } - -#if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI) - // RTTI: debug mode only! - assert(dynamic_cast(&f) != NULL); -#endif - return *static_cast(&f); -} - -template -inline To bit_cast(const From& from) { - GOOGLE_COMPILE_ASSERT(sizeof(From) == sizeof(To), - bit_cast_with_different_sizes); - To dest; - memcpy(&dest, &from, sizeof(dest)); - return dest; -} - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::implicit_cast; -using internal::down_cast; -using internal::bit_cast; - -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_CASTS_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/common.h b/app/src/main/cpp/google/protobuf/stubs/common.h deleted file mode 100644 index 43e88ff..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/common.h +++ /dev/null @@ -1,225 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) and others -// -// Contains basic types and utilities used by the rest of the library. - -#ifndef GOOGLE_PROTOBUF_COMMON_H__ -#define GOOGLE_PROTOBUF_COMMON_H__ - -#include - -#include -#include -#include - -// TODO(liujisi): Remove the following includes after the include clean-up. -#include -#include -#include -#include - -#ifndef PROTOBUF_USE_EXCEPTIONS -#if defined(_MSC_VER) && defined(_CPPUNWIND) - #define PROTOBUF_USE_EXCEPTIONS 1 -#elif defined(__EXCEPTIONS) - #define PROTOBUF_USE_EXCEPTIONS 1 -#else - #define PROTOBUF_USE_EXCEPTIONS 0 -#endif -#endif - -#if PROTOBUF_USE_EXCEPTIONS -#include -#endif -#if defined(__APPLE__) -#include // for TARGET_OS_IPHONE -#endif - -#if defined(__ANDROID__) || defined(GOOGLE_PROTOBUF_OS_ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) || defined(GOOGLE_PROTOBUF_OS_IPHONE) -#include -#endif - -#if defined(_WIN32) && defined(GetMessage) -// Allow GetMessage to be used as a valid method name in protobuf classes. -// windows.h defines GetMessage() as a macro. Let's re-define it as an inline -// function. The inline function should be equivalent for C++ users. -inline BOOL GetMessage_Win32( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#undef GetMessage -inline BOOL GetMessage( - LPMSG lpMsg, HWND hWnd, - UINT wMsgFilterMin, UINT wMsgFilterMax) { - return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax); -} -#endif - -namespace std {} - -namespace google { -namespace protobuf { -namespace internal { - -// Some of these constants are macros rather than const ints so that they can -// be used in #if directives. - -// The current version, represented as a single integer to make comparison -// easier: major * 10^6 + minor * 10^3 + micro -#define GOOGLE_PROTOBUF_VERSION 3001000 - -// The minimum library version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 3001000 - -// The minimum header version which works with the current version of -// the library. This constant should only be used by protoc's C++ code -// generator. -static const int kMinHeaderVersionForLibrary = 3001000; - -// The minimum protoc version which works with the current version of the -// headers. -#define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 3001000 - -// The minimum header version which works with the current version of -// protoc. This constant should only be used in VerifyVersion(). -static const int kMinHeaderVersionForProtoc = 3001000; - -// Verifies that the headers and libraries are compatible. Use the macro -// below to call this. -void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion, - const char* filename); - -// Converts a numeric version number to a string. -std::string LIBPROTOBUF_EXPORT VersionString(int version); - -} // namespace internal - -// Place this macro in your main() function (or somewhere before you attempt -// to use the protobuf library) to verify that the version you link against -// matches the headers you compiled against. If a version mismatch is -// detected, the process will abort. -#define GOOGLE_PROTOBUF_VERIFY_VERSION \ - ::google::protobuf::internal::VerifyVersion( \ - GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \ - __FILE__) - - -// =================================================================== -// from google3/util/utf8/public/unilib.h - -class StringPiece; -namespace internal { - -// Checks if the buffer contains structurally-valid UTF-8. Implemented in -// structurally_valid.cc. -LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len); - -inline bool IsStructurallyValidUTF8(const std::string& str) { - return IsStructurallyValidUTF8(str.data(), static_cast(str.length())); -} - -// Returns initial number of bytes of structually valid UTF-8. -LIBPROTOBUF_EXPORT int UTF8SpnStructurallyValid(const StringPiece& str); - -// Coerce UTF-8 byte string in src_str to be -// a structurally-valid equal-length string by selectively -// overwriting illegal bytes with replace_char (typically ' ' or '?'). -// replace_char must be legal printable 7-bit Ascii 0x20..0x7e. -// src_str is read-only. -// -// Returns pointer to output buffer, src_str.data() if no changes were made, -// or idst if some bytes were changed. idst is allocated by the caller -// and must be at least as big as src_str -// -// Optimized for: all structurally valid and no byte copying is done. -// -LIBPROTOBUF_EXPORT char* UTF8CoerceToStructurallyValid( - const StringPiece& str, char* dst, char replace_char); - -} // namespace internal - - -// =================================================================== -// Shutdown support. - -// Shut down the entire protocol buffers library, deleting all static-duration -// objects allocated by the library or by generated .pb.cc files. -// -// There are two reasons you might want to call this: -// * You use a draconian definition of "memory leak" in which you expect -// every single malloc() to have a corresponding free(), even for objects -// which live until program exit. -// * You are writing a dynamically-loaded library which needs to clean up -// after itself when the library is unloaded. -// -// It is safe to call this multiple times. However, it is not safe to use -// any other part of the protocol buffers library after -// ShutdownProtobufLibrary() has been called. -LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary(); - -namespace internal { - -// Register a function to be called when ShutdownProtocolBuffers() is called. -LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); - -} // namespace internal - -#if PROTOBUF_USE_EXCEPTIONS -class FatalException : public std::exception { - public: - FatalException(const char* filename, int line, const std::string& message) - : filename_(filename), line_(line), message_(message) {} - virtual ~FatalException() throw(); - - virtual const char* what() const throw(); - - const char* filename() const { return filename_; } - int line() const { return line_; } - const std::string& message() const { return message_; } - - private: - const char* filename_; - const int line_; - const std::string message_; -}; -#endif - -// This is at the end of the file instead of the beginning to work around a bug -// in some versions of MSVC. -using namespace std; // Don't do this at home, kids. - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_COMMON_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/fastmem.h b/app/src/main/cpp/google/protobuf/stubs/fastmem.h deleted file mode 100644 index 763a6e6..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/fastmem.h +++ /dev/null @@ -1,152 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Fast memory copying and comparison routines. -// strings::fastmemcmp_inlined() replaces memcmp() -// strings::memcpy_inlined() replaces memcpy() -// strings::memeq(a, b, n) replaces memcmp(a, b, n) == 0 -// -// strings::*_inlined() routines are inline versions of the -// routines exported by this module. Sometimes using the inlined -// versions is faster. Measure before using the inlined versions. -// -// Performance measurement: -// strings::fastmemcmp_inlined -// Analysis: memcmp, fastmemcmp_inlined, fastmemcmp -// 2012-01-30 - -#ifndef GOOGLE_PROTOBUF_STUBS_FASTMEM_H_ -#define GOOGLE_PROTOBUF_STUBS_FASTMEM_H_ - -#include -#include -#include - -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Return true if the n bytes at a equal the n bytes at b. -// The regions are allowed to overlap. -// -// The performance is similar to the performance memcmp(), but faster for -// moderately-sized inputs, or inputs that share a common prefix and differ -// somewhere in their last 8 bytes. Further optimizations can be added later -// if it makes sense to do so.:w -inline bool memeq(const char* a, const char* b, size_t n) { - size_t n_rounded_down = n & ~static_cast(7); - if (GOOGLE_PREDICT_FALSE(n_rounded_down == 0)) { // n <= 7 - return memcmp(a, b, n) == 0; - } - // n >= 8 - uint64 u = GOOGLE_UNALIGNED_LOAD64(a) ^ GOOGLE_UNALIGNED_LOAD64(b); - uint64 v = GOOGLE_UNALIGNED_LOAD64(a + n - 8) ^ GOOGLE_UNALIGNED_LOAD64(b + n - 8); - if ((u | v) != 0) { // The first or last 8 bytes differ. - return false; - } - a += 8; - b += 8; - n = n_rounded_down - 8; - if (n > 128) { - // As of 2012, memcmp on x86-64 uses a big unrolled loop with SSE2 - // instructions, and while we could try to do something faster, it - // doesn't seem worth pursuing. - return memcmp(a, b, n) == 0; - } - for (; n >= 16; n -= 16) { - uint64 x = GOOGLE_UNALIGNED_LOAD64(a) ^ GOOGLE_UNALIGNED_LOAD64(b); - uint64 y = GOOGLE_UNALIGNED_LOAD64(a + 8) ^ GOOGLE_UNALIGNED_LOAD64(b + 8); - if ((x | y) != 0) { - return false; - } - a += 16; - b += 16; - } - // n must be 0 or 8 now because it was a multiple of 8 at the top of the loop. - return n == 0 || GOOGLE_UNALIGNED_LOAD64(a) == GOOGLE_UNALIGNED_LOAD64(b); -} - -inline int fastmemcmp_inlined(const char *a, const char *b, size_t n) { - if (n >= 64) { - return memcmp(a, b, n); - } - const char* a_limit = a + n; - while (a + sizeof(uint64) <= a_limit && - GOOGLE_UNALIGNED_LOAD64(a) == GOOGLE_UNALIGNED_LOAD64(b)) { - a += sizeof(uint64); - b += sizeof(uint64); - } - if (a + sizeof(uint32) <= a_limit && - GOOGLE_UNALIGNED_LOAD32(a) == GOOGLE_UNALIGNED_LOAD32(b)) { - a += sizeof(uint32); - b += sizeof(uint32); - } - while (a < a_limit) { - int d = static_cast(*a++) - static_cast(*b++); - if (d) return d; - } - return 0; -} - -// The standard memcpy operation is slow for variable small sizes. -// This implementation inlines the optimal realization for sizes 1 to 16. -// To avoid code bloat don't use it in case of not performance-critical spots, -// nor when you don't expect very frequent values of size <= 16. -inline void memcpy_inlined(char *dst, const char *src, size_t size) { - // Compiler inlines code with minimal amount of data movement when third - // parameter of memcpy is a constant. - switch (size) { - case 1: memcpy(dst, src, 1); break; - case 2: memcpy(dst, src, 2); break; - case 3: memcpy(dst, src, 3); break; - case 4: memcpy(dst, src, 4); break; - case 5: memcpy(dst, src, 5); break; - case 6: memcpy(dst, src, 6); break; - case 7: memcpy(dst, src, 7); break; - case 8: memcpy(dst, src, 8); break; - case 9: memcpy(dst, src, 9); break; - case 10: memcpy(dst, src, 10); break; - case 11: memcpy(dst, src, 11); break; - case 12: memcpy(dst, src, 12); break; - case 13: memcpy(dst, src, 13); break; - case 14: memcpy(dst, src, 14); break; - case 15: memcpy(dst, src, 15); break; - case 16: memcpy(dst, src, 16); break; - default: memcpy(dst, src, size); break; - } -} - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_FASTMEM_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/hash.h b/app/src/main/cpp/google/protobuf/stubs/hash.h deleted file mode 100644 index 4eac7d5..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/hash.h +++ /dev/null @@ -1,438 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// Deals with the fact that hash_map is not defined everywhere. - -#ifndef GOOGLE_PROTOBUF_STUBS_HASH_H__ -#define GOOGLE_PROTOBUF_STUBS_HASH_H__ - -#include -#include - -#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 -#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 - -// Android -#if defined(__ANDROID__) -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP - -// Use C++11 unordered_{map|set} if available. -#elif ((_LIBCPP_STD_VER >= 11) || \ - (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ - (__GLIBCXX__ > 20090421))) -# define GOOGLE_PROTOBUF_HAS_CXX11_HASH - -// For XCode >= 4.6: the compiler is clang with libc++. -// For earlier XCode version: the compiler is gcc-4.2.1 with libstdc++. -// libc++ provides and friends even in non C++11 mode, -// and it does not provide the tr1 library. Therefore the following macro -// checks against this special case. -// Note that we should not test the __APPLE_CC__ version number or the -// __clang__ macro, since the new compiler can still use -stdlib=libstdc++, in -// which case is not compilable without -std=c++11 -#elif defined(__APPLE_CC__) -# if __GNUC__ >= 4 -# define GOOGLE_PROTOBUF_HAS_TR1 -# else -// Not tested for gcc < 4... These setting can compile under 4.2.1 though. -# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# endif - -// Version checks for gcc. -#elif defined(__GNUC__) -// For GCC 4.x+, use tr1::unordered_map/set; otherwise, follow the -// instructions from: -// https://gcc.gnu.org/onlinedocs/libstdc++/manual/backwards.html -# if __GNUC__ >= 4 -# define GOOGLE_PROTOBUF_HAS_TR1 -# elif __GNUC__ >= 3 -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# if __GNUC__ == 3 && __GNUC_MINOR__ == 0 -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std // GCC 3.0 -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE __gnu_cxx // GCC 3.1 and later -# endif -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# endif - -// Version checks for MSC. -// Apparently Microsoft decided to move hash_map *back* to the std namespace in -// MSVC 2010: -// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx -// And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That -// said, use unordered_map for MSVC 2010 and beyond is our safest bet. -#elif defined(_MSC_VER) -# if _MSC_VER >= 1600 // Since Visual Studio 2010 -# define GOOGLE_PROTOBUF_HAS_CXX11_HASH -# define GOOGLE_PROTOBUF_HASH_COMPARE std::hash_compare -# elif _MSC_VER >= 1500 // Since Visual Studio 2008 -# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# define GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE -# elif _MSC_VER >= 1310 -# define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# else -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set -# define GOOGLE_PROTOBUF_HASH_COMPARE stdext::hash_compare -# endif - -// **ADD NEW COMPILERS SUPPORT HERE.** -// For other compilers, undefine the macro and fallback to use std::map, in -// google/protobuf/stubs/hash.h -#else -# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP -# undef GOOGLE_PROTOBUF_HAVE_HASH_SET -#endif - -#if defined(GOOGLE_PROTOBUF_HAS_CXX11_HASH) -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set -#elif defined(GOOGLE_PROTOBUF_HAS_TR1) -# define GOOGLE_PROTOBUF_HASH_NAMESPACE std::tr1 -# include -# define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map -# include -# define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set -#endif - -# define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START \ - namespace google { \ - namespace protobuf { -# define GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END }} - -#undef GOOGLE_PROTOBUF_HAS_CXX11_HASH -#undef GOOGLE_PROTOBUF_HAS_TR1 - -#if defined(GOOGLE_PROTOBUF_HAVE_HASH_MAP) && \ - defined(GOOGLE_PROTOBUF_HAVE_HASH_SET) -#else -#define GOOGLE_PROTOBUF_MISSING_HASH -#include -#include -#endif - -namespace google { -namespace protobuf { - -#ifdef GOOGLE_PROTOBUF_MISSING_HASH -#undef GOOGLE_PROTOBUF_MISSING_HASH - -// This system doesn't have hash_map or hash_set. Emulate them using map and -// set. - -// Make hash be the same as less. Note that everywhere where custom -// hash functions are defined in the protobuf code, they are also defined such -// that they can be used as "less" functions, which is required by MSVC anyway. -template -struct hash { - // Dummy, just to make derivative hash functions compile. - int operator()(const Key& key) { - GOOGLE_LOG(FATAL) << "Should never be called."; - return 0; - } - - inline bool operator()(const Key& a, const Key& b) const { - return a < b; - } -}; - -// Make sure char* is compared by value. -template <> -struct hash { - // Dummy, just to make derivative hash functions compile. - int operator()(const char* key) { - GOOGLE_LOG(FATAL) << "Should never be called."; - return 0; - } - - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) < 0; - } -}; - -template , - typename EqualKey = std::equal_to, - typename Alloc = std::allocator< std::pair > > -class hash_map : public std::map { - typedef std::map BaseClass; - - public: - hash_map(int a = 0, const HashFcn& b = HashFcn(), - const EqualKey& c = EqualKey(), - const Alloc& d = Alloc()) : BaseClass(b, d) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -template , - typename EqualKey = std::equal_to > -class hash_set : public std::set { - public: - hash_set(int = 0) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) - -template -struct hash : public GOOGLE_PROTOBUF_HASH_COMPARE { -}; - -// MSVC's hash_compare hashes based on the string contents but -// compares based on the string pointer. WTF? -class CstringLess { - public: - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) < 0; - } -}; - -template <> -struct hash - : public GOOGLE_PROTOBUF_HASH_COMPARE {}; - -#ifdef GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE - -template -struct InternalHashCompare : public GOOGLE_PROTOBUF_HASH_COMPARE { - InternalHashCompare() {} - InternalHashCompare(HashFcn hashfcn, EqualKey equalkey) - : hashfcn_(hashfcn), equalkey_(equalkey) {} - size_t operator()(const Key& key) const { return hashfcn_(key); } - bool operator()(const Key& key1, const Key& key2) const { - return !equalkey_(key1, key2); - } - HashFcn hashfcn_; - EqualKey equalkey_; -}; - -template , - typename EqualKey = std::equal_to, - typename Alloc = std::allocator< std::pair > > -class hash_map - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, InternalHashCompare, Alloc> { - typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, InternalHashCompare, Alloc> BaseClass; - - public: - hash_map(int a = 0, const HashFcn& b = HashFcn(), - const EqualKey& c = EqualKey(), const Alloc& d = Alloc()) - : BaseClass(InternalHashCompare(b, c), d) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -template , - typename EqualKey = std::equal_to > -class hash_set - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS< - Key, InternalHashCompare > { - public: - hash_set(int = 0) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -#else // GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE - -template , - typename EqualKey = std::equal_to, - typename Alloc = std::allocator< std::pair > > -class hash_map - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey, Alloc> { - typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey, Alloc> BaseClass; - - public: - hash_map(int a = 0, const HashFcn& b = HashFcn(), - const EqualKey& c = EqualKey(), - const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -template , - typename EqualKey = std::equal_to > -class hash_set - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS< - Key, HashFcn, EqualKey> { - public: - hash_set(int = 0) {} - - HashFcn hash_function() const { return HashFcn(); } -}; -#endif // GOOGLE_PROTOBUF_CONTAINERS_NEED_HASH_COMPARE - -#else // defined(_MSC_VER) && !defined(_STLPORT_VERSION) - -template -struct hash : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash { -}; - -template -struct hash { - inline size_t operator()(const Key* key) const { - return reinterpret_cast(key); - } -}; - -// Unlike the old SGI version, the TR1 "hash" does not special-case char*. So, -// we go ahead and provide our own implementation. -template <> -struct hash { - inline size_t operator()(const char* str) const { - size_t result = 0; - for (; *str != '\0'; str++) { - result = 5 * result + *str; - } - return result; - } -}; - -template<> -struct hash { - size_t operator()(bool x) const { - return static_cast(x); - } -}; - -template , - typename EqualKey = std::equal_to, - typename Alloc = std::allocator< std::pair > > -class hash_map - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey, Alloc> { - typedef GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS< - Key, Data, HashFcn, EqualKey, Alloc> BaseClass; - - public: - hash_map(int a = 0, const HashFcn& b = HashFcn(), - const EqualKey& c = EqualKey(), - const Alloc& d = Alloc()) : BaseClass(a, b, c, d) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -template , - typename EqualKey = std::equal_to > -class hash_set - : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS< - Key, HashFcn, EqualKey> { - public: - hash_set(int = 0) {} - - HashFcn hash_function() const { return HashFcn(); } -}; - -#endif // !GOOGLE_PROTOBUF_MISSING_HASH - -template <> -struct hash { - inline size_t operator()(const string& key) const { - return hash()(key.c_str()); - } - - static const size_t bucket_size = 4; - static const size_t min_buckets = 8; - inline bool operator()(const string& a, const string& b) const { - return a < b; - } -}; - -template -struct hash > { - inline size_t operator()(const pair& key) const { - size_t first_hash = hash()(key.first); - size_t second_hash = hash()(key.second); - - // FIXME(kenton): What is the best way to compute this hash? I have - // no idea! This seems a bit better than an XOR. - return first_hash * ((1 << 16) - 1) + second_hash; - } - - static const size_t bucket_size = 4; - static const size_t min_buckets = 8; - inline bool operator()(const pair& a, - const pair& b) const { - return a < b; - } -}; - -// Used by GCC/SGI STL only. (Why isn't this provided by the standard -// library? :( ) -struct streq { - inline bool operator()(const char* a, const char* b) const { - return strcmp(a, b) == 0; - } -}; - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_HASH_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/logging.h b/app/src/main/cpp/google/protobuf/stubs/logging.h deleted file mode 100644 index f69605d..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/logging.h +++ /dev/null @@ -1,237 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_STUBS_LOGGING_H_ -#define GOOGLE_PROTOBUF_STUBS_LOGGING_H_ - -#include -#include - -// =================================================================== -// emulates google3/base/logging.h - -namespace google { -namespace protobuf { - -enum LogLevel { - LOGLEVEL_INFO, // Informational. This is never actually used by - // libprotobuf. - LOGLEVEL_WARNING, // Warns about issues that, although not technically a - // problem now, could cause problems in the future. For - // example, a // warning will be printed when parsing a - // message that is near the message size limit. - LOGLEVEL_ERROR, // An error occurred which should never happen during - // normal use. - LOGLEVEL_FATAL, // An error occurred from which the library cannot - // recover. This usually indicates a programming error - // in the code which calls the library, especially when - // compiled in debug mode. - -#ifdef NDEBUG - LOGLEVEL_DFATAL = LOGLEVEL_ERROR -#else - LOGLEVEL_DFATAL = LOGLEVEL_FATAL -#endif -}; - -class StringPiece; -namespace util { -class Status; -} -class uint128; -namespace internal { - -class LogFinisher; - -class LIBPROTOBUF_EXPORT LogMessage { - public: - LogMessage(LogLevel level, const char* filename, int line); - ~LogMessage(); - - LogMessage& operator<<(const std::string& value); - LogMessage& operator<<(const char* value); - LogMessage& operator<<(char value); - LogMessage& operator<<(int value); - LogMessage& operator<<(uint value); - LogMessage& operator<<(long value); - LogMessage& operator<<(unsigned long value); - LogMessage& operator<<(long long value); - LogMessage& operator<<(unsigned long long value); - LogMessage& operator<<(double value); - LogMessage& operator<<(void* value); - LogMessage& operator<<(const StringPiece& value); - LogMessage& operator<<(const ::google::protobuf::util::Status& status); - LogMessage& operator<<(const uint128& value); - - private: - friend class LogFinisher; - void Finish(); - - LogLevel level_; - const char* filename_; - int line_; - std::string message_; -}; - -// Used to make the entire "LOG(BLAH) << etc." expression have a void return -// type and print a newline after each message. -class LIBPROTOBUF_EXPORT LogFinisher { - public: - void operator=(LogMessage& other); -}; - -template -bool IsOk(T status) { return status.ok(); } -template<> -inline bool IsOk(bool status) { return status; } - -} // namespace internal - -// Undef everything in case we're being mixed with some other Google library -// which already defined them itself. Presumably all Google libraries will -// support the same syntax for these so it should not be a big deal if they -// end up using our definitions instead. -#undef GOOGLE_LOG -#undef GOOGLE_LOG_IF - -#undef GOOGLE_CHECK -#undef GOOGLE_CHECK_OK -#undef GOOGLE_CHECK_EQ -#undef GOOGLE_CHECK_NE -#undef GOOGLE_CHECK_LT -#undef GOOGLE_CHECK_LE -#undef GOOGLE_CHECK_GT -#undef GOOGLE_CHECK_GE -#undef GOOGLE_CHECK_NOTNULL - -#undef GOOGLE_DLOG -#undef GOOGLE_DCHECK -#undef GOOGLE_DCHECK_OK -#undef GOOGLE_DCHECK_EQ -#undef GOOGLE_DCHECK_NE -#undef GOOGLE_DCHECK_LT -#undef GOOGLE_DCHECK_LE -#undef GOOGLE_DCHECK_GT -#undef GOOGLE_DCHECK_GE - -#define GOOGLE_LOG(LEVEL) \ - ::google::protobuf::internal::LogFinisher() = \ - ::google::protobuf::internal::LogMessage( \ - ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__) -#define GOOGLE_LOG_IF(LEVEL, CONDITION) \ - !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL) - -#define GOOGLE_CHECK(EXPRESSION) \ - GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": " -#define GOOGLE_CHECK_OK(A) GOOGLE_CHECK(::google::protobuf::internal::IsOk(A)) -#define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B)) -#define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B)) -#define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B)) -#define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B)) -#define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B)) -#define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B)) - -namespace internal { -template -T* CheckNotNull(const char* /* file */, int /* line */, - const char* name, T* val) { - if (val == NULL) { - GOOGLE_LOG(FATAL) << name; - } - return val; -} -} // namespace internal -#define GOOGLE_CHECK_NOTNULL(A) \ - ::google::protobuf::internal::CheckNotNull(\ - __FILE__, __LINE__, "'" #A "' must not be NULL", (A)) - -#ifdef NDEBUG - -#define GOOGLE_DLOG(LEVEL) GOOGLE_LOG_IF(LEVEL, false) - -#define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION) -#define GOOGLE_DCHECK_OK(E) GOOGLE_DCHECK(::google::protobuf::internal::IsOk(E)) -#define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B)) -#define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B)) -#define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) < (B)) -#define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B)) -#define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) > (B)) -#define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B)) - -#else // NDEBUG - -#define GOOGLE_DLOG GOOGLE_LOG - -#define GOOGLE_DCHECK GOOGLE_CHECK -#define GOOGLE_DCHECK_OK GOOGLE_CHECK_OK -#define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ -#define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE -#define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT -#define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE -#define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT -#define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE - -#endif // !NDEBUG - -typedef void LogHandler(LogLevel level, const char* filename, int line, - const std::string& message); - -// The protobuf library sometimes writes warning and error messages to -// stderr. These messages are primarily useful for developers, but may -// also help end users figure out a problem. If you would prefer that -// these messages be sent somewhere other than stderr, call SetLogHandler() -// to set your own handler. This returns the old handler. Set the handler -// to NULL to ignore log messages (but see also LogSilencer, below). -// -// Obviously, SetLogHandler is not thread-safe. You should only call it -// at initialization time, and probably not from library code. If you -// simply want to suppress log messages temporarily (e.g. because you -// have some code that tends to trigger them frequently and you know -// the warnings are not important to you), use the LogSilencer class -// below. -LIBPROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func); - -// Create a LogSilencer if you want to temporarily suppress all log -// messages. As long as any LogSilencer objects exist, non-fatal -// log messages will be discarded (the current LogHandler will *not* -// be called). Constructing a LogSilencer is thread-safe. You may -// accidentally suppress log messages occurring in another thread, but -// since messages are generally for debugging purposes only, this isn't -// a big deal. If you want to intercept log messages, use SetLogHandler(). -class LIBPROTOBUF_EXPORT LogSilencer { - public: - LogSilencer(); - ~LogSilencer(); -}; - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_LOGGING_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/macros.h b/app/src/main/cpp/google/protobuf/stubs/macros.h deleted file mode 100644 index 0e9a9ec..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/macros.h +++ /dev/null @@ -1,168 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_MACROS_H__ -#define GOOGLE_PROTOBUF_MACROS_H__ - -#include - -namespace google { -namespace protobuf { - -#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS -#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - -#undef GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS -#define GOOGLE_DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \ - TypeName(); \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - -// =================================================================== -// from google3/base/basictypes.h - -// The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr. -// The expression is a compile-time constant, and therefore can be -// used in defining new arrays, for example. -// -// GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error -// -// "warning: division by zero in ..." -// -// when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer. -// You should only use GOOGLE_ARRAYSIZE on statically allocated arrays. -// -// The following comments are on the implementation details, and can -// be ignored by the users. -// -// ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in -// the array) and sizeof(*(arr)) (the # of bytes in one array -// element). If the former is divisible by the latter, perhaps arr is -// indeed an array, in which case the division result is the # of -// elements in the array. Otherwise, arr cannot possibly be an array, -// and we generate a compiler error to prevent the code from -// compiling. -// -// Since the size of bool is implementation-defined, we need to cast -// !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final -// result has type size_t. -// -// This macro is not perfect as it wrongfully accepts certain -// pointers, namely where the pointer size is divisible by the pointee -// size. Since all our code has to go through a 32-bit compiler, -// where a pointer is 4 bytes, this means all pointers to a type whose -// size is 3 or greater than 4 will be (righteously) rejected. -// -// Kudos to Jorg Brown for this simple and elegant implementation. - -#undef GOOGLE_ARRAYSIZE -#define GOOGLE_ARRAYSIZE(a) \ - ((sizeof(a) / sizeof(*(a))) / \ - static_cast(!(sizeof(a) % sizeof(*(a))))) - -// The COMPILE_ASSERT macro can be used to verify that a compile time -// expression is true. For example, you could use it to verify the -// size of a static array: -// -// COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES, -// content_type_names_incorrect_size); -// -// or to make sure a struct is smaller than a certain size: -// -// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); -// -// The second argument to the macro is the name of the variable. If -// the expression is false, most compilers will issue a warning/error -// containing the name of the variable. - -namespace internal { - -template -struct CompileAssert { -}; - -} // namespace internal - -#undef GOOGLE_COMPILE_ASSERT -#if __cplusplus >= 201103L -#define GOOGLE_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) -#else -#define GOOGLE_COMPILE_ASSERT(expr, msg) \ - ::google::protobuf::internal::CompileAssert<(bool(expr))> \ - msg[bool(expr) ? 1 : -1]; \ - (void)msg -// Implementation details of COMPILE_ASSERT: -// -// - COMPILE_ASSERT works by defining an array type that has -1 -// elements (and thus is invalid) when the expression is false. -// -// - The simpler definition -// -// #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1] -// -// does not work, as gcc supports variable-length arrays whose sizes -// are determined at run-time (this is gcc's extension and not part -// of the C++ standard). As a result, gcc fails to reject the -// following code with the simple definition: -// -// int foo; -// COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is -// // not a compile-time constant. -// -// - By using the type CompileAssert<(bool(expr))>, we ensures that -// expr is a compile-time constant. (Template arguments must be -// determined at compile-time.) -// -// - The outter parentheses in CompileAssert<(bool(expr))> are necessary -// to work around a bug in gcc 3.4.4 and 4.0.1. If we had written -// -// CompileAssert -// -// instead, these compilers will refuse to compile -// -// COMPILE_ASSERT(5 > 0, some_message); -// -// (They seem to think the ">" in "5 > 0" marks the end of the -// template argument list.) -// -// - The array size is (bool(expr) ? 1 : -1), instead of simply -// -// ((expr) ? 1 : -1). -// -// This is to avoid running into a bug in MS VC 7.1, which -// causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1. -#endif // __cplusplus >= 201103L - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_MACROS_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/mutex.h b/app/src/main/cpp/google/protobuf/stubs/mutex.h deleted file mode 100644 index 7ef1cb6..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/mutex.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_STUBS_MUTEX_H_ -#define GOOGLE_PROTOBUF_STUBS_MUTEX_H_ - -#ifdef GOOGLE_PROTOBUF_NO_THREADLOCAL -#include -#endif - -#include - -// =================================================================== -// emulates google3/base/mutex.h -namespace google { -namespace protobuf { -namespace internal { - -// A Mutex is a non-reentrant (aka non-recursive) mutex. At most one thread T -// may hold a mutex at a given time. If T attempts to Lock() the same Mutex -// while holding it, T will deadlock. -class LIBPROTOBUF_EXPORT Mutex { - public: - // Create a Mutex that is not held by anybody. - Mutex(); - - // Destructor - ~Mutex(); - - // Block if necessary until this Mutex is free, then acquire it exclusively. - void Lock(); - - // Release this Mutex. Caller must hold it exclusively. - void Unlock(); - - // Crash if this Mutex is not held exclusively by this thread. - // May fail to crash when it should; will never crash when it should not. - void AssertHeld(); - - private: - struct Internal; - Internal* mInternal; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex); -}; - -// Undefine the macros to workaround the conflicts with Google internal -// MutexLock implementation. -// TODO(liujisi): Remove the undef once internal macros are removed. -#undef MutexLock -#undef ReaderMutexLock -#undef WriterMutexLock -#undef MutexLockMaybe - -// MutexLock(mu) acquires mu when constructed and releases it when destroyed. -class LIBPROTOBUF_EXPORT MutexLock { - public: - explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); } - ~MutexLock() { this->mu_->Unlock(); } - private: - Mutex *const mu_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock); -}; - -// TODO(kenton): Implement these? Hard to implement portably. -typedef MutexLock ReaderMutexLock; -typedef MutexLock WriterMutexLock; - -// MutexLockMaybe is like MutexLock, but is a no-op when mu is NULL. -class LIBPROTOBUF_EXPORT MutexLockMaybe { - public: - explicit MutexLockMaybe(Mutex *mu) : - mu_(mu) { if (this->mu_ != NULL) { this->mu_->Lock(); } } - ~MutexLockMaybe() { if (this->mu_ != NULL) { this->mu_->Unlock(); } } - private: - Mutex *const mu_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe); -}; - -#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) -template -class ThreadLocalStorage { - public: - ThreadLocalStorage() { - pthread_key_create(&key_, &ThreadLocalStorage::Delete); - } - ~ThreadLocalStorage() { - pthread_key_delete(key_); - } - T* Get() { - T* result = static_cast(pthread_getspecific(key_)); - if (result == NULL) { - result = new T(); - pthread_setspecific(key_, result); - } - return result; - } - private: - static void Delete(void* value) { - delete static_cast(value); - } - pthread_key_t key_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ThreadLocalStorage); -}; -#endif - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::Mutex; -using internal::MutexLock; -using internal::ReaderMutexLock; -using internal::WriterMutexLock; -using internal::MutexLockMaybe; - - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_MUTEX_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/once.h b/app/src/main/cpp/google/protobuf/stubs/once.h deleted file mode 100644 index 1f082c3..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/once.h +++ /dev/null @@ -1,167 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: kenton@google.com (Kenton Varda) -// -// emulates google3/base/once.h -// -// This header is intended to be included only by internal .cc files and -// generated .pb.cc files. Users should not use this directly. -// -// This is basically a portable version of pthread_once(). -// -// This header declares: -// * A type called ProtobufOnceType. -// * A macro GOOGLE_PROTOBUF_DECLARE_ONCE() which declares a variable of type -// ProtobufOnceType. This is the only legal way to declare such a variable. -// The macro may only be used at the global scope (you cannot create local or -// class member variables of this type). -// * A function GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()). -// This function, when invoked multiple times given the same ProtobufOnceType -// object, will invoke init_func on the first call only, and will make sure -// none of the calls return before that first call to init_func has finished. -// * The user can provide a parameter which GoogleOnceInit() forwards to the -// user-provided function when it is called. Usage example: -// int a = 10; -// GoogleOnceInit(&my_once, &MyFunctionExpectingIntArgument, &a); -// * This implementation guarantees that ProtobufOnceType is a POD (i.e. no -// static initializer generated). -// -// This implements a way to perform lazy initialization. It's more efficient -// than using mutexes as no lock is needed if initialization has already -// happened. -// -// Example usage: -// void Init(); -// GOOGLE_PROTOBUF_DECLARE_ONCE(once_init); -// -// // Calls Init() exactly once. -// void InitOnce() { -// GoogleOnceInit(&once_init, &Init); -// } -// -// Note that if GoogleOnceInit() is called before main() has begun, it must -// only be called by the thread that will eventually call main() -- that is, -// the thread that performs dynamic initialization. In general this is a safe -// assumption since people don't usually construct threads before main() starts, -// but it is technically not guaranteed. Unfortunately, Win32 provides no way -// whatsoever to statically-initialize its synchronization primitives, so our -// only choice is to assume that dynamic initialization is single-threaded. - -#ifndef GOOGLE_PROTOBUF_STUBS_ONCE_H__ -#define GOOGLE_PROTOBUF_STUBS_ONCE_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { - -#ifdef GOOGLE_PROTOBUF_NO_THREAD_SAFETY - -typedef bool ProtobufOnceType; - -#define GOOGLE_PROTOBUF_ONCE_INIT false - -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { - if (!*once) { - *once = true; - init_func(); - } -} - -template -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)(Arg), - Arg arg) { - if (!*once) { - *once = true; - init_func(arg); - } -} - -#else - -enum { - ONCE_STATE_UNINITIALIZED = 0, - ONCE_STATE_EXECUTING_CLOSURE = 1, - ONCE_STATE_DONE = 2 -}; - -typedef internal::AtomicWord ProtobufOnceType; - -#define GOOGLE_PROTOBUF_ONCE_INIT ::google::protobuf::ONCE_STATE_UNINITIALIZED - -LIBPROTOBUF_EXPORT -void GoogleOnceInitImpl(ProtobufOnceType* once, Closure* closure); - -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { - if (internal::Acquire_Load(once) != ONCE_STATE_DONE) { - internal::FunctionClosure0 func(init_func, false); - GoogleOnceInitImpl(once, &func); - } -} - -template -inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)(Arg*), - Arg* arg) { - if (internal::Acquire_Load(once) != ONCE_STATE_DONE) { - internal::FunctionClosure1 func(init_func, false, arg); - GoogleOnceInitImpl(once, &func); - } -} - -#endif // GOOGLE_PROTOBUF_NO_THREAD_SAFETY - -class GoogleOnceDynamic { - public: - GoogleOnceDynamic() : state_(GOOGLE_PROTOBUF_ONCE_INIT) { } - - // If this->Init() has not been called before by any thread, - // execute (*func_with_arg)(arg) then return. - // Otherwise, wait until that prior invocation has finished - // executing its function, then return. - template - void Init(void (*func_with_arg)(T*), T* arg) { - GoogleOnceInit(&this->state_, - func_with_arg, - arg); - } - private: - ProtobufOnceType state_; -}; - -#define GOOGLE_PROTOBUF_DECLARE_ONCE(NAME) \ - ::google::protobuf::ProtobufOnceType NAME = GOOGLE_PROTOBUF_ONCE_INIT - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_ONCE_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/platform_macros.h b/app/src/main/cpp/google/protobuf/stubs/platform_macros.h deleted file mode 100644 index 4ba4b34..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/platform_macros.h +++ /dev/null @@ -1,125 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2012 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_PLATFORM_MACROS_H_ -#define GOOGLE_PROTOBUF_PLATFORM_MACROS_H_ - -#define GOOGLE_PROTOBUF_PLATFORM_ERROR \ -#error "Host platform was not detected as supported by protobuf" - -// Processor architecture detection. For more info on what's defined, see: -// http://msdn.microsoft.com/en-us/library/b0084kay.aspx -// http://www.agner.org/optimize/calling_conventions.pdf -// or with gcc, run: "echo | gcc -E -dM -" -#if defined(_M_X64) || defined(__x86_64__) -#define GOOGLE_PROTOBUF_ARCH_X64 1 -#define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -#elif defined(_M_IX86) || defined(__i386__) -#define GOOGLE_PROTOBUF_ARCH_IA32 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__QNX__) -#define GOOGLE_PROTOBUF_ARCH_ARM_QNX 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__ARMEL__) -#define GOOGLE_PROTOBUF_ARCH_ARM 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__aarch64__) -#define GOOGLE_PROTOBUF_ARCH_AARCH64 1 -#define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -#elif defined(__MIPSEL__) -#if defined(__LP64__) -#define GOOGLE_PROTOBUF_ARCH_MIPS64 1 -#define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -#else -#define GOOGLE_PROTOBUF_ARCH_MIPS 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#endif -#elif defined(__pnacl__) -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(sparc) -#define GOOGLE_PROTOBUF_ARCH_SPARC 1 -#if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__) -#define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -#else -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#endif -#elif defined(_POWER) || defined(__powerpc64__) || defined(__PPC64__) -#define GOOGLE_PROTOBUF_ARCH_POWER 1 -#define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -#elif defined(__PPC__) -#define GOOGLE_PROTOBUF_ARCH_PPC 1 -#define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -#elif defined(__GNUC__) -# if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)) || (__GNUC__ > 4)) -// We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h -# elif defined(__clang__) -# if !__has_extension(c_atomic) -GOOGLE_PROTOBUF_PLATFORM_ERROR -# endif -// We fallback to the generic Clang/GCC >= 4.7 implementation in atomicops.h -# endif -# if __LP64__ -# define GOOGLE_PROTOBUF_ARCH_64_BIT 1 -# else -# define GOOGLE_PROTOBUF_ARCH_32_BIT 1 -# endif -#else -GOOGLE_PROTOBUF_PLATFORM_ERROR -#endif - -#if defined(__APPLE__) -#define GOOGLE_PROTOBUF_OS_APPLE -#include -#if TARGET_OS_IPHONE -#define GOOGLE_PROTOBUF_OS_IPHONE -#endif -#elif defined(__EMSCRIPTEN__) -#define GOOGLE_PROTOBUF_OS_EMSCRIPTEN -#elif defined(__native_client__) -#define GOOGLE_PROTOBUF_OS_NACL -#elif defined(sun) -#define GOOGLE_PROTOBUF_OS_SOLARIS -#elif defined(_AIX) -#define GOOGLE_PROTOBUF_OS_AIX -#elif defined(__ANDROID__) -#define GOOGLE_PROTOBUF_OS_ANDROID -#endif - -#undef GOOGLE_PROTOBUF_PLATFORM_ERROR - -#if defined(GOOGLE_PROTOBUF_OS_ANDROID) || defined(GOOGLE_PROTOBUF_OS_IPHONE) -// Android ndk does not support the __thread keyword very well yet. Here -// we use pthread_key_create()/pthread_getspecific()/... methods for -// TLS support on android. -// iOS also does not support the __thread keyword. -#define GOOGLE_PROTOBUF_NO_THREADLOCAL -#endif - -#endif // GOOGLE_PROTOBUF_PLATFORM_MACROS_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/port.h b/app/src/main/cpp/google/protobuf/stubs/port.h deleted file mode 100644 index 376be5f..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/port.h +++ /dev/null @@ -1,448 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_STUBS_PORT_H_ -#define GOOGLE_PROTOBUF_STUBS_PORT_H_ - -#include -#include -#include -#include -#include -#if defined(__osf__) -// Tru64 lacks stdint.h, but has inttypes.h which defines a superset of -// what stdint.h would define. -#include -#elif !defined(_MSC_VER) -#include -#endif - -#undef PROTOBUF_LITTLE_ENDIAN -#ifdef _WIN32 - // Assuming windows is always little-endian. - // TODO(xiaofeng): The PROTOBUF_LITTLE_ENDIAN is not only used for - // optimization but also for correctness. We should define an - // different macro to test the big-endian code path in coded_stream. - #if !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif - #if _MSC_VER >= 1300 && !defined(__INTEL_COMPILER) - // If MSVC has "/RTCc" set, it will complain about truncating casts at - // runtime. This file contains some intentional truncating casts. - #pragma runtime_checks("c", off) - #endif -#else - #include // __BYTE_ORDER - #if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ - (defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \ - !defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST) - #define PROTOBUF_LITTLE_ENDIAN 1 - #endif -#endif -#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS) - #ifdef LIBPROTOBUF_EXPORTS - #define LIBPROTOBUF_EXPORT __declspec(dllexport) - #else - #define LIBPROTOBUF_EXPORT __declspec(dllimport) - #endif - #ifdef LIBPROTOC_EXPORTS - #define LIBPROTOC_EXPORT __declspec(dllexport) - #else - #define LIBPROTOC_EXPORT __declspec(dllimport) - #endif -#else - #define LIBPROTOBUF_EXPORT - #define LIBPROTOC_EXPORT -#endif - -// These #includes are for the byte swap functions declared later on. -#ifdef _MSC_VER -#include // NOLINT(build/include) -#elif defined(__APPLE__) -#include -#elif defined(__GLIBC__) || defined(__CYGWIN__) -#include // IWYU pragma: export -#endif - -// =================================================================== -// from google3/base/port.h -namespace google { -namespace protobuf { - -typedef unsigned int uint; - -#ifdef _MSC_VER -typedef signed __int8 int8; -typedef __int16 int16; -typedef __int32 int32; -typedef __int64 int64; - -typedef unsigned __int8 uint8; -typedef unsigned __int16 uint16; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; -#else -typedef int8_t int8; -typedef int16_t int16; -typedef int32_t int32; -typedef int64_t int64; - -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; -#endif - -// long long macros to be used because gcc and vc++ use different suffixes, -// and different size specifiers in format strings -#undef GOOGLE_LONGLONG -#undef GOOGLE_ULONGLONG -#undef GOOGLE_LL_FORMAT - -#ifdef _MSC_VER -#define GOOGLE_LONGLONG(x) x##I64 -#define GOOGLE_ULONGLONG(x) x##UI64 -#define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...) -#else -// By long long, we actually mean int64. -#define GOOGLE_LONGLONG(x) x##LL -#define GOOGLE_ULONGLONG(x) x##ULL -// Used to format real long long integers. -#define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also. -#endif - -static const int32 kint32max = 0x7FFFFFFF; -static const int32 kint32min = -kint32max - 1; -static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF); -static const int64 kint64min = -kint64max - 1; -static const uint32 kuint32max = 0xFFFFFFFFu; -static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF); - -// ------------------------------------------------------------------- -// Annotations: Some parts of the code have been annotated in ways that might -// be useful to some compilers or tools, but are not supported universally. -// You can #define these annotations yourself if the default implementation -// is not right for you. - -#ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE -#if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) -// For functions we want to force inline. -// Introduced in gcc 3.1. -#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) -#else -// Other compilers will have to figure it out for themselves. -#define GOOGLE_ATTRIBUTE_ALWAYS_INLINE -#endif -#endif - -#ifndef GOOGLE_ATTRIBUTE_NOINLINE -#if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) -// For functions we want to force not inline. -// Introduced in gcc 3.1. -#define GOOGLE_ATTRIBUTE_NOINLINE __attribute__ ((noinline)) -#elif defined(_MSC_VER) && (_MSC_VER >= 1400) -// Seems to have been around since at least Visual Studio 2005 -#define GOOGLE_ATTRIBUTE_NOINLINE __declspec(noinline) -#else -// Other compilers will have to figure it out for themselves. -#define GOOGLE_ATTRIBUTE_NOINLINE -#endif -#endif - -#ifndef GOOGLE_ATTRIBUTE_NORETURN -#ifdef __GNUC__ -// Tell the compiler that a given function never returns. -#define GOOGLE_ATTRIBUTE_NORETURN __attribute__((noreturn)) -#else -#define GOOGLE_ATTRIBUTE_NORETURN -#endif -#endif - -#ifndef GOOGLE_ATTRIBUTE_DEPRECATED -#ifdef __GNUC__ -// If the method/variable/type is used anywhere, produce a warning. -#define GOOGLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated)) -#else -#define GOOGLE_ATTRIBUTE_DEPRECATED -#endif -#endif - -#ifndef GOOGLE_PREDICT_TRUE -#ifdef __GNUC__ -// Provided at least since GCC 3.0. -#define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) -#else -#define GOOGLE_PREDICT_TRUE(x) (x) -#endif -#endif - -#ifndef GOOGLE_PREDICT_FALSE -#ifdef __GNUC__ -// Provided at least since GCC 3.0. -#define GOOGLE_PREDICT_FALSE(x) (__builtin_expect(x, 0)) -#else -#define GOOGLE_PREDICT_FALSE(x) (x) -#endif -#endif - -// Delimits a block of code which may write to memory which is simultaneously -// written by other threads, but which has been determined to be thread-safe -// (e.g. because it is an idempotent write). -#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN -#define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN() -#endif -#ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END -#define GOOGLE_SAFE_CONCURRENT_WRITES_END() -#endif - -#if defined(__clang__) && defined(__has_cpp_attribute) \ - && !defined(GOOGLE_PROTOBUF_OS_APPLE) -# if defined(GOOGLE_PROTOBUF_OS_NACL) || defined(EMSCRIPTEN) || \ - __has_cpp_attribute(clang::fallthrough) -# define GOOGLE_FALLTHROUGH_INTENDED [[clang::fallthrough]] -# endif -#endif - -#ifndef GOOGLE_FALLTHROUGH_INTENDED -# define GOOGLE_FALLTHROUGH_INTENDED -#endif - -#define GOOGLE_GUARDED_BY(x) -#define GOOGLE_ATTRIBUTE_COLD - -// x86 and x86-64 can perform unaligned loads/stores directly. -#if defined(_M_X64) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(__i386__) - -#define GOOGLE_UNALIGNED_LOAD16(_p) (*reinterpret_cast(_p)) -#define GOOGLE_UNALIGNED_LOAD32(_p) (*reinterpret_cast(_p)) -#define GOOGLE_UNALIGNED_LOAD64(_p) (*reinterpret_cast(_p)) - -#define GOOGLE_UNALIGNED_STORE16(_p, _val) (*reinterpret_cast(_p) = (_val)) -#define GOOGLE_UNALIGNED_STORE32(_p, _val) (*reinterpret_cast(_p) = (_val)) -#define GOOGLE_UNALIGNED_STORE64(_p, _val) (*reinterpret_cast(_p) = (_val)) - -#else -inline uint16 GOOGLE_UNALIGNED_LOAD16(const void *p) { - uint16 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline uint32 GOOGLE_UNALIGNED_LOAD32(const void *p) { - uint32 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline uint64 GOOGLE_UNALIGNED_LOAD64(const void *p) { - uint64 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline void GOOGLE_UNALIGNED_STORE16(void *p, uint16 v) { - memcpy(p, &v, sizeof v); -} - -inline void GOOGLE_UNALIGNED_STORE32(void *p, uint32 v) { - memcpy(p, &v, sizeof v); -} - -inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) { - memcpy(p, &v, sizeof v); -} -#endif - -#if defined(_MSC_VER) -#define GOOGLE_THREAD_LOCAL __declspec(thread) -#else -#define GOOGLE_THREAD_LOCAL __thread -#endif - -// The following guarantees declaration of the byte swap functions. -#ifdef _MSC_VER -#define bswap_16(x) _byteswap_ushort(x) -#define bswap_32(x) _byteswap_ulong(x) -#define bswap_64(x) _byteswap_uint64(x) - -#elif defined(__APPLE__) -// Mac OS X / Darwin features -#define bswap_16(x) OSSwapInt16(x) -#define bswap_32(x) OSSwapInt32(x) -#define bswap_64(x) OSSwapInt64(x) - -#elif !defined(__GLIBC__) && !defined(__CYGWIN__) - -static inline uint16 bswap_16(uint16 x) { - return static_cast(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8)); -} -#define bswap_16(x) bswap_16(x) -static inline uint32 bswap_32(uint32 x) { - return (((x & 0xFF) << 24) | - ((x & 0xFF00) << 8) | - ((x & 0xFF0000) >> 8) | - ((x & 0xFF000000) >> 24)); -} -#define bswap_32(x) bswap_32(x) -static inline uint64 bswap_64(uint64 x) { - return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) | - ((x & GOOGLE_ULONGLONG(0xFF00)) << 40) | - ((x & GOOGLE_ULONGLONG(0xFF0000)) << 24) | - ((x & GOOGLE_ULONGLONG(0xFF000000)) << 8) | - ((x & GOOGLE_ULONGLONG(0xFF00000000)) >> 8) | - ((x & GOOGLE_ULONGLONG(0xFF0000000000)) >> 24) | - ((x & GOOGLE_ULONGLONG(0xFF000000000000)) >> 40) | - ((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56)); -} -#define bswap_64(x) bswap_64(x) - -#endif - -// =================================================================== -// from google3/util/bits/bits.h - -class Bits { - public: - static uint32 Log2FloorNonZero(uint32 n) { -#if defined(__GNUC__) - return 31 ^ __builtin_clz(n); -#elif defined(COMPILER_MSVC) && defined(_M_IX86) - _asm { - bsr ebx, n - mov n, ebx - } - return n; -#else - return Log2FloorNonZero_Portable(n); -#endif - } - - static uint64 Log2FloorNonZero64(uint64 n) { -#if defined(__GNUC__) - return 63 ^ __builtin_clzll(n); -#else - return Log2FloorNonZero64_Portable(n); -#endif - } - private: - static int Log2FloorNonZero_Portable(uint32 n) { - if (n == 0) - return -1; - int log = 0; - uint32 value = n; - for (int i = 4; i >= 0; --i) { - int shift = (1 << i); - uint32 x = value >> shift; - if (x != 0) { - value = x; - log += shift; - } - } - assert(value == 1); - return log; - } - - static int Log2FloorNonZero64_Portable(uint64 n) { - const uint32 topbits = static_cast(n >> 32); - if (topbits == 0) { - // Top bits are zero, so scan in bottom bits - return Log2FloorNonZero(static_cast(n)); - } else { - return 32 + Log2FloorNonZero(topbits); - } - } -}; - -// =================================================================== -// from google3/util/endian/endian.h -LIBPROTOBUF_EXPORT uint32 ghtonl(uint32 x); - -class BigEndian { - public: -#ifdef PROTOBUF_LITTLE_ENDIAN - - static uint16 FromHost16(uint16 x) { return bswap_16(x); } - static uint16 ToHost16(uint16 x) { return bswap_16(x); } - - static uint32 FromHost32(uint32 x) { return bswap_32(x); } - static uint32 ToHost32(uint32 x) { return bswap_32(x); } - - static uint64 FromHost64(uint64 x) { return bswap_64(x); } - static uint64 ToHost64(uint64 x) { return bswap_64(x); } - - static bool IsLittleEndian() { return true; } - -#else - - static uint16 FromHost16(uint16 x) { return x; } - static uint16 ToHost16(uint16 x) { return x; } - - static uint32 FromHost32(uint32 x) { return x; } - static uint32 ToHost32(uint32 x) { return x; } - - static uint64 FromHost64(uint64 x) { return x; } - static uint64 ToHost64(uint64 x) { return x; } - - static bool IsLittleEndian() { return false; } - -#endif /* ENDIAN */ - - // Functions to do unaligned loads and stores in big-endian order. - static uint16 Load16(const void *p) { - return ToHost16(GOOGLE_UNALIGNED_LOAD16(p)); - } - - static void Store16(void *p, uint16 v) { - GOOGLE_UNALIGNED_STORE16(p, FromHost16(v)); - } - - static uint32 Load32(const void *p) { - return ToHost32(GOOGLE_UNALIGNED_LOAD32(p)); - } - - static void Store32(void *p, uint32 v) { - GOOGLE_UNALIGNED_STORE32(p, FromHost32(v)); - } - - static uint64 Load64(const void *p) { - return ToHost64(GOOGLE_UNALIGNED_LOAD64(p)); - } - - static void Store64(void *p, uint64 v) { - GOOGLE_UNALIGNED_STORE64(p, FromHost64(v)); - } -}; - - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_PORT_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/scoped_ptr.h b/app/src/main/cpp/google/protobuf/stubs/scoped_ptr.h deleted file mode 100644 index 4423c11..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/scoped_ptr.h +++ /dev/null @@ -1,236 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef GOOGLE_PROTOBUF_STUBS_SCOPED_PTR_H_ -#define GOOGLE_PROTOBUF_STUBS_SCOPED_PTR_H_ - -#include - -namespace google { -namespace protobuf { - -// =================================================================== -// from google3/base/scoped_ptr.h - -namespace internal { - -// This is an implementation designed to match the anticipated future TR2 -// implementation of the scoped_ptr class, and its closely-related brethren, -// scoped_array, scoped_ptr_malloc, and make_scoped_ptr. - -template class scoped_ptr; -template class scoped_array; - -// A scoped_ptr is like a T*, except that the destructor of scoped_ptr -// automatically deletes the pointer it holds (if any). -// That is, scoped_ptr owns the T object that it points to. -// Like a T*, a scoped_ptr may hold either NULL or a pointer to a T object. -// -// The size of a scoped_ptr is small: -// sizeof(scoped_ptr) == sizeof(C*) -template -class scoped_ptr { - public: - - // The element type - typedef C element_type; - - // Constructor. Defaults to initializing with NULL. - // There is no way to create an uninitialized scoped_ptr. - // The input parameter must be allocated with new. - explicit scoped_ptr(C* p = NULL) : ptr_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_ptr() { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != ptr_) { - enum { type_must_be_complete = sizeof(C) }; - delete ptr_; - ptr_ = p; - } - } - - // Accessors to get the owned object. - // operator* and operator-> will assert() if there is no current object. - C& operator*() const { - assert(ptr_ != NULL); - return *ptr_; - } - C* operator->() const { - assert(ptr_ != NULL); - return ptr_; - } - C* get() const { return ptr_; } - - // Comparison operators. - // These return whether two scoped_ptr refer to the same object, not just to - // two different but equal objects. - bool operator==(C* p) const { return ptr_ == p; } - bool operator!=(C* p) const { return ptr_ != p; } - - // Swap two scoped pointers. - void swap(scoped_ptr& p2) { - C* tmp = ptr_; - ptr_ = p2.ptr_; - p2.ptr_ = tmp; - } - - // Release a pointer. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = ptr_; - ptr_ = NULL; - return retVal; - } - - private: - C* ptr_; - - // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't - // make sense, and if C2 == C, it still doesn't make sense because you should - // never have the same object owned by two different scoped_ptrs. - template bool operator==(scoped_ptr const& p2) const; - template bool operator!=(scoped_ptr const& p2) const; - - // Disallow evil constructors - scoped_ptr(const scoped_ptr&); - void operator=(const scoped_ptr&); -}; - -// scoped_array is like scoped_ptr, except that the caller must allocate -// with new [] and the destructor deletes objects with delete []. -// -// As with scoped_ptr, a scoped_array either points to an object -// or is NULL. A scoped_array owns the object that it points to. -// -// Size: sizeof(scoped_array) == sizeof(C*) -template -class scoped_array { - public: - - // The element type - typedef C element_type; - - // Constructor. Defaults to initializing with NULL. - // There is no way to create an uninitialized scoped_array. - // The input parameter must be allocated with new []. - explicit scoped_array(C* p = NULL) : array_(p) { } - - // Destructor. If there is a C object, delete it. - // We don't need to test ptr_ == NULL because C++ does that for us. - ~scoped_array() { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - } - - // Reset. Deletes the current owned object, if any. - // Then takes ownership of a new object, if given. - // this->reset(this->get()) works. - void reset(C* p = NULL) { - if (p != array_) { - enum { type_must_be_complete = sizeof(C) }; - delete[] array_; - array_ = p; - } - } - - // Get one element of the current object. - // Will assert() if there is no current object, or index i is negative. - C& operator[](std::ptrdiff_t i) const { - assert(i >= 0); - assert(array_ != NULL); - return array_[i]; - } - - // Get a pointer to the zeroth element of the current object. - // If there is no current object, return NULL. - C* get() const { - return array_; - } - - // Comparison operators. - // These return whether two scoped_array refer to the same object, not just to - // two different but equal objects. - bool operator==(C* p) const { return array_ == p; } - bool operator!=(C* p) const { return array_ != p; } - - // Swap two scoped arrays. - void swap(scoped_array& p2) { - C* tmp = array_; - array_ = p2.array_; - p2.array_ = tmp; - } - - // Release an array. - // The return value is the current pointer held by this object. - // If this object holds a NULL pointer, the return value is NULL. - // After this operation, this object will hold a NULL pointer, - // and will not own the object any more. - C* release() { - C* retVal = array_; - array_ = NULL; - return retVal; - } - - private: - C* array_; - - // Forbid comparison of different scoped_array types. - template bool operator==(scoped_array const& p2) const; - template bool operator!=(scoped_array const& p2) const; - - // Disallow evil constructors - scoped_array(const scoped_array&); - void operator=(const scoped_array&); -}; - -} // namespace internal - -// We made these internal so that they would show up as such in the docs, -// but we don't want to stick "internal::" in front of them everywhere. -using internal::scoped_ptr; -using internal::scoped_array; - - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_SCOPED_PTR_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/shared_ptr.h b/app/src/main/cpp/google/protobuf/stubs/shared_ptr.h deleted file mode 100644 index d250bf4..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/shared_ptr.h +++ /dev/null @@ -1,470 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/util/gtl/shared_ptr.h - -#ifndef GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ -#define GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ - -#include - -#include // for swap -#include -#include - -namespace google { -namespace protobuf { -namespace internal { - -// Alias to std::shared_ptr for any C++11 platform, -// and for any supported MSVC compiler. -#if !defined(UTIL_GTL_USE_STD_SHARED_PTR) && \ - (defined(COMPILER_MSVC) || defined(LANG_CXX11)) -#define UTIL_GTL_USE_STD_SHARED_PTR 1 -#endif - -#if defined(UTIL_GTL_USE_STD_SHARED_PTR) && UTIL_GTL_USE_STD_SHARED_PTR - -// These are transitional. They will be going away soon. -// Please just #include and just type std::shared_ptr yourself, instead -// of relying on this file. -// -// Migration doc: http://go/std-shared-ptr-lsc -using std::enable_shared_from_this; -using std::shared_ptr; -using std::static_pointer_cast; -using std::weak_ptr; - -#else // below, UTIL_GTL_USE_STD_SHARED_PTR not set or set to 0. - -// For everything else there is the google3 implementation. -inline bool RefCountDec(volatile Atomic32 *ptr) { - return Barrier_AtomicIncrement(ptr, -1) != 0; -} - -inline void RefCountInc(volatile Atomic32 *ptr) { - NoBarrier_AtomicIncrement(ptr, 1); -} - -template class shared_ptr; -template class weak_ptr; - -// This class is an internal implementation detail for shared_ptr. If two -// shared_ptrs point to the same object, they also share a control block. -// An "empty" shared_pointer refers to NULL and also has a NULL control block. -// It contains all of the state that's needed for reference counting or any -// other kind of resource management. In this implementation the control block -// happens to consist of two atomic words, the reference count (the number -// of shared_ptrs that share ownership of the object) and the weak count -// (the number of weak_ptrs that observe the object, plus 1 if the -// refcount is nonzero). -// -// The "plus 1" is to prevent a race condition in the shared_ptr and -// weak_ptr destructors. We need to make sure the control block is -// only deleted once, so we need to make sure that at most one -// object sees the weak count decremented from 1 to 0. -class SharedPtrControlBlock { - template friend class shared_ptr; - template friend class weak_ptr; - private: - SharedPtrControlBlock() : refcount_(1), weak_count_(1) { } - Atomic32 refcount_; - Atomic32 weak_count_; -}; - -// Forward declaration. The class is defined below. -template class enable_shared_from_this; - -template -class shared_ptr { - template friend class weak_ptr; - public: - typedef T element_type; - - shared_ptr() : ptr_(NULL), control_block_(NULL) {} - - explicit shared_ptr(T* ptr) - : ptr_(ptr), - control_block_(ptr != NULL ? new SharedPtrControlBlock : NULL) { - // If p is non-null and T inherits from enable_shared_from_this, we - // set up the data that shared_from_this needs. - MaybeSetupWeakThis(ptr); - } - - // Copy constructor: makes this object a copy of ptr, and increments - // the reference count. - template - shared_ptr(const shared_ptr& ptr) - : ptr_(NULL), - control_block_(NULL) { - Initialize(ptr); - } - // Need non-templated version to prevent the compiler-generated default - shared_ptr(const shared_ptr& ptr) - : ptr_(NULL), - control_block_(NULL) { - Initialize(ptr); - } - - // Assignment operator. Replaces the existing shared_ptr with ptr. - // Increment ptr's reference count and decrement the one being replaced. - template - shared_ptr& operator=(const shared_ptr& ptr) { - if (ptr_ != ptr.ptr_) { - shared_ptr me(ptr); // will hold our previous state to be destroyed. - swap(me); - } - return *this; - } - - // Need non-templated version to prevent the compiler-generated default - shared_ptr& operator=(const shared_ptr& ptr) { - if (ptr_ != ptr.ptr_) { - shared_ptr me(ptr); // will hold our previous state to be destroyed. - swap(me); - } - return *this; - } - - // TODO(austern): Consider providing this constructor. The draft C++ standard - // (20.8.10.2.1) includes it. However, it says that this constructor throws - // a bad_weak_ptr exception when ptr is expired. Is it better to provide this - // constructor and make it do something else, like fail with a CHECK, or to - // leave this constructor out entirely? - // - // template - // shared_ptr(const weak_ptr& ptr); - - ~shared_ptr() { - if (ptr_ != NULL) { - if (!RefCountDec(&control_block_->refcount_)) { - delete ptr_; - - // weak_count_ is defined as the number of weak_ptrs that observe - // ptr_, plus 1 if refcount_ is nonzero. - if (!RefCountDec(&control_block_->weak_count_)) { - delete control_block_; - } - } - } - } - - // Replaces underlying raw pointer with the one passed in. The reference - // count is set to one (or zero if the pointer is NULL) for the pointer - // being passed in and decremented for the one being replaced. - // - // If you have a compilation error with this code, make sure you aren't - // passing NULL, nullptr, or 0 to this function. Call reset without an - // argument to reset to a null ptr. - template - void reset(Y* p) { - if (p != ptr_) { - shared_ptr tmp(p); - tmp.swap(*this); - } - } - - void reset() { - reset(static_cast(NULL)); - } - - // Exchanges the contents of this with the contents of r. This function - // supports more efficient swapping since it eliminates the need for a - // temporary shared_ptr object. - void swap(shared_ptr& r) { - using std::swap; // http://go/using-std-swap - swap(ptr_, r.ptr_); - swap(control_block_, r.control_block_); - } - - // The following function is useful for gaining access to the underlying - // pointer when a shared_ptr remains in scope so the reference-count is - // known to be > 0 (e.g. for parameter passing). - T* get() const { - return ptr_; - } - - T& operator*() const { - return *ptr_; - } - - T* operator->() const { - return ptr_; - } - - long use_count() const { - return control_block_ ? control_block_->refcount_ : 1; - } - - bool unique() const { - return use_count() == 1; - } - - private: - // If r is non-empty, initialize *this to share ownership with r, - // increasing the underlying reference count. - // If r is empty, *this remains empty. - // Requires: this is empty, namely this->ptr_ == NULL. - template - void Initialize(const shared_ptr& r) { - // This performs a static_cast on r.ptr_ to U*, which is a no-op since it - // is already a U*. So initialization here requires that r.ptr_ is - // implicitly convertible to T*. - InitializeWithStaticCast(r); - } - - // Initializes *this as described in Initialize, but additionally performs a - // static_cast from r.ptr_ (V*) to U*. - // NOTE(gfc): We'd need a more general form to support const_pointer_cast and - // dynamic_pointer_cast, but those operations are sufficiently discouraged - // that supporting static_pointer_cast is sufficient. - template - void InitializeWithStaticCast(const shared_ptr& r) { - if (r.control_block_ != NULL) { - RefCountInc(&r.control_block_->refcount_); - - ptr_ = static_cast(r.ptr_); - control_block_ = r.control_block_; - } - } - - // Helper function for the constructor that takes a raw pointer. If T - // doesn't inherit from enable_shared_from_this then we have nothing to - // do, so this function is trivial and inline. The other version is declared - // out of line, after the class definition of enable_shared_from_this. - void MaybeSetupWeakThis(enable_shared_from_this* ptr); - void MaybeSetupWeakThis(...) { } - - T* ptr_; - SharedPtrControlBlock* control_block_; - -#ifndef SWIG - template - friend class shared_ptr; - - template - friend shared_ptr static_pointer_cast(const shared_ptr& rhs); -#endif -}; - -// Matches the interface of std::swap as an aid to generic programming. -template void swap(shared_ptr& r, shared_ptr& s) { - r.swap(s); -} - -template -shared_ptr static_pointer_cast(const shared_ptr& rhs) { - shared_ptr lhs; - lhs.template InitializeWithStaticCast(rhs); - return lhs; -} - -// See comments at the top of the file for a description of why this -// class exists, and the draft C++ standard (as of July 2009 the -// latest draft is N2914) for the detailed specification. -template -class weak_ptr { - template friend class weak_ptr; - public: - typedef T element_type; - - // Create an empty (i.e. already expired) weak_ptr. - weak_ptr() : ptr_(NULL), control_block_(NULL) { } - - // Create a weak_ptr that observes the same object that ptr points - // to. Note that there is no race condition here: we know that the - // control block can't disappear while we're looking at it because - // it is owned by at least one shared_ptr, ptr. - template weak_ptr(const shared_ptr& ptr) { - CopyFrom(ptr.ptr_, ptr.control_block_); - } - - // Copy a weak_ptr. The object it points to might disappear, but we - // don't care: we're only working with the control block, and it can't - // disappear while we're looking at because it's owned by at least one - // weak_ptr, ptr. - template weak_ptr(const weak_ptr& ptr) { - CopyFrom(ptr.ptr_, ptr.control_block_); - } - - // Need non-templated version to prevent default copy constructor - weak_ptr(const weak_ptr& ptr) { - CopyFrom(ptr.ptr_, ptr.control_block_); - } - - // Destroy the weak_ptr. If no shared_ptr owns the control block, and if - // we are the last weak_ptr to own it, then it can be deleted. Note that - // weak_count_ is defined as the number of weak_ptrs sharing this control - // block, plus 1 if there are any shared_ptrs. We therefore know that it's - // safe to delete the control block when weak_count_ reaches 0, without - // having to perform any additional tests. - ~weak_ptr() { - if (control_block_ != NULL && - !RefCountDec(&control_block_->weak_count_)) { - delete control_block_; - } - } - - weak_ptr& operator=(const weak_ptr& ptr) { - if (&ptr != this) { - weak_ptr tmp(ptr); - tmp.swap(*this); - } - return *this; - } - template weak_ptr& operator=(const weak_ptr& ptr) { - weak_ptr tmp(ptr); - tmp.swap(*this); - return *this; - } - template weak_ptr& operator=(const shared_ptr& ptr) { - weak_ptr tmp(ptr); - tmp.swap(*this); - return *this; - } - - void swap(weak_ptr& ptr) { - using std::swap; // http://go/using-std-swap - swap(ptr_, ptr.ptr_); - swap(control_block_, ptr.control_block_); - } - - void reset() { - weak_ptr tmp; - tmp.swap(*this); - } - - // Return the number of shared_ptrs that own the object we are observing. - // Note that this number can be 0 (if this pointer has expired). - long use_count() const { - return control_block_ != NULL ? control_block_->refcount_ : 0; - } - - bool expired() const { return use_count() == 0; } - - // Return a shared_ptr that owns the object we are observing. If we - // have expired, the shared_ptr will be empty. We have to be careful - // about concurrency, though, since some other thread might be - // destroying the last owning shared_ptr while we're in this - // function. We want to increment the refcount only if it's nonzero - // and get the new value, and we want that whole operation to be - // atomic. - shared_ptr lock() const { - shared_ptr result; - if (control_block_ != NULL) { - Atomic32 old_refcount; - do { - old_refcount = control_block_->refcount_; - if (old_refcount == 0) - break; - } while (old_refcount != - NoBarrier_CompareAndSwap( - &control_block_->refcount_, old_refcount, - old_refcount + 1)); - if (old_refcount > 0) { - result.ptr_ = ptr_; - result.control_block_ = control_block_; - } - } - - return result; - } - - private: - void CopyFrom(T* ptr, SharedPtrControlBlock* control_block) { - ptr_ = ptr; - control_block_ = control_block; - if (control_block_ != NULL) - RefCountInc(&control_block_->weak_count_); - } - - private: - element_type* ptr_; - SharedPtrControlBlock* control_block_; -}; - -template void swap(weak_ptr& r, weak_ptr& s) { - r.swap(s); -} - -// See comments at the top of the file for a description of why this class -// exists, and section 20.8.10.5 of the draft C++ standard (as of July 2009 -// the latest draft is N2914) for the detailed specification. -template -class enable_shared_from_this { - friend class shared_ptr; - public: - // Precondition: there must be a shared_ptr that owns *this and that was - // created, directly or indirectly, from a raw pointer of type T*. (The - // latter part of the condition is technical but not quite redundant; it - // rules out some complicated uses involving inheritance hierarchies.) - shared_ptr shared_from_this() { - // Behavior is undefined if the precondition isn't satisfied; we choose - // to die with a CHECK failure. - CHECK(!weak_this_.expired()) << "No shared_ptr owns this object"; - return weak_this_.lock(); - } - shared_ptr shared_from_this() const { - CHECK(!weak_this_.expired()) << "No shared_ptr owns this object"; - return weak_this_.lock(); - } - - protected: - enable_shared_from_this() { } - enable_shared_from_this(const enable_shared_from_this& other) { } - enable_shared_from_this& operator=(const enable_shared_from_this& other) { - return *this; - } - ~enable_shared_from_this() { } - - private: - weak_ptr weak_this_; -}; - -// This is a helper function called by shared_ptr's constructor from a raw -// pointer. If T inherits from enable_shared_from_this, it sets up -// weak_this_ so that shared_from_this works correctly. If T does not inherit -// from weak_this we get a different overload, defined inline, which does -// nothing. -template -void shared_ptr::MaybeSetupWeakThis(enable_shared_from_this* ptr) { - if (ptr) { - CHECK(ptr->weak_this_.expired()) << "Object already owned by a shared_ptr"; - ptr->weak_this_ = *this; - } -} - -#endif // UTIL_GTL_USE_STD_SHARED_PTR - -} // internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_SHARED_PTR_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/singleton.h b/app/src/main/cpp/google/protobuf/stubs/singleton.h deleted file mode 100644 index 9301f54..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/singleton.h +++ /dev/null @@ -1,68 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2014 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef GOOGLE_PROTOBUF_STUBS_SINGLETON_H__ -#define GOOGLE_PROTOBUF_STUBS_SINGLETON_H__ - -#include -#include -#include - -namespace google { -namespace protobuf { -namespace internal { -template -class Singleton { - public: - static T* get() { - GoogleOnceInit(&once_, &Singleton::Init); - return instance_; - } - static void ShutDown() { - delete instance_; - instance_ = NULL; - } - private: - static void Init() { - instance_ = new T(); - } - static ProtobufOnceType once_; - static T* instance_; -}; - -template -ProtobufOnceType Singleton::once_; - -template -T* Singleton::instance_ = NULL; -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_SINGLETON_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/status.h b/app/src/main/cpp/google/protobuf/stubs/status.h deleted file mode 100644 index 614ab99..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/status.h +++ /dev/null @@ -1,116 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef GOOGLE_PROTOBUF_STUBS_STATUS_H_ -#define GOOGLE_PROTOBUF_STUBS_STATUS_H_ - -#include -#include - -#include -#include - -namespace google { -namespace protobuf { -namespace util { -namespace error { -// These values must match error codes defined in google/rpc/code.proto. -enum Code { - OK = 0, - CANCELLED = 1, - UNKNOWN = 2, - INVALID_ARGUMENT = 3, - DEADLINE_EXCEEDED = 4, - NOT_FOUND = 5, - ALREADY_EXISTS = 6, - PERMISSION_DENIED = 7, - UNAUTHENTICATED = 16, - RESOURCE_EXHAUSTED = 8, - FAILED_PRECONDITION = 9, - ABORTED = 10, - OUT_OF_RANGE = 11, - UNIMPLEMENTED = 12, - INTERNAL = 13, - UNAVAILABLE = 14, - DATA_LOSS = 15, -}; -} // namespace error - -class LIBPROTOBUF_EXPORT Status { - public: - // Creates a "successful" status. - Status(); - - // Create a status in the canonical error space with the specified - // code, and error message. If "code == 0", error_message is - // ignored and a Status object identical to Status::OK is - // constructed. - Status(error::Code error_code, StringPiece error_message); - Status(const Status&); - Status& operator=(const Status& x); - ~Status() {} - - // Some pre-defined Status objects - static const Status OK; // Identical to 0-arg constructor - static const Status CANCELLED; - static const Status UNKNOWN; - - // Accessor - bool ok() const { - return error_code_ == error::OK; - } - int error_code() const { - return error_code_; - } - StringPiece error_message() const { - return error_message_; - } - - bool operator==(const Status& x) const; - bool operator!=(const Status& x) const { - return !operator==(x); - } - - // Return a combination of the error code name and message. - string ToString() const; - - private: - error::Code error_code_; - string error_message_; -}; - -// Prints a human-readable representation of 'x' to 'os'. -LIBPROTOBUF_EXPORT ostream& operator<<(ostream& os, const Status& x); - -#define EXPECT_OK(value) EXPECT_TRUE((value).ok()) - -} // namespace util -} // namespace protobuf -} // namespace google -#endif // GOOGLE_PROTOBUF_STUBS_STATUS_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/stl_util.h b/app/src/main/cpp/google/protobuf/stubs/stl_util.h deleted file mode 100644 index 9e4c82a..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/stl_util.h +++ /dev/null @@ -1,121 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// from google3/util/gtl/stl_util.h - -#ifndef GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ -#define GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ - -#include - -namespace google { -namespace protobuf { - -// STLDeleteContainerPointers() -// For a range within a container of pointers, calls delete -// (non-array version) on these pointers. -// NOTE: for these three functions, we could just implement a DeleteObject -// functor and then call for_each() on the range and functor, but this -// requires us to pull in all of algorithm.h, which seems expensive. -// For hash_[multi]set, it is important that this deletes behind the iterator -// because the hash_set may call the hash function on the iterator when it is -// advanced, which could result in the hash function trying to deference a -// stale pointer. -template -void STLDeleteContainerPointers(ForwardIterator begin, - ForwardIterator end) { - while (begin != end) { - ForwardIterator temp = begin; - ++begin; - delete *temp; - } -} - -// Inside Google, this function implements a horrible, disgusting hack in which -// we reach into the string's private implementation and resize it without -// initializing the new bytes. In some cases doing this can significantly -// improve performance. However, since it's totally non-portable it has no -// place in open source code. Feel free to fill this function in with your -// own disgusting hack if you want the perf boost. -inline void STLStringResizeUninitialized(string* s, size_t new_size) { - s->resize(new_size); -} - -// Return a mutable char* pointing to a string's internal buffer, -// which may not be null-terminated. Writing through this pointer will -// modify the string. -// -// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the -// next call to a string method that invalidates iterators. -// -// As of 2006-04, there is no standard-blessed way of getting a -// mutable reference to a string's internal buffer. However, issue 530 -// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#530) -// proposes this as the method. According to Matt Austern, this should -// already work on all current implementations. -inline char* string_as_array(string* str) { - // DO NOT USE const_cast(str->data())! See the unittest for why. - return str->empty() ? NULL : &*str->begin(); -} - -// STLDeleteElements() deletes all the elements in an STL container and clears -// the container. This function is suitable for use with a vector, set, -// hash_set, or any other STL container which defines sensible begin(), end(), -// and clear() methods. -// -// If container is NULL, this function is a no-op. -// -// As an alternative to calling STLDeleteElements() directly, consider -// ElementDeleter (defined below), which ensures that your container's elements -// are deleted when the ElementDeleter goes out of scope. -template -void STLDeleteElements(T *container) { - if (!container) return; - STLDeleteContainerPointers(container->begin(), container->end()); - container->clear(); -} - -// Given an STL container consisting of (key, value) pairs, STLDeleteValues -// deletes all the "value" components and clears the container. Does nothing -// in the case it's given a NULL pointer. - -template -void STLDeleteValues(T *v) { - if (!v) return; - for (typename T::iterator i = v->begin(); i != v->end(); ++i) { - delete i->second; - } - v->clear(); -} - -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_STUBS_STL_UTIL_H__ diff --git a/app/src/main/cpp/google/protobuf/stubs/stringpiece.h b/app/src/main/cpp/google/protobuf/stubs/stringpiece.h deleted file mode 100644 index 8910688..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/stringpiece.h +++ /dev/null @@ -1,483 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// A StringPiece points to part or all of a string, Cord, double-quoted string -// literal, or other string-like object. A StringPiece does *not* own the -// string to which it points. A StringPiece is not null-terminated. -// -// You can use StringPiece as a function or method parameter. A StringPiece -// parameter can receive a double-quoted string literal argument, a "const -// char*" argument, a string argument, or a StringPiece argument with no data -// copying. Systematic use of StringPiece for arguments reduces data -// copies and strlen() calls. -// -// Prefer passing StringPieces by value: -// void MyFunction(StringPiece arg); -// If circumstances require, you may also pass by const reference: -// void MyFunction(const StringPiece& arg); // not preferred -// Both of these have the same lifetime semantics. Passing by value -// generates slightly smaller code. For more discussion, see the thread -// go/stringpiecebyvalue on c-users. -// -// StringPiece is also suitable for local variables if you know that -// the lifetime of the underlying object is longer than the lifetime -// of your StringPiece variable. -// -// Beware of binding a StringPiece to a temporary: -// StringPiece sp = obj.MethodReturningString(); // BAD: lifetime problem -// -// This code is okay: -// string str = obj.MethodReturningString(); // str owns its contents -// StringPiece sp(str); // GOOD, because str outlives sp -// -// StringPiece is sometimes a poor choice for a return value and usually a poor -// choice for a data member. If you do use a StringPiece this way, it is your -// responsibility to ensure that the object pointed to by the StringPiece -// outlives the StringPiece. -// -// A StringPiece may represent just part of a string; thus the name "Piece". -// For example, when splitting a string, vector is a natural data -// type for the output. For another example, a Cord is a non-contiguous, -// potentially very long string-like object. The Cord class has an interface -// that iteratively provides StringPiece objects that point to the -// successive pieces of a Cord object. -// -// A StringPiece is not null-terminated. If you write code that scans a -// StringPiece, you must check its length before reading any characters. -// Common idioms that work on null-terminated strings do not work on -// StringPiece objects. -// -// There are several ways to create a null StringPiece: -// StringPiece() -// StringPiece(NULL) -// StringPiece(NULL, 0) -// For all of the above, sp.data() == NULL, sp.length() == 0, -// and sp.empty() == true. Also, if you create a StringPiece with -// a non-NULL pointer then sp.data() != NULL. Once created, -// sp.data() will stay either NULL or not-NULL, except if you call -// sp.clear() or sp.set(). -// -// Thus, you can use StringPiece(NULL) to signal an out-of-band value -// that is different from other StringPiece values. This is similar -// to the way that const char* p1 = NULL; is different from -// const char* p2 = "";. -// -// There are many ways to create an empty StringPiece: -// StringPiece() -// StringPiece(NULL) -// StringPiece(NULL, 0) -// StringPiece("") -// StringPiece("", 0) -// StringPiece("abcdef", 0) -// StringPiece("abcdef"+6, 0) -// For all of the above, sp.length() will be 0 and sp.empty() will be true. -// For some empty StringPiece values, sp.data() will be NULL. -// For some empty StringPiece values, sp.data() will not be NULL. -// -// Be careful not to confuse: null StringPiece and empty StringPiece. -// The set of empty StringPieces properly includes the set of null StringPieces. -// That is, every null StringPiece is an empty StringPiece, -// but some non-null StringPieces are empty Stringpieces too. -// -// All empty StringPiece values compare equal to each other. -// Even a null StringPieces compares equal to a non-null empty StringPiece: -// StringPiece() == StringPiece("", 0) -// StringPiece(NULL) == StringPiece("abc", 0) -// StringPiece(NULL, 0) == StringPiece("abcdef"+6, 0) -// -// Look carefully at this example: -// StringPiece("") == NULL -// True or false? TRUE, because StringPiece::operator== converts -// the right-hand side from NULL to StringPiece(NULL), -// and then compares two zero-length spans of characters. -// However, we are working to make this example produce a compile error. -// -// Suppose you want to write: -// bool TestWhat?(StringPiece sp) { return sp == NULL; } // BAD -// Do not do that. Write one of these instead: -// bool TestNull(StringPiece sp) { return sp.data() == NULL; } -// bool TestEmpty(StringPiece sp) { return sp.empty(); } -// The intent of TestWhat? is unclear. Did you mean TestNull or TestEmpty? -// Right now, TestWhat? behaves likes TestEmpty. -// We are working to make TestWhat? produce a compile error. -// TestNull is good to test for an out-of-band signal. -// TestEmpty is good to test for an empty StringPiece. -// -// Caveats (again): -// (1) The lifetime of the pointed-to string (or piece of a string) -// must be longer than the lifetime of the StringPiece. -// (2) There may or may not be a '\0' character after the end of -// StringPiece data. -// (3) A null StringPiece is empty. -// An empty StringPiece may or may not be a null StringPiece. - -#ifndef GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_ -#define GOOGLE_PROTOBUF_STUBS_STRINGPIECE_H_ - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace google { -namespace protobuf { -// StringPiece has *two* size types. -// StringPiece::size_type -// is unsigned -// is 32 bits in LP32, 64 bits in LP64, 64 bits in LLP64 -// no future changes intended -// stringpiece_ssize_type -// is signed -// is 32 bits in LP32, 64 bits in LP64, 64 bits in LLP64 -// future changes intended: http://go/64BitStringPiece -// -typedef string::difference_type stringpiece_ssize_type; - -// STRINGPIECE_CHECK_SIZE protects us from 32-bit overflows. -// TODO(mec): delete this after stringpiece_ssize_type goes 64 bit. -#if !defined(NDEBUG) -#define STRINGPIECE_CHECK_SIZE 1 -#elif defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE > 0 -#define STRINGPIECE_CHECK_SIZE 1 -#else -#define STRINGPIECE_CHECK_SIZE 0 -#endif - -class LIBPROTOBUF_EXPORT StringPiece { - private: - const char* ptr_; - stringpiece_ssize_type length_; - - // Prevent overflow in debug mode or fortified mode. - // sizeof(stringpiece_ssize_type) may be smaller than sizeof(size_t). - static stringpiece_ssize_type CheckedSsizeTFromSizeT(size_t size) { -#if STRINGPIECE_CHECK_SIZE > 0 -#ifdef max -#undef max -#endif - if (size > static_cast( - std::numeric_limits::max())) { - // Some people grep for this message in logs - // so take care if you ever change it. - LogFatalSizeTooBig(size, "size_t to int conversion"); - } -#endif - return static_cast(size); - } - - // Out-of-line error path. - static void LogFatalSizeTooBig(size_t size, const char* details); - - public: - // We provide non-explicit singleton constructors so users can pass - // in a "const char*" or a "string" wherever a "StringPiece" is - // expected. - // - // Style guide exception granted: - // http://goto/style-guide-exception-20978288 - StringPiece() : ptr_(NULL), length_(0) {} - - StringPiece(const char* str) // NOLINT(runtime/explicit) - : ptr_(str), length_(0) { - if (str != NULL) { - length_ = CheckedSsizeTFromSizeT(strlen(str)); - } - } - - template - StringPiece( // NOLINT(runtime/explicit) - const std::basic_string, Allocator>& str) - : ptr_(str.data()), length_(0) { - length_ = CheckedSsizeTFromSizeT(str.size()); - } - - StringPiece(const char* offset, stringpiece_ssize_type len) - : ptr_(offset), length_(len) { - assert(len >= 0); - } - - // Substring of another StringPiece. - // pos must be non-negative and <= x.length(). - StringPiece(StringPiece x, stringpiece_ssize_type pos); - // Substring of another StringPiece. - // pos must be non-negative and <= x.length(). - // len must be non-negative and will be pinned to at most x.length() - pos. - StringPiece(StringPiece x, - stringpiece_ssize_type pos, - stringpiece_ssize_type len); - - // data() may return a pointer to a buffer with embedded NULs, and the - // returned buffer may or may not be null terminated. Therefore it is - // typically a mistake to pass data() to a routine that expects a NUL - // terminated string. - const char* data() const { return ptr_; } - stringpiece_ssize_type size() const { return length_; } - stringpiece_ssize_type length() const { return length_; } - bool empty() const { return length_ == 0; } - - void clear() { - ptr_ = NULL; - length_ = 0; - } - - void set(const char* data, stringpiece_ssize_type len) { - assert(len >= 0); - ptr_ = data; - length_ = len; - } - - void set(const char* str) { - ptr_ = str; - if (str != NULL) - length_ = CheckedSsizeTFromSizeT(strlen(str)); - else - length_ = 0; - } - - void set(const void* data, stringpiece_ssize_type len) { - ptr_ = reinterpret_cast(data); - length_ = len; - } - - char operator[](stringpiece_ssize_type i) const { - assert(0 <= i); - assert(i < length_); - return ptr_[i]; - } - - void remove_prefix(stringpiece_ssize_type n) { - assert(length_ >= n); - ptr_ += n; - length_ -= n; - } - - void remove_suffix(stringpiece_ssize_type n) { - assert(length_ >= n); - length_ -= n; - } - - // returns {-1, 0, 1} - int compare(StringPiece x) const { - const stringpiece_ssize_type min_size = - length_ < x.length_ ? length_ : x.length_; - int r = memcmp(ptr_, x.ptr_, min_size); - if (r < 0) return -1; - if (r > 0) return 1; - if (length_ < x.length_) return -1; - if (length_ > x.length_) return 1; - return 0; - } - - string as_string() const { - return ToString(); - } - // We also define ToString() here, since many other string-like - // interfaces name the routine that converts to a C++ string - // "ToString", and it's confusing to have the method that does that - // for a StringPiece be called "as_string()". We also leave the - // "as_string()" method defined here for existing code. - string ToString() const { - if (ptr_ == NULL) return string(); - return string(data(), size()); - } - - operator string() const { - return ToString(); - } - - void CopyToString(string* target) const; - void AppendToString(string* target) const; - - bool starts_with(StringPiece x) const { - return (length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0); - } - - bool ends_with(StringPiece x) const { - return ((length_ >= x.length_) && - (memcmp(ptr_ + (length_-x.length_), x.ptr_, x.length_) == 0)); - } - - // Checks whether StringPiece starts with x and if so advances the beginning - // of it to past the match. It's basically a shortcut for starts_with - // followed by remove_prefix. - bool Consume(StringPiece x); - // Like above but for the end of the string. - bool ConsumeFromEnd(StringPiece x); - - // standard STL container boilerplate - typedef char value_type; - typedef const char* pointer; - typedef const char& reference; - typedef const char& const_reference; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - static const size_type npos; - typedef const char* const_iterator; - typedef const char* iterator; - typedef std::reverse_iterator const_reverse_iterator; - typedef std::reverse_iterator reverse_iterator; - iterator begin() const { return ptr_; } - iterator end() const { return ptr_ + length_; } - const_reverse_iterator rbegin() const { - return const_reverse_iterator(ptr_ + length_); - } - const_reverse_iterator rend() const { - return const_reverse_iterator(ptr_); - } - stringpiece_ssize_type max_size() const { return length_; } - stringpiece_ssize_type capacity() const { return length_; } - - // cpplint.py emits a false positive [build/include_what_you_use] - stringpiece_ssize_type copy(char* buf, size_type n, size_type pos = 0) const; // NOLINT - - bool contains(StringPiece s) const; - - stringpiece_ssize_type find(StringPiece s, size_type pos = 0) const; - stringpiece_ssize_type find(char c, size_type pos = 0) const; - stringpiece_ssize_type rfind(StringPiece s, size_type pos = npos) const; - stringpiece_ssize_type rfind(char c, size_type pos = npos) const; - - stringpiece_ssize_type find_first_of(StringPiece s, size_type pos = 0) const; - stringpiece_ssize_type find_first_of(char c, size_type pos = 0) const { - return find(c, pos); - } - stringpiece_ssize_type find_first_not_of(StringPiece s, - size_type pos = 0) const; - stringpiece_ssize_type find_first_not_of(char c, size_type pos = 0) const; - stringpiece_ssize_type find_last_of(StringPiece s, - size_type pos = npos) const; - stringpiece_ssize_type find_last_of(char c, size_type pos = npos) const { - return rfind(c, pos); - } - stringpiece_ssize_type find_last_not_of(StringPiece s, - size_type pos = npos) const; - stringpiece_ssize_type find_last_not_of(char c, size_type pos = npos) const; - - StringPiece substr(size_type pos, size_type n = npos) const; -}; - -// This large function is defined inline so that in a fairly common case where -// one of the arguments is a literal, the compiler can elide a lot of the -// following comparisons. -inline bool operator==(StringPiece x, StringPiece y) { - stringpiece_ssize_type len = x.size(); - if (len != y.size()) { - return false; - } - - return x.data() == y.data() || len <= 0 || - memcmp(x.data(), y.data(), len) == 0; -} - -inline bool operator!=(StringPiece x, StringPiece y) { - return !(x == y); -} - -inline bool operator<(StringPiece x, StringPiece y) { - const stringpiece_ssize_type min_size = - x.size() < y.size() ? x.size() : y.size(); - const int r = memcmp(x.data(), y.data(), min_size); - return (r < 0) || (r == 0 && x.size() < y.size()); -} - -inline bool operator>(StringPiece x, StringPiece y) { - return y < x; -} - -inline bool operator<=(StringPiece x, StringPiece y) { - return !(x > y); -} - -inline bool operator>=(StringPiece x, StringPiece y) { - return !(x < y); -} - -// allow StringPiece to be logged -extern std::ostream& operator<<(std::ostream& o, StringPiece piece); - -namespace internal { -// StringPiece is not a POD and can not be used in an union (pre C++11). We -// need a POD version of it. -struct StringPiecePod { - // Create from a StringPiece. - static StringPiecePod CreateFromStringPiece(StringPiece str) { - StringPiecePod pod; - pod.data_ = str.data(); - pod.size_ = str.size(); - return pod; - } - - // Cast to StringPiece. - operator StringPiece() const { return StringPiece(data_, size_); } - - bool operator==(const char* value) const { - return StringPiece(data_, size_) == StringPiece(value); - } - - char operator[](stringpiece_ssize_type i) const { - assert(0 <= i); - assert(i < size_); - return data_[i]; - } - - const char* data() const { return data_; } - - stringpiece_ssize_type size() const { - return size_; - } - - std::string ToString() const { return std::string(data_, size_); } - private: - const char* data_; - stringpiece_ssize_type size_; -}; - -} // namespace internal -} // namespace protobuf -} // namespace google - -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_START -template<> struct hash { - size_t operator()(const StringPiece& s) const { - size_t result = 0; - for (const char *str = s.data(), *end = str + s.size(); str < end; str++) { - result = 5 * result + *str; - } - return result; - } -}; -GOOGLE_PROTOBUF_HASH_NAMESPACE_DECLARATION_END - -#endif // STRINGS_STRINGPIECE_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/template_util.h b/app/src/main/cpp/google/protobuf/stubs/template_util.h deleted file mode 100644 index feef904..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/template_util.h +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2005 Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// ---- -// Author: lar@google.com (Laramie Leavitt) -// -// Template metaprogramming utility functions. -// -// This code is compiled directly on many platforms, including client -// platforms like Windows, Mac, and embedded systems. Before making -// any changes here, make sure that you're not breaking any platforms. -// -// -// The names chosen here reflect those used in tr1 and the boost::mpl -// library, there are similar operations used in the Loki library as -// well. I prefer the boost names for 2 reasons: -// 1. I think that portions of the Boost libraries are more likely to -// be included in the c++ standard. -// 2. It is not impossible that some of the boost libraries will be -// included in our own build in the future. -// Both of these outcomes means that we may be able to directly replace -// some of these with boost equivalents. -// -#ifndef GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ -#define GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ - -namespace google { -namespace protobuf { -namespace internal { - -// Types small_ and big_ are guaranteed such that sizeof(small_) < -// sizeof(big_) -typedef char small_; - -struct big_ { - char dummy[2]; -}; - -// Identity metafunction. -template -struct identity_ { - typedef T type; -}; - -// integral_constant, defined in tr1, is a wrapper for an integer -// value. We don't really need this generality; we could get away -// with hardcoding the integer type to bool. We use the fully -// general integer_constant for compatibility with tr1. - -template -struct integral_constant { - static const T value = v; - typedef T value_type; - typedef integral_constant type; -}; - -template const T integral_constant::value; - - -// Abbreviations: true_type and false_type are structs that represent boolean -// true and false values. Also define the boost::mpl versions of those names, -// true_ and false_. -typedef integral_constant true_type; -typedef integral_constant false_type; -typedef true_type true_; -typedef false_type false_; - -// if_ is a templatized conditional statement. -// if_ is a compile time evaluation of cond. -// if_<>::type contains A if cond is true, B otherwise. -template -struct if_{ - typedef A type; -}; - -template -struct if_ { - typedef B type; -}; - - -// type_equals_ is a template type comparator, similar to Loki IsSameType. -// type_equals_::value is true iff "A" is the same type as "B". -// -// New code should prefer base::is_same, defined in base/type_traits.h. -// It is functionally identical, but is_same is the standard spelling. -template -struct type_equals_ : public false_ { -}; - -template -struct type_equals_ : public true_ { -}; - -// and_ is a template && operator. -// and_::value evaluates "A::value && B::value". -template -struct and_ : public integral_constant { -}; - -// or_ is a template || operator. -// or_::value evaluates "A::value || B::value". -template -struct or_ : public integral_constant { -}; - - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_TEMPLATE_UTIL_H_ diff --git a/app/src/main/cpp/google/protobuf/stubs/type_traits.h b/app/src/main/cpp/google/protobuf/stubs/type_traits.h deleted file mode 100644 index 8d48c6a..0000000 --- a/app/src/main/cpp/google/protobuf/stubs/type_traits.h +++ /dev/null @@ -1,372 +0,0 @@ -// Copyright (c) 2006, Google Inc. -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// ---- -// Author: Matt Austern -// -// This code is compiled directly on many platforms, including client -// platforms like Windows, Mac, and embedded systems. Before making -// any changes here, make sure that you're not breaking any platforms. -// -// Define a small subset of tr1 type traits. The traits we define are: -// enable_if -// is_integral -// is_floating_point -// is_pointer -// is_enum -// is_reference -// is_pod -// has_trivial_constructor -// has_trivial_copy -// has_trivial_assign -// has_trivial_destructor -// remove_const -// remove_volatile -// remove_cv -// remove_reference -// add_reference -// remove_pointer -// is_same -// is_convertible -// We can add more type traits as required. - -#ifndef GOOGLE_PROTOBUF_TYPE_TRAITS_H_ -#define GOOGLE_PROTOBUF_TYPE_TRAITS_H_ - -#include // for NULL -#include // For pair - -#include // For true_type and false_type - -namespace google { -namespace protobuf { -namespace internal { - -template -struct is_base_of { - typedef char (&yes)[1]; - typedef char (&no)[2]; - - // BEGIN GOOGLE LOCAL MODIFICATION -- check is a #define on Mac. - #undef check - // END GOOGLE LOCAL MODIFICATION - - static yes check(const B*); - static no check(const void*); - - enum { - value = sizeof(check(static_cast(NULL))) == sizeof(yes), - }; -}; - -template struct enable_if; -template struct is_integral; -template struct is_floating_point; -template struct is_pointer; -// MSVC can't compile this correctly, and neither can gcc 3.3.5 (at least) -#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) -// is_enum uses is_convertible, which is not available on MSVC. -template struct is_enum; -#endif -template struct is_reference; -template struct is_pod; -template struct has_trivial_constructor; -template struct has_trivial_copy; -template struct has_trivial_assign; -template struct has_trivial_destructor; -template struct remove_const; -template struct remove_volatile; -template struct remove_cv; -template struct remove_reference; -template struct add_reference; -template struct remove_pointer; -template struct is_same; -#if !(defined(__GNUC__) && __GNUC__ <= 3) -template struct is_convertible; -#endif - -// enable_if, equivalent semantics to c++11 std::enable_if, specifically: -// "If B is true, the member typedef type shall equal T; otherwise, there -// shall be no member typedef type." -// Specified by 20.9.7.6 [Other transformations] - -template struct enable_if { typedef T type; }; -template struct enable_if {}; -// is_integral is false except for the built-in integer types. A -// cv-qualified type is integral if and only if the underlying type is. -template struct is_integral : false_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -#if defined(_MSC_VER) -// wchar_t is not by default a distinct type from unsigned short in -// Microsoft C. -// See http://msdn2.microsoft.com/en-us/library/dh8che7s(VS.80).aspx -template<> struct is_integral<__wchar_t> : true_type { }; -#else -template<> struct is_integral : true_type { }; -#endif -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -#ifdef HAVE_LONG_LONG -template<> struct is_integral : true_type { }; -template<> struct is_integral : true_type { }; -#endif -#if defined(_MSC_VER) -// With VC, __int8, __int16, and __int32 are synonymous with standard types -// with the same size, but __int64 has not equivalent (i.e., it's neither -// long, nor long long and should be treated differnetly). -// https://msdn.microsoft.com/en-us/library/29dh1w7z.aspx -template<> struct is_integral<__int64> : true_type { }; -template<> struct is_integral : true_type {}; -#endif -template struct is_integral : is_integral { }; -template struct is_integral : is_integral { }; -template struct is_integral : is_integral { }; - -// is_floating_point is false except for the built-in floating-point types. -// A cv-qualified type is integral if and only if the underlying type is. -template struct is_floating_point : false_type { }; -template<> struct is_floating_point : true_type { }; -template<> struct is_floating_point : true_type { }; -template<> struct is_floating_point : true_type { }; -template struct is_floating_point - : is_floating_point { }; -template struct is_floating_point - : is_floating_point { }; -template struct is_floating_point - : is_floating_point { }; - -// is_pointer is false except for pointer types. A cv-qualified type (e.g. -// "int* const", as opposed to "int const*") is cv-qualified if and only if -// the underlying type is. -template struct is_pointer : false_type { }; -template struct is_pointer : true_type { }; -template struct is_pointer : is_pointer { }; -template struct is_pointer : is_pointer { }; -template struct is_pointer : is_pointer { }; - -#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) - -namespace type_traits_internal { - -template struct is_class_or_union { - template static small_ tester(void (U::*)()); - template static big_ tester(...); - static const bool value = sizeof(tester(0)) == sizeof(small_); -}; - -// is_convertible chokes if the first argument is an array. That's why -// we use add_reference here. -template struct is_enum_impl - : is_convertible::type, int> { }; - -template struct is_enum_impl : false_type { }; - -} // namespace type_traits_internal - -// Specified by TR1 [4.5.1] primary type categories. - -// Implementation note: -// -// Each type is either void, integral, floating point, array, pointer, -// reference, member object pointer, member function pointer, enum, -// union or class. Out of these, only integral, floating point, reference, -// class and enum types are potentially convertible to int. Therefore, -// if a type is not a reference, integral, floating point or class and -// is convertible to int, it's a enum. Adding cv-qualification to a type -// does not change whether it's an enum. -// -// Is-convertible-to-int check is done only if all other checks pass, -// because it can't be used with some types (e.g. void or classes with -// inaccessible conversion operators). -template struct is_enum - : type_traits_internal::is_enum_impl< - is_same::value || - is_integral::value || - is_floating_point::value || - is_reference::value || - type_traits_internal::is_class_or_union::value, - T> { }; - -template struct is_enum : is_enum { }; -template struct is_enum : is_enum { }; -template struct is_enum : is_enum { }; - -#endif - -// is_reference is false except for reference types. -template struct is_reference : false_type {}; -template struct is_reference : true_type {}; - - -// We can't get is_pod right without compiler help, so fail conservatively. -// We will assume it's false except for arithmetic types, enumerations, -// pointers and cv-qualified versions thereof. Note that std::pair -// is not a POD even if T and U are PODs. -template struct is_pod - : integral_constant::value || - is_floating_point::value || -#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3) - // is_enum is not available on MSVC. - is_enum::value || -#endif - is_pointer::value)> { }; -template struct is_pod : is_pod { }; -template struct is_pod : is_pod { }; -template struct is_pod : is_pod { }; - - -// We can't get has_trivial_constructor right without compiler help, so -// fail conservatively. We will assume it's false except for: (1) types -// for which is_pod is true. (2) std::pair of types with trivial -// constructors. (3) array of a type with a trivial constructor. -// (4) const versions thereof. -template struct has_trivial_constructor : is_pod { }; -template struct has_trivial_constructor > - : integral_constant::value && - has_trivial_constructor::value)> { }; -template struct has_trivial_constructor - : has_trivial_constructor { }; -template struct has_trivial_constructor - : has_trivial_constructor { }; - -// We can't get has_trivial_copy right without compiler help, so fail -// conservatively. We will assume it's false except for: (1) types -// for which is_pod is true. (2) std::pair of types with trivial copy -// constructors. (3) array of a type with a trivial copy constructor. -// (4) const versions thereof. -template struct has_trivial_copy : is_pod { }; -template struct has_trivial_copy > - : integral_constant::value && - has_trivial_copy::value)> { }; -template struct has_trivial_copy - : has_trivial_copy { }; -template struct has_trivial_copy : has_trivial_copy { }; - -// We can't get has_trivial_assign right without compiler help, so fail -// conservatively. We will assume it's false except for: (1) types -// for which is_pod is true. (2) std::pair of types with trivial copy -// constructors. (3) array of a type with a trivial assign constructor. -template struct has_trivial_assign : is_pod { }; -template struct has_trivial_assign > - : integral_constant::value && - has_trivial_assign::value)> { }; -template struct has_trivial_assign - : has_trivial_assign { }; - -// We can't get has_trivial_destructor right without compiler help, so -// fail conservatively. We will assume it's false except for: (1) types -// for which is_pod is true. (2) std::pair of types with trivial -// destructors. (3) array of a type with a trivial destructor. -// (4) const versions thereof. -template struct has_trivial_destructor : is_pod { }; -template struct has_trivial_destructor > - : integral_constant::value && - has_trivial_destructor::value)> { }; -template struct has_trivial_destructor - : has_trivial_destructor { }; -template struct has_trivial_destructor - : has_trivial_destructor { }; - -// Specified by TR1 [4.7.1] -template struct remove_const { typedef T type; }; -template struct remove_const { typedef T type; }; -template struct remove_volatile { typedef T type; }; -template struct remove_volatile { typedef T type; }; -template struct remove_cv { - typedef typename remove_const::type>::type type; -}; - - -// Specified by TR1 [4.7.2] Reference modifications. -template struct remove_reference { typedef T type; }; -template struct remove_reference { typedef T type; }; - -template struct add_reference { typedef T& type; }; -template struct add_reference { typedef T& type; }; - -// Specified by TR1 [4.7.4] Pointer modifications. -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { typedef T type; }; -template struct remove_pointer { - typedef T type; }; - -// Specified by TR1 [4.6] Relationships between types -template struct is_same : public false_type { }; -template struct is_same : public true_type { }; - -// Specified by TR1 [4.6] Relationships between types -#if !(defined(__GNUC__) && __GNUC__ <= 3) -namespace type_traits_internal { - -// This class is an implementation detail for is_convertible, and you -// don't need to know how it works to use is_convertible. For those -// who care: we declare two different functions, one whose argument is -// of type To and one with a variadic argument list. We give them -// return types of different size, so we can use sizeof to trick the -// compiler into telling us which function it would have chosen if we -// had called it with an argument of type From. See Alexandrescu's -// _Modern C++ Design_ for more details on this sort of trick. - -template -struct ConvertHelper { - static small_ Test(To); - static big_ Test(...); - static From Create(); - enum { - value = sizeof(Test(Create())) == sizeof(small_) - }; -}; -} // namespace type_traits_internal - -// Inherits from true_type if From is convertible to To, false_type otherwise. -template -struct is_convertible - : integral_constant::value> { -}; -#endif - -} // namespace internal -} // namespace protobuf -} // namespace google - -#endif // GOOGLE_PROTOBUF_TYPE_TRAITS_H_ diff --git a/app/src/main/cpp/google/protobuf/text_format.h b/app/src/main/cpp/google/protobuf/text_format.h deleted file mode 100644 index 2873d33..0000000 --- a/app/src/main/cpp/google/protobuf/text_format.h +++ /dev/null @@ -1,521 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// Author: jschorr@google.com (Joseph Schorr) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// Utilities for printing and parsing protocol messages in a human-readable, -// text-based format. - -#ifndef GOOGLE_PROTOBUF_TEXT_FORMAT_H__ -#define GOOGLE_PROTOBUF_TEXT_FORMAT_H__ - -#include -#include -#ifndef _SHARED_PTR_H -#include -#endif -#include -#include - -#include -#include -#include - -namespace google { -namespace protobuf { - -namespace io { - class ErrorCollector; // tokenizer.h -} - -// This class implements protocol buffer text format. Printing and parsing -// protocol messages in text format is useful for debugging and human editing -// of messages. -// -// This class is really a namespace that contains only static methods. -class LIBPROTOBUF_EXPORT TextFormat { - public: - // Outputs a textual representation of the given message to the given - // output stream. - static bool Print(const Message& message, io::ZeroCopyOutputStream* output); - - // Print the fields in an UnknownFieldSet. They are printed by tag number - // only. Embedded messages are heuristically identified by attempting to - // parse them. - static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, - io::ZeroCopyOutputStream* output); - - // Like Print(), but outputs directly to a string. - // Note: output will be cleared before prior to printing, and will - // be left empty even if printing fails. - static bool PrintToString(const Message& message, string* output); - - // Like PrintUnknownFields(), but outputs directly to a string. - static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, - string* output); - - // Outputs a textual representation of the value of the field supplied on - // the message supplied. For non-repeated fields, an index of -1 must - // be supplied. Note that this method will print the default value for a - // field if it is not set. - static void PrintFieldValueToString(const Message& message, - const FieldDescriptor* field, - int index, - string* output); - - // The default printer that converts scalar values from fields into - // their string representation. - // You can derive from this FieldValuePrinter if you want to have - // fields to be printed in a different way and register it at the - // Printer. - class LIBPROTOBUF_EXPORT FieldValuePrinter { - public: - FieldValuePrinter(); - virtual ~FieldValuePrinter(); - virtual string PrintBool(bool val) const; - virtual string PrintInt32(int32 val) const; - virtual string PrintUInt32(uint32 val) const; - virtual string PrintInt64(int64 val) const; - virtual string PrintUInt64(uint64 val) const; - virtual string PrintFloat(float val) const; - virtual string PrintDouble(double val) const; - virtual string PrintString(const string& val) const; - virtual string PrintBytes(const string& val) const; - virtual string PrintEnum(int32 val, const string& name) const; - virtual string PrintFieldName(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field) const; - virtual string PrintMessageStart(const Message& message, - int field_index, - int field_count, - bool single_line_mode) const; - virtual string PrintMessageEnd(const Message& message, - int field_index, - int field_count, - bool single_line_mode) const; - - private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldValuePrinter); - }; - - // Class for those users which require more fine-grained control over how - // a protobuffer message is printed out. - class LIBPROTOBUF_EXPORT Printer { - public: - Printer(); - ~Printer(); - - // Like TextFormat::Print - bool Print(const Message& message, io::ZeroCopyOutputStream* output) const; - // Like TextFormat::PrintUnknownFields - bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, - io::ZeroCopyOutputStream* output) const; - // Like TextFormat::PrintToString - bool PrintToString(const Message& message, string* output) const; - // Like TextFormat::PrintUnknownFieldsToString - bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, - string* output) const; - // Like TextFormat::PrintFieldValueToString - void PrintFieldValueToString(const Message& message, - const FieldDescriptor* field, - int index, - string* output) const; - - // Adjust the initial indent level of all output. Each indent level is - // equal to two spaces. - void SetInitialIndentLevel(int indent_level) { - initial_indent_level_ = indent_level; - } - - // If printing in single line mode, then the entire message will be output - // on a single line with no line breaks. - void SetSingleLineMode(bool single_line_mode) { - single_line_mode_ = single_line_mode; - } - - bool IsInSingleLineMode() { - return single_line_mode_; - } - - // If use_field_number is true, uses field number instead of field name. - void SetUseFieldNumber(bool use_field_number) { - use_field_number_ = use_field_number; - } - - // Set true to print repeated primitives in a format like: - // field_name: [1, 2, 3, 4] - // instead of printing each value on its own line. Short format applies - // only to primitive values -- i.e. everything except strings and - // sub-messages/groups. - void SetUseShortRepeatedPrimitives(bool use_short_repeated_primitives) { - use_short_repeated_primitives_ = use_short_repeated_primitives; - } - - // Set true to output UTF-8 instead of ASCII. The only difference - // is that bytes >= 0x80 in string fields will not be escaped, - // because they are assumed to be part of UTF-8 multi-byte - // sequences. This will change the default FieldValuePrinter. - void SetUseUtf8StringEscaping(bool as_utf8); - - // Set the default FieldValuePrinter that is used for all fields that - // don't have a field-specific printer registered. - // Takes ownership of the printer. - void SetDefaultFieldValuePrinter(const FieldValuePrinter* printer); - - // Sets whether we want to hide unknown fields or not. - // Usually unknown fields are printed in a generic way that includes the - // tag number of the field instead of field name. However, sometimes it - // is useful to be able to print the message without unknown fields (e.g. - // for the python protobuf version to maintain consistency between its pure - // python and c++ implementations). - void SetHideUnknownFields(bool hide) { - hide_unknown_fields_ = hide; - } - - // If print_message_fields_in_index_order is true, print fields of a proto - // message using the order defined in source code instead of the field - // number. By default, use the field number order. - void SetPrintMessageFieldsInIndexOrder( - bool print_message_fields_in_index_order) { - print_message_fields_in_index_order_ = - print_message_fields_in_index_order; - } - - // If expand==true, expand google.protobuf.Any payloads. The output - // will be of form - // [type_url] { } - // - // If expand==false, print Any using the default printer. The output will - // look like - // type_url: "" value: "serialized_content" - void SetExpandAny(bool expand) { - expand_any_ = expand; - } - - // If non-zero, we truncate all string fields that are longer than this - // threshold. This is useful when the proto message has very long strings, - // e.g., dump of encoded image file. - // - // NOTE(hfgong): Setting a non-zero value breaks round-trip safe - // property of TextFormat::Printer. That is, from the printed message, we - // cannot fully recover the original string field any more. - void SetTruncateStringFieldLongerThan( - const int64 truncate_string_field_longer_than) { - truncate_string_field_longer_than_ = truncate_string_field_longer_than; - } - - // Register a custom field-specific FieldValuePrinter for fields - // with a particular FieldDescriptor. - // Returns "true" if the registration succeeded, or "false", if there is - // already a printer for that FieldDescriptor. - // Takes ownership of the printer on successful registration. - bool RegisterFieldValuePrinter(const FieldDescriptor* field, - const FieldValuePrinter* printer); - - private: - // Forward declaration of an internal class used to print the text - // output to the OutputStream (see text_format.cc for implementation). - class TextGenerator; - - // Internal Print method, used for writing to the OutputStream via - // the TextGenerator class. - void Print(const Message& message, - TextGenerator& generator) const; - - // Print a single field. - void PrintField(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Print a repeated primitive field in short form. - void PrintShortRepeatedField(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Print the name of a field -- i.e. everything that comes before the - // ':' for a single name/value pair. - void PrintFieldName(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const; - - // Outputs a textual representation of the value of the field supplied on - // the message supplied or the default value if not set. - void PrintFieldValue(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - int index, - TextGenerator& generator) const; - - // Print the fields in an UnknownFieldSet. They are printed by tag number - // only. Embedded messages are heuristically identified by attempting to - // parse them. - void PrintUnknownFields(const UnknownFieldSet& unknown_fields, - TextGenerator& generator) const; - - bool PrintAny(const Message& message, TextGenerator& generator) const; - - int initial_indent_level_; - - bool single_line_mode_; - - bool use_field_number_; - - bool use_short_repeated_primitives_; - - bool hide_unknown_fields_; - - bool print_message_fields_in_index_order_; - - bool expand_any_; - - int64 truncate_string_field_longer_than_; - - google::protobuf::scoped_ptr default_field_value_printer_; - typedef std::map CustomPrinterMap; - CustomPrinterMap custom_printers_; - }; - - // Parses a text-format protocol message from the given input stream to - // the given message object. This function parses the human-readable format - // written by Print(). Returns true on success. The message is cleared first, - // even if the function fails -- See Merge() to avoid this behavior. - // - // Example input: "user {\n id: 123 extra { gender: MALE language: 'en' }\n}" - // - // One use for this function is parsing handwritten strings in test code. - // Another use is to parse the output from google::protobuf::Message::DebugString() - // (or ShortDebugString()), because these functions output using - // google::protobuf::TextFormat::Print(). - // - // If you would like to read a protocol buffer serialized in the - // (non-human-readable) binary wire format, see - // google::protobuf::MessageLite::ParseFromString(). - static bool Parse(io::ZeroCopyInputStream* input, Message* output); - // Like Parse(), but reads directly from a string. - static bool ParseFromString(const string& input, Message* output); - - // Like Parse(), but the data is merged into the given message, as if - // using Message::MergeFrom(). - static bool Merge(io::ZeroCopyInputStream* input, Message* output); - // Like Merge(), but reads directly from a string. - static bool MergeFromString(const string& input, Message* output); - - // Parse the given text as a single field value and store it into the - // given field of the given message. If the field is a repeated field, - // the new value will be added to the end - static bool ParseFieldValueFromString(const string& input, - const FieldDescriptor* field, - Message* message); - - // Interface that TextFormat::Parser can use to find extensions. - // This class may be extended in the future to find more information - // like fields, etc. - class LIBPROTOBUF_EXPORT Finder { - public: - virtual ~Finder(); - - // Try to find an extension of *message by fully-qualified field - // name. Returns NULL if no extension is known for this name or number. - virtual const FieldDescriptor* FindExtension( - Message* message, - const string& name) const = 0; - }; - - // A location in the parsed text. - struct ParseLocation { - int line; - int column; - - ParseLocation() : line(-1), column(-1) {} - ParseLocation(int line_param, int column_param) - : line(line_param), column(column_param) {} - }; - - // Data structure which is populated with the locations of each field - // value parsed from the text. - class LIBPROTOBUF_EXPORT ParseInfoTree { - public: - ParseInfoTree(); - ~ParseInfoTree(); - - // Returns the parse location for index-th value of the field in the parsed - // text. If none exists, returns a location with line = -1. Index should be - // -1 for not-repeated fields. - ParseLocation GetLocation(const FieldDescriptor* field, int index) const; - - // Returns the parse info tree for the given field, which must be a message - // type. The nested information tree is owned by the root tree and will be - // deleted when it is deleted. - ParseInfoTree* GetTreeForNested(const FieldDescriptor* field, - int index) const; - - private: - // Allow the text format parser to record information into the tree. - friend class TextFormat; - - // Records the starting location of a single value for a field. - void RecordLocation(const FieldDescriptor* field, ParseLocation location); - - // Create and records a nested tree for a nested message field. - ParseInfoTree* CreateNested(const FieldDescriptor* field); - - // Defines the map from the index-th field descriptor to its parse location. - typedef std::map > LocationMap; - - // Defines the map from the index-th field descriptor to the nested parse - // info tree. - typedef std::map > NestedMap; - - LocationMap locations_; - NestedMap nested_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ParseInfoTree); - }; - - // For more control over parsing, use this class. - class LIBPROTOBUF_EXPORT Parser { - public: - Parser(); - ~Parser(); - - // Like TextFormat::Parse(). - bool Parse(io::ZeroCopyInputStream* input, Message* output); - // Like TextFormat::ParseFromString(). - bool ParseFromString(const string& input, Message* output); - // Like TextFormat::Merge(). - bool Merge(io::ZeroCopyInputStream* input, Message* output); - // Like TextFormat::MergeFromString(). - bool MergeFromString(const string& input, Message* output); - - // Set where to report parse errors. If NULL (the default), errors will - // be printed to stderr. - void RecordErrorsTo(io::ErrorCollector* error_collector) { - error_collector_ = error_collector; - } - - // Set how parser finds extensions. If NULL (the default), the - // parser will use the standard Reflection object associated with - // the message being parsed. - void SetFinder(Finder* finder) { - finder_ = finder; - } - - // Sets where location information about the parse will be written. If NULL - // (the default), then no location will be written. - void WriteLocationsTo(ParseInfoTree* tree) { - parse_info_tree_ = tree; - } - - // Normally parsing fails if, after parsing, output->IsInitialized() - // returns false. Call AllowPartialMessage(true) to skip this check. - void AllowPartialMessage(bool allow) { - allow_partial_ = allow; - } - - // Allow field names to be matched case-insensitively. - // This is not advisable if there are fields that only differ in case, or - // if you want to enforce writing in the canonical form. - // This is 'false' by default. - void AllowCaseInsensitiveField(bool allow) { - allow_case_insensitive_field_ = allow; - } - - // Like TextFormat::ParseFieldValueFromString - bool ParseFieldValueFromString(const string& input, - const FieldDescriptor* field, - Message* output); - - - void AllowFieldNumber(bool allow) { - allow_field_number_ = allow; - } - - private: - // Forward declaration of an internal class used to parse text - // representations (see text_format.cc for implementation). - class ParserImpl; - - // Like TextFormat::Merge(). The provided implementation is used - // to do the parsing. - bool MergeUsingImpl(io::ZeroCopyInputStream* input, - Message* output, - ParserImpl* parser_impl); - - io::ErrorCollector* error_collector_; - Finder* finder_; - ParseInfoTree* parse_info_tree_; - bool allow_partial_; - bool allow_case_insensitive_field_; - bool allow_unknown_field_; - bool allow_unknown_enum_; - bool allow_field_number_; - bool allow_relaxed_whitespace_; - bool allow_singular_overwrites_; - }; - - - private: - // Hack: ParseInfoTree declares TextFormat as a friend which should extend - // the friendship to TextFormat::Parser::ParserImpl, but unfortunately some - // old compilers (e.g. GCC 3.4.6) don't implement this correctly. We provide - // helpers for ParserImpl to call methods of ParseInfoTree. - static inline void RecordLocation(ParseInfoTree* info_tree, - const FieldDescriptor* field, - ParseLocation location); - static inline ParseInfoTree* CreateNested(ParseInfoTree* info_tree, - const FieldDescriptor* field); - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TextFormat); -}; - -inline void TextFormat::RecordLocation(ParseInfoTree* info_tree, - const FieldDescriptor* field, - ParseLocation location) { - info_tree->RecordLocation(field, location); -} - - -inline TextFormat::ParseInfoTree* TextFormat::CreateNested( - ParseInfoTree* info_tree, const FieldDescriptor* field) { - return info_tree->CreateNested(field); -} - -} // namespace protobuf - -} // namespace google -#endif // GOOGLE_PROTOBUF_TEXT_FORMAT_H__ diff --git a/app/src/main/cpp/google/protobuf/timestamp.pb.h b/app/src/main/cpp/google/protobuf/timestamp.pb.h deleted file mode 100644 index 1abe8d0..0000000 --- a/app/src/main/cpp/google/protobuf/timestamp.pb.h +++ /dev/null @@ -1,197 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/timestamp.proto - -#ifndef PROTOBUF_google_2fprotobuf_2ftimestamp_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2ftimestamp_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto(); - -class Timestamp; - -// =================================================================== - -class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Timestamp) */ { - public: - Timestamp(); - virtual ~Timestamp(); - - Timestamp(const Timestamp& from); - - inline Timestamp& operator=(const Timestamp& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Timestamp& default_instance(); - - static const Timestamp* internal_default_instance(); - - void UnsafeArenaSwap(Timestamp* other); - void Swap(Timestamp* other); - - // implements Message ---------------------------------------------- - - inline Timestamp* New() const { return New(NULL); } - - Timestamp* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Timestamp& from); - void MergeFrom(const Timestamp& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Timestamp* other); - void UnsafeMergeFrom(const Timestamp& from); - protected: - explicit Timestamp(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional int64 seconds = 1; - void clear_seconds(); - static const int kSecondsFieldNumber = 1; - ::google::protobuf::int64 seconds() const; - void set_seconds(::google::protobuf::int64 value); - - // optional int32 nanos = 2; - void clear_nanos(); - static const int kNanosFieldNumber = 2; - ::google::protobuf::int32 nanos() const; - void set_nanos(::google::protobuf::int32 value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Timestamp) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::int64 seconds_; - ::google::protobuf::int32 nanos_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftimestamp_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftimestamp_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftimestamp_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftimestamp_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Timestamp_default_instance_; - -// =================================================================== - - -// =================================================================== - -#if !PROTOBUF_INLINE_NOT_IN_HEADERS -// Timestamp - -// optional int64 seconds = 1; -inline void Timestamp::clear_seconds() { - seconds_ = GOOGLE_LONGLONG(0); -} -inline ::google::protobuf::int64 Timestamp::seconds() const { - // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.seconds) - return seconds_; -} -inline void Timestamp::set_seconds(::google::protobuf::int64 value) { - - seconds_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.seconds) -} - -// optional int32 nanos = 2; -inline void Timestamp::clear_nanos() { - nanos_ = 0; -} -inline ::google::protobuf::int32 Timestamp::nanos() const { - // @@protoc_insertion_point(field_get:google.protobuf.Timestamp.nanos) - return nanos_; -} -inline void Timestamp::set_nanos(::google::protobuf::int32 value) { - - nanos_ = value; - // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.nanos) -} - -inline const Timestamp* Timestamp::internal_default_instance() { - return &Timestamp_default_instance_.get(); -} -#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS - -// @@protoc_insertion_point(namespace_scope) - -} // namespace protobuf -} // namespace google - -// @@protoc_insertion_point(global_scope) - -#endif // PROTOBUF_google_2fprotobuf_2ftimestamp_2eproto__INCLUDED diff --git a/app/src/main/cpp/google/protobuf/timestamp.proto b/app/src/main/cpp/google/protobuf/timestamp.proto deleted file mode 100644 index 67e2eba..0000000 --- a/app/src/main/cpp/google/protobuf/timestamp.proto +++ /dev/null @@ -1,108 +0,0 @@ -// Protocol Buffers - Google's data interchange format -// Copyright 2008 Google Inc. All rights reserved. -// https://developers.google.com/protocol-buffers/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -syntax = "proto3"; - -package google.protobuf; - -option csharp_namespace = "Google.Protobuf.WellKnownTypes"; -option cc_enable_arenas = true; -option go_package = "github.com/golang/protobuf/ptypes/timestamp"; -option java_package = "com.google.protobuf"; -option java_outer_classname = "TimestampProto"; -option java_multiple_files = true; -option objc_class_prefix = "GPB"; - -// A Timestamp represents a point in time independent of any time zone -// or calendar, represented as seconds and fractions of seconds at -// nanosecond resolution in UTC Epoch time. It is encoded using the -// Proleptic Gregorian Calendar which extends the Gregorian calendar -// backwards to year one. It is encoded assuming all minutes are 60 -// seconds long, i.e. leap seconds are "smeared" so that no leap second -// table is needed for interpretation. Range is from -// 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z. -// By restricting to that range, we ensure that we can convert to -// and from RFC 3339 date strings. -// See [https://www.ietf.org/rfc/rfc3339.txt](https://www.ietf.org/rfc/rfc3339.txt). -// -// Example 1: Compute Timestamp from POSIX `time()`. -// -// Timestamp timestamp; -// timestamp.set_seconds(time(NULL)); -// timestamp.set_nanos(0); -// -// Example 2: Compute Timestamp from POSIX `gettimeofday()`. -// -// struct timeval tv; -// gettimeofday(&tv, NULL); -// -// Timestamp timestamp; -// timestamp.set_seconds(tv.tv_sec); -// timestamp.set_nanos(tv.tv_usec * 1000); -// -// Example 3: Compute Timestamp from Win32 `GetSystemTimeAsFileTime()`. -// -// FILETIME ft; -// GetSystemTimeAsFileTime(&ft); -// UINT64 ticks = (((UINT64)ft.dwHighDateTime) << 32) | ft.dwLowDateTime; -// -// // A Windows tick is 100 nanoseconds. Windows epoch 1601-01-01T00:00:00Z -// // is 11644473600 seconds before Unix epoch 1970-01-01T00:00:00Z. -// Timestamp timestamp; -// timestamp.set_seconds((INT64) ((ticks / 10000000) - 11644473600LL)); -// timestamp.set_nanos((INT32) ((ticks % 10000000) * 100)); -// -// Example 4: Compute Timestamp from Java `System.currentTimeMillis()`. -// -// long millis = System.currentTimeMillis(); -// -// Timestamp timestamp = Timestamp.newBuilder().setSeconds(millis / 1000) -// .setNanos((int) ((millis % 1000) * 1000000)).build(); -// -// -// Example 5: Compute Timestamp from current time in Python. -// -// timestamp = Timestamp() -// timestamp.GetCurrentTime() -// -// -message Timestamp { - - // Represents seconds of UTC time since Unix epoch - // 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to - // 9999-12-31T23:59:59Z inclusive. - int64 seconds = 1; - - // Non-negative fractions of a second at nanosecond resolution. Negative - // second values with fractions must still have non-negative nanos values - // that count forward in time. Must be from 0 to 999,999,999 - // inclusive. - int32 nanos = 2; -} diff --git a/app/src/main/cpp/google/protobuf/type.pb.h b/app/src/main/cpp/google/protobuf/type.pb.h deleted file mode 100644 index 1b6d341..0000000 --- a/app/src/main/cpp/google/protobuf/type.pb.h +++ /dev/null @@ -1,2112 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: google/protobuf/type.proto - -#ifndef PROTOBUF_google_2fprotobuf_2ftype_2eproto__INCLUDED -#define PROTOBUF_google_2fprotobuf_2ftype_2eproto__INCLUDED - -#include - -#include - -#if GOOGLE_PROTOBUF_VERSION < 3001000 -#error This file was generated by a newer version of protoc which is -#error incompatible with your Protocol Buffer headers. Please update -#error your headers. -#endif -#if 3001000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION -#error This file was generated by an older version of protoc which is -#error incompatible with your Protocol Buffer headers. Please -#error regenerate this file with a newer version of protoc. -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) - -namespace google { -namespace protobuf { - -// Internal implementation detail -- do not call these. -void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto(); -void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto(); -void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); -void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - -class Enum; -class EnumValue; -class Field; -class Option; -class Type; - -enum Field_Kind { - Field_Kind_TYPE_UNKNOWN = 0, - Field_Kind_TYPE_DOUBLE = 1, - Field_Kind_TYPE_FLOAT = 2, - Field_Kind_TYPE_INT64 = 3, - Field_Kind_TYPE_UINT64 = 4, - Field_Kind_TYPE_INT32 = 5, - Field_Kind_TYPE_FIXED64 = 6, - Field_Kind_TYPE_FIXED32 = 7, - Field_Kind_TYPE_BOOL = 8, - Field_Kind_TYPE_STRING = 9, - Field_Kind_TYPE_GROUP = 10, - Field_Kind_TYPE_MESSAGE = 11, - Field_Kind_TYPE_BYTES = 12, - Field_Kind_TYPE_UINT32 = 13, - Field_Kind_TYPE_ENUM = 14, - Field_Kind_TYPE_SFIXED32 = 15, - Field_Kind_TYPE_SFIXED64 = 16, - Field_Kind_TYPE_SINT32 = 17, - Field_Kind_TYPE_SINT64 = 18, - Field_Kind_Field_Kind_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, - Field_Kind_Field_Kind_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max -}; -LIBPROTOBUF_EXPORT bool Field_Kind_IsValid(int value); -const Field_Kind Field_Kind_Kind_MIN = Field_Kind_TYPE_UNKNOWN; -const Field_Kind Field_Kind_Kind_MAX = Field_Kind_TYPE_SINT64; -const int Field_Kind_Kind_ARRAYSIZE = Field_Kind_Kind_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* Field_Kind_descriptor(); -inline const ::std::string& Field_Kind_Name(Field_Kind value) { - return ::google::protobuf::internal::NameOfEnum( - Field_Kind_descriptor(), value); -} -inline bool Field_Kind_Parse( - const ::std::string& name, Field_Kind* value) { - return ::google::protobuf::internal::ParseNamedEnum( - Field_Kind_descriptor(), name, value); -} -enum Field_Cardinality { - Field_Cardinality_CARDINALITY_UNKNOWN = 0, - Field_Cardinality_CARDINALITY_OPTIONAL = 1, - Field_Cardinality_CARDINALITY_REQUIRED = 2, - Field_Cardinality_CARDINALITY_REPEATED = 3, - Field_Cardinality_Field_Cardinality_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, - Field_Cardinality_Field_Cardinality_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max -}; -LIBPROTOBUF_EXPORT bool Field_Cardinality_IsValid(int value); -const Field_Cardinality Field_Cardinality_Cardinality_MIN = Field_Cardinality_CARDINALITY_UNKNOWN; -const Field_Cardinality Field_Cardinality_Cardinality_MAX = Field_Cardinality_CARDINALITY_REPEATED; -const int Field_Cardinality_Cardinality_ARRAYSIZE = Field_Cardinality_Cardinality_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* Field_Cardinality_descriptor(); -inline const ::std::string& Field_Cardinality_Name(Field_Cardinality value) { - return ::google::protobuf::internal::NameOfEnum( - Field_Cardinality_descriptor(), value); -} -inline bool Field_Cardinality_Parse( - const ::std::string& name, Field_Cardinality* value) { - return ::google::protobuf::internal::ParseNamedEnum( - Field_Cardinality_descriptor(), name, value); -} -enum Syntax { - SYNTAX_PROTO2 = 0, - SYNTAX_PROTO3 = 1, - Syntax_INT_MIN_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32min, - Syntax_INT_MAX_SENTINEL_DO_NOT_USE_ = ::google::protobuf::kint32max -}; -LIBPROTOBUF_EXPORT bool Syntax_IsValid(int value); -const Syntax Syntax_MIN = SYNTAX_PROTO2; -const Syntax Syntax_MAX = SYNTAX_PROTO3; -const int Syntax_ARRAYSIZE = Syntax_MAX + 1; - -LIBPROTOBUF_EXPORT const ::google::protobuf::EnumDescriptor* Syntax_descriptor(); -inline const ::std::string& Syntax_Name(Syntax value) { - return ::google::protobuf::internal::NameOfEnum( - Syntax_descriptor(), value); -} -inline bool Syntax_Parse( - const ::std::string& name, Syntax* value) { - return ::google::protobuf::internal::ParseNamedEnum( - Syntax_descriptor(), name, value); -} -// =================================================================== - -class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Type) */ { - public: - Type(); - virtual ~Type(); - - Type(const Type& from); - - inline Type& operator=(const Type& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Type& default_instance(); - - static const Type* internal_default_instance(); - - void UnsafeArenaSwap(Type* other); - void Swap(Type* other); - - // implements Message ---------------------------------------------- - - inline Type* New() const { return New(NULL); } - - Type* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Type& from); - void MergeFrom(const Type& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Type* other); - void UnsafeMergeFrom(const Type& from); - protected: - explicit Type(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - ::std::string* unsafe_arena_release_name(); - void unsafe_arena_set_allocated_name( - ::std::string* name); - - // repeated .google.protobuf.Field fields = 2; - int fields_size() const; - void clear_fields(); - static const int kFieldsFieldNumber = 2; - const ::google::protobuf::Field& fields(int index) const; - ::google::protobuf::Field* mutable_fields(int index); - ::google::protobuf::Field* add_fields(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Field >* - mutable_fields(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Field >& - fields() const; - - // repeated string oneofs = 3; - int oneofs_size() const; - void clear_oneofs(); - static const int kOneofsFieldNumber = 3; - const ::std::string& oneofs(int index) const; - ::std::string* mutable_oneofs(int index); - void set_oneofs(int index, const ::std::string& value); - void set_oneofs(int index, const char* value); - void set_oneofs(int index, const char* value, size_t size); - ::std::string* add_oneofs(); - void add_oneofs(const ::std::string& value); - void add_oneofs(const char* value); - void add_oneofs(const char* value, size_t size); - const ::google::protobuf::RepeatedPtrField< ::std::string>& oneofs() const; - ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_oneofs(); - - // repeated .google.protobuf.Option options = 4; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 4; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // optional .google.protobuf.SourceContext source_context = 5; - bool has_source_context() const; - void clear_source_context(); - static const int kSourceContextFieldNumber = 5; - private: - void _slow_mutable_source_context(); - ::google::protobuf::SourceContext* _slow_release_source_context(); - public: - const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); - ::google::protobuf::SourceContext* release_source_context(); - void set_allocated_source_context(::google::protobuf::SourceContext* source_context); - ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); - void unsafe_arena_set_allocated_source_context( - ::google::protobuf::SourceContext* source_context); - - // optional .google.protobuf.Syntax syntax = 6; - void clear_syntax(); - static const int kSyntaxFieldNumber = 6; - ::google::protobuf::Syntax syntax() const; - void set_syntax(::google::protobuf::Syntax value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Type) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Field > fields_; - ::google::protobuf::RepeatedPtrField< ::std::string> oneofs_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::SourceContext* source_context_; - int syntax_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Type_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Field) */ { - public: - Field(); - virtual ~Field(); - - Field(const Field& from); - - inline Field& operator=(const Field& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Field& default_instance(); - - static const Field* internal_default_instance(); - - void UnsafeArenaSwap(Field* other); - void Swap(Field* other); - - // implements Message ---------------------------------------------- - - inline Field* New() const { return New(NULL); } - - Field* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Field& from); - void MergeFrom(const Field& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Field* other); - void UnsafeMergeFrom(const Field& from); - protected: - explicit Field(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - typedef Field_Kind Kind; - static const Kind TYPE_UNKNOWN = - Field_Kind_TYPE_UNKNOWN; - static const Kind TYPE_DOUBLE = - Field_Kind_TYPE_DOUBLE; - static const Kind TYPE_FLOAT = - Field_Kind_TYPE_FLOAT; - static const Kind TYPE_INT64 = - Field_Kind_TYPE_INT64; - static const Kind TYPE_UINT64 = - Field_Kind_TYPE_UINT64; - static const Kind TYPE_INT32 = - Field_Kind_TYPE_INT32; - static const Kind TYPE_FIXED64 = - Field_Kind_TYPE_FIXED64; - static const Kind TYPE_FIXED32 = - Field_Kind_TYPE_FIXED32; - static const Kind TYPE_BOOL = - Field_Kind_TYPE_BOOL; - static const Kind TYPE_STRING = - Field_Kind_TYPE_STRING; - static const Kind TYPE_GROUP = - Field_Kind_TYPE_GROUP; - static const Kind TYPE_MESSAGE = - Field_Kind_TYPE_MESSAGE; - static const Kind TYPE_BYTES = - Field_Kind_TYPE_BYTES; - static const Kind TYPE_UINT32 = - Field_Kind_TYPE_UINT32; - static const Kind TYPE_ENUM = - Field_Kind_TYPE_ENUM; - static const Kind TYPE_SFIXED32 = - Field_Kind_TYPE_SFIXED32; - static const Kind TYPE_SFIXED64 = - Field_Kind_TYPE_SFIXED64; - static const Kind TYPE_SINT32 = - Field_Kind_TYPE_SINT32; - static const Kind TYPE_SINT64 = - Field_Kind_TYPE_SINT64; - static inline bool Kind_IsValid(int value) { - return Field_Kind_IsValid(value); - } - static const Kind Kind_MIN = - Field_Kind_Kind_MIN; - static const Kind Kind_MAX = - Field_Kind_Kind_MAX; - static const int Kind_ARRAYSIZE = - Field_Kind_Kind_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Kind_descriptor() { - return Field_Kind_descriptor(); - } - static inline const ::std::string& Kind_Name(Kind value) { - return Field_Kind_Name(value); - } - static inline bool Kind_Parse(const ::std::string& name, - Kind* value) { - return Field_Kind_Parse(name, value); - } - - typedef Field_Cardinality Cardinality; - static const Cardinality CARDINALITY_UNKNOWN = - Field_Cardinality_CARDINALITY_UNKNOWN; - static const Cardinality CARDINALITY_OPTIONAL = - Field_Cardinality_CARDINALITY_OPTIONAL; - static const Cardinality CARDINALITY_REQUIRED = - Field_Cardinality_CARDINALITY_REQUIRED; - static const Cardinality CARDINALITY_REPEATED = - Field_Cardinality_CARDINALITY_REPEATED; - static inline bool Cardinality_IsValid(int value) { - return Field_Cardinality_IsValid(value); - } - static const Cardinality Cardinality_MIN = - Field_Cardinality_Cardinality_MIN; - static const Cardinality Cardinality_MAX = - Field_Cardinality_Cardinality_MAX; - static const int Cardinality_ARRAYSIZE = - Field_Cardinality_Cardinality_ARRAYSIZE; - static inline const ::google::protobuf::EnumDescriptor* - Cardinality_descriptor() { - return Field_Cardinality_descriptor(); - } - static inline const ::std::string& Cardinality_Name(Cardinality value) { - return Field_Cardinality_Name(value); - } - static inline bool Cardinality_Parse(const ::std::string& name, - Cardinality* value) { - return Field_Cardinality_Parse(name, value); - } - - // accessors ------------------------------------------------------- - - // optional .google.protobuf.Field.Kind kind = 1; - void clear_kind(); - static const int kKindFieldNumber = 1; - ::google::protobuf::Field_Kind kind() const; - void set_kind(::google::protobuf::Field_Kind value); - - // optional .google.protobuf.Field.Cardinality cardinality = 2; - void clear_cardinality(); - static const int kCardinalityFieldNumber = 2; - ::google::protobuf::Field_Cardinality cardinality() const; - void set_cardinality(::google::protobuf::Field_Cardinality value); - - // optional int32 number = 3; - void clear_number(); - static const int kNumberFieldNumber = 3; - ::google::protobuf::int32 number() const; - void set_number(::google::protobuf::int32 value); - - // optional string name = 4; - void clear_name(); - static const int kNameFieldNumber = 4; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - ::std::string* unsafe_arena_release_name(); - void unsafe_arena_set_allocated_name( - ::std::string* name); - - // optional string type_url = 6; - void clear_type_url(); - static const int kTypeUrlFieldNumber = 6; - const ::std::string& type_url() const; - void set_type_url(const ::std::string& value); - void set_type_url(const char* value); - void set_type_url(const char* value, size_t size); - ::std::string* mutable_type_url(); - ::std::string* release_type_url(); - void set_allocated_type_url(::std::string* type_url); - ::std::string* unsafe_arena_release_type_url(); - void unsafe_arena_set_allocated_type_url( - ::std::string* type_url); - - // optional int32 oneof_index = 7; - void clear_oneof_index(); - static const int kOneofIndexFieldNumber = 7; - ::google::protobuf::int32 oneof_index() const; - void set_oneof_index(::google::protobuf::int32 value); - - // optional bool packed = 8; - void clear_packed(); - static const int kPackedFieldNumber = 8; - bool packed() const; - void set_packed(bool value); - - // repeated .google.protobuf.Option options = 9; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 9; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // optional string json_name = 10; - void clear_json_name(); - static const int kJsonNameFieldNumber = 10; - const ::std::string& json_name() const; - void set_json_name(const ::std::string& value); - void set_json_name(const char* value); - void set_json_name(const char* value, size_t size); - ::std::string* mutable_json_name(); - ::std::string* release_json_name(); - void set_allocated_json_name(::std::string* json_name); - ::std::string* unsafe_arena_release_json_name(); - void unsafe_arena_set_allocated_json_name( - ::std::string* json_name); - - // optional string default_value = 11; - void clear_default_value(); - static const int kDefaultValueFieldNumber = 11; - const ::std::string& default_value() const; - void set_default_value(const ::std::string& value); - void set_default_value(const char* value); - void set_default_value(const char* value, size_t size); - ::std::string* mutable_default_value(); - ::std::string* release_default_value(); - void set_allocated_default_value(::std::string* default_value); - ::std::string* unsafe_arena_release_default_value(); - void unsafe_arena_set_allocated_default_value( - ::std::string* default_value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Field) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::internal::ArenaStringPtr type_url_; - ::google::protobuf::internal::ArenaStringPtr json_name_; - ::google::protobuf::internal::ArenaStringPtr default_value_; - int kind_; - int cardinality_; - ::google::protobuf::int32 number_; - ::google::protobuf::int32 oneof_index_; - bool packed_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Field_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Enum) */ { - public: - Enum(); - virtual ~Enum(); - - Enum(const Enum& from); - - inline Enum& operator=(const Enum& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Enum& default_instance(); - - static const Enum* internal_default_instance(); - - void UnsafeArenaSwap(Enum* other); - void Swap(Enum* other); - - // implements Message ---------------------------------------------- - - inline Enum* New() const { return New(NULL); } - - Enum* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Enum& from); - void MergeFrom(const Enum& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Enum* other); - void UnsafeMergeFrom(const Enum& from); - protected: - explicit Enum(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - ::std::string* unsafe_arena_release_name(); - void unsafe_arena_set_allocated_name( - ::std::string* name); - - // repeated .google.protobuf.EnumValue enumvalue = 2; - int enumvalue_size() const; - void clear_enumvalue(); - static const int kEnumvalueFieldNumber = 2; - const ::google::protobuf::EnumValue& enumvalue(int index) const; - ::google::protobuf::EnumValue* mutable_enumvalue(int index); - ::google::protobuf::EnumValue* add_enumvalue(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValue >* - mutable_enumvalue(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValue >& - enumvalue() const; - - // repeated .google.protobuf.Option options = 3; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // optional .google.protobuf.SourceContext source_context = 4; - bool has_source_context() const; - void clear_source_context(); - static const int kSourceContextFieldNumber = 4; - private: - void _slow_mutable_source_context(); - ::google::protobuf::SourceContext* _slow_release_source_context(); - public: - const ::google::protobuf::SourceContext& source_context() const; - ::google::protobuf::SourceContext* mutable_source_context(); - ::google::protobuf::SourceContext* release_source_context(); - void set_allocated_source_context(::google::protobuf::SourceContext* source_context); - ::google::protobuf::SourceContext* unsafe_arena_release_source_context(); - void unsafe_arena_set_allocated_source_context( - ::google::protobuf::SourceContext* source_context); - - // optional .google.protobuf.Syntax syntax = 5; - void clear_syntax(); - static const int kSyntaxFieldNumber = 5; - ::google::protobuf::Syntax syntax() const; - void set_syntax(::google::protobuf::Syntax value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Enum) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValue > enumvalue_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::SourceContext* source_context_; - int syntax_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed Enum_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.EnumValue) */ { - public: - EnumValue(); - virtual ~EnumValue(); - - EnumValue(const EnumValue& from); - - inline EnumValue& operator=(const EnumValue& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const EnumValue& default_instance(); - - static const EnumValue* internal_default_instance(); - - void UnsafeArenaSwap(EnumValue* other); - void Swap(EnumValue* other); - - // implements Message ---------------------------------------------- - - inline EnumValue* New() const { return New(NULL); } - - EnumValue* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const EnumValue& from); - void MergeFrom(const EnumValue& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(EnumValue* other); - void UnsafeMergeFrom(const EnumValue& from); - protected: - explicit EnumValue(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - ::std::string* unsafe_arena_release_name(); - void unsafe_arena_set_allocated_name( - ::std::string* name); - - // optional int32 number = 2; - void clear_number(); - static const int kNumberFieldNumber = 2; - ::google::protobuf::int32 number() const; - void set_number(::google::protobuf::int32 value); - - // repeated .google.protobuf.Option options = 3; - int options_size() const; - void clear_options(); - static const int kOptionsFieldNumber = 3; - const ::google::protobuf::Option& options(int index) const; - ::google::protobuf::Option* mutable_options(int index); - ::google::protobuf::Option* add_options(); - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >* - mutable_options(); - const ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option >& - options() const; - - // @@protoc_insertion_point(class_scope:google.protobuf.EnumValue) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::int32 number_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed EnumValue_default_instance_; - -// ------------------------------------------------------------------- - -class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.Option) */ { - public: - Option(); - virtual ~Option(); - - Option(const Option& from); - - inline Option& operator=(const Option& from) { - CopyFrom(from); - return *this; - } - - inline ::google::protobuf::Arena* GetArena() const { return GetArenaNoVirtual(); } - inline void* GetMaybeArenaPointer() const { - return MaybeArenaPtr(); - } - static const ::google::protobuf::Descriptor* descriptor(); - static const Option& default_instance(); - - static const Option* internal_default_instance(); - - void UnsafeArenaSwap(Option* other); - void Swap(Option* other); - - // implements Message ---------------------------------------------- - - inline Option* New() const { return New(NULL); } - - Option* New(::google::protobuf::Arena* arena) const; - void CopyFrom(const ::google::protobuf::Message& from); - void MergeFrom(const ::google::protobuf::Message& from); - void CopyFrom(const Option& from); - void MergeFrom(const Option& from); - void Clear(); - bool IsInitialized() const; - - size_t ByteSizeLong() const; - bool MergePartialFromCodedStream( - ::google::protobuf::io::CodedInputStream* input); - void SerializeWithCachedSizes( - ::google::protobuf::io::CodedOutputStream* output) const; - ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( - bool deterministic, ::google::protobuf::uint8* output) const; - ::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const { - return InternalSerializeWithCachedSizesToArray(false, output); - } - int GetCachedSize() const { return _cached_size_; } - private: - void SharedCtor(); - void SharedDtor(); - void SetCachedSize(int size) const; - void InternalSwap(Option* other); - void UnsafeMergeFrom(const Option& from); - protected: - explicit Option(::google::protobuf::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::google::protobuf::Arena* arena); - private: - inline ::google::protobuf::Arena* GetArenaNoVirtual() const { - return _internal_metadata_.arena(); - } - inline void* MaybeArenaPtr() const { - return _internal_metadata_.raw_arena_ptr(); - } - public: - - ::google::protobuf::Metadata GetMetadata() const; - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - // optional string name = 1; - void clear_name(); - static const int kNameFieldNumber = 1; - const ::std::string& name() const; - void set_name(const ::std::string& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - ::std::string* mutable_name(); - ::std::string* release_name(); - void set_allocated_name(::std::string* name); - ::std::string* unsafe_arena_release_name(); - void unsafe_arena_set_allocated_name( - ::std::string* name); - - // optional .google.protobuf.Any value = 2; - bool has_value() const; - void clear_value(); - static const int kValueFieldNumber = 2; - private: - void _slow_mutable_value(); - ::google::protobuf::Any* _slow_release_value(); - public: - const ::google::protobuf::Any& value() const; - ::google::protobuf::Any* mutable_value(); - ::google::protobuf::Any* release_value(); - void set_allocated_value(::google::protobuf::Any* value); - ::google::protobuf::Any* unsafe_arena_release_value(); - void unsafe_arena_set_allocated_value( - ::google::protobuf::Any* value); - - // @@protoc_insertion_point(class_scope:google.protobuf.Option) - private: - - ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::google::protobuf::internal::ArenaStringPtr name_; - ::google::protobuf::Any* value_; - mutable int _cached_size_; - friend void LIBPROTOBUF_EXPORT protobuf_InitDefaults_google_2fprotobuf_2ftype_2eproto_impl(); - friend void LIBPROTOBUF_EXPORT protobuf_AddDesc_google_2fprotobuf_2ftype_2eproto_impl(); - friend void protobuf_AssignDesc_google_2fprotobuf_2ftype_2eproto(); - friend void protobuf_ShutdownFile_google_2fprotobuf_2ftype_2eproto(); - - void InitAsDefaultInstance(); -}; -extern ::google::protobuf::internal::ExplicitlyConstructed