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
0145ca8a
Commit
0145ca8a
authored
Nov 04, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a cuBLAS test
parent
93410af3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
cublas.cpp
dlib/test/cublas.cpp
+134
-0
No files found.
dlib/test/CMakeLists.txt
View file @
0145ca8a
...
...
@@ -35,6 +35,7 @@ set (tests
config_reader.cpp
crc32.cpp
create_iris_datafile.cpp
cublas.cpp
data_io.cpp
directed_graph.cpp
discriminant_pca.cpp
...
...
dlib/test/cublas.cpp
0 → 100644
View file @
0145ca8a
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <dlib/matrix.h>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "../dnn/cublas_dlibapi.h"
#include "tester.h"
// We only do these tests if CUDA is available to test in the first place.
#ifdef DLIB_USE_CUDA
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
logger
dlog
(
"test.cublas"
);
class
cublas_tester
:
public
tester
{
public
:
cublas_tester
(
)
:
tester
(
"test_cublas"
,
"Runs tests on the cuBLAS bindings."
)
{}
void
perform_test
(
)
{
{
resizable_tensor
a
(
4
,
3
),
b
(
3
,
4
),
c
(
3
,
3
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
trans
(
mat
(
a
))
*
trans
(
mat
(
b
));
cuda
::
gemm
(
2
,
c
,
1
,
a
,
true
,
b
,
true
);
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
4
,
3
),
b
(
4
,
3
),
c
(
3
,
3
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
trans
(
mat
(
a
))
*
mat
(
b
);
cuda
::
gemm
(
2
,
c
,
1
,
a
,
true
,
b
,
false
);
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
3
,
4
),
b
(
3
,
4
),
c
(
3
,
3
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
mat
(
a
)
*
trans
(
mat
(
b
));
cuda
::
gemm
(
2
,
c
,
1
,
a
,
false
,
b
,
true
);
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
3
,
4
),
b
(
4
,
3
),
c
(
3
,
3
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
mat
(
a
)
*
mat
(
b
);
cuda
::
gemm
(
2
,
c
,
1
,
a
,
false
,
b
,
false
);
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
3
,
4
),
b
(
4
,
4
),
c
(
3
,
4
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
mat
(
a
)
*
mat
(
b
);
cuda
::
gemm
(
2
,
c
,
1
,
a
,
false
,
b
,
false
);
DLIB_TEST
(
get_rect
(
truth
)
==
get_rect
(
mat
(
c
)));
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
4
,
3
),
b
(
4
,
4
),
c
(
3
,
4
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
trans
(
mat
(
a
))
*
mat
(
b
);
cuda
::
gemm
(
2
,
c
,
1
,
a
,
true
,
b
,
false
);
DLIB_TEST
(
get_rect
(
truth
)
==
get_rect
(
mat
(
c
)));
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
{
resizable_tensor
a
(
4
,
3
),
b
(
4
,
5
),
c
(
3
,
5
);
c
=
1
;
a
=
matrix_cast
<
float
>
(
gaussian_randm
(
a
.
num_samples
(),
a
.
size
()
/
a
.
num_samples
()));
b
=
matrix_cast
<
float
>
(
gaussian_randm
(
b
.
num_samples
(),
b
.
size
()
/
b
.
num_samples
()));
matrix
<
float
>
truth
=
2
*
mat
(
c
)
+
trans
(
mat
(
a
))
*
mat
(
b
);
cuda
::
gemm
(
2
,
c
,
1
,
a
,
true
,
b
,
false
);
DLIB_TEST
(
get_rect
(
truth
)
==
get_rect
(
mat
(
c
)));
DLIB_TEST
(
max
(
abs
(
truth
-
mat
(
c
)))
<
1e-6
);
}
}
}
a
;
}
#endif // DLIB_USE_CUDA
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