-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] add benchmarking page. (#142)
* feat: added benchmarking MVP
- Loading branch information
1 parent
cbe06d6
commit f8dcd16
Showing
62 changed files
with
3,878 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
APP_RELEASE_STORE_PASSWORD= | ||
APP_RELEASE_KEY_PASSWORD= | ||
FIREBASE_FUNCTIONS_URL= | ||
|
||
# Debug tokens (only for local development) | ||
APPCHECK_DEBUG_TOKEN_ANDROID= | ||
APPCHECK_DEBUG_TOKEN_IOS= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mockAppCheck = { | ||
newReactNativeFirebaseAppCheckProvider: jest.fn().mockReturnValue({ | ||
configure: jest.fn(), | ||
}), | ||
initializeAppCheck: jest.fn(), | ||
getToken: jest.fn().mockResolvedValue({token: 'mock-token'}), | ||
}; | ||
|
||
export default () => ({ | ||
appCheck: () => mockAppCheck, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const mockFirebase = { | ||
appCheck: jest.fn().mockReturnValue({ | ||
newReactNativeFirebaseAppCheckProvider: jest.fn().mockReturnValue({ | ||
configure: jest.fn(), | ||
}), | ||
initializeAppCheck: jest.fn(), | ||
getToken: jest.fn().mockResolvedValue({token: 'mock-token'}), | ||
}), | ||
}; | ||
|
||
export default mockFirebase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {BenchmarkResult} from '../../src/utils/types'; | ||
import {mockResult} from '../../jest/fixtures/benchmark'; | ||
|
||
// Create mock functions | ||
const mockRemoveResult = jest.fn((timestamp: string) => { | ||
benchmarkStore.results = benchmarkStore.results.filter( | ||
result => result.timestamp !== timestamp, | ||
); | ||
}); | ||
|
||
const mockClearResults = jest.fn(() => { | ||
benchmarkStore.results = []; | ||
}); | ||
|
||
const mockAddResult = jest.fn((result: BenchmarkResult) => { | ||
benchmarkStore.results.unshift(result); | ||
}); | ||
|
||
const mockMarkAsSubmitted = jest.fn((uuid: string) => { | ||
const result = benchmarkStore.results.find(r => r.uuid === uuid); | ||
if (result) { | ||
result.submitted = true; | ||
} | ||
}); | ||
|
||
const mockGetResultsByModel = jest.fn((modelId: string): BenchmarkResult[] => { | ||
return benchmarkStore.results.filter(result => result.modelId === modelId); | ||
}); | ||
|
||
// Define the mockBenchmarkStore | ||
export const benchmarkStore = { | ||
results: [mockResult], | ||
addResult: mockAddResult, | ||
removeResult: mockRemoveResult, | ||
clearResults: mockClearResults, | ||
markAsSubmitted: mockMarkAsSubmitted, | ||
getResultsByModel: mockGetResultsByModel, | ||
latestResult: mockResult, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
android/app/src/main/java/com/pocketpalai/DeviceInfoModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.pocketpal | ||
|
||
import com.facebook.react.bridge.* | ||
import android.os.Build | ||
import java.io.File | ||
|
||
class DeviceInfoModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { | ||
|
||
override fun getName(): String = "DeviceInfoModule" | ||
|
||
@ReactMethod | ||
fun getChipset(promise: Promise) { | ||
try { | ||
val chipset = Build.HARDWARE.takeUnless { it.isNullOrEmpty() } ?: Build.BOARD | ||
promise.resolve(chipset) | ||
} catch (e: Exception) { | ||
promise.reject("ERROR", e.message) | ||
} | ||
} | ||
|
||
@ReactMethod | ||
fun getCPUInfo(promise: Promise) { | ||
try { | ||
val cpuInfo = Arguments.createMap() | ||
cpuInfo.putInt("cores", Runtime.getRuntime().availableProcessors()) | ||
|
||
val processors = Arguments.createArray() | ||
val features = mutableSetOf<String>() | ||
val cpuInfoFile = File("/proc/cpuinfo") | ||
|
||
if (cpuInfoFile.exists()) { | ||
val cpuInfoLines = cpuInfoFile.readLines() | ||
var currentProcessor = Arguments.createMap() | ||
var hasData = false | ||
|
||
for (line in cpuInfoLines) { | ||
if (line.isEmpty() && hasData) { | ||
processors.pushMap(currentProcessor) | ||
currentProcessor = Arguments.createMap() | ||
hasData = false | ||
continue | ||
} | ||
|
||
val parts = line.split(":") | ||
if (parts.size >= 2) { | ||
val key = parts[0].trim() | ||
val value = parts[1].trim() | ||
when (key) { | ||
"processor", "model name", "cpu MHz", "vendor_id" -> { | ||
currentProcessor.putString(key, value) | ||
hasData = true | ||
} | ||
"flags", "Features" -> { // "flags" for x86, "Features" for ARM | ||
features.addAll(value.split(" ").filter { it.isNotEmpty() }) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (hasData) { | ||
processors.pushMap(currentProcessor) | ||
} | ||
|
||
cpuInfo.putArray("processors", processors) | ||
|
||
// Convert features set to array | ||
val featuresArray = Arguments.createArray() | ||
features.forEach { featuresArray.pushString(it) } | ||
cpuInfo.putArray("features", featuresArray) | ||
|
||
// ML-related CPU features detection | ||
cpuInfo.putBoolean("hasFp16", features.any { it in setOf("fphp", "fp16") }) | ||
cpuInfo.putBoolean("hasDotProd", features.any { it in setOf("dotprod", "asimddp") }) | ||
cpuInfo.putBoolean("hasSve", features.any { it == "sve" }) | ||
cpuInfo.putBoolean("hasI8mm", features.any { it == "i8mm" }) | ||
} | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
cpuInfo.putString("socModel", Build.SOC_MODEL) | ||
} | ||
|
||
promise.resolve(cpuInfo) | ||
} catch (e: Exception) { | ||
promise.reject("ERROR", e.message) | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
android/app/src/main/java/com/pocketpalai/DeviceInfoPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.pocketpal | ||
|
||
import android.view.View | ||
import com.facebook.react.ReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.uimanager.ReactShadowNode | ||
import com.facebook.react.uimanager.ViewManager | ||
|
||
class DeviceInfoPackage : ReactPackage { | ||
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> { | ||
return listOf(DeviceInfoModule(reactContext)) | ||
} | ||
|
||
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<View, ReactShadowNode<*>>> { | ||
return emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
module.exports = { | ||
presets: ['module:@react-native/babel-preset'], | ||
plugins: ['react-native-reanimated/plugin'], | ||
plugins: [ | ||
'react-native-reanimated/plugin', | ||
['module:react-native-dotenv', {moduleName: '@env'}], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module '@env' { | ||
export const FIREBASE_FUNCTIONS_URL: string; | ||
export const APPCHECK_DEBUG_TOKEN_ANDROID: string; | ||
export const APPCHECK_DEBUG_TOKEN_IOS: string; | ||
} |
Oops, something went wrong.