Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions third_party/xla/xla/debug_options_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ DebugOptions DefaultDebugOptionsIgnoringFlags() {
opts.set_xla_gpu_nccl_collective_max_nchannels(0);
opts.set_xla_gpu_nccl_p2p_max_nchannels(0);

#if GOOGLE_CUDA
opts.set_xla_gpu_mlir_emitter_level(4);
#else
opts.set_xla_gpu_mlir_emitter_level(0);
#endif
// #if GOOGLE_CUDA
// opts.set_xla_gpu_mlir_emitter_level(4);
// #else
// opts.set_xla_gpu_mlir_emitter_level(0);
// #endif

opts.set_xla_gpu_multi_streamed_windowed_einsum(false);

Expand Down Expand Up @@ -1798,12 +1798,12 @@ void MakeDebugOptionsFlags(std::vector<tsl::Flag>* flag_list,
"Specify the maximum number of channels(SMs) NCCL will use "
"for p2p operations. Default is 0 which is to let "
"NCCL decide."));
flag_list->push_back(
tsl::Flag("xla_gpu_mlir_emitter_level",
int64_setter_for(&DebugOptions::set_xla_gpu_mlir_emitter_level),
debug_options->xla_gpu_mlir_emitter_level(),
"Enable new MLIR-based emitters. Level 0 means disabled, "
"higher levels enable more of the emitters."));
// flag_list->push_back(
// tsl::Flag("xla_gpu_mlir_emitter_level",
// int64_setter_for(&DebugOptions::set_xla_gpu_mlir_emitter_level),
// debug_options->xla_gpu_mlir_emitter_level(),
// "Enable new MLIR-based emitters. Level 0 means disabled, "
// "higher levels enable more of the emitters."));
flag_list->push_back(tsl::Flag(
"xla_gpu_multi_streamed_windowed_einsum",
bool_setter_for(
Expand Down
33 changes: 19 additions & 14 deletions third_party/xla/xla/service/gpu/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ xla_cc_test(
srcs = ["gpu_copy_insertion_test.cc"],
deps = [
":buffer_sharing",
":gpu_device_info_for_tests",
"//xla:test",
"//xla:test_helpers",
"//xla/hlo/analysis:hlo_dataflow_analysis",
"//xla/hlo/ir:hlo",
"//xla/service:copy_insertion",
"//xla/tests:hlo_test_base",
Expand Down Expand Up @@ -263,7 +265,7 @@ xla_cc_test(

cc_library(
name = "gpu_device_info_for_tests",
testonly = 1,
testonly = 0,
srcs = ["gpu_device_info_for_tests.cc"],
hdrs = ["gpu_device_info_for_tests.h"],
compatible_with = get_compatible_with_portable(),
Expand Down Expand Up @@ -696,25 +698,18 @@ cc_library(
srcs = ["reduction_utils.cc"],
hdrs = ["reduction_utils.h"],
compatible_with = get_compatible_with_portable(),
local_defines = if_cuda_is_configured(["GOOGLE_CUDA=1"]),
deps = [
":ir_emission_utils",
"//xla:shape_util",
"//xla:util",
"//xla/hlo/ir:hlo",
"//xla/service:hlo_module_config",
"//xla/stream_executor:semantic_version",
"//xla/stream_executor:device_description",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:inlined_vector",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/synchronization",
"@com_google_absl//absl/types:span",
"@local_tsl//tsl/platform:logging",
] + if_cuda_is_configured([
":gpu_asm_opts_util",
"//xla/stream_executor/cuda:cuda_asm_compiler",
]),
],
)

xla_cc_test(
Expand Down Expand Up @@ -1345,6 +1340,7 @@ cc_library(
"//xla/service/gpu/transforms:copy_fusion",
"//xla/service/gpu/transforms:horizontal_loop_fusion",
"//xla/service/gpu/transforms:sanitize_constant_names",
"//xla/stream_executor:device_description",
],
)

Expand Down Expand Up @@ -2262,6 +2258,11 @@ xla_cc_test(
],
)

cc_library(
name = "stream_executor_util_kernel_stub",
srcs = ["stream_executor_util_kernel_stub.cc"],
)

gpu_kernel_library(
name = "stream_executor_util_kernel",
srcs = ["stream_executor_util_kernel.cu.cc"],
Expand All @@ -2278,7 +2279,6 @@ cc_library(
srcs = ["stream_executor_util.cc"],
hdrs = ["stream_executor_util.h"],
copts = tsl_copts(),
local_defines = if_cuda_is_configured(["GOOGLE_CUDA=1"]),
deps = [
":cublas_cudnn",
":launch_dimensions",
Expand Down Expand Up @@ -2311,9 +2311,10 @@ cc_library(
"@local_tsl//tsl/platform:status",
"@local_tsl//tsl/platform:statusor",
"@local_tsl//tsl/protobuf:dnn_proto_cc",
] + if_gpu_is_configured([
":stream_executor_util_kernel",
]),
] + if_gpu_is_configured(
if_false = [":stream_executor_util_kernel_stub"],
if_true = [":stream_executor_util_kernel"],
),
)

xla_cc_test(
Expand Down Expand Up @@ -2520,6 +2521,10 @@ xla_cc_test(
":gpu_fusible",
"//xla/hlo/ir:hlo",
"//xla/service:hlo_parser",
"//xla/service:hlo_runner",
"//xla/service:instruction_fusion",
"//xla/service:platform_util",
"//xla/stream_executor:device_description",
"//xla/tests:hlo_test_base",
"//xla/tests:xla_internal_test_main",
"@com_google_absl//absl/strings",
Expand Down
19 changes: 8 additions & 11 deletions third_party/xla/xla/service/gpu/autotuning/autotuner_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,8 @@ class AutotuneConfig {
debug_options.xla_gpu_experimental_autotune_cache_mode()) {}

std::string GetModelStr() const {
if (auto deviceless_config = std::get_if<DevicelessConfig>(&config_)) {
return AutotuneCacheKey::DeviceDescriptionToCacheKey(
deviceless_config->device_description);
}

const auto& device_config = std::get<DeviceConfig>(config_);
return AutotuneCacheKey::DeviceDescriptionToCacheKey(
device_config.stream_exec->GetDeviceDescription());
GetDeviceDescription());
}

se::StreamExecutor* GetExecutor() const {
Expand All @@ -175,11 +169,14 @@ class AutotuneConfig {
}

const se::GpuComputeCapability& GetGpuComputeCapability() const {
if (auto c = std::get_if<DeviceConfig>(&config_)) {
return c->stream_exec->GetDeviceDescription().gpu_compute_capability();
return GetDeviceDescription().gpu_compute_capability();
}

const se::DeviceDescription& GetDeviceDescription() const {
if (auto* device_config = std::get_if<DeviceConfig>(&config_)) {
return device_config->stream_exec->GetDeviceDescription();
}
return std::get<DevicelessConfig>(config_)
.device_description.gpu_compute_capability();
return std::get<DevicelessConfig>(config_).device_description;
}

bool IsDeviceless() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,7 @@ GpuConvAlgorithmPicker::AutotuneRuntimeArguments::FromInstruction(

// Get canonical HLO.
std::string canonical_hlo(
AutotuneCacheKey(config.GetExecutor()->GetDeviceDescription(), *instr)
.GetHlo());
AutotuneCacheKey(config.GetDeviceDescription(), *instr).GetHlo());

TF_ASSIGN_OR_RETURN(GpuConvConfig gpu_conv_config, GetGpuConvConfig(instr));

Expand Down
26 changes: 14 additions & 12 deletions third_party/xla/xla/service/gpu/autotuning/gemm_fusion_autotuner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ absl::StatusOr<std::unique_ptr<HloModule>> TritonGemmAutotuneExtractor(

// If the priority fusion pass above skipped some instructions, turn them
// into fusions.
FusionWrapper fusion_wrapper;
FusionWrapper fusion_wrapper(gpu_device_info);
TF_RETURN_IF_ERROR(fusion_wrapper.Run(new_module.get()).status());
}
return new_module;
Expand Down Expand Up @@ -528,7 +528,7 @@ absl::Status DumpAutotunedFusion(const AutotuneConfig& autotune_config,
TritonGemmConfig::FromProto(result.triton()));
}
const se::DeviceDescription& device_desc =
autotune_config.GetExecutor()->GetDeviceDescription();
autotune_config.GetDeviceDescription();
TF_ASSIGN_OR_RETURN(
std::unique_ptr<HloModule> module,
util.ExtractModule([&](const DebugOptions& debug_opts) {
Expand Down Expand Up @@ -693,12 +693,12 @@ GemmFusionAutotunerImpl::GenerateTritonConfigs(const HloDotInstruction& dot) {
// a sufficient number of thread block programs to occupy all available cores.
// Around 5 full waves completely avoid the need for split-K.
// n_tiles = split_k * (M * N) / (block_m * block_n)
const int kCoreCount =
!config_.IsDeviceless()
? config_.GetExecutor()->GetDeviceDescription().core_count()
: 100; // some sensible default
const int kCoreCount = config_.GetDeviceDescription().core_count();
CHECK_GE(kCoreCount, 1);
const int64_t kSufficientNumberOfTiles = kMaxWavesForSplitK * kCoreCount;
const int64_t result_size = ShapeUtil::ElementsIn(dot.shape());
const int64_t threads_per_warp =
config_.GetDeviceDescription().threads_per_warp();

// Triton configurations are adjusted and deduplicated.
absl::flat_hash_set<TritonGemmConfig> added;
Expand Down Expand Up @@ -735,7 +735,7 @@ GemmFusionAutotunerImpl::GenerateTritonConfigs(const HloDotInstruction& dot) {
2 * std::max(kMinTileSize, kLdmatrixGranularity / minBitWidth));
int meta_elements = config.block_m * config.block_k / 16;
config.num_warps =
std::min<int>(config.num_warps, meta_elements / WarpSize());
std::min<int>(config.num_warps, meta_elements / threads_per_warp);
}

if (added.insert(config).second) {
Expand Down Expand Up @@ -783,11 +783,11 @@ GemmFusionAutotunerImpl::CompileAll(AutotunerCompileUtil& compile_util,
-> absl::StatusOr<bool> {
std::unique_ptr<Executable> executable;
if (std::holds_alternative<TritonGemmConfig>(config)) {
TF_ASSIGN_OR_RETURN(
executable, compile_util.Compile([&](const DebugOptions& opts) {
TF_ASSIGN_OR_RETURN(executable,
compile_util.Compile([&](const DebugOptions& opts) {
return TritonGemmAutotuneExtractor(
std::get<TritonGemmConfig>(config),
config_.GetExecutor()->GetDeviceDescription(), fusion, opts,
config_.GetDeviceDescription(), fusion, opts,
allow_filtering_kernels_spilling_registers);
}));
} else if (std::holds_alternative<CuDnnConfig>(config)) {
Expand All @@ -802,7 +802,7 @@ GemmFusionAutotunerImpl::CompileAll(AutotunerCompileUtil& compile_util,
TF_ASSIGN_OR_RETURN(
executable, compile_util.Compile([&](const DebugOptions& opts) {
return CublasGemmAutotuneExtractor(
config_, config_.GetExecutor()->GetDeviceDescription(),
config_, config_.GetDeviceDescription(),
toolkit_version_, fusion, opts);
}));
} else {
Expand Down Expand Up @@ -1005,6 +1005,8 @@ GemmFusionAutotunerImpl::GetExhaustiveTritonConfigs() const {
bool tune_ctas =
debug_options_.xla_gpu_enable_triton_hopper() && cc.IsAtLeastHopper();

const int64_t threads_per_warp =
config_.GetDeviceDescription().threads_per_warp();
for (int num_stages : kNumStages) {
// Volta doesn't support num_stages > 2.
if (!cc.IsAtLeastAmpere() && num_stages > 2) {
Expand All @@ -1017,7 +1019,7 @@ GemmFusionAutotunerImpl::GetExhaustiveTritonConfigs() const {
const int tile_rhs = tile_k * tile_n;
for (int num_warps : kNumWarps) {
// Each thread should read at least one input element.
if (num_warps * WarpSize() > std::min(tile_lhs, tile_rhs)) {
if (num_warps * threads_per_warp > std::min(tile_lhs, tile_rhs)) {
break;
}
for (int split_k : kSplitK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ absl::StatusOr<std::vector<TritonGemmConfig>> GetPossibleMatmulAutotuneConfigs(
auto ccc = deviceless_proto.mutable_cuda_compute_capability();
ccc->set_major(compute_capability.major);
ccc->set_minor(compute_capability.minor);
deviceless_proto.set_core_count(100);
deviceless_proto.set_threads_per_warp(32);
DevicelessConfig test_config{se::DeviceDescription{deviceless_proto}};
AutotuneConfig autotune_config{test_config, debug_options};
GemmFusionAutotunerImpl autotuner(autotune_config, toolkit_version,
Expand Down Expand Up @@ -941,7 +943,9 @@ ENTRY wais {
compute_capability, GetToolkitVersion(), debug_options));
for (const auto& config : configs) {
int metadata_size = config.block_m * config.block_k / 16;
EXPECT_LE(config.num_warps * WarpSize(), metadata_size);
EXPECT_LE(config.num_warps *
WarpSize(backend().default_stream_executor()->GetDeviceDescription()),
metadata_size);
EXPECT_GT(config.block_k, 16); // kMinTileSize
}
}
Expand Down
10 changes: 5 additions & 5 deletions third_party/xla/xla/service/gpu/buffer_sharing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace gpu {

std::optional<bool> FusionCanShareBufferHint(const HloInstruction* user,
const HloInstruction* operand,
const ShapeIndex& user_index) {
const ShapeIndex& user_index,
const se::DeviceDescription& device_description) {
const HloFusionInstruction* fusion = DynCast<HloFusionInstruction>(user);
if (fusion == nullptr) {
return std::nullopt;
Expand Down Expand Up @@ -77,8 +78,6 @@ std::optional<bool> FusionCanShareBufferHint(const HloInstruction* user,
// Allow multiple output users, if they end in reductions.
// This only works for the reduction emitter, as it calculates the reduction
// first, i.e. before processing other outputs (that may overwrite the input).
stream_executor::GpuDeviceInfoProto device_info;
stream_executor::DeviceDescription device_description(device_info);
auto analysis = HloFusionAnalysis::Create(*user, device_description);
bool is_reduction_emitter = analysis.GetEmitterFusionKind() ==
HloFusionAnalysis::EmitterFusionKind::kReduction;
Expand Down Expand Up @@ -221,7 +220,8 @@ std::optional<bool> FusionCanShareBufferHint(const HloInstruction* user,

std::optional<bool> CanShareBufferHint(const HloInstruction* user,
const HloInstruction* operand,
const ShapeIndex& user_index) {
const ShapeIndex& user_index,
const se::DeviceDescription& device_description) {
switch (user->opcode()) {
case HloOpcode::kAllReduce:
case HloOpcode::kCollectiveBroadcast:
Expand All @@ -243,7 +243,7 @@ std::optional<bool> CanShareBufferHint(const HloInstruction* user,
}
return false;
case HloOpcode::kFusion:
return FusionCanShareBufferHint(user, operand, user_index);
return FusionCanShareBufferHint(user, operand, user_index, device_description);
default:
return std::nullopt;
}
Expand Down
7 changes: 5 additions & 2 deletions third_party/xla/xla/service/gpu/buffer_sharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,19 @@ limitations under the License.

#include "xla/hlo/ir/hlo_instruction.h"
#include "xla/shape_util.h"
#include "xla/stream_executor/device_description.h"

namespace xla {
namespace gpu {
std::optional<bool> FusionCanShareBufferHint(const HloInstruction* user,
const HloInstruction* operand,
const ShapeIndex& user_index);
const ShapeIndex& user_index,
const se::DeviceDescription& device_description);

std::optional<bool> CanShareBufferHint(const HloInstruction* user,
const HloInstruction* operand,
const ShapeIndex& user_index);
const ShapeIndex& user_index,
const se::DeviceDescription& device_description);
} // namespace gpu
} // namespace xla

Expand Down
2 changes: 1 addition & 1 deletion third_party/xla/xla/service/gpu/fusion_pipeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ HloPassPipeline FusionPipeline(
HloPassPipeline HorizontalFusionPipeline(
const se::DeviceDescription& gpu_device_info) {
HloPassFix<HloPassPipeline> horizontal_fusion("horizontal fusion");
horizontal_fusion.AddPass<HorizontalLoopFusion>();
horizontal_fusion.AddPass<HorizontalLoopFusion>(gpu_device_info);
horizontal_fusion.AddPass<HorizontalInputFusion>(gpu_device_info);
horizontal_fusion.AddPass<HloCSE>(/*is_layout_sensitive=*/true,
/*only_fusion_computations=*/true);
Expand Down
20 changes: 10 additions & 10 deletions third_party/xla/xla/service/gpu/fusions/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -222,17 +222,17 @@ cc_library(
"//xla/service/gpu:hlo_fusion_analysis",
"//xla/service/gpu:hlo_traversal",
"//xla/service/gpu:ir_emission_utils",
"//xla/service/gpu/fusions/legacy:concatenate",
"//xla/service/gpu/fusions/legacy:in_place_dynamic_update_slice",
"//xla/service/gpu/fusions/legacy:input_slices",
"//xla/service/gpu/fusions/legacy:loop",
"//xla/service/gpu/fusions/legacy:reduction",
"//xla/service/gpu/fusions/legacy:scatter",
"//xla/service/gpu/fusions/legacy:transpose",
"//xla/service/gpu/fusions/mlir:elemental_hlo_to_mlir",
# "//xla/service/gpu/fusions/legacy:concatenate",
# "//xla/service/gpu/fusions/legacy:in_place_dynamic_update_slice",
# "//xla/service/gpu/fusions/legacy:input_slices",
# "//xla/service/gpu/fusions/legacy:loop",
# "//xla/service/gpu/fusions/legacy:reduction",
# "//xla/service/gpu/fusions/legacy:scatter",
# "//xla/service/gpu/fusions/legacy:transpose",
# "//xla/service/gpu/fusions/mlir:elemental_hlo_to_mlir",
"@com_google_absl//absl/algorithm:container",
"@com_google_absl//absl/log",
"@com_google_absl//absl/log:check",
# "@com_google_absl//absl/log",
# "@com_google_absl//absl/log:check",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
],
Expand Down
Loading