MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BitGen

Function BitGen

tensorflow/compiler/tf2xla/kernels/stateful_random_ops.cc:40–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38namespace {
39
40xla::BitGeneratorTy BitGen(Algorithm alg) {
41 if (alg == RNG_ALG_PHILOX) {
42 return [=](xla::XlaOp key, xla::XlaOp state, const xla::Shape& shape) {
43 state =
44 xla::ConcatInDim(key.builder(), {xla::Reshape(key, {1}), state}, 0);
45 xla::XlaOp result =
46 xla::RngBitGenerator(xla::RandomAlgorithm::RNG_PHILOX, state, shape);
47 xla::XlaOp data = xla::GetTupleElement(result, 1);
48 xla::XlaOp new_state =
49 xla::Slice(xla::GetTupleElement(result, 0), {1}, {3}, {1});
50 return xla::RngOutput{data, new_state};
51 };
52 } else {
53 return [=](xla::XlaOp key, xla::XlaOp state, const xla::Shape& shape) {
54 state = xla::ConcatScalars(key.builder(), {key, state});
55 xla::XlaOp result = xla::RngBitGenerator(
56 xla::RandomAlgorithm::RNG_THREE_FRY, state, shape);
57 xla::XlaOp data = xla::GetTupleElement(result, 1);
58 xla::XlaOp new_state = xla::Reshape(
59 xla::Slice(xla::GetTupleElement(result, 0), {1}, {2}, {1}), {});
60 return xla::RngOutput{data, new_state};
61 };
62 }
63}
64
65xla::RngOutput StatefulRngUniform(Algorithm alg, xla::XlaOp key,
66 xla::XlaOp initial_state,

Callers 3

StatefulRngUniformFunction · 0.85
CompileMethod · 0.85

Calls 7

ConcatInDimFunction · 0.85
RngBitGeneratorFunction · 0.85
ConcatScalarsFunction · 0.85
ReshapeFunction · 0.50
GetTupleElementFunction · 0.50
SliceFunction · 0.50
builderMethod · 0.45

Tested by

no test coverage detected