Skip to content

[ESIMD] Add 'inline' to function decls to fix ODR problems. #3085

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 6 commits into from
Jan 28, 2021

Conversation

kbobrovs
Copy link
Contributor

Fixes "multiple definition" linker errors when multiple sources using ESIMD are linked together.

Signed-off-by: Konstantin S Bobrovsky [email protected]

@@ -466,7 +466,7 @@ __esimd_raw_send_store(uint8_t modifier, uint8_t execSize,

template <typename Ty, int N, int NumBlk, sycl::INTEL::gpu::CacheHint L1H,
sycl::INTEL::gpu::CacheHint L3H>
SYCL_EXTERNAL sycl::INTEL::gpu::vector_type_t<
inline sycl::INTEL::gpu::vector_type_t<
Copy link
Contributor

Choose a reason for hiding this comment

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

With this change, for non-sycl-device build, compiler FE will see one SYCL_EXTERNAL declaration and one inline definition for the same API, while the existing code made it consistent. What is the exact FE rule here, or compiler doesn't have diagnostic for this? Should similar change be made in other files such as esimd_math_intrin.hpp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inline will be seen only by the host compiler, which is really the intent.
Device compiler will continue to see SYCL_EXTERNAL w/o definition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should similar change be made in other files such as esimd_math_intrin.hpp?

Yes. This is achieved by including inline into ESIMD_INLINE used in other files.
Also, SYCL_EXTERNAL is defined to empty string for the host compiler, so void foo followed by inline void foo should be OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had a sync with @kychendev - esimd_math_intrin.hpp should be really fixed, my omission. Will do.

@kbobrovs kbobrovs requested a review from kychendev January 26, 2021 03:00
@kbobrovs
Copy link
Contributor Author

It turns out all the intrinsic functions in esimd_math_intrin.hpp are templated. C++ ODR allows to have multiple definitions for template functions in a program as long as they are not specializations (always full for functions) and appear in different
translation units (+ some more conditions, which are all satisfied in our case). See https://en.cppreference.com/w/cpp/language/definition

One Definition Rule
...
There can be more than one definition in a program of each of the following: class type, enumeration type, inline function, inline variable (since C++17), templated entity (template or member of template, but not full template specialization), as long as all of the following is true:

So there is no need to fix esimd_math_intrin.hpp, even though due to a different reason than I provided before.
@kychendev - please approve if you are OK with this resolution.

@kbobrovs
Copy link
Contributor Author

So there is no need to fix esimd_math_intrin.hpp

actually, some clean-up still would be good - SYCL_EXTERNAL is used for host-only definitions, which does not make sense, albeit harmless. Plus the test has an error, which prevents from correct execution - it is still good for intended purpose, but I'll fix it anyway.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
@kychendev
Copy link
Contributor

@kbobrovs, looks good but there is test error related to unsupported sycl target. Please double check.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
@kbobrovs
Copy link
Contributor Author

@kychendev, all checks now pass

kychendev
kychendev previously approved these changes Jan 27, 2021
@kbobrovs
Copy link
Contributor Author

@bader, please take a look.

@bader
Copy link
Contributor

bader commented Jan 28, 2021

@bader, please take a look.

@kbobrovs, I'm familiar with this code very well, so I think your approval as a code owner should be enough to merge this patch.

bader
bader previously approved these changes Jan 28, 2021
@kbobrovs kbobrovs dismissed stale reviews from bader and kychendev via 9d7fbeb January 28, 2021 18:17
@kbobrovs
Copy link
Contributor Author

@bader, please take a look.

@kbobrovs, I'm familiar with this code very well, so I think your approval as a code owner should be enough to merge this patch.

@bader, right, but in this case I'm also an author. But if you are OK with this, I will merge myself then. Thanks.

Signed-off-by: Konstantin S Bobrovsky <[email protected]>
@bader
Copy link
Contributor

bader commented Jan 28, 2021

But if you are OK with this, I will merge myself then. Thanks.

I suggest adding one more person as a code owner for ESIMD, who is familiar with the code and can do code review for your changes.
I'm okay, but it doesn't count. :-)

@kbobrovs
Copy link
Contributor Author

I suggest adding one more person as a code owner for ESIMD

right, good idea. I created #3114

@kbobrovs
Copy link
Contributor Author

@DenisBakhvalov - could you please review/approve? @kychendev already approved (approval lost due to test re-formatting)

@kbobrovs kbobrovs merged commit 32ca1b9 into intel:sycl Jan 28, 2021
@kbobrovs kbobrovs deleted the esimd-odr branch January 19, 2022 22:51
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.

4 participants