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

feat(core,ffi): Add Swift tests for MSM benchmarking #56

Merged
merged 11 commits into from
Feb 13, 2024
Merged

feat(core,ffi): Add Swift tests for MSM benchmarking #56

merged 11 commits into from
Feb 13, 2024

Conversation

FoodChain1028
Copy link
Collaborator

@FoodChain1028 FoodChain1028 commented Jan 23, 2024

Related Issue

#21

Main modification

This branch has swift test added in mopro-ffi

Issue met now

feature flag does not work in swift after building with --features gpu-benchmarks.

to reproduce (in mopro-ffi):

1. cargo build --release --features gpu-benchmarks
2. cargo test --test test_generated_bindings --features gpu-benchmak

screenshot:

gpu-benchmarks feature not enabled!
thread '<unnamed>' panicked at 'gpu-benchmarks feature not enabled!', src/lib.rs:183:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: mopro.(unknown context at $10f04699c).UniffiInternalError.rustPanic("gpu-benchmarks feature not enabled!")
Stack dump:
0.      Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret /Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/tests/bindings/test_mopro_gpu_benchmarks.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -I /Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/tmp/mopro-ffi-c9b386fc8fa179b3 -color-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -Xcc -fmodule-map-file=/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/tmp/mopro-ffi-c9b386fc8fa179b3/moproFFI.modulemap -module-name test_mopro_gpu_benchmarks -disable-clang-spi -target-sdk-version 14.2 -target-sdk-name macosx14.2 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -lmopro_ffi -ltestmod_mopro
1.      Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
3.      Compiling with the current language version
4.      While running user code "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/tests/bindings/test_mopro_gpu_benchmarks.swift"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001039d9abc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010663fcb0 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001063a9054 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x00000001841a4a24 _sigtramp + 56
4  libswiftCore.dylib       0x0000000193a6f1e8 $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAHSus6UInt32VtF + 268
5  libswiftCore.dylib       0x0000000193b0ca24 $ss5ErrorPsSYRzs17FixedWidthInteger8RawValueSYRpzrlE5_codeSivg + 0
6  libswiftCore.dylib       0x000000010dbfc6d4 $ss5ErrorPsSYRzs17FixedWidthInteger8RawValueSYRpzrlE5_codeSivg + 18446744071462386864
7  swift-frontend           0x0000000104f8ddb8 llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::Optional<llvm::StringRef>) + 1276
8  swift-frontend           0x0000000100ff57e8 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>&&) + 11524
9  swift-frontend           0x0000000105f19c24 processCommandLineAndRunImmediately(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>&&, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::FrontendObserver*, int&) + 484
10 swift-frontend           0x0000000105f21650 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1464
11 swift-frontend           0x0000000105f1cf00 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 3020
12 swift-frontend           0x0000000105f20854 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
13 swift-frontend           0x0000000105f87d44 swift::mainEntry(int, char const**) + 4408
14 dyld                     0x0000000183df50e0 start + 2360

to fix this, I had tried to modify Makefile in mopro-ffi to:

TARGETS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim
BUILD_TYPES = debug release benchmarks

all: $(BUILD_TYPES)

debug: $(TARGETS)
	for target in $(TARGETS); do \
		cargo build --target $$target; \
	done

release:
	for target in $(TARGETS); do \
		cargo build --release --target $$target; \
	done

benchmarks:
	for target in $(TARGETS); do \
		cargo build --release --target $$target --features gpu-benchmarks; \
	done

.PHONY: all $(BUILD_TYPES) $(TARGETS)

which would encounter the below issue while running cargo build --release --target aarch64-apple-ios-sim --features gpu-benchmarks.

screenshot (put on the full trace just in case)

error: failed to run custom build command for `jemalloc-sys v0.5.4+5.3.0-patched`

