Git Product home page Git Product logo

pelemay's People

Contributors

christianjgreen avatar connorrigby avatar fhunleth avatar hisaway avatar kentaro avatar mobileoverlord avatar muramasa8191 avatar supersimple avatar zacky1972 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pelemay's Issues

Add basic functional testing of Pelemay

Describe the bug
There isn't any functional testing of Pelemay.

To Reproduce
omitted

Expected behavior
Basic functional testing brings future automatic CI.

Screenshots
omitted

Desktop (please complete the following information):
It is required for all environments.

Additional context
None.

Support to convert Range into List

Is your feature request related to a problem? Please describe.

Currently, we need to write "Enum.to_list" like this:

  defpelemay do
    def func list do
      list |> Enum.map(& &1 * 2)
    end
  end

  def do_test do
    1..1000
    |> Enum.to_list
    |> func
  end

Describe the solution you'd like

I'd like to write it without Enum.to_list like this:

  defpelemay do
    def func list do
      list |> Enum.map(& &1 * 2)
    end
  end

  def do_test do
    1..1000
    |> func
  end

Describe alternatives you've considered
None.

Additional context
It brings more efficiency because to reduce Enum.to_list is so effective to efficiency.

Degrading occurs: basic functional testing is NOT passed

Describe the bug
Basic functional testing is NOT passed.

To Reproduce
Steps to reproduce the behavior:

  1. Checkout the master branch.
  2. Describe the following code in the lib directory:
defmodule Test do
  require Pelemay
  import Pelemay

  defpelemay do
      def map_square list do
        list |> Enum.map(& &1 * &1)
      end
  end

  def do_test do
      list = 1..4 |> Enum.to_list |> map_square
      [1, 4, 9, 16] = list
  end
end
  1. Run mix compile

  2. Do iex -S mix and Test.do_test

  3. See error:

$ mix compile
Compiling 1 file (.ex)

21:18:13.452 [warn]  The on_load function for module Elixir.PelemayNif returned:
{:error, {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/zacky/github/pelemay/_build/dev/lib/pelemay/priv/libnif.so, 2): image not found\''}}

warning: PelemayNifElixirTest.map_mult/1 is undefined (module PelemayNifElixirTest is not available or is yet to be defined)
  lib/test.ex:5: Test.map_square/1

Generated pelemay app
make: Nothing to be done for `all'.
$ iex -S mix
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

make: Nothing to be done for `all'.
Interactive Elixir (1.10.0-dev) - press Ctrl+C to exit (type h() ENTER for help) 
iex(1)> Test.do_test
** (UndefinedFunctionError) function PelemayNifElixirTest.map_mult/1 is undefined (module PelemayNifElixirTest is not available)
    PelemayNifElixirTest.map_mult(1..4)
    (pelemay 0.0.1) lib/test.ex:12: Test.do_test/0
iex(1)> 

Expected behavior
Compiling is done successfully, there are no error by mix compile, and the following output occurs by iex -S mix and Test do_test:


Screenshots
None.

Desktop (please complete the following information):

  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.10.0-dev (587453b) (compiled with Erlang/OTP 22)
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS: macOS Mojave 10.14.6
$ uname -a
Darwin SachiAir.local 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Version: master

Additional context

I guess it is caused by some degrading.

Support elem function

Is your feature request related to a problem? Please describe.

In conv2d: https://github.com/zeam-vm/conv2d

To enhance to use Pelemay:

git diff:

diff --git a/lib/conv2d.ex b/lib/conv2d.ex
index c6dd785..aeb15da 100644
--- a/lib/conv2d.ex
+++ b/lib/conv2d.ex
@@ -1,4 +1,7 @@
 defmodule Conv2d do
+  require Pelemay
+  import Pelemay
+
   @moduledoc """
   Documentation for Conv2d.
   """
@@ -93,7 +96,7 @@ defmodule Conv2d do
     t_input = input |> dup(m) |> t1
     t_weight = weight |> t1
 
-    mult = Enum.zip(t_input, t_weight) |> Enum.map(& elem(&1, 0) * elem(&1, 1))
+    mult = Enum.zip(t_input, t_weight) |> map_mult()
 
     mult
     |> Enum.chunk_every(x * y)
@@ -105,6 +108,12 @@ defmodule Conv2d do
     |> List.flatten
   end
 
