Skip to content

[SYCL][NFC] Optimize getKernelNamesUsingAssert #5196

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 5 commits into from
Dec 27, 2021

Conversation

maksimsab
Copy link
Contributor

Now it traverses reversed call graph by BFS algorithm from
__devicelib_assert_fail function up to SPIR kernels.

Now it traverses reversed call graph by BFS algorithm from
__devicelib_assert_fail function up to SPIR kernels.
@bader bader changed the title [SYCL] optimize getKernelNamesUsingAssert [SYCL][NFC] Optimize getKernelNamesUsingAssert Dec 21, 2021
; Function Attrs: convergent norecurse mustprogress
define weak_odr dso_local spir_kernel void @"_ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel8"() local_unnamed_addr #0 {
call spir_func void @_Z1Gv()
call spir_func void @_Z1Hv()
ret void
}

; CHECK-NOT: _ZTSZZ4mainENK3$_0clERN2cl4sycl7handlerEE7Kernel6
Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that CHECK-NOT is bounded by surrounding CHECK directives. If you want to ensure that some patters is not present in the file at all, then you should use --implicit-check-not

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, today I learnt that implicit-check-not option doesn't work with CHECK-DAG. At least, in a way which I got from documentation.
For example, consider the following inputs:
file:

a
b
c

ll:

; CHECK-DAG: a
; CHECK-DAG: c

If you run FileCheck ll -input-file=./file --implicit-check-not b then you get exit code 0 while I would expect to get non-zero.

Copy link
Contributor

@AlexeySachkov AlexeySachkov Dec 27, 2021

Choose a reason for hiding this comment

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

Unfortunately, today I learnt that implicit-check-not option doesn't work with CHECK-DAG. At least, in a way which I got from documentation.

Yeah, I see it too now.

I did that kernel' names print in a sorted order so that it would be easier to check them with simple CHECK:. You might have an approach better than mine.

We shouldn't be doing extra actions like sorting strings just to make our unit-tests pass. Better solution would be to still work on tests: let's just have two separate FileCheck runs on the same input, but with different prefixes (--check-prefix). The first one will check that expected names are present in the result through CHECK-DAG, the second one will only check that unexpected names are not present in the result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! Done that way.

bader
bader previously approved these changes Dec 22, 2021
Copy link
Contributor

@bader bader left a comment

Choose a reason for hiding this comment

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

LGTM, just one nit.

bader
bader previously approved these changes Dec 22, 2021
@bader
Copy link
Contributor

bader commented Dec 22, 2021

/summary:run

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.

Overall LGTM, but I'm concerned that there could be a couple of corner cases not accounted for, related to function pointers

Comment on lines 385 to 386
const Instruction *I = cast<const Instruction>(U);
const Function *ParentF = I->getFunction();
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 concerned that there could be other uses of function, which are not instructions, but ConstantExpr. To generate such LLVM IR we can try to cast one function pointer type into another before doing a call. There is an example of such LLVM IR in the translator repo

Another concern is that theoretically, an Instruction can be located in module scope, i.e. outside of a function. Therefore, I->getFunction() will return nullptr. There is an example of such LLVM IR in the translator repo as well. Note: I don't have good idea about how to generate such LLVM IR out of a SYCL app if you want to replicate it yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added dyn_cast to CallInst.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that even though you have fixed a nullptr dereference, functionally we still have an issue, i.e. we can say that there are no assert uses whilst there are through more complex usages of function pointers.

That is probably a minor problem at the moment, because function pointers are not widely used, but we should leave a FIXME here, at least, mentioning the use cases we don't analyze properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, there is a kernel empty_kernel in assert-indirect-with-split-2 which checks that traversing doesn't go in such cases.

Kernel's names in tests are sorted so that order of checking
was strictly fixed.
@maksimsab
Copy link
Contributor Author

I did that kernel' names print in a sorted order so that it would be easier to check them with simple CHECK:. You might have an approach better than mine.

@AlexeySachkov
Copy link
Contributor

Two failing tests were fixed about an hour ago in intel/llvm-test-suite#683 and intel/llvm-test-suite#684. Failures were not caused by this patch, but rather by misconfiguration of those tests

@bader bader merged commit f659946 into intel:sycl Dec 27, 2021
@maksimsab maksimsab deleted the optimize_getKernelNamesUsingAssert branch December 7, 2022 15:30
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.

[sycl-post-link] Refactor algorithm that searches for kernels with device assert built-in call in call stack
3 participants