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 support for SPV_INTEL_usm_storage_classes extension #579

Merged

Conversation

MrSidims
Copy link
Contributor

@MrSidims MrSidims commented Jun 9, 2020

With this extension 2 new Storage Classes are introduced:
DeviceOnlyINTEL and HostOnlyINTEL appropriately mapped on
global_device and global_host SYCL/OpenCL address spaces which
are part of SYCL_INTEL_usm_address_spaces extension.

Spec: intel/llvm#1840

Co-authored-by: Viktoria Maksimova [email protected]

Signed-off-by: Dmitry Sidorov [email protected]
Signed-off-by: Viktoria Maksimova [email protected]

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 9, 2020

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 9, 2020

The error:

error: line 138: Expected input to have storage class Generic: GenericCastToPtr
%59 = OpGenericCastToPtr %_ptr_CrossWorkgroup_uint %58

which I don't really understand from where it comes. Would appreciate any kind of hint.

@vmaksimo
Copy link
Contributor

vmaksimo commented Jun 9, 2020

The error:

error: line 138: Expected input to have storage class Generic: GenericCastToPtr
%59 = OpGenericCastToPtr %_ptr_CrossWorkgroup_uint %58

which I don't really understand from where it comes. Would appreciate any kind of hint.

@MrSidims This error is produced by spirv-val. It doesn't fail locally if you don't have it in the PATH variable

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 9, 2020

The error:

error: line 138: Expected input to have storage class Generic: GenericCastToPtr
%59 = OpGenericCastToPtr %_ptr_CrossWorkgroup_uint %58

which I don't really understand from where it comes. Would appreciate any kind of hint.

@MrSidims This error is produced by spirv-val. It doesn't fail locally if you don't have it in the PATH variable

Got it, thanks! The reasons is that spirv-val tools checks that GenericCastToPtr has input of Generic storage type, while in the extension we allows an input of CrossWorkgroup storage class in case if it's being casted to Device/Host.

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 9, 2020

I have disabled spirv-val for now. But may be we will reconsider the specification.

@MrSidims
Copy link
Contributor Author

MrSidims commented Jun 9, 2020

@svenvh @AlexeySotkin can I ask your opinion of changing rules for already existing instructions GenericCastToPtr and PtrCastToGeneric (under the extension) and if it's possible to upstream the changes to spirv-val tool? If it's not OK we can just implement new instructions to reflect desired address space casts in SPIR-V.

Copy link
Contributor

@AlexeySachkov AlexeySachkov left a comment

Choose a reason for hiding this comment

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

A few question prior proper detailed review

