Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Commits
daebbce1
There was an error fetching the commit references. Please try again later.
Commit
daebbce1
authored
5 years ago
by
Jakub Klinkovský
Browse files
Options
Downloads
Patches
Plain Diff
Fixed StaticFor for loops with a large iterations count
parent
55ded6ad
No related branches found
No related tags found
1 merge request
!18
NDArray
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/TNL/StaticFor.h
+35
-13
35 additions, 13 deletions
src/TNL/StaticFor.h
with
35 additions
and
13 deletions
src/TNL/StaticFor.h
+
35
−
13
View file @
daebbce1
...
...
@@ -14,25 +14,47 @@
namespace
TNL
{
// Manual unrolling does not make sense for loops with a large iterations
// count. For a very large iterations count it would trigger the compiler's
// limit on recursive template instantiation. Also note that the compiler
// will (at least partially) unroll loops with static bounds anyway.
template
<
int
Begin
,
int
End
,
bool
unrolled
=
(
End
-
Begin
<=
8
)
>
struct
StaticFor
;
template
<
int
Begin
,
int
End
>
struct
StaticFor
struct
StaticFor
<
Begin
,
End
,
true
>
{
template
<
typename
Function
,
typename
...
Args
>
__cuda_callable__
static
void
exec
(
const
Function
&
f
,
Args
...
args
)
{
static_assert
(
Begin
<
End
,
"Wrong index interval for StaticFor. Being must be lower than end."
);
f
(
Begin
,
args
...
);
StaticFor
<
Begin
+
1
,
End
>::
exec
(
f
,
args
...
);
};
static_assert
(
Begin
<
End
,
"Wrong index interval for StaticFor. Begin must be less than end."
);
template
<
typename
Function
,
typename
...
Args
>
__cuda_callable__
static
void
exec
(
const
Function
&
f
,
Args
...
args
)
{
f
(
Begin
,
args
...
);
StaticFor
<
Begin
+
1
,
End
>::
exec
(
f
,
args
...
);
}
};
template
<
int
End
>
struct
StaticFor
<
End
,
End
>
struct
StaticFor
<
End
,
End
,
true
>
{
template
<
typename
Function
,
typename
...
Args
>
__cuda_callable__
static
void
exec
(
const
Function
&
f
,
Args
...
args
){};
template
<
typename
Function
,
typename
...
Args
>
__cuda_callable__
static
void
exec
(
const
Function
&
f
,
Args
...
args
)
{}
};
template
<
int
Begin
,
int
End
>
struct
StaticFor
<
Begin
,
End
,
false
>
{
static_assert
(
Begin
<=
End
,
"Wrong index interval for StaticFor. Begin must be less than or equal to end."
);
template
<
typename
Function
,
typename
...
Args
>
__cuda_callable__
static
void
exec
(
const
Function
&
f
,
Args
...
args
)
{
for
(
int
i
=
Begin
;
i
<
End
;
i
++
)
f
(
i
,
args
...
);
}
};
}
//namespace TNL
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment