Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
8466d332
"apps/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "1de192f44558e5d2b7bcfa12c511f4f1f7e129c4"
Commit
8466d332
authored
Jan 01, 2016
by
Davis King
Browse files
Made the tensor dot() function use cuBLAS.
parent
8424083e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
dlib/dnn/cublas_dlibapi.cpp
dlib/dnn/cublas_dlibapi.cpp
+18
-0
dlib/dnn/cublas_dlibapi.h
dlib/dnn/cublas_dlibapi.h
+17
-1
dlib/dnn/tensor.h
dlib/dnn/tensor.h
+5
-1
No files found.
dlib/dnn/cublas_dlibapi.cpp
View file @
8466d332
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include "cublas_dlibapi.h"
#include "cublas_dlibapi.h"
#include "cuda_utils.h"
#include "cuda_utils.h"
#include "tensor.h"
#include <cublas_v2.h>
#include <cublas_v2.h>
...
@@ -88,6 +89,23 @@ namespace dlib
...
@@ -88,6 +89,23 @@ namespace dlib
return
c
.
get_handle
();
return
c
.
get_handle
();
}
}
// -----------------------------------------------------------------------------------
float
dot
(
const
tensor
&
a
,
const
tensor
&
b
)
{
DLIB_CASSERT
(
a
.
size
()
==
b
.
size
(),
""
);
float
result
=
0
;
CHECK_CUBLAS
(
cublasSdot
(
context
(),
a
.
size
(),
a
.
device
(),
1
,
b
.
device
(),
1
,
&
result
));
return
result
;
}
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
void
gemm
(
void
gemm
(
...
...
dlib/dnn/cublas_dlibapi.h
View file @
8466d332
...
@@ -5,14 +5,30 @@
...
@@ -5,14 +5,30 @@
#ifdef DLIB_USE_CUDA
#ifdef DLIB_USE_CUDA
#include "tensor.h"
#include "cuda_errors.h"
#include "cuda_errors.h"
namespace
dlib
namespace
dlib
{
{
class
tensor
;
namespace
cuda
namespace
cuda
{
{
// -----------------------------------------------------------------------------------
float
dot
(
const
tensor
&
a
,
const
tensor
&
b
);
/*!
requires
- a.size() == b.size()
ensures
- returns the dot product between a and b when they are both treated as
a.size() dimensional vectors. That is, this function pointwise
multiplies the vectors together, then sums the result and returns it.
!*/
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
void
gemm
(
void
gemm
(
...
...
dlib/dnn/tensor.h
View file @
8466d332
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include <cstring>
#include <cstring>
#include "../matrix.h"
#include "../matrix.h"
#include "cudnn_dlibapi.h"
#include "cudnn_dlibapi.h"
#include "cublas_dlibapi.h"
#include "gpu_data.h"
#include "gpu_data.h"
#include <memory>
#include <memory>
...
@@ -405,7 +406,9 @@ namespace dlib
...
@@ -405,7 +406,9 @@ namespace dlib
const
tensor
&
b
const
tensor
&
b
)
)
{
{
// TODO, do on GPU?
#ifdef DLIB_USE_CUDA
return
cuda
::
dot
(
a
,
b
);
#else
DLIB_CASSERT
(
a
.
size
()
==
b
.
size
(),
""
);
DLIB_CASSERT
(
a
.
size
()
==
b
.
size
(),
""
);
const
float
*
da
=
a
.
host
();
const
float
*
da
=
a
.
host
();
const
float
*
db
=
b
.
host
();
const
float
*
db
=
b
.
host
();
...
@@ -413,6 +416,7 @@ namespace dlib
...
@@ -413,6 +416,7 @@ namespace dlib
for
(
size_t
i
=
0
;
i
<
a
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
a
.
size
();
++
i
)
sum
+=
da
[
i
]
*
db
[
i
];
sum
+=
da
[
i
]
*
db
[
i
];
return
sum
;
return
sum
;
#endif
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment