Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Apple Silicon #9

Merged
merged 6 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions extension/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ genrule(
d="$${d#*external/$${extname}/}"
fi
# Remap llvm paths
d="$${d/llvm\/include\/llvm/llvm}"
d="$${d/llvm\/include\/llvm-c/llvm-c}"
d="$${d/llvm\\/include\\/llvm/llvm}"
d="$${d/llvm\\/include\\/llvm-c/llvm-c}"
Copy link
Member Author

Choose a reason for hiding this comment

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

@seanmor5 my hypothesis is that the escape in \/ would be first interpreted by Bazel and for bazel \/ would be an invalid escape. On the other hand \\ would be a valid escape and appear as \ in the actual script.

# Remap google path
d="$${d/src\/google/google}"
d="$${d/src\\/google/google}"
# Remap grpc paths
d="$${d/include\/grpc/grpc}"
d="$${d/include\\/grpc/grpc}"
mkdir -p "$@/$${d}"
cp "$${f}" "$@/$${d}/"
done
Expand Down
42 changes: 26 additions & 16 deletions lib/xla.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ defmodule XLA do

@doc false
def make_env() do
bazel_build_flags =
bazel_build_flags_accelerator =
case xla_target() do
"cuda" <> _ -> "--config=cuda"
"rocm" <> _ -> "--config=rocm --action_env=HIP_PLATFORM=hcc"
"tpu" <> _ -> "--config=tpu"
_ -> ""
"cuda" <> _ -> ["--config=cuda"]
"rocm" <> _ -> ["--config=rocm", "--action_env=HIP_PLATFORM=hcc"]
"tpu" <> _ -> ["--config=tpu"]
_ -> []
end

bazel_build_flags_cpu =
case cpu_and_os() do
{"aarch64", "darwin"} -> ["--config=macos_arm64"]
_ -> []
end

bazel_build_flags = Enum.join(bazel_build_flags_accelerator ++ bazel_build_flags_cpu, " ")

# Additional environment variables passed to make
%{
"BUILD_INTERNAL_FLAGS" => bazel_build_flags,
Expand All @@ -90,20 +98,22 @@ defmodule XLA do
end

defp target() do
{cpu, os} =
:erlang.system_info(:system_architecture)
|> List.to_string()
|> String.split("-")
|> case do
["arm" <> _, _vendor, "darwin" <> _ | _] -> {"aarch64", "darwin"}
[cpu, _vendor, "darwin" <> _ | _] -> {cpu, "darwin"}
[cpu, _vendor, os | _] -> {cpu, os}
["win32"] -> {"x86_64", "windows"}
end

{cpu, os} = cpu_and_os()
"#{cpu}-#{os}-#{xla_target()}"
end

defp cpu_and_os() do
:erlang.system_info(:system_architecture)
|> List.to_string()
|> String.split("-")
|> case do
["arm" <> _, _vendor, "darwin" <> _ | _] -> {"aarch64", "darwin"}
[cpu, _vendor, "darwin" <> _ | _] -> {cpu, "darwin"}
[cpu, _vendor, os | _] -> {cpu, os}
["win32"] -> {"x86_64", "windows"}
end
end

defp archive_path_for_build() do
filename = archive_filename_with_target()
cache_path(["build", filename])
Expand Down