Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add QNN Op package #1 #2840

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ option('enable-avx', type: 'boolean', value: true)
option('enable-opencl', type: 'boolean', value: false)
option('enable-biqgemm', type: 'boolean', value: false)
option('enable-benchmarks', type: 'boolean', value : false)
option('enable-qnn', type: 'boolean', value: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about setting the default value of enable-qnn as false?


# ml-api dependency (to enable, install capi-inference from github.com/nnstreamer/api )
# To inter-operate with nnstreamer and ML-API packages, you need to enable this.
Expand All @@ -57,3 +58,4 @@ option('nnstreamer-subplugin-install-path', type: 'string', value: '/usr/lib/nns

# application related options
option('enable_encoder', type: 'boolean', value: false)

5 changes: 5 additions & 0 deletions nntrainer/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ if get_option('enable-opencl')
nntrainer_elements += 'layers/cl_layers'
endif

if get_option('enable-qnn')
message ('QNN build is enabled. Will work only if Qualcomm NPU is available.')
nntrainer_elements += 'npu'
endif

foreach elem : nntrainer_elements
subdir(elem)
nntrainer_inc += include_directories(elem)
Expand Down
1 change: 1 addition & 0 deletions nntrainer/npu/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
subdir('qnn')
21 changes: 21 additions & 0 deletions nntrainer/npu/qnn/PAL/include/PAL/Debug.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//============================================================================
//
// Copyright (c) 2020-2022 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//============================================================================

#pragma once

#define DEBUG_ON 0

#if DEBUG_ON
#define DEBUG_MSG(...) \
{ \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
}
#else
#define DEBUG_MSG(...)
#endif
81 changes: 81 additions & 0 deletions nntrainer/npu/qnn/PAL/include/PAL/Directory.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//==============================================================================
//
// Copyright (c) 2008-2014, 2020-2022 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================

//---------------------------------------------------------------------------
/// @file
/// This file includes APIs for directory operations on supported platforms
//---------------------------------------------------------------------------

#pragma once

#include <string>

#include "PAL/FileOp.hpp"

namespace pal {
class Directory;
}

class pal::Directory {
public:
using DirMode = pal::FileOp::FileMode;
//---------------------------------------------------------------------------
/// @brief
/// Creates a directory in the file system.
/// @param path
/// Name of directory to create.
/// @param dirmode
/// Directory mode
/// @return
/// True if
/// 1. create a directory successfully
/// 2. or directory exist already
/// False otherwise
///
/// For example:
///
/// - Create a directory in default.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// pal::Directory::Create(path, pal::Directory::DirMode::S_DEFAULT_);
/// pal::Directory::Create(path);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// - Create a directory with specific permission.
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// pal::Directory::Create(path, pal::Directory::DirMode::S_IRWXU_|
/// pal::Directory::DirMode::S_IRWXG_|
/// pal::Directory::DirMode::S_IRWXO_);
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
///
/// @note For windows, dirmode is not used.
/// @note For linux, dirmode is used to set the permission of the folder.
//---------------------------------------------------------------------------
static bool
create(const std::string &path,
pal::Directory::DirMode dirmode = pal::Directory::DirMode::S_DEFAULT_);

//---------------------------------------------------------------------------
/// @brief
/// Removes the entire directory whether it's empty or not.
/// @param path
/// Name of directory to delete.
/// @return
/// True if the directory was successfully deleted, false otherwise.
//---------------------------------------------------------------------------
static bool remove(const std::string &path);

//---------------------------------------------------------------------------
/// @brief
/// Creates a directory and all parent directories required.
/// @param path
/// Path of directory to create.
/// @return
/// True if the directory was successfully created, false otherwise.
//---------------------------------------------------------------------------
static bool makePath(const std::string &path);
};
101 changes: 101 additions & 0 deletions nntrainer/npu/qnn/PAL/include/PAL/DynamicLoading.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//==============================================================================
//
// Copyright (c) 2020-2022 Qualcomm Technologies, Inc.
// All Rights Reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc.
//
//==============================================================================

//---------------------------------------------------------------------------
/// @file
/// This file includes APIs for dynamic loading on supported platforms
//---------------------------------------------------------------------------

#pragma once

#include <string>

namespace pal {
namespace dynamicloading {
// we only support subset of POSIX of dlopen/dlsym/dladdr/dlerror/dlclose
// except the following flags for dlopen, others should be done only
// when we really need them
// DL_NOW is MUST
// DL_LOCAL is enabled if not specified
enum {
DL_NOW = 0x0001,
DL_LOCAL = 0x0002,
DL_GLOBAL = 0x0004,
};

// specify this address to distingiush from NULL pointer
#define DL_DEFAULT (void *)(0x4)

//---------------------------------------------------------------------------
/// @brief
/// Loads the dynamic shared object
/// @param filename
/// If contains path separators, treat it as relative or absolute pathname
/// or search it for the rule of dynamic linker
/// @param flags
/// - DL_NOW: resolve undefined symbols before return. MUST be specified.
/// - DL_LOCAL: optional, but the default specified. Symbols defined in this
/// shared object are not made available to resolve references in
/// subsequently loaded shared objects
/// - DL_GLOBAL: optional, resolve symbol globally
/// @return
/// On success, a non-NULL handle for the loaded library.
/// On error, NULL
//---------------------------------------------------------------------------
void *dlOpen(const char *filename, int flags);

//---------------------------------------------------------------------------
/// @brief
/// Obtain address of a symbol in a shared object or executable
/// @param handle
/// A handle of a dynamic loaded shared object returned by dlopen
/// @param symbol
/// A null-terminated symbol name
/// @return
/// On success, return the address associated with symbol
/// On error, NULL
//---------------------------------------------------------------------------
void *dlSym(void *handle, const char *symbol);

//---------------------------------------------------------------------------
/// @brief
/// Translate the address of a symbol to the path of the belonging shared
/// object
/// @param addr
/// Address of symbol in a shared object
/// @param path
/// Full name of shared object that contains address, usually it is an
/// absolute path
/// @return
/// On success, return a non-zero value
/// On error, return 0
//---------------------------------------------------------------------------
int dlAddrToLibName(void *addr, std::string &name);

//---------------------------------------------------------------------------
/// @brief
/// Decrements the reference count on the dynamically loaded shared object
/// referred to by handle. If the reference count drops to 0, then the
/// object is unloaded.
/// @return
/// On success, 0; on error, a nonzero value
//---------------------------------------------------------------------------
int dlClose(void *handle);

//---------------------------------------------------------------------------
/// @brief
/// Obtain error diagnostic for functions in the dl-family APIs.
/// @return
/// Returns a human-readable, null-terminated string describing the most
/// recent error that occurred from a call to one of the functions in the
/// dl-family APIs.
//---------------------------------------------------------------------------
char *dlError(void);

} // namespace dynamicloading
} // namespace pal
Loading
Loading