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
5f8e41a8
"vscode:/vscode.git/clone" did not exist on "47898ab657e53e4d2cabb6fe8d869d68485414c9"
Commit
5f8e41a8
authored
Dec 08, 2015
by
Davis King
Browse files
Added another version of multiply()
parent
79344339
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
0 deletions
+85
-0
dlib/dnn/cpu_dlib.cpp
dlib/dnn/cpu_dlib.cpp
+17
-0
dlib/dnn/cpu_dlib.h
dlib/dnn/cpu_dlib.h
+6
-0
dlib/dnn/cuda_dlib.cu
dlib/dnn/cuda_dlib.cu
+21
-0
dlib/dnn/cuda_dlib.h
dlib/dnn/cuda_dlib.h
+6
-0
dlib/dnn/tensor_tools.cpp
dlib/dnn/tensor_tools.cpp
+18
-0
dlib/dnn/tensor_tools.h
dlib/dnn/tensor_tools.h
+17
-0
No files found.
dlib/dnn/cpu_dlib.cpp
View file @
5f8e41a8
...
...
@@ -26,6 +26,23 @@ namespace dlib
d
[
i
]
*=
s
[
i
];
}
// -----------------------------------------------------------------------------------
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
)
{
DLIB_CASSERT
(
dest
.
size
()
==
src1
.
size
(),
""
);
DLIB_CASSERT
(
dest
.
size
()
==
src2
.
size
(),
""
);
const
auto
d
=
dest
.
host
();
const
auto
s1
=
src1
.
host
();
const
auto
s2
=
src2
.
host
();
for
(
size_t
i
=
0
;
i
<
src1
.
size
();
++
i
)
d
[
i
]
=
s1
[
i
]
*
s2
[
i
];
}
// -----------------------------------------------------------------------------------
void
affine_transform
(
...
...
dlib/dnn/cpu_dlib.h
View file @
5f8e41a8
...
...
@@ -20,6 +20,12 @@ namespace dlib
const
tensor
&
src
);
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
);
// -----------------------------------------------------------------------------------
void
affine_transform
(
...
...
dlib/dnn/cuda_dlib.cu
View file @
5f8e41a8
...
...
@@ -46,6 +46,27 @@ namespace dlib
_cuda_multiply
<<<
512
,
512
>>>
(
dest
.
device
(),
src
.
device
(),
src
.
size
());
}
// -----------------------------------------------------------------------------------
__global__
void
_cuda_multiply
(
float
*
d
,
const
float
*
s1
,
const
float
*
s2
,
size_t
n
)
{
for
(
auto
i
:
grid_stride_range
(
0
,
n
))
{
d
[
i
]
=
s1
[
i
]
*
s2
[
i
];
}
}
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
)
{
DLIB_CASSERT
(
dest
.
size
()
==
src1
.
size
(),
""
);
DLIB_CASSERT
(
dest
.
size
()
==
src2
.
size
(),
""
);
_cuda_multiply
<<<
512
,
512
>>>
(
dest
.
device
(),
src1
.
device
(),
src2
.
device
(),
src1
.
size
());
}
// -----------------------------------------------------------------------------------
__global__
void
_cuda_affine_transform
(
float
*
d
,
const
float
*
s
,
size_t
n
,
float
A
,
float
B
)
...
...
dlib/dnn/cuda_dlib.h
View file @
5f8e41a8
...
...
@@ -29,6 +29,12 @@ namespace dlib
const
tensor
&
src
);
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
);
// -----------------------------------------------------------------------------------
void
affine_transform
(
...
...
dlib/dnn/tensor_tools.cpp
View file @
5f8e41a8
...
...
@@ -108,6 +108,24 @@ namespace dlib { namespace tt
}
// ----------------------------------------------------------------------------------------
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
)
{
DLIB_CASSERT
(
have_same_dimensions
(
dest
,
src1
)
==
true
,
""
);
DLIB_CASSERT
(
have_same_dimensions
(
dest
,
src2
)
==
true
,
""
);
#ifdef DLIB_USE_CUDA
cuda
::
multiply
(
dest
,
src1
,
src2
);
#else
cpu
::
multiply
(
dest
,
src1
,
src2
);
#endif
}
// ----------------------------------------------------------------------------------------
void
affine_transform
(
...
...
dlib/dnn/tensor_tools.h
View file @
5f8e41a8
...
...
@@ -105,6 +105,23 @@ namespace dlib { namespace tt
#dest.host()[i] == dest.host()[i]*src.host()[i]
!*/
// ----------------------------------------------------------------------------------------
void
multiply
(
tensor
&
dest
,
const
tensor
&
src1
,
const
tensor
&
src2
);
/*!
requires
- have_same_dimensions(dest,src1) == true
- have_same_dimensions(dest,src2) == true
ensures
- #dest == src1*src2
That is, for all valid i:
#dest.host()[i] == src1.host()[i]*src2.host()[i]
!*/
// ----------------------------------------------------------------------------------------
void
affine_transform
(
...
...
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