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
0145ca8a
"vscode:/vscode.git/clone" did not exist on "f26316edb055215fd11cf1975268d5909bc435a5"
Commit
0145ca8a
authored
Nov 03, 2015
by
Davis King
Browse files
Added a cuBLAS test
parent
93410af3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
0 deletions
+135
-0
dlib/test/CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
dlib/test/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