#pragma once #include #include "glog/logging.h" #include "paddle/framework/eigen.h" #include "paddle/framework/operator.h" namespace paddle { namespace operators { template bool Gaussian(DeviceContext& ctx, framework::Tensor* output, const int size, const T& mean, const T& std, const T& seed); template bool Gaussian(platform::CPUDeviceContext& ctx, framework::Tensor* output, const int size, const T& mean, const T& std, const T& seed); template bool Gaussian(platform::CUDADeviceContext& ctx, framework::Tensor* output, const int size, const T& mean, const T& std, const T& seed); template class RandomOpKernel : public framework::OpKernel { public: void Compute(const framework::KernelContext& context) const override { auto mean = context.op_.GetAttr("mean"); auto std = context.op_.GetAttr("std"); auto seed = context.op_.GetAttr("seed"); auto* output = context.Output(0)->GetMutable(); output->mutable_data(context.GetPlace()); Gaussian(context.device_context_, output, framework::product(output->dims()), mean, std, seed); // Gaussian(context.device_context_, // output, // framework::product(output->dims()), // mean, std, seed); // std::default_random_engine generator(seed); // std::normal_distribution distribution(mean, std); // framework::EigenMatrix::From(*output).device(*( // context.GetEigenDevice())) = // framework::EigenMatrix::Random(); } }; // using paddle::platform::CPUPlace; // template // class RandomOpKernel : public framework::OpKernel { // public: // void Compute(const framework::KernelContext& context) const override { // std::unique_ptr generator(seed); // for(size_t i=0; i < output->size(); ++i) { // output[i] = distribution(generator()); // } // } // }; // using paddle::platform::GPUPlace; // template // class RandomOpKernel : public framework::OpKernel { // public: // void Compute(const framework::KernelContext& context) const override { // } // } } // namespace operators } // namespace paddle