zeam-vm / pelemay

Pelemay is a native compiler for Elixir, which generates SIMD instructions. It has a plan to generate for GPU code.
Apache License 2.0
186 stars 13 forks source link

Error when M1 Mac with Rosetta 2 mode #154

Open zacky1972 opened 3 years ago

zacky1972 commented 3 years ago

Describe the bug An error occurs when M1 Mac with Rosetta 2 mode.

To Reproduce Steps to reproduce the behavior:

  1. Use Pelemay in pelemay_sample
  2. Run in the command mix compile
  3. See error:
% mix compile
Compiling 1 file (.ex)

14:56:16.601 [error] /usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/libnifelixirpelemaysample.c -o ../obj/libnifelixirpelemaysample.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel.c -o ../obj/map_elem1_mult_2_kernel.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_driver.c -o ../obj/map_elem1_mult_2_kernel_driver.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_bench.c -o ../obj/map_elem1_mult_2_kernel_bench.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_base.c -o ../obj/map_elem1_mult_2_kernel_base.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_driver_base.c -o ../obj/map_elem1_mult_2_kernel_driver_base.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_bench.c -o ../obj/map_elem1_mult_2_kernel_bench.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_driver.c -o ../obj/map_elem1_mult_2_kernel_driver.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_base.c -o ../obj/map_elem1_mult_2_kernel_base.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel_driver_base.c -o ../obj/map_elem1_mult_2_kernel_driver_base.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_mult_2_kernel.c -o ../obj/map_elem1_mult_2_kernel.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -c /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/libnifelixirpelemaysample.c -o ../obj/libnifelixirpelemaysample.o  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_bench.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_bench.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_base.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_base.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
/usr/bin/clang -S /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/src/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver_base.c -o ../obj/map_elem1_plus_1_mult_22_mult_elem1_mod_6700417_kernel_driver_base.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23. (truncated)

== Compilation error in file lib/pelemay_sample.ex ==
** (RuntimeError) Build failed.
    lib/pelemay/generator/builder.ex:369: Pelemay.Generator.Builder.generate/1
    expanding macro: Pelemay.defpelemay/1
    lib/pelemay_sample.ex:21: PelemaySample (module)

Expected behavior No error occurs and benchmarks will start.

Screenshots None.

Desktop (please complete the following information):

Running CpuInfo.all_profile:

iex(1)> CpuInfo.all_profile
%{
  compiler: %{
    apple_clang: [
      %{
        bin: "/usr/bin/clang",
        type: :apple_clang,
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    "apple_clang++": [
      %{
        bin: "/usr/bin/clang++",
        type: :"apple_clang++",
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    cc_env: [],
    cflags_env: "",
    clang: [
      %{
        bin: "/usr/bin/clang",
        type: :apple_clang,
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    "clang++": [
      %{
        bin: "/usr/bin/clang++",
        type: :"apple_clang++",
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    cxx_env: [],
    cxxflags_env: "",
    "g++": [
      %{ 
        bin: "/usr/bin/g++",
        type: :"apple_clang++",
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    gcc: [
      %{
        bin: "/usr/bin/gcc",
        type: :apple_clang, 
        version: "12.0.0",
        versions: "Apple clang version 12.0.0 (clang-1200.0.32.27)"
      }
    ],
    ldflags_env: ""
  },
  cpu: %{
    cpu_model: "Unknown",
    cpu_models: ["Unknown"],
    cpu_type: "x86_64",
    hyper_threading: :disabled,
    num_of_cores_of_a_processor: 8,
    num_of_ecores: 0,
    num_of_pcores: 0,
    num_of_processors: 1,
    num_of_threads_of_a_processor: 8,
    os_type: :macos,
    total_num_of_cores: 8,
    total_num_of_threads: 8
  },
  cuda: %{cuda: false},
  elixir: %{version: "1.11.2"},
  erlang: %{otp_version: 23},
  kernel: %{
    kernel_release: "20.1.0",
    kernel_version: "Darwin 20.1.0",
    system_version: "macOS 11.0.1 (20B29)"
  },
  metal: %{metal: true}
}

Additional context Add any other context about the problem here.

zacky1972 commented 3 years ago

make -f _build/dev/lib/pelemay/build/libnifelixirpelemaysample.mk:

% make -f _build/dev/lib/pelemay/build/libnifelixirpelemaysample.mk      
/usr/bin/clang -S  -o ../obj/libnifelixirpelemaysample.s  -Ofast -g -ansi -pedantic -I/Users/zacky/github/pelemay_sample/deps/pelemay/lib/pelemay/generator/native -I/usr/local/Cellar/erlang/23.1.4/lib/erlang/erts-11.1.3/include -std=c11 -Wno-unused-function -fPIC -I`xcrun --show-sdk-path 2>/dev/null`/usr/include
clang: error: no input files
make: *** [../obj/libnifelixirpelemaysample.o] Error 1

I guess it will be compiled correctly if call CC as xrun clang instead of /usr/bin/clang.