| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9225636 commit 05c0502
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | # Description: | |
| 2 | 2 | # GPU-specific components in XLA service implementation. | |
| 3 | 3 | ||
| 4 | + load("//tensorflow/compiler/xla:xla.bzl", "xla_proto_library") | ||
| 5 | + | ||
| 4 | 6 | licenses(["notice"]) # Apache 2.0 | |
| 5 | 7 | ||
| 6 | 8 | package(default_visibility = [":friends"]) | |
@@ -23,6 +25,11 @@ filegroup( | |||
| 23 | 25 | ||
| 24 | 26 | load("//tensorflow:tensorflow.bzl", "tf_cc_test") | |
| 25 | 27 | ||
| 28 | + xla_proto_library( | ||
| 29 | + name = "backend_configs", | ||
| 30 | + srcs = ["backend_configs.proto"], | ||
| 31 | + ) | ||
| 32 | + | ||
| 26 | 33 | cc_library( | |
| 27 | 34 | name = "gpu_constants", | |
| 28 | 35 | srcs = ["gpu_constants.cc"], | |
@@ -133,6 +140,7 @@ cc_library( | |||
| 133 | 140 | "ir_emitter_unnested.h", | |
| 134 | 141 | ], | |
| 135 | 142 | deps = [ | |
| 143 | + ":backend_configs", | ||
| 136 | 144 | ":cudnn_convolution_runner", | |
| 137 | 145 | ":elemental_ir_emitter", | |
| 138 | 146 | ":gpu_constants", | |
@@ -266,6 +274,7 @@ cc_library( | |||
| 266 | 274 | "while_thunk.h", | |
| 267 | 275 | ], | |
| 268 | 276 | deps = [ | |
| 277 | + ":backend_configs", | ||
| 269 | 278 | ":buffer_allocations", | |
| 270 | 279 | ":cudnn_convolution_runner", | |
| 271 | 280 | ":infeed_manager", | |
@@ -322,6 +331,7 @@ cc_library( | |||
| 322 | 331 | srcs = ["cudnn_convolution_algorithm_picker.cc"], | |
| 323 | 332 | hdrs = ["cudnn_convolution_algorithm_picker.h"], | |
| 324 | 333 | deps = [ | |
| 334 | + ":backend_configs", | ||
| 325 | 335 | ":cudnn_convolution_runner", | |
| 326 | 336 | ":gpu_executable", | |
| 327 | 337 | ":ir_emission_utils", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,27 @@ | |||
| 1 | + syntax = "proto3"; | ||
| 2 | + | ||
| 3 | + package xla.gpu; | ||
| 4 | + | ||
| 5 | + // Backend configs for XLA:GPU. | ||
| 6 | + // | ||
| 7 | + // These are metadata that the GPU backend attaches to HloInstrucitons and later | ||
| 8 | + // uses during e.g. codegen. | ||
| 9 | + // | ||
| 10 | + // Remember that proto3 doesn't give clients a way to tell the difference | ||
| 11 | + // between a field not being present and a field having the default value. | ||
| 12 | + // Choose your defaults carefully. | ||
| 13 | + // | ||
| 14 | + // No guarantee is made about the stability of these protos. | ||
| 15 | + // | ||
| 16 | + // See HloInstruction::backend_config() for more info. | ||
| 17 | + | ||
| 18 | + // Backend config for a convolution that runs through cudnn. | ||
| 19 | + message CudnnConvBackendConfig { | ||
| 20 | + // Opaque algorithm number of cudnn algorithm chosen for this conv. | ||
| 21 | + int64 algorithm = 1; | ||
| 22 | + | ||
| 23 | + // Whether we may use tensor cores when running this conv. Even if this is | ||
| 24 | + // true, cudnn may choose not to use tensor cores, e.g. because the GPU or | ||
| 25 | + // selected algorithm doesn't support it. | ||
| 26 | + bool tensor_ops_enabled = 2; | ||
| 27 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ limitations under the License. | |||
| 14 | 14 | ==============================================================================*/ | |
| 15 | 15 | ||
| 16 | 16 | #include "tensorflow/compiler/xla/service/gpu/cudnn_convolution_algorithm_picker.h" | |
| 17 | + #include "tensorflow/compiler/xla/service/gpu/backend_configs.pb.h" | ||
| 17 | 18 | #include "tensorflow/compiler/xla/service/gpu/convolution_thunk.h" | |
| 18 | 19 | #include "tensorflow/compiler/xla/service/gpu/ir_emission_utils.h" | |
| 19 | 20 | #include "tensorflow/core/lib/gtl/optional.h" | |
@@ -316,21 +317,20 @@ StatusOr<bool> CudnnConvolutionAlgorithmPicker::RunOnInstruction( | |||
| 316 | 317 | Shape new_call_shape = | |
| 317 | 318 | ShapeUtil::MakeTupleShape({instr->shape().tuple_shapes(0), | |
| 318 | 319 | ShapeUtil::MakeShape(U8, {scratch_bytes})}); | |
| 319 | - HloInstruction* algorithm_hlo = computation->AddInstruction( | ||
| 320 | - HloInstruction::CreateConstant(Literal::CreateR0<int64>(algorithm))); | ||
| 321 | - HloInstruction* tensor_ops_enabled_hlo = | ||
| 322 | - computation->AddInstruction(HloInstruction::CreateConstant( | ||
| 323 | - Literal::CreateR0<bool>(tensor_ops_enabled))); | ||
| 320 | + | ||
| 321 | + CudnnConvBackendConfig backend_config; | ||
| 322 | + backend_config.set_algorithm(algorithm); | ||
| 323 | + backend_config.set_tensor_ops_enabled(tensor_ops_enabled); | ||
| 324 | 324 | ||
| 325 | 325 | HloInstruction* new_call = | |
| 326 | 326 | computation->AddInstruction(HloInstruction::CreateCustomCall( | |
| 327 | 327 | new_call_shape, | |
| 328 | - {instr->mutable_operand(0), instr->mutable_operand(1), algorithm_hlo, | ||
| 329 | - tensor_ops_enabled_hlo}, | ||
| 328 | + {instr->mutable_operand(0), instr->mutable_operand(1)}, | ||
| 330 | 329 | instr->custom_call_target())); | |
| 331 | 330 | new_call->set_window(instr->window()); | |
| 332 | 331 | new_call->set_convolution_dimension_numbers( | |
| 333 | 332 | instr->convolution_dimension_numbers()); | |
| 333 | + TF_RETURN_IF_ERROR(new_call->set_backend_config(backend_config)); | ||
| 334 | 334 | ||
| 335 | 335 | // Repackage new_call so it has the same shape as the original call, namely | |
| 336 | 336 | // (conv_result, u8[0]). | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,12 +78,6 @@ StatusOr<bool> GpuCopyInsertion::Run(HloModule* module) { | |||
| 78 | 78 | for (int64 i = 0; i < hlo->operand_count() - 2; ++i) { | |
| 79 | 79 | TF_RETURN_IF_ERROR(copy_operand_if_constant(i)); | |
| 80 | 80 | } | |
| 81 | - } else if (IsCustomCallToDnnConvolution(*hlo)) { | ||
| 82 | - // The last two arguments to a CUDNN convolution are two HLO constants for | ||
| 83 | - // cudnn algorithm and tensor_ops_enabled flag, which shouldn't be copied. | ||
| 84 | - for (int64 i = 0; i < hlo->operand_count() - 2; ++i) { | ||
| 85 | - TF_RETURN_IF_ERROR(copy_operand_if_constant(i)); | ||
| 86 | - } | ||
| 87 | 81 | } else if (ImplementedAsLibraryCall(*hlo) || | |
| 88 | 82 | hlo->opcode() == HloOpcode::kCrossReplicaSum) { | |
| 89 | 83 | // For all other library calls and cross-replica-sum, materialize all the | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -162,19 +162,8 @@ static HloInstruction* CreateCudnnConv( | |||
| 162 | 162 | Shape call_shape = | |
| 163 | 163 | ShapeUtil::MakeTupleShape({shape, ShapeUtil::MakeShape(U8, {0})}); | |
| 164 | 164 | ||
| 165 | - // Our CustomCall takes four arguments: The conv lhs and rhs, the cudnn | ||
| 166 | - // algorithm to use, and a boolean indicating whether to use tensor cores. | ||
| 167 | - // | ||
| 168 | - // It's up to a later pass to choose the algorithm and decide whether to use | ||
| 169 | - // tensor cores, so to indicate that we haven't yet made a choice, we speicfy | ||
| 170 | - // -1 and false for those args. | ||
| 171 | - HloInstruction* negative_one = computation->AddInstruction( | ||
| 172 | - HloInstruction::CreateConstant(Literal::CreateR0<int64>(-1))); | ||
| 173 | - HloInstruction* false_constant = computation->AddInstruction( | ||
| 174 | - HloInstruction::CreateConstant(Literal::CreateR0<bool>(false))); | ||
| 175 | - HloInstruction* custom_call = | ||
| 176 | - computation->AddInstruction(HloInstruction::CreateCustomCall( | ||
| 177 | - call_shape, {lhs, rhs, negative_one, false_constant}, call_target)); | ||
| 165 | + HloInstruction* custom_call = computation->AddInstruction( | ||
| 166 | + HloInstruction::CreateCustomCall(call_shape, {lhs, rhs}, call_target)); | ||
| 178 | 167 | custom_call->set_window(window); | |
| 179 | 168 | custom_call->set_convolution_dimension_numbers(dnums); | |
| 180 | 169 | return custom_call; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ limitations under the License. | |||
| 32 | 32 | #include "tensorflow/compiler/xla/ptr_util.h" | |
| 33 | 33 | #include "tensorflow/compiler/xla/service/buffer_assignment.h" | |
| 34 | 34 | #include "tensorflow/compiler/xla/service/dfs_hlo_visitor.h" | |
| 35 | + #include "tensorflow/compiler/xla/service/gpu/backend_configs.pb.h" | ||
| 35 | 36 | #include "tensorflow/compiler/xla/service/gpu/conditional_thunk.h" | |
| 36 | 37 | #include "tensorflow/compiler/xla/service/gpu/convolution_thunk.h" | |
| 37 | 38 | #include "tensorflow/compiler/xla/service/gpu/copy_thunk.h" | |
@@ -423,15 +424,8 @@ Status IrEmitterUnnested::HandleCustomCall(HloInstruction* custom_call) { | |||
| 423 | 424 | auto conv_result_slice = assn.GetUniqueSlice(custom_call, {0}).ValueOrDie(); | |
| 424 | 425 | auto scratch_slice = assn.GetUniqueSlice(custom_call, {1}).ValueOrDie(); | |
| 425 | 426 | ||
| 426 | - const HloInstruction* algorithm_inst = custom_call->operand(2); | ||
| 427 | - CHECK(algorithm_inst->IsConstant()) << algorithm_inst->ToString(); | ||
| 428 | - int64 algorithm = algorithm_inst->literal().Get<int64>({}); | ||
| 429 | - | ||
| 430 | - const HloInstruction* tensor_ops_enabled_inst = custom_call->operand(3); | ||
| 431 | - CHECK(tensor_ops_enabled_inst->IsConstant()) | ||
| 432 | - << tensor_ops_enabled_inst->ToString(); | ||
| 433 | - bool tensor_ops_enabled = tensor_ops_enabled_inst->literal().Get<bool>({}); | ||
| 434 | - | ||
| 427 | + TF_ASSIGN_OR_RETURN(CudnnConvBackendConfig backend_config, | ||
| 428 | + custom_call->backend_config<CudnnConvBackendConfig>()); | ||
| 435 | 429 | const auto& target = custom_call->custom_call_target(); | |
| 436 | 430 | std::unique_ptr<ConvolutionThunk> thunk; | |
| 437 | 431 | if (target == kCudnnConvForwardCallTarget) { | |
@@ -446,7 +440,8 @@ Status IrEmitterUnnested::HandleCustomCall(HloInstruction* custom_call) { | |||
| 446 | 440 | /*filter_shape=*/rhs_shape, | |
| 447 | 441 | /*output_shape=*/conv_result_shape, // | |
| 448 | 442 | custom_call->window(), custom_call->convolution_dimension_numbers(), | |
| 449 | - algorithm, tensor_ops_enabled, custom_call); | ||
| 443 | + backend_config.algorithm(), backend_config.tensor_ops_enabled(), | ||
| 444 | + custom_call); | ||
| 450 | 445 | } else if (target == kCudnnConvBackwardInputCallTarget) { | |
| 451 | 446 | thunk = MakeUnique<ConvolutionThunk>( | |
| 452 | 447 | CudnnConvKind::kBackwardInput, | |
@@ -459,7 +454,8 @@ Status IrEmitterUnnested::HandleCustomCall(HloInstruction* custom_call) { | |||
| 459 | 454 | /*filter_shape=*/rhs_shape, | |
| 460 | 455 | /*output_shape=*/lhs_shape, // | |
| 461 | 456 | custom_call->window(), custom_call->convolution_dimension_numbers(), | |
| 462 | - algorithm, tensor_ops_enabled, custom_call); | ||
| 457 | + backend_config.algorithm(), backend_config.tensor_ops_enabled(), | ||
| 458 | + custom_call); | ||
| 463 | 459 | } else if (target == kCudnnConvBackwardFilterCallTarget) { | |
| 464 | 460 | thunk = MakeUnique<ConvolutionThunk>( | |
| 465 | 461 | CudnnConvKind::kBackwardFilter, | |
@@ -472,7 +468,8 @@ Status IrEmitterUnnested::HandleCustomCall(HloInstruction* custom_call) { | |||
| 472 | 468 | /*filter_shape=*/conv_result_shape, | |
| 473 | 469 | /*output_shape=*/rhs_shape, // | |
| 474 | 470 | custom_call->window(), custom_call->convolution_dimension_numbers(), | |
| 475 | - algorithm, tensor_ops_enabled, custom_call); | ||
| 471 | + backend_config.algorithm(), backend_config.tensor_ops_enabled(), | ||
| 472 | + custom_call); | ||
| 476 | 473 | } else { | |
| 477 | 474 | LOG(FATAL) << "Unexpected custom call target: " | |
| 478 | 475 | << custom_call->custom_call_target(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments