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
63f4f73b
Commit
63f4f73b
authored
Apr 21, 2017
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tt::log(), tt::exp(), and tt::log10()
parent
dd4850b5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
186 additions
and
1 deletion
+186
-1
cuda_dlib.cu
dlib/dnn/cuda_dlib.cu
+54
-1
cuda_dlib.h
dlib/dnn/cuda_dlib.h
+15
-0
tensor_tools.cpp
dlib/dnn/tensor_tools.cpp
+48
-0
tensor_tools.h
dlib/dnn/tensor_tools.h
+39
-0
dnn.cpp
dlib/test/dnn.cpp
+30
-0
No files found.
dlib/dnn/cuda_dlib.cu
View file @
63f4f73b
...
...
@@ -261,6 +261,57 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
__global__ void _cuda_exp(float* dest, const float* src, size_t n)
{
for (auto i : grid_stride_range(0, n))
dest[i] = ::exp(src[i]);
}
void exp (
tensor& dest,
const tensor& src
)
{
DLIB_ASSERT(dest.size() == src.size());
launch_kernel(_cuda_exp, max_jobs(src.size()), dest.device(), src.device(), src.size());
}
// ----------------------------------------------------------------------------------------
__global__ void _cuda_log(float* dest, const float* src, size_t n)
{
for (auto i : grid_stride_range(0, n))
dest[i] = ::log(src[i]);
}
void log (
tensor& dest,
const tensor& src
)
{
DLIB_ASSERT(dest.size() == src.size());
launch_kernel(_cuda_log, max_jobs(src.size()), dest.device(), src.device(), src.size());
}
// ----------------------------------------------------------------------------------------
__global__ void _cuda_log10(float* dest, const float* src, size_t n)
{
for (auto i : grid_stride_range(0, n))
dest[i] = ::log10(src[i]);
}
void log10 (
tensor& dest,
const tensor& src
)
{
DLIB_ASSERT(dest.size() == src.size());
launch_kernel(_cuda_log10, max_jobs(src.size()), dest.device(), src.device(), src.size());
}
// -----------------------------------------------------------------------------------
__global__ void _cuda_multiply1(float* d, const float* s1, const float* s2, size_t n)
...
...
@@ -1085,7 +1136,8 @@ namespace dlib
grad.device(), src.device(), gradient_input.device(), grad.size(),
param.device(), params_grad.device());
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
void copy_tensor(
tensor& dest,
...
...
@@ -1117,6 +1169,7 @@ namespace dlib
src_p += src_sample_size;
}
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/dnn/cuda_dlib.h
View file @
63f4f73b
...
...
@@ -142,6 +142,21 @@ namespace dlib
const
tensor
&
v2
);
void
exp
(
tensor
&
dest
,
const
tensor
&
src
);
void
log
(
tensor
&
dest
,
const
tensor
&
src
);
void
log10
(
tensor
&
dest
,
const
tensor
&
src
);
// ------------------------------------------------------------------------------------
void
set_tensor
(
...
...
dlib/dnn/tensor_tools.cpp
View file @
63f4f73b
...
...
@@ -135,6 +135,54 @@ namespace dlib { namespace tt
#endif
}
// ----------------------------------------------------------------------------------------
void
exp
(
tensor
&
dest
,
const
tensor
&
src
)
{
DLIB_CASSERT
(
dest
.
size
()
==
src
.
size
());
#ifdef DLIB_USE_CUDA
cuda
::
exp
(
dest
,
src
);
#else
dest
=
exp
(
mat
(
src
));
#endif
}
// ----------------------------------------------------------------------------------------
void
log
(
tensor
&
dest
,
const
tensor
&
src
)
{
DLIB_CASSERT
(
dest
.
size
()
==
src
.
size
());
#ifdef DLIB_USE_CUDA
cuda
::
log
(
dest
,
src
);
#else
dest
=
log
(
mat
(
src
));
#endif
}
// ----------------------------------------------------------------------------------------
void
log10
(
tensor
&
dest
,
const
tensor
&
src
)
{
DLIB_CASSERT
(
dest
.
size
()
==
src
.
size
());
#ifdef DLIB_USE_CUDA
cuda
::
log10
(
dest
,
src
);
#else
dest
=
log10
(
mat
(
src
));
#endif
}
// ----------------------------------------------------------------------------------------
void
gemm
(
...
...
dlib/dnn/tensor_tools.h
View file @
63f4f73b
...
...
@@ -98,6 +98,45 @@ namespace dlib { namespace tt
out = beta*out + scale_rows(mat(m1) - scale_rows(mat(m2),mat(v1)), mat(v2));
!*/
// ----------------------------------------------------------------------------------------
void
exp
(
tensor
&
dest
,
const
tensor
&
src
);
/*!
requires
- dest.size() == src.size()
ensures
- performs: dest = exp(mat(src))
!*/
// ----------------------------------------------------------------------------------------
void
log
(
tensor
&
dest
,
const
tensor
&
src
);
/*!
requires
- dest.size() == src.size()
ensures
- performs: dest = log(mat(src))
!*/
// ----------------------------------------------------------------------------------------
void
log10
(
tensor
&
dest
,
const
tensor
&
src
);
/*!
requires
- dest.size() == src.size()
ensures
- performs: dest = log10(mat(src))
!*/
// ----------------------------------------------------------------------------------------
void
gemm
(
...
...
dlib/test/dnn.cpp
View file @
63f4f73b
...
...
@@ -692,6 +692,36 @@ namespace
cpu
::
add
(
2
,
AA
,
3
,
BB
);
DLIB_TEST_MSG
(
max
(
abs
(
mat
(
A
)
-
mat
(
AA
)
))
<
1e-6
,
max
(
abs
(
mat
(
A
)
-
mat
(
AA
)
)));
}
{
print_spinner
();
resizable_tensor
dest1
(
123
,
456
),
dest2
(
123
,
456
);
resizable_tensor
src1
(
123
,
456
),
src2
(
123
,
456
);
tt
::
tensor_rand
rnd
;
rnd
.
fill_uniform
(
src1
);
tt
::
affine_transform
(
src1
,
src1
,
1
,
2
);
src2
=
src1
;
// random in range [2, 3]
dest1
=
exp
(
mat
(
src1
));
tt
::
exp
(
dest2
,
src2
);
tt
::
exp
(
src2
,
src2
);
// should work in place
DLIB_TEST_MSG
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
dest2
)))
<
1e-5
,
max
(
abs
(
mat
(
dest1
)
-
mat
(
dest2
))));
DLIB_TEST
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
src2
)))
<
1e-5
);
rnd
.
fill_uniform
(
src1
);
tt
::
affine_transform
(
src1
,
src1
,
1
,
2
);
src2
=
src1
;
// random in range [2, 3]
dest1
=
log
(
mat
(
src1
));
tt
::
log
(
dest2
,
src2
);
tt
::
log
(
src2
,
src2
);
// should work in place
DLIB_TEST
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
dest2
)))
<
1e-5
);
DLIB_TEST
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
src2
)))
<
1e-5
);
rnd
.
fill_uniform
(
src1
);
tt
::
affine_transform
(
src1
,
src1
,
1
,
2
);
src2
=
src1
;
// random in range [2, 3]
dest1
=
log10
(
mat
(
src1
));
tt
::
log10
(
dest2
,
src2
);
tt
::
log10
(
src2
,
src2
);
// should work in place
DLIB_TEST
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
dest2
)))
<
1e-5
);
DLIB_TEST
(
max
(
abs
(
mat
(
dest1
)
-
mat
(
src2
)))
<
1e-5
);
}
}
// ----------------------------------------------------------------------------------------
...
...
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