Skip to content

pytorch clamp fix for fedora 40 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From e3509eae726e4bca1f61f9bb17686c0802a57faa Mon Sep 17 00:00:00 2001
From 57ea92a345b8bdf25893b548f8d9bbf74b6b0eb4 Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Mon, 11 Dec 2023 09:20:07 -0800
Subject: [PATCH 1/7] pytorch_rocm build and package scripts
Subject: [PATCH 1/8] pytorch_rocm build and package scripts

Signed-off-by: Mika Laitio <[email protected]>
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 2fe6791d47bb3d9ad1c094b855bba014063bd363 Mon Sep 17 00:00:00 2001
From 518fd25d450f2a1461794ba98a21089e4fe17c20 Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 10 May 2024 10:16:19 -0700
Subject: [PATCH 2/7] show error message if ROCM_SOURCE_DIR not defined
Subject: [PATCH 2/8] show error message if ROCM_SOURCE_DIR not defined

ROCM_SOURCE_DIR is required by by third_party/kineto module
and if it is not set, kineto will not find the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 5046c437018a4c32307721657df7f2e8e5fe0404 Mon Sep 17 00:00:00 2001
From bbfb6e70f3e2994766aa12cd11013c9ad17153e4 Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 10 May 2024 10:32:33 -0700
Subject: [PATCH 3/7] LoadHIP force ROCM detection and patches
Subject: [PATCH 3/8] LoadHIP force ROCM detection and patches

- set HIP_ROOT_DIR to ROCM_PATH which is set
by the build scripts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 268f465c7d2b4123aeb50c09c0d92e3f6f8f4478 Mon Sep 17 00:00:00 2001
From 7730d87a24a49f404e18947a7ca2bdf8385fc4fd Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 10 May 2024 11:11:47 -0700
Subject: [PATCH 4/7] LoadHIP lib and lib64 search path adjustements
Subject: [PATCH 4/8] LoadHIP lib and lib64 search path adjustements

- search both lib and lib64 directories
(note some libs still installed to lib-dir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 1047827e6b7d8e57e2109e083d553e8efe597624 Mon Sep 17 00:00:00 2001
From 4644c90bcb782da01181a1b620fcd228acd42a5a Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 10 May 2024 19:25:50 -0700
Subject: [PATCH 5/7] fix gcc parameter is null optimization error
Subject: [PATCH 5/8] fix gcc parameter is null optimization error

https://github.com/pytorch/pytorch/issues/112089
and
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From adbb347de92db04c15acfc9d1bd7c3ca62c95f34 Mon Sep 17 00:00:00 2001
From a6bf3a1ab381f48c2596625a8575c99900590c60 Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Tue, 21 May 2024 20:17:36 -0700
Subject: [PATCH 6/7] cherry-pick hipify fix from never version
Subject: [PATCH 6/8] cherry-pick hipify fix from never version

Signed-off-by: Mika Laitio <[email protected]>
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 2296735a9e3d8c5062111b95f8ea749e6569b306 Mon Sep 17 00:00:00 2001
From 9c24891bc5fbe9796b35ff3b88ebbdbb3283dcb5 Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 31 May 2024 11:34:17 -0700
Subject: [PATCH 7/7] Maybe uninitialized error fix for Fedora 40
Subject: [PATCH 7/8] Maybe uninitialized error fix for Fedora 40

- Occurs on fbgemm submodule with Fedora 40/gcc 14

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
From 4635e7834d872aedc71e33a4a7784bb3de4515eb Mon Sep 17 00:00:00 2001
From: Mika Laitio <[email protected]>
Date: Fri, 31 May 2024 18:35:12 -0700
Subject: [PATCH 8/8] replace clamp with min and max for fedora 40 issue

Fedora 40/gcc 14 throws following error during build time
for clamp function usage during pytorch build time.

In file included from /usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/algorithm:61:
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/bits/stl_algo.h:3625:7: error: reference to host function '__glibcxx_assert_fail' in host device function
3625 | __glibcxx_assert(!(__hi < __lo));
| ^
/usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/x86_64-redhat-linux/bits/c++config.h:2453:7: note: expanded from macro '__glibcxx_assert'
2453 | std::__glibcxx_assert_fail();
| ^
pytorch/aten/src/ATen/native/hip/IndexKernel.hip:254:21: note: called by 'operator()'
254 | qvalue = std::clamp(qvalue, qmin, qmax);

https://github.com/pytorch/pytorch/issues/127666
https://github.com/lamikr/rocm_sdk_builder/issues/12

Signed-off-by: Mika Laitio <[email protected]>
---
aten/src/ATen/native/cuda/IndexKernel.cu | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/aten/src/ATen/native/cuda/IndexKernel.cu b/aten/src/ATen/native/cuda/IndexKernel.cu
index 5682ba27573..862bcb9614d 100644
--- a/aten/src/ATen/native/cuda/IndexKernel.cu
+++ b/aten/src/ATen/native/cuda/IndexKernel.cu
@@ -249,7 +249,9 @@ void index_put_kernel_quantized_cuda(TensorIterator& iter, const IntArrayRef ind

gpu_index_kernel(iter, index_size, index_stride, [inv_scale, zero_point, qmin, qmax]C10_DEVICE(char* const out_data, const char* const in_data, const int64_t offset) {
int64_t qvalue = static_cast<int64_t>(zero_point + nearbyintf(*(float*)in_data * inv_scale));
- qvalue = std::clamp(qvalue, qmin, qmax);
+ int64_t new_max = std::max<int64_t>(qmin, qvalue);
+ qvalue = std::min<int64_t>(qmax, new_max);
+ //qvalue = std::clamp(qvalue, qmin, qmax);
*(scalar_t*)(out_data + offset) = static_cast<scalar_t>(qvalue);
});
});
--
2.45.1