Skip to content

Commit

Permalink
feat(ios): added basic UI in MSM Benchmark (#71)
Browse files Browse the repository at this point in the history
* feat(ios): added basic UI in MSM Benchmark

# Conflicts:
#	mopro-ios/MoproKit/Example/MoproKit/ViewController.swift

* feat: remove redundant part and update function mapping

* feat(msm benchmark): finalize display content in iOS

* feat(msm benchmark): add percentage difference comparison logic of baseline

* update(gpu-benchmark): document added

* docs: added todo for future work

---------

Co-authored-by: moven0831 <[email protected]>
  • Loading branch information
FoodChain1028 and moven0831 authored Feb 22, 2024
1 parent cd18595 commit a9376db
Show file tree
Hide file tree
Showing 6 changed files with 364 additions and 11 deletions.
2 changes: 2 additions & 0 deletions mopro-core/src/middleware/gpu_explorations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub struct BenchmarkResult {
pub total_processing_time: f64,
}

// TODO: refactor fn name and add more benchmarks in the future
fn single_msm() -> Result<(), Box<dyn Error>> {
let mut rng = ark_std::test_rng();

Expand All @@ -27,6 +28,7 @@ fn single_msm() -> Result<(), Box<dyn Error>> {
Ok(())
}

// TODO: figure out a way to configure the algorithm fn used
// Run the msm benchmark with timing
pub fn run_msm_benchmark(num_msm: Option<u32>) -> Result<BenchmarkResult, Box<dyn Error>> {
let num_msm = num_msm.unwrap_or(1000); // default to 1000 msm operations
Expand Down
12 changes: 2 additions & 10 deletions mopro-ios/MoproKit/Bindings/mopro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,13 @@ public struct BenchmarkResult {
public var numMsm: UInt32
public var avgProcessingTime: Double
public var totalProcessingTime: Double
public var allocatedMemory: UInt32

// Default memberwise initializers are never public by default, so we
// declare one manually.
public init(numMsm: UInt32, avgProcessingTime: Double, totalProcessingTime: Double, allocatedMemory: UInt32) {
public init(numMsm: UInt32, avgProcessingTime: Double, totalProcessingTime: Double) {
self.numMsm = numMsm
self.avgProcessingTime = avgProcessingTime
self.totalProcessingTime = totalProcessingTime
self.allocatedMemory = allocatedMemory
}
}

Expand All @@ -533,17 +531,13 @@ extension BenchmarkResult: Equatable, Hashable {
if lhs.totalProcessingTime != rhs.totalProcessingTime {
return false
}
if lhs.allocatedMemory != rhs.allocatedMemory {
return false
}
return true
}

public func hash(into hasher: inout Hasher) {
hasher.combine(numMsm)
hasher.combine(avgProcessingTime)
hasher.combine(totalProcessingTime)
hasher.combine(allocatedMemory)
}
}

Expand All @@ -553,16 +547,14 @@ public struct FfiConverterTypeBenchmarkResult: FfiConverterRustBuffer {
return try BenchmarkResult(
numMsm: FfiConverterUInt32.read(from: &buf),
avgProcessingTime: FfiConverterDouble.read(from: &buf),
totalProcessingTime: FfiConverterDouble.read(from: &buf),
allocatedMemory: FfiConverterUInt32.read(from: &buf)
totalProcessingTime: FfiConverterDouble.read(from: &buf)
)
}

public static func write(_ value: BenchmarkResult, into buf: inout [UInt8]) {
FfiConverterUInt32.write(value.numMsm, into: &buf)
FfiConverterDouble.write(value.avgProcessingTime, into: &buf)
FfiConverterDouble.write(value.totalProcessingTime, into: &buf)
FfiConverterUInt32.write(value.allocatedMemory, into: &buf)
}
}

Expand Down
4 changes: 4 additions & 0 deletions mopro-ios/MoproKit/Example/MoproKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
1ECF32642B728A6F00482C55 /* MSMBenchmarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF32632B728A6F00482C55 /* MSMBenchmarkViewController.swift */; };
2A418AB02AF4B1200004B747 /* CircomUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A418AAF2AF4B1200004B747 /* CircomUITests.swift */; };
2A6E5BAF2AF499460052A601 /* CircomTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2A6E5BAE2AF499460052A601 /* CircomTests.swift */; };
4384FD09A96F702A375841EE /* Pods_MoproKit_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 78B0F9CBE5DD22576996A993 /* Pods_MoproKit_Tests.framework */; };
Expand Down Expand Up @@ -46,6 +47,7 @@

/* Begin PBXFileReference section */
1E5E014D70B48C9A59F14658 /* Pods-MoproKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MoproKit_Example.release.xcconfig"; path = "Target Support Files/Pods-MoproKit_Example/Pods-MoproKit_Example.release.xcconfig"; sourceTree = "<group>"; };
1ECF32632B728A6F00482C55 /* MSMBenchmarkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MSMBenchmarkViewController.swift; sourceTree = "<group>"; };
2A418AAF2AF4B1200004B747 /* CircomUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomUITests.swift; sourceTree = "<group>"; };
2A6E5BAE2AF499460052A601 /* CircomTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircomTests.swift; sourceTree = "<group>"; };
47F8ADB0AC4168C6E874818D /* MoproKit.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = MoproKit.podspec; path = ../MoproKit.podspec; sourceTree = "<group>"; };
Expand Down Expand Up @@ -131,6 +133,7 @@
607FACD21AFB9204008FA782 /* Example for MoproKit */ = {
isa = PBXGroup;
children = (
1ECF32632B728A6F00482C55 /* MSMBenchmarkViewController.swift */,
CEB804572AFF81BF0063F091 /* RSAViewController.swift */,
E6E6F42D2B5860F7002F5F18 /* AnonAadhaarViewControllerNew.swift */,
E69338632AFFDB1A00B80312 /* AnonAadhaarViewController.swift */,
Expand Down Expand Up @@ -416,6 +419,7 @@
CEB804582AFF81BF0063F091 /* RSAViewController.swift in Sources */,
CEB804562AFF81AF0063F091 /* KeccakZkeyViewController.swift in Sources */,
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
1ECF32642B728A6F00482C55 /* MSMBenchmarkViewController.swift in Sources */,
CEB804502AFF81960063F091 /* KeccakSetupViewController.swift in Sources */,
E6D848592B766C8C00DBAF30 /* ComplexZkeyViewController.swift in Sources */,
E6E6F42E2B5860F7002F5F18 /* AnonAadhaarViewControllerNew.swift in Sources */,
Expand Down
Loading

0 comments on commit a9376db

Please sign in to comment.