Skip to content

ARROW-9688: [C++][Python] Enable building c++ library and pyarrow package for win/arm64 build - #11383

Closed
niyas-sait wants to merge 6 commits into
apache:masterfrom
niyas-sait:enable_win_arm64
Closed

niyas-sait wants to merge 6 commits into
apache:masterfrom
niyas-sait:enable_win_arm64

Conversation

@niyas-sait

Copy link
Copy Markdown
Contributor

The patch will enable building arrow c++ library and pyarrow package for windows/arm64 targets using clang-cl and ninja toolchain.

The patch contains steps to build c++ library for basic configuration. Library with Python can be built similar to other platforms.

MSVC cannot be yet used for win/arm64 build as some of the templates from xsimd and boost are not properly handled by MSVC.

PyArrow can be built with Ninja and clang-cl by setting the following environment variables

set PYARROW_CMAKE_GENERATOR="Ninja"
set PYARROW_CMAKE_OPTIONS="-DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl"

PyArrow tests are all passing

=============================================================================== test session starts ===============================================================================
platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: C:\users\niysai01\workspace\arrow\python, configfile: setup.cfg
plugins: hypothesis-6.23.2, lazy-fixture-0.6.3
collected 4106 items / 3 skipped / 4103 selected                                                                                                                                   

pyarrow\tests\test_adhoc_memory_leak.py s                                                                                                                                    [  0%]
pyarrow\tests\test_array.py ......................s...............................................................................................s......................... [  3%]
....................................................ss...........                                                                                                            [  5%]
pyarrow\tests\test_builder.py ....                                                                                                                                           [  5%]
pyarrow\tests\test_cffi.py ..........                                                                                                                                        [  5%]
pyarrow\tests\test_compute.py .............................................................................................................................................. [  8%]
...................................sss....................                                                                                                                   [ 10%]
pyarrow\tests\test_convert_builtin.py ...................................................................................................................................... [ 13%]
.............................................................................x......................................................................................x....... [ 17%]
................ssssss........................................................................................................sssssssss                                      [ 21%]
pyarrow\tests\test_csv.py ......................................................................................................sss.......                                   [ 23%]
pyarrow\tests\test_cython.py ..                                                                                                                                              [ 23%]
pyarrow\tests\test_dataset.py ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 27%]
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 31%]
sssssssssssssssssssssssss                                                                                                                                                    [ 32%]
pyarrow\tests\test_extension_type.py ..............................sssss..                                                                                                   [ 33%]
pyarrow\tests\test_feather.py ............s...............ss..............s...............ss...x.....ss.s...ssss                                                             [ 34%]
pyarrow\tests\test_filesystem.py ....                                                                                                                                        [ 35%]
pyarrow\tests\test_flight.py ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss                                                                                  [ 36%]
pyarrow\tests\test_fs.py s.......ssx.xsss...ssx.xsss....ss...sss...ss...sss...ss...sss...ss...sss...ss...sss...ss...sss...ss...sss....ss...sss...ss...sss...ss...sss...ss... [ 40%]
sssssssssssssssssssssssssssssssssssssssssssssss...ss...sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss...ss...sss....sss........ [ 44%]
.......s...........sss.                                                                                                                                                      [ 44%]
pyarrow\tests\test_gandiva.py sssssssssss                                                                                                                                    [ 45%]
pyarrow\tests\test_hdfs.py ssssssssssssssssssssssss                                                                                                                          [ 45%]
pyarrow\tests\test_io.py ........s..........................ssssssssssss..........s...s..............sssssss.....sssssssssss..........s..s.sss....s.s.s.                     [ 48%]
pyarrow\tests\test_ipc.py ...............s..............s....................                                                                                                [ 50%]
pyarrow\tests\test_json.py ..........................                                                                                                                        [ 50%]
pyarrow\tests\test_memory.py ........                                                                                                                                        [ 50%]
pyarrow\tests\test_misc.py ................................................................................................                                                  [ 53%]
pyarrow\tests\test_orc.py sssss                                                                                                                                              [ 53%]
pyarrow\tests\test_pandas.py .............................................................s............................sss.................................................. [ 56%]
...s.........s............................................................s...................................................................s..............                [ 60%]
pyarrow\tests\test_plasma.py sssssssssssssssssssssssssssssssss                                                                                                               [ 61%]
pyarrow\tests\test_plasma_tf_op.py s                                                                                                                                         [ 61%]
pyarrow\tests\test_scalars.py ..............................................s...s....................                                                                        [ 63%]
pyarrow\tests\test_schema.py ................................                                                                                                                [ 64%]
pyarrow\tests\test_serialization.py ........s..ss........................................................................................................................... [ 67%]
.........................................................ss................................................................................................................. [ 71%]
...............................................................s............................................................................................................ [ 75%]
....................................................................s....................................................................................................... [ 79%]
............................................................................s..............                                                                                  [ 82%]
pyarrow\tests\test_serialization_deprecated.py ..                                                                                                                            [ 82%]
pyarrow\tests\test_sparse_tensor.py ....................................................................................................................................ssss [ 85%]
sssssssssssssssssssssssssssss                                                                                                                                                [ 86%]
pyarrow\tests\test_strategies.py ssssssss                                                                                                                                    [ 86%]
pyarrow\tests\test_table.py ....................s.........................................................................                                                   [ 88%]
pyarrow\tests\test_tensor.py ..............s......                                                                                                                           [ 89%]
pyarrow\tests\test_types.py .....................s............................................................ss                                                             [ 91%]
pyarrow\tests\test_util.py s                                                                                                                                                 [ 91%]
pyarrow\tests\parquet\test_basic.py ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss                                                 [ 93%]
pyarrow\tests\parquet\test_compliant_nested_type.py ssssssss                                                                                                                 [ 93%]
pyarrow\tests\parquet\test_data_types.py ssssssssssssssssssssssssssssssssssssssssss                                                                                          [ 94%]
pyarrow\tests\parquet\test_dataset.py ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss                                     [ 97%]
pyarrow\tests\parquet\test_datetime.py ssssssssssssssssss                                                                                                                    [ 97%]
pyarrow\tests\parquet\test_metadata.py ssssssssssssssssssssssssss                                                                                                            [ 98%]
pyarrow\tests\parquet\test_pandas.py ssssssssssssssssssssssssssssssssssssssssssssssss                                                                                        [ 99%]
pyarrow\tests\parquet\test_parquet_file.py ssssssssssssss                                                                                                                    [ 99%]
pyarrow\tests\parquet\test_parquet_writer.py ssssssssssssssss                                                                                                                [100%]

