Skip to content

Commit

Permalink
Reduce TensorShape vector to a common template
Browse files Browse the repository at this point in the history
  • Loading branch information
yuslepukhin committed Nov 20, 2023
1 parent 2a8189f commit 276366e
Showing 1 changed file with 11 additions and 38 deletions.
49 changes: 11 additions & 38 deletions include/onnxruntime/core/framework/tensor_shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,17 @@
// Licensed under the MIT License.

#pragma once
#include <iosfwd>
#include <vector>

#include <algorithm>
#include <string>
#include <cstring>
#include "core/common/gsl.h"
#include "onnxruntime_config.h"

#ifndef DISABLE_ABSEIL
// Need to include abseil inlined_vector.h header directly here
// as hash tables cause CUDA 10.2 compilers to fail. inlined_vector.h is fine.
#ifdef _MSC_VER
#pragma warning(push)
// C4127: conditional expression is constant
#pragma warning(disable : 4127)
// C4324: structure was padded due to alignment specifier
// Usage of alignas causes some internal padding in places.
#pragma warning(disable : 4324)
#endif

#include <absl/container/inlined_vector.h>

#ifdef _MSC_VER
#pragma warning(pop)
#endif
#endif // DISABLE_ABSEIL
#include <iosfwd>
#include <string>
#include <vector>

#include "core/common/gsl.h"
#include "core/common/inlined_containers_fwd.h"
#include "core/common/span_utils.h"
#include "onnxruntime_config.h"

Check warning on line 15 in include/onnxruntime/core/framework/tensor_shape.h

View workflow job for this annotation

GitHub Actions / cpplint

[cpplint] include/onnxruntime/core/framework/tensor_shape.h#L15

Include the directory when naming header files [build/include_subdir] [4]
Raw output
include/onnxruntime/core/framework/tensor_shape.h:15:  Include the directory when naming header files  [build/include_subdir] [4]

namespace onnxruntime {
#ifdef __GNUC__
Expand All @@ -41,18 +24,10 @@ namespace onnxruntime {

constexpr size_t kTensorShapeSmallBufferElementsSize = 5;

#ifndef DISABLE_ABSEIL
// Use this type to build a shape and then create TensorShape.
using TensorShapeVector = absl::InlinedVector<int64_t, kTensorShapeSmallBufferElementsSize>;
#else
class TensorShapeVector : public std::vector<int64_t> {
using Base = std::vector<int64_t>;

public:
using Base::Base;
};

#endif // DISABLE_ABSEIL
// We opt to re-use a common instantiation instead of a typedef with kTensorShapeSmallBufferElementsSize
// To reduce on binary size.
using TensorShapeVector = InlinedVector<int64_t>;

inline TensorShapeVector ToShapeVector(const gsl::span<const int64_t>& span) {
TensorShapeVector out;
Expand Down Expand Up @@ -194,9 +169,7 @@ class TensorShape {

friend struct ProviderHostImpl; // So that the shared provider interface can access Allocate
};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

// operator<< to nicely output to a stream
std::ostream& operator<<(std::ostream& out, const TensorShape& shape);

Expand Down

0 comments on commit 276366e

Please sign in to comment.