timescale / pgvectorscale

A complement to pgvector for high performance, cost efficient vector search on large workloads.
PostgreSQL License
610 stars 23 forks source link

Compile error - AVX2 and fma features #97

Closed markwillowtree closed 3 weeks ago

markwillowtree commented 3 weeks ago

I am running postgresql16 on ubuntu 22.04 with a 14900k cpu.

I have followed the instructions to compile from source on this page https://github.com/timescale/pgvectorscale/blob/main/DEVELOPMENT.md and am getting the following errors

Could you advise on how to proceed, please?

cargo pgrx install --release
       Using PgConfig("pg16") and `pg_config` from /usr/bin/pg_config
    Building extension with features pg16
     Running command "/home/linux/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo" "build" "--release" "--features" "pg16" "--no-default-features" "--message-format=json-render-diagnostics"
   Compiling pgrx-pg-sys v0.11.4
   Compiling pgrx v0.11.4
   Compiling vectorscale v0.2.0 (/tmp/pgvectorscale/pgvectorscale)
error: On x86, the AVX2 feature must be enabled. Set RUSTFLAGS="-C target-feature=+avx2,+fma"
 --> src/access_method/distance.rs:4:1
  |
4 | / compile_error!(
5 | |     "On x86, the AVX2 feature must be enabled. Set RUSTFLAGS=\"-C targe...
6 | | );
  | |_^

error: On x86, the AVX2 feature must be enabled. Set RUSTFLAGS="-C target-feature=+avx2,+fma"
  --> src/access_method/distance_x86.rs:10:1
   |
10 | / compile_error!(
11 | |     "On x86, the AVX2 feature must be enabled. Set RUSTFLAGS=\"-C targ...
12 | | );
   | |_^

error: On x86, the fma feature must be enabled. Set RUSTFLAGS="-C target-feature=+avx2,+fma"
  --> src/access_method/distance_x86.rs:16:1
   |
16 | / compile_error!(
17 | |     "On x86, the fma feature must be enabled. Set RUSTFLAGS=\"-C targe...
18 | | );
   | |_^

error: could not compile `vectorscale` (lib) due to 3 previous errors
cevian commented 3 weeks ago

can you try

RUSTFLAGS="-C target-feature=+avx2,+fma" cargo pgrx install --release
markwillowtree commented 3 weeks ago

Thanks, that has helped move me forward but I have encountered new problems with the installation procedure.

With the new command I got a new error about a missing library

RUSTFLAGS="-C target-feature=+avx2,+fma" cargo pgrx install --release

error: linking with `cc` failed: exit status: 1
...
/usr/bin/ld: cannot find -lopenblas: No such file or directory
          collect2: error: ld returned 1 exit status

I fixed this issue by installing libopenblas

sudo apt-get install libopenblas-dev

Now compilation succeeds, but the copying of the file fails due to lack of permissions.

   0: failed writing `/home/linux/pgvectorscale/pgvectorscale/vectorscale.control` to `/usr/share/postgresql/16/extension/vectorscale.control`
   1: Permission denied (os error 13)

So I copied this file manually using sudo.

sudo cp vectorscale.control /usr/share/postgresql/16/extension

and then ran this SQL in pgadmin

CREATE EXTENSION IF NOT EXISTS vectorscale CASCADE;

and got the following error.

ERROR:  extension "vectorscale" has no installation script nor update path for version "@CARGO_VERSION@" 
markwillowtree commented 3 weeks ago

I figured the permissions issue out. I've added the necessary steps below in case anyone else is having the same problem.

Change permissions on postgres extensions folder to allow postgres user access.

sudo chown postgres -R /usr/share/postgresql/16/extension/
sudo chown postgres -R /usr/lib/postgresql/16/lib/

Compile the code as the postgres user and specify target features.

sudo -u postgres -i
RUSTFLAGS="-C target-feature=+avx2,+fma" cargo pgrx install --release

The following SQL should now work.

CREATE EXTENSION IF NOT EXISTS vectorscale CASCADE;