Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XLA] Seed each convolution with the same rng state, so that the conv… #29499

Merged
merged 1 commit into from
Jun 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions tensorflow/compiler/xla/service/gpu/cudnn_conv_algorithm_picker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ UniformDistribution(T lhs, T rhs, Generator* gen) {
}

template <typename T>
void InitializeTypedBuffer(se::Stream* stream, se::DeviceMemory<T> buffer) {
void InitializeTypedBuffer(se::Stream* stream, se::DeviceMemory<T> buffer,
int64* rng_state) {
static_assert(
std::is_floating_point<T>::value || std::is_same<T, Eigen::half>::value,
"Unimplemented for integers yet.");
Expand All @@ -275,7 +276,8 @@ void InitializeTypedBuffer(se::Stream* stream, se::DeviceMemory<T> buffer) {
}
return ret;
}();
static int64 host_index = 0;

int64& host_index = *rng_state;

char* current_addr = static_cast<char*>(buffer.opaque());
CHECK_EQ(0, buffer.size() % sizeof(T));
Expand Down Expand Up @@ -326,17 +328,22 @@ StatusOr<AutotuneResult> CudnnConvAlgorithmPicker::PickBestAlgorithmNoCache(
allocator = &*se_allocator;
}

const auto initialize_buffer = [&stream,
&result_shape](DeviceMemoryBase buffer) {
int64 rng_state = 0;

const auto initialize_buffer = [&stream, &result_shape,
&rng_state](DeviceMemoryBase buffer) {
switch (result_shape.element_type()) {
case xla::F16:
InitializeTypedBuffer(&stream, se::DeviceMemory<Eigen::half>(buffer));
InitializeTypedBuffer(&stream, se::DeviceMemory<Eigen::half>(buffer),
&rng_state);
break;
case xla::F32:
InitializeTypedBuffer(&stream, se::DeviceMemory<float>(buffer));
InitializeTypedBuffer(&stream, se::DeviceMemory<float>(buffer),
&rng_state);
break;
case xla::F64:
InitializeTypedBuffer(&stream, se::DeviceMemory<double>(buffer));
InitializeTypedBuffer(&stream, se::DeviceMemory<double>(buffer),
&rng_state);
break;
default:
stream.ThenMemZero(&buffer, buffer.size());
Expand Down