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

Function GenerateKey

tensorflow/core/kernels/stateless_random_ops.cc:30–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28using GPUDevice = Eigen::GpuDevice;
29
30Status GenerateKey(Tensor seed, random::PhiloxRandom::Key* out_key,
31 random::PhiloxRandom::ResultType* out_counter) {
32 // Grab the two seeds
33 uint64 seed0;
34 uint64 seed1;
35 if (seed.dtype() == DT_INT32) {
36 const auto seed_vals = seed.flat<int32>();
37 seed0 = internal::SubtleMustCopy(seed_vals(0));
38 seed1 = internal::SubtleMustCopy(seed_vals(1));
39 } else if (seed.dtype() == DT_INT64) {
40 const auto seed_vals = seed.flat<int64>();
41 seed0 = internal::SubtleMustCopy(seed_vals(0));
42 seed1 = internal::SubtleMustCopy(seed_vals(1));
43 } else {
44 return errors::InvalidArgument("Invalid seed type: ",
45 DataTypeString(seed.dtype()));
46 }
47
48 // Scramble the seeds so that the user doesn't need to worry about which
49 // part of the seed needs to be strong.
50 (*out_key)[0] = 0x3ec8f720;
51 (*out_key)[1] = 0x02461e29;
52 (*out_counter)[0] = static_cast<uint32>(seed0);
53 (*out_counter)[1] = static_cast<uint32>(seed0 >> 32);
54 (*out_counter)[2] = static_cast<uint32>(seed1);
55 (*out_counter)[3] = static_cast<uint32>(seed1 >> 32);
56 const auto mix = random::PhiloxRandom(*out_counter, *out_key)();
57 (*out_key)[0] = mix[0];
58 (*out_key)[1] = mix[1];
59 (*out_counter)[0] = (*out_counter)[1] = 0;
60 (*out_counter)[2] = mix[2];
61 (*out_counter)[3] = mix[3];
62 return Status::OK();
63}
64
65namespace {
66

Callers 2

ComputeMethod · 0.85
ComputeMethod · 0.85

Calls 5

SubtleMustCopyFunction · 0.85
InvalidArgumentFunction · 0.85
PhiloxRandomClass · 0.85
DataTypeStringFunction · 0.50
dtypeMethod · 0.45

Tested by

no test coverage detected