uniform_random_kernel.cc 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

15 16 17 18
#include "paddle/phi/kernels/selected_rows/uniform_random_kernel.h"

#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
19
#include "paddle/phi/core/kernel_registry.h"
20
#include "paddle/phi/kernels/uniform_random_kernel.h"
21 22

namespace phi {
23
namespace sr {
24 25

template <typename T, typename Context>
26 27 28 29 30 31 32 33 34 35
void UniformRandomRawKernel(const Context& dev_ctx,
                            const ScalarArray& shape,
                            DataType dtype,
                            float min,
                            float max,
                            int seed,
                            int diag_num,
                            int diag_step,
                            float diag_val,
                            SelectedRows* out) {
36 37 38 39 40 41 42 43 44 45 46 47 48
  phi::UniformRandomRawKernel<T>(dev_ctx,
                                 shape,
                                 dtype,
                                 min,
                                 max,
                                 seed,
                                 diag_num,
                                 diag_step,
                                 diag_val,
                                 out->mutable_value());
}

template <typename T, typename Context>
49 50 51 52 53 54 55
void UniformRandomKernel(const Context& dev_ctx,
                         const ScalarArray& shape,
                         DataType dtype,
                         float min,
                         float max,
                         int seed,
                         SelectedRows* out) {
56 57 58 59
  phi::UniformRandomKernel<T>(
      dev_ctx, shape, dtype, min, max, seed, out->mutable_value());
}

60
}  // namespace sr
61 62 63 64 65
}  // namespace phi

PD_REGISTER_KERNEL(uniform_random_raw_sr,
                   CPU,
                   ALL_LAYOUT,
66
                   phi::sr::UniformRandomRawKernel,
67 68 69 70 71 72 73
                   float,
                   double,
                   phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(uniform_random_sr,
                   CPU,
                   ALL_LAYOUT,
74
                   phi::sr::UniformRandomKernel,
75 76 77 78 79 80 81 82 83
                   float,
                   double,
                   phi::dtype::bfloat16) {}

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)

PD_REGISTER_KERNEL(uniform_random_raw_sr,
                   GPU,
                   ALL_LAYOUT,
84
                   phi::sr::UniformRandomRawKernel,
85 86 87 88 89 90
                   float,
                   double) {}

PD_REGISTER_KERNEL(uniform_random_sr,
                   GPU,
                   ALL_LAYOUT,
91
                   phi::sr::UniformRandomKernel,
92 93 94
                   float,
                   double) {}
#endif