SPIRSPIRVAddrSpaceMap::rmap(T->getPointerStorageClass());
// If generation of SYCL USM address spaces isn't allowed in the reversed
// translation - transform them into global address space
if (!BM->isUsmAddrspacesEnabled() &&
Copy link
Contributor

@AlexeySachkov AlexeySachkov Jun 9, 2020

Choose a reason for hiding this comment

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

What is the reason to add this option? I mean, new storage classes enable USMStorageClassesINTEL capability in the module and it is responsibility of the particular consumer to either reject SPIR-V with such capability as unsupported or accept new storage classes, which can be done by lowering them to whichever address spaces or to anything else what is desired by the consumer.

So, the generator is responsible to either generate more portable SPIR-V, which doesn't use the extension, or generate less portable SPIR-V, which uses the extension, but cannot be supplied to any consumer (because of lack of the extension support).

If consumer is aware of that option, it means that it is aware of that extension and therefore, it could perform desired lowering by itself and code in the translator would be simpler.

I do understand that some projects are using the translator as SPIR-V consumer as well and this option allows to simplify their code, but it would be good if such customizations are not unique to a single consumer/backend/vendor and we don't end up with bunch of tweaks in the translator for each particular backend.

P.S. This is just my vision and it might be wrong. Probably it is not such a problem to have some consumer part customizations not in the actual SPIR-V consumers, but here, in the translator. It would be good to hear feedback from someone else

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In general I don't see such customization as a big problem, we have here in the translator different flows for OpenCL 2.0 and OpenCL 1.2, right? Yet I see your point and understand it. Would also love to here other opinions.

(The story below isn't valuable for SPIR-V to LLVM IR translator project at all, but I want you to see the logic, why this option was added).
This option came from (surprise-surprise) some implementation details of SYCL compiler's driver and desire to make the feature adoptable not only for FPGA, but for other targets in JIT compilation (aka with triple spirv-unknown-unknown for which we add spirv-ext=+all option.

Copy link
Contributor

Choose a reason for hiding this comment

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

we have here in the translator different flows for OpenCL 2.0 and OpenCL 1.2, right?

This is for sure shared between several vendors

This option came from (surprise-surprise) some implementation details of SYCL compiler's driver and desire to make the feature adoptable not only for FPGA, but for other targets in JIT compilation (aka with triple spirv-unknown-unknown for which we add spirv-ext=+all option.

This is exactly what I'm talking about: device-/vendor-specific consumption rules are being moved into the translator. I think it is okay to outline common parts into the translator, but at the same time I wouldn't like to see bunch of vendor-specific options in this repo.

I don't have strong objections at this point: probably we can add this option as a first example and when we have the second one we can see how this can be generalized, where it goes to and how does it look like

Copy link
Contributor

Choose a reason for hiding this comment

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

A SPIR-V module declares capabilities, i.e. features which are used in the module. A client API environment (aka target environment) should check capabilities declared in the module against capabilities it supports. If the client API doesn't support a capability declared in the module it's "allowed to reject the module."
The EnableUsmAddrspaces option looks like we are trying adapt a SPIR-V module with USMStorageClassesINTEL capability for client API(device) which doesn't support that capability. IMO a client API should either support the capability or reject the module.
I agree with @AlexeySachkov, we should not move device specific logic into the translator.

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. Do you have any comments other than this one?

lib/SPIRV/SPIRVInternal.h Outdated Show resolved Hide resolved
@AlexeySachkov
Copy link
Contributor

@svenvh @AlexeySotkin can I ask your opinion of changing rules for already existing instructions GenericCastToPtr and PtrCastToGeneric (under the extension)

This is probably question not to the translator, but to the SPIR-V core and extension specs maintainers, i.e. what is better for extension: define new instruction or change semantic of an existing one? I guess there is no single answer to that and it should be decided case by case

and if it's possible to upstream the changes to spirv-val tool?

Again, this is probably question not for the translator, but for KhronosGroup/SPIRV-Tools. AFAIK, if you have your extension published in KhronosGroup/SPIRV-Headers there should be no problem with extending spirv-val with support for a new extension. I remember @bashbaug advised me to do so several times

@MrSidims MrSidims force-pushed the private/MrSidims/USMStorageClasses branch from 15c8347 to 1b33fbf Compare June 18, 2020 20:42
@MrSidims
Copy link
Contributor Author

@svenvh @AlexeySotkin can I ask your opinion of changing rules for already existing instructions GenericCastToPtr and PtrCastToGeneric (under the extension) and if it's possible to upstream the changes to spirv-val tool? If it's not OK we can just implement new instructions to reflect desired address space casts in SPIR-V.

We have changed the extension, adding two more instructions.

@MrSidims MrSidims requested a review from AlexeySachkov June 19, 2020 12:12
@MrSidims MrSidims force-pushed the private/MrSidims/USMStorageClasses branch from 9aaa840 to b37fac3 Compare June 22, 2020 06:54
lib/SPIRV/SPIRVWriter.cpp Outdated Show resolved Hide resolved
@MrSidims
Copy link
Contributor Author

@AlexeySotkin @AlexeySachkov ping

Copy link
Contributor

@AlexeySachkov AlexeySachkov left a comment

Choose a reason for hiding this comment

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

A few minor comments, LGTM overall.

I'm still not convinced that new option is actually needed, but I don't have strong objections against it either. Would be good to hear feedback from @AlexeySotkin and @svenvh

lib/SPIRV/SPIRVWriter.cpp Outdated Show resolved Hide resolved
lib/SPIRV/libSPIRV/SPIRVInstruction.h Show resolved Hide resolved
lib/SPIRV/libSPIRV/SPIRVModule.h Outdated Show resolved Hide resolved
SPIRSPIRVAddrSpaceMap::rmap(T->getPointerStorageClass());
// If generation of SYCL USM address spaces isn't allowed in the reversed
// translation - transform them into global address space
if (!BM->isUsmAddrspacesEnabled() &&
Copy link
Contributor

Choose a reason for hiding this comment

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

we have here in the translator different flows for OpenCL 2.0 and OpenCL 1.2, right?

This is for sure shared between several vendors

This option came from (surprise-surprise) some implementation details of SYCL compiler's driver and desire to make the feature adoptable not only for FPGA, but for other targets in JIT compilation (aka with triple spirv-unknown-unknown for which we add spirv-ext=+all option.

This is exactly what I'm talking about: device-/vendor-specific consumption rules are being moved into the translator. I think it is okay to outline common parts into the translator, but at the same time I wouldn't like to see bunch of vendor-specific options in this repo.

I don't have strong objections at this point: probably we can add this option as a first example and when we have the second one we can see how this can be generalized, where it goes to and how does it look like

Comment on lines +778 to +789
assert(
(DestAddrSpace == SPIRAS_Global || DestAddrSpace == SPIRAS_Generic) &&
"Casts from global_device/global_host only allowed to \
global/generic");
if (!BM->isAllowedToUseExtension(
ExtensionID::SPV_INTEL_usm_storage_classes)) {
if (DestAddrSpace == SPIRAS_Global)
return nullptr;
BOC = OpPtrCastToGeneric;
} else {
BOC = OpPtrCastToCrossWorkgroupINTEL;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: this probably can (but not necessarily) be factored out to a function or lambda.

@AlexeySotkin
Copy link
Contributor

The commit message should be updated. Also it would be great if you squash your commits. Thanks.

@MrSidims MrSidims force-pushed the private/MrSidims/USMStorageClasses branch from 68238d1 to 5407c12 Compare June 25, 2020 13:08
Copy link
Contributor

@AlexeySotkin AlexeySotkin left a comment

Choose a reason for hiding this comment

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

I'd remove the second paragraph of the commit message.
Other than that, LGTM. Thanks!

With this extension 2 new Storage Classes are introduced:
DeviceOnlyINTEL and HostOnlyINTEL appropriately mapped on
global_device and global_host SYCL/OpenCL address spaces which
are part of SYCL_INTEL_usm_address_spaces extension.

Co-authored-by: Viktoria Maksimova <[email protected]>

Signed-off-by: Dmitry Sidorov <[email protected]>
Signed-off-by: Viktoria Maksimova <[email protected]>
@MrSidims MrSidims force-pushed the private/MrSidims/USMStorageClasses branch from 5407c12 to 6d7c946 Compare June 25, 2020 15:04
@MrSidims
Copy link
Contributor Author

I'd remove the second paragraph of the commit message.
Other than that, LGTM. Thanks!

Okay, thank you and @AlexeySachkov for the review!

@AlexeySotkin AlexeySotkin merged commit d8dd6f4 into KhronosGroup:master Jun 26, 2020
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.

5 participants