Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Parallel STL course
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
Michaël El Kharroubi
Parallel STL course
Commits
aae35579
Commit
aae35579
authored
1 year ago
by
Michaël El Kharroubi
Browse files
Options
Downloads
Patches
Plain Diff
Future exemple works
parent
90d962e6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Examples/future.cpp
+27
-9
27 additions, 9 deletions
Examples/future.cpp
Examples/makefile
+5
-2
5 additions, 2 deletions
Examples/makefile
with
32 additions
and
11 deletions
Examples/future.cpp
+
27
−
9
View file @
aae35579
#include
<array>
#include
<execution>
#include
<iomanip>
#include
<iostream>
#include
<iostream>
#include
<ranges>
#include
<ranges>
#include
<vector>
#include
<vector>
...
@@ -7,22 +8,39 @@
...
@@ -7,22 +8,39 @@
#include
"includes/cartesian_product.hpp"
#include
"includes/cartesian_product.hpp"
#include
"includes/mdspan.hpp"
#include
"includes/mdspan.hpp"
constexpr
int
dim_x
=
5
;
constexpr
int
dim_x
=
8
;
constexpr
int
dim_y
=
5
;
constexpr
int
dim_y
=
8
;
int
main
()
{
int
main
()
{
std
::
array
<
float
,
dim_x
*
dim_y
>
data
{
0
};
std
::
vector
<
int
>
data
{
dim_x
*
dim_y
};
auto
md
=
std
::
mdspan
{
data
.
data
(),
dim_x
,
dim_y
};
// We create a view for x & y indexes
auto
xs
=
std
::
views
::
iota
(
0
,
dim_x
);
auto
xs
=
std
::
views
::
iota
(
0
,
dim_x
);
auto
ys
=
std
::
views
::
iota
(
0
,
dim_y
);
auto
ys
=
std
::
views
::
iota
(
0
,
dim_y
);
// We build the indexes using the cartesian product
auto
idxs
=
std
::
views
::
cartesian_product
(
xs
,
ys
);
auto
idxs
=
std
::
views
::
cartesian_product
(
xs
,
ys
);
auto
md
=
std
::
experimental
::
mdspan
{
data
.
data
(),
dim_x
,
dim_y
};
// We perform our operations on GPU
std
::
for_each
(
std
::
execution
::
par_unseq
,
std
::
for_each
(
idxs
.
begin
(),
idxs
.
end
(),
[
&
md
](
auto
tup
)
{
idxs
.
begin
(),
const
auto
&
[
x
,
y
]
=
tup
;
idxs
.
end
(),
std
::
cout
<<
x
<<
","
<<
y
<<
std
::
endl
;
// Here we need to do a copy capture so that compiler knows that
// we will use the underlying memory on the GPU.
[
md
](
auto
tup
)
{
const
auto
&
[
x
,
y
]
=
tup
;
md
(
x
,
y
)
=
x
*
y
;
});
// We print the result, since it's performed on CPU,
// we can simply capture by reference.
std
::
for_each
(
xs
.
begin
(),
xs
.
end
(),
[
&
md
,
&
ys
](
auto
i
)
{
std
::
for_each
(
ys
.
begin
(),
ys
.
end
(),
[
&
md
,
i
](
auto
j
)
{
std
::
cout
<<
std
::
setw
(
3
)
<<
md
(
i
,
j
);
});
std
::
cout
<<
"
\n
"
;
});
});
std
::
cout
<<
"
\n
"
;
std
::
cout
<<
"
\n
"
;
...
...
This diff is collapsed.
Click to expand it.
Examples/makefile
+
5
−
2
View file @
aae35579
.PHONY
:
clean all
.PHONY
:
clean all
CC
=
nvc++
FLAGS
=
--std
=
c++23
-stdpar
=
gpu
INCLUDES_WARNINGS
:=
--diag_suppress
useless_using_declaration
INCLUDES_WARNINGS
:=
--diag_suppress
useless_using_declaration
all
:
artefacts/future
all
:
artefacts/future
artefacts/future
:
artefacts/future.o
artefacts/future
:
artefacts/future.o
nvc++
$^
-o
$@
$(
CC
)
$(
FLAGS
)
$^
-o
$@
artefacts/%.o
:
%.cpp
artefacts/%.o
:
%.cpp
nvc++
--std
=
c++23
$(
INCLUDES_WARNINGS
)
-c
$^
-o
$@
$(
CC
)
$(
FLAGS
)
$(
INCLUDES_WARNINGS
)
-c
$^
-o
$@
clean
:
clean
:
rm
-vf
artefacts/
**
rm
-vf
artefacts/
**
\ No newline at end of file
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