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
ffc00260
There was an error fetching the commit references. Please try again later.
Commit
ffc00260
authored
6 years ago
by
Jakub Klinkovský
Committed by
Jakub Klinkovský
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
NDArray: simplified executors for operations
parent
f6d08f4b
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/Containers/ndarray/Operations.h
+36
-78
36 additions, 78 deletions
src/TNL/Containers/ndarray/Operations.h
with
36 additions
and
78 deletions
src/TNL/Containers/ndarray/Operations.h
+
36
−
78
View file @
ffc00260
...
...
@@ -90,86 +90,29 @@ struct SequentialExecutorRTL< Array, IndexTag< 0 > >
template
<
typename
Array
,
typename
D
imTag
=
IndexTag
<
Array
::
getDimension
()
>
>
struct
OpenMPExecutor
typename
D
evice
=
typename
Array
::
DeviceType
>
struct
ParallelExecutorDeviceDispatch
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
SequentialExecutor
<
Array
,
IndexTag
<
3
>
>
exec
;
const
auto
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
auto
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
const
auto
size2
=
array
.
template
getSize
<
get
<
2
>(
typename
Array
::
PermutationType
{}
)
>
();
#ifdef HAVE_OPENMP
#pragma omp parallel for collapse(3)
#endif
for
(
typename
Array
::
IndexType
i0
=
0
;
i0
<
size0
;
i0
++
)
for
(
typename
Array
::
IndexType
i1
=
0
;
i1
<
size1
;
i1
++
)
for
(
typename
Array
::
IndexType
i2
=
0
;
i2
<
size2
;
i2
++
)
exec
(
array
,
f
,
i0
,
i1
,
i2
);
}
};
using
Index
=
typename
Array
::
IndexType
;
template
<
typename
Array
>
struct
OpenMPExecutor
<
Array
,
IndexTag
<
3
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
const
auto
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
auto
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
const
auto
size2
=
array
.
template
getSize
<
get
<
2
>(
typename
Array
::
PermutationType
{}
)
>
();
#ifdef HAVE_OPENMP
#pragma omp parallel for collapse(2)
#endif
for
(
typename
Array
::
IndexType
i0
=
0
;
i0
<
size0
;
i0
++
)
for
(
typename
Array
::
IndexType
i1
=
0
;
i1
<
size1
;
i1
++
)
for
(
typename
Array
::
IndexType
i2
=
0
;
i2
<
size2
;
i2
++
)
call_with_permuted_arguments
<
typename
Array
::
PermutationType
>
(
f
,
i0
,
i1
,
i2
);
}
};
auto
kernel
=
[
=
]
(
Index
i2
,
Index
i1
,
Index
i0
)
{
SequentialExecutor
<
Array
,
IndexTag
<
3
>
>
exec
;
exec
(
array
,
f
,
i0
,
i1
,
i2
);
};
template
<
typename
Array
>
struct
OpenMPExecutor
<
Array
,
IndexTag
<
2
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
const
auto
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
auto
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for
(
typename
Array
::
IndexType
i0
=
0
;
i0
<
size0
;
i0
++
)
for
(
typename
Array
::
IndexType
i1
=
0
;
i1
<
size1
;
i1
++
)
call_with_permuted_arguments
<
typename
Array
::
PermutationType
>
(
f
,
i0
,
i1
);
const
Index
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
Index
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
const
Index
size2
=
array
.
template
getSize
<
get
<
2
>(
typename
Array
::
PermutationType
{}
)
>
();
ParallelFor3D
<
Device
>::
exec
(
(
Index
)
0
,
(
Index
)
0
,
(
Index
)
0
,
size2
,
size1
,
size0
,
kernel
);
}
};
template
<
typename
Array
>
struct
OpenMPExecutor
<
Array
,
IndexTag
<
1
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
const
auto
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
#ifdef HAVE_OPENMP
#pragma omp parallel for
#endif
for
(
typename
Array
::
IndexType
i0
=
0
;
i0
<
size0
;
i0
++
)
call_with_permuted_arguments
<
typename
Array
::
PermutationType
>
(
f
,
i0
);
}
};
template
<
typename
Array
,
typename
DimTag
=
IndexTag
<
Array
::
getDimension
()
>
>
struct
CudaExecutor
struct
ParallelExecutorDeviceDispatch
<
Array
,
Devices
::
Cuda
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
...
...
@@ -189,12 +132,25 @@ struct CudaExecutor
}
};
template
<
typename
Array
,
typename
DimTag
=
IndexTag
<
Array
::
getDimension
()
>
>
struct
ParallelExecutor
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
ParallelExecutorDeviceDispatch
<
Array
>
dispatch
;
dispatch
(
array
,
f
);
}
};
template
<
typename
Array
>
struct
Cuda
Executor
<
Array
,
IndexTag
<
3
>
>
struct
Parallel
Executor
<
Array
,
IndexTag
<
3
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
using
Device
=
typename
Array
::
DeviceType
;
using
Index
=
typename
Array
::
IndexType
;
auto
kernel
=
[
=
]
__cuda_callable__
(
Index
i2
,
Index
i1
,
Index
i0
)
...
...
@@ -205,16 +161,17 @@ struct CudaExecutor< Array, IndexTag< 3 > >
const
Index
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
Index
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
const
Index
size2
=
array
.
template
getSize
<
get
<
2
>(
typename
Array
::
PermutationType
{}
)
>
();
ParallelFor3D
<
Device
s
::
Cuda
>::
exec
(
(
Index
)
0
,
(
Index
)
0
,
(
Index
)
0
,
size2
,
size1
,
size0
,
kernel
);
ParallelFor3D
<
Device
>::
exec
(
(
Index
)
0
,
(
Index
)
0
,
(
Index
)
0
,
size2
,
size1
,
size0
,
kernel
);
}
};
template
<
typename
Array
>
struct
Cuda
Executor
<
Array
,
IndexTag
<
2
>
>
struct
Parallel
Executor
<
Array
,
IndexTag
<
2
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
using
Device
=
typename
Array
::
DeviceType
;
using
Index
=
typename
Array
::
IndexType
;
auto
kernel
=
[
=
]
__cuda_callable__
(
Index
i1
,
Index
i0
)
...
...
@@ -224,16 +181,17 @@ struct CudaExecutor< Array, IndexTag< 2 > >
const
Index
size0
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
const
Index
size1
=
array
.
template
getSize
<
get
<
1
>(
typename
Array
::
PermutationType
{}
)
>
();
ParallelFor2D
<
Device
s
::
Cuda
>::
exec
(
(
Index
)
0
,
(
Index
)
0
,
size1
,
size0
,
kernel
);
ParallelFor2D
<
Device
>::
exec
(
(
Index
)
0
,
(
Index
)
0
,
size1
,
size0
,
kernel
);
}
};
template
<
typename
Array
>
struct
Cuda
Executor
<
Array
,
IndexTag
<
1
>
>
struct
Parallel
Executor
<
Array
,
IndexTag
<
1
>
>
{
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
using
Device
=
typename
Array
::
DeviceType
;
using
Index
=
typename
Array
::
IndexType
;
auto
kernel
=
[
=
]
__cuda_callable__
(
Index
i
)
...
...
@@ -242,7 +200,7 @@ struct CudaExecutor< Array, IndexTag< 1 > >
};
const
Index
size
=
array
.
template
getSize
<
get
<
0
>(
typename
Array
::
PermutationType
{}
)
>
();
ParallelFor
<
Device
s
::
Cuda
>::
exec
(
(
Index
)
0
,
size
,
kernel
);
ParallelFor
<
Device
>::
exec
(
(
Index
)
0
,
size
,
kernel
);
}
};
...
...
@@ -265,7 +223,7 @@ struct ExecutorDispatcher< Array, Devices::Host >
void
operator
()(
const
Array
&
array
,
Func
f
)
{
if
(
Devices
::
Host
::
isOMPEnabled
()
&&
Devices
::
Host
::
getMaxThreadsCount
()
>
1
)
OpenMP
Executor
<
Array
>
()(
array
,
f
);
Parallel
Executor
<
Array
>
()(
array
,
f
);
else
SequentialExecutor
<
Array
>
()(
array
,
f
);
}
...
...
@@ -277,7 +235,7 @@ struct ExecutorDispatcher< Array, Devices::Cuda >
template
<
typename
Func
>
void
operator
()(
const
Array
&
array
,
Func
f
)
{
Cuda
Executor
<
Array
>
()(
array
,
f
);
Parallel
Executor
<
Array
>
()(
array
,
f
);
}
};
...
...
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