You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by li...@apache.org on 2017/12/30 02:22:07 UTC

[incubator-mxnet] branch v1.0.0 updated: fix link error for parallel rng (#9256)

This is an automated email from the ASF dual-hosted git repository.

liuyizhi pushed a commit to branch v1.0.0
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/v1.0.0 by this push:
     new ecf4c9f  fix link error for parallel rng (#9256)
ecf4c9f is described below

commit ecf4c9f41b6ac97b3aab0c2545cfeef4420248ad
Author: Yizhi Liu <ja...@gmail.com>
AuthorDate: Fri Dec 29 18:16:07 2017 -0800

    fix link error for parallel rng (#9256)
---
 src/common/random_generator.cu |  6 ++++++
 src/common/random_generator.h  | 25 +++++++++++++------------
 src/operator/random/sampler.h  |  6 +++---
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/common/random_generator.cu b/src/common/random_generator.cu
index 5f6ac44..edb3d4e 100644
--- a/src/common/random_generator.cu
+++ b/src/common/random_generator.cu
@@ -31,6 +31,12 @@ namespace mxnet {
 namespace common {
 namespace random {
 
+template<>
+const int RandGenerator<gpu, float>::kMinNumRandomPerThread = 64;
+
+template<>
+const int RandGenerator<gpu, float>::kNumRandomStates = 32768;
+
 __global__ void rand_generator_seed_kernel(curandStatePhilox4_32_10_t *states_,
                                            const int size,
                                            uint32_t seed) {
diff --git a/src/common/random_generator.h b/src/common/random_generator.h
index 21db9d7..01cbbd1 100644
--- a/src/common/random_generator.h
+++ b/src/common/random_generator.h
@@ -47,9 +47,9 @@ template<typename DType>
 class RandGenerator<cpu, DType> {
  public:
   // at least how many random numbers should be generated by one CPU thread.
-  static const int kMinNumRandomPerThread = 64;
+  static const int kMinNumRandomPerThread;
   // store how many global random states for CPU.
-  static const int kNumRandomStates = 1024;
+  static const int kNumRandomStates;
 
   // implementation class for random number generator
   class Impl {
@@ -96,7 +96,13 @@ class RandGenerator<cpu, DType> {
 
  private:
   std::mt19937 *states_;
-};
+};  // class RandGenerator<cpu, DType>
+
+template<typename DType>
+const int RandGenerator<cpu, DType>::kMinNumRandomPerThread = 64;
+
+template<typename DType>
+const int RandGenerator<cpu, DType>::kNumRandomStates = 1024;
 
 #if MXNET_USE_CUDA
 
@@ -104,9 +110,9 @@ template<typename DType>
 class RandGenerator<gpu, DType> {
  public:
   // at least how many random numbers should be generated by one GPU thread.
-  static const int kMinNumRandomPerThread = 64;
+  static const int kMinNumRandomPerThread;
   // store how many global random states for GPU.
-  static const int kNumRandomStates = 32768;
+  static const int kNumRandomStates;
 
   // uniform number generation in Cuda made consistent with stl (include 0 but exclude 1)
   // by using 1.0-curand_uniform().
@@ -159,16 +165,11 @@ class RandGenerator<gpu, DType> {
 
  private:
   curandStatePhilox4_32_10_t *states_;
-};
+};  // class RandGenerator<gpu, DType>
 
 template<>
 class RandGenerator<gpu, double> {
  public:
-  // at least how many random numbers should be generated by one GPU thread.
-  static const int kMinNumRandomPerThread = 64;
-  // store how many global random states for GPU.
-  static const int kNumRandomStates = 32768;
-
   // uniform number generation in Cuda made consistent with stl (include 0 but exclude 1)
   // by using 1.0-curand_uniform().
   // Needed as some samplers in sampler.h won't be able to deal with
@@ -209,7 +210,7 @@ class RandGenerator<gpu, double> {
 
  private:
   curandStatePhilox4_32_10_t *states_;
-};
+};  // class RandGenerator<gpu, double>
 
 #endif  // MXNET_USE_CUDA
 
diff --git a/src/operator/random/sampler.h b/src/operator/random/sampler.h
index 8eace1e..e211e75 100644
--- a/src/operator/random/sampler.h
+++ b/src/operator/random/sampler.h
@@ -44,9 +44,9 @@ template<typename OP, typename xpu, typename GType, typename ...Args>
 inline static void LaunchRNG(mshadow::Stream<xpu> *s,
                              common::random::RandGenerator<xpu, GType> *gen,
                              const int N, Args... args) {
-  const int nloop = (N + RandGenerator<xpu, GType>::kMinNumRandomPerThread - 1) /
-                    RandGenerator<xpu, GType>::kMinNumRandomPerThread;
-  const int nthread = std::min(nloop, RandGenerator<xpu, GType>::kNumRandomStates);
+  const int nloop = (N + RandGenerator<xpu>::kMinNumRandomPerThread - 1) /
+                    RandGenerator<xpu>::kMinNumRandomPerThread;
+  const int nthread = std::min(nloop, RandGenerator<xpu>::kNumRandomStates);
   const int step = (N + nthread - 1) / nthread;
   Kernel<OP, xpu>::Launch(s, nthread, *gen, N, step, args...);
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@mxnet.apache.org" <co...@mxnet.apache.org>'].