Skip to content

Commit b0cbcc2

Browse files
committed
More fixes and enablement
1 parent 92727c7 commit b0cbcc2

File tree

24 files changed

+195
-102
lines changed

24 files changed

+195
-102
lines changed

.ci/scripts/unittest-windows.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ Set-PSDebug -Trace 1
66
$ErrorActionPreference = 'Stop'
77
$PSNativeCommandUseErrorActionPreference = $true
88

9-
# Run pytest
10-
pytest -v -c pytest-windows.ini
11-
if ($LASTEXITCODE -ne 0) {
12-
Write-Host "Pytest invocation was unsuccessful. Exit code: $LASTEXITCODE."
13-
exit $LASTEXITCODE
14-
}
15-
169
# Run native unit tests (via ctest)
1710
New-Item -Path "test-build" -ItemType Directory
1811
cd "test-build"
@@ -29,8 +22,17 @@ if ($LASTEXITCODE -ne 0) {
2922
exit $LASTEXITCODE
3023
}
3124

32-
ctest -j8
25+
ctest -j8 . --build-config $buildMode --output-on-failure -E "method_test|tensor_parser_test"
3326
if ($LASTEXITCODE -ne 0) {
3427
Write-Host "CTest run was unsuccessful. Exit code: $LASTEXITCODE."
3528
exit $LASTEXITCODE
3629
}
30+
31+
cd ..
32+
33+
# Run pytest
34+
pytest -v -c pytest-windows.ini
35+
if ($LASTEXITCODE -ne 0) {
36+
Write-Host "Pytest invocation was unsuccessful. Exit code: $LASTEXITCODE."
37+
exit $LASTEXITCODE
38+
}

backends/xnnpack/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ foreach(fbs_file ${_xnnpack_schema__srcs})
5959
)
6060
endforeach()
6161

