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
141b384b
Commit
141b384b
authored
Nov 08, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added binding to cuRAND
parent
6539ea67
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
1 deletion
+171
-1
CMakeLists.txt
dlib/CMakeLists.txt
+6
-1
curand_dlibapi.cpp
dlib/dnn/curand_dlibapi.cpp
+93
-0
curand_dlibapi.h
dlib/dnn/curand_dlibapi.h
+72
-0
No files found.
dlib/CMakeLists.txt
View file @
141b384b
...
...
@@ -456,9 +456,14 @@ if (NOT TARGET dlib)
dnn/cuda_dlib.cu
dnn/cudnn_dlibapi.cpp
dnn/cublas_dlibapi.cpp
dnn/curand_dlibapi.cpp
dnn/gpu_data.cpp
)
set
(
dlib_needed_libraries
${
dlib_needed_libraries
}
${
CUDA_CUBLAS_LIBRARIES
}
${
cudnn
}
)
set
(
dlib_needed_libraries
${
dlib_needed_libraries
}
${
CUDA_CUBLAS_LIBRARIES
}
${
cudnn
}
${
CUDA_curand_LIBRARY
}
)
include_directories
(
${
cudnn_include
}
)
else
()
set
(
DLIB_USE_CUDA OFF CACHE STRING
${
DLIB_USE_BLAS_STR
}
FORCE
)
...
...
dlib/dnn/curand_dlibapi.cpp
0 → 100644
View file @
141b384b
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_DNN_CuRAND_CPP_
#define DLIB_DNN_CuRAND_CPP_
#ifdef DLIB_USE_CUDA
#include "curand_dlibapi.h"
#include <curand.h>
#include "../string.h"
namespace
dlib
{
namespace
cuda
{
// ----------------------------------------------------------------------------------------
// 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
));
}
}
// ----------------------------------------------------------------------------------------
curand_generator
::
curand_generator
(
unsigned
long
long
seed
)
:
handle
(
nullptr
)
{
curandGenerator_t
gen
;
check
(
curandCreateGenerator
(
&
gen
,
CURAND_RNG_PSEUDO_DEFAULT
));
handle
=
gen
;
check
(
curandSetPseudoRandomGeneratorSeed
(
gen
,
seed
));
}
curand_generator
::
~
curand_generator
()
{
if
(
handle
)
{
curandDestroyGenerator
((
curandGenerator_t
)
handle
);
}
}
void
curand_generator
::
fill_gaussian
(
tensor
&
data
,
float
mean
,
float
stddev
)
{
if
(
data
.
size
()
==
0
)
return
;
check
(
curandGenerateNormal
((
curandGenerator_t
)
handle
,
data
.
device
(),
data
.
size
(),
mean
,
stddev
));
}
void
curand_generator
::
fill_uniform
(
tensor
&
data
)
{
if
(
data
.
size
()
==
0
)
return
;
check
(
curandGenerateUniform
((
curandGenerator_t
)
handle
,
data
.
device
(),
data
.
size
()));
}
// -----------------------------------------------------------------------------------
}
}
#endif // DLIB_USE_CUDA
#endif // DLIB_DNN_CuRAND_CPP_
dlib/dnn/curand_dlibapi.h
0 → 100644
View file @
141b384b
// Copyright (C) 2015 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_DNN_CuRAND_H_
#define DLIB_DNN_CuRAND_H_
#ifdef DLIB_USE_CUDA
#include "tensor.h"
#include "../error.h"
namespace
dlib
{
namespace
cuda
{
// -----------------------------------------------------------------------------------
struct
curand_error
:
public
error
{
curand_error
(
const
std
::
string
&
message
)
:
error
(
message
)
{}
};
// ----------------------------------------------------------------------------------------
class
curand_generator
{
public
:
// not copyable
curand_generator
(
const
curand_generator
&
)
=
delete
;
curand_generator
&
operator
=
(
const
curand_generator
&
)
=
delete
;
curand_generator
()
:
curand_generator
(
0
)
{}
curand_generator
(
unsigned
long
long
seed
);
~
curand_generator
();
void
fill_gaussian
(
tensor
&
data
,
float
mean
,
float
stddev
);
/*!
requires
- data.size()%2 == 0
ensures
- Fills data with random numbers drawn from a Gaussian distribution
with the given mean and standard deviation.
!*/
void
fill_uniform
(
tensor
&
data
);
/*!
ensures
- Fills data with uniform random numbers in the range (0.0, 1.0].
!*/
private
:
void
*
handle
;
};
// -----------------------------------------------------------------------------------
}
}
#endif // DLIB_USE_CUDA
#endif // DLIB_DNN_CuRAND_H_
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