=========================================================== 2899 passed, 1203 skipped, 7 xfailed, 40 warnings in 56.11s ===========================================================

@github-actions

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

@cyb70289 cyb70289 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nsait-linaro for enabling arrow on windows/arm64.
Just out of curiosity, is there free resources (e.g., cloud based) to try windows on arm?

Comment thread docs/source/developers/cpp/windows.rst Resolved
Comment thread cpp/src/arrow/util/bit_util.h Resolved
Comment thread docs/source/developers/cpp/windows.rst Resolved
@niyas-sait

Copy link
Copy Markdown
Contributor Author

Thanks @nsait-linaro for enabling arrow on windows/arm64. Just out of curiosity, is there free resources (e.g., cloud based) to try windows on arm?

I don't think one is available yet. We can still cross-compile for ARM64 from an x64 machine. I will try to put together a CI for build at least until the VMs for ARM64 is up and running in azure.

@kou kou changed the title ARROW-9688: Enable building c++ library and pyarrow package for win/arm64 build ARROW-9688: [C++][Python] Enable building c++ library and pyarrow package for win/arm64 build Oct 12, 2021
@niyas-sait

Copy link
Copy Markdown
Contributor Author

Failing CI flow seems to be due to missing LLVM. It doesn't look related to this patch. Is this a known issue?

-- Could NOT find LLVM (missing: LLVM_DIR)
CMake Error at /usr/local/Cellar/cmake/3.21.3_1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find LLVMAlt (missing: LLVM_PACKAGE_VERSION CLANG_EXECUTABLE
  LLVM_FOUND LLVM_LINK_EXECUTABLE)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.21.3_1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  cmake_modules/FindLLVMAlt.cmake:68 (find_package_handle_standard_args)
  src/gandiva/CMakeLists.txt:28 (find_package)


@cyb70289

cyb70289 commented Oct 12, 2021 •

Copy link
Copy Markdown
Contributor

Failing CI flow seems to be due to missing LLVM. It doesn't look related to this patch. Is this a known issue?

It's known issue. Not related to this PR.

Comment thread docs/source/developers/cpp/windows.rst Resolved
Comment on lines 906 to 913

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have details why this change? And your original PR works without this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, clang for windows on arm64 has some bugs around int128_t type. The issue is very similar to the linker issue highlighted in line 900.

if(ARROW_USE_UBSAN)
  # NOTE: Avoid native int128_t on clang with UBSan as it produces linker errors
  # (such as "undefined reference to '__muloti4'")
  set(ARROW_USE_NATIVE_INT128 FALSE)
else()

For example even simple programs like following would throw an error

int main(){
    __int128_t x, y;
    // int128_t div
    auto r = x / y;
    // cast int128_t to float
    float mean = static_cast<float>(x);
    return 0;
}

Linker error raised

lld-link: error: undefined symbol: __divti3
>>> referenced by C:\Users\niysai01\AppData\Local\Temp\test-ed00b3.o:(main)

lld-link: error: undefined symbol: __floattisf
>>> referenced by C:\Users\niysai01\AppData\Local\Temp\test-ed00b3.o:(main)

I am waiting for an LLVM account to file a bug report.

I had this change initially but then reverted it thinking that it wasn't necessary and since I wasn't doing a clean build this didn't show up as an issue after reverting. I have tried on a clean checkout yesterday and can confirm that this change is required.

@cyb70289 cyb70289 Oct 20, 2021 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried llvm-13 [1] and found this bug is fixed. Will you test it?

[1] https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/LLVM-13.0.0-woa64.zip

