[3/N] Replace c10::sv with std::sv (#139861)

Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139861
Approved by: https://github.com/ezyang
This commit is contained in:
cyy 2024-11-07 20:03:52 +00:00 committed by PyTorch MergeBot
parent 85204d0081
commit 83fa1014f1
16 changed files with 48 additions and 47 deletions

View File

@ -61,7 +61,7 @@ constexpr const char* unknown_eventname = "eventname not specified";
#endif
} // namespace (anonymous)
MapAllocator::MapAllocator(WithFd, c10::string_view filename, int fd, int flags, size_t size)
MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags, size_t size)
: filename_(filename.empty() ? unknown_filename : filename)
, size_(0) // to be filled later
#ifdef _WIN32
@ -369,7 +369,7 @@ MapAllocator::MapAllocator(WithFd, c10::string_view filename, int fd, int flags,
c10::reportMemoryUsageToProfiler(base_ptr_, size_, 0, size_, c10::Device(c10::DeviceType::CPU));
}
MapAllocator::MapAllocator(c10::string_view filename, int flags, size_t size)
MapAllocator::MapAllocator(std::string_view filename, int flags, size_t size)
: MapAllocator(WITH_FD, filename, -1, flags, size)
{}
@ -435,11 +435,11 @@ void MapAllocator::close() {
#else /* defined(_WIN32) || defined(HAVE_MMAP) */
MapAllocator::MapAllocator(c10::string_view filename, int flags, size_t size) {
MapAllocator::MapAllocator(std::string_view filename, int flags, size_t size) {
TORCH_CHECK(false, "file mapping not supported on your system");
}
MapAllocator::MapAllocator(WithFd, c10::string_view filename, int fd, int flags, size_t size) {
MapAllocator::MapAllocator(WithFd, std::string_view filename, int fd, int flags, size_t size) {
TORCH_CHECK(false, "file mapping not supported on your system");
}
@ -584,7 +584,7 @@ RefcountedMapAllocator* RefcountedMapAllocator::fromDataPtr(const at::DataPtr& d
return dptr.cast_context<RefcountedMapAllocator>(&deleteRefcountedMapAllocator);
}
at::DataPtr MapAllocator::makeDataPtr(c10::string_view filename, int flags, size_t size, size_t* actual_size_out) {
at::DataPtr MapAllocator::makeDataPtr(std::string_view filename, int flags, size_t size, size_t* actual_size_out) {
auto* context = new MapAllocator(filename, flags, size);
if (actual_size_out) *actual_size_out = context->size();
return {context->data(), context, &deleteMapAllocator, at::DeviceType::CPU};

View File

@ -23,10 +23,10 @@ TORCH_API std::string NewProcessWideShmHandle();
class TORCH_API MapAllocator {
public:
MapAllocator(c10::string_view filename, int flags, size_t size);
MapAllocator(std::string_view filename, int flags, size_t size);
MapAllocator(
WithFd,
c10::string_view filename,
std::string_view filename,
int fd,
int flags,
size_t size);
@ -61,7 +61,7 @@ class TORCH_API MapAllocator {
static MapAllocator* fromDataPtr(const at::DataPtr&);
static at::DataPtr makeDataPtr(
c10::string_view filename,
std::string_view filename,
int flags,
size_t size,
size_t* actual_size_out);

View File

@ -22,7 +22,7 @@ struct BuiltinOpFunction : public Function {
TORCH_INTERNAL_ASSERT(schema_.returns().size() == 1);
}
c10::string_view doc_string() const override {
std::string_view doc_string() const override {
return doc_string_;
}

View File

@ -42,8 +42,8 @@ struct TORCH_API Function {
Function& operator=(const Function&) = default;
Function(Function&&) noexcept = default;
Function& operator=(Function&&) noexcept = default;
virtual c10::string_view doc_string() const {
static constexpr c10::string_view no_doc_string = "";
virtual std::string_view doc_string() const {
static constexpr std::string_view no_doc_string = "";
return no_doc_string;
}

View File

@ -395,7 +395,7 @@ struct TORCH_API FunctionSchema {
const AliasInfo* aliasInfo = getCorrectList(argument.type)[argument.index].alias_info();
return aliasInfo && aliasInfo->isWrite();
}
bool is_mutable(c10::string_view name) const {
bool is_mutable(std::string_view name) const {
std::optional<int> index = argumentIndexWithName(name);
TORCH_INTERNAL_ASSERT(
index != std::nullopt, "Schema has no argument named ", name);
@ -432,7 +432,7 @@ struct TORCH_API FunctionSchema {
// output => returns(), input => arguments()
const std::vector<Argument>& getCorrectList(SchemaArgType type) const;
std::optional<int> argumentIndexWithName(c10::string_view name) const {
std::optional<int> argumentIndexWithName(std::string_view name) const {
for (const auto i : c10::irange(arguments().size())) {
if(name == arguments()[i].name())
return i;
@ -515,7 +515,7 @@ struct TORCH_API FunctionSchema {
alias_kind_ = v;
}
std::optional<c10::string_view> getNamespace() const {
std::optional<std::string_view> getNamespace() const {
return name_.getNamespace();
}

View File

@ -23,12 +23,12 @@ struct OperatorName final {
// Return the namespace of this OperatorName, if it exists. The
// returned string_view is only live as long as the OperatorName
// exists and name is not mutated
std::optional<c10::string_view> getNamespace() const {
std::optional<std::string_view> getNamespace() const {
auto pos = name.find("::");
if (pos == std::string::npos) {
return std::nullopt;
} else {
return std::make_optional(c10::string_view(name.data(), pos));
return std::make_optional(std::string_view(name.data(), pos));
}
}
@ -55,17 +55,17 @@ struct OperatorName final {
// its functions are constexpr, so it can be used for compile time
// computations
struct OperatorNameView final {
c10::string_view name;
c10::string_view overload_name;
std::string_view name;
std::string_view overload_name;
constexpr OperatorNameView(
c10::string_view name,
c10::string_view overload_name)
std::string_view name,
std::string_view overload_name)
: name(name), overload_name(overload_name) {}
// Parses strings like "foo.overload" and also "foo"
constexpr static OperatorNameView parse(c10::string_view full_name) {
constexpr static OperatorNameView parse(std::string_view full_name) {
auto i = full_name.find('.');
if (i == c10::string_view::npos) {
return OperatorNameView(full_name, c10::string_view());
if (i == std::string_view::npos) {
return OperatorNameView(full_name, std::string_view());
} else {
return OperatorNameView(full_name.substr(0, i), full_name.substr(i + 1));
}

View File

@ -9,7 +9,7 @@ TEST(OperatorNameTest, SetNamespaceIfNotSetWithoutExistingNamespace) {
EXPECT_TRUE(result);
EXPECT_EQ(testName.name, "ns::operator");
EXPECT_EQ(testName.overload_name, "operator.overload");
EXPECT_EQ(testName.getNamespace(), std::optional<c10::string_view>("ns"));
EXPECT_EQ(testName.getNamespace(), std::optional<std::string_view>("ns"));
}
TEST(OperatorNameTest, SetNamespaceIfNotSetWithExistingNamespace) {
@ -18,5 +18,5 @@ TEST(OperatorNameTest, SetNamespaceIfNotSetWithExistingNamespace) {
EXPECT_FALSE(result);
EXPECT_EQ(namespacedName.name, "already_namespaced::operator");
EXPECT_EQ(namespacedName.overload_name, "operator.overload");
EXPECT_EQ(namespacedName.getNamespace(), std::optional<c10::string_view>("already_namespaced"));
EXPECT_EQ(namespacedName.getNamespace(), std::optional<std::string_view>("already_namespaced"));
}

View File

@ -120,7 +120,7 @@ namespace torch {
static void processErrorMsgInplace(std::string& str) {
// Translate Aten types to their respective pytorch ones
constexpr std::array<std::pair<c10::string_view, c10::string_view>, 64>
constexpr std::array<std::pair<std::string_view, std::string_view>, 64>
changes{{
// TODO: remove torch.(cuda.|)sparse.*Tensor items?
{"Variable[SparseCUDAByteType]", "torch.cuda.sparse.ByteTensor"},

View File

@ -151,7 +151,7 @@ ucc_status_t oob_allgather_free(void* req);
// trim: remove spaces before and after the string view
// implementation borrowed from https://stackoverflow.com/a/17976541
inline c10::string_view trim(c10::string_view s) {
inline std::string_view trim(std::string_view s) {
auto wsfront = std::find_if_not(
s.begin(), s.end(), [](int c) { return std::isspace(c); });
auto wsback = std::find_if_not(s.rbegin(), s.rend(), [](int c) {
@ -161,7 +161,7 @@ inline c10::string_view trim(c10::string_view s) {
wsback <= wsfront ? "" : s.substr(wsfront - s.begin(), wsback - wsfront));
}
inline std::string tolower(c10::string_view s) {
inline std::string tolower(std::string_view s) {
std::string result;
result.reserve(s.size());
for (auto c : s) {
@ -177,7 +177,7 @@ inline std::vector<std::string> parse_list(std::string list) {
const auto end_pos = list.find_first_of(',');
const auto token = trim(list.substr(0, end_pos));
result.push_back(std::string(token));
list = (end_pos != c10::string_view::npos) ? list.substr(end_pos + 1) : "";
list = (end_pos != std::string_view::npos) ? list.substr(end_pos + 1) : "";
}
return result;
}

View File

@ -398,7 +398,7 @@ static PyObject* reduceopmeta___instancecheck__(
Py_RETURN_TRUE;
}
if (std::string_view(args->ob_type->tp_name).find("RedOpType") !=
c10::string_view::npos) {
std::string_view::npos) {
Py_RETURN_TRUE;
}
Py_RETURN_FALSE;

View File

@ -166,8 +166,8 @@ std::vector<ParameterMetadata> unpack_input_parameters(
AOTIPythonKernelHolder::AOTIPythonKernelHolder(
c10::DispatchKey dispatch_key,
c10::string_view ns,
c10::string_view op_name_with_overload)
std::string_view ns,
std::string_view op_name_with_overload)
: dispatch_key_(dispatch_key),
ns_(std::string(ns)),
op_name_with_overload_(std::string(op_name_with_overload)),

View File

@ -68,8 +68,8 @@ class AOTIPythonKernelHolder : public c10::OperatorKernel {
public:
AOTIPythonKernelHolder(
c10::DispatchKey dispatch_key,
c10::string_view ns,
c10::string_view op_name_with_overload);
std::string_view ns,
std::string_view op_name_with_overload);
void operator()(
const c10::OperatorHandle& op,

View File

@ -62,9 +62,9 @@ AOTITorchError aoti_torch_cpu_mkldnn__convolution_pointwise_binary(
groups,
binary_attr,
pointer_to_optional<c10::Scalar>(alpha),
pointer_to_optional<c10::string_view>(unary_attr),
pointer_to_optional<std::string_view>(unary_attr),
unary_scalars_list,
pointer_to_optional<c10::string_view>(unary_algorithm));
pointer_to_optional<std::string_view>(unary_algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -105,9 +105,9 @@ AOTITorchError aoti_torch_cpu_mkldnn__convolution_pointwise_binary_(
groups,
binary_attr,
pointer_to_optional<c10::Scalar>(alpha),
pointer_to_optional<c10::string_view>(unary_attr),
pointer_to_optional<std::string_view>(unary_attr),
unary_scalars_list,
pointer_to_optional<c10::string_view>(unary_algorithm));
pointer_to_optional<std::string_view>(unary_algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -144,7 +144,7 @@ AOTITorchError aoti_torch_cpu_mkldnn__convolution_pointwise(
groups,
attr,
scalars_list,
pointer_to_optional<c10::string_view>(algorithm));
pointer_to_optional<std::string_view>(algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -185,7 +185,7 @@ aoti_torch_cpu_mkldnn__convolution_transpose_pointwise(
groups,
attr,
scalars_list,
pointer_to_optional<c10::string_view>(algorithm));
pointer_to_optional<std::string_view>(algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -258,7 +258,7 @@ AOTITorchError aoti_torch_cpu__linear_pointwise(
pointer_to_optional<at::Tensor>(B),
attr,
scalars_list,
pointer_to_optional<c10::string_view>(algorithm));
pointer_to_optional<std::string_view>(algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -428,7 +428,7 @@ AOTI_TORCH_EXPORT AOTITorchError aoti_torch_cpu__qconv2d_pointwise_tensor(
pointer_to_optional<at::ScalarType>(output_dtype),
attr,
scalars_list,
pointer_to_optional<c10::string_view>(algorithm));
pointer_to_optional<std::string_view>(algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}
@ -496,9 +496,9 @@ aoti_torch_cpu__qconv2d_pointwise_binary_tensor(
accum_zero_point,
binary_attr,
pointer_to_optional<c10::Scalar>(alpha),
pointer_to_optional<c10::string_view>(unary_attr),
pointer_to_optional<std::string_view>(unary_attr),
unary_scalars_list,
pointer_to_optional<c10::string_view>(unary_algorithm));
pointer_to_optional<std::string_view>(unary_algorithm));
*ret0 = new_tensor_handle(std::move(tmp_result));
});
}

View File

@ -47,6 +47,7 @@ static std::unordered_map<std::string, ParameterType> type_map = {
{"Stream", ParameterType::STREAM},
{"std::string", ParameterType::STRING},
{"c10::string_view", ParameterType::STRING},
{"std::string_view", ParameterType::STRING},
{"Dimname", ParameterType::DIMNAME},
{"DimnameList", ParameterType::DIMNAME_LIST},
{"ScalarList", ParameterType::SCALAR_LIST},

View File

@ -285,7 +285,7 @@ struct PythonArgs {
inline std::string_view stringViewWithDefault(
int i,
const std::string_view default_str);
inline std::optional<c10::string_view> stringViewOptional(int i);
inline std::optional<std::string_view> stringViewOptional(int i);
inline PyObject* pyobject(int i);
inline int64_t toInt64(int i);
inline c10::SymInt toSymInt(int i);
@ -947,7 +947,7 @@ inline std::string_view PythonArgs::stringViewWithDefault(
return THPUtils_unpackStringView(args[i]);
}
inline std::optional<c10::string_view> PythonArgs::stringViewOptional(int i) {
inline std::optional<std::string_view> PythonArgs::stringViewOptional(int i) {
if (!args[i])
return std::nullopt;
return THPUtils_unpackStringView(args[i]);

View File

@ -34,7 +34,7 @@ inline std::string THPUtils_unpackString(PyObject* obj) {
throw std::runtime_error("unpackString: expected bytes or unicode object");
}
// Unpacks PyBytes (PyString) or PyUnicode as c10::string_view
// Unpacks PyBytes (PyString) or PyUnicode as std::string_view
// PyBytes are unpacked as-is. PyUnicode is unpacked as UTF-8.
// NOTE: If `obj` is destroyed, then the non-owning std::string_view will
// become invalid. If the string needs to be accessed at any point after