Caused by:
  process didn't exit successfully: `/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/release/build/jemalloc-sys-48a32c1de55e40fa/build-script-build` (exit status: 101)
  --- stdout
  TARGET=aarch64-apple-ios-sim
  HOST=aarch64-apple-darwin
  NUM_JOBS=8
  OUT_DIR="/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out"
  BUILD_DIR="/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build"
  SRC_DIR="/Users/foodchain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jemalloc-sys-0.5.4+5.3.0-patched"
  cargo:rustc-cfg=prefixed
  cargo:rerun-if-env-changed=JEMALLOC_OVERRIDE
  OPT_LEVEL = Some("3")
  TARGET = Some("aarch64-apple-ios-sim")
  HOST = Some("aarch64-apple-darwin")
  cargo:rerun-if-env-changed=CC_aarch64-apple-ios-sim
  CC_aarch64-apple-ios-sim = None
  cargo:rerun-if-env-changed=CC_aarch64_apple_ios_sim
  CC_aarch64_apple_ios_sim = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  Detecting iOS SDK path for iphonesimulator
  running: "xcrun" "--show-sdk-path" "--sdk" "iphonesimulator"
  exit status: 0
  cargo:rerun-if-env-changed=CFLAGS_aarch64-apple-ios-sim
  CFLAGS_aarch64-apple-ios-sim = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_apple_ios_sim
  CFLAGS_aarch64_apple_ios_sim = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  CC="clang"
  CFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall"
  JEMALLOC_REPO_DIR="jemalloc"
  cargo:rerun-if-env-changed=JEMALLOC_SYS_WITH_MALLOC_CONF
  cargo:rerun-if-env-changed=JEMALLOC_SYS_WITH_LG_PAGE
  cargo:rerun-if-env-changed=JEMALLOC_SYS_WITH_LG_HUGEPAGE
  cargo:rerun-if-env-changed=JEMALLOC_SYS_WITH_LG_QUANTUM
  cargo:rerun-if-env-changed=JEMALLOC_SYS_WITH_LG_VADDR
  --with-jemalloc-prefix=_rjem_
  running: cd "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build" && CC="clang" CFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" CPPFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" LDFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" "sh" "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build/configure" "--disable-cxx" "--enable-doc=no" "--enable-shared=no" "--with-lg-page=14" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=aarch64-apple-ios-sim" "--build=aarch64-apple-darwin" "--prefix=/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out"
  checking for xsltproc... /usr/bin/xsltproc
  checking for aarch64-apple-ios-sim-gcc... clang
  checking whether the C compiler works... yes
  checking for C compiler default output file name... a.out
  checking for suffix of executables... 
  checking whether we are cross compiling... yes
  checking for suffix of object files... o
  checking whether we are using the GNU C compiler... yes
  checking whether clang accepts -g... yes
  checking for clang option to accept ISO C89... none needed
  checking whether compiler is cray... no
  checking whether compiler supports -std=gnu11... yes
  checking whether compiler supports -Werror=unknown-warning-option... yes
  checking whether compiler supports -Wall... yes
  checking whether compiler supports -Wextra... yes
  checking whether compiler supports -Wshorten-64-to-32... yes
  checking whether compiler supports -Wsign-compare... yes
  checking whether compiler supports -Wundef... yes
  checking whether compiler supports -Wno-format-zero-length... yes
  checking whether compiler supports -Wpointer-arith... yes
  checking whether compiler supports -Wno-missing-braces... yes
  checking whether compiler supports -Wno-missing-field-initializers... yes
  checking whether compiler supports -Wno-missing-attributes... no
  checking whether compiler supports -pipe... yes
  checking whether compiler supports -g3... yes
  checking how to run the C preprocessor... clang -E
  checking for grep that handles long lines and -e... /usr/bin/grep
  checking for egrep... /usr/bin/grep -E
  checking for ANSI C header files... yes
  checking for sys/types.h... yes
  checking for sys/stat.h... yes
  checking for stdlib.h... yes
  checking for string.h... yes
  checking for memory.h... yes
  checking for strings.h... yes
  checking for inttypes.h... yes
  checking for stdint.h... yes
  checking for unistd.h... yes
  checking whether byte ordering is bigendian... no
  checking size of void *... 8
  checking size of int... 4
  checking size of long... 8
  checking size of long long... 8
  checking size of intmax_t... 8
  checking build system type... aarch64-apple-darwin
  checking host system type... running: "tail" "-n" "100" "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build/config.log"
  dvidir='${docdir}'
  enable_autogen=''
  enable_cache_oblivious=''
  enable_cxx='0'
  enable_debug=''
  enable_doc='no'
  enable_experimental_smallocx=''
  enable_fill=''
  enable_initial_exec_tls=''
  enable_lazy_lock=''
  enable_log=''
  enable_opt_safety_checks=''
  enable_opt_size_checks=''
  enable_prof=''
  enable_readlinkat=''
  enable_shared='no'
  enable_static=''
  enable_stats=''
  enable_tls=''
  enable_uaf_detection=''
  enable_utrace=''
  enable_xmalloc=''
  enable_zone_allocator=''
  exe=''
  exec_prefix='/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out'
  host='aarch64-apple-ios-sim'
  host_alias='aarch64-apple-ios-sim'
  host_cpu=''
  host_os=''
  host_vendor=''
  htmldir='${docdir}'
  importlib=''
  includedir='${prefix}/include'
  infodir='${datarootdir}/info'
  install_suffix=''
  je_=''
  jemalloc_version=''
  jemalloc_version_bugfix=''
  jemalloc_version_gid=''
  jemalloc_version_major=''
  jemalloc_version_minor=''
  jemalloc_version_nrev=''
  libdir='${exec_prefix}/lib'
  libdl=''
  libexecdir='${exec_prefix}/libexec'
  libprefix=''
  link_whole_archive=''
  localedir='${datarootdir}/locale'
  localstatedir='${prefix}/var'
  mandir='${datarootdir}/man'
  o=''
  objroot=''
  oldincludedir='/usr/include'
  pdfdir='${docdir}'
  prefix='/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out'
  private_namespace=''
  program_transform_name='s,x,x,'
  psdir='${docdir}'
  rev='2'
  sbindir='${exec_prefix}/sbin'
  sharedstatedir='${prefix}/com'
  so=''
  srcroot=''
  sysconfdir='${prefix}/etc'
  target_alias=''

  ## ----------- ##
  ## confdefs.h. ##
  ## ----------- ##

  /* confdefs.h */
  #define PACKAGE_NAME ""
  #define PACKAGE_TARNAME ""
  #define PACKAGE_VERSION ""
  #define PACKAGE_STRING ""
  #define PACKAGE_BUGREPORT ""
  #define PACKAGE_URL ""
  #define JEMALLOC_HAS_RESTRICT
  #define STDC_HEADERS 1
  #define HAVE_SYS_TYPES_H 1
  #define HAVE_SYS_STAT_H 1
  #define HAVE_STDLIB_H 1
  #define HAVE_STRING_H 1
  #define HAVE_MEMORY_H 1
  #define HAVE_STRINGS_H 1
  #define HAVE_INTTYPES_H 1
  #define HAVE_STDINT_H 1
  #define HAVE_UNISTD_H 1
  #define SIZEOF_VOID_P 8
  #define LG_SIZEOF_PTR 3
  #define SIZEOF_INT 4
  #define LG_SIZEOF_INT 2
  #define SIZEOF_LONG 8
  #define LG_SIZEOF_LONG 3
  #define SIZEOF_LONG_LONG 8
  #define LG_SIZEOF_LONG_LONG 3
  #define SIZEOF_INTMAX_T 8
  #define LG_SIZEOF_INTMAX_T 3

  configure: exit 1

  --- stderr
  Invalid configuration `aarch64-apple-ios-sim': Kernel `ios' not known to work with OS `sim'.
  configure: error: /bin/sh build-aux/config.sub aarch64-apple-ios-sim failed
  thread 'main' panicked at 'command did not execute successfully: cd "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build" && CC="clang" CFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" CPPFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" LDFLAGS="-O3 -fPIC --target=arm64-apple-ios7.0-simulator -arch arm64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator17.2.sdk -fembed-bitcode -Wall" "sh" "/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out/build/configure" "--disable-cxx" "--enable-doc=no" "--enable-shared=no" "--with-lg-page=14" "--with-jemalloc-prefix=_rjem_" "--with-private-namespace=_rjem_" "--host=aarch64-apple-ios-sim" "--build=aarch64-apple-darwin" "--prefix=/Users/foodchain/Documents/PSE/mopro-21/mopro-ffi/target/aarch64-apple-ios-sim/release/build/jemalloc-sys-efa822009dbcc843/out"
  expected success, got: exit status: 1', /Users/foodchain/.cargo/registry/src/index.crates.io-6f17d22bba15001f/jemalloc-sys-0.5.4+5.3.0-patched/build.rs:351:9
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make: *** [benchmarks] Error 101

