diff --git a/.ci/docker/ci_commit_pins/pytorch.txt b/.ci/docker/ci_commit_pins/pytorch.txt index 242371cbebe..401a0594d98 100644 --- a/.ci/docker/ci_commit_pins/pytorch.txt +++ b/.ci/docker/ci_commit_pins/pytorch.txt @@ -1 +1 @@ -release/2.12 +release/2.13 diff --git a/.ci/docker/common/install_pytorch.sh b/.ci/docker/common/install_pytorch.sh index 3c80d093ab2..c55e3ac878d 100755 --- a/.ci/docker/common/install_pytorch.sh +++ b/.ci/docker/common/install_pytorch.sh @@ -16,6 +16,21 @@ install_domains() { pip_install --no-build-isolation --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}" } +configure_pytorch_compiler() { + local cxx_version + cxx_version=$(/usr/bin/c++ --version | head -n1) + if [[ "${cxx_version}" == *clang* ]]; then + local clang_major + clang_major=$(/usr/bin/c++ -dumpversion | cut -d. -f1) + if [[ "${clang_major}" =~ ^[0-9]+$ && "${clang_major}" -lt 16 ]] && + command -v gcc >/dev/null && + command -v g++ >/dev/null; then + export CC=gcc + export CXX=g++ + fi + fi +} + install_pytorch_and_domains() { git clone https://github.com/pytorch/pytorch.git @@ -33,6 +48,7 @@ install_pytorch_and_domains() { if [[ -n "${PYTORCH_BUILD_MAX_JOBS:-}" ]]; then export MAX_JOBS="${PYTORCH_BUILD_MAX_JOBS}" fi + configure_pytorch_compiler # Then build and install PyTorch conda_run python setup.py bdist_wheel pip_install "$(echo dist/*.whl)" @@ -40,7 +56,7 @@ install_pytorch_and_domains() { # Grab the pinned audio and vision commits from PyTorch TORCHAUDIO_VERSION=release/2.11 export TORCHAUDIO_VERSION - TORCHVISION_VERSION=release/0.27 + TORCHVISION_VERSION=release/0.28 export TORCHVISION_VERSION install_domains diff --git a/.ci/scripts/setup-windows.ps1 b/.ci/scripts/setup-windows.ps1 index 2cf28e0cdfe..a38d43bbfd8 100644 --- a/.ci/scripts/setup-windows.ps1 +++ b/.ci/scripts/setup-windows.ps1 @@ -14,6 +14,10 @@ conda activate et # Install test dependencies pip install -r .ci/docker/requirements-ci.txt +# PyTorch 2.13 headers use designated initializers in c10, which require C++20 +# with MSVC. +$env:CMAKE_ARGS = "$env:CMAKE_ARGS -DCMAKE_CXX_STANDARD=20" + # The Windows CI image ships CUDA toolkits on PATH, so install_executorch # (setup.py) auto-enables EXECUTORCH_BUILD_CUDA whenever the detected nvcc # version is in SUPPORTED_CUDA_VERSIONS. CPU-only jobs install CPU torch, so a diff --git a/.ci/scripts/test_model_e2e_windows.ps1 b/.ci/scripts/test_model_e2e_windows.ps1 index 73a78c92112..8f7d6c2456e 100644 --- a/.ci/scripts/test_model_e2e_windows.ps1 +++ b/.ci/scripts/test_model_e2e_windows.ps1 @@ -172,22 +172,34 @@ try { "-DCUDAToolkit_ROOT=$env:CUDA_HOME" ) } + $cmakeCommonArgs = @("-DCMAKE_CXX_STANDARD=20") Write-Host "::endgroup::" Write-Host "::group::Build ExecuTorch (CUDA)" $numCores = [Math]::Max([Environment]::ProcessorCount - 1, 1) + $cmakeOut = Join-Path -Path $executorchRoot -ChildPath "cmake-out" + $executorchCmakeDir = Join-Path -Path $cmakeOut -ChildPath "lib\cmake\ExecuTorch" + $executorchConfig = Join-Path -Path $executorchCmakeDir -ChildPath "executorch-config.cmake" # EXECUTORCH_BUILD_EXTENSION_IMAGE defaults OFF in the preset, so it must be # enabled explicitly here (matching the Makefile CUDA target used on Linux). # The dinov2 runner links the installed extension_image.lib; without this the # main install never builds it and dinov2_runner fails to link (LNK1181). - cmake --preset llm-release-cuda -DEXECUTORCH_BUILD_EXTENSION_IMAGE=ON @cmakeCudaArgs - cmake --build cmake-out --target install --config Release -j $numCores + cmake --preset llm-release-cuda -DEXECUTORCH_BUILD_EXTENSION_IMAGE=ON @cmakeCommonArgs @cmakeCudaArgs + cmake --build $cmakeOut --target install --config Release -j $numCores + if (-not (Test-Path -Path $executorchConfig -PathType Leaf)) { + throw "ExecuTorch CMake package config not found after install: $executorchConfig" + } Write-Host "::endgroup::" Write-Host "::group::Build $runnerTarget" + $cmakePackageArgs = @( + "-DCMAKE_FIND_ROOT_PATH=$cmakeOut", + "-DCMAKE_PREFIX_PATH=$cmakeOut;$executorchCmakeDir", + "-Dexecutorch_DIR=$executorchCmakeDir" + ) Push-Location (Join-Path -Path $executorchRoot -ChildPath "examples\models\$runnerPath") try { - cmake --preset $runnerPreset @cmakeCudaArgs + cmake --preset $runnerPreset @cmakeCommonArgs @cmakePackageArgs @cmakeCudaArgs cmake --build (Join-Path -Path $executorchRoot -ChildPath "cmake-out\examples\models\$runnerPath") --target $runnerTarget --config Release -j $numCores } finally { diff --git a/.ci/scripts/utils.sh b/.ci/scripts/utils.sh index b312d0ede83..234e162e48e 100644 --- a/.ci/scripts/utils.sh +++ b/.ci/scripts/utils.sh @@ -107,7 +107,7 @@ install_pytorch_and_domains() { local torch_release=$(cat version.txt) # Download key must match the upload key below (basename of dist/*.whl, # which always carries setup.py's resolved +gitHASH). Branch-ref pins - # like `release/2.12` would otherwise produce `+gitrelease` here and + # like `release/2.13` would otherwise produce `+gitrelease` here and # never hit the cache. local torch_short_hash=$(git rev-parse --short=7 HEAD) local torch_wheel_path="cached_artifacts/pytorch/executorch/pytorch_wheels/${system_name}/${python_version}" @@ -178,7 +178,7 @@ install_pytorch_and_domains() { # Grab the pinned audio and vision commits from PyTorch TORCHAUDIO_VERSION=release/2.11 export TORCHAUDIO_VERSION - TORCHVISION_VERSION=release/0.27 + TORCHVISION_VERSION=release/0.28 export TORCHVISION_VERSION install_domains diff --git a/.github/workflows/_unittest.yml b/.github/workflows/_unittest.yml index e300c1541b8..4216d3aaa27 100644 --- a/.github/workflows/_unittest.yml +++ b/.github/workflows/_unittest.yml @@ -24,6 +24,10 @@ on: required: false type: string default: '3.10' + linux-timeout: + required: false + type: number + default: 90 jobs: linux: @@ -36,7 +40,7 @@ jobs: docker-image: ${{ inputs.docker-image }} submodules: 'recursive' ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 + timeout: ${{ inputs.linux-timeout }} script: | set -eux .ci/scripts/unittest-linux.sh --build-tool "${{ inputs.build-tool }}" --build-mode "${{ inputs.build-mode }}" --editable "${{ inputs.editable }}" diff --git a/.github/workflows/mlx.yml b/.github/workflows/mlx.yml index 40ebabbcf28..0de68134c4e 100644 --- a/.github/workflows/mlx.yml +++ b/.github/workflows/mlx.yml @@ -158,10 +158,10 @@ jobs: --prompt-len 4 \ --max-new-tokens 5 2>&1) echo "$OUTPUT" - if echo "$OUTPUT" | grep -q "Generated token ids: \[167, 94, 253, 88, 227\]"; then + if echo "$OUTPUT" | grep -q "Generated token ids: \[167, 180, 167, 180, 167\]"; then echo "Success: Qwen 3.5 MoE MLX export + inference completed with expected output" else - echo "Failed: unexpected output (expected [167, 94, 253, 88, 227])" + echo "Failed: unexpected output (expected [167, 180, 167, 180, 167])" exit 1 fi echo "::endgroup::" diff --git a/.github/workflows/trunk.yml b/.github/workflows/trunk.yml index 7ff3ee5d601..5cecba6dc07 100644 --- a/.github/workflows/trunk.yml +++ b/.github/workflows/trunk.yml @@ -1006,6 +1006,7 @@ jobs: build-mode: Release build-tool: cmake docker-image: ci-image:executorch-ubuntu-22.04-clang12 + linux-timeout: 120 llm-server: needs: [changed-files, run-decision] diff --git a/CMakeLists.txt b/CMakeLists.txt index 91e3982f7f8..b8d9b38f694 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,10 @@ project(executorch VERSION "${ET_VERSION_MAJOR}.${ET_VERSION_MINOR}.${ET_VERSION_PATCH}" ) +if(WIN32) + add_compile_definitions(NOMINMAX) +endif() + # Hexagon toolchain with release build complains about code in third party # libraries. Must come after project(), which runs the toolchain file that sets # CMAKE_SYSTEM_PROCESSOR, and before add_subdirectory(third-party). diff --git a/backends/aoti/common_shims.cpp b/backends/aoti/common_shims.cpp index 49d445e955d..f3a34a09987 100644 --- a/backends/aoti/common_shims.cpp +++ b/backends/aoti/common_shims.cpp @@ -154,6 +154,11 @@ AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim) { return Error::Ok; } +AOTITorchError aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel) { + *ret_numel = static_cast(tensor->numel()); + return Error::Ok; +} + // Device and layout utility functions int32_t aoti_torch_device_type_cpu() { // Let's say cpu is 0 for ET as well diff --git a/backends/aoti/common_shims.h b/backends/aoti/common_shims.h index 869aece5a3b..d057279e22a 100644 --- a/backends/aoti/common_shims.h +++ b/backends/aoti/common_shims.h @@ -59,6 +59,9 @@ aoti_torch_get_device_index(Tensor* tensor, int32_t* ret_device_index); AOTI_SHIM_EXPORT AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim); +AOTI_SHIM_EXPORT AOTITorchError +aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel); + // Utility functions for device and layout information AOTI_SHIM_EXPORT int32_t aoti_torch_device_type_cpu(); AOTI_SHIM_EXPORT int32_t aoti_torch_layout_strided(); diff --git a/backends/aoti/common_shims_slim.cpp b/backends/aoti/common_shims_slim.cpp index f4b50400778..c8c7408aa62 100644 --- a/backends/aoti/common_shims_slim.cpp +++ b/backends/aoti/common_shims_slim.cpp @@ -60,6 +60,14 @@ AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim) { return Error::Ok; } +AOTITorchError aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel) { + if (tensor == nullptr || ret_numel == nullptr) { + return Error::InvalidArgument; + } + *ret_numel = static_cast(tensor->numel()); + return Error::Ok; +} + int32_t aoti_torch_layout_strided() { // Slimtensor only support strided layout, the return value will always be 0, // a.k.a at::Layout::Strided; diff --git a/backends/aoti/common_shims_slim.h b/backends/aoti/common_shims_slim.h index 3ec867bcf6e..c5a5cab9413 100644 --- a/backends/aoti/common_shims_slim.h +++ b/backends/aoti/common_shims_slim.h @@ -48,6 +48,9 @@ aoti_torch_get_dtype(Tensor* tensor, int32_t* ret_dtype); AOTI_SHIM_EXPORT AOTITorchError aoti_torch_get_dim(Tensor* tensor, int64_t* ret_dim); +AOTI_SHIM_EXPORT AOTITorchError +aoti_torch_get_numel(Tensor* tensor, int64_t* ret_numel); + AOTI_SHIM_EXPORT int32_t aoti_torch_layout_strided(); // ============================================================ diff --git a/backends/aoti/tests/test_common_shims.cpp b/backends/aoti/tests/test_common_shims.cpp index 0fd1b057f99..b2dc2c01dc2 100644 --- a/backends/aoti/tests/test_common_shims.cpp +++ b/backends/aoti/tests/test_common_shims.cpp @@ -241,6 +241,21 @@ TEST_F(CommonShimsTest, ScalarTensor) { error = aoti_torch_get_sizes(tensor_0d, &sizes_ptr2); EXPECT_EQ(error, Error::Ok); EXPECT_EQ(sizes_ptr, sizes_ptr2); + + int64_t numel = -1; + error = aoti_torch_get_numel(tensor_0d, &numel); + EXPECT_EQ(error, Error::Ok); + EXPECT_EQ(numel, 1); +} + +TEST_F(CommonShimsTest, GetNumel) { + auto tensor = create_tracked_tensor({2, 3, 4}); + + int64_t numel = -1; + AOTITorchError error = aoti_torch_get_numel(tensor, &numel); + + EXPECT_EQ(error, Error::Ok); + EXPECT_EQ(numel, 24); } // Test large tensor dimensions @@ -266,6 +281,11 @@ TEST_F(CommonShimsTest, LargeTensorDimensions) { EXPECT_EQ(strides_ptr[1], 120000); EXPECT_EQ(strides_ptr[2], 400); EXPECT_EQ(strides_ptr[3], 1); + + int64_t numel = -1; + error = aoti_torch_get_numel(tensor, &numel); + EXPECT_EQ(error, Error::Ok); + EXPECT_EQ(numel, 2400000000); } // Test that cleanup_tensor_metadata clears the cache diff --git a/backends/aoti/tests/test_common_shims_slim.cpp b/backends/aoti/tests/test_common_shims_slim.cpp index 94319c6f94d..2dd8475a4d8 100644 --- a/backends/aoti/tests/test_common_shims_slim.cpp +++ b/backends/aoti/tests/test_common_shims_slim.cpp @@ -289,6 +289,50 @@ void runGetDimTest(slim_c10::DeviceType device_type) { } } +void runGetNumelTest(slim_c10::DeviceType device_type) { + slim_c10::Device device(device_type, 0); + + // Test 0D tensor (scalar) + { + std::vector sizes = {}; + std::vector strides = {}; + + Tensor* tensor = new Tensor(slim::empty_strided( + slim::makeArrayRef(sizes), + slim::makeArrayRef(strides), + slim_c10::ScalarType::Float, + device)); + + int64_t ret_numel = -1; + AOTITorchError error = aoti_torch_get_numel(tensor, &ret_numel); + + EXPECT_EQ(error, Error::Ok); + EXPECT_EQ(ret_numel, 1); + + delete tensor; + } + + // Test 3D tensor + { + std::vector sizes = {2, 3, 4}; + std::vector strides = calculateContiguousStrides(sizes); + + Tensor* tensor = new Tensor(slim::empty_strided( + slim::makeArrayRef(sizes), + slim::makeArrayRef(strides), + slim_c10::ScalarType::Float, + device)); + + int64_t ret_numel = -1; + AOTITorchError error = aoti_torch_get_numel(tensor, &ret_numel); + + EXPECT_EQ(error, Error::Ok); + EXPECT_EQ(ret_numel, 24); + + delete tensor; + } +} + // ============================================================================ // Storage & Device Property Tests // ============================================================================ @@ -400,6 +444,10 @@ TEST_F(CommonShimsSlimTest, GetDim_CPU) { runGetDimTest(slim_c10::DeviceType::CPU); } +TEST_F(CommonShimsSlimTest, GetNumel_CPU) { + runGetNumelTest(slim_c10::DeviceType::CPU); +} + TEST_F(CommonShimsSlimTest, GetStorageOffset_CPU) { runGetStorageOffsetTest(slim_c10::DeviceType::CPU); } @@ -456,6 +504,13 @@ TEST_F(CommonShimsSlimTest, GetDim_CUDA) { runGetDimTest(slim_c10::DeviceType::CUDA); } +TEST_F(CommonShimsSlimTest, GetNumel_CUDA) { + if (!isCudaAvailable()) { + GTEST_SKIP() << "CUDA not available"; + } + runGetNumelTest(slim_c10::DeviceType::CUDA); +} + TEST_F(CommonShimsSlimTest, GetStorageOffset_CUDA) { if (!isCudaAvailable()) { GTEST_SKIP() << "CUDA not available"; @@ -495,6 +550,7 @@ TEST_F(CommonShimsSlimTest, NullTensorArgument) { int64_t* strides = nullptr; int32_t dtype = -1; int64_t dim = -1; + int64_t numel = -1; EXPECT_EQ( aoti_torch_get_data_ptr(nullptr, &data_ptr), Error::InvalidArgument); @@ -502,6 +558,7 @@ TEST_F(CommonShimsSlimTest, NullTensorArgument) { EXPECT_EQ(aoti_torch_get_strides(nullptr, &strides), Error::InvalidArgument); EXPECT_EQ(aoti_torch_get_dtype(nullptr, &dtype), Error::InvalidArgument); EXPECT_EQ(aoti_torch_get_dim(nullptr, &dim), Error::InvalidArgument); + EXPECT_EQ(aoti_torch_get_numel(nullptr, &numel), Error::InvalidArgument); } TEST_F(CommonShimsSlimTest, NullReturnPointer) { @@ -512,6 +569,7 @@ TEST_F(CommonShimsSlimTest, NullReturnPointer) { EXPECT_EQ(aoti_torch_get_strides(tensor, nullptr), Error::InvalidArgument); EXPECT_EQ(aoti_torch_get_dtype(tensor, nullptr), Error::InvalidArgument); EXPECT_EQ(aoti_torch_get_dim(tensor, nullptr), Error::InvalidArgument); + EXPECT_EQ(aoti_torch_get_numel(tensor, nullptr), Error::InvalidArgument); } // ============================================================================ @@ -534,6 +592,7 @@ TEST_F(CommonShimsSlimTest, ScalarTensor) { int64_t* ret_sizes = nullptr; int64_t* ret_strides = nullptr; int64_t ret_dim = -1; + int64_t ret_numel = -1; EXPECT_EQ(aoti_torch_get_sizes(tensor, &ret_sizes), Error::Ok); EXPECT_NE(ret_sizes, nullptr); @@ -543,6 +602,9 @@ TEST_F(CommonShimsSlimTest, ScalarTensor) { EXPECT_EQ(aoti_torch_get_dim(tensor, &ret_dim), Error::Ok); EXPECT_EQ(ret_dim, 0); + + EXPECT_EQ(aoti_torch_get_numel(tensor, &ret_numel), Error::Ok); + EXPECT_EQ(ret_numel, 1); } TEST_F(CommonShimsSlimTest, LargeTensor) { @@ -559,6 +621,7 @@ TEST_F(CommonShimsSlimTest, LargeTensor) { int64_t* ret_sizes = nullptr; int64_t* ret_strides = nullptr; + int64_t ret_numel = -1; EXPECT_EQ(aoti_torch_get_sizes(tensor, &ret_sizes), Error::Ok); EXPECT_EQ(ret_sizes[0], 100); @@ -569,6 +632,9 @@ TEST_F(CommonShimsSlimTest, LargeTensor) { EXPECT_EQ(ret_strides[0], 60000); // 200 * 300 EXPECT_EQ(ret_strides[1], 300); // 300 EXPECT_EQ(ret_strides[2], 1); + + EXPECT_EQ(aoti_torch_get_numel(tensor, &ret_numel), Error::Ok); + EXPECT_EQ(ret_numel, 6000000); } TEST_F(CommonShimsSlimTest, ConsistentPointerReturn) { diff --git a/backends/cuda/cuda_backend.py b/backends/cuda/cuda_backend.py index ef746830bed..bf28077c62c 100644 --- a/backends/cuda/cuda_backend.py +++ b/backends/cuda/cuda_backend.py @@ -263,6 +263,13 @@ def _move_to_device_resize_kv(ep, location): return ep +def _on_off_compile_spec_value(spec: CompileSpec) -> bool: + value = spec.value.decode("utf-8").upper() + if value not in ["ON", "OFF"]: + raise ValueError(f"Invalid {spec.key}: {value}. Expected 'ON' or 'OFF'.") + return value == "ON" + + @final @experimental( "This API and all of cuda backend related functionality are experimental." @@ -496,12 +503,25 @@ def get_aoti_compile_options( # Parse compile_specs to check for platform platform = "linux" + emulate_precision_casts = True + max_autotune = True + autotune_at_compile_time = None shim_library_path = None for spec in compile_specs: if spec.key == "platform": platform = spec.value.decode("utf-8") - if spec.key == "shim_library_path": + elif spec.key == "emulate_precision_casts": + emulate_precision_casts = _on_off_compile_spec_value(spec) + elif spec.key == "max_autotune": + max_autotune = _on_off_compile_spec_value(spec) + elif spec.key == "autotune_at_compile_time": + autotune_at_compile_time = _on_off_compile_spec_value(spec) + elif spec.key == "shim_library_path": shim_library_path = spec.value.decode("utf-8") + options["emulate_precision_casts"] = emulate_precision_casts + options["max_autotune"] = max_autotune + if autotune_at_compile_time is not None: + options["triton.autotune_at_compile_time"] = autotune_at_compile_time # Add platform-specific options if platform == "windows": diff --git a/backends/cuda/runtime/aoti_cuda_shims.lib b/backends/cuda/runtime/aoti_cuda_shims.lib index 63c8d79bd7a..8bb03cc1c1e 100644 Binary files a/backends/cuda/runtime/aoti_cuda_shims.lib and b/backends/cuda/runtime/aoti_cuda_shims.lib differ diff --git a/backends/cuda/tests/test_cuda_export.py b/backends/cuda/tests/test_cuda_export.py index 83d792187d1..2bd3d4db109 100644 --- a/backends/cuda/tests/test_cuda_export.py +++ b/backends/cuda/tests/test_cuda_export.py @@ -16,6 +16,47 @@ from torch.export import export +class TestCudaBackendCompileOptions(unittest.TestCase): + def test_emulate_precision_casts_compile_spec(self): + options = CudaBackend.get_aoti_compile_options( + [CompileSpec(key="emulate_precision_casts", value=b"OFF")] + ) + + self.assertFalse(options["emulate_precision_casts"]) + + def test_invalid_emulate_precision_casts_compile_spec(self): + with self.assertRaisesRegex(ValueError, "Invalid emulate_precision_casts"): + CudaBackend.get_aoti_compile_options( + [CompileSpec(key="emulate_precision_casts", value=b"MAYBE")] + ) + + def test_max_autotune_compile_spec(self): + options = CudaBackend.get_aoti_compile_options( + [CompileSpec(key="max_autotune", value=b"OFF")] + ) + + self.assertFalse(options["max_autotune"]) + + def test_invalid_max_autotune_compile_spec(self): + with self.assertRaisesRegex(ValueError, "Invalid max_autotune"): + CudaBackend.get_aoti_compile_options( + [CompileSpec(key="max_autotune", value=b"MAYBE")] + ) + + def test_autotune_at_compile_time_compile_spec(self): + options = CudaBackend.get_aoti_compile_options( + [CompileSpec(key="autotune_at_compile_time", value=b"OFF")] + ) + + self.assertFalse(options["triton.autotune_at_compile_time"]) + + def test_invalid_autotune_at_compile_time_compile_spec(self): + with self.assertRaisesRegex(ValueError, "Invalid autotune_at_compile_time"): + CudaBackend.get_aoti_compile_options( + [CompileSpec(key="autotune_at_compile_time", value=b"MAYBE")] + ) + + class TestCudaExport(unittest.TestCase): """Test CUDA export functionality for various operations using to_edge_transform_and_lower.""" diff --git a/examples/models/dinov2/CMakeLists.txt b/examples/models/dinov2/CMakeLists.txt index a2af3002a35..8e83ee44873 100644 --- a/examples/models/dinov2/CMakeLists.txt +++ b/examples/models/dinov2/CMakeLists.txt @@ -7,7 +7,9 @@ cmake_minimum_required(VERSION 3.24) project(dinov2_runner) -set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/examples/models/llama/install_requirements.sh b/examples/models/llama/install_requirements.sh index 8a2fa25d244..7692306c50b 100755 --- a/examples/models/llama/install_requirements.sh +++ b/examples/models/llama/install_requirements.sh @@ -11,7 +11,18 @@ # Install snakeviz for cProfile flamegraph # Install lm-eval for Model Evaluation with lm-evalution-harness. # Install safetensors to load safetensors checkpoints (currently adapter only). -pip install hydra-core huggingface_hub tiktoken torchtune sentencepiece tokenizers snakeviz lm_eval==0.4.5 blobfile safetensors +TORCHTUNE_COMMIT=3c1872ace149f03ef4ffec765d3f0a5fd0399497 +pip install \ + hydra-core \ + huggingface_hub \ + tiktoken \ + "torchtune @ git+https://github.com/pytorch/torchtune.git@${TORCHTUNE_COMMIT}" \ + sentencepiece \ + tokenizers \ + snakeviz \ + lm_eval==0.4.5 \ + blobfile \ + safetensors # Call the install helper for further setup python examples/models/llama/install_requirement_helper.py diff --git a/examples/models/parakeet/CMakeLists.txt b/examples/models/parakeet/CMakeLists.txt index a2b798de557..9449583c613 100644 --- a/examples/models/parakeet/CMakeLists.txt +++ b/examples/models/parakeet/CMakeLists.txt @@ -7,7 +7,9 @@ cmake_minimum_required(VERSION 3.24) project(parakeet_runner) -set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/examples/models/qwen3_5_moe/export.py b/examples/models/qwen3_5_moe/export.py index d2c3914c6a2..9485a5ee32c 100644 --- a/examples/models/qwen3_5_moe/export.py +++ b/examples/models/qwen3_5_moe/export.py @@ -1073,6 +1073,8 @@ def _export_cuda(model, config, args): "enable_dynamic_shape": True, "get_mutable_buffer_metadata": _mutable_buffer_metadata_json(model), } + # Avoid a PyTorch 2.13 Triton codegen bug in Qwen's fused cast/reduction + # compile-time autotune path while keeping the CUDA backend defaults unchanged. et_prog = to_edge_transform_and_lower( {"decode": decode_ep, "prefill": prefill_ep}, partitioner={ @@ -1081,6 +1083,9 @@ def _export_cuda(model, config, args): [ CudaBackend.generate_method_name_compile_spec("decode"), CompileSpec("low_memory_mode", b"ON"), + CompileSpec("emulate_precision_casts", b"OFF"), + CompileSpec("max_autotune", b"OFF"), + CompileSpec("autotune_at_compile_time", b"OFF"), ] ) ], @@ -1089,6 +1094,9 @@ def _export_cuda(model, config, args): [ CudaBackend.generate_method_name_compile_spec("prefill"), CompileSpec("low_memory_mode", b"ON"), + CompileSpec("emulate_precision_casts", b"OFF"), + CompileSpec("max_autotune", b"OFF"), + CompileSpec("autotune_at_compile_time", b"OFF"), ] ) ], diff --git a/examples/models/sortformer/CMakeLists.txt b/examples/models/sortformer/CMakeLists.txt index bdc0fbfbbe5..171eb726ed2 100644 --- a/examples/models/sortformer/CMakeLists.txt +++ b/examples/models/sortformer/CMakeLists.txt @@ -7,7 +7,9 @@ cmake_minimum_required(VERSION 3.24) project(sortformer_runner) -set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/examples/models/voxtral_realtime/CMakeLists.txt b/examples/models/voxtral_realtime/CMakeLists.txt index 28545f407ca..93fa9249cad 100644 --- a/examples/models/voxtral_realtime/CMakeLists.txt +++ b/examples/models/voxtral_realtime/CMakeLists.txt @@ -7,7 +7,9 @@ cmake_minimum_required(VERSION 3.24) project(voxtral_realtime) -set(CMAKE_CXX_STANDARD 17) +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..) diff --git a/extension/llm/export/nvfp4.py b/extension/llm/export/nvfp4.py index feeb95f50a6..b0671d11173 100644 --- a/extension/llm/export/nvfp4.py +++ b/extension/llm/export/nvfp4.py @@ -161,7 +161,7 @@ def _exportable_nvfp4_transform(module: nn.Module, config: ExportableNVFP4Config f"NVFP4 requires weight dims divisible by 16, got {weight.shape}" ) - per_tensor_scale = 1.0 + per_tensor_scale = None if config.use_per_tensor_scale: tensor_amax = torch.max(torch.abs(weight)) per_tensor_scale = per_tensor_amax_to_scale(tensor_amax) @@ -173,7 +173,11 @@ def _exportable_nvfp4_transform(module: nn.Module, config: ExportableNVFP4Config qdata_u32 = qdata_packed.view(torch.uint32) scales_u8 = scales_fp8.view(torch.uint8) - pts = torch.tensor(per_tensor_scale, dtype=torch.float32) + pts = torch.as_tensor( + 1.0 if per_tensor_scale is None else per_tensor_scale, + dtype=torch.float32, + device=weight.device, + ) quantized_weight = ExportableNVFP4Tensor( qdata_u32, scales_u8, diff --git a/install_requirements.py b/install_requirements.py index 53204ffd3ee..7986cfacff9 100644 --- a/install_requirements.py +++ b/install_requirements.py @@ -15,6 +15,8 @@ # The pip repository that hosts nightly torch packages. # This will be dynamically set based on CUDA availability and CUDA backend enabled/disabled. TORCH_URL_BASE = "https://download.pytorch.org/whl/test" +TORCHAO_URL_BASE = "https://download.pytorch.org/whl/nightly" +TORCHAO_NIGHTLY_VERSION = "0.18.0.dev20260715" # Since ExecuTorch often uses main-branch features of pytorch, only the nightly # pip versions will have the required features. @@ -43,13 +45,15 @@ def install_requirements(use_pytorch_nightly): # Determine the appropriate PyTorch URL based on CUDA delegate status torch_url = determine_torch_url(TORCH_URL_BASE) + torchao_url = determine_torch_url(TORCHAO_URL_BASE) # pip packages needed by exir. TORCH_PACKAGE = [ # Setting use_pytorch_nightly to false to test the pinned PyTorch commit. Note # that we don't need to set any version number there because they have already # been installed on CI before this step, so pip won't reinstall them - ("torch==2.12.0" if use_pytorch_nightly else "torch"), + ("torch==2.13.0" if use_pytorch_nightly else "torch"), + f"torchao=={TORCHAO_NIGHTLY_VERSION}", ] # Install the requirements for core ExecuTorch package. @@ -66,44 +70,48 @@ def install_requirements(use_pytorch_nightly): *TORCH_PACKAGE, "--extra-index-url", torch_url, + "--extra-index-url", + torchao_url, ], check=True, ) - LOCAL_REQUIREMENTS = [ - "third-party/ao", # We need the latest kernels for fast iteration, so not relying on pypi. - ] + ( - [ - "extension/llm/tokenizers", # TODO(larryliu0820): Setup a pypi package for this. - ] - if sys.platform != "win32" - else [] - ) # TODO(gjcomer): Re-enable when buildable on Windows. - - # Install packages directly from local copy instead of pypi. - # This is usually not recommended. - new_env = os.environ.copy() - if ("EXECUTORCH_BUILD_KERNELS_TORCHAO" not in new_env) or ( - new_env["EXECUTORCH_BUILD_KERNELS_TORCHAO"] == "0" + LOCAL_REQUIREMENTS = [] + if ( + os.environ.get("EXECUTORCH_BUILD_KERNELS_TORCHAO") == "1" + or os.environ.get("TORCHAO_BUILD_EXPERIMENTAL_MPS") == "1" ): - new_env["USE_CPP"] = "0" - else: - assert new_env["EXECUTORCH_BUILD_KERNELS_TORCHAO"] == "1" - new_env["USE_CPP"] = "1" - new_env["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" - subprocess.run( - [ - sys.executable, - "-m", - "pip", - "install", - # Without --no-build-isolation, setup.py can't find the torch module. - "--no-build-isolation", - *LOCAL_REQUIREMENTS, - ], - env=new_env, - check=True, - ) + LOCAL_REQUIREMENTS.append("third-party/ao") + if sys.platform != "win32": + # TODO(larryliu0820): Setup a pypi package for this. + LOCAL_REQUIREMENTS.append("extension/llm/tokenizers") + # TODO(gjcomer): Re-enable when buildable on Windows. + + if LOCAL_REQUIREMENTS: + # Install packages directly from local copy instead of pypi. + # This is usually not recommended. + new_env = os.environ.copy() + if ("EXECUTORCH_BUILD_KERNELS_TORCHAO" not in new_env) or ( + new_env["EXECUTORCH_BUILD_KERNELS_TORCHAO"] == "0" + ): + new_env["USE_CPP"] = "0" + else: + assert new_env["EXECUTORCH_BUILD_KERNELS_TORCHAO"] == "1" + new_env["USE_CPP"] = "1" + new_env["CMAKE_POLICY_VERSION_MINIMUM"] = "3.5" + subprocess.run( + [ + sys.executable, + "-m", + "pip", + "install", + # Without --no-build-isolation, setup.py can't find the torch module. + "--no-build-isolation", + *LOCAL_REQUIREMENTS, + ], + env=new_env, + check=True, + ) def install_optional_example_requirements(use_pytorch_nightly): @@ -112,7 +120,7 @@ def install_optional_example_requirements(use_pytorch_nightly): print("Installing torch domain libraries") DOMAIN_LIBRARIES = [ - ("torchvision==0.27.0" if use_pytorch_nightly else "torchvision"), + ("torchvision==0.28.0" if use_pytorch_nightly else "torchvision"), ("torchaudio==2.11.0" if use_pytorch_nightly else "torchaudio"), ] # Then install domain libraries diff --git a/kernels/optimized/cpu/op_add.cpp b/kernels/optimized/cpu/op_add.cpp index 562d4e227dd..96a1ef049da 100644 --- a/kernels/optimized/cpu/op_add.cpp +++ b/kernels/optimized/cpu/op_add.cpp @@ -51,7 +51,7 @@ Tensor& opt_add_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "add.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "add.out"); if (b.numel() == 1) { if (executorch::runtime::isComplexType(a_type) || @@ -129,7 +129,7 @@ Tensor& opt_add_scalar_out( ctx, resize_tensor(out, a.sizes()) == Error::Ok, InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "add.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "add.Scalar_out"); if (a_type == common_type && a_type == out_type && a_type != ScalarType::Half && a_type != ScalarType::BFloat16) { diff --git a/kernels/optimized/cpu/op_add_sub_impl.h b/kernels/optimized/cpu/op_add_sub_impl.h index d15c143770d..d2a84eb6d6f 100644 --- a/kernels/optimized/cpu/op_add_sub_impl.h +++ b/kernels/optimized/cpu/op_add_sub_impl.h @@ -22,7 +22,7 @@ namespace impl { using Tensor = executorch::aten::Tensor; using ScalarType = executorch::aten::ScalarType; -template +template Tensor& opt_add_sub_out_impl( KernelRuntimeContext& ctx, const Tensor& a, diff --git a/kernels/optimized/cpu/op_div.cpp b/kernels/optimized/cpu/op_div.cpp index c2da64e7088..855b2bb23f4 100644 --- a/kernels/optimized/cpu/op_div.cpp +++ b/kernels/optimized/cpu/op_div.cpp @@ -56,7 +56,7 @@ Tensor& opt_div_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.out"); ScalarType a_type = a.scalar_type(); ScalarType b_type = b.scalar_type(); @@ -196,7 +196,7 @@ Tensor& opt_div_scalar_out( ctx, resize_tensor(out, a.sizes()) == Error::Ok, InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.Scalar_out"); if (a_type == common_type && a_type == out_type && a_type != ScalarType::Half && a_type != ScalarType::BFloat16) { diff --git a/kernels/optimized/cpu/op_le.cpp b/kernels/optimized/cpu/op_le.cpp index 60696f1d2f1..bf1f3ba6b15 100644 --- a/kernels/optimized/cpu/op_le.cpp +++ b/kernels/optimized/cpu/op_le.cpp @@ -40,7 +40,7 @@ Tensor& opt_le_tensor_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "le.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "le.Tensor_out"); // Check for optimized broadcast paths auto selected_optimized_path = select_optimized_path(a, b, out); @@ -85,7 +85,7 @@ Tensor& opt_le_scalar_out( ctx, resize_tensor(out, a.sizes()) == Error::Ok, InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "le.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "le.Scalar_out"); if (a_type == common_type && a_type == out_type && a_type != ScalarType::Half && a_type != ScalarType::BFloat16) { diff --git a/kernels/optimized/cpu/op_mul.cpp b/kernels/optimized/cpu/op_mul.cpp index 48670b7441b..f6bfc7a8dac 100644 --- a/kernels/optimized/cpu/op_mul.cpp +++ b/kernels/optimized/cpu/op_mul.cpp @@ -44,7 +44,7 @@ Tensor& opt_mul_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "mul.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "mul.out"); if (b.numel() == 1) { if (a_type == b_type && a_type == out_type && a_type != ScalarType::Half && @@ -165,7 +165,7 @@ Tensor& opt_mul_scalar_out( ctx, resize_tensor(out, a.sizes()) == Error::Ok, InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "mul.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "mul.Scalar_out"); if (a_type == common_type && a_type == out_type && a_type != ScalarType::Half && a_type != ScalarType::BFloat16) { diff --git a/kernels/optimized/cpu/op_sub.cpp b/kernels/optimized/cpu/op_sub.cpp index 41d46d1661e..29c54506417 100644 --- a/kernels/optimized/cpu/op_sub.cpp +++ b/kernels/optimized/cpu/op_sub.cpp @@ -55,7 +55,7 @@ Tensor& opt_sub_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sub.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "sub.out"); if (a.numel() == 1 || b.numel() == 1) { if (a_type == b_type && a_type == out_type && a_type != ScalarType::Half && @@ -137,7 +137,7 @@ Tensor& opt_sub_scalar_out( ctx, resize_tensor(out, a.sizes()) == Error::Ok, InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sub.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "sub.Scalar_out"); if (a_type == common_type && a_type == out_type && a_type != ScalarType::Half && a_type != ScalarType::BFloat16) { diff --git a/kernels/optimized/cpu/op_where.cpp b/kernels/optimized/cpu/op_where.cpp index f2c25119400..0087f49704e 100644 --- a/kernels/optimized/cpu/op_where.cpp +++ b/kernels/optimized/cpu/op_where.cpp @@ -40,7 +40,7 @@ Tensor& opt_where_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "where.self_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "where.self_out"); if (a.scalar_type() == b.scalar_type() && a.scalar_type() == out.scalar_type() && a.scalar_type() == compute_type && diff --git a/kernels/portable/cpu/op_abs.cpp b/kernels/portable/cpu/op_abs.cpp index 42072351a66..75c38867f01 100644 --- a/kernels/portable/cpu/op_abs.cpp +++ b/kernels/portable/cpu/op_abs.cpp @@ -38,7 +38,7 @@ Tensor& abs_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "abs.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "abs.out"); if (in_is_complex) { // NOTE: Elected not to add COMPLEXH to dtype_util.h for now diff --git a/kernels/portable/cpu/op_add.cpp b/kernels/portable/cpu/op_add.cpp index c7782e4276b..2a438ce0fe4 100644 --- a/kernels/portable/cpu/op_add.cpp +++ b/kernels/portable/cpu/op_add.cpp @@ -48,7 +48,7 @@ Tensor& add_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "add.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "add.out"); if (executorch::runtime::isComplexType(a.scalar_type()) || executorch::runtime::isComplexType(b.scalar_type()) || @@ -124,7 +124,7 @@ Tensor& add_scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "add.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "add.Scalar_out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_addmm.cpp b/kernels/portable/cpu/op_addmm.cpp index 3e53100d356..5a455918685 100644 --- a/kernels/portable/cpu/op_addmm.cpp +++ b/kernels/portable/cpu/op_addmm.cpp @@ -54,7 +54,7 @@ Tensor& addmm_out( ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(in), InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "addmm.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "addmm.out"); ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() { CTYPE alpha_val = utils::scalar_to(alpha); diff --git a/kernels/portable/cpu/op_atan2.cpp b/kernels/portable/cpu/op_atan2.cpp index d5ec2516bd4..eaaddc9df9e 100644 --- a/kernels/portable/cpu/op_atan2.cpp +++ b/kernels/portable/cpu/op_atan2.cpp @@ -52,7 +52,7 @@ Tensor& atan2_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "atan2.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "atan2.out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_bitensor_elementwise_fn< diff --git a/kernels/portable/cpu/op_bitwise_and.cpp b/kernels/portable/cpu/op_bitwise_and.cpp index 609dcb1e949..6daa7e76396 100644 --- a/kernels/portable/cpu/op_bitwise_and.cpp +++ b/kernels/portable/cpu/op_bitwise_and.cpp @@ -20,7 +20,7 @@ Tensor& bitwise_and_Tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_and.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_and.Tensor_out"); return internal::bitwise_tensor_out(ctx, a, b, out); } @@ -30,7 +30,7 @@ Tensor& bitwise_and_Scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_and.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_and.Scalar_out"); return internal::bitwise_scalar_out(ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_bitwise_left_shift.cpp b/kernels/portable/cpu/op_bitwise_left_shift.cpp index 1a229950181..6e8e0fa39c1 100644 --- a/kernels/portable/cpu/op_bitwise_left_shift.cpp +++ b/kernels/portable/cpu/op_bitwise_left_shift.cpp @@ -18,7 +18,7 @@ Tensor& bitwise_left_shift_Tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_left_shift.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_left_shift.Tensor_out"); return internal::bitwise_tensor_out( ctx, a, b, out); } @@ -29,8 +29,7 @@ Tensor& bitwise_left_shift_Tensor_Scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = - "bitwise_left_shift.Tensor_Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_left_shift.Tensor_Scalar_out"); return internal::bitwise_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_bitwise_or.cpp b/kernels/portable/cpu/op_bitwise_or.cpp index 42cb2a6c3ba..96ecbfa62ab 100644 --- a/kernels/portable/cpu/op_bitwise_or.cpp +++ b/kernels/portable/cpu/op_bitwise_or.cpp @@ -20,7 +20,7 @@ Tensor& bitwise_or_Tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_or.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_or.Tensor_out"); return internal::bitwise_tensor_out(ctx, a, b, out); } @@ -30,7 +30,7 @@ Tensor& bitwise_or_Scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_or.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_or.Scalar_out"); return internal::bitwise_scalar_out(ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_bitwise_right_shift.cpp b/kernels/portable/cpu/op_bitwise_right_shift.cpp index 9d54b8d0c8e..5f91351c54e 100644 --- a/kernels/portable/cpu/op_bitwise_right_shift.cpp +++ b/kernels/portable/cpu/op_bitwise_right_shift.cpp @@ -18,7 +18,7 @@ Tensor& bitwise_right_shift_Tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_right_shift.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_right_shift.Tensor_out"); return internal::bitwise_tensor_out( ctx, a, b, out); } @@ -29,8 +29,7 @@ Tensor& bitwise_right_shift_Tensor_Scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = - "bitwise_right_shift.Tensor_Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_right_shift.Tensor_Scalar_out"); return internal::bitwise_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_bitwise_xor.cpp b/kernels/portable/cpu/op_bitwise_xor.cpp index 5fe4e1708d5..b56ba9ac4dd 100644 --- a/kernels/portable/cpu/op_bitwise_xor.cpp +++ b/kernels/portable/cpu/op_bitwise_xor.cpp @@ -20,7 +20,7 @@ Tensor& bitwise_xor_Tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_xor.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_xor.Tensor_out"); return internal::bitwise_tensor_out(ctx, a, b, out); } @@ -30,7 +30,7 @@ Tensor& bitwise_xor_Scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "bitwise_xor.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "bitwise_xor.Scalar_out"); return internal::bitwise_scalar_out(ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_clamp.cpp b/kernels/portable/cpu/op_clamp.cpp index 72134ae9ff8..9c67dddba92 100644 --- a/kernels/portable/cpu/op_clamp.cpp +++ b/kernels/portable/cpu/op_clamp.cpp @@ -42,7 +42,7 @@ ET_NODISCARD bool check_bounds( auto is_valid = true; // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "clamp.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "clamp.out"); if (isIntegralType(out_type, /*includeBool=*/false)) { const int64_t val_long = utils::scalar_to(val_scalar); @@ -132,7 +132,7 @@ Tensor& clamp_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "clamp.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "clamp.out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_unitensor_elementwise_fn< @@ -210,7 +210,7 @@ Tensor& clamp_tensor_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "clamp.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "clamp.Tensor_out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_tritensor_elementwise_fn< diff --git a/kernels/portable/cpu/op_convolution.cpp b/kernels/portable/cpu/op_convolution.cpp index bf848bc53c2..df606bc5d95 100644 --- a/kernels/portable/cpu/op_convolution.cpp +++ b/kernels/portable/cpu/op_convolution.cpp @@ -410,7 +410,7 @@ Tensor& convolution_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char name[] = "convolution.out"; + ET_DEFINE_OPERATOR_NAME(name, "convolution.out"); ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, name, CTYPE, [&]() { const auto load_bias = bias.has_value() diff --git a/kernels/portable/cpu/op_copy.cpp b/kernels/portable/cpu/op_copy.cpp index 8164d1ebb02..a7fe8ac7493 100644 --- a/kernels/portable/cpu/op_copy.cpp +++ b/kernels/portable/cpu/op_copy.cpp @@ -44,7 +44,7 @@ Tensor& copy_out( ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "copy.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "copy.out"); // Use direct copy fast path if broadcast is not needed and tensors are // non-empty @@ -87,7 +87,7 @@ Tensor& copy_( ctx, tensors_have_same_dim_order(in, src), InvalidArgument, in); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "copy_"; + ET_DEFINE_OPERATOR_NAME(op_name, "copy_"); // Use direct copy fast path if broadcast is not needed and tensors are // non-empty diff --git a/kernels/portable/cpu/op_cumsum.cpp b/kernels/portable/cpu/op_cumsum.cpp index 3a518d30715..5023be7b694 100644 --- a/kernels/portable/cpu/op_cumsum.cpp +++ b/kernels/portable/cpu/op_cumsum.cpp @@ -109,7 +109,7 @@ Tensor& cumsum_out( dim = (self.dim() == 0) ? 0 : dim < 0 ? dim + self.dim() : dim; // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "cumsum.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "cumsum.out"); ET_SWITCH_REALHBBF16_TYPES(out.scalar_type(), ctx, op_name, CTYPE_OUT, [&]() { const auto load_self = diff --git a/kernels/portable/cpu/op_div.cpp b/kernels/portable/cpu/op_div.cpp index 299997ad322..700cefcd55c 100644 --- a/kernels/portable/cpu/op_div.cpp +++ b/kernels/portable/cpu/op_div.cpp @@ -55,7 +55,7 @@ Tensor& div_out( out); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.out"); if (executorch::runtime::isComplexType(common_type)) { ET_SWITCH_COMPLEX_TYPES(common_type, ctx, op_name, CTYPE, [&]() { @@ -129,7 +129,7 @@ Tensor& div_out_mode( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.out_mode"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.out_mode"); const bool mode_is_trunc = mode_val == "trunc"; bool div_by_zero_error = false; @@ -200,7 +200,7 @@ Tensor& div_scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.Scalar_out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); @@ -268,7 +268,7 @@ Tensor& div_scalar_mode_out( const bool mode_is_trunc = mode_val == "trunc"; // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "div.Scalar_mode_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "div.Scalar_mode_out"); ET_SWITCH_REAL_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_elu.cpp b/kernels/portable/cpu/op_elu.cpp index 2e03111502b..e760f7fbced 100644 --- a/kernels/portable/cpu/op_elu.cpp +++ b/kernels/portable/cpu/op_elu.cpp @@ -33,7 +33,7 @@ Tensor& elu_out( ET_KERNEL_CHECK(ctx, tensors_have_same_dtype(in, out), InvalidArgument, out); - static constexpr const char op_name[] = "elu.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "elu.out"); ET_SWITCH_FLOATHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() { using MathT = std:: conditional_t, float, CTYPE>; diff --git a/kernels/portable/cpu/op_eq.cpp b/kernels/portable/cpu/op_eq.cpp index 9e21b82c43c..2c59a64cde8 100644 --- a/kernels/portable/cpu/op_eq.cpp +++ b/kernels/portable/cpu/op_eq.cpp @@ -20,7 +20,7 @@ Tensor& eq_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "eq.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "eq.Tensor_out"); return internal::comparison_tensor_out( ctx, a, b, out); } @@ -31,7 +31,7 @@ Tensor& eq_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "eq.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "eq.Scalar_out"); return internal::comparison_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_floor_divide.cpp b/kernels/portable/cpu/op_floor_divide.cpp index 50723c3fa0a..416d599eb25 100644 --- a/kernels/portable/cpu/op_floor_divide.cpp +++ b/kernels/portable/cpu/op_floor_divide.cpp @@ -48,7 +48,7 @@ Tensor& floor_divide_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "floor_divide.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "floor_divide.out"); bool div_by_zero_error = false; diff --git a/kernels/portable/cpu/op_fmod.cpp b/kernels/portable/cpu/op_fmod.cpp index 05bb4f9e553..de0d44fd2f1 100644 --- a/kernels/portable/cpu/op_fmod.cpp +++ b/kernels/portable/cpu/op_fmod.cpp @@ -50,7 +50,7 @@ Tensor& fmod_Tensor_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "fmod.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "fmod.Tensor_out"); bool div_by_zero_error = false; @@ -130,7 +130,7 @@ Tensor& fmod_Scalar_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "fmod.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "fmod.Scalar_out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_ge.cpp b/kernels/portable/cpu/op_ge.cpp index d5e7576b7ae..50cdd2c3010 100644 --- a/kernels/portable/cpu/op_ge.cpp +++ b/kernels/portable/cpu/op_ge.cpp @@ -20,7 +20,7 @@ Tensor& ge_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "ge.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "ge.Tensor_out"); return internal::comparison_tensor_out( ctx, a, b, out); } @@ -31,7 +31,7 @@ Tensor& ge_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "ge.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "ge.Scalar_out"); return internal::comparison_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_glu.cpp b/kernels/portable/cpu/op_glu.cpp index f204b0fd516..9cad01d05e2 100644 --- a/kernels/portable/cpu/op_glu.cpp +++ b/kernels/portable/cpu/op_glu.cpp @@ -91,7 +91,7 @@ Tensor& glu_out_tensor( ? self.scalar_type() : ScalarType::Float; // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "glu.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "glu.out"); ET_SWITCH_FLOATHBF16_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_bitensor_elementwise_fn< CTYPE_COMPUTE, diff --git a/kernels/portable/cpu/op_gt.cpp b/kernels/portable/cpu/op_gt.cpp index cd65a3b68d9..3aa504782fc 100644 --- a/kernels/portable/cpu/op_gt.cpp +++ b/kernels/portable/cpu/op_gt.cpp @@ -20,7 +20,7 @@ Tensor& gt_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "gt.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "gt.Tensor_out"); return internal::comparison_tensor_out(ctx, a, b, out); } @@ -30,7 +30,7 @@ Tensor& gt_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "gt.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "gt.Scalar_out"); return internal::comparison_scalar_out(ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_le.cpp b/kernels/portable/cpu/op_le.cpp index 909de1bfad2..76fbb811dd5 100644 --- a/kernels/portable/cpu/op_le.cpp +++ b/kernels/portable/cpu/op_le.cpp @@ -20,7 +20,7 @@ Tensor& le_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "le.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "le.Tensor_out"); return internal::comparison_tensor_out( ctx, a, b, out); } @@ -31,7 +31,7 @@ Tensor& le_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "le.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "le.Scalar_out"); return internal::comparison_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_logical_and.cpp b/kernels/portable/cpu/op_logical_and.cpp index 361c9a3dbc5..35a47dc5932 100644 --- a/kernels/portable/cpu/op_logical_and.cpp +++ b/kernels/portable/cpu/op_logical_and.cpp @@ -27,7 +27,7 @@ Tensor& logical_and_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "logical_and.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "logical_and.out"); return internal::logical_tensor_out(logical_and, ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_logical_or.cpp b/kernels/portable/cpu/op_logical_or.cpp index d654104a69e..1a4d6f6cd32 100644 --- a/kernels/portable/cpu/op_logical_or.cpp +++ b/kernels/portable/cpu/op_logical_or.cpp @@ -27,7 +27,7 @@ Tensor& logical_or_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "logical_or.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "logical_or.out"); return internal::logical_tensor_out(logical_or, ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_logical_xor.cpp b/kernels/portable/cpu/op_logical_xor.cpp index 854dd8e572f..74dfb0fdeff 100644 --- a/kernels/portable/cpu/op_logical_xor.cpp +++ b/kernels/portable/cpu/op_logical_xor.cpp @@ -27,7 +27,7 @@ Tensor& logical_xor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "logical_xor.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "logical_xor.out"); return internal::logical_tensor_out(logical_xor, ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_lt.cpp b/kernels/portable/cpu/op_lt.cpp index 5af89920536..e837f587302 100644 --- a/kernels/portable/cpu/op_lt.cpp +++ b/kernels/portable/cpu/op_lt.cpp @@ -20,7 +20,7 @@ Tensor& lt_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "lt.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "lt.Tensor_out"); return internal::comparison_tensor_out(ctx, a, b, out); } @@ -30,7 +30,7 @@ Tensor& lt_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "lt.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "lt.Scalar_out"); return internal::comparison_scalar_out(ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_maximum.cpp b/kernels/portable/cpu/op_maximum.cpp index 3da154ede82..63fd022f78f 100644 --- a/kernels/portable/cpu/op_maximum.cpp +++ b/kernels/portable/cpu/op_maximum.cpp @@ -42,7 +42,7 @@ Tensor& maximum_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "maximum.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "maximum.out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_bitensor_elementwise_fn< diff --git a/kernels/portable/cpu/op_minimum.cpp b/kernels/portable/cpu/op_minimum.cpp index 1bac23187d8..f12c5c6acf9 100644 --- a/kernels/portable/cpu/op_minimum.cpp +++ b/kernels/portable/cpu/op_minimum.cpp @@ -42,7 +42,7 @@ Tensor& minimum_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "minimum.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "minimum.out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_bitensor_elementwise_fn< diff --git a/kernels/portable/cpu/op_mul.cpp b/kernels/portable/cpu/op_mul.cpp index 58172c249d4..e8785141fd1 100644 --- a/kernels/portable/cpu/op_mul.cpp +++ b/kernels/portable/cpu/op_mul.cpp @@ -42,7 +42,7 @@ Tensor& mul_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "mul.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "mul.out"); ET_KERNEL_CHECK( ctx, @@ -108,7 +108,7 @@ Tensor& mul_scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "mul.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "mul.Scalar_out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_native_dropout.cpp b/kernels/portable/cpu/op_native_dropout.cpp index dc72fb54599..956a930203d 100644 --- a/kernels/portable/cpu/op_native_dropout.cpp +++ b/kernels/portable/cpu/op_native_dropout.cpp @@ -45,7 +45,7 @@ std::tuple native_dropout_out( prob); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "native_dropout.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "native_dropout.out"); if ((!train.has_value() || train.value()) && prob != 0) { { std::mt19937 gen((std::random_device())()); diff --git a/kernels/portable/cpu/op_ne.cpp b/kernels/portable/cpu/op_ne.cpp index a4b292359df..f2e8d4070df 100644 --- a/kernels/portable/cpu/op_ne.cpp +++ b/kernels/portable/cpu/op_ne.cpp @@ -20,7 +20,7 @@ Tensor& ne_tensor_out( const Tensor& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "ne.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "ne.Tensor_out"); return internal::comparison_tensor_out( ctx, a, b, out); } @@ -31,7 +31,7 @@ Tensor& ne_scalar_out( const Scalar& b, Tensor& out) { // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "ne.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "ne.Scalar_out"); return internal::comparison_scalar_out( ctx, a, b, out); } diff --git a/kernels/portable/cpu/op_neg.cpp b/kernels/portable/cpu/op_neg.cpp index 4d7a9284e4c..ed416a14547 100644 --- a/kernels/portable/cpu/op_neg.cpp +++ b/kernels/portable/cpu/op_neg.cpp @@ -33,7 +33,7 @@ Tensor& neg_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { ET_KERNEL_CHECK( ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out); - static constexpr const char op_name[] = "neg.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "neg.out"); ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] { utils::internal::apply_unitensor_elementwise_fn< CTYPE, diff --git a/kernels/portable/cpu/op_pow.cpp b/kernels/portable/cpu/op_pow.cpp index 31085165dde..14f634e5073 100644 --- a/kernels/portable/cpu/op_pow.cpp +++ b/kernels/portable/cpu/op_pow.cpp @@ -50,7 +50,7 @@ Tensor& pow_Tensor_Tensor_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "pow.Tensor_Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "pow.Tensor_Tensor_out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_bitensor_elementwise_fn< @@ -102,7 +102,7 @@ Tensor& pow_Tensor_Scalar_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "pow.Tensor_Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "pow.Tensor_Scalar_out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); @@ -157,7 +157,7 @@ Tensor& pow_Scalar_out( } // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "pow.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "pow.Scalar_out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_a = utils::scalar_to(a); diff --git a/kernels/portable/cpu/op_remainder.cpp b/kernels/portable/cpu/op_remainder.cpp index 01a5d72de01..912827cf3a8 100644 --- a/kernels/portable/cpu/op_remainder.cpp +++ b/kernels/portable/cpu/op_remainder.cpp @@ -48,7 +48,7 @@ Tensor& remainder_Tensor_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "remainder.Tensor_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "remainder.Tensor_out"); bool div_by_zero_error = false; @@ -125,7 +125,7 @@ Tensor& remainder_Scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "remainder.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "remainder.Scalar_out"); ET_SWITCH_REAL_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_rsub.cpp b/kernels/portable/cpu/op_rsub.cpp index 17faed95c52..7a80e20f266 100644 --- a/kernels/portable/cpu/op_rsub.cpp +++ b/kernels/portable/cpu/op_rsub.cpp @@ -47,7 +47,7 @@ Tensor& rsub_scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "rsub.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "rsub.Scalar_out"); ET_SWITCH_REAL_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_sigmoid.cpp b/kernels/portable/cpu/op_sigmoid.cpp index 08c85e8fd01..8fa0458356c 100644 --- a/kernels/portable/cpu/op_sigmoid.cpp +++ b/kernels/portable/cpu/op_sigmoid.cpp @@ -40,7 +40,7 @@ Tensor& sigmoid_out(KernelRuntimeContext& ctx, const Tensor& in, Tensor& out) { compute_type = utils::get_compute_type(compute_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sigmoid.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "sigmoid.out"); ET_SWITCH_FLOAT_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_unitensor_elementwise_fn< diff --git a/kernels/portable/cpu/op_sub.cpp b/kernels/portable/cpu/op_sub.cpp index 32322aa90cd..e64a309dc4c 100644 --- a/kernels/portable/cpu/op_sub.cpp +++ b/kernels/portable/cpu/op_sub.cpp @@ -52,7 +52,7 @@ Tensor& sub_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sub.out"; + ET_DEFINE_OPERATOR_NAME(op_name, "sub.out"); ET_SWITCH_REAL_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_alpha = utils::scalar_to(alpha); @@ -107,7 +107,7 @@ Tensor& sub_scalar_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "sub.Scalar_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "sub.Scalar_out"); ET_SWITCH_REAL_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { const CTYPE_COMPUTE val_b = utils::scalar_to(b); diff --git a/kernels/portable/cpu/op_where.cpp b/kernels/portable/cpu/op_where.cpp index b1eb4ff442c..e5f98f925e5 100644 --- a/kernels/portable/cpu/op_where.cpp +++ b/kernels/portable/cpu/op_where.cpp @@ -40,7 +40,7 @@ Tensor& where_out( ScalarType compute_type = utils::get_compute_type(common_type); // @lint-ignore CLANGTIDY facebook-hte-CArray - static constexpr const char op_name[] = "where.self_out"; + ET_DEFINE_OPERATOR_NAME(op_name, "where.self_out"); ET_SWITCH_REALB_TYPES(compute_type, ctx, op_name, CTYPE_COMPUTE, [&]() { utils::apply_tritensor_elementwise_fn< diff --git a/kernels/portable/cpu/pattern/bitwise_op.h b/kernels/portable/cpu/pattern/bitwise_op.h index ca869c77162..858f0eeabee 100644 --- a/kernels/portable/cpu/pattern/bitwise_op.h +++ b/kernels/portable/cpu/pattern/bitwise_op.h @@ -45,9 +45,9 @@ struct bit_rshift { template using bitwise_fn = T (*)(const T, const T); -template +template constexpr bitwise_fn get_bitwise_fn() { - std::string_view op = op_name; + std::string_view op = static_cast(op_name); if (op == "bitwise_and.Tensor_out" || op == "bitwise_and.Scalar_out") { return bitwise_and; } @@ -60,7 +60,7 @@ constexpr bitwise_fn get_bitwise_fn() { return nullptr; }; -template +template struct BitwiseFnForOp { static constexpr auto get_value() { return get_bitwise_fn(); @@ -68,7 +68,7 @@ struct BitwiseFnForOp { static_assert(get_value() != nullptr, "unknown op_name!"); }; -template