+  defpelemay do
+    def map_mult list do
+      list |> Enum.map(& elem(&1, 0) * elem(&1, 1))      
+    end
+  end
+
   @doc """
 
   ## Examples
diff --git a/mix.exs b/mix.exs
index aa86e28..af448e2 100644
--- a/mix.exs
+++ b/mix.exs
@@ -4,8 +4,8 @@ defmodule Conv2d.MixProject do
   def project do
     [
       app: :conv2d,
-      version: "0.0.1",
-      elixir: "~> 1.7",
+      version: "0.0.2",
+      elixir: "~> 1.9",
       start_permanent: Mix.env() == :prod,
       deps: deps()
     ]
@@ -21,6 +21,8 @@ defmodule Conv2d.MixProject do
   # Run "mix help deps" to learn about dependencies.
   defp deps do
     [
+      {:pelemay, "~> 0.0.2"},
+      {:benchfella, "~> 0.3.0", only: :dev},
       # {:dep_from_hexpm, "~> 0.3.0"},
       # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
     ]

The following error occurs:

$ mix compile
Compiling 1 file (.ex)

== Compilation error in file lib/conv2d.ex ==
** (ArgumentError) cannot pipe list into elem(&1, 0) * elem(&1, 1), the :* operator can only take two arguments
    (elixir) lib/macro.ex:155: Macro.pipe/3
    (stdlib) lists.erl:1263: :lists.foldl/3
    (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
    lib/sum_mag.ex:261: SumMag.optimize_func/2
    (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
    lib/sum_mag.ex:253: SumMag.map/2
    expanding macro: Pelemay.defpelemay/1
    lib/conv2d.ex:111: Conv2d (module)

Describe the solution you'd like
Support elem function in defpelemay.

Describe alternatives you've considered
No idea.

Additional context
None.

After fix #73: CC=gcc-7 doesn't work

バグの説明
#73 でchristianjgreenが作成したパッチをlinuxOS(ubuntu)とgccで動作するか確認した結果です
gcc-9では動作し、gcc-7では動作しませんでした

再現方法
下記の情報を記載してください.

  1. �Pelemayを適用したソースコード
    README.mdにあるサンプルコード
  2. 実行したコマンド
CC=gcc-7 mix compile
  1. 発生したエラー
Compiling 11 files (.ex)
"gcc-7"
"gcc-7"
/.../pelemay/_build/dev/lib/pelemay/priv/libnifelixirm.c:47:31: error: initializer element is not constant
 const size_t init_size_long = cache_line_size / sizeof(long);
                               ^~~~~~~~~~~~~~~
/.../pelemay/_build/dev/lib/pelemay/priv/libnifelixirm.c:48:33: error: initializer element is not constant
 const size_t init_size_double = cache_line_size / sizeof(double);
                                 ^~~~~~~~~~~~~~~
/.../pelemay/_build/dev/lib/pelemay/priv/libnifelixirm.c:49:35: error: initializer element is not constant
 const size_t size_t_highest_bit = ~(size_t_max >> 1);
                                   ^
                                   
== Compilation error in file lib/sample.ex ==
** (MatchError) no match of right hand side value: {"", 1}
    lib/pelemay/generator/builder.ex:53: Pelemay.Generator.Builder.generate/1
    lib/pelemay.ex:51: Pelemay.pelemaystub/2
    expanding macro: Pelemay.defpelemay/1
    lib/sample.ex:5: M (module)

期待している動作

スクリーンショット
バグの修正に役立ちそうな時はスクリーンショットを追加してください.

動作環境(必須)

  • Pelemay Version:0.0.4
  • Elixir & Erlang/OTP versions (elixir --version):OTP 22/Elixir 1.9.1
  • OS (OS name & version, and uname -a): Linux rigel 5.0.0-36-generic #39~18.04.1-Ubuntu SMP Tue Nov 12 11:09:50 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
  • gcc versions (gcc -v):gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

備考
christianjgreenがforkしたリポジトリをoriginにブランチを切っています。
ブランチ名:nerves_gcc

Testing Pelemay on various processor architectures

Current Pelemay is tested on x86_64 architectures (Intel and AMD), though is not tested well on other platforms including IA-32, ARM, MIPS and so on, which are supported by Erlang VM.

Unfortunately, we don't have enough PCs, embedded and IoT systems, which have such above-mentioned architectures...

Thus, I'll ask YOU to test Pelemay on various processor architectures.

Testing is easy:

  1. Set up your system.
  2. Install Erlang, Elixir and Clang
  3. mix new test.
  4. cd test.
  5. Edit deps in mix.exs:
def deps do
  [
    {:pelemay, "~> 0.0"},
  ]
end
  1. mix deps.get
  2. Write lib/test.ex:
defmodule Test do
  require Pelemay
  import Pelemay

  defpelemay do
    def enum_square list do
       list |> Enum.map(& &1 * &1)
    end
  end

  @doc """
    ## Examples
    iex> Test.do_test()
    [1, 4, 9, 16]
  """
  def do_test do
    1..4 |> Enum.to_list |> enum_square()
  end
end
  1. Modify test/test_test.exs into:
defmodule TestTest do
  use ExUnit.Case, async: true
  doctest Test
end
  1. mix test
  2. Write a bug report in the manner of our issue templates, if you got some errors.
    Please describe information on your platform in details.
  3. Report your platform on which the testing succeed on this issue.

Support GCC (it focus on switching compiler and compiling options)

Is your feature request related to a problem? Please describe.

Nerves and Atom VM uses GCC, not Clang.
I found current GCC supports auto vectorization.
Thus, I guess Pelemay should use not only Clang but also GCC.
Freedom of Pelemay requires so.

Describe the solution you'd like
CC environment variable may be set to suitable compiler.
Thus, If CC is set, Pelemay uses the compiler that CC selected.

If it gets an error, try Clang and GCC in this order.

If all of them gets an error, compute it as an Elixir program.

Describe alternatives you've considered
None.

Additional context

This is a part of #73

Description of the top of the API Reference is incomplete

Describe the bug
Description in README.md includes sample code, though that of the top of the API Reference in HexDocs ( https://hexdocs.pm/pelemay/0.0.3/api-reference.html ) don't so.

To Reproduce
None.

Expected behavior
Description of the top of the API Reference should include sample code.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.3

Additional context
It is necessary to ask details of the specification of ExDoc and HexDocs to someone who understand it enough to explain it to us.

error: dynamic_lookup: No such file or directory in the case of Nerves

Describe the bug
Reported by @TORIFUKUKaiou

An error: dynamic_lookup: No such file or directory occurs in the case of Nerves.

A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. mix nerves.new hello_pelemay
  2. modify it according to pelemay_sample ( TORIFUKUKaiou/hello_pelemay@4648d03 )
  3. export MIX_TARGET=rpi2
    4, export NERVES_NETWORK_SSID="ssid..."
  4. export NERVES_NETWORK_PSK="psk..."
  5. mix deps.get
  6. mix firmware

generates the following error:

$ mix firmware

Nerves environment
  MIX_TARGET:   rpi2
  MIX_ENV:      dev

==> nerves_system_br
Generated nerves_system_br app
==> socket
Compiling 11 files (.ex)
Generated socket app
==> uboot_env
Compiling 7 files (.ex)
Generated uboot_env app
==> nerves_toolchain_ctng
Compiling 1 file (.ex)
Generated nerves_toolchain_ctng app
==> ring_logger
Compiling 4 files (.ex)
Generated ring_logger app
==> nerves_system_linter
Compiling 14 files (.ex)
Generated nerves_system_linter app
==> dns
Compiling 7 files (.ex)
Generated dns app
==> mdns
Compiling 5 files (.ex)
Generated mdns app
==> gen_stage
Compiling 10 files (.ex)
Generated gen_stage app
==> nerves_toolchain_arm_unknown_linux_gnueabihf
Generated nerves_toolchain_arm_unknown_linux_gnueabihf app
==> system_registry
Compiling 13 files (.ex)
Generated system_registry app
==> shoehorn
Compiling 8 files (.ex)
Generated shoehorn app
==> benchfella
Compiling 9 files (.ex)
warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
  lib/benchfella.ex:506

warning: Kernel.ParallelRequire.files/1 is deprecated. Use Kernel.ParallelCompiler.require/2 instead
  lib/mix/tasks/bench.ex:109

Generated benchfella app
==> elixir_make
Compiling 1 file (.ex)
Generated elixir_make app
==> nerves_runtime
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/priv
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=gnu99 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/nerves_runtime.o src/nerves_runtime.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=gnu99 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/uevent.o src/uevent.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=gnu99 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/kmsg_tailer.o src/kmsg_tailer.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/nerves_runtime.o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/uevent.o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/obj/kmsg_tailer.o -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/lib -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/lib -lerts -lerl_interface -lei --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging -lmnl -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_runtime/priv/nerves_runtime
Compiling 13 files (.ex)
Generated nerves_runtime app
==> toolshed
Compiling 9 files (.ex)
Generated toolshed app
==> nerves_firmware_ssh
Compiling 9 files (.ex)
Generated nerves_firmware_ssh app
==> one_dhcpd
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/one_dhcpd/priv
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/one_dhcpd/obj
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/one_dhcpd/obj/arp_set.o src/arp_set.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/one_dhcpd/priv/arp_set --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/one_dhcpd/obj/arp_set.o
Compiling 9 files (.ex)
Generated one_dhcpd app
==> muontrap
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C src all
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/muontrap/priv
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/muontrap/obj
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=c99 -D_GNU_SOURCE -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/muontrap/obj/muontrap.o muontrap.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/muontrap/obj/muontrap.o --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging  -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/muontrap/priv/muontrap
if [ -f test/Makefile ]; then /Applications/Xcode.app/Contents/Developer/usr/bin/make -C test; fi
Compiling 5 files (.ex)
Generated muontrap app
==> nerves_network_interface
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../priv
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../obj
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=c99 -D_XOPEN_SOURCE=600 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../obj/erlcmd.o src/erlcmd.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=c99 -D_XOPEN_SOURCE=600 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../obj/netif.o src/netif.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../obj/erlcmd.o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../obj/netif.o -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/lib -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/lib -lerts -lerl_interface -lei --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging -lmnl -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../priv/netif
# setuid root net_basic so that it can configure network interfaces
SUDO_ASKPASS= true -- sh -c 'chown root:root /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../priv/netif; chmod +s /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network_interface/ebin/../priv/netif'
Compiling 3 files (.ex)
Generated nerves_network_interface app
==> nerves_wpa_supplicant
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../priv
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ctrl
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ex.o src/wpa_ex.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ctrl/os_unix.o src/wpa_ctrl/os_unix.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -DCONFIG_CTRL_IFACE -DCONFIG_CTRL_IFACE_UNIX -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ctrl/wpa_ctrl.o src/wpa_ctrl/wpa_ctrl.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ex.o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ctrl/os_unix.o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../obj/wpa_ctrl/wpa_ctrl.o --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging -lrt -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../priv/wpa_ex
# setuid root wpa_ex so that it can interact with the wpa_supplicant
SUDO_ASKPASS= true -- sh -c 'chown root:root /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../priv/wpa_ex; chmod +s /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_wpa_supplicant/ebin/../priv/wpa_ex'
Compiling 3 files (.ex)
Generated nerves_wpa_supplicant app
==> flow
Compiling 10 files (.ex)
Generated flow app
==> nerves_network
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../obj
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../priv
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=c99 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../obj/udhcpc_wrapper.o src/udhcpc_wrapper.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../obj/udhcpc_wrapper.o -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/lib -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/lib -lerts -lerl_interface -lei --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging  -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../priv/udhcpc_wrapper
# setuid root udhcpc_wrapper so that it can call udhcpc
SUDO_ASKPASS= true -- sh -c 'chown root:root /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../priv/udhcpc_wrapper; chmod +s /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_network/ebin/../priv/udhcpc_wrapper'
Compiling 12 files (.ex)
Generated nerves_network app
==> nerves_system_rpi2
Generated nerves_system_rpi2 app
==> nerves_time
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_time/priv
mkdir -p /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_time/obj
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc -c -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/erts-10.5.6/include -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64  -pipe -Os -I/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/include -std=c99 -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_time/obj/ntpd_script.o src/ntpd_script.c
/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-darwin_x86_64-1.2.0/bin/arm-unknown-linux-gnueabihf-gcc /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_time/obj/ntpd_script.o -L/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging/usr/lib/erlang/lib/erl_interface-3.13/lib -lei_st --sysroot=/Users/yamauchi/.nerves/Users/yamauchi/nervesProjects/hello_pelemay/deps/nerves/artifacts/nerves_system_rpi2-portable-1.10.0/staging  -o /Users/yamauchi/nervesProjects/hello_pelemay/_build/rpi2_dev/lib/nerves_time/priv/ntpd_script
Compiling 5 files (.ex)
Generated nerves_time app
==> nerves_init_gadget
Compiling 5 files (.ex)
Generated nerves_init_gadget app
==> pelemay
Compiling 11 files (.ex)
Generated pelemay app
==> hello_pelemay
Compiling 3 files (.ex)
"map_elem_minus_2"
"map_x_plus_2"
"map_x_mult_2"
"map_elem_div_2"
"map_elem_mod_2"
"map_elem_mod_2_plus_1"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
"map_elem_plus_1_mult_22_mult_elem_mod_6700417"
arm-unknown-linux-gnueabihf-gcc: error: dynamic_lookup: No such file or directory

== Compilation error in file lib/pelemay_sample.ex ==
** (MatchError) no match of right hand side value: {"", 1}
    lib/pelemay/generator/builder.ex:53: Pelemay.Generator.Builder.generate/1
    lib/pelemay.ex:48: Pelemay.pelemaystub/2
    expanding macro: Pelemay.defpelemay/1
    lib/pelemay_sample.ex:21: PelemaySample (module)

Expected behavior

mix firmware will be done successfully.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: master (346cde1)
  • Elixir & Erlang/OTP versions (elixir --version): N/A
  • OS (OS name & version, and uname -a): Nerves
  • Clang versions (clang -v): N/A

Additional context
Add any other context about the problem here.

Compile error: /usr/include doesn't match in the case of Nerves cross compiled by macOS

Describe the bug

Compile errors occur because /usr/include doesn't match in the case of Nerves cross compiled by macOS.

To Reproduce
Steps to reproduce the behavior:

  1. mix nerves.new hello_pelemay
  2. modify according to (TORIFUKUKaiou/hello_pelemay@4648d03)
  3. Use Pelemay in mix.exs 'branch: nerves_gcc' (cfe5c44)
  4. export MIX_TARGET=rpi4 (or another platform)
  5. mix deps.get
  6. mix firmware

The following errors occurs:

In file included from /usr/include/sys/types.h:75,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_drv_nif.h:158,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_nif.h:31,
                 from /Users/zacky/hello_pelemay/_build/rpi4_dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
/usr/include/sys/cdefs.h:784:2: error: #error Unsupported architecture
 #error Unsupported architecture
  ^~~~~
In file included from /usr/include/sys/types.h:78,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_drv_nif.h:158,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_nif.h:31,
                 from /Users/zacky/hello_pelemay/_build/rpi4_dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
/usr/include/machine/types.h:37:2: error: #error architecture not supported
 #error architecture not supported
  ^~~~~
In file included from /usr/include/sys/_types.h:33,
                 from /usr/include/sys/types.h:79,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_drv_nif.h:158,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_nif.h:31,
                 from /Users/zacky/hello_pelemay/_build/rpi4_dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
/usr/include/machine/_types.h:34:2: error: #error architecture not supported
 #error architecture not supported
  ^~~~~
In file included from /usr/include/sys/types.h:79,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_drv_nif.h:158,
                 from /Users/zacky/kerl/22.1_clang_10.0.0_6c3f/erts-10.5/include/erl_nif.h:31,
                 from /Users/zacky/hello_pelemay/_build/rpi4_dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
/usr/include/sys/_types.h:55:9: error: unknown type name '__int64_t'
 typedef __int64_t       __darwin_blkcnt_t;      /* total blocks */
         ^~~~~~~~~
/usr/include/sys/_types.h:56:9: error: unknown type name '__int32_t'
 typedef __int32_t       __darwin_blksize_t;     /* preferred block size */
         ^~~~~~~~~
/usr/include/sys/_types.h:57:9: error: unknown type name '__int32_t'
 typedef __int32_t       __darwin_dev_t;         /* dev_t */
         ^~~~~~~~~
/usr/include/sys/_types.h:60:9: error: unknown type name '__uint32_t'
 typedef __uint32_t      __darwin_gid_t;         /* [???] process and group IDs */
         ^~~~~~~~~~
/usr/include/sys/_types.h:61:9: error: unknown type name '__uint32_t'
 typedef __uint32_t      __darwin_id_t;          /* [XSI] pid_t, uid_t, or gid_t*/
[snipped]

This is because of mismatch of /use/include

Expected behavior
No error occurs.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 'branch: nerves gcc' (cfe5c44)
  • Elixir & Erlang/OTP versions (elixir --version): 1.9.4 / 22
  • OS (OS name & version, and uname -a): macOS
  • Clang versions (clang -v): N/A

Additional context
None.

Put CPU_Info when error

Is your feature request related to a problem? Please describe.
Reporting CPU info is troublesome when an error occurred.

Describe the solution you'd like
Puts CPU info when an error occurred.

Describe alternatives you've considered
None

Additional context
None

Convert from a list to an array with comprehensive type checking and inference

Is your feature request related to a problem? Please describe.

Current type checking of Pelemay is not perfect.
It may cause "sudden death", that is, an uncaught segmentation fault or error due to type mismatch.

Describe the solution you'd like

When converting a list into an array In the beginning of a NIF, check type of arguments of the NIF and its elements thoroughly.
It is desirable to inference types and generate more efficient code.

Describe alternatives you've considered
None.

Additional context

This issue brings other issues to modify the meta-programming part.

Warning: Kernel.ParallelRequire.files/1 is deprecated.

When mix compile, the following warning occurs:

warning: Kernel.ParallelRequire.files/1 is deprecated. Use Kernel.ParallelCompiler.require/2 instead
  lib/mix/tasks/bench.ex:109

to run elixir -v:

$ elixir -v
Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:36:36] [ds:36:36:10] [async-threads:1] [hipe]

Elixir 1.9.0 (compiled with Erlang/OTP 22)

I guess this issue may due to Benchfella, but we should contribute it to report this issue.

Can't build

I'm getting:

make: *** No rule to make target 'native/lib.c', needed by '/home/olafura/dev/pelemay/_build/dev/lib/pelemay/priv/libnif.so'. Stop.
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. If you are using
Ubuntu or any other Debian-based system, install the packages
"build-essential". Also install "erlang-dev" package if not
included in your Erlang/OTP version. If you're on Fedora, run
"dnf group install 'Development Tools'".

mix test invoked error

I made a Pelery clone.
And I updated Elixir to 1.9.0.
I ran mix test. I got following results:
== Compilation error in file test/hastega/generator_test.exs ==
** (CompileError) test/hastega/generator_test.exs:3: module Hastega.Generator is not loaded and could not
be found

Supporting String functions

Is your feature request related to a problem? Please describe.

Currently Pelemay only supports four arithmetic operations and remainder

When using Pelemay in data science, it's necessary to support string manipulation

Describe the solution you'd like

I wish Pelemay to support "String.replace"

Why first is "String.replace"?, because it occupies most of data science

Describe alternatives you've considered
No idea

Additional context
None

Type checking and inference with investigation of range of a value of each element

Is your feature request related to a problem? Please describe.
In SIMD calculation, optimized code is different according to which type of each element is required, 8, 16, 32, or 64 bit.

Describe the solution you'd like
Type checking and inference system should investigate range of a value of each element and generate code using suitable type of array.

Describe alternatives you've considered
None.

Additional context
This issue is related to #75

Supporting CUDA for efficient matrix calculation

Is your feature request related to a problem? Please describe.

Efficient matrix calculation is strongly and seriously required from AI and machine learning purposes.

Describe the solution you'd like

One of current main stream and the state-of-the-art matrix calculation technologies is to use CUDA.
I guess supporting CUDA for efficient matrix calculation is desired strongly from the market.

Describe alternatives you've considered

It may be an alternative to compile general arithmetic operations into CUDA by nvcc.

Additional context

Many stakeholders has an interest on it. Do our best.

Run mix format?

Could you add a .formatter.exs and run mix format? I realize this is a trivial request, but it would make it easier to send clean PRs up. There are just enough minor changes that the formatter makes that I did not feel comfortable sending the PR up myself.

Update mix.exs and README for version 0.0.3

  • update version into 0.0.3
  • modify def deps in README into this because updating doesn't work well:
def deps do
  [
    {:pelemay, "~> 0.0.3"},
  ]
end
  • update the installation guide in README.

Not found basic.c when installed from Hex

Problem detail

When we write the defpelemay in our own projects, the generator try to read basic.c in deps/pelemay/lib/pelemay/generator/native. However, the path as dir attribute points just from the library, "lib/pelemay/generator/native/". It results file not found.

Suggestion

When the file is not found, add the path for dependency, "deps/pelemay/".

The functional testing is not passed in the PR #38

Describe the bug
When applying the PR #38, the functional testing is not passed.

To Reproduce
Steps to reproduce the behavior:

  1. Pull the PR #38
  2. Do mix test
  3. See error
$ mix test
make: Nothing to be done for `all'.


  1) test Basic functional testing for Pelemay (PelemayTest)
     test/pelemay_test.exs:5
     ** (UndefinedFunctionError) function PelemayTest.Sample.map_square/1 is undefined (module PelemayTest.Sample is not available)
     code: result = 1..4 |> Enum.to_list |> PelemayTest.Sample.map_square
     stacktrace:
       PelemayTest.Sample.map_square([1, 2, 3, 4])
       test/pelemay_test.exs:6: (test)


20:47:28.204 [warn]  The on_load function for module Elixir.PelemayNif returned:
{:error, {:load_failed, 'Failed to load NIF library: \'dlopen(/Users/zacky/github/pelemay/_build/test/lib/pelemay/priv/libnif.so, 2): image not found\''}}

...........warning: PelemayNifElixirPelemayTestSample.map_mult/1 is undefined (module PelemayNifElixirPelemayTestSample is not available or is yet to be defined)
  test/pelemay_test.exs:15: PelemayTest.Sample.map_square/1

There aren't generate code completely in the building directory:

$ ls _build/test/lib/pelemay/priv/
generated.mk
pelemay_nif_elixir_pelemaytest_sample.ex

The target in the generated generated.mk is empty:

$ cat _build/test/lib/pelemay/priv/generated.mk 
# This file was generated by Pelemay.Generator.Makefile
TARGET_LIBS :=

Expected behavior

ls in the building directory should be as follows:

$ ls _build/test/lib/pelemay/priv/
generated.mk
pelemay_nif_elixir_pelemaytest_sample.ex
libelixirpelemaytestsample.c
libelixirpelemaytestsample.so

The target in the generated generated.mk should be as follows:

$ cat _build/test/lib/pelemay/priv/generated.mk 
# This file was generated by Pelemay.Generator.Makefile
TARGET_LIBS := libelixirpelemaytestsample.so

And then, the functional testing will be passed successfully.

Screenshots
omitted

Desktop (please complete the following information):

  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.10.0-dev (587453b) (compiled with Erlang/OTP 22)
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS:

macOS Mojave 10.14.6

  • Version:

master

Additional context

I guess Pelemay doesn't work well in test directory.

Error: ** (Mix) Could not compile with "make"

When mix compile, the following a FATAL ERROR occurs:

mkdir -p /Users/zacky/github/pelemay/_build/dev/lib/pelemay/priv
make: *** No rule to make target `native/lib.c', needed by `/Users/zacky/github/pelemay/_build/dev/lib/pelemay/priv/libnif.so'.  Stop.
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. Try running the
commands "gcc --version" and / or "make --version". If these programs
are not installed, you will be prompted to install them.

elixir -v:

$ elixir -v
Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:36:36] [ds:36:36:10] [async-threads:1] [hipe]

Elixir 1.9.0 (compiled with Erlang/OTP 22)

gcc --version:

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

and make --version:

$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0

Handle integer overflow

Describe the bug
Current Pelemay performs integer calculation incorrectly when the value is or will be overflow.

To Reproduce
Snip.

Expected behavior
Same to using Enum.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.4
    Snip.

Additional context
None.

For Numexy.add

Describe the bug
When applying Pelemay to Numexy.add, an error occurs.

The code is as follows:
https://github.com/zeam-vm/numexy/blob/zacky1972_develop/lib/numexy.ex#L43

To Reproduce
Steps to reproduce the behavior:

  1. Use Pelemay in the source code as follows:
    https://github.com/zeam-vm/numexy/blob/zacky1972_develop/lib/numexy.ex#L43

  2. Run in the command 'mix test'

  3. See error:

$ mix test
==> pelemay
Compiling 8 files (.ex)
Generated pelemay app
==> numexy
Compiling 2 files (.ex)

== Compilation error in file lib/numexy.ex ==
** (FunctionClauseError) no function clause matching in SumMag.optimize_func/2    
    
    The following arguments were given to SumMag.optimize_func/2:
    
        # 1
        {:defp, [line: 44], [{:enum_add_sub, [line: 44], [{:list, [line: 44], nil}, {:s, [line: 44], nil}]}, [do: {:|>, [line: 45], [{:list, [line: 45], nil}, {{:., [line: 45], [{:__aliases__, [line: 45], [:Enum]}, :map]}, [line: 45], [{:&, [line: 45], [{:+, [line: 45], [{:&, [line: 45], [1]}, {:s, [line: 45], nil}]}]}]}]}]]}
    
        # 2
        #Function<0.131710887/1 in Pelemay."MACRO-defpelemay"/2>
    
    Attempted function clauses (showing 1 out of 1):
    
        defp optimize_func({:def, meta, [arg_info, exprs]}, optimizer)
    
    lib/sum_mag.ex:257: SumMag.optimize_func/2
    (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
    lib/sum_mag.ex:253: SumMag.map/2
    expanding macro: Pelemay.defpelemay/1
    lib/numexy.ex:43: Numexy (module)

Expected behavior
mix test should be done successfully.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.2
  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS (OS name & version, and uname -a):

macOS Mojave 10.14.6

$ uname -a
Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Clang versions (clang -v):
$ clang -v
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Additional context

Current Pelemay may support not to use it in defp nor to use second parameter in NIFs.

All of Doctests aren't executed

Describe the bug
All of Doctests aren't executed.

To Reproduce
Steps to reproduce the behavior:

  1. Run in the command mix test
  2. Number of doctests are too few.
$ mix test
...................

Finished in 0.1 seconds
8 doctests, 11 tests, 0 failures

Expected behavior

There are more doctests in the source code.
Expected mix test results are here:

33 doctests, 11 tests, 3 failures

Screenshots
None

Desktop (please complete the following information):

  • Pelemay Version: 0.0.2
  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS (OS name & version, and uname -a):

macOS Mojave 10.14.6

$ uname -a
Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Clang versions (clang -v):
$ clang -v
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Additional context

To fix this issue, this patch will be effective:

diff --git a/test/pelemay/generator_test.exs b/test/pelemay/generator_test.exs
index cdb81ec..15ce7ee 100644
--- a/test/pelemay/generator_test.exs
+++ b/test/pelemay/generator_test.exs
@@ -1,4 +1,7 @@
 defmodule Pelemay.GeneratorTest do
   use ExUnit.Case
   doctest Pelemay.Generator
+  doctest Pelemay.Generator.Interface
+  doctest Pelemay.Generator.Native
+  doctest Pelemay.Generator.Builder
 end
diff --git a/test/pelemay_test.exs b/test/pelemay_test.exs
index 737683d..6657c4d 100644
--- a/test/pelemay_test.exs
+++ b/test/pelemay_test.exs
@@ -1,4 +1,6 @@
 defmodule PelemayTest do
   use ExUnit.Case, async: true
   doctest Pelemay
+  doctest Pelemay.Db
+  doctest SumMag
 end

However, this causes another issue because the doctests of SumMag don't passed.

For Elixir 1.10

Is your feature request related to a problem? Please describe.
For Elixir 1.10 https://github.com/elixir-lang/elixir/pull/9673/files

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Sample Project using Pelemay doesn't work on Windows

Describe the bug
Sample Project using Pelemay doesn't work on Windows
(Since this phenomenon doesn't occur in mac, it's bug assumed specific to Windows)

To Reproduce

  1. Use Pelemay in the source code
    Source codes and commands are written in following column
    https://qiita.com/piacerex/items/b6f12682038975d59119

  2. Run in the command:

iex -S mix
iex> PelemaySample.map_square [ 1, 2, 3 ]
  1. See error
** (ArgumentError) argument error
    (stdlib) :io.put_chars(:standard_io, :unicode, [<<32, 32, 32, 131, 137, 131, 67, 131, 117, 131, 137, 131, 138, 32, 99, 58, 47, 112, 105, 97, 99, 101, 114, 101, 47, 99, 111, 100, 101, 47, 112, 101, 108, 101, 109, 97, 121, 95, 115, 97, 109, 112, 108, 101, 47, 95, 98, 117, 105, ...>>, 10])
    lib/pelemay.ex:53: Pelemay.pelemaystub/2
    expanding macro: Pelemay.defpelemay/1
    lib/pelemay_sample.ex:5: PelemaySample (module)

Expected behavior

iex> PelemaySample.map_square [ 1, 2, 3 ]
[ 1, 4, 9 ]

Screenshots
See following column
https://qiita.com/piacerex/items/b6f12682038975d59119

Desktop (please complete the following information):
Below is my desktop version on Windows:

  • Pelemay Version: 0.0.2
  • Elixir & Erlang/OTP versions (elixir --version):
> elixir --version
Erlang/OTP 20 [erts-9.0] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10]

Elixir 1.9.1 (compiled with Erlang/OTP 20)
  • OS (OS name & version, and On Windows, use ver instead of uname):
> ver
Microsoft Windows [Version 10.0.17134.1006]
  • Clang versions (clang -v):
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Tools\LLVM\bin

Additional context
This details are discussed in the comments section in following column (but in japanese)
https://qiita.com/piacerex/items/b6f12682038975d59119

Build failed in the case that there is a defpelemay macro for each module.

Describe the bug
Build failed in the case that there is a defpelemay for each module.

To Reproduce
Steps to reproduce the behavior:

  1. mix new test
  2. Define Test in lib/test.ex as follows:
defmodule Test do
  alias Test.Test1
  alias Test.Test2

  @moduledoc """
  Documentation for Test.
  """

  def do_test() do
    1..1000
    |> Enum.to_list()
    |> Test1.do_test()
    |> Test2.do_test()
  end
end
  1. Define Test.Test1 in lib/test/test1.ex as follows:
defmodule Test.Test1 do
  require Pelemay
  import Pelemay

  defpelemay do
    def do_test(list) do
      list |> Enum.map(& &1 * 2)
    end
  end
end
  1. Define Test.Test2 in lib/test/test2.ex as follows:
defmodule Test.Test2 do
  require Pelemay
  import Pelemay

  defpelemay do
    def do_test(list) do
      list |> Enum.map(& &1 + 1)
    end
  end
end
  1. mix compile will be failed in the following errors:
$ mix compile
Compiling 3 files (.ex)

== Compilation error in file lib/test/test2.ex ==
** (ArgumentError) argument error
    (stdlib) :ets.new(:nif_func, [:set, :public, :named_table])
    lib/pelemay/db.ex:10: Pelemay.Db.init/0
    expanding macro: Pelemay.defpelemay/1
    lib/test/test2.ex:5: Test.Test2 (module)

Expected behavior

The compile mix compile become successful, and iex -S mix and type following command will works:

$ iex -S mix
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Interactive Elixir (1.9.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Test.do_test
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43,
 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83,
 85, 87, 89, 91, 93, 95, 97, 99, 101, ...]
iex(2)> 

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay version: 0.0.2
  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir --version
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS:

macOS Mojave 10.14.6

$ uname -a
Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Clang Version:
$ clang --version
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Additional context

The compile will works the following steps:

  1. Make test2.ex inactive
  2. mix compile
  3. Make test2.ex active
  4. mix compile

Perhaps, it doesn't work in the case of two or more compilation of defpelemay concurrently.

Separate sample codes

After watched #27, I thought that it is NOT suitable for including sample codes into this library.
It's same with benchmark tool.

So, we should better separate samples from this repository.

/usr/include and /usr/lib may be disappeared in the case of macOS

Describe the bug

Error occurs when Clang compiled from the original site, not Apple Clang

To Reproduce
Steps to reproduce the behavior:

  1. Use Pelemay in the source code in the pelemay_sample repository
  2. Run in the command 'mix bench' when it uses clang in /usr/local/bin
  3. See error
$ mix bench
Compiling 1 file (.ex)
In file included from /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
In file included from /Users/zacky/.asdf/installs/erlang/22.0.7/erts-10.4.4/include/erl_nif.h:31:
/Users/zacky/.asdf/installs/erlang/22.0.7/erts-10.4.4/include/erl_drv_nif.h:158:12: fatal error: 
      'sys/types.h' file not found
#  include <sys/types.h>
           ^~~~~~~~~~~~~
1 error generated.

== Compilation error in file lib/pelemay_sample.ex ==
** (MatchError) no match of right hand side value: {"", 1}
    lib/pelemay/generator/builder.ex:35: Pelemay.Generator.Builder.generate/1
    lib/pelemay.ex:51: Pelemay.pelemaystub/2
    expanding macro: Pelemay.defpelemay/1
    lib/pelemay_sample.ex:22: PelemaySample (module)

Expected behavior
Compilation and benchmarking run successful.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.4
  • Elixir & Erlang/OTP versions (elixir --version): 1.9.2 OTP 22
  • OS (OS name & version, and uname -a): macOS Mojave
  • Clang versions (clang -v):
$ clang --version
clang version 10.0.0 (https://github.com/llvm/llvm-project.git 078bec6c48dd9d17ab9720897d2bb7ccbb886763)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/bin

Additional context
Compilation options may be wrong.

ld: warning: directory not found for option '-L/usr/local/opt/openblas/lib' if OpenBLAS is not installed

The following warning occurs If OpenBLAS is not installed.

clang -Ofast -g -ansi -pedantic -femit-all-decls -I/Users/zacky/kerl/22.0/erts-10.4/include -I/usr/local/include -I/usr/include -L/usr/local/lib -L/usr/lib -std=c11 -Wno-unused-function -fPIC -shared -L/usr/local/opt/llvm/lib -L/usr/local/opt/sqlite/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/openblas/lib -L/usr/local/opt/[email protected]/lib -L/usr/local/opt/icu4c/lib -dynamiclib -undefined dynamic_lookup -o /Users/zacky/github/pelemay/_build/dev/lib/pelemay/priv/libnif.so native/lib.c
ld: warning: directory not found for option '-L/usr/local/opt/openblas/lib'

To fix this warning requires to detect whether OpenBLAS is installed or not.

Fail `mix firmware` on Nerves RPi0 with Pelemay ** (Mix) Nerves encountered an error. %IO.Stream{device: :standard_io, line_or_bytes: :line, raw: true}

Describe the bug

RaspberryPi Zero WH のNerves環境下にてmix firmwareに失敗する.

** (Mix) Nerves encountered an error. %IO.Stream{device: :standard_io, line_or_bytes: :line, raw: true}

To Reproduce
Steps to reproduce the behavior:

  1. Use Pelemay in the source code '...'

lib/pelemay_sample.ex:

defmodule PelemaySample do
  require Pelemay
  import Pelemay
  
  defpelemay do
    def enum_square list do
      list |> Enum.map(& &1 * &1)
    end
  end

  @doc """
    ## Examples
    iex> PelemaySample.do_test()
    [1, 4, 9, 16]
  """
  def do_test do
    1..4 |> Enum.to_list |> enum_square()
  end

  def hello do
    :world
  end
  
end
  1. Run in the command '....'
$ mix firmware
  1. See error
Nerves environment
  MIX_TARGET:   rpi0
  MIX_ENV:      dev

Compiling 1 file (.ex)
|nerves_bootstrap| Building OTP Release...

* skipping runtime configuration (config/releases.exs not found)
* creating _build/rpi0_dev/rel/pelemay_sample/releases/0.1.0/vm.args
Updating base firmware image with Erlang release...
scrub-otp-release.sh: ERROR: Unexpected executable format for '/Users/osako/Documents/nerves/pelemay_sample/_build/_nerves-tmp/rootfs-additions/srv/erlang/lib/pelemay-0.0.4/priv/libnifelixirpelemaysample.so'

Got:
 file:Mach-O 64-bit dynamically linked shared library x86_64

Expecting:
 readelf:ARM;0x5000200, Version5 EABI, soft-float ABI

This file was compiled for the host or a different target and probably
will not work.

Check the following:

1. Are you using a path dependency in your mix deps? If so, run
   'mix clean' in that directory to avoid pulling in any of its
   build products.

2. Did you recently upgrade to Elixir 1.9 or Nerves 1.5?
   Nerves 1.5 adds support for Elixir 1.9 Releases and requires
   you to either add an Elixir 1.9 Release configuration or add
   Distillery as a dependency. Without this, the OTP binaries
   for your build machine will get included incorrectly and cause
   this error. See
   https://hexdocs.pm/nerves/updating-projects.html#updating-from-v1-4-to-v1-5

3. Did you recently upgrade or change your Nerves system? If so,
   try cleaning and rebuilding this project and its deps.

4. Are you building outside of Nerves' mix integration? If so,
   make sure that you've sourced 'nerves-env.sh'.

If you're still having trouble, please file an issue on Github
at https://github.com/nerves-project/nerves_system_br/issues.

** (Mix) Nerves encountered an error. %IO.Stream{device: :standard_io, line_or_bytes: :line, raw: true}

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.4
  • Elixir & Erlang/OTP versions (elixir --version): OTP22/Elixir 1.9.1
  • OS (OS name & version, and uname -a): macOS 10.14.6 / Darwin VLAN2-dhcp18.is.env.kitakyu-u.ac.jp 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Clang versions (clang -v): Apple LLVM version 10.0.1 (clang-1001.0.46.4)

Additional context

Pelemayをmix deps.getした状態のものをmix do firmware, firmware.burnして,iexでコードをテストすると,以下のような挙動を得た.

iex([email protected])3> defpelemay do              
...([email protected])3> def enum_square list do    
...([email protected])3> list |> Enum.map(& &1 * &1)
...([email protected])3> end                        
...([email protected])3> end
** (ArgumentError) argument error
    (stdlib) :ets.new(:nif_func, [:set, :public, :named_table])
    (pelemay) lib/pelemay/db.ex:10: Pelemay.Db.init/0
    (pelemay) expanding macro: Pelemay.defpelemay/1
    iex:3: (file)

なお,Nervesを通さずにDocTestを通すことはできます.

Implement map/map fusion of program-fusion

Is your feature request related to a problem? Please describe.

Written codes with pipe is so readable, however it is not efficient because exist temporary datas between pipes.

Describe the solution you'd like

When optimizer found succession of pipes and Enum.map, merge computation which be send as argument into one liner.

Describe alternatives you've considered

Use GHC and NIF, after we make GHC parser for a part of Elixir.

Additional context

Elixir is not pure functional programming language, so I think that verifying strictly code transformation is difficult.

Support some float and math functions

Is your feature request related to a problem? Please describe.

Mathematical calculation requires some float and math functions.

Describe the solution you'd like
Support the following functions:

  • abs/1
  • div/2
  • min/2
  • max/2
  • Enum.min_max/1
  • round/1
  • Float.round/2
  • :math.pi/0
  • :math.sin/1
  • :math.cos/1
  • :math.tan/1
  • :math.sqrt/1
  • :math.pow/2
  • :math.exp/1
  • :math.log/1
  • :math.log10/1
  • :math.log2/1

and so on

Describe alternatives you've considered
None.

Additional context
None.

Doctests of SumMag don't passed successfully

Describe the bug
Doctests of SumMag don't passed successfully

To Reproduce
Steps to reproduce the behavior:

  1. Apply the following patch to Pelemay:
diff --git a/test/pelemay/generator_test.exs b/test/pelemay/generator_test.exs
index cdb81ec..15ce7ee 100644
--- a/test/pelemay/generator_test.exs
+++ b/test/pelemay/generator_test.exs
@@ -1,4 +1,7 @@
 defmodule Pelemay.GeneratorTest do
   use ExUnit.Case
   doctest Pelemay.Generator
+  doctest Pelemay.Generator.Interface
+  doctest Pelemay.Generator.Native
+  doctest Pelemay.Generator.Builder
 end
diff --git a/test/pelemay_test.exs b/test/pelemay_test.exs
index 737683d..6657c4d 100644
--- a/test/pelemay_test.exs
+++ b/test/pelemay_test.exs
@@ -1,4 +1,6 @@
 defmodule PelemayTest do
   use ExUnit.Case, async: true
   doctest Pelemay
+  doctest Pelemay.Db
+  doctest SumMag
 end
  1. Run in the command mix test

  2. See error:

$ mix test
...........warning: this check/guard will always yield the same result
  (for doctest at) lib/sum_mag.ex

.....

  1) doctest SumMag.melt_block/1 (12) (PelemayTest)
     test/pelemay_test.exs:5
     Doctest failed
     doctest:
       iex> quote do  
       ...>   def func do: "doctest"    
       ...> end  
       {:def, [context: SumMagTest, import: Kernel],
         [{:func, [context: SumMagTest], [[do: "doctest"]]}]}
     code:  quote do
              def(func do
                "doctest"
              end)
            end === {:def, [context: SumMagTest, import: Kernel],
              [{:func, [context: SumMagTest], [[do: "doctest"]]}]}
     left:  {:def, [context: PelemayTest, import: Kernel], [{:func, [context: PelemayTest], [[do: "doctest"]]}]}
     right: {:def, [context: SumMagTest, import: Kernel], [{:func, [context: SumMagTest], [[do: "doctest"]]}]}
     stacktrace:
       lib/sum_mag.ex:228: SumMag (module)

..

  2) doctest SumMag.parse/2 (16) (PelemayTest)
     test/pelemay_test.exs:5
     Doctest failed
     doctest:
       iex> (quote do
       ...>    def func(list) do
       ...>      list
       ...>      |> Enum.map(& &1)
       ...>    end
       ...> end) |> SumMag.parse(%{target: :pelemay})
       [[function_name: :func, is_public: true, args: [:list], do: [{:|>, [context: SumMagTest, import: Kernel], [{:list, [], SumMagTest}, {{:., [], [{:__aliases__, [alias: false], [:Enum]}, :map]}, [], [{:&, [], [{:&, [], [1]}]}]}]}], is_nif: false ]]
     code:  quote do
              def(func(list)) do
                list |> Enum.map(&(&1))
              end
            end |> SumMag.parse(%{target: :pelemay}) === [[function_name: :func, is_public: true, args: [:list], do: [{:|>, [context: SumMagTest, import: Kernel], [{:list, [], SumMagTest}, {{:., [], [{:__aliases__, [alias: false], [:Enum]}, :map]}, [], [{:&, [], [{:&, [], [1]}]}]}]}], is_nif: false ]]
     left:  [[function_name: :func, is_public: true, args: [:list], do: [{:|>, [context: PelemayTest, import: Kernel], [{:list, [], PelemayTest}, {{:., [], [{:__aliases__, [alias: false], [:Enum]}, :map]}, [], [{:&, [], [{:&, [], [1]}]}]}]}], is_nif: false]]
     right: [[function_name: :func, is_public: true, args: [:list], do: [{:|>, [context: SumMagTest, import: Kernel], [{:list, [], SumMagTest}, {{:., [], [{:__aliases__, [alias: false], [:Enum]}, :map]}, [], [{:&, [], [{:&, [], [1]}]}]}]}], is_nif: false]]
     stacktrace:
       lib/sum_mag.ex:14: SumMag (module)

....

  3) doctest SumMag.parse/2 (15) (PelemayTest)
     test/pelemay_test.exs:5
     Doctest failed
     doctest:
       iex> (quote do: def func(a), do: a) |> SumMag.parse(%{target: :pelemay})
       [[function_name: :func, is_public: true, args: [:a], do: [{:a, [], SumMagTest}], is_nif: false ]]
     code:  quote do
              def(func(a)) do
                a
              end
            end |> SumMag.parse(%{target: :pelemay}) === [[function_name: :func, is_public: true, args: [:a], do: [{:a, [], SumMagTest}], is_nif: false ]]
     left:  [[function_name: :func, is_public: true, args: [:a], do: [{:a, [], PelemayTest}], is_nif: false]]
     right: [[function_name: :func, is_public: true, args: [:a], do: [{:a, [], SumMagTest}], is_nif: false]]
     stacktrace:
       lib/sum_mag.ex:11: SumMag (module)

...................

Finished in 0.2 seconds
33 doctests, 11 tests, 3 failures

Randomized with seed 201099

Expected behavior
All doctests must pass successfully.

Screenshots
None.

Desktop (please complete the following information):

  • Pelemay Version: 0.0.2
  • Elixir & Erlang/OTP versions (elixir --version):
$ elixir -v
Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Elixir 1.9.1 (compiled with Erlang/OTP 22)
  • OS (OS name & version, and uname -a):

macOS Mojave 10.14.6

$ uname -a
Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64
  • Clang versions (clang -v):
$ clang -v
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Additional context

This issue is related to #50

Warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated.

When mix compile, the following warning occurs:

warning: System.stacktrace/0 outside of rescue/catch clauses is deprecated. If you want to support only Elixir v1.7+, you must access __STACKTRACE__ inside a rescue/catch. If you want to support earlier Elixir versions, move System.stacktrace/0 inside a rescue/catch
  lib/benchfella.ex:506

to run elixir -v:

$ elixir -v
Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:36:36] [ds:36:36:10] [async-threads:1] [hipe]

Elixir 1.9.0 (compiled with Erlang/OTP 22)

I guess this warning is due to Benchfella, but we should contribute it by reporting this issue.

Can't install to WSL

I got following message.

mix deps.get

12:50:53.498 [error] Unable to load crypto library. Failed with error:
":load_failed, Failed to load NIF library: '/usr/lib/x86_64-linux-gnu/libcrypto.so.1.1: version `OPENSSL_1
_1_1' not found (required by /usr/lib/erlang/lib/crypto-4.5.1/priv/lib/crypto.so)'"
OpenSSL might not be installed on this system.

I updated Elixir by ASDF
asdf list
elixir
1.9.0
erlang
No versions installed

My environment is following.
Windows subsystem for LInux
Ubuntu 18.04

Create CUDA template

defp enum_map(%{nif_name: nif_name, args: args, operators: operators})in lib/pelemay/generator/native.ex defines a template generator function extracted from Enum.map.

So, would you prepare a CUDA version of it?

I named the function enum_map_CUDA.

branch name is also the same to the function.

Supporting some functions for using libraries which were implemented by C / C ++.

Is your feature request related to a problem? Please describe.

I used visualization of point cloud library.
https://github.com/PointCloudLibrary/pcl
This library has been implemented by C++.

But now, we cannot apply pelemay for elixir project with pcl.

Describe the solution you'd like

Supporting the following functions:

String.replace/2
String.slice/2
String.split/2
String.to_integer/1
Enum.split/2
Enum.reduce/3
Base.encode16/1
length/1
is_bitstring/1

operator
<>

other
calling a function in Enum.map.

Describe alternatives you've considered
No idea

Additional context
None.

Implement a new type code generator

Suppose the following ZEAM IR is given:

[{:include, [], "stdbool.h"}, 
 {:include, [], "erl_nif.h"},
 {:define_const_int, [], [{:=, [], [{:FAIL, [], :macro}, 0]}]},
 {:define_const_int, [], [{:=, [], [{:SUCCESS, [], :macro}, 1]}]},
 {:defunc, :add, [
  {:raise_badarg_if, [{:!=, :argc, 2}]},
  {:let, [
  	{:a, {:return_if_fail, {:get_int64, {:get_array, :argv, 0}}}},
  	{:b, {:return_if_fail, {:get_int64, {:get_array, :argv, 1}}}},
  	], {
    {:make_int64, {:add_int64, :a, :b}}
  }}
]}]

It will be converted into the following C code:

#include <stdbool.h>
#include <erl_nif.h>
#define FAIL 0
#define SUCCESS 1

static ERL_NIF_TERM
add(ErlNifEnv * env, int argc, const ERL_NIF_TERM argv[])
{
  if (__builtin_expect((argc != 2), false)) {
    return enif_make_badarg(env);
  }
  {
    long a;
    if (__builtin_expect((enif_get_int64(env, argv[0], &a) == FAIL), false)) {
    	return FAIL;
    }
    long b;
    if (__builtin_expect((enif_get_int64(env, argv[1], &b) == FAIL), false)) {
    	return FAIL;
    }
    return enif_make_int64(env, (a + b));
  }
}

Create String.replace SIMD function

I guess to implement String.replace/4 using SIMD instructions will be as follows:

  1. Allocate a memory area for replaced string because memory area in Elixir should be immutable.
  • Keep the same size to the original memory area if the length of the pattern is larger than that of the replacement.
  • Otherwise, keep some larger size than the original memory area.
  1. Copy the original memory area into the replaced string memory area until the pattern is matched to the original memory area or the end of the area is reached, with auto-vectorization and SIMD instructions.
  2. Copy the rest of the original area into the replaced area if the length of the rest is smaller than the pattern with auto-vectorization and SIMD instructions, and Finish.
  3. Match the whole of the pattern and the original area with auto-vectorization and SIMD instructions
  • If matched, confirm and reallocate if necessary the size of the rest of the replaced string area to have an enough capacity, and copy the replacement into the replaced string area with auto-vectorization and SIMD instructions.
  • If not, copy the unmatched original area into the replaced string area with auto-vectorization and SIMD instructions.
  1. Go back 2

This issue is a part of #49

branch name is string_replace.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.