@FoodChain1028 FoodChain1028 changed the title feat: added swift test for msm benchmarking WIP: Feat: added swift test for msm benchmarking Jan 23, 2024
@oskarth
Copy link
Collaborator

oskarth commented Jan 24, 2024

Not quite sure why flag isn't respected when running tests. I mentioned this in DM, but the easiest workaround is probably to hardcode the flag while testing. Did you try this? When I do this I don't get the above error.

diff --git a/mopro-ffi/Cargo.toml b/mopro-ffi/Cargo.toml
index 141c5aa..3a16f7d 100644
--- a/mopro-ffi/Cargo.toml
+++ b/mopro-ffi/Cargo.toml
@@ -14,7 +14,7 @@ name = "uniffi-bindgen"
 path = "uniffi-bindgen.rs"
 
 [features]
-default = []
+default = ["gpu-benchmarks"]
 
 # If we enable them here, they should be enabled in mopro-core as well

@FoodChain1028
Copy link
Collaborator Author

Not quite sure why flag isn't respected when running tests. I mentioned this in DM, but the easiest workaround is probably to hardcode the flag while testing. Did you try this? When I do this I don't get the above error.

diff --git a/mopro-ffi/Cargo.toml b/mopro-ffi/Cargo.toml
index 141c5aa..3a16f7d 100644
--- a/mopro-ffi/Cargo.toml
+++ b/mopro-ffi/Cargo.toml
@@ -14,7 +14,7 @@ name = "uniffi-bindgen"
 path = "uniffi-bindgen.rs"
 
 [features]
