Skip to content

[HIP] Add generic address space impl of __spirv_ocl_frexp for HIP backend #5377

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 3 commits into from
Jan 28, 2022

Conversation

FMarno
Copy link
Contributor

@FMarno FMarno commented Jan 24, 2022

This involved manually mangling the namespaces since the default would be address space 5 otherwise.

bader
bader previously approved these changes Jan 24, 2022
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

LGTM, although vector variant implementations are verbose and it would be great to re-use vector functions instead of scalar versions.

Comment on lines 57 to 60
__CLC_GENTYPE_VEC res = (__CLC_GENTYPE_VEC)(__spirv_ocl_frexp(x.s0, &ep_0),
__spirv_ocl_frexp(x.s1, &ep_1),
__spirv_ocl_frexp(x.s2, &ep_2),
__spirv_ocl_frexp(x.s3, &ep_3));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we use VEC_FUNCNAME(2) here? Similar to the existing approach where computation for vector length 2*N done by combining results for vector length N.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that is possible but would it not lead to extra vector being created? For example VEC_FUNCNAME(16) would create a 8 int2, 4 int4, 2 int8 and an int16.

Copy link
Contributor

Choose a reason for hiding this comment

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

VEC_FUNCNAME(16) should create just 2 int8. Currently it creates 16(!) scalar values, so I don't think creating 2 int8 should be a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I think I didn't get your concern right. There should be no overhead on creating vectors. Compiler should generate the same for code for both variants. It's just less code to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, looking at _CLC_V_V_VP_VECTORIZE and modf this also seems to be a fairly common pattern. Thanks!

@bader bader changed the title [HIP] added generic address space impl of __spirv_ocl_frexp for HIP backend [HIP] Add generic address space impl of __spirv_ocl_frexp for HIP backend Jan 25, 2022
@FMarno
Copy link
Contributor Author

FMarno commented Jan 27, 2022

Apologies, I accidentally rebased. It's almost all redone anyway.
@bader I added a new file with a common macro but I'm not sure if I've put it in the correct place or if this needs to be added to the SOURCES file or CMake somewhere, can you please advise.

Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

I'm not sure if I've put it in the correct place or if this needs to be added to the SOURCES file or CMake somewhere, can you please advise.

I suggest we change the file extension from .cl to .h for mangle_common.cl.

According to my understanding SOURCES is used to enable the library binary re-build when sources are changed, so adding new files impacting re-build results is required.
Everything else looks good.

@@ -6,81 +6,104 @@
//
//===----------------------------------------------------------------------===//

#include "mangle_common.cl"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include "mangle_common.cl"
#include "mangle_common.h"

bader
bader previously approved these changes Jan 27, 2022
@FMarno
Copy link
Contributor Author

FMarno commented Jan 27, 2022

I think the problem is that modf and sincos are not inlining. One thing I've notices is that the test seems to have a slightly different ending, "S_" instead of "Dv2_f", which seems to be something to do with compression in Itanium (https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression), caused by the type float2 being using twice. That would also explain why frexp doesn't have the problem, since it have two different argument types. I'll try fixing it in the morning 😄

@FMarno
Copy link
Contributor Author

FMarno commented Jan 28, 2022

Hi @bader,
After my change I reran the test on my local machine and it seems to be inlining now, which is good.

I noticed that modf, sincos and frexp dont work for the half type, but this isn't just limited to the HIP backend.
minimal reproducer:

#include <CL/sycl.hpp>

int main() {
    sycl::half x;
    sycl::modf(sycl::half{1.0}, &x);
    sycl::sincos(sycl::half{1.0}, &x);
    return 0;
}

Is it ok if open an issue for this?

@bader
Copy link
Contributor

bader commented Jan 28, 2022

Is it ok if open an issue for this?

Yes. Please, file a bug report.

@FMarno
Copy link
Contributor Author

FMarno commented Jan 28, 2022

Bug reported here: #5418

@bader bader merged commit 513691d into intel:sycl Jan 28, 2022
@FMarno FMarno deleted the finlay/frexp_mangle branch January 31, 2022 10:14
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.

2 participants