本文整理汇总了C++中CURAND_CHECK函数的典型用法代码示例。如果您正苦于以下问题:C++ CURAND_CHECK函数的具体用法?C++ CURAND_CHECK怎么用?C++ CURAND_CHECK使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CURAND_CHECK函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CURAND_CHECK
void Caffe::set_random_seed(const unsigned int seed) {
if (Caffe::GetDefaultDeviceContext()->backend() == BACKEND_CUDA) {
#ifdef USE_CUDA
// Curand seed
static bool g_curand_availability_logged = false;
if (Get().curand_generator_) {
CURAND_CHECK(
curandSetPseudoRandomGeneratorSeed(curand_generator(), seed));
CURAND_CHECK(curandSetGeneratorOffset(curand_generator(), 0));
} else {
if (!g_curand_availability_logged) {
LOG(ERROR)<<
"Curand not available. Skipping setting the curand seed.";
g_curand_availability_logged = true;
}
}
#endif // USE_CUDA
} else {
#ifdef USE_GREENTEA
// TODO: Proper RNG and Seed for OpenCL
#endif // USE_GREENTEA
}
// RNG seed
Get().random_generator_.reset(new RNG(seed));
}
示例2: CUDA_CHECK
void Caffe::SetDevice(const int device_id) {
int current_device;
CUDA_CHECK(cudaGetDevice(¤t_device));
if (current_device == device_id) {
return;
}
// The call to cudaSetDevice must come before any calls to Get, which
// may perform initialization using the GPU.
CUDA_CHECK(cudaSetDevice(device_id));
if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));
if (Get().cusparse_descr_)CUSPARSE_CHECK(cusparseDestroyMatDescr(Get().cusparse_descr_));
if (Get().cusparse_handle_)CUSPARSE_CHECK(cusparseDestroy(Get().cusparse_handle_));
if (Get().curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
}
CUSPARSE_CHECK(cusparseCreate(&Get().cusparse_handle_));
CUSPARSE_CHECK(cusparseCreateMatDescr(&Get().cusparse_descr_));
// cusparseSetMatType(cusparse_descr_,CUSPARSE_MATRIX_TYPE_GENERAL);
// cusparseSetMatIndexBase(cusparse_descr_,CUSPARSE_INDEX_BASE_ZERO);
LOG(INFO)<<"set descr";
CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,
cluster_seedgen()));
}
示例3: if
void Caffe::set_random_seed(uint64_t random_seed) {
if (root_seed_.load() == Caffe::SEED_NOT_SET) {
root_seed_.store(random_seed);
} else if (random_seed == Caffe::SEED_NOT_SET) {
return; // i.e. root solver was previously set to 0+ and there is no need to re-generate
}
#ifndef CPU_ONLY
{
// Curand seed
std::lock_guard<std::mutex> lock(seed_mutex_);
if (random_seed == Caffe::SEED_NOT_SET) {
random_seed = cluster_seedgen();
}
static bool g_curand_availability_logged = false;
curandGenerator_t curand_generator_handle = curand_generator();
if (curand_generator_handle) {
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(curand_generator_handle, random_seed));
CURAND_CHECK(curandSetGeneratorOffset(curand_generator_handle, 0));
} else if (!g_curand_availability_logged) {
LOG(ERROR) << "Curand not available. Skipping setting the curand seed.";
g_curand_availability_logged = true;
}
}
#endif
// RNG seed
Get().random_generator_.reset(new RNG(random_seed));
}
示例4: CURAND_CHECK
void Caffe::set_random_seed(unsigned int seed)
{
CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_, CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_, seed));
VSL_CHECK(vslDeleteStream(&Get().vsl_stream_));
VSL_CHECK(vslNewStream(&Get().vsl_stream_, VSL_BRNG_MT19937, seed));
}
示例5: mode_
Caffe::Caffe()
: mode_(Caffe::CPU), phase_(Caffe::TRAIN), cublas_handle_(NULL),
curand_generator_(NULL), vsl_stream_(NULL)
{
CUBLAS_CHECK(cublasCreate(&cublas_handle_));
//TODO: original caffe code has bug here!
CURAND_CHECK(curandCreateGenerator(&curand_generator_, CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(curand_generator_, 1701ULL));
VSL_CHECK(vslNewStream(&vsl_stream_, VSL_BRNG_MT19937, 1701));
}
示例6: TEST_F
TEST_F(CommonTest, TestRandSeedGPU) {
SyncedMemory data_a(10 * sizeof(unsigned int));
SyncedMemory data_b(10 * sizeof(unsigned int));
Caffe::set_random_seed(1701);
CURAND_CHECK(curandGenerate(Caffe::curand_generator(),
static_cast<unsigned int*>(data_a.mutable_gpu_data()), 10));
Caffe::set_random_seed(1701);
CURAND_CHECK(curandGenerate(Caffe::curand_generator(),
static_cast<unsigned int*>(data_b.mutable_gpu_data()), 10));
for (int i = 0; i < 10; ++i) {
EXPECT_EQ(((const unsigned int*)(data_a.cpu_data()))[i],
((const unsigned int*)(data_b.cpu_data()))[i]);
}
}
示例7: CURAND_CHECK
void Caffe::set_random_seed(const unsigned int seed) {
// Curand seed
// Yangqing's note: simply setting the generator seed does not seem to
// work on the tesla K20s, so I wrote the ugly reset thing below.
if (Get().curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(curand_generator()));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(curand_generator(),
seed));
} else {
LOG(ERROR) << "Curand not available. Skipping setting the curand seed.";
}
// RNG seed
Get().random_generator_.reset(new RNG(seed));
}
示例8: CURAND_CHECK
// implements for CPU/GPU Manager
void Dragon::set_random_seed(const unsigned int seed) {
// Curand seed
static bool g_curand_availability_logged = false;
if (get_curand_generator()) {
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(get_curand_generator(), seed));
CURAND_CHECK(curandSetGeneratorOffset(get_curand_generator(), 0));
}
else {
if (!g_curand_availability_logged) {
LOG(ERROR) <<"Curand not available. Skipping setting the curand seed.";
g_curand_availability_logged = true;
}
}
// RNG seed
Get().random_generator.reset(new RNG(seed));
}
示例9: CUDA_CHECK
void Caffe::SetDevice(const int device_id) {
int current_device;
CUDA_CHECK(cudaGetDevice(¤t_device));
if (current_device == device_id) {
return;
}
if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));
if (Get().curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
}
CUDA_CHECK(cudaSetDevice(device_id));
CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,
cluster_seedgen()));
}
示例10: CURAND_CHECK
Caffe::~Caffe() {
if (cusparse_descr_) CUSPARSE_CHECK(cusparseDestroyMatDescr(cusparse_descr_));
if (cublas_handle_) CUBLAS_CHECK(cublasDestroy(cublas_handle_));
if (cusparse_handle_) CUSPARSE_CHECK(cusparseDestroy(cusparse_handle_));
if (curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(curand_generator_));
}
}
示例11: CUBLAS_CHECK
Caffe::~Caffe()
{
if (cublas_handle_)
CUBLAS_CHECK(cublasDestroy(cublas_handle_));
if (curand_generator_)
CURAND_CHECK(curandDestroyGenerator(curand_generator_));
if (vsl_stream_)
VSL_CHECK(vslDeleteStream(&vsl_stream_));
}
示例12: CUDA_CHECK
void Engine::SetDevice(const int device_id) {
int current_device;
CUDA_CHECK(cudaGetDevice(¤t_device));
if (current_device == device_id) {
return;
}
// The call to cudaSetDevice must come before any calls to Get, which
// may perform initialization using the GPU.
CUDA_CHECK(cudaSetDevice(device_id));
if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));
if (Get().curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
}
CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,
cluster_seedgen()));
}
示例13: CUBLAS_CHECK
Caffe::~Caffe() {
// Make sure all device contexts and
// dependent memory blocks are freed properly
device_contexts_.clear();
#ifdef USE_CUDA
if (cublas_handle_)
CUBLAS_CHECK(cublasDestroy(cublas_handle_));
if (curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(curand_generator_));
}
#endif // USE_CUDA
}
示例14: TEST_F
TEST_F(CommonTest, TestRandSeedGPU) {
device *dc = Caffe::GetDefaultDevice();
if (dc->backend() == BACKEND_CUDA) {
#ifdef USE_CUDA
SyncedMemory data_a(10 * sizeof(unsigned int),
Caffe::GetDefaultDevice());
SyncedMemory data_b(10 * sizeof(unsigned int),
Caffe::GetDefaultDevice());
Caffe::set_random_seed(1701, Caffe::GetDefaultDevice());
CURAND_CHECK(curandGenerate(Caffe::curand_generator(),
static_cast<unsigned int*>(data_a.mutable_gpu_data()), 10));
Caffe::set_random_seed(1701, Caffe::GetDefaultDevice());
CURAND_CHECK(curandGenerate(Caffe::curand_generator(),
static_cast<unsigned int*>(data_b.mutable_gpu_data()), 10));
for (int i = 0; i < 10; ++i) {
EXPECT_EQ(((const unsigned int*)(data_a.cpu_data()))[i],
((const unsigned int*)(data_b.cpu_data()))[i]);
}
#endif // USE_CUDA
}
}
示例15: CUDA_CHECK
void Caffe::SetSlaveDevice(const int slave_device_id) {
int current_device;
CUDA_CHECK(cudaGetDevice(¤t_device));
if (current_device == slave_device_id) {
return;
}
if (Get().slave_cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().slave_cublas_handle_));
if (Get().slave_curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(Get().slave_curand_generator_));
}
CUDA_CHECK(cudaSetDevice(slave_device_id));
CUDA_CHECK(cudaStreamCreate (&Get().slave_cu_stream_));
CUBLAS_CHECK(cublasCreate(&Get().slave_cublas_handle_));
CUBLAS_CHECK(cublasSetStream(Get().slave_cublas_handle_, Get().slave_cu_stream_));
CURAND_CHECK(curandCreateGenerator(&Get().slave_curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().slave_curand_generator_,
cluster_seedgen()));
Get().slave_device_id_ = slave_device_id;
CUDA_CHECK(cudaSetDevice(current_device));
Caffe::set_gpu_mode(Caffe::MASTER_SLAVE);
}