Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
30005b7e
Commit
30005b7e
authored
Jan 03, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrapped new dot() function into the tt namespace and gave it a CPU version.
parent
d248a225
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
0 deletions
+59
-0
cpu_dlib.cpp
dlib/dnn/cpu_dlib.cpp
+17
-0
cpu_dlib.h
dlib/dnn/cpu_dlib.h
+7
-0
tensor_tools.cpp
dlib/dnn/tensor_tools.cpp
+14
-0
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
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
float
thresh
);
void
dot
(
const
tensor
&
a
,
const
tensor
&
b
,
tensor
&
result
,
size_t
idx
);
// -----------------------------------------------------------------------------------
void
softmax
(
...
...
dlib/dnn/tensor_tools.cpp
View file @
30005b7e
...
...
@@ -307,6 +307,20 @@ namespace dlib { namespace tt
#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
(
...
...
dlib/dnn/tensor_tools.h
View file @
30005b7e
...
...
@@ -398,6 +398,27 @@ namespace dlib { namespace tt
- #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
(
...
...
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