Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pi
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
Model registry
Operate
Environments
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
pub
pi
Commits
fde4cf7c
Commit
fde4cf7c
authored
3 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
64e3c3be
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#16405
passed
3 years ago
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
CUDA/cudapi.cu
+17
-16
17 additions, 16 deletions
CUDA/cudapi.cu
with
17 additions
and
16 deletions
CUDA/cudapi.cu
+
17
−
16
View file @
fde4cf7c
...
...
@@ -7,10 +7,27 @@
#include
<iostream>
#include
<chrono>
#include
<cstdint>
#include
<string>
uint64_t
blocks
=
1024
;
uint64_t
threads
=
1024
;
uint64_t
nloop
=
1000000
;
uint64_t
npts
=
blocks
*
threads
;
void
cudaCheck
(
string
msg
)
{
cudaError
err
;
err
=
cudaGetLastError
();
if
(
cudaSuccess
!=
err
)
cerr
<<
msg
<<
": "
<<
cudaGetErrorString
(
err
)
<<
endl
;
}
void
reduce
(
double
*
arr
)
{
uint64_t
len
=
npts
>>
1
;
while
(
1
)
{
reduce_sum
<<<
blocks
,
threads
>>>
(
arr
,
len
);
cudaCheck
(
"reduce"
);
len
=
len
>>
1
;
if
(
len
==
0
)
return
;
}
}
__global__
void
init
(
double
*
arr
,
uint64_t
nloop
)
{
uint64_t
i
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
uint64_t
start
=
nloop
*
i
+
1
;
...
...
@@ -24,22 +41,6 @@ __global__ void reduce_sum(double *arr,uint64_t len) {
if
(
i
<
len
)
arr
[
i
]
+=
arr
[
i
+
len
];
}
void
reduce
(
double
*
arr
)
{
uint64_t
len
=
npts
>>
1
;
while
(
1
)
{
reduce_sum
<<<
blocks
,
threads
>>>
(
arr
,
len
);
cudaCheck
(
"reduce"
);
len
=
len
>>
1
;
if
(
len
==
0
)
return
;
}
}
void
cudaCheck
(
string
msg
)
{
cudaError
err
;
err
=
cudaGetLastError
();
if
(
cudaSuccess
!=
err
)
cerr
<<
msg
<<
": "
<<
cudaGetErrorString
(
err
)
<<
endl
;
}
int
main
(
void
)
{
double
harr
[
1
],
*
darr
;
cudaMalloc
(
&
darr
,
npts
*
sizeof
(
double
));
...
...
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