Skip to content

[sycl-post-link] Add property with the default values of specialization constants #3666

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 17 commits into from
May 27, 2021

Conversation

vmaksimo
Copy link
Contributor

This patch introduces a new property which contains all the defaults for spec
constants.
It is done by setting of metadata with the default values:

; Compilation line:
; sycl-post-link -spec-const=default -S llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020.ll -o property.table
!5 = !{i32 42}
!6 = !{%struct.ComposConst { i32 1, double 2.000000e+00, %struct.myConst { i32 13, float 0x4020666660000000 } }}

Property set looks this way:

[SYCL/specialization constants default values]
all=2|gAAAAAAAAAgKAAAA

…on constants

This patch introduces a new property which contains all the defaults for spec
constants.
It is done by setting of metadata with the default values:
```
; Compilation line:
; sycl-post-link -spec-const=default -S llvm/test/tools/sycl-post-link/spec-constants/SYCL-2020.ll -o property.table
!5 = !{i32 42}
!6 = !{%struct.ComposConst { i32 1, double 2.000000e+00, %struct.myConst { i32 13, float 0x4020666660000000 } }}

```

Property set looks this way:
```
[SYCL/specialization constants default values]
all=2|gAAAAAAAAAgKAAAA
```
@vmaksimo vmaksimo requested a review from AlexeySachkov April 30, 2021 16:43
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.

Partial review

Comment on lines 349 to 350
Offset += Ty->getPrimitiveSizeInBits() / 8 +
(Ty->getPrimitiveSizeInBits() % 8 != 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you are appending to a vector and not inserting into a pre-allocated vector, you probably don't need this argument 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.

Offset argument is actually used for calculations in StructTy - it helps to fill the buffer with the correct alignment:
https://github.com/intel/llvm/pull/3666/files#diff-f9a582625f70ea58ef88b7713c591e8187629cca507b424557a3e4664e23848fR308-R312

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.

And the rest of the review

@vmaksimo vmaksimo marked this pull request as ready for review May 5, 2021 16:48
@vmaksimo vmaksimo requested review from kbobrovs, mlychkov, smaslov-intel and a team as code owners May 5, 2021 16:48
/// Recursively iterates over a composite type in order to collect information
/// about default values of its scalar elements.
void collectCompositeElementsDefaultValuesRecursive(
const Module &M, Constant *C, unsigned &Offset,
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: processing of composite spec constants is similar in this function, emitSpecConstantRecursiveImpl and generateSpecConstDefaultValueMetadata. Could be factored out using e.g. the visitor pattern. At least a TODO for now would be good.

// default value of corresponding specialization constant.
DefaultValue = Initializer->getAggregateElement(0u);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what GV == 0 means? please add a comment or handle

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we should just use cast instead of dyn_cast and always expect to see a value there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can meet nullptr instead of value here - this check is still needed. I left a comment above the if-.

@vmaksimo vmaksimo requested review from kbobrovs and AlexeySachkov May 7, 2021 17:06
/// Recursively iterates over a composite type in order to collect information
/// about default values of its scalar elements.
/// TODO: processing of composite spec constants here is similar to
/// collectCompositeElementsInfoRecursive. Possible place for improvement -
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it also similar to emitSpecConstantRecursiveImpl and generateSpecConstDefaultValueMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, it doesn't look similar. generateSpecConstDefaultValueMetadata is not related to recursive methods, and emitSpecConstantRecursiveImpl is too different from this function.

Copy link
Contributor

@kbobrovs kbobrovs left a comment

Choose a reason for hiding this comment

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

added few comments

// default value of corresponding specialization constant.
DefaultValue = Initializer->getAggregateElement(0u);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we should just use cast instead of dyn_cast and always expect to see a value there.

AlexeySachkov
AlexeySachkov previously approved these changes May 11, 2021
alexbatashev
alexbatashev previously approved these changes May 11, 2021
Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

RT changes look good

AlexeySachkov
AlexeySachkov previously approved these changes May 11, 2021
@bader
Copy link
Contributor

bader commented May 13, 2021

@kbobrovs, ping.

kbobrovs
kbobrovs previously approved these changes May 17, 2021
@vmaksimo vmaksimo dismissed stale reviews from kbobrovs, AlexeySachkov, and alexbatashev via a5cbe74 May 18, 2021 09:11
AlexeySachkov
AlexeySachkov previously approved these changes May 18, 2021
vmaksimo added 2 commits May 24, 2021 14:32
…binaries

DefaultValues.DefaultValuesAreSet and DefaultValues.DefaultValuesAreOverriden
tests only support JIT which is not the case for the default values.

Once AOT binaries support is added, the tests can be enabled back.
@vmaksimo vmaksimo force-pushed the spec_const_property_defaults branch from 57f8fbd to 02293fb Compare May 24, 2021 11:32
@@ -256,7 +256,7 @@ class device_image_impl {
// supposed to be called from c'tor.
MSpecConstSymMap[std::string{SCName}].push_back(
SpecConstDescT{/*ID*/ It[0], /*CompositeOffset*/ It[1],
/*Size*/ It[2], BlobOffset, HasDefaultValues});
/*Size*/ It[2], BlobOffset});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit concerned that this change is being committed in scope of this PR. The PR title says that this is a modification of sycl-post-link tool and all 13 commits are very likely to be squashed into a single one during the merge - we will end up with a commit to sycl-post-link, which modifies DPC++ RT.

Moreover, it is not clear to me why this change is needed at all. From my point of view it is better if we submit it in a separate PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Tagging @dm-vodopyanov here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is related to https://github.com/intel/llvm/pull/3667/files#r631154823. I'll create a separate PR to make it clear.

@@ -201,11 +201,21 @@ class PropertySetRegistry {
PropSet.insert(std::make_pair(Prop.first, PropertyValue(Prop.second)));
}

template <typename T>
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Please add a comment when this function should be used instead of void add(StringRef Category, const std::map<StringRef, T> &Props) above. I.e. when the order of properties matters.
  • Suggest to make add templated on the map type to have single implementation for both std::map<StringRef, T> and std::map<StringRef, T>

vmaksimo added a commit that referenced this pull request May 25, 2021
Remove backward compatibility according to discussion:
https://github.com/intel/llvm/pull/3667/files#r631154823i

This patch is expected to be merged together or before
#3666
kbobrovs
kbobrovs previously approved these changes May 25, 2021
@vmaksimo vmaksimo requested a review from kbobrovs May 26, 2021 16:50
@romanovvlad romanovvlad merged commit 7d5ee05 into intel:sycl May 27, 2021
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.

6 participants