parent
2447c34a0e
commit
0f8c9dbe61
@ -1,30 +1,30 @@
|
|||||||
#include "paddle/operators/random_op.h"
|
|
||||||
#include "paddle/framework/op_registry.h"
|
#include "paddle/framework/op_registry.h"
|
||||||
|
#include "paddle/operators/guassian_random_op.h"
|
||||||
|
|
||||||
namespace paddle {
|
namespace paddle {
|
||||||
namespace operators {
|
namespace operators {
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
class GaussianRandomOpKernel<platform::GPUPlace, T> : public framework::OpKernel {
|
class GaussianRandomOpKernel<platform::GPUPlace, T>
|
||||||
public:
|
: public framework::OpKernel {
|
||||||
|
public:
|
||||||
void Compute(const framework::KernelContext& context) const override {
|
void Compute(const framework::KernelContext& context) const override {
|
||||||
auto mean = context.op_.GetAttr<T>("mean");
|
auto mean = context.op_.GetAttr<T>("mean");
|
||||||
auto std = context.op_.GetAttr<T>("std");
|
auto std = context.op_.GetAttr<T>("std");
|
||||||
auto* output = context.Output(0)->GetMutable<framework::Tensor>();
|
auto* output = context.Output(0)->GetMutable<framework::Tensor>();
|
||||||
T* r = output->mutable_data<T>(context.GetPlace());
|
T* r = output->mutable_data<T>(context.GetPlace());
|
||||||
auto ctx = static_cast<const platform::GPUDeviceContext*>
|
auto ctx =
|
||||||
(context.device_context_);
|
static_cast<const platform::GPUDeviceContext*>(context.device_context_);
|
||||||
// generator need to modify context
|
// generator need to modify context
|
||||||
auto g = const_cast<platform::GPUDeviceContext*>(ctx)->RandGenerator();
|
auto g = const_cast<platform::GPUDeviceContext*>(ctx)->RandGenerator();
|
||||||
curandGenerateNormal(g, r, framework::product(output->dims()), mean, std);
|
curandGenerateNormal(g, r, framework::product(output->dims()), mean, std);
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace operators
|
} // namespace operators
|
||||||
} // namespace paddle
|
} // namespace paddle
|
||||||
|
|
||||||
|
|
||||||
typedef paddle::operators::GaussianRandomOpKernel<paddle::platform::GPUPlace, float>
|
typedef paddle::operators::GaussianRandomOpKernel<paddle::platform::GPUPlace,
|
||||||
RandomOpKernel_GPU_float;
|
float>
|
||||||
|
RandomOpKernel_GPU_float;
|
||||||
REGISTER_OP_GPU_KERNEL(gaussian_random, GaussianRandomOpKernel_GPU_float);
|
REGISTER_OP_GPU_KERNEL(gaussian_random, GaussianRandomOpKernel_GPU_float);
|
Loading…
Reference in new issue