GithubHelp home page GithubHelp logo

Comments (5)

mberry avatar mberry commented on June 1, 2024 1

Thanks, those asm symbols should be fine with 64-bit windows but we don't have a test harness for it yet. I'll try to find the cause later this week.

optimizations are opt-in instead of opt-out

Fair call. There's a usability vs "doing it the rust way" tradeoff that I'm mulling over a lot, for an extreme example of how messy it gets when going full generic:

https://github.com/Argyle-Software/sphincsplus/blob/refactor/src/sign.rs#L17-L33

The alternative is large amounts of code duplication and build scripts for dozens of individual crates. As far as trade-off's go it's not an easy choice but this stuff should probably be a different issue altogether.

from kyber.

mberry avatar mberry commented on June 1, 2024 1

With the version bump avx2 will be opt-in only, so I'll consider this fixed, I'd prefer to keep it simple rather than layering on ever more conditional compilation and runtime detections for each platform, opt-in works best. The current C reference doesn't have optimisations for windows, nor does PQClean.

Have added windows CI runners also for 32/64 bit x86 windows gnu/msvc as well as aarch64.

I've rewritten the at&t syntax GAS files into NASM, not tested on windows yet but it's passing all the test vectors on linux. Will keep it as an experimental feature for a while, it's behind the nasm feature gate on the nasm-conversion branch and will likely stay there for a while to be assessed:

https://github.com/Argyle-Software/kyber/tree/nasm-conversion

from kyber.

mberry avatar mberry commented on June 1, 2024

Can you confirm this is built with:

RUSTFLAGS="-C target-cpu=native -C target-feature=+aes,+avx2,+sse2,+sse4.1,+bmi2,+popcnt"

before compiling?

In your output there is: CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2") and that's not enough for the optimised version to compile.

At the moment anything x86_64 will use the optimised version. This is changed now to: target_feature="avx2"on the macos-fix branch. Master assumes everyone with x86_64 can run avx2 simd instructions. This makes it unnecessary to export the rustflags but includes all the chips that intel somehow still ships without it like modern pentiums and celerons which need to use reference.
Perhaps needs some note under #[cfg(debug_assertions)] in the build script to publish whether they are building the reference or optimised version.

from kyber.

faern avatar faern commented on June 1, 2024

I get the same error with RUSTFLAGS="-C target-cpu=native -C target-feature=+aes,+avx2,+sse2,+sse4.1,+bmi2,+popcnt".

In your output there is: CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2") and that's not enough for the optimised version to compile.

Then I don't think the crate should enable the optimized version. IMO it would be most developer friendly if the crate always works and optimizations are opt-in instead of opt-out. If they can be automatically enabled in a reliable way that would of course be the best 👌

New log
$ RUSTFLAGS="-C target-cpu=native -C target-feature=+aes,+avx2,+sse2,+sse4.1,+bmi2,+popcnt" cargo build
   Compiling proc-macro2 v1.0.43
   Compiling quote v1.0.21
   Compiling unicode-ident v1.0.4
   Compiling syn v1.0.100
   Compiling unicode-xid v0.2.4
   Compiling cc v1.0.73
   Compiling cfg-if v1.0.0
   Compiling getrandom v0.2.7
   Compiling rand_core v0.6.4
   Compiling pqc_kyber v0.2.1 (C:\Users\faern\src\kyber-master)
The following warnings were emitted during compilation:
warning: cl : Command line warning D9024 : unrecognized source file type 'src/avx2/basemul.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/avx2/basemul.S' ignored
warning: cl : Command line warning D9024 : unrecognized source file type 'src/avx2/fq.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/avx2/fq.S' ignored
warning: cl : Command line warning D9024 : unrecognized source file type 'src/avx2/invntt.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/avx2/invntt.S' ignored
warning: cl : Command line warning D9024 : unrecognized source file type 'src/avx2/ntt.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/avx2/ntt.S' ignored
warning: cl : Command line warning D9024 : unrecognized source file type 'src/avx2/shuffle.S', object file assumed
warning: cl : Command line warning D9027 : source file 'src/avx2/shuffle.S' ignored
error: failed to run custom build command for `pqc_kyber v0.2.1 (C:\Users\faern\src\kyber-master)`
Caused by:
  process didn't exit successfully: `C:\Users\faern\src\kyber-master\target\debug\build\pqc_kyber-de0e4d6bdeecf67b\build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("x86_64-pc-windows-msvc")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-pc-windows-msvc")
  CC_x86_64-pc-windows-msvc = None
  CC_x86_64_pc_windows_msvc = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-pc-windows-msvc = None
  CFLAGS_x86_64_pc_windows_msvc = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = Some("adx,aes,avx,avx2,bmi1,bmi2,fma,fxsr,lzcnt,pclmulqdq,popcnt,rdrand,rdseed,sse,sse2,sse3,sse4.1,sse4.2,ssse3,xsave,xsavec,xsaveopt,xsaves")
  DEBUG = Some("true")
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "src/avx2/" "-W4" "-FoC:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/basemul.o" "-c" "src/avx2/basemul.S"
  cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/avx2/basemul.S', object file assumed
  cargo:warning=cl : Command line warning D9027 : source file 'src/avx2/basemul.S' ignored
  cl : Command line warning D9021 : no action performed
  exit code: 0
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "src/avx2/" "-W4" "-FoC:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/fq.o" "-c" "src/avx2/fq.S"
  cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/avx2/fq.S', object file assumed
  cargo:warning=cl : Command line warning D9027 : source file 'src/avx2/fq.S' ignored
  cl : Command line warning D9021 : no action performed
  exit code: 0
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "src/avx2/" "-W4" "-FoC:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/invntt.o" "-c" "src/avx2/invntt.S"
  cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/avx2/invntt.S', object file assumed
  cargo:warning=cl : Command line warning D9027 : source file 'src/avx2/invntt.S' ignored
  cl : Command line warning D9021 : no action performed
  exit code: 0
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "src/avx2/" "-W4" "-FoC:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/ntt.o" "-c" "src/avx2/ntt.S"
  cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/avx2/ntt.S', object file assumed
  cargo:warning=cl : Command line warning D9027 : source file 'src/avx2/ntt.S' ignored
  cl : Command line warning D9021 : no action performed
  exit code: 0
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\cl.exe" "-nologo" "-MD" "-Z7" "-Brepro" "-I" "src/avx2/" "-W4" "-FoC:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/shuffle.o" "-c" "src/avx2/shuffle.S"
  cargo:warning=cl : Command line warning D9024 : unrecognized source file type 'src/avx2/shuffle.S', object file assumed
  cargo:warning=cl : Command line warning D9027 : source file 'src/avx2/shuffle.S' ignored
  cl : Command line warning D9021 : no action performed
  exit code: 0
  AR_x86_64-pc-windows-msvc = None
  AR_x86_64_pc_windows_msvc = None
  HOST_AR = None
  AR = None
  running: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\lib.exe" "-out:C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\libpqc_kyber.a" "-nologo" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/basemul.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/fq.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/invntt.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/ntt.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/shuffle.o"
  LINK : fatal error LNK1181: cannot open input file 'C:\Users\faern\src\kyber-master\target\debug\build\pqc_kyber-4e4cd6b4fd1f06c6\out\src\avx2\basemul.o'
  exit code: 1181
  --- stderr
  error occurred: Command "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.33.31629\\bin\\HostX64\\x64\\lib.exe" "-out:C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\libpqc_kyber.a" "-nologo" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/basemul.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/fq.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/invntt.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/ntt.o" "C:\\Users\\faern\\src\\kyber-master\\target\\debug\\build\\pqc_kyber-4e4cd6b4fd1f06c6\\out\\src/avx2/shuffle.o" with args "lib.exe" did not execute successfully (status code exit code: 1181).
warning: build failed, waiting for other jobs to finish...

EDIT: I also upgraded to VS2022 between these builds. But I don't think that's relevant to the issue at hand(?)

from kyber.

mberry avatar mberry commented on June 1, 2024

Got this to build on x86_64-pc-windows-gnu using mingw64 gcc[1]. Alas it's segfaulting at runtime, the assembly is written in GAS and windows will need MASM or NASM. There's not a particularly large amount of it, so it could be rewritten eventually.

I wrongly assumed the optimised code used in the C reference codebase compiled for windows but it doesn't. There's still a lot of optimised code written in rust so I'm thinking the best way forward at this point is to put in target_vendor checks and use the reference ntt functions, it will need a bit of refactoring.

from kyber.

Related Issues (20)

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.