Skip to content

Commit

Permalink
Change gsl::byte to std::byte (#23872)
Browse files Browse the repository at this point in the history
To be compatible with the latest GSL library. Without this fix we will
get:

```
onnxruntime\core\providers\cpu\controlflow\loop.cc(247): error C4996: 'gsl::byte': Use std::byte instead.
```
  • Loading branch information
snnn authored Mar 4, 2025
1 parent 30c6825 commit bde4fbe
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/cpu/controlflow/loop.cc
Original file line number Diff line number Diff line change
@@ -244,7 +244,7 @@ static Status ConcatenateCpuOutput(void* /*stream*/,

// we can't easily use a C++ template for the tensor element type,
// so use a span for some protection but work in bytes
gsl::span<gsl::byte> output_span = gsl::make_span<gsl::byte>(static_cast<gsl::byte*>(output),
gsl::span<std::byte> output_span = gsl::make_span<std::byte>(static_cast<std::byte*>(output),
output_size_in_bytes);

for (size_t i = 0, num_iterations = per_iteration_output.size(); i < num_iterations; ++i) {
@@ -257,7 +257,7 @@ static Status ConcatenateCpuOutput(void* /*stream*/,
" Expected:", per_iteration_shape, " Got:", iteration_data.Shape());
}

auto src = gsl::make_span<const gsl::byte>(static_cast<const gsl::byte*>(iteration_data.DataRaw()),
auto src = gsl::make_span<const std::byte>(static_cast<const std::byte*>(iteration_data.DataRaw()),
bytes_per_iteration);
auto dst = output_span.subspan(i * bytes_per_iteration, bytes_per_iteration);
gsl::copy(src, dst);
4 changes: 2 additions & 2 deletions onnxruntime/core/providers/cuda/controlflow/loop.cc
Original file line number Diff line number Diff line change
@@ -84,10 +84,10 @@ static Status ConcatenateGpuOutput(void* stream, std::vector<OrtValue>& per_iter
CUDA_RETURN_IF_ERROR(cudaMemcpyAsync(cur_output, iteration_data.DataRaw(), bytes_per_iteration,
cudaMemcpyDeviceToDevice, static_cast<cudaStream_t>(stream)));

cur_output = static_cast<void*>((static_cast<gsl::byte*>(cur_output) + bytes_per_iteration));
cur_output = static_cast<void*>((static_cast<std::byte*>(cur_output) + bytes_per_iteration));
}

ORT_ENFORCE(static_cast<gsl::byte*>(cur_output) - static_cast<gsl::byte*>(output) == output_size_in_bytes,
ORT_ENFORCE(static_cast<std::byte*>(cur_output) - static_cast<std::byte*>(output) == output_size_in_bytes,
"Concatenation did not fill output buffer as expected.");

return Status::OK();
6 changes: 3 additions & 3 deletions onnxruntime/test/providers/base_tester.cc
Original file line number Diff line number Diff line change
@@ -174,7 +174,7 @@ static std::unique_ptr<SparseTensor> MakeSparseTensor(MLDataType data_type, cons
return p_tensor;
}

void BaseTester::CopyDataToTensor(gsl::span<const gsl::byte> data, Tensor& dst) {
void BaseTester::CopyDataToTensor(gsl::span<const std::byte> data, Tensor& dst) {
ORT_ENFORCE(dst.SizeInBytes() >= data.size_bytes(), "Not enough space in the destination tensor");
memcpy(dst.MutableDataRaw(), data.data(), data.size_bytes());
}
@@ -203,7 +203,7 @@ void BaseTester::AddSparseCooTensorData(std::vector<Data>& data,
MLDataType data_type,
const char* name,
gsl::span<const int64_t> dims,
gsl::span<const gsl::byte> values,
gsl::span<const std::byte> values,
gsl::span<const int64_t> indices,
const ValidateOutputParams& check_params,
const std::vector<std::string>* dim_params) {
@@ -247,7 +247,7 @@ void BaseTester::AddSparseCsrTensorData(std::vector<Data>& data,
MLDataType data_type,
const char* name,
gsl::span<const int64_t> dims,
gsl::span<const gsl::byte> values,
gsl::span<const std::byte> values,
gsl::span<const int64_t> inner_indices,
gsl::span<const int64_t> outer_indices,
const ValidateOutputParams& check_params,
6 changes: 3 additions & 3 deletions onnxruntime/test/providers/base_tester.h
Original file line number Diff line number Diff line change
@@ -868,7 +868,7 @@ class BaseTester {
void AddShapeToTensorData(NodeArg& node_arg, gsl::span<const int64_t> dims,
const std::vector<std::string>* dim_params);

void CopyDataToTensor(gsl::span<const gsl::byte> data, Tensor& dst);
void CopyDataToTensor(gsl::span<const std::byte> data, Tensor& dst);

#if !defined(DISABLE_SPARSE_TENSORS)
NodeArg MakeSparseNodeArg(int32_t dtype, const char* name,
@@ -879,7 +879,7 @@ class BaseTester {
MLDataType data_type,
const char* name,
gsl::span<const int64_t> dims,
gsl::span<const gsl::byte> values,
gsl::span<const std::byte> values,
gsl::span<const int64_t> indices,
const ValidateOutputParams& check_params,
const std::vector<std::string>* dim_params = nullptr);
@@ -895,7 +895,7 @@ class BaseTester {
MLDataType data_type,
const char* name,
gsl::span<const int64_t> dims,
gsl::span<const gsl::byte> values,
gsl::span<const std::byte> values,
gsl::span<const int64_t> inner_indices,
gsl::span<const int64_t> outer_indices,
const ValidateOutputParams& check_params,

0 comments on commit bde4fbe

Please sign in to comment.