Wednesday 11 May 2022

Running hdbcli on an Apple M1 chip: an alternative way with using arch command

A look at arch command

I tried an alternative approach, that I would like to share here. It does not involve making a copy of the terminal application, but instead using arch command.

As man arch explains:

By default, the operating system will select the architecture that most closely matches the processor type. … The arch command can be used to alter the operating system’s normal selection order.

The arch command with no arguments, displays the machine’s architecture type.

Let’s run the command without any parameters on a new laptop with an Apple chip. It should return arm64 value.

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

To run a command that supports x86_64 translation mode, you can execute:

/usr/bin/arch -arch x86_64 <command>

One more helpful command will be sysctl to display, if a process is native or translated.

sysctl sysctl.proc_translated
/usr/bin/arch -arch x86_64 sysctl sysctl.proc_translated

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

A command or a binary you are running needs to support a given architecture as can be checked using file /path/to/binary:

file $(which sysctl)
file $(which zsh)

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

Interestingly, MacOS default’s Python is a universal library…

file $(which python3)
python3 -V
arch -arch x86_64 python3 -V

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

…which Python installed with conda is ARM64-only:

file $(which python)
python -V
arch -arch x86_64 python -V

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

Attempt to install hdbcli using pip on Apple silicon


If I try to install hdbcli using pip today (with no “universal” version of HDBCLI for Apple M1 available yet), then I get:

ERROR: Could not find a version that satisfies the requirement hdbcli (from versions: none)
ERROR: No matching distribution found for hdbcli

And what about the Miniconda?

Let us create a separate myhana Conda’s environment…

conda create -n myhana python=3.9
conda activate myhana

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

Still the same.

Start a shell as the x86_64 process


Let’s start a shell with x86_64 compatible architecture…

arch -x86_64 zsh
export PS1='x86$ '

…and check the architecture set for the session.

arch
uname -m

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

I must admit this i386 vs x86_64 is still confusing me. I will appreciate, if you share your explanation in comments, should you know why these two values are different.

Install hdbcli in x86_64 process


Now that we are in the x86_64 translated process, let’s try installing hdbcli using pip.

python3 -m pip install hdbcli
python3 -m pip show hdbcli

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

And what about Miniconda environment?

Unfortunately it does not work.

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

I assume, it is because it got arm64-compatible binary of Python only — as we have checked above. And I have not found a way yet to install universal binary of Python into a conda’s environment yet. Have you?

Bonus: Create a profile in a terminal application for an x86 translated mode


To streamline invoking a shell in an x86 translated mode you can create a separate profile.

I am using iTerm2 application, so this is how my setup looks like.

SAP HANA, SAP HANA Exam Prep, SAP HANA Certification, SAP HANA Learning, SAP HANA Career, SAP HANA Skills, SAP HANA Jobs, SAP HANA Preparation Exam

1. Make a copy of the Default profile and called it “Rosetta Shell”,

2. Change Command setting from “Login Shell” to “Command” with the value /usr/bin/arch -x86_64 /bin/zs.

No comments:

Post a Comment