-default = []
+default = ["gpu-benchmarks"]
 
 # If we enable them here, they should be enabled in mopro-core as well

Yes, it worked. I will add the content in README.md for people who want to run the test again

making // default=["gpu-benchmarks"] commented and left the original (default=[]) in Cargo.toml.

@@ -1,4 +1,6 @@
uniffi::build_foreign_language_testcases!(
// "tests/bindings/test_mopro_gen_benchmarks_report.swift", // uncomment this to generate the benchmarks report in swift
"tests/bindings/test_mopro_gpu_benchmarks.swift",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can gate this whole block with the feature flag

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you. I added a feature flag for this function. (seems like it is not allow to add a feature flag inside the function parameters)

@oskarth
Copy link
Collaborator

oskarth commented Jan 29, 2024

Btw, seems like previous PR introduced this error when running ./scripts/build_ios.sh simulator release:

   Compiling mopro-core v0.1.0 (/Users/user/repos/github.com/oskarth/mopro/mopro-core)
warning: zkey_file: /Users/user/repos/github.com/oskarth/mopro/mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.zkey
warning: wasm_file: /Users/user/repos/github.com/oskarth/mopro/mopro-core/examples/circom/keccak256/target/keccak256_256_test_js/keccak256_256_test.wasm
warning: arkzkey_file: /Users/user/repos/github.com/oskarth/mopro/mopro-core/examples/circom/keccak256/target/keccak256_256_test_final.arkzkey
error[E0601]: `main` function not found in crate `generate_benchmark_report`
  --> src/middleware/gpu_explorations/bin/generate_benchmark_report.rs:34:2
   |
34 | }
   |  ^ consider adding a `main` function to `src/middleware/gpu_explorations/bin/generate_benchmark_report.rs`

