mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Use std::string_view (#145906)
Fixes #ISSUE_NUMBER Pull Request resolved: https://github.com/pytorch/pytorch/pull/145906 Approved by: https://github.com/albanD
This commit is contained in:
@ -6,7 +6,6 @@
|
||||
#include <c10/util/Half.h>
|
||||
#include <c10/util/Metaprogramming.h>
|
||||
#include <c10/util/complex.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#include <cuda.h> // For CUDA_VERSION
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/core/Allocator.h>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace at {
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
namespace at {
|
||||
|
||||
|
@ -54,6 +54,7 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <typeindex>
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/util/StringUtil.h>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <c10/util/irange.h>
|
||||
#include <ATen/core/jit_type.h>
|
||||
#include <ATen/core/symbol.h>
|
||||
@ -9,6 +8,7 @@
|
||||
#include <ATen/core/alias_info.h>
|
||||
#include <ATen/core/operator_name.h>
|
||||
#include <ATen/core/dispatch/OperatorOptions.h>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
* will fail (and the operator will be included in the binary anyway).
|
||||
*/
|
||||
|
||||
#include <c10/util/string_view.h>
|
||||
#include <string_view>
|
||||
#include <c10/core/DispatchKey.h>
|
||||
#include <c10/macros/Macros.h>
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
|
||||
namespace c10::impl {
|
||||
|
||||
constexpr bool allowlist_contains(string_view allowlist, string_view item); // Forward Declare
|
||||
constexpr bool allowlist_contains(std::string_view allowlist, std::string_view item); // Forward Declare
|
||||
|
||||
/**
|
||||
* In selective build mode returns true/false depending on whether a build
|
||||
@ -102,14 +102,14 @@ constexpr bool is_build_feature_available(const char* name) {
|
||||
|
||||
// returns true iff allowlist contains item
|
||||
// allowlist_contains("a;bc;d", "bc") == true
|
||||
constexpr bool allowlist_contains(string_view allowlist, string_view item) {
|
||||
constexpr bool allowlist_contains(std::string_view allowlist, std::string_view item) {
|
||||
//Choose a really big value for next so that if something goes wrong
|
||||
//this code will blow up in a hopefully detectable way.
|
||||
size_t next = std::numeric_limits<size_t>::max();
|
||||
for (size_t cur = 0; cur <= allowlist.size(); cur = next) {
|
||||
next = allowlist.find(';', cur);
|
||||
if (next != string_view::npos) {
|
||||
if (allowlist.substr(cur, next - cur).compare(item) == 0) {
|
||||
if (next != std::string_view::npos) {
|
||||
if (allowlist.substr(cur, next - cur) == item) {
|
||||
return true;
|
||||
}
|
||||
next++;
|
||||
@ -125,12 +125,12 @@ constexpr bool allowlist_contains(string_view allowlist, string_view item) {
|
||||
|
||||
// Returns true iff the given op name is on the allowlist
|
||||
// and should be registered
|
||||
constexpr bool op_allowlist_check(string_view op_name [[maybe_unused]]) {
|
||||
assert(op_name.find("::") != string_view::npos);
|
||||
constexpr bool op_allowlist_check(std::string_view op_name [[maybe_unused]]) {
|
||||
assert(op_name.find("::") != std::string_view::npos);
|
||||
// Use assert() instead of throw() due to a gcc bug. See:
|
||||
// https://stackoverflow.com/questions/34280729/throw-in-constexpr-function
|
||||
// https://github.com/fmtlib/fmt/issues/682
|
||||
assert(op_name.find("(") == string_view::npos);
|
||||
assert(op_name.find('(') == std::string_view::npos);
|
||||
#if !defined(TORCH_OPERATOR_WHITELIST)
|
||||
// If the TORCH_OPERATOR_WHITELIST parameter is not defined,
|
||||
// all ops are to be registered
|
||||
@ -150,21 +150,20 @@ constexpr bool op_allowlist_check(string_view op_name [[maybe_unused]]) {
|
||||
|
||||
// Returns true iff the given schema string is on the allowlist
|
||||
// and should be registered
|
||||
constexpr bool schema_allowlist_check(string_view schema) {
|
||||
constexpr bool schema_allowlist_check(std::string_view schema) {
|
||||
#if defined(TORCH_FORCE_SCHEMA_REGISTRATION)
|
||||
return true;
|
||||
#else
|
||||
return op_allowlist_check(schema.substr(0, schema.find("(")));
|
||||
return op_allowlist_check(schema.substr(0, schema.find('(')));
|
||||
#endif
|
||||
}
|
||||
|
||||
// Returns true iff the given custom class name is on the allowlist
|
||||
// and should be registered
|
||||
constexpr bool custom_class_allowlist_check(string_view custom_class_name) {
|
||||
constexpr bool custom_class_allowlist_check(std::string_view custom_class_name [[maybe_unused]]) {
|
||||
#if !defined(TORCH_CUSTOM_CLASS_ALLOWLIST)
|
||||
// If the TORCH_CUSTOM_CLASS_ALLOWLIST parameter is not defined,
|
||||
// all custom classes are to be registered
|
||||
(void)custom_class_name;
|
||||
return true;
|
||||
#else
|
||||
return allowlist_contains(
|
||||
@ -175,8 +174,8 @@ constexpr bool custom_class_allowlist_check(string_view custom_class_name) {
|
||||
|
||||
// schema_allowlist_check() implicitly depends on a macro, TORCH_OPERATOR_WHITELIST.
|
||||
// Add this API to pass arbitrary allowlist.
|
||||
constexpr bool op_allowlist_contains_name_in_schema(string_view allowlist, string_view schema) {
|
||||
return allowlist_contains(allowlist, schema.substr(0, schema.find("(")));
|
||||
constexpr bool op_allowlist_contains_name_in_schema(std::string_view allowlist, std::string_view schema) {
|
||||
return allowlist_contains(allowlist, schema.substr(0, schema.find('(')));
|
||||
}
|
||||
|
||||
// Returns true iff the given dispatch key is on the allowlist
|
||||
|
@ -2,12 +2,12 @@
|
||||
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
namespace c10 {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <string_view>
|
||||
#include <ATen/Config.h>
|
||||
#include <ATen/native/DispatchStub.h>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace at::native {
|
||||
// These constants control the approximation behavior of gelu function.
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <ATen/NestedTensorImpl.h>
|
||||
#include <ATen/native/nested/NestedTensorUtils.h>
|
||||
|
||||
#include <c10/util/string_view.h>
|
||||
#include <c10/util/Exception.h>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
namespace at::native {
|
||||
namespace {
|
||||
|
@ -23,7 +23,6 @@
|
||||
#endif
|
||||
|
||||
#include <c10/core/SymInt.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
#if USE_ROCM
|
||||
#if defined(USE_FLASH_ATTENTION) || defined(USE_MEM_EFF_ATTENTION)
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
#include <c10/core/SymInt.h>
|
||||
#include <c10/core/SymFloat.h>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
namespace sdp {
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <c10/core/TensorOptions.h>
|
||||
#include <c10/util/Deprecated.h>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
|
||||
${static_dispatch_ops_headers}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
// ${generated_comment}
|
||||
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <c10/core/Scalar.h>
|
||||
#include <ATen/core/TensorBody.h>
|
||||
|
||||
#include <c10/util/string_view.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace at {
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <c10/util/error.h>
|
||||
#include <c10/util/irange.h>
|
||||
#include <c10/util/numa.h>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef USE_MIMALLOC
|
||||
#include <mimalloc.h>
|
||||
|
@ -2,9 +2,9 @@
|
||||
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/IdWrapper.h>
|
||||
#include <c10/util/string_view.h>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
namespace c10::util {
|
||||
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
#include <c10/macros/Macros.h>
|
||||
#include <c10/util/string_utils.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
C10_CLANG_DIAGNOSTIC_PUSH()
|
||||
#if C10_CLANG_HAS_WARNING("-Wshorten-64-to-32")
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <c10/util/Exception.h>
|
||||
#include <c10/util/Logging.h>
|
||||
#include <c10/util/hash.h>
|
||||
#include <c10/util/string_view.h>
|
||||
|
||||
#include "caffe2/core/common.h"
|
||||
#include "caffe2/serialize/file_adapter.h"
|
||||
|
@ -48,6 +48,7 @@ static std::unordered_map<std::string, ParameterType> type_map = {
|
||||
{"std::string", ParameterType::STRING},
|
||||
{"c10::string_view", ParameterType::STRING},
|
||||
{"std::string_view", ParameterType::STRING},
|
||||
{"::std::string_view", ParameterType::STRING},
|
||||
{"Dimname", ParameterType::DIMNAME},
|
||||
{"DimnameList", ParameterType::DIMNAME_LIST},
|
||||
{"ScalarList", ParameterType::SCALAR_LIST},
|
||||
|
Reference in New Issue
Block a user