1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_KERNELS_RANDOM_OP_H_
17#define TENSORFLOW_CORE_KERNELS_RANDOM_OP_H_
18
19#include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
20#include "tensorflow/core/lib/random/random_distributions.h"
21
22namespace tensorflow {
23
24class OpKernelContext;
25
26namespace functor {
27
28template <typename Device, class Distribution>
29struct FillPhiloxRandom;
30
31typedef Eigen::ThreadPoolDevice CPUDevice;
32// Declares the partially CPU-specialized functor struct.
33//
34// NOTE: Due to inlining done by the compiler, you may need to add
35// explicit instantiation of the functor in random_op.cc. See example
36// functor::FillPhiloxRandom<CPUDevice, random::UniformDistribution>.
37//
38// This functor can take the PhiloxRandom input from either device memory `key`
39// and `counter` or a stack value `gen`. If both `key` and `counter` are not
40// nullptr, they provide the input; otherwise `gen` provides the input.
41template <class Distribution>
42struct FillPhiloxRandom<CPUDevice, Distribution> {
43 void operator()(OpKernelContext* ctx, const CPUDevice& d, const uint64* key,
44 const uint64* counter, random::PhiloxRandom gen,
45 typename Distribution::ResultElementType* data, int64_t size,
46 Distribution dist);
47};
48
49#if GOOGLE_CUDA || TENSORFLOW_USE_ROCM
50typedef Eigen::GpuDevice GPUDevice;
51// Declares the partially GPU-specialized functor struct.
52template <class Distribution>
53struct FillPhiloxRandom<GPUDevice, Distribution> {
54 void operator()(OpKernelContext* ctx, const GPUDevice& d, const uint64* key,
55 const uint64* counter, random::PhiloxRandom gen,
56 typename Distribution::ResultElementType* data, int64_t size,
57 Distribution dist);
58};
59#endif // GOOGLE_CUDA || TENSORFLOW_USE_ROCM
60
61} // namespace functor
62} // namespace tensorflow
63
64#endif // TENSORFLOW_CORE_KERNELS_RANDOM_OP_H_
65