Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix/public internal header (#12374)
Browse files Browse the repository at this point in the history
* move random-gen header to internal code

* uncomment header

* remove public method from cc

* move cuda randgen logic to cc

* remove private files

* include correct header in cu random_gen

* fix include in cu random-gen

* fix template

* remove static kw

* add missing template expression

* change dtype to float

* remove old header

* fix lint

* fix imports

* fix space

* fix template

* fix template

* add todo

* fix lint
  • Loading branch information
azai91 authored and anirudh2290 committed Sep 13, 2018
1 parent b8153f6 commit 7735fa6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
21 changes: 9 additions & 12 deletions src/common/random_generator.h → include/mxnet/random_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,15 @@
* \file random_generator.h
* \brief Parallel random number generator.
*/
#ifndef MXNET_COMMON_RANDOM_GENERATOR_H_
#define MXNET_COMMON_RANDOM_GENERATOR_H_
#ifndef MXNET_RANDOM_GENERATOR_H_
#define MXNET_RANDOM_GENERATOR_H_

#include <mxnet/base.h>
#include <random>
#include <new>
#include "./base.h"

#if MXNET_USE_CUDA
#include <curand_kernel.h>
#include "../common/cuda_utils.h"
#endif // MXNET_USE_CUDA

namespace mxnet {
Expand All @@ -50,6 +49,7 @@ class RandGenerator<cpu, DType> {
static const int kNumRandomStates;

// implementation class for random number generator
// TODO(alexzai): move impl class to separate file - tracked in MXNET-948
class Impl {
public:
typedef typename std::conditional<std::is_floating_point<DType>::value,
Expand Down Expand Up @@ -116,6 +116,7 @@ class RandGenerator<gpu, DType> {
// by using 1.0-curand_uniform().
// Needed as some samplers in sampler.h won't be able to deal with
// one of the boundary cases.
// TODO(alexzai): move impl class to separate file - tracked in MXNET-948
class Impl {
public:
Impl &operator=(const Impl &) = delete;
Expand Down Expand Up @@ -150,14 +151,9 @@ class RandGenerator<gpu, DType> {
curandStatePhilox4_32_10_t state_;
}; // class RandGenerator<gpu, DType>::Impl

static void AllocState(RandGenerator<gpu, DType> *inst) {
CUDA_CALL(cudaMalloc(&inst->states_,
kNumRandomStates * sizeof(curandStatePhilox4_32_10_t)));
}
static void AllocState(RandGenerator<gpu, DType> *inst);

static void FreeState(RandGenerator<gpu, DType> *inst) {
CUDA_CALL(cudaFree(inst->states_));
}
static void FreeState(RandGenerator<gpu, DType> *inst);

void Seed(mshadow::Stream<gpu> *s, uint32_t seed);

Expand All @@ -172,6 +168,7 @@ class RandGenerator<gpu, double> {
// by using 1.0-curand_uniform().
// Needed as some samplers in sampler.h won't be able to deal with
// one of the boundary cases.
// TODO(alexzai): move impl class to separate file - tracked in MXNET-948
class Impl {
public:
Impl &operator=(const Impl &) = delete;
Expand Down Expand Up @@ -215,4 +212,4 @@ class RandGenerator<gpu, double> {
} // namespace random
} // namespace common
} // namespace mxnet
#endif // MXNET_COMMON_RANDOM_GENERATOR_H_
#endif // MXNET_RANDOM_GENERATOR_H_
2 changes: 1 addition & 1 deletion include/mxnet/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <dmlc/logging.h>
#include "./base.h"
#include "./engine.h"
#include "../../src/common/random_generator.h"
#include "./random_generator.h"

namespace mxnet {

Expand Down
13 changes: 12 additions & 1 deletion src/common/random_generator.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
* \brief gpu implements for parallel random number generator.
*/

#include <mxnet/random_generator.h>
#include <algorithm>
#include "./random_generator.h"
#include "../operator/mxnet_op.h"

namespace mxnet {
Expand Down Expand Up @@ -59,6 +59,17 @@ void RandGenerator<gpu, float>::Seed(mshadow::Stream<gpu> *s, uint32_t seed) {
s->Wait();
}

template<>
void RandGenerator<gpu, float>::AllocState(RandGenerator<gpu> *inst) {
CUDA_CALL(cudaMalloc(&inst->states_,
kNumRandomStates * sizeof(curandStatePhilox4_32_10_t)));
}

template<>
void RandGenerator<gpu, float>::FreeState(RandGenerator<gpu> *inst) {
CUDA_CALL(cudaFree(inst->states_));
}

} // namespace random
} // namespace common
} // namespace mxnet
2 changes: 1 addition & 1 deletion src/operator/leaky_relu-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <mxnet/random_generator.h>
#include <mxnet/operator.h>
#include <cstring>
#include <map>
#include <string>
#include <vector>
#include <utility>
#include "../common/random_generator.h"
#include "./operator_common.h"
#include "./mshadow_op.h"
#include "./random/sampler.h"
Expand Down
2 changes: 1 addition & 1 deletion src/resource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
#include <dmlc/thread_local.h>
#include <mxnet/base.h>
#include <mxnet/engine.h>
#include <mxnet/random_generator.h>
#include <mxnet/resource.h>
#include <mxnet/storage.h>
#include <limits>
#include <atomic>
#include "./common/lazy_alloc_array.h"
#include "./common/random_generator.h"
#include "./common/utils.h"

namespace mxnet {
Expand Down

0 comments on commit 7735fa6

Please sign in to comment.