EDIT: Looks not fixed. There are still similar errors somewhere else. Sorry for the noise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I just tried and gives the same error. Thanks for confirming.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record. Below command does gives me a successful build of your test code.
clang-cl /clang:"--rtlib=compiler-rt" test.c

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work on x64 windows?

Just an educated guess: from the looks of it, and @cyb70289 's comment, it looks like an incompatibility between clang-cl and MSVC's runtime libraries -- clang-cl generates calls to __*ti3() functions expecting them in the runtime libs. Compiler-rt does provide them, but MSVC's libraries do not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested. Same issue happens on x64 windows. @maxim-kuvyrkov

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clang targeting windows-msvc expects to link against the VC++ runtime. But VC++ doesnt support __int128 intrinsic which explain why using --rtlib=compiler-rt compiles the code fine.
See link below for reference:
https://docs.microsoft.com/en-us/cpp/cpp/fundamental-types-cpp?view=msvc-160#integer-types

This appears to be a known issue in community but I could not find a bug report against it. Please refer to following upstream discussions:
https://reviews.llvm.org/D91139#2429595
https://reviews.llvm.org/D91413

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, clang for windows on arm64 has some bugs around int128_t type. The issue is very similar to the linker issue highlighted in line 900.

if(ARROW_USE_UBSAN)
  # NOTE: Avoid native int128_t on clang with UBSan as it produces linker errors
  # (such as "undefined reference to '__muloti4'")
  set(ARROW_USE_NATIVE_INT128 FALSE)
else()

For example even simple programs like following would throw an error

int main(){
    __int128_t x, y;
    // int128_t div
    auto r = x / y;
    // cast int128_t to float
    float mean = static_cast<float>(x);
    return 0;
}

Linker error raised

lld-link: error: undefined symbol: __divti3
>>> referenced by C:\Users\niysai01\AppData\Local\Temp\test-ed00b3.o:(main)

lld-link: error: undefined symbol: __floattisf
>>> referenced by C:\Users\niysai01\AppData\Local\Temp\test-ed00b3.o:(main)

I am waiting for an LLVM account to file a bug report.

I had this change initially but then reverted it thinking that it wasn't necessary and since I wasn't doing a clean build this didn't show up as an issue after reverting. I have tried on a clean checkout yesterday and can confirm that this change is required.

This looks more like a feature request where we want Clang to enable VC++ missing intrinsic like __int128 from compiler-rt when building for MSVC

Comment thread docs/source/developers/cpp/windows.rst Resolved
@niyas-sait
niyas-sait requested a review from cyb70289 October 20, 2021 07:10
@cyb70289

Copy link
Copy Markdown
Contributor

@nsait-linaro , I installed windows on arm in apple m1 box. Tried your patch and it looks great. Except c++ unit test build failed. I have pushed a pr to fix the build errors #11495, will rebase when that pr is merged.

@niyas-sait

Copy link
Copy Markdown
Contributor Author

@nsait-linaro , I installed windows on arm in apple m1 box. Tried your patch and it looks great. Except c++ unit test build failed. I have pushed a pr to fix the build errors #11495, will rebase when that pr is merged.

Thanks , sounds good

Comment thread docs/source/developers/cpp/windows.rst Resolved

@cyb70289 cyb70289 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, thanks @nsait-linaro !

@cyb70289

cyb70289 commented Oct 28, 2021 •

Copy link
Copy Markdown
Contributor

R4.1 job failed (looks timed out). Maybe a spurious error? @nealrichardson

[UPDATE] No worry, I rerun the test, it's passing now.

@cyb70289 cyb70289 closed this in 0f3e36e Oct 28, 2021
@ursabot

ursabot commented Oct 28, 2021 •

Copy link
Copy Markdown

Benchmark runs are scheduled for baseline = 61a2212 and contender = 0f3e36e. 0f3e36e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.0% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.8% ⬆️0.13%] ursa-thinkcentre-m75q
Supported benchmarks:
ursa-i9-9960x: langs = Python, R, JavaScript
ursa-thinkcentre-m75q: langs = C++, Java
ec2-t3-xlarge-us-east-2: cloud = True

@nealrichardson

Copy link
Copy Markdown
Member

R4.1 job failed (looks timed out). Maybe a spurious error? @nealrichardson

[UPDATE] No worry, I rerun the test, it's passing now.

👍 For the future, if you see any of the R jobs hanging/timing out, please note it on https://issues.apache.org/jira/browse/ARROW-14159 with any useful details. We tried to eliminate the sources of the hanging but it looks like we haven't found them all yet.

@niyas-sait

Copy link
Copy Markdown
Contributor Author

Thanks, everyone for your help to get it merged.

As the changes are merged now, It would be good to look at CI options for win/arm64 build.

We have a few machines available in Linaro WoA64 farm which we could allocate for testing Arrow. What would be a good channel to kick start this discussion?

@cyb70289

cyb70289 commented Nov 1, 2021

Copy link
Copy Markdown
Contributor

Arrow dev mail list is the best place to talk about it.
https://arrow.apache.org/community/
[email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants