Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into snnn/up_header
Browse files Browse the repository at this point in the history
  • Loading branch information
snnn committed Jan 21, 2025
2 parents 63a74ce + c7f764c commit 63b7236
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 215 deletions.
7 changes: 1 addition & 6 deletions cmake/external/onnxruntime_external_deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,7 @@ if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto)
add_library(onnx_proto ALIAS ONNX::onnx_proto)
endif()

find_package(Eigen3 CONFIG)
if(Eigen3_FOUND)
get_target_property(eigen_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES)
else()
include(eigen) # FetchContent
endif()
include(external/eigen.cmake)

if(onnxruntime_USE_VCPKG)
find_package(wil CONFIG REQUIRED)
Expand Down
37 changes: 27 additions & 10 deletions onnxruntime/core/providers/qnn/builder/qnn_backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ void QnnLogging(const char* format,
ORT_UNUSED_PARAMETER(level);
ORT_UNUSED_PARAMETER(timestamp);

if (!::onnxruntime::logging::LoggingManager::HasDefaultLogger()) {
// QNN may call this logging callback at any point, which means that we need to explicitly check
// that the default logger has been initialized before trying to use it (otherwise get segfault).
return;
}

const auto& logger = ::onnxruntime::logging::LoggingManager::DefaultLogger();
const auto severity = ::onnxruntime::logging::Severity::kVERBOSE;
const auto data_type = ::onnxruntime::logging::DataType::SYSTEM;
Expand All @@ -273,6 +279,9 @@ Status QnnBackendManager::InitializeQnnLog(const logging::Logger& logger) {
QnnLog_Level_t qnn_log_level = MapOrtSeverityToQNNLogLevel(ort_log_level);
LOGS(*logger_, VERBOSE) << "Set Qnn log level: " << qnn_log_level;

// NOTE: Even if logCreate() fails and QNN does not return a valid log_handle_, QNN may still
// call the QnnLogging() callback. So, we have to make sure that QnnLogging() can handle calls
// in which ORT logging is not available.
Qnn_ErrorHandle_t result = qnn_interface_.logCreate(QnnLogging, qnn_log_level, &log_handle_);

if (result != QNN_SUCCESS) {
Expand Down Expand Up @@ -879,6 +888,10 @@ Status QnnBackendManager::SetupBackend(const logging::Logger& logger,
}

Status QnnBackendManager::CreateHtpPowerCfgId(uint32_t device_id, uint32_t core_id, uint32_t& htp_power_config_id) {
// This function is called in QNN EP's OnRunStart() even if QNN backend setup failed and the model is assigned
// to a different EP. Therefore, we have to check that backend setup actually completed before trying to
// create an HTP power config ID. Otherwise, this causes a segfault because the QNN backend lib is unloaded.
ORT_RETURN_IF_NOT(backend_setup_completed_, "Cannot create HTP power config ID if backend setup is not complete.");
QnnDevice_Infrastructure_t qnn_device_infra = nullptr;
auto status = qnn_interface_.deviceGetInfrastructure(&qnn_device_infra);
ORT_RETURN_IF(QNN_SUCCESS != status, "backendGetPerfInfrastructure failed.");
Expand All @@ -896,6 +909,10 @@ Status QnnBackendManager::CreateHtpPowerCfgId(uint32_t device_id, uint32_t core_

Status QnnBackendManager::SetHtpPowerConfig(uint32_t htp_power_config_client_id,
HtpPerformanceMode htp_performance_mode) {
// This function is called in QNN EP's OnRunStart() even if QNN backend setup failed and the model is assigned
// to a different EP. Therefore, we have to check that backend setup actually completed before trying to
// set an HTP power config ID. Otherwise, this causes a segfault because the QNN backend lib is unloaded.
ORT_RETURN_IF_NOT(backend_setup_completed_, "Cannot set HTP power config ID if backend setup is not complete.");
QnnDevice_Infrastructure_t qnn_device_infra = nullptr;
auto status = qnn_interface_.deviceGetInfrastructure(&qnn_device_infra);
ORT_RETURN_IF(QNN_SUCCESS != status, "backendGetPerfInfrastructure failed.");
Expand Down Expand Up @@ -1037,6 +1054,10 @@ Status QnnBackendManager::SetHtpPowerConfig(uint32_t htp_power_config_client_id,

Status QnnBackendManager::SetRpcControlLatency(uint32_t htp_power_config_client_id,
uint32_t rpc_control_latency) {
// This function is called in QNN EP's OnRunStart() even if QNN backend setup failed and the model is assigned
// to a different EP. Therefore, we have to check that backend setup actually completed before trying to
// set RPC control latency. Otherwise, this causes a segfault because the QNN backend library is unloaded.
ORT_RETURN_IF_NOT(backend_setup_completed_, "Cannot set HTP RPC control latency if backend setup is not complete.");
if (rpc_control_latency != 0) {
QnnDevice_Infrastructure_t qnn_device_infra = nullptr;
auto status = qnn_interface_.deviceGetInfrastructure(&qnn_device_infra);
Expand Down Expand Up @@ -1099,39 +1120,35 @@ Status QnnBackendManager::TerminateQnnLog() {
}

void QnnBackendManager::ReleaseResources() {
if (!backend_setup_completed_) {
return;
}

auto result = ReleaseContext();
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to ReleaseContext.";
LOGS_DEFAULT(ERROR) << "Failed to ReleaseContext: " << result.ErrorMessage();
}

result = ReleaseProfilehandle();
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to ReleaseProfilehandle.";
LOGS_DEFAULT(ERROR) << "Failed to ReleaseProfilehandle: " << result.ErrorMessage();
}

result = ReleaseDevice();
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to ReleaseDevice.";
LOGS_DEFAULT(ERROR) << "Failed to ReleaseDevice: " << result.ErrorMessage();
}

result = ShutdownBackend();
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to ShutdownBackend.";
LOGS_DEFAULT(ERROR) << "Failed to ShutdownBackend: " << result.ErrorMessage();
}

result = TerminateQnnLog();
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to TerminateQnnLog.";
LOGS_DEFAULT(ERROR) << "Failed to TerminateQnnLog: " << result.ErrorMessage();
}

if (backend_lib_handle_) {
result = UnloadLib(backend_lib_handle_);
if (Status::OK() != result) {
LOGS_DEFAULT(ERROR) << "Failed to unload backend library.";
LOGS_DEFAULT(ERROR) << "Failed to unload backend library: " << result.ErrorMessage();
}
}

Expand Down
2 changes: 1 addition & 1 deletion requirements-lintrunner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ lintrunner-adapters==0.12.4
# RUFF
ruff==0.9.1
# CLANGFORMAT
clang-format==19.1.6
clang-format==19.1.7
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
parameters:
- name: PackageName
displayName: 'Package name'
type: string
default: 'NPM_packages'

- name: ArtifactName
type: string
default: 'onnxruntime-android-full-aar'

- name: NpmPackagingMode
displayName: 'NPM packages publish configuration'
type: string
default: 'dev'

jobs:
- job: ReactNative_CI_Android
pool: 'onnxruntime-Ubuntu2204-AMD-CPU'
variables:
runCodesignValidationInjection: false
timeoutInMinutes: 90
steps:
- task: UsePythonVersion@0
displayName: Use python 3.12
inputs:
versionSpec: "3.12"
addToPath: true
architecture: "x64"

- task: JavaToolInstaller@0
displayName: Use jdk 17
inputs:
versionSpec: '17'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'

- task: NodeTool@0
inputs:
versionSpec: '20.x'

- script: |
sudo apt install coreutils ninja-build nodejs npm yarn
npm install --global yarn
displayName: Install coreutils, ninja, npm, and yarn
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: '${{parameters.ArtifactName}}'
targetPath: '$(Build.BinariesDirectory)/android-full-aar'
displayName: Download Android AAR artifacts

- task: CopyFiles@2
inputs:
sourceFolder: $(Build.BinariesDirectory)/android-full-aar
contents: onnxruntime-android-*.aar
targetFolder: $(Build.SourcesDirectory)/js/react_native/android/libs
displayName: Copy Android package to React Native directory

- script: |
npm ci
workingDirectory: '$(Build.SourcesDirectory)/js'
displayName: npm ci js
- script: |
npm ci
workingDirectory: '$(Build.SourcesDirectory)/js/common'
displayName: npm ci js/common
- script: |
yarn
workingDirectory: '$(Build.SourcesDirectory)/js/react_native'
displayName: yarn js/react_native
- task: PowerShell@2
inputs:
filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1'
arguments: '"-dev.$(Get-Date -Format yyyyMMdd)-$(git rev-parse --short HEAD)" $(Build.SourcesDirectory) react_native'
workingDirectory: '$(Build.SourcesDirectory)'
errorActionPreference: stop
env:
ORT_JS_PACK_MODE: e2e
displayName: Pack NPM packages

- script: |
mv $(Build.SourcesDirectory)/js/common/onnxruntime-common*.tgz onnxruntime-common.tgz
yarn add --no-lockfile file:./onnxruntime-common.tgz
mv $(Build.SourcesDirectory)/js/react_native/onnxruntime-react-native*.tgz onnxruntime-react-native.tgz
yarn add --no-lockfile file:./onnxruntime-react-native.tgz
yarn
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e'
displayName: Bootstrap Android and iOS e2e tests
- script: |
yarn add --dev jest-junit
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e'
displayName: install jest junit reporter js/react_native/e2e
- script: |
keytool -genkey -v -keystore debug.keystore -alias androiddebugkey -storepass android \
-keypass android -keyalg RSA -keysize 2048 -validity 999999 -dname "CN=Android Debug,O=Android,C=US"
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e/android'
displayName: Generate a debug keystore
- task: CopyFiles@2
inputs:
sourceFolder: $(Build.BinariesDirectory)/android-full-aar
contents: onnxruntime-*.aar
targetFolder: $(Build.SourcesDirectory)/js/react_native/e2e/android/app/libs
displayName: Copy Android package to Android e2e test directory

- script: |
yarn global add detox-cli
echo "Path: $PATH"
echo "##vso[task.prependpath]$(yarn global bin)"
echo "Updated PATH: $PATH"
echo "Detox bin directory: $(yarn global bin)"
ls $(yarn global bin)
displayName: Install detox cli tools and prepend to PATH
- script: |
detox build --configuration android.emu.release
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e'
displayName: Build React Native Detox Android e2e Tests
#
# Unit tests and E2E tests with Android emulator
#
- template: ../../templates/use-android-emulator.yml
parameters:
create: true
start: true

- template: ../../templates/android-dump-logs-from-steps.yml
parameters:
steps:
- task: Gradle@3
inputs:
gradleWrapperFile: '$(Build.SourcesDirectory)/js/react_native/android/gradlew'
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/android'
options: '--stacktrace'
tasks: 'connectedDebugAndroidTest'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
testRunTitle: 'React Native Android Instrumented Test results'
sonarQubeRunAnalysis: false
spotBugsAnalysis: false
displayName: Run React Native Android Instrumented Tests

- script: |
JEST_JUNIT_OUTPUT_FILE=$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml \
detox test --record-logs all \
--configuration android.emu.release \
--loglevel trace \
--take-screenshots failing
workingDirectory: '$(Build.SourcesDirectory)/js/react_native/e2e'
displayName: Run React Native Detox Android e2e Tests
- template: ../../templates/use-android-emulator.yml
parameters:
stop: true

- task: PublishTestResults@2
inputs:
testResultsFiles: '$(Build.SourcesDirectory)/js/react_native/e2e/android-test-results.xml'
failTaskOnFailedTests: true
testRunTitle: 'React Native Detox Android e2e Test Results'
condition: succeededOrFailed()
displayName: Publish React Native Detox Android e2e Test Results

- script: |
git restore .
workingDirectory: '$(Build.SourcesDirectory)/js'
displayName: Restore git changes
- task: PowerShell@2
inputs:
filePath: '$(Build.SourcesDirectory)/tools/ci_build/github/js/pack-npm-packages.ps1'
arguments: '"${{parameters.NpmPackagingMode}}" $(Build.SourcesDirectory) react_native'
workingDirectory: '$(Build.SourcesDirectory)'
errorActionPreference: stop
displayName: Pack NPM packages

- task: CopyFiles@2
inputs:
sourceFolder: $(Build.SourcesDirectory)/js/common
contents: onnxruntime-common*.tgz
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: 'Create Artifacts onnxruntime-common'

- task: CopyFiles@2
inputs:
sourceFolder: $(Build.SourcesDirectory)/js/react_native
contents: onnxruntime-react-native*.tgz
targetFolder: $(Build.ArtifactStagingDirectory)
displayName: Create Artifacts onnxruntime-react-native

- task: PublishPipelineArtifact@1
inputs:
artifact: android_e2e_test_logs_$(Build.BuildId)_$(Build.BuildNumber)_$(System.JobAttempt)
targetPath: '$(Build.SourcesDirectory)/js/react_native/e2e/artifacts'
condition: succeededOrFailed()
displayName: Publish React Native Detox E2E test logs

- task: PublishPipelineArtifact@0
inputs:
artifactName: '${{parameters.PackageName}}'
targetPath: '$(Build.ArtifactStagingDirectory)'
displayName: Publish Pipeline Artifact

- template: ../../templates/explicitly-defined-final-tasks.yml
Loading

0 comments on commit 63b7236

Please sign in to comment.