samskalicky commented on a change in pull request #17762: Custom Operator
Random Number Generator Support
URL: https://github.com/apache/incubator-mxnet/pull/17762#discussion_r399043126
##########
File path: example/extensions/lib_custom_op/relu_lib.cu
##########
@@ -180,6 +182,75 @@ REGISTER_OP(my_state_relu)
.setCreateOpState(createOpStateCPU, "cpu")
.setCreateOpState(createOpStateGPU, "gpu");
+
+
+/* ------------------------ Below is noisy relu operator example
---------------------*/
+
+#include <curand_kernel.h>
+#include <random>
+
+#define NumRandomPerThread 64 // mxnet recommended random numbers generated
per thread
+
+__global__ void noisy_relu_gpu_forward(float *out, float *in, int64_t N, void
*states, int step) {
+ int tid = blockIdx.x * blockDim.x + threadIdx.x;
+ curandStatePhilox4_32_10_t* global_states =
(curandStatePhilox4_32_10_t*)states;
+ curandStatePhilox4_32_10_t thread_state = global_states[tid];
+
+ int start = tid * step;
+ int end = start + step;
+ for (int i=start; i<end && i<N; ++i) {
+ float noise = curand_normal(&thread_state);
+ out[i] = in[i] + noise > 0 ? in[i] + noise : 0;
Review comment:
can you add some comments to explain how/why you're calculating this for
noisy relu?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services