@@ -238,16 +238,20 @@ def add_artifact_subcommand_global_arguments(parser: argparse.ArgumentParser):
238238 )
239239
240240 parser .add_argument (
241- "--target_cpu_features" ,
242- choices = ["release" , "native" , "default" ],
243- default = "release" ,
241+ "--enable_release_cpu_features" ,
242+ action = "store_true" ,
243+ help = """
244+ Eenables CPU features that should be enabled for a release build, which
245+ on x86-64 architectures enables AVX.
246+ """ ,
247+ )
248+
249+ parser .add_argument (
250+ "--enable_native_cpu_features" ,
251+ action = "store_true" ,
244252 help = """
245- What CPU features should we target? 'release' enables CPU features that
246- should be enabled for a release build, which on x86-64 architectures
247- enables AVX. 'native' enables -march=native, which generates code
248- targeted to use all features of the current machine. 'default' means
249- don't opt-in to any architectural features and use whatever the C
250- compiler generates by default.
253+ Enables -march=native, which generates code targeted to use all features
254+ of the current machine.
251255 """ ,
252256 )
253257
@@ -443,93 +447,94 @@ async def main():
443447 logging .debug ("Using --config=%s from .bazelrc" , bazelrc_config )
444448 bazel_command .append (f"--config={ bazelrc_config } " )
445449 else :
450+ # If not running in CI mode, find out the path to the Clang binary and
451+ # pass it to Bazel to use as the C++ compiler.
446452 clang_path = args .clang_path or utils .get_clang_path_or_exit ()
447453 logging .debug ("Using Clang as the compiler, clang path: %s" , clang_path )
448454 bazel_command .append (f"--action_env CLANG_COMPILER_PATH={ clang_path } " )
449455 bazel_command .append (f"--repo_env CC={ clang_path } " )
450456 bazel_command .append (f"--repo_env BAZEL_COMPILER={ clang_path } " )
451457 bazel_command .append ("--config=clang" )
452458
453- if args .target_cpu :
454- logging .debug ("Target CPU: %s" , args .target_cpu )
455- bazel_command .append (f"--cpu={ args .target_cpu } " )
459+ if "cuda" in args .command :
460+ bazel_command .append ("--config=cuda" )
461+ bazel_command .append (
462+ f"--action_env=CLANG_CUDA_COMPILER_PATH={ clang_path } "
463+ )
456464
457- if args .enable_mkl_dnn :
458- logging .debug ("Enabling MKL DNN" )
459- bazel_command .append ("--config=mkl_open_source_only " )
465+ if args .target_cpu :
466+ logging .debug ("Target CPU: %s" , args . target_cpu )
467+ bazel_command .append (f "--cpu= { args . target_cpu } " )
460468
461- if hasattr ( args , "disable_nccl" ) and args . disable_nccl :
462- logging .debug ("Disabling NCCL " )
463- bazel_command .append ("--config=nonccl " )
469+ if args . enable_mkl_dnn :
470+ logging .debug ("Enabling MKL DNN " )
471+ bazel_command .append ("--config=mkl_open_source_only " )
464472
465- if args .target_cpu_features == "release" :
466- logging .debug (
467- "Using release cpu features: --config=avx_%s" ,
468- "windows" if utils .is_windows () else "posix" ,
473+ if hasattr (args , "disable_nccl" ) and args .disable_nccl :
474+ logging .debug ("Disabling NCCL" )
475+ bazel_command .append ("--config=nonccl" )
476+
477+ if args .enable_release_cpu_features :
478+ logging .debug (
479+ "Using release cpu features: --config=avx_%s" ,
480+ "windows" if utils .is_windows () else "posix" ,
481+ )
482+ if arch == "x86_64" :
483+ bazel_command .append (
484+ "--config=avx_windows"
485+ if utils .is_windows ()
486+ else "--config=avx_posix"
487+ )
488+
489+ if args .enable_native_cpu_features :
490+ if utils .is_windows ():
491+ logger .warning (
492+ "--target_cpu_features=native is not supported on Windows;"
493+ " ignoring."
469494 )
470- if arch == "x86_64" :
471- bazel_command .append (
472- "--config=avx_windows"
473- if utils .is_windows ()
474- else "--config=avx_posix"
475- )
476- elif args .target_cpu_features == "native" :
477- if utils .is_windows ():
478- logger .warning (
479- "--target_cpu_features=native is not supported on Windows;"
480- " ignoring."
481- )
482- else :
483- logging .debug ("Using native cpu features: --config=native_arch_posix" )
484- bazel_command .append ("--config=native_arch_posix" )
485495 else :
486- logging .debug ("Using default cpu features" )
496+ logging .debug ("Using native cpu features: --config=native_arch_posix" )
497+ bazel_command .append ("--config=native_arch_posix" )
487498
488- if "cuda" in args .command :
489- bazel_command .append ("--config=cuda" )
499+ if "cuda" in args .command :
500+ if args .build_cuda_with_clang :
501+ logging .debug ("Building CUDA with Clang" )
502+ bazel_command .append ("--config=build_cuda_with_clang" )
503+ else :
504+ logging .debug ("Building CUDA with NVCC" )
505+ bazel_command .append ("--config=build_cuda_with_nvcc" )
490506
491- if args .build_cuda_with_clang :
492- logging .debug ("Building CUDA with Clang" )
493- bazel_command .append ("--config=build_cuda_with_clang" )
494- bazel_command .append (
495- f"--action_env=CLANG_CUDA_COMPILER_PATH={ clang_path } "
496- )
497- else :
498- logging .debug ("Building CUDA with NVCC" )
499- bazel_command .append ("--config=build_cuda_with_nvcc" )
500-
501- if args .cuda_version :
502- logging .debug ("Hermetic CUDA version: %s" , args .cuda_version )
503- bazel_command .append (
504- f"--repo_env=HERMETIC_CUDA_VERSION={ args .cuda_version } "
505- )
506- if args .cudnn_version :
507- logging .debug ("Hermetic cuDNN version: %s" , args .cudnn_version )
508- bazel_command .append (
509- f"--repo_env=HERMETIC_CUDNN_VERSION={ args .cudnn_version } "
510- )
511- if args .cuda_compute_capabilities :
512- logging .debug (
513- "Hermetic CUDA compute capabilities: %s" ,
514- args .cuda_compute_capabilities ,
515- )
516- bazel_command .append (
517- "--repo_env"
518- f" HERMETIC_CUDA_COMPUTE_CAPABILITIES={ args .cuda_compute_capabilities } "
519- )
507+ if args .cuda_version :
508+ logging .debug ("Hermetic CUDA version: %s" , args .cuda_version )
509+ bazel_command .append (
510+ f"--repo_env=HERMETIC_CUDA_VERSION={ args .cuda_version } "
511+ )
512+ if args .cudnn_version :
513+ logging .debug ("Hermetic cuDNN version: %s" , args .cudnn_version )
514+ bazel_command .append (
515+ f"--repo_env=HERMETIC_CUDNN_VERSION={ args .cudnn_version } "
516+ )
517+ if args .cuda_compute_capabilities :
518+ logging .debug (
519+ "Hermetic CUDA compute capabilities: %s" ,
520+ args .cuda_compute_capabilities ,
521+ )
522+ bazel_command .append (
523+ "--repo_env"
524+ f" HERMETIC_CUDA_COMPUTE_CAPABILITIES={ args .cuda_compute_capabilities } "
525+ )
520526
521- if "rocm" in args .command :
522- bazel_command .append ("--config=rocm" )
523- bazel_command .append ("--action_env=CLANG_COMPILER_PATH={clang_path}" )
524-
525- if args .rocm_path :
526- logging .debug ("ROCm tookit path: %s" , args .rocm_path )
527- bazel_command .append (f"--action_env ROCM_PATH='{ args .rocm_path } '" )
528- if args .rocm_amdgpu_targets :
529- logging .debug ("ROCm AMD GPU targets: %s" , args .rocm_amdgpu_targets )
530- bazel_command .append (
531- f"--action_env TF_ROCM_AMDGPU_TARGETS={ args .rocm_amdgpu_targets } "
532- )
527+ if "rocm" in args .command :
528+ bazel_command .append ("--config=rocm" )
529+
530+ if args .rocm_path :
531+ logging .debug ("ROCm tookit path: %s" , args .rocm_path )
532+ bazel_command .append (f"--action_env ROCM_PATH='{ args .rocm_path } '" )
533+ if args .rocm_amdgpu_targets :
534+ logging .debug ("ROCm AMD GPU targets: %s" , args .rocm_amdgpu_targets )
535+ bazel_command .append (
536+ f"--action_env TF_ROCM_AMDGPU_TARGETS={ args .rocm_amdgpu_targets } "
537+ )
533538
534539 if args .local_xla_path :
535540 logging .debug ("Local XLA path: %s" , args .local_xla_path )
0 commit comments