You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/12/30 02:16:11 UTC

[GitHub] javelinjs closed pull request #9256: fix link error for parallel rng

javelinjs closed pull request #9256: fix link error for parallel rng
URL: https://github.com/apache/incubator-mxnet/pull/9256
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/common/random_generator.cu b/src/common/random_generator.cu
index 5f6ac4469e..edb3d4e26e 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 21db9d7a72..01cbbd166f 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 8eace1e092..e211e7547c 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...);
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services