For more information about this error, try `rustc --explain E0601`.

Issue: #61

@moven0831
Copy link
Collaborator

moven0831 commented Jan 29, 2024

I found that the jemalloc/build-aux/config.sub does not have ios-sim, which cause the error. However, in both x86_64-apple-ios and aarch64-apple-ios, jemalloc can be successfully built.

Check the demo branch with jemalloc packages
https://github.com/FoodChain1028/mopro-21/tree/feat/test-in-swift-with-memory/

To reproduce error:

// at mopro/mopro-ffi
cargo build --target aarch64-apple-ios-sim --release --features gpu-benchmarks

To reproduce success compilation:

// at mopro/mopro-ffi
cargo build --target aarch64-apple-ios --release --features gpu-benchmarks

cargo build --target x86_64-apple-ios --release --features gpu-benchmarks

https://github.com/jemalloc/jemalloc/blob/f96010b7fa8ce5f83802144bdebf2bb7a6679649/build-aux/config.sub#L1700

cc @FoodChain1028

@moven0831
Copy link
Collaborator

moven0831 commented Jan 29, 2024

Moreover, the --features gpu-benchmarks only affect tests other than extern crates called in test_generated_bindings.

The tests in mopro-ffi/tests/bindings only take the default features in mopro-ffi/Cargo.toml

With the default = ["gpu-benchmarks"] modified in mopro-ffi/Cargo.toml, you can test the above situation with

Check the demo branch with jemalloc packages
https://github.com/FoodChain1028/mopro-21/tree/feat/test-in-swift-with-memory/

// This two will produce the same result
cargo test --test test_generated_bindings 

cargo test --test test_generated_bindings --features gpu-benchmarks

cc @FoodChain1028

@FoodChain1028 FoodChain1028 changed the title WIP: Feat: added swift test for msm benchmarking feat: added swift test for msm benchmarking Jan 31, 2024
@FoodChain1028 FoodChain1028 marked this pull request as ready for review January 31, 2024 16:05
Copy link
Collaborator

@oskarth oskarth left a comment

Choose a reason for hiding this comment

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

Generally LGTM! Some comments

@@ -14,7 +14,8 @@ name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"

