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
30005b7e
Commit
30005b7e
authored
Jan 03, 2016
by
Davis King
Browse files
Wrapped new dot() function into the tt namespace and gave it a CPU version.
parent
d248a225
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
0 deletions
+59
-0
dlib/dnn/cpu_dlib.cpp
dlib/dnn/cpu_dlib.cpp
+17
-0
dlib/dnn/cpu_dlib.h
dlib/dnn/cpu_dlib.h
+7
-0
dlib/dnn/tensor_tools.cpp
dlib/dnn/tensor_tools.cpp
+14
-0
dlib/dnn/tensor_tools.h
dlib/dnn/tensor_tools.h
+21
-0
No files found.
dlib/dnn/cpu_dlib.cpp
View file @
30005b7e
...
@@ -830,6 +830,23 @@ namespace dlib
...
@@ -830,6 +830,23 @@ namespace dlib
d
[
i
]
=
d
[
i
]
>
thresh
?
1
:
0
;
d
[
i
]
=
d
[
i
]
>
thresh
?
1
:
0
;
}
}
void
dot
(
const
tensor
&
a
,
const
tensor
&
b
,
tensor
&
result
,
size_t
idx
)
{
DLIB_CASSERT
(
a
.
size
()
==
b
.
size
(),
""
);
DLIB_CASSERT
(
idx
<
result
.
size
(),
""
);
const
auto
aa
=
a
.
host
();
const
auto
bb
=
b
.
host
();
auto
r
=
result
.
host
();
for
(
size_t
i
=
0
;
i
<
a
.
size
();
++
i
)
r
[
idx
]
+=
aa
[
i
]
*
bb
[
i
];
}
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
...
...
dlib/dnn/cpu_dlib.h
View file @
30005b7e
...
@@ -154,6 +154,13 @@ namespace dlib
...
@@ -154,6 +154,13 @@ namespace dlib
float
thresh
float
thresh
);
);
void
dot
(
const
tensor
&
a
,
const
tensor
&
b
,
tensor
&
result
,
size_t
idx
);
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
void
softmax
(
void
softmax
(
...
...
dlib/dnn/tensor_tools.cpp
View file @
30005b7e
...
@@ -307,6 +307,20 @@ namespace dlib { namespace tt
...
@@ -307,6 +307,20 @@ namespace dlib { namespace tt
#endif
#endif
}
}
void
dot
(
const
tensor
&
a
,
const
tensor
&
b
,
tensor
&
result
,
size_t
idx
)
{
#ifdef DLIB_USE_CUDA
cuda
::
dot
(
a
,
b
,
result
,
idx
);
#else
cpu
::
dot
(
a
,
b
,
result
,
idx
);
#endif
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
add
(
void
add
(
...
...
dlib/dnn/tensor_tools.h
View file @
30005b7e
...
@@ -398,6 +398,27 @@ namespace dlib { namespace tt
...
@@ -398,6 +398,27 @@ namespace dlib { namespace tt
- #data.host()[i] == data.host()[i]>thresh ? 1 : 0
- #data.host()[i] == data.host()[i]>thresh ? 1 : 0
!*/
!*/
void
dot
(
const
tensor
&
a
,
const
tensor
&
b
,
tensor
&
result
,
size_t
idx
);
/*!
requires
- a.size() == b.size()
- idx < result.size()
ensures
- #result.host()[idx] == result.host()[idx] + dot(a,b);
I.e. Adds the dot product between a and b into the idx-th element of result.
The reason you might want to use this more complex version of dot() is
because, when using CUDA, it runs by generating asynchronous kernel launches
whereas the version of dot() that returns the result immediately as a scalar
must block the host while we wait for the result to be computed and then
transfered from the GPU do the host for return by dot(). So this version of
dot() might be much faster in some cases.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void
add
(
void
add
(
...
...
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