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

Add missing addrspace_operators.ll to kernel #1289

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JayFoxRox
Copy link

@JayFoxRox JayFoxRox commented Aug 29, 2023

Closes #1288

Not sure how this ever worked. The functions that implement this were simply missing. The file was unused.
From what I can tell, this should have affected all platforms?! Is nobody using the CPU devices?

@@ -27,6 +27,7 @@
set(SOURCES_WITH_SLEEF abs.cl
abs_diff.cl
add_sat.cl
addrspace_operators.ll
Copy link
Author

@JayFoxRox JayFoxRox Aug 29, 2023

Choose a reason for hiding this comment

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

I only tested the non-SLEEF version. I also wasn't sure how / where to add this exactly.
This might also have to be part of the generate.rb script. I'd appreciate if someone else could do the SLEEF changes if more changes are necessary.

Copy link
Author

@JayFoxRox JayFoxRox Aug 30, 2023

Choose a reason for hiding this comment

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

Also note that 4500774 explicitly removed more specialized variants of these functions from the "host" backend (but the new solution doesn't appear to work for me / new code isn't running (?): #1288 (comment)).

@@ -29,6 +29,7 @@ acos.cl
acosh.cl
acospi.cl
add_sat.cl
addrspace_operators.ll
Copy link
Author

Choose a reason for hiding this comment

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

Also note the new strategy in 4500774 for SLEEF which may or may not be broken.
I'm also not sure if this file is used in non-"host" backends where it might cause issues now.

@franz
Copy link
Contributor

franz commented Aug 30, 2023

Thanks for the effort, however this won't work as it is. Let me try to explain. As you have noticed, commit 4500774 removed these from lib/kernel/host. In short, the problem is: 1) __to_XYZ are operators, not functions -> Clang doesn't do name mangling on them; 2) you need two versions of each operator to support two different compilation inputs with the CPU driver (SPIR-V and OpenCL C source). In case of SPIR-V you need: ptr addrspace(1) __to_global(ptr addrspace(4) %p); in case of OpenCL C source you need ptr __to_global(ptr %p). This is because the LLVM IR output from SPIR-V translator has pointers with SPIR address space numbers (e.g. global is 1), while the OpenCL C compiled to LLVM IR with Clang has pointer address space numbers of the target (for CPU, all OpenCL address spaces map to zero). Both of these LLVM IR outputs need to be linked with PoCL's builtin library. Since LLVM IR doesn't support having two functions with the same name & different signature in the same bitcode file, we cannot implement the operators in the builtin library. That's why addrspace_operators.ll was removed from lib/kernel/host.

There are multiple solutions (changing SPIRV-translator to output target AS numbers, or having the operators in separate files and linking it separately). But the simplest solution right now, could be to add the triple-underscore names to the f->getName().equals("__to_local")... code block in commit 4500774.

@franz
Copy link
Contributor

franz commented Aug 30, 2023

Actually after re-reading the bugreport, ignore my suggestion about triple-underscore names, they only appear in the .so object files, and with the CPU driver this should never happen. Seems like there's some bug in the code from commit 4500774 and it misses the calls (possibly the remove-inside-loop ?).

@pjaaskel
Copy link
Member

@franz maybe you missed the discussion in #1288?

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.

macOS: Undefined symbols for architecture arm64: [...] "___to_global"
3 participants