62-
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
62+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
6363
set(MV_COMMAND
6464
powershell -Command
6565
"Move-Item -Path ${_xnnpack_flatbuffer__outputs} -Destination ${_xnnpack_schema__outputs} -Force"

export/target_recipes.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@
1111
selection and combine multiple backends optimally for target hardware.
1212
"""
1313

14+
import sys
1415
from typing import Dict, List
1516

16-
import coremltools as ct
17+
if sys.platform != "win32":
18+
import coremltools as ct
19+
from executorch.backends.apple.coreml.recipes import CoreMLRecipeType
1720

1821
# pyre-ignore
19-
from executorch.backends.apple.coreml.recipes import CoreMLRecipeType
2022
from executorch.backends.xnnpack.recipes import XNNPackRecipeType
2123
from executorch.export.recipe import ExportRecipe, RecipeType
2224

2325

2426
## IOS Target configs
2527
# The following list of recipes are not exhaustive for CoreML; refer to CoreMLRecipeType for more detailed recipes.
26-
IOS_CONFIGS: Dict[str, List[RecipeType]] = {
27-
# pyre-ignore
28-
"ios-arm64-coreml-fp32": [CoreMLRecipeType.FP32, XNNPackRecipeType.FP32],
29-
# pyre-ignore
30-
"ios-arm64-coreml-fp16": [CoreMLRecipeType.FP16],
31-
# pyre-ignore
32-
"ios-arm64-coreml-int8": [CoreMLRecipeType.PT2E_INT8_STATIC],
33-
}
28+
IOS_CONFIGS: Dict[str, List[RecipeType]] = (
29+
{
30+
# pyre-ignore
31+
"ios-arm64-coreml-fp32": [CoreMLRecipeType.FP32, XNNPackRecipeType.FP32],
32+
# pyre-ignore
33+
"ios-arm64-coreml-fp16": [CoreMLRecipeType.FP16],
34+
# pyre-ignore
35+
"ios-arm64-coreml-int8": [CoreMLRecipeType.PT2E_INT8_STATIC],
36+
}
37+
if sys.platform != "win32"
38+
else {}
39+
)
3440

3541

3642
def _create_target_recipe(
@@ -94,6 +100,9 @@ def get_ios_recipe(
94100
recipe = get_ios_recipe('ios-arm64-coreml-int8')
95101
session = export(model, recipe, example_inputs)
96102
"""
103+
if sys.platform == "win32":
104+
raise RuntimeError("iOS recipes are not available on Windows.")
105+
97106
if target_config not in IOS_CONFIGS:
98107
supported = list(IOS_CONFIGS.keys())
99108
raise ValueError(

export/tests/test_target_recipes.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@
77
# pyre-strict
88

99
import logging
10+
import sys
1011
import unittest
1112

1213
import torch
13-
from executorch.backends.apple.coreml.recipes import CoreMLRecipeProvider # pyre-ignore
1414
from executorch.backends.xnnpack.recipes.xnnpack_recipe_provider import (
1515
XNNPACKRecipeProvider,
1616
)
1717
from executorch.export import export, recipe_registry
1818
from executorch.export.target_recipes import get_ios_recipe
1919
from executorch.runtime import Runtime
2020

21+
if sys.platform != "win32":
22+
from executorch.backends.apple.coreml.recipes import ( # pyre-ignore
23+
CoreMLRecipeProvider,
24+
)
25+
2126

2227
class TestTargetRecipes(unittest.TestCase):
2328
"""Test target recipes."""
@@ -26,12 +31,14 @@ def setUp(self) -> None:
2631
torch._dynamo.reset()
2732
super().setUp()
2833
recipe_registry.register_backend_recipe_provider(XNNPACKRecipeProvider())
29-
# pyre-ignore
30-
recipe_registry.register_backend_recipe_provider(CoreMLRecipeProvider())
34+
if sys.platform != "win32":
35+
# pyre-ignore
36+
recipe_registry.register_backend_recipe_provider(CoreMLRecipeProvider())
3137

3238
def tearDown(self) -> None:
3339
super().tearDown()
3440

41+
@unittest.skipIf(sys.platform == "win32", "Core ML is not available on Windows.")
3542
def test_ios_fp32_recipe_with_xnnpack_fallback(self) -> None:
3643
# Linear ops skipped by coreml but handled by xnnpack
3744
class Model(torch.nn.Module):
@@ -107,6 +114,7 @@ def forward(self, x, y):
107114
et_output = session.run_method("forward", example_inputs[0])
108115
logging.info(f"et output {et_output}")
109116

117+
@unittest.skipIf(sys.platform == "win32", "Core ML is not available on Windows.")
110118
def test_ios_quant_recipes(self) -> None:
111119
class Model(torch.nn.Module):
112120
def __init__(self):

extension/evalue_util/test/print_evalue_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ TEST(PrintEvalueTest, UnelidedBoolLists) {
267267
// case; the other scalar types use the same underlying code, so they don't
268268
// need to test this again.
269269
{
270-
EValue value(ArrayRef<bool>(list.data(), 0ul));
270+
EValue value(ArrayRef<bool>(list.data(), static_cast<size_t>(0ul)));
271271
expect_output(value, "(len=0)[]");
272272
}
273273
{
@@ -419,7 +419,7 @@ TEST(PrintEvalueTest, UnelidedDoubleLists) {
419419
std::array<double, 6> list = {-2.2, -1, 0, INFINITY, NAN, 3.3};
420420

421421
{
422-
EValue value(ArrayRef<double>(list.data(), 0ul));
422+
EValue value(ArrayRef<double>(list.data(), static_cast<size_t>(0ul)));
423423
expect_output(value, "(len=0)[]");
424424
}
425425
{

extension/flat_tensor/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ add_custom_command(
2323
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2424
COMMAND
2525
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
26-
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
26+
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}"
2727
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2828
)
2929

extension/module/test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ add_custom_command(
2424
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.pte"
2525
"${CMAKE_CURRENT_BINARY_DIR}/ModuleAddMulProgram.ptd"
2626
COMMAND ${PYTHON_EXECUTABLE} -m test.models.export_program --modules
27-
"ModuleAdd" --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
27+
"ModuleAdd" --outdir "${CMAKE_CURRENT_BINARY_DIR}"
2828
COMMAND
2929
${PYTHON_EXECUTABLE} -m test.models.export_program --modules "ModuleAddMul"
30-
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
30+
--external-constants --outdir "${CMAKE_CURRENT_BINARY_DIR}"
3131
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
3232
)
3333

extension/runner_util/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include(${EXECUTORCH_ROOT}/tools/cmake/Test.cmake)
2020
add_custom_command(
2121
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/ModuleAdd.pte"
2222
COMMAND ${PYTHON_EXECUTABLE} -m test.models.export_program --modules
23-
"ModuleAdd" --outdir "${CMAKE_CURRENT_BINARY_DIR}" 2> /dev/null
23+
"ModuleAdd" --outdir "${CMAKE_CURRENT_BINARY_DIR}"
2424
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
2525
)
2626

extension/testing_util/temp_file.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
#pragma once
1010

1111
#include <array>
12+
#include <fstream>
1213
#include <memory>
1314
#include <string>
1415

1516
#include <fcntl.h> // open()
16-
#include <stdio.h> // tmpnam(), remove()
17-
#include <unistd.h> // write(), close()
18-
1917
#include <gtest/gtest.h>
2018

2119
namespace executorch {
@@ -72,19 +70,13 @@ class TempFile {
7270
}
7371

7472
// Write the contents to the file.
75-
int fd = open(
76-
path.c_str(),
77-
// O_EXCL ensures that we are the ones creating this file, to help
78-
// protect against race conditions.
79-
O_CREAT | O_EXCL | O_RDWR,
80-
// User can read and write, group can read.
81-
S_IRUSR | S_IWUSR | S_IRGRP);
82-
ASSERT_GE(fd, 0) << "open(" << path << ") failed: " << strerror(errno);
83-
84-
ssize_t nwrite = write(fd, data, size);
85-
ASSERT_EQ(nwrite, size) << "Failed to write " << size << " bytes (wrote "
86-
<< nwrite << "): " << strerror(errno);
87-
close(fd);
73+
std::ofstream file(path, std::ios::out | std::ios::binary);
74+
ASSERT_TRUE(file.is_open())
75+
<< "open(" << path << ") failed: " << strerror(errno);
76+
77+
file.write((const char*)data, size);
78+
ASSERT_TRUE(file.good())
79+
<< "Failed to write " << size << " bytes: " << strerror(errno);
8880

8981
*out_path = path;
9082
}

kernels/portable/cpu/op_argmax.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ Tensor& argmax_out(
4949
static constexpr const char op_name[] = "argmax.out";
5050

5151
ET_SWITCH_REALHBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&] {
52-
long* out_data = out.mutable_data_ptr<long>();
52+
int64_t* out_data = out.mutable_data_ptr<int64_t>();
5353

5454
const bool success = parallel_for_each_reduce_over_dim_output_index(
5555
in, dim, out, [&](const auto begin, const auto end) {
5656
for (const auto out_ix : c10::irange(begin, end)) {
57-
std::tuple<CTYPE, long> acc = reduce_over_dim<CTYPE>(
58-
[](CTYPE v, long ix, CTYPE acc_val, long acc_ix) {
57+
std::tuple<CTYPE, int64_t> acc = reduce_over_dim<CTYPE>(
58+
[](CTYPE v, int64_t ix, CTYPE acc_val, int64_t acc_ix) {
5959
// the below condition as written is equivalent to
6060
// !isnan(accval) && (isnan(v) || v > acc_val). See
6161
// argument in op_argmin.cpp.
6262
if (!utils::isnan_override(acc_val) && !(v <= acc_val)) {
6363
acc_val = v;
6464
acc_ix = ix;
6565
}
66-
return std::tuple<CTYPE, long>{acc_val, acc_ix};
66+
return std::tuple<CTYPE, int64_t>{acc_val, acc_ix};
6767
},
6868
in,
6969
dim,

0 commit comments

Comments
 (0)