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

Function IsGpuCompatible

tensorflow/core/grappler/optimizers/remapper.cc:349–385  ·  view source on GitHub ↗

Checks if we can rewrite a pattern to the `_FusedConv2D` on GPU device.

Source from the content-addressed store, hash-verified

347
348// Checks if we can rewrite a pattern to the `_FusedConv2D` on GPU device.
349bool IsGpuCompatible(const RemapperContext& ctx,
350 const ContractionWithBiasAddAndActivation& matched) {
351#if TENSORFLOW_USE_ROCM
352 // ROCm does not support _FusedConv2D
353 return false;
354#endif
355 // xla does not cluster _FusedConv2D, and knows how to do this optimization
356 if (ctx.xla_on_) return false;
357
358 const GraphDef* graph = ctx.graph_view.graph();
359
360 // We rely on cuDNN for fused convolution and cublasLt for fused matmul.
361 const NodeDef& activation_node = graph->node(matched.activation);
362 if (!IsRelu(activation_node)) return false;
363 const NodeDef& contraction_node = graph->node(matched.contraction);
364 if (IsConv2D(contraction_node)) {
365 const std::vector<OpInfo::TensorProperties>& input_props =
366 ctx.graph_properties.GetInputProperties(contraction_node.name());
367 const TensorShapeProto& filter_shape =
368 input_props.size() >= 2 ? input_props[1].shape() : TensorShapeProto();
369
370 // FusedConv2D on GPU with 1x1 convolution is marginally faster than
371 // in-graph computation in micro benchmarks (see kernels/conv_ops_test.cc),
372 // and significantly slower in large scale benchmarks.
373 bool is_spatial_conv = Rank(filter_shape) == 4 && //
374 IsKnown(filter_shape.dim(1)) && //
375 IsKnown(filter_shape.dim(2)) && //
376 filter_shape.dim(1).size() != 1 && //
377 filter_shape.dim(2).size() != 1;
378
379 return is_spatial_conv && IsGpuCompatibleConv2D(ctx, &contraction_node);
380 } else if (IsMatMul(contraction_node)) {
381 return IsGpuCompatibleMatMul(ctx, &contraction_node);
382 }
383
384 return false;
385}
386
387// Checks if we can rewrite a pattern to the `_FusedMatMul` on GPU device.
388bool IsGpuCompatible(const RemapperContext& ctx,

Callers 1

IsDeviceCompatibleFunction · 0.85

Calls 14

IsReluFunction · 0.85
IsConv2DFunction · 0.85
TensorShapeProtoClass · 0.85
IsKnownFunction · 0.85
IsGpuCompatibleConv2DFunction · 0.85
IsMatMulFunction · 0.85
IsGpuCompatibleMatMulFunction · 0.85
nameMethod · 0.65
RankFunction · 0.50
graphMethod · 0.45
nodeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected