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
ccb148b4
Commit
ccb148b4
authored
Nov 26, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up cuda error handling code
parent
dbbce825
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
82 additions
and
56 deletions
+82
-56
cublas_dlibapi.cpp
dlib/dnn/cublas_dlibapi.cpp
+28
-19
cublas_dlibapi.h
dlib/dnn/cublas_dlibapi.h
+1
-8
cuda_errors.h
dlib/dnn/cuda_errors.h
+22
-0
cudnn_dlibapi.cpp
dlib/dnn/cudnn_dlibapi.cpp
+0
-0
curand_dlibapi.cpp
dlib/dnn/curand_dlibapi.cpp
+30
-21
curand_dlibapi.h
dlib/dnn/curand_dlibapi.h
+1
-8
No files found.
dlib/dnn/cublas_dlibapi.cpp
View file @
ccb148b4
...
...
@@ -9,27 +9,36 @@
#include <cublas_v2.h>
namespace
dlib
static
const
char
*
cublas_get_error_string
(
cublasStatus_t
s
)
{
namespace
cuda
switch
(
s
)
{
case
CUBLAS_STATUS_NOT_INITIALIZED
:
return
"CUDA Runtime API initialization failed."
;
case
CUBLAS_STATUS_ALLOC_FAILED
:
return
"CUDA Resources could not be allocated."
;
default:
return
"A call to cuBLAS failed"
;
}
}
// ----------------------------------------------------------------------------------------
// Check the return value of a call to the cuBLAS runtime for an error condition.
#define CHECK_CUBLAS(call) \
{ \
const cublasStatus_t error = call; \
if (error != CUBLAS_STATUS_SUCCESS) \
{ \
std::ostringstream sout; \
sout << "Error while calling " << #call << " in file " << __FILE__ << ":" << __LINE__ << ". ";\
sout << "code: " << error << ", reason: " << cublas_get_error_string(error);\
throw dlib::cublas_error(sout.str()); \
} \
}
// TODO, make into a macro that prints more information like the line number, etc.
static
void
check
(
cublasStatus_t
s
)
{
switch
(
s
)
{
case
CUBLAS_STATUS_SUCCESS
:
return
;
case
CUBLAS_STATUS_NOT_INITIALIZED
:
throw
cublas_error
(
"CUDA Runtime API initialization failed."
);
case
CUBLAS_STATUS_ALLOC_FAILED
:
throw
cublas_error
(
"CUDA Resources could not be allocated."
);
default
:
throw
cublas_error
(
"A call to cuBLAS failed"
);
}
}
namespace
dlib
{
namespace
cuda
{
// -----------------------------------------------------------------------------------
...
...
@@ -42,7 +51,7 @@ namespace dlib
cublas_context
()
{
check
(
cublasCreate
(
&
handle
));
CHECK_CUBLAS
(
cublasCreate
(
&
handle
));
}
~
cublas_context
()
{
...
...
@@ -117,7 +126,7 @@ namespace dlib
}
const
int
k
=
trans_rhs
?
rhs_nc
:
rhs_nr
;
check
(
cublasSgemm
(
context
(),
CHECK_CUBLAS
(
cublasSgemm
(
context
(),
transb
,
transa
,
dest_nc
,
dest_nr
,
k
,
...
...
dlib/dnn/cublas_dlibapi.h
View file @
ccb148b4
...
...
@@ -6,20 +6,13 @@
#ifdef DLIB_USE_CUDA
#include "tensor.h"
#include "
../error
.h"
#include "
cuda_errors
.h"
namespace
dlib
{
namespace
cuda
{
// -----------------------------------------------------------------------------------
struct
cublas_error
:
public
error
{
cublas_error
(
const
std
::
string
&
message
)
:
error
(
message
)
{}
};
// -----------------------------------------------------------------------------------
void
gemm
(
...
...
dlib/dnn/cuda_errors.h
View file @
ccb148b4
...
...
@@ -30,6 +30,28 @@ namespace dlib
cudnn_error
(
const
std
::
string
&
message
)
:
cuda_error
(
message
)
{}
};
struct
curand_error
:
public
cuda_error
{
/*!
WHAT THIS OBJECT REPRESENTS
This is the exception thrown if any calls to the NVIDIA cuRAND library
returns an error.
!*/
curand_error
(
const
std
::
string
&
message
)
:
cuda_error
(
message
)
{}
};
struct
cublas_error
:
public
cuda_error
{
/*!
WHAT THIS OBJECT REPRESENTS
This is the exception thrown if any calls to the NVIDIA cuBLAS library
returns an error.
!*/
cublas_error
(
const
std
::
string
&
message
)
:
cuda_error
(
message
)
{}
};
}
...
...
dlib/dnn/cudnn_dlibapi.cpp
View file @
ccb148b4
This diff is collapsed.
Click to expand it.
dlib/dnn/curand_dlibapi.cpp
View file @
ccb148b4
...
...
@@ -9,27 +9,36 @@
#include <curand.h>
#include "../string.h"
namespace
dlib
static
const
char
*
curand_get_error_string
(
curandStatus_t
s
)
{
namespace
cuda
switch
(
s
)
{
case
CURAND_STATUS_NOT_INITIALIZED
:
return
"CUDA Runtime API initialization failed."
;
case
CURAND_STATUS_LENGTH_NOT_MULTIPLE
:
return
"The requested length must be a multiple of two."
;
default:
return
"A call to cuRAND failed"
;
}
}
// ----------------------------------------------------------------------------------------
// Check the return value of a call to the cuDNN runtime for an error condition.
#define CHECK_CURAND(call) \
{ \
const curandStatus_t error = call; \
if (error != CURAND_STATUS_SUCCESS) \
{ \
std::ostringstream sout; \
sout << "Error while calling " << #call << " in file " << __FILE__ << ":" << __LINE__ << ". ";\
sout << "code: " << error << ", reason: " << curand_get_error_string(error);\
throw dlib::curand_error(sout.str()); \
} \
}
// TODO, make into a macro that prints more information like the line number, etc.
static
void
check
(
curandStatus_t
s
)
{
switch
(
s
)
{
case
CURAND_STATUS_SUCCESS
:
return
;
case
CURAND_STATUS_NOT_INITIALIZED
:
throw
curand_error
(
"CUDA Runtime API initialization failed."
);
case
CURAND_STATUS_LENGTH_NOT_MULTIPLE
:
throw
curand_error
(
"The requested length must be a multiple of two."
);
default
:
throw
curand_error
(
"A call to cuRAND failed: "
+
cast_to_string
(
s
));
}
}
namespace
dlib
{
namespace
cuda
{
// ----------------------------------------------------------------------------------------
...
...
@@ -39,10 +48,10 @@ namespace dlib
)
:
handle
(
nullptr
)
{
curandGenerator_t
gen
;
check
(
curandCreateGenerator
(
&
gen
,
CURAND_RNG_PSEUDO_DEFAULT
));
CHECK_CURAND
(
curandCreateGenerator
(
&
gen
,
CURAND_RNG_PSEUDO_DEFAULT
));
handle
=
gen
;
check
(
curandSetPseudoRandomGeneratorSeed
(
gen
,
seed
));
CHECK_CURAND
(
curandSetPseudoRandomGeneratorSeed
(
gen
,
seed
));
}
curand_generator
::
...
...
@@ -64,7 +73,7 @@ namespace dlib
if
(
data
.
size
()
==
0
)
return
;
check
(
curandGenerateNormal
((
curandGenerator_t
)
handle
,
CHECK_CURAND
(
curandGenerateNormal
((
curandGenerator_t
)
handle
,
data
.
device
(),
data
.
size
(),
mean
,
...
...
@@ -79,7 +88,7 @@ namespace dlib
if
(
data
.
size
()
==
0
)
return
;
check
(
curandGenerateUniform
((
curandGenerator_t
)
handle
,
data
.
device
(),
data
.
size
()));
CHECK_CURAND
(
curandGenerateUniform
((
curandGenerator_t
)
handle
,
data
.
device
(),
data
.
size
()));
}
// -----------------------------------------------------------------------------------
...
...
dlib/dnn/curand_dlibapi.h
View file @
ccb148b4
...
...
@@ -6,7 +6,7 @@
#ifdef DLIB_USE_CUDA
#include "tensor.h"
#include "
../error
.h"
#include "
cuda_errors
.h"
namespace
dlib
{
...
...
@@ -15,13 +15,6 @@ namespace dlib
// -----------------------------------------------------------------------------------
struct
curand_error
:
public
error
{
curand_error
(
const
std
::
string
&
message
)
:
error
(
message
)
{}
};
// ----------------------------------------------------------------------------------------
class
curand_generator
{
public
:
...
...
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