Skip to content

Commit c9f6a00

Browse files
lamikrMika Laitio
authored and
Mika Laitio
committed
pytorch clamp fix for fedora 40
fedora 40/gcc 14 build failure. Replace clamp with min and max. pytorch/pytorch#127666 #12 Signed-off-by: Mika Laitio <[email protected]>
1 parent e154e72 commit c9f6a00

8 files changed

+58
-14
lines changed

patches/rocm-6.1.1/pytorch/0001-pytorch_rocm-build-and-package-scripts.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From e3509eae726e4bca1f61f9bb17686c0802a57faa Mon Sep 17 00:00:00 2001
1+
From 57ea92a345b8bdf25893b548f8d9bbf74b6b0eb4 Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Mon, 11 Dec 2023 09:20:07 -0800
4-
Subject: [PATCH 1/7] pytorch_rocm build and package scripts
4+
Subject: [PATCH 1/8] pytorch_rocm build and package scripts
55

66
Signed-off-by: Mika Laitio <[email protected]>
77
---

patches/rocm-6.1.1/pytorch/0002-show-error-message-if-ROCM_SOURCE_DIR-not-defined.patch

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

66
ROCM_SOURCE_DIR is required by by third_party/kineto module
77
and if it is not set, kineto will not find the

patches/rocm-6.1.1/pytorch/0003-LoadHIP-force-ROCM-detection-and-patches.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 5046c437018a4c32307721657df7f2e8e5fe0404 Mon Sep 17 00:00:00 2001
1+
From bbfb6e70f3e2994766aa12cd11013c9ad17153e4 Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Fri, 10 May 2024 10:32:33 -0700
4-
Subject: [PATCH 3/7] LoadHIP force ROCM detection and patches
4+
Subject: [PATCH 3/8] LoadHIP force ROCM detection and patches
55

66
- set HIP_ROOT_DIR to ROCM_PATH which is set
77
by the build scripts

patches/rocm-6.1.1/pytorch/0004-LoadHIP-lib-and-lib64-search-path-adjustements.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 268f465c7d2b4123aeb50c09c0d92e3f6f8f4478 Mon Sep 17 00:00:00 2001
1+
From 7730d87a24a49f404e18947a7ca2bdf8385fc4fd Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Fri, 10 May 2024 11:11:47 -0700
4-
Subject: [PATCH 4/7] LoadHIP lib and lib64 search path adjustements
4+
Subject: [PATCH 4/8] LoadHIP lib and lib64 search path adjustements
55

66
- search both lib and lib64 directories
77
(note some libs still installed to lib-dir

patches/rocm-6.1.1/pytorch/0005-fix-gcc-parameter-is-null-optimization-error.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 1047827e6b7d8e57e2109e083d553e8efe597624 Mon Sep 17 00:00:00 2001
1+
From 4644c90bcb782da01181a1b620fcd228acd42a5a Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Fri, 10 May 2024 19:25:50 -0700
4-
Subject: [PATCH 5/7] fix gcc parameter is null optimization error
4+
Subject: [PATCH 5/8] fix gcc parameter is null optimization error
55

66
https://github.com/pytorch/pytorch/issues/112089
77
and

patches/rocm-6.1.1/pytorch/0006-cherry-pick-hipify-fix-from-never-version.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From adbb347de92db04c15acfc9d1bd7c3ca62c95f34 Mon Sep 17 00:00:00 2001
1+
From a6bf3a1ab381f48c2596625a8575c99900590c60 Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Tue, 21 May 2024 20:17:36 -0700
4-
Subject: [PATCH 6/7] cherry-pick hipify fix from never version
4+
Subject: [PATCH 6/8] cherry-pick hipify fix from never version
55

66
Signed-off-by: Mika Laitio <[email protected]>
77
---

patches/rocm-6.1.1/pytorch/0007-Maybe-uninitialized-error-fix-for-Fedora-40.patch

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
From 2296735a9e3d8c5062111b95f8ea749e6569b306 Mon Sep 17 00:00:00 2001
1+
From 9c24891bc5fbe9796b35ff3b88ebbdbb3283dcb5 Mon Sep 17 00:00:00 2001
22
From: Mika Laitio <[email protected]>
33
Date: Fri, 31 May 2024 11:34:17 -0700
4-
Subject: [PATCH 7/7] Maybe uninitialized error fix for Fedora 40
4+
Subject: [PATCH 7/8] Maybe uninitialized error fix for Fedora 40
55

66
- Occurs on fbgemm submodule with Fedora 40/gcc 14
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
From 4635e7834d872aedc71e33a4a7784bb3de4515eb Mon Sep 17 00:00:00 2001
2+
From: Mika Laitio <[email protected]>
3+
Date: Fri, 31 May 2024 18:35:12 -0700
4+
Subject: [PATCH 8/8] replace clamp with min and max for fedora 40 issue
5+
6+
Fedora 40/gcc 14 throws following error during build time
7+
for clamp function usage during pytorch build time.
8+
9+
In file included from /usr/lib/gcc/x86_64-redhat-linux/14/../../../../include/c++/14/algorithm:61:
10+
/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
11+
3625 | __glibcxx_assert(!(__hi < __lo));
12+
| ^
13+
/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'
14+
2453 | std::__glibcxx_assert_fail();
15+
| ^
16+
pytorch/aten/src/ATen/native/hip/IndexKernel.hip:254:21: note: called by 'operator()'
17+
254 | qvalue = std::clamp(qvalue, qmin, qmax);
18+
19+
https://github.com/pytorch/pytorch/issues/127666
20+
https://github.com/lamikr/rocm_sdk_builder/issues/12
21+
22+
Signed-off-by: Mika Laitio <[email protected]>
23+
---
24+
aten/src/ATen/native/cuda/IndexKernel.cu | 4 +++-
25+
1 file changed, 3 insertions(+), 1 deletion(-)
26+
27+
diff --git a/aten/src/ATen/native/cuda/IndexKernel.cu b/aten/src/ATen/native/cuda/IndexKernel.cu
28+
index 5682ba27573..862bcb9614d 100644
29+
--- a/aten/src/ATen/native/cuda/IndexKernel.cu
30+
+++ b/aten/src/ATen/native/cuda/IndexKernel.cu
31+
@@ -249,7 +249,9 @@ void index_put_kernel_quantized_cuda(TensorIterator& iter, const IntArrayRef ind
32+
33+
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) {
34+
int64_t qvalue = static_cast<int64_t>(zero_point + nearbyintf(*(float*)in_data * inv_scale));
35+
- qvalue = std::clamp(qvalue, qmin, qmax);
36+
+ int64_t new_max = std::max<int64_t>(qmin, qvalue);
37+
+ qvalue = std::min<int64_t>(qmax, new_max);
38+
+ //qvalue = std::clamp(qvalue, qmin, qmax);
39+
*(scalar_t*)(out_data + offset) = static_cast<scalar_t>(qvalue);
40+
});
41+
});
42+
--
43+
2.45.1
44+

0 commit comments

Comments
 (0)