Skip to content

Commit c17ba69

Browse files
atalmanpytorchmergebot
authored andcommitted
[submodule] Revert "Adds support for accelerated sorting with x86-simd-sort (pytorch#127936) (pytorch#141901)
Looks like the original PR caused: pytorch#140590 Please see comment: pytorch#140590 (comment) Pull Request resolved: pytorch#141901 Approved by: https://github.com/andrewor14, https://github.com/malfet
1 parent e41a0b3 commit c17ba69

File tree

8 files changed

+2
-207
lines changed

8 files changed

+2
-207
lines changed

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,3 @@
131131
path = third_party/composable_kernel
132132
url = https://github.com/ROCm/composable_kernel.git
133133
branch = develop
134-
[submodule "third_party/x86-simd-sort"]
135-
path = third_party/x86-simd-sort
136-
url = https://github.com/intel/x86-simd-sort.git

CMakeLists.txt

-8
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ else()
262262
cmake_dependent_option(USE_CUFILE "Use cuFile" OFF "USE_CUDA AND NOT WIN32" OFF)
263263
endif()
264264
option(USE_FBGEMM "Use FBGEMM (quantized 8-bit server operators)" ON)
265-
option(USE_X86_SIMD_SORT "Use x86-simd-sort to accelerate sorting and topk for AVX2/AVX512" ON)
266265
option(USE_KINETO "Use Kineto profiling library" ON)
267266
option(USE_CUPTI_SO "Use CUPTI as a shared library" ON)
268267
option(USE_FAKELOWP "Use FakeLowp operators" OFF)
@@ -904,13 +903,6 @@ if(USE_FBGEMM)
904903
string(APPEND CMAKE_CXX_FLAGS " -DUSE_FBGEMM")
905904
endif()
906905

907-
if(USE_X86_SIMD_SORT)
908-
string(APPEND CMAKE_CXX_FLAGS " -DUSE_X86_SIMD_SORT")
909-
if(USE_XSS_OPENMP)
910-
string(APPEND CMAKE_CXX_FLAGS " -DXSS_USE_OPENMP")
911-
endif()
912-
endif()
913-
914906
if(USE_PYTORCH_QNNPACK)
915907
string(APPEND CMAKE_CXX_FLAGS " -DUSE_PYTORCH_QNNPACK")
916908
endif()

NOTICE

-34
Original file line numberDiff line numberDiff line change
@@ -454,37 +454,3 @@ and reference the following license:
454454
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
455455
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
456456
PERFORMANCE OF THIS SOFTWARE.
457-
458-
=======================================================================
459-
x86-simd-sort BSD 3-Clause License
460-
=======================================================================
461-
462-
Code derived from implementations in x86-simd-sort should mention its
463-
derivation and reference the following license:
464-
465-
Copyright (c) 2022, Intel. All rights reserved.
466-
467-
Redistribution and use in source and binary forms, with or without
468-
modification, are permitted provided that the following conditions are met:
469-
470-
1. Redistributions of source code must retain the above copyright notice, this
471-
list of conditions and the following disclaimer.
472-
473-
2. Redistributions in binary form must reproduce the above copyright notice,
474-
this list of conditions and the following disclaimer in the documentation
475-
and/or other materials provided with the distribution.
476-
477-
3. Neither the name of the copyright holder nor the names of its
478-
contributors may be used to endorse or promote products derived from
479-
this software without specific prior written permission.
480-
481-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
482-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
483-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
484-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
485-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
486-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
487-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
488-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
489-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
490-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

aten/src/ATen/native/cpu/SortingKernel.cpp

+2-129
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@
1515
#include <ATen/native/CompositeRandomAccessor.h>
1616
#include <ATen/native/TopKImpl.h>
1717
#include <c10/core/WrapDimMinimal.h>
18-
#include <c10/util/SmallBuffer.h>
1918
#include <c10/util/irange.h>
20-
2119
#ifdef USE_FBGEMM
2220
#include <fbgemm/Utils.h>
2321
#endif
2422