[features]
default = []
# default = []
default = ["gpu-benchmarks"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure we want to keep this on by default, might interfere with other Anon-Aadhaar integration work

Copy link
Collaborator

@moven0831 moven0831 Feb 1, 2024

Choose a reason for hiding this comment

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

Sure, we can keep the default clean and comment on the one with "gpu-benchmarks" feature at this moment.

We found that the external swift and kotlin tests mopro-ffi/tests/bindings only take the default features in mopro-ffi/Cargo.toml. If we can find a way to have the tests in bindings take --feature flags, we will remove the # default = ["gpu-benchmarks"].

// "tests/bindings/test_mopro.py",
"tests/bindings/test_mopro_keccak.swift",
// "tests/bindings/test_mopro_keccak.kts", // FIXME: java.lang.OutOfMemoryError: Java heap space
"tests/bindings/test_mopro_keccak2.swift",
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are all these other stuff? Are you using more than "tests/bindings/test_mopro_gpu_benchmarks.swift",?

Copy link
Collaborator

@moven0831 moven0831 Feb 1, 2024

Choose a reason for hiding this comment

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

I think we can keep these two msm-related test under #[cfg(feature = "gpu-benchmarks")] and other swift tests under #[cfg(not(feature = "gpu-benchmarks"))]. What do you think? @FoodChain1028

#[cfg(feature = "gpu-benchmarks")]
uniffi::build_foreign_language_testcases!(
    "tests/bindings/test_mopro_gen_benchmarks_report.swift",
    "tests/bindings/test_mopro_gpu_benchmarks.swift",
);

#[cfg(not(feature = "gpu-benchmarks"))]
uniffi::build_foreign_language_testcases!(
    // OTHERS
);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll make it like this.

@@ -1,3 +1,21 @@
#[cfg(feature = "gpu-benchmarks")]
uniffi::build_foreign_language_testcases!(
// "tests/bindings/test_mopro_gen_benchmarks_report.swift", // Uncomment to generate benchmarks report, takes nearly 10 minutes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't need to do uncomment if gated by feature flag afaik

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

#56 (comment)

do {
// for tracking the progress
print("Running benchmark with \(each) MSMs...")
let benchData: BenchmarkResult = try runMsmBenchmark(numMsm: each)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So for 10k MSMs it will do all these in Rust and only return results once done, right? Just trying to understand if it is going back and forth between swift and rust or something

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems like the test script is running directly through swift command according to this.

Copy link
Collaborator

@oskarth oskarth left a comment

Choose a reason for hiding this comment

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

LGTM, just minor tweaks

## Generate MSM benchmark report in swift on laptop

* Enable `gpu-benchmarks` feature as default in `Cargo.toml`
* Uncomment the 3rd line in `mopro-ffi/tests/test_generated_bindings.rs` to enable report generation
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is needed any more

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I reckon the first bullet should be kept since the default is now default=[], but I will change the description to better understand the meaning


* Enable `gpu-benchmarks` feature as default in `Cargo.toml`
* Uncomment the 3rd line in `mopro-ffi/tests/test_generated_bindings.rs` to enable report generation
* run `cargo test --test test_generated_bindings --features gpu-benchmarks --release`
Copy link
Collaborator

Choose a reason for hiding this comment

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

New command now right


## Generate MSM benchmark report in swift on laptop

* Enable `gpu-benchmarks` feature as default in `Cargo.toml`
Copy link
Collaborator

Choose a reason for hiding this comment

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

To clarify, after adding feature flag around test_generate_bindings.rs this is still needed? Can't just pass flag as argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, we cannot. The feature flag for now doesn't work though, we can only enable the feature through the deafult flag in Cargo.toml

* Enable `gpu-benchmarks` feature as default in `Cargo.toml`
* Uncomment the 3rd line in `mopro-ffi/tests/test_generated_bindings.rs` to enable report generation
* run `cargo test --test test_generated_bindings --features gpu-benchmarks --release`
* The report would be generated at `mopro-core/benchmarks/gpu_explorations/msm_bench_swift_laptop.csv`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd add link to hackmd report maybe, can also add image easier to see (unless too big)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I just updated the README.md, please have a look, thanks

@@ -389,10 +388,6 @@ mod tests {
"└─ Average msm time: {:.5} ms\n└─ Overall processing time: {:.5} ms",
benchmarks.avg_processing_time, benchmarks.total_processing_time
);
println!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: on L229 num_msm should be _num_msm for lint not to complain

warning: unused variable: `num_msm`
   --> src/lib.rs:229:26
    |
229 | pub fn run_msm_benchmark(num_msm: Option<u32>) -> Result<BenchmarkResult, MoproError> {
    |                          ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_num_msm```
    ```

@oskarth
Copy link
Collaborator

oskarth commented Feb 3, 2024

Rebase on master please and we can merge

default = ["wasmer/dylib"]
dylib = [] # NOTE: can probably remove this if we use env config instead
gpu-benchmarks = ["jemalloc-ctl", "jemallocator"]
default = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

You need to rebase on master, this is not the latest version

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sorry I'll reset and rebase again.

@oskarth oskarth changed the title feat: added swift test for msm benchmarking feat(core,ffi): Add Swift tests for MSM benchmarking Feb 13, 2024
@oskarth oskarth merged commit e1f3f1f into zkmopro:main Feb 13, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants