Skip to content

Commit

Permalink
Refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
quic-zhanweiw committed Feb 10, 2025
1 parent 8bd4ea8 commit fe7a8e1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions script/qai_appbuilder/qnncontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ 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 @@ -268,10 +269,10 @@ def __del__(self):
if hasattr(self, "m_memory") and self.m_memory is not None:
del(self.m_memory)
m_memory = None



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

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

1 change: 1 addition & 0 deletions src/LibAppBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ bool ModelInitializeEx(const std::string& model_name, const std::string& proc_na
const std::string& backend_lib_path, const std::string& system_lib_path,
const std::vector<LoraAdapter>& lora_adapters) {
bool result = false;

QNN_INF("LibAppBuilder::ModelInitialize: %s \n", model_name.c_str());

#ifdef _WIN32
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<LoraAdapter>& 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
25 changes: 14 additions & 11 deletions src/SVC/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ int svcprocess_run(HANDLE hSvcPipeInRead, HANDLE hSvcPipeOutWrite) {

char* cmdBuf = g_buffer + 1;
switch (g_buffer[0]) {
case 'l': // load model.
ModelLoad(cmdBuf, hSvcPipeOutWrite);
break;
case 'l': // load model.
ModelLoad(cmdBuf, hSvcPipeOutWrite);
break;

case 'g': // run Graphs.
ModelRun(cmdBuf, hSvcPipeOutWrite);
break;
case 'g': // run Graphs.
ModelRun(cmdBuf, hSvcPipeOutWrite);
break;

case 'r': // release model.
ModelRelease(cmdBuf, hSvcPipeOutWrite);
break;
case 'r': // release model.
ModelRelease(cmdBuf, hSvcPipeOutWrite);
break;
}
}

Expand All @@ -212,7 +212,7 @@ int svcprocess_run(HANDLE hSvcPipeInRead, HANDLE hSvcPipeOutWrite) {
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 <LoraAdapter>& Adapters ) {
BOOL result = false;
BOOL result = false;

std::string MODEL_NAME = "<model_name>";
std::string PROC_NAME = "<proc_name>";
Expand Down Expand Up @@ -284,6 +284,7 @@ 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 @@ -420,7 +421,8 @@ int main(int argc, char** argv) {
--model_path <str:model_path> --perf_profile <str:perf_profile> --input_path <str:input_raw_path>
--input_count <int:input_count> --memory_size<int:memory_size>
--binary_updates<str:graph_name,binary_update_path_1;binary_update_path_2>
input files are under 'input_raw_path' and the file names format are 'input_%d.raw'. */
input files are under 'input_raw_path' and the file names format are 'input_%d.raw'.
*/

try {
// Parse command-line arguments
Expand Down Expand Up @@ -482,3 +484,4 @@ int main(int argc, char** argv) {

return 0;
}

0 comments on commit fe7a8e1

Please sign in to comment.