-
Notifications
You must be signed in to change notification settings - Fork 222
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
Add support for SPV_INTEL_usm_storage_classes extension #579
Conversation
The error:
which I don't really understand from where it comes. Would appreciate any kind of hint. |
@MrSidims This error is produced by |
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. |
I have disabled spirv-val for now. But may be we will reconsider the specification. |
@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. |
There was a problem hiding this 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
lib/SPIRV/SPIRVReader.cpp
Outdated
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() && |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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
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 |
15c8347
to
1b33fbf
Compare
We have changed the extension, adding two more instructions. |
9aaa840
to
b37fac3
Compare
There was a problem hiding this 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/SPIRVReader.cpp
Outdated
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() && |
There was a problem hiding this comment.
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
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; | ||
} |
There was a problem hiding this comment.
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.
The commit message should be updated. Also it would be great if you squash your commits. Thanks. |
68238d1
to
5407c12
Compare
There was a problem hiding this 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]>
5407c12
to
6d7c946
Compare
Okay, thank you and @AlexeySachkov for the review! |
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]