Skip to content
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

Fix build issues for musl libc (#267) #268

Open
wants to merge 4 commits into
base: amd-staging
Choose a base branch
from

Conversation

AngryLoki
Copy link
Contributor

@AngryLoki AngryLoki commented Dec 15, 2024

This fixes few issues, which allow to build and pass kfdtest on musl-based systems:

Issues with libhsakmt:

  1. result of daad183#diff-681b7d40f71f20573413d5072e1c381fde6c02aed03a56307afcbe82cf3f5e5eR36-R37f - extern int hsakmt_page_shift is under ifndef, while it should not.
openclose.c:117:9: error: 'hsakmt_page_size' undeclared (first use in this function); did you mean 'hsakmt_page_shift'?
  117 |         hsakmt_page_size = sysconf(_SC_PAGESIZE);
      |         ^~~~~~~~~~~~~~~~
      |         hsakmt_page_shift
  1. warning of PAGE_SIZE macro redefinition (defined previously in limits.h)

  2. no operator to compare 0 with std::nullptr_t (NULL is defined as nullptr_t-typed value, following support.types.nullptr)

.../libhsakmt/tests/kfdtest/gtest-1.6.0/gtest/gtest.h: In instantiation of 'testing::AssertionResult testing::internal::CmpHelperNE(const char*, const char*, const T1&, const T2&) [with T1 = long unsigned int; T2 = std::nullptr_t]':
.../libhsakmt/tests/kfdtest/src/KFDTestUtilQueue.cpp:60:29:   required from here
19072 |   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
      |                            ^
.../libhsakmt/tests/kfdtest/gtest-1.6.0/gtest/gtest.h:18573:28: error: invalid operands of types 'const long unsigned int' and 'std::nullptr_t' to binary 'operator!='
18573 | GTEST_IMPL_CMP_HELPER_(NE, !=);
      |                            ^

Issues with hsa-runtime:

Attempt to fix issues with missing symbols pthread_attr_setaffinity_np and pthread_rwlockattr_setkind was done earlier, but suggested patch was reworked and partially reverted in 1cee865.

  1. reverted commit checked if pthread_attr_setaffinity_np symbol exists, but this check did not work (and effectively disabled better path), because this function requires #define _GNU_SOURCE (see https://man7.org/linux/man-pages/man3/pthread_attr_setaffinity_np.3.html)

  2. non-reverted part implied that pthread_rwlockattr_setkind function replaces pthread_rwlockattr_setkind_np, which is incorrect. This function is non-portable, PTHREAD_RWLOCK_PREFER_WRITER_NP serves as a hint and has no alternatives.

Closes: #267

This fixes few issues, which allow to build and pass kfdtest on musl-based systems:

1) result of ROCm@daad183#diff-681b7d40f71f20573413d5072e1c381fde6c02aed03a56307afcbe82cf3f5e5eR36-R37f - `extern int hsakmt_page_shift` is under `ifndef`, while it should not
```
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/src/openclose.c: In function 'init_page_size':
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/src/openclose.c:117:9: error: 'hsakmt_page_size' undeclared (first use in this function); did you mean 'hsakmt_page_shift'?
  117 |         hsakmt_page_size = sysconf(_SC_PAGESIZE);
      |         ^~~~~~~~~~~~~~~~
      |         hsakmt_page_shift
```

2) warning of `PAGE_SIZE` macro redefinition (defined previously in `limits.h`)

3) no operator to compare 0 with std::nullptr_t (null is defined as nullptr_t, following https://eel.is/c++draft/support.types.nullptr)
```
In file included from /var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/src/KFDTestUtil.hpp:27,
                 from /var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/src/BaseQueue.hpp:28,
                 from /var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/src/SDMAQueue.hpp:27,
                 from /var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/src/KFDTestUtilQueue.cpp:28:
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/gtest-1.6.0/gtest/gtest.h: In instantiation of 'testing::AssertionResult testing::internal::CmpHelperNE(const char*, const char*, const T1&, const T2&) [with T1 = long unsigned int; T2 = std::nullptr_t]':
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/src/KFDTestUtilQueue.cpp:60:29:   required from here
19072 |   GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2),\
      |                            ^
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/gtest-1.6.0/gtest/gtest.h:18573:28: error: invalid operands of types 'const long unsigned int' and 'std::nullptr_t' to binary 'operator!='
18573 | GTEST_IMPL_CMP_HELPER_(NE, !=);
      |                            ^
/var/tmp/portage/dev-libs/roct-thunk-interface-6.3.0/work/ROCR-Runtime-rocm-6.3.0/libhsakmt/tests/kfdtest/gtest-1.6.0/gtest/gtest.h:18558:12: note: in definition of macro 'GTEST_IMPL_CMP_HELPER_'
18558 |   if (val1 op val2) {\
      |            ^~
```

Closes: ROCm#267
Signed-off-by: Sv. Lockal <[email protected]>
This commit applies a similar change, that was reverted in 1cee865, with major issues fixed.

1) reverted commit checked if `pthread_attr_setaffinity_np` symbol exists, but this check did not work (and effectively disabled better path), because this symbol requires `#define _GNU_SOURCE` (see https://man7.org/linux/man-pages/man3/pthread_attr_setaffinity_np.3.html)

2) non-reverted part implied that `pthread_rwlockattr_setkind` function replaces `pthread_rwlockattr_setkind_np`, which is incorrect. This function is non-portable, serves as a hint and has no alternatives.

Signed-off-by: Sv. Lockal <[email protected]>
The macro NULL sometimes is defined as 0, sometimes as nullptr_t-typed value (following [support.types.nullptr]), so to compare with pointers without warnings nullptr should be used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This portion should be covered by 09d789c , right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block was intentional. If we have to pick one or the other, we want them to align. If PAGE_SIZE isn't defined, but PAGE_SHIFT=5000 , then setting just PAGE_SIZE=1<<12 won't really work.

@dayatsin-amd
Copy link
Collaborator

!verify full

@dayatsin-amd
Copy link
Collaborator

!verify

@dayatsin-amd
Copy link
Collaborator

!verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue]: musl build issues in rocm-6.3.0 release
4 participants