Skip to content

[SYCL][PI] get backend type from Plugin, not env #1477

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

Closed
wants to merge 1 commit into from

Conversation

hiaselhans
Copy link
Contributor

useBackend queried for "SYCL_BE" env. scheduler wrongly relied on this.
Instead it should get the backend type from the used plugin

Signed-off-by: hiaselhans simon.klemenc@gmail.com

This PR is adressing #1473 which i was experiencing as well.
It is just an idea how it could work, maybe it could be solved more elegant by making the enum extendible or so. There are still some "useBackend" left in USM code which i think we should get rid of aswel. that function just checks for the SYCL_BE env variable which does not garuantee that this plugin is actually used.

useBackend queried for "SYCL_BE" env. scheduler wrongly relied on this.
Instead it should get the backend type from the used plugin

Signed-off-by: hiaselhans <simon.klemenc@gmail.com>
@hiaselhans
Copy link
Contributor Author

hiaselhans commented Apr 4, 2020

oh, and i found that that usm code is gone as well with #1474
:)

Copy link
Contributor

@Ruyk Ruyk left a comment

Choose a reason for hiding this comment

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

Some minor changes re:interface, thanks for the fix.
Is this fixing any particular bug you have encountered?

@@ -60,6 +60,10 @@ using pi_uint64 = uint64_t;
using pi_bool = pi_uint32;
using pi_bitfield = pi_uint64;

// For selection of SYCL RT back-end, now manually through the "SYCL_BE"
// environment variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the comment still apply? The environmental variable is not used anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, i will remove it. i just took the part from pi.hpp to get feedback on this

@@ -31,6 +31,10 @@ class plugin {

const RT::PiPlugin &getPiPlugin() const { return MPlugin; }

bool isBackendType(Backend backend) const {
return MPlugin.backend == backend;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems awkward to have a comparison method inside a plugin, why not simply return the Plugin type and let the caller do the comparison?
Simply have a

Backend getBackendType() const noexcept {
   return MPlugin.backend;
}

Copy link
Contributor

@smaslov-intel smaslov-intel Apr 6, 2020

Choose a reason for hiding this comment

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

+1 for returning the Backend.

Also we need this info be available externally. Could you add a method to return the BE via, say

platform.get_info<info::platform::backend>

?

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 sure. Actually, as I'm at it already, maybe there is a more agnostic way than to have the plugin types hard-coded in an enum in "pi.h"?

what if - for example - there was a char* backend which we can return as std::string getBackendType() and std::string platform.get_info<>? Then the plugin interface stays a bit more general and we would compare ContextImpl->getPlugin()->getBackendType() == "OpenCL"

On the other hand i found this: Sycl-Shared and they describe to even have an enum at sycl::backend to compare with...

Copy link
Contributor

Choose a reason for hiding this comment

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

have an enum at sycl::backend
That's right. It is coming very soon in this PR:
https://github.com/intel/llvm/pull/1332/files#diff-f42957493751abda949e943bbb84b93d
Let's use it in these interfaces.

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, thanks. Then I'll wait for that PR to be merged and base off it.

regarding the platform.get_info<> it should return an std::string in the end...?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should return the "backend" not a string. But note that the BE generalization proposal defines get_backend() method instead (maybe in addition?): https://github.com/KhronosGroup/SYCL-Shared/blob/master/proposals/sycl_generalization.md

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on returning the backend, not a string.

We don't have a get_info query for backends on the generalization proposal, but can be easily added if that is useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, sure. thanks. i will stick to whats in the generalization for now.

// Returns the backend to which this platform belongs
backend get_backend() const noexcept;

i will wait for #1332 to be merged and start from there.

// OpenCL 2.1 and greater require clCreateProgramWithIL
if (pi::useBackend(pi::SYCL_BE_PI_OPENCL) &&
if (ContextImpl->getPlugin().isBackendType(Backend::SYCL_BE_PI_OPENCL) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be instead:

ContextImpl->getPlugin()->getBackend() == Backend::SYCL_BE_PI_OPENCL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as above, getBackendType ? if you prefer, i will do that :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say getBackend is enough, since the return type encodes what the type is (a Backend)

@@ -1661,7 +1661,7 @@ cl_int ExecCGCommand::enqueueImp() {
Requirement *Req = (Requirement *)(Arg.MPtr);
AllocaCommandBase *AllocaCmd = getAllocaForReq(Req);
RT::PiMem MemArg = (RT::PiMem)AllocaCmd->getMemAllocation();
if (RT::useBackend(pi::Backend::SYCL_BE_PI_OPENCL)) {
if (Plugin.isBackendType(Backend::SYCL_BE_PI_OPENCL)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above...

@hiaselhans
Copy link
Contributor Author

thanks for the review @Ruyk ,
actually this does fix #1473 . especially the change in scheduler, which i guess didn't come up in the tests because there SYCL_BE is set.

@hiaselhans
Copy link
Contributor Author

I am now closing this and wait for #1332 and #1490 to be merged.
Those should make this pr obsolete and solve #1473

@hiaselhans hiaselhans closed this Apr 8, 2020
dwoodwor-intel pushed a commit to dwoodwor-intel/llvm that referenced this pull request Jun 10, 2022
The centerpiece of this patch is the addition of getParameterTypes function,
which will parse out the pointee struct types using LLVM's built-in Itanium
demangling interface (which is unfortunately not easy to use). Passing this
information along via llvm StructTypes was chosen to minimize the impact of
this change on caller code; it is likely that a future cleanup patch to use
an enum or similar mechanism to represent possible SPIR-V struct types would
be advisable.

A side effect of this change is that several helper methods that query
pointer element types can be eliminated, which does lead to some cleanup that
got tangled up in the demangler-enabling work.

Extra function calls to getPointerElementType() are temporarily added to
disentangle this patch from work moving OCLTypeToSPIRV to store pointee types
rather than pointer types; this will likely be fixed as part of the effort to
get SPIRVWriter working with opaque pointer types.

Original commit:
KhronosGroup/SPIRV-LLVM-Translator@76e181e
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.

3 participants