You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by an...@apache.org on 2018/09/13 01:36:45 UTC

[incubator-mxnet] branch master updated: Fix/public internal header (#12374)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7735fa6  Fix/public internal header (#12374)
7735fa6 is described below

commit 7735fa65ba533aecbc473427369da01ea06d9443
Author: Alexander Zai <az...@gmail.com>
AuthorDate: Wed Sep 12 18:36:34 2018 -0700

    Fix/public internal header (#12374)
    
    * 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
---
 {src/common => include/mxnet}/random_generator.h | 21 +++++++++------------
 include/mxnet/resource.h                         |  2 +-
 src/common/random_generator.cu                   | 13 ++++++++++++-
 src/operator/leaky_relu-inl.h                    |  2 +-
 src/resource.cc                                  |  2 +-
 5 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/common/random_generator.h b/include/mxnet/random_generator.h
similarity index 92%
rename from src/common/random_generator.h
rename to include/mxnet/random_generator.h
index 5d78b61..6e37efd 100644
--- a/src/common/random_generator.h
+++ b/include/mxnet/random_generator.h
@@ -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 {
@@ -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,
@@ -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;
@@ -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);
 
@@ -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;
@@ -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_
diff --git a/include/mxnet/resource.h b/include/mxnet/resource.h
index 74ae7e3..67c14b6 100644
--- a/include/mxnet/resource.h
+++ b/include/mxnet/resource.h
@@ -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 {
 
diff --git a/src/common/random_generator.cu b/src/common/random_generator.cu
index 930e5e0..a2d3e0d 100644
--- a/src/common/random_generator.cu
+++ b/src/common/random_generator.cu
@@ -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 {
@@ -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
diff --git a/src/operator/leaky_relu-inl.h b/src/operator/leaky_relu-inl.h
index 1c4f48b..1d2baa4 100644
--- a/src/operator/leaky_relu-inl.h
+++ b/src/operator/leaky_relu-inl.h
@@ -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"
diff --git a/src/resource.cc b/src/resource.cc
index 2794d48..ba4ab72 100644
--- a/src/resource.cc
+++ b/src/resource.cc
@@ -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 {