25-
#if USE_X86_SIMD_SORT && (defined(CPU_CAPABILITY_AVX512) || defined(CPU_CAPABILITY_AVX2))
26-
#define XSS_COMPILE_TIME_SUPPORTED
27-
#include <src/x86simdsort-static-incl.h>
28-
#endif
29-
3023
namespace at::native {
3124

3225
namespace {
@@ -124,7 +117,6 @@ static void parallel_sort1d_kernel(
124117
std::vector<int64_t> tmp_vals(elements);
125118
const scalar_t* sorted_keys = nullptr;
126119
const int64_t* sorted_vals = nullptr;
127-
128120
std::tie(sorted_keys, sorted_vals) = fbgemm::radix_sort_parallel(
129121
keys,
130122
vals,
@@ -173,116 +165,6 @@ static inline void sort_kernel_impl(const value_accessor_t& value_accessor,
173165
}
174166
}
175167

176-
#if defined(XSS_COMPILE_TIME_SUPPORTED)
177-
178-
#define AT_DISPATCH_CASE_XSS_TYPES(...) \
179-
AT_DISPATCH_CASE(at::ScalarType::Long, __VA_ARGS__) \
180-
AT_DISPATCH_CASE(at::ScalarType::Int, __VA_ARGS__) \
181-
AT_DISPATCH_CASE(at::ScalarType::Double, __VA_ARGS__) \
182-
AT_DISPATCH_CASE(at::ScalarType::Float, __VA_ARGS__)
183-
184-
#define AT_DISPATCH_XSS_TYPES(TYPE, NAME, ...) \
185-
AT_DISPATCH_SWITCH(TYPE, NAME, AT_DISPATCH_CASE_XSS_TYPES(__VA_ARGS__))
186-
187-
static bool can_use_xss_sort(const TensorBase& values, const TensorBase& indices, int64_t dim, const bool stable) {
188-
// xss_sort is not a stable sort
189-
if (stable) return false;
190-
191-
auto type = values.scalar_type();
192-
if (! (type == ScalarType::Long || type == ScalarType::Int || type == ScalarType::Double || type == ScalarType::Float)) return false;
193-
194-
return true;
195-
}
196-
197-
static bool xss_sort_preferred(const TensorBase& values, const bool descending) {
198-
#if defined(XSS_USE_OPENMP) || !defined(USE_FBGEMM)
199-
return true;
200-
#else
201-
// Without OpenMP support for x86-simd-sort, fbgemm radix sort is faster when it can be used
202-
return !can_use_radix_sort(values, descending);
203-
#endif
204-
}
205-
206-
static void xss_sort_kernel(
207-
const TensorBase& values,
208-
const TensorBase& indices,
209-
int64_t dim,
210-
bool descending) {
211-
auto iter = TensorIteratorConfig()
212-
.check_all_same_dtype(false)
213-
.resize_outputs(false)
214-
.declare_static_shape(values.sizes(), /*squash_dims=*/dim)
215-
.add_output(values)
216-
.add_output(indices)
217-
.build();
218-
219-
using index_t = int64_t;
220-
221-
AT_DISPATCH_XSS_TYPES(values.scalar_type(), "xss_sort_kernel", [&] {
222-
223-
auto values_dim_stride = values.stride(dim);
224-
auto indices_dim_stride = indices.stride(dim);
225-
auto dim_size = values.size(dim);
226-
227-
auto loop = [&](char** data, const int64_t* strides, int64_t n) {
228-
auto* values_data_bytes = data[0];
229-
auto* indices_data_bytes = data[1];
230-
231-
if(values_data_bytes==nullptr || indices_data_bytes==nullptr){
232-
return;
233-
}
234-
235-
if (values_dim_stride == 1 && indices_dim_stride == 1){
236-
for (const auto i [[maybe_unused]] : c10::irange(n)) {
237-
x86simdsortStatic::keyvalue_qsort<scalar_t, index_t>(
238-
reinterpret_cast<scalar_t*>(values_data_bytes),
239-
reinterpret_cast<index_t*>(indices_data_bytes),
240-
dim_size,
241-
true,
242-
descending);
243-
244-
values_data_bytes += strides[0];
245-
indices_data_bytes += strides[1];
246-
}
247-
}else{
248-
c10::SmallBuffer<scalar_t, 0> tmp_values(dim_size);
249-
c10::SmallBuffer<index_t, 0> tmp_indices(dim_size);
250-
251-
for (const auto i : c10::irange(n)) {
252-
TensorAccessor<scalar_t, 1> mode_values_acc(
253-
reinterpret_cast<scalar_t*>(data[0] + i * strides[0]),
254-
&dim_size, &values_dim_stride);
255-
TensorAccessor<index_t, 1> mode_indices_acc(
256-
reinterpret_cast<index_t*>(data[1] + i * strides[1]),
257-
&dim_size, &indices_dim_stride);
258-
259-
for (const auto j : c10::irange(dim_size)) {
260-
tmp_values[j] = mode_values_acc[j];
261-
tmp_indices[j] = j;
262-
}
263-
264-
x86simdsortStatic::keyvalue_qsort<scalar_t, index_t>(
265-
tmp_values.data(),
266-
tmp_indices.data(),
267-
dim_size,
268-
true,
269-
descending);
270-
271-
for (const auto j : c10::irange(dim_size)) {
272-
mode_values_acc[j] = tmp_values[j];
273-
mode_indices_acc[j] = tmp_indices[j];
274-
}
275-
}
276-
}
277-
};
278-
279-
int64_t grain_size = internal::GRAIN_SIZE / std::max(int64_t{1}, dim_size);
280-
iter.for_each(loop, /*grain_size=*/grain_size);
281-
282-
});
283-
}
284-
#endif
285-
286168
static void sort_kernel(
287169
const TensorBase& self,
288170
const TensorBase& values,
@@ -297,14 +179,6 @@ static void sort_kernel(
297179
// https://github.com/pytorch/pytorch/issues/91420
298180
return;
299181
}
300-
301-
#if defined(XSS_COMPILE_TIME_SUPPORTED)
302-
if (can_use_xss_sort(values, indices, dim, stable) && xss_sort_preferred(values, descending)){
303-
xss_sort_kernel(values, indices, dim, descending);
304-
return;
305-
}
306-
#endif
307-
308182
#ifdef USE_FBGEMM
309183
if (can_use_radix_sort(values, descending)) {
310184
parallel_sort1d_kernel(values, indices);
@@ -356,7 +230,6 @@ static void topk_kernel(
356230
int64_t dim,
357231
bool largest,
358232
bool sorted) {
359-
360233
auto sizes = self.sizes();
361234
auto iter = TensorIteratorConfig()
362235
.check_all_same_dtype(false)
@@ -391,7 +264,7 @@ static void topk_kernel(
391264

392265
} // anonymous namespace
393266

394-
ALSO_REGISTER_AVX512_DISPATCH(sort_stub, &sort_kernel)
395-
ALSO_REGISTER_AVX512_DISPATCH(topk_stub, &topk_kernel)
267+
REGISTER_DISPATCH(sort_stub, &sort_kernel)
268+
REGISTER_DISPATCH(topk_stub, &topk_kernel)
396269

397270
} //at::native

cmake/Dependencies.cmake

-22
Original file line numberDiff line numberDiff line change
@@ -1310,28 +1310,6 @@ if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO AND NOT INTERN_DISABLE_ONNX)
13101310
set(BUILD_SHARED_LIBS ${TEMP_BUILD_SHARED_LIBS})
13111311
endif()
13121312

1313-
# --[ x86-simd-sort integration
1314-
if(USE_X86_SIMD_SORT)
1315-
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
1316-
message(WARNING
1317-
"x64 operating system is required for x86-simd-sort. "
1318-
"Not compiling with x86-simd-sort. "
1319-
"Turn this warning off by USE_X86_SIMD_SORT=OFF.")
1320-
set(USE_X86_SIMD_SORT OFF)
1321-
endif()
1322-
1323-
if(USE_X86_SIMD_SORT)
1324-
if(USE_OPENMP AND NOT MSVC)
1325-
set(USE_XSS_OPENMP ON)
1326-
else()
1327-
set(USE_XSS_OPENMP OFF)
1328-
endif()
1329-
1330-
set(XSS_SIMD_SORT_INCLUDE_DIR ${CMAKE_CURRENT_LIST_DIR}/../third_party/x86-simd-sort)
1331-
include_directories(SYSTEM ${XSS_SIMD_SORT_INCLUDE_DIR})
1332-
endif()
1333-
endif()
1334-
13351313
# --[ ATen checks
13361314
set(USE_LAPACK 0)
13371315

cmake/Summary.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ function(caffe2_print_configuration_summary)
134134
endif()
135135
message(STATUS " BUILD_NVFUSER : ${BUILD_NVFUSER}")
136136
message(STATUS " USE_EIGEN_FOR_BLAS : ${CAFFE2_USE_EIGEN_FOR_BLAS}")
137-
message(STATUS " USE_X86_SIMD_SORT : ${USE_X86_SIMD_SORT}")
138137
message(STATUS " USE_FBGEMM : ${USE_FBGEMM}")
139138
message(STATUS " USE_FAKELOWP : ${USE_FAKELOWP}")
140139
message(STATUS " USE_KINETO : ${USE_KINETO}")

test/inductor/test_torchinductor_opinfo.py

-9
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,6 @@ def wrapper_noop_set_seed(op, *args, **kwargs):
463463
("nn.functional.interpolate.bicubic", u8): {"atol": 1, "rtol": 0},
464464
# High atol due to precision loss
465465
("nn.functional.interpolate.bicubic", f32): {"atol": 5e-3, "rtol": 0},
466-
# reference_in_float can cause erroneous failures in sorting tests
467-
"argsort": {"reference_in_float": False},
468-
"sort": {"reference_in_float": False},
469466
}
470467

471468
inductor_override_kwargs["cuda"] = {
@@ -536,9 +533,6 @@ def wrapper_noop_set_seed(op, *args, **kwargs):
536533
("index_reduce.amax", f32): {"check_gradient": False},
537534
("index_reduce.amax", f16): {"check_gradient": False},
538535
("tanh", f16): {"atol": 1e-4, "rtol": 1e-2},
539-
# reference_in_float can cause erroneous failures in sorting tests
540-
"argsort": {"reference_in_float": False},
541-
"sort": {"reference_in_float": False},
542536
}
543537

544538
inductor_override_kwargs["xpu"] = {
@@ -663,9 +657,6 @@ def wrapper_noop_set_seed(op, *args, **kwargs):
663657
("nn.functional.embedding_bag", f64): {"check_gradient": False},
664658
("_unsafe_masked_index", f16): {"atol": 1e-5, "rtol": 2e-3},
665659
("_unsafe_masked_index_put_accumulate", f16): {"atol": 1e-5, "rtol": 5e-3},
666-
# reference_in_float can cause erroneous failures in sorting tests
667-
"argsort": {"reference_in_float": False},
668-
"sort": {"reference_in_float": False},
669660
}
670661

671662
# Test with one sample only for following ops

third_party/x86-simd-sort

-1
This file was deleted.

0 commit comments

Comments
 (0)