Skip to content

Commit

Permalink
Add license header to new files, Format the C++ files
Browse files Browse the repository at this point in the history
Signed-off-by: Ashwath Jadhav <[email protected]>
  • Loading branch information
Ashwath Jadhav authored and quic-zhanweiw committed Feb 10, 2025
1 parent 0f4c55c commit 8bd4ea8
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 44 deletions.
7 changes: 3 additions & 4 deletions pybind/AppBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ QNNContext::QNNContext(const std::string& model_name, const std::string& proc_na

QNNContext::QNNContext(const std::string& model_name,
const std::string& model_path, const std::string& backend_lib_path,
const std::string& system_lib_path, const std::vector<LoraAdaptor>& lora_adapters) {
const std::string& system_lib_path, const std::vector<LoraAdapter>& lora_adapters) {

m_model_name = model_name;
m_lora_adapters = lora_adapters;
Expand Down Expand Up @@ -112,13 +112,12 @@ PYBIND11_MODULE(appbuilder, m) {

py::class_<QNNContext>(m, "QNNContext")
.def(py::init<const std::string&, const std::string&, const std::string&, const std::string&>())
.def(py::init<const std::string&, const std::string&, const std::string&, const std::string&, const std::vector<LoraAdaptor>&>())
.def(py::init<const std::string&, const std::string&, const std::string&, const std::string&, const std::vector<LoraAdapter>&>())
.def(py::init<const std::string&, const std::string&, const std::string&, const std::string&, const std::string&>())
.def("Inference", py::overload_cast<const std::vector<py::array_t<float>>&, const std::string&>(&QNNContext::Inference))
.def("Inference", py::overload_cast<const ShareMemory&, const std::vector<py::array_t<float>>&, const std::string&>(&QNNContext::Inference));

py::class_<LoraAdaptor>(m, "LoraAdaptor")
py::class_<LoraAdapter>(m, "LoraAdapter")
.def(py::init<const std::string &, const std::vector<std::string> &>());

}

4 changes: 2 additions & 2 deletions pybind/AppBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ class QNNContext {
public:
std::string m_model_name;
std::string m_proc_name;
std::vector<LoraAdaptor> m_lora_adapters;
std::vector<LoraAdapter> m_lora_adapters;

QNNContext(const std::string& model_name,
const std::string& model_path, const std::string& backend_lib_path,
const std::string& system_lib_path);

QNNContext(const std::string& model_name,
const std::string& model_path, const std::string& backend_lib_path,
const std::string& system_lib_path, const std::vector<LoraAdaptor>& lora_adapters);
const std::string& system_lib_path, const std::vector<LoraAdapter>& lora_adapters);

QNNContext(const std::string& model_name, const std::string& proc_name,
const std::string& model_path, const std::string& backend_lib_path,
Expand Down
5 changes: 2 additions & 3 deletions script/qai_appbuilder/qnncontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ def __del__(self):
del(self.m_context)
m_context = None


class QNNShareMemory:
"""High-level Python wrapper for a AppBuilder model."""
def __init__(self,
Expand All @@ -270,9 +269,9 @@ def __del__(self):
del(self.m_memory)
m_memory = None

class LoraAdaptor: # this will just hold data
class LoraAdapter: # this will just hold data
m_adapter = None

def __init__(self, graph_name, lora_file_paths):
self.m_adapter = appbuilder.LoraAdaptor(graph_name, lora_file_paths) # cpp object
self.m_adapter = appbuilder.LoraAdapter(graph_name, lora_file_paths) # cpp object

12 changes: 6 additions & 6 deletions src/LibAppBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ std::unique_ptr<sample_app::QnnSampleApp> initQnnSampleApp(std::string cachedBin
std::string backEndPath,
std::string systemLibraryPath,
bool loadFromCachedBinary,
const std::vector<LoraAdaptor>& lora_adapters) {
const std::vector<LoraAdapter>& lora_adapters) {
// Just keep blank for below paths.
std::string modelPath;
std::string cachedBinaryPath2;
Expand Down Expand Up @@ -288,7 +288,7 @@ bool DeleteShareMemory(std::string share_memory_name) {

bool ModelInitializeEx(const std::string& model_name, const std::string& proc_name, const std::string& model_path,
const std::string& backend_lib_path, const std::string& system_lib_path,
const std::vector<LoraAdaptor>& lora_adapters) {
const std::vector<LoraAdapter>& lora_adapters) {
bool result = false;
QNN_INF("LibAppBuilder::ModelInitialize: %s \n", model_name.c_str());

Expand Down Expand Up @@ -392,7 +392,7 @@ bool ModelInitializeEx(const std::string& model_name, const std::string& proc_na
}
}

// apply lora adaptor on graph
// apply lora Adapter on graph
if (app->binaryUpdates() &&
sample_app::StatusCode::SUCCESS != app->contextApplyBinarySection(QNN_CONTEXT_SECTION_UPDATABLE)) {
return app->reportError("Binary update/execution failure");
Expand Down Expand Up @@ -518,12 +518,12 @@ bool LibAppBuilder::ModelInitialize(const std::string& model_name, const std::st

bool LibAppBuilder::ModelInitialize(const std::string& model_name, const std::string& model_path,
const std::string& backend_lib_path, const std::string& system_lib_path) {
std::vector<LoraAdaptor> adaptors = std::vector<LoraAdaptor>();
return ModelInitializeEx(model_name, "", model_path, backend_lib_path, system_lib_path, adaptors);
std::vector<LoraAdapter> Adapters = std::vector<LoraAdapter>();
return ModelInitializeEx(model_name, "", model_path, backend_lib_path, system_lib_path, Adapters);
}

bool LibAppBuilder::ModelInitialize(const std::string& model_name, const std::string& model_path,
const std::string& backend_lib_path, const std::string& system_lib_path,const std::vector<LoraAdaptor>& lora_adapters) {
const std::string& backend_lib_path, const std::string& system_lib_path,const std::vector<LoraAdapter>& lora_adapters) {
return ModelInitializeEx(model_name, "", model_path, backend_lib_path, system_lib_path, lora_adapters);
}

Expand Down
2 changes: 1 addition & 1 deletion src/LibAppBuilder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LIBAPPBUILDER_API LibAppBuilder
const std::string& backend_lib_path, const std::string& system_lib_path);

bool ModelInitialize(const std::string& model_name, const std::string& model_path,
const std::string& backend_lib_path, const std::string& system_lib_path, const std::vector<LoraAdaptor>& lora_adapters);
const std::string& backend_lib_path, const std::string& system_lib_path, const std::vector<LoraAdapter>& lora_adapters);

bool ModelInference(std::string model_name, std::vector<uint8_t*>& inputBuffers,
std::vector<uint8_t*>& outputBuffers, std::vector<size_t>& outputSize,
Expand Down
12 changes: 10 additions & 2 deletions src/Lora.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
//==============================================================================
//
// Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
//
//==============================================================================

#pragma once

#include <string>
#include <vector>
#include "Lora.hpp"

LoraAdaptor::LoraAdaptor(const std::string &graph_name, const std::vector<std::string> &bin_paths) {
LoraAdapter::LoraAdapter(const std::string &graph_name, const std::vector<std::string> &bin_paths) {
m_graph_name = graph_name;
m_bin_paths = bin_paths;
}

LoraAdaptor::~LoraAdaptor(){
LoraAdapter::~LoraAdapter(){
}
14 changes: 11 additions & 3 deletions src/Lora.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//==============================================================================
//
// Copyright (c) 2025, Qualcomm Innovation Center, Inc. All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
//
//==============================================================================

#pragma once

#include <string>
Expand All @@ -14,12 +22,12 @@
#endif


class LIBAPPBUILDER_API LoraAdaptor{
class LIBAPPBUILDER_API LoraAdapter{
public:
std::string m_graph_name;
std::vector<std::string> m_bin_paths;

LoraAdaptor(const std::string &graph_name, const std::vector<std::string> &bin_paths);
LoraAdapter(const std::string &graph_name, const std::vector<std::string> &bin_paths);

~LoraAdaptor();
~LoraAdapter();
};
8 changes: 5 additions & 3 deletions src/QnnSampleApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ sample_app::QnnSampleApp::QnnSampleApp(QnnFunctionPointers qnnFunctionPointers,
bool dumpOutputs,
std::string cachedBinaryPath,
std::string saveBinaryName,
const std::vector<LoraAdaptor>& lora_adapters)
const std::vector<LoraAdapter>& lora_adapters)
: m_qnnFunctionPointers(qnnFunctionPointers),
m_outputPath(outputPath),
m_saveBinaryName(saveBinaryName),
Expand Down Expand Up @@ -677,8 +677,10 @@ sample_app::StatusCode sample_app::QnnSampleApp::initializeProfileHandle(
return StatusCode::SUCCESS;
}

bool sample_app::QnnSampleApp::binaryUpdates() {
return m_lora_adapters.size() > 0; }
bool sample_app::QnnSampleApp::binaryUpdates() {
return m_lora_adapters.size() > 0;
}


sample_app::StatusCode sample_app::QnnSampleApp::initializeProfileConfigOption(
const QNN_INTERFACE_VER_TYPE* qnnInterfaceHandle,
Expand Down
5 changes: 2 additions & 3 deletions src/QnnSampleApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class QnnSampleApp {
bool dumpOutputs = false,
std::string cachedBinaryPath = "",
std::string saveBinaryName = "",
const std::vector<LoraAdaptor>& lora_adapters = std::vector<LoraAdaptor>());
const std::vector<LoraAdapter>& lora_adapters = std::vector<LoraAdapter>());

// @brief Print a message to STDERR then return a nonzero
// exit status.
Expand Down Expand Up @@ -103,7 +103,7 @@ class QnnSampleApp {
StatusCode contextApplyBinarySection(QnnContext_SectionType_t section);
bool binaryUpdates();

const std::vector<LoraAdaptor>& m_lora_adapters = {};
const std::vector<LoraAdapter>& m_lora_adapters = {};

StatusCode applyBinarySection(
std::string graphName,
Expand Down Expand Up @@ -133,7 +133,6 @@ class QnnSampleApp {
StatusCode addGraphToContext(
qnn_wrapper_api::GraphInfo_t* graphInfo);


StatusCode freeDevice();

StatusCode verifyFailReturnStatus(Qnn_ErrorHandle_t errCode);
Expand Down
31 changes: 15 additions & 16 deletions src/SVC/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ void ModelLoad(std::string cmdBuf, HANDLE hSvcPipeOutWrite) {
std::vector<std::string> commands;
split_string(commands, cmdBuf, ';');

std::string model_name = commands[0];
std::string model_path = commands[1];
std::string backend_lib_path = commands[2];
std::string system_lib_path = commands[3];
std::string model_name = commands[0];
std::string model_path = commands[1];
std::string backend_lib_path = commands[2];
std::string system_lib_path = commands[3];

Print_MemInfo("ModelLoad::ModelInitialize Start.");
QNN_INF("ModelLoad::ModelInitialize::Model name %s\n", model_name.c_str());
std::vector<LoraAdaptor> adaptors ;
bSuccess = g_LibAppBuilder.ModelInitialize(model_name.c_str(), model_path, backend_lib_path, system_lib_path, adaptors);
std::vector<LoraAdapter> Adapters ;
bSuccess = g_LibAppBuilder.ModelInitialize(model_name.c_str(), model_path, backend_lib_path, system_lib_path, Adapters);
QNN_INF("ModelLoad::ModelInitialize End ret = %d\n", bSuccess);
Print_MemInfo("ModelLoad::ModelInitialize End.");

if (bSuccess) {
if(bSuccess) {
bSuccess = WriteFile(hSvcPipeOutWrite, ACTION_OK, (DWORD)strlen(ACTION_OK) + 1, NULL, NULL);
}
else {
Expand Down Expand Up @@ -210,9 +210,9 @@ int svcprocess_run(HANDLE hSvcPipeInRead, HANDLE hSvcPipeOutWrite) {

// test code, load and run model.
int hostprocess_run(std::string qnn_lib_path, std::string model_path,
std::string input_raw_path, int input_count, int memory_size,
std::string perf_profile, const std::vector <LoraAdaptor>& adaptors ) {
BOOL result = false;
std::string input_raw_path, int input_count, int memory_size,
std::string perf_profile, const std::vector <LoraAdapter>& Adapters ) {
BOOL result = false;

std::string MODEL_NAME = "<model_name>";
std::string PROC_NAME = "<proc_name>";
Expand Down Expand Up @@ -263,7 +263,7 @@ int hostprocess_run(std::string qnn_lib_path, std::string model_path,

if (0 == memory_size) { // Load & run model locally.
QNN_INF("Load and run model locally Start.\n");
result = libAppBuilder.ModelInitialize(model_name, model_path, backend_lib_path, system_lib_path, adaptors);
result = libAppBuilder.ModelInitialize(model_name, model_path, backend_lib_path, system_lib_path, Adapters);
Print_MemInfo("ModelInitialize End.");

// SetPerfProfileGlobal("burst");
Expand All @@ -284,7 +284,6 @@ int hostprocess_run(std::string qnn_lib_path, std::string model_path,
}
os.close();
}

for (int i = 0; i < outputBuffers.size(); i++) {
free(outputBuffers[i]);
}
Expand Down Expand Up @@ -456,16 +455,16 @@ int main(int argc, char** argv) {
}

// Creating list of adapters
std::vector<LoraAdaptor> adaptors;
std::vector<LoraAdapter> Adapters;
for (const auto& update : binary_updates) {
std::string graph_name = update.first;
std::vector<std::string> bin_path = update.second;
LoraAdaptor adaptor(graph_name, bin_path);
adaptors.push_back(adaptor);
LoraAdapter Adapter(graph_name, bin_path);
Adapters.push_back(Adapter);
}


hostprocess_run(qnn_lib_path, model_path, input_list_path, input_count, memory_size, perf_profile, adaptors);
hostprocess_run(qnn_lib_path, model_path, input_list_path, input_count, memory_size, perf_profile, Adapters);

}
catch (const std::exception& e) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/QnnSampleAppUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace qnn {
namespace tools {
namespace sample_app {

enum class ProfilingLevel { OFF, BASIC, DETAILED, INVALID, CLIENT};
enum class ProfilingLevel { OFF, BASIC, DETAILED, INVALID, CLIENT };
enum class ProfilingOption { NONE, OPTRACE, INVALID };

using ReadInputListRetType_t = std::
Expand Down

0 comments on commit 8bd4ea8

Please sign in to comment.