-
Notifications
You must be signed in to change notification settings - Fork 86
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
[Loops] Adds occa::forLoop #465
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dmed256
force-pushed
the
loops/adds-for-loop
branch
from
January 20, 2021 23:43
fac6ac3
to
fc0c80c
Compare
Codecov Report
@@ Coverage Diff @@
## main #465 +/- ##
==========================================
+ Coverage 75.25% 75.36% +0.11%
==========================================
Files 254 260 +6
Lines 19396 19605 +209
==========================================
+ Hits 14596 14775 +179
- Misses 4800 4830 +30
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Similar to
occa::array
,occa::forLoop
allows us to build for-loop kernels inline. This allows injecting arguments along with adding compile-time defines.Iterators
.outer()
and.inner()
support 1, 2, or 3 arguments which can be of types:int N
which generates a loop between[0, N)
occa::range
which generates a loop given the rangestart
,end
, andstep
definitionocca::array<int>
which iterates through the indices of the arrayFor-loop body
Based on the
.outer
and.inner
argument counts, the for-loop body will expect a lambda with the proper typesA few examples:
.outer(N)
->[=](const int outerIndex) -> void {}
.outer(N, N)
->[=](const int2 outerIndex) -> void {}
.outer(N, N).inner(N)
->[=](const int2 outerIndex, const int innerIndex) -> void {}
.outer(N).inner(N, N)
->[=](const int outerIndex, const int2 innerIndex) -> void {}
If the input types don't correspond with the
.outer().inner()
definitions, the compiler will complain:@.outer-only loops
The use of
@shared
memory can be crucial for some implementations. Because of this, we easily support@shared
memory by automating only the@outer
loop generation and leaving the@inner
loop implementations to the user.Note the weird usage of
OKL("...");
. This is used to inject source-code due to compiler restrictions:OKL(<source-code>)
can be used to bypass this issue. This is useful to setup directives, such as#if
/#endif
.TODOs
Handle
const
on scope injected arguments properlyHandle
occa::int#
in OKL to avoid having to useResolves #462