-
Notifications
You must be signed in to change notification settings - Fork 61
Add custom op examples and documentation #638
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1298d8e
Add custom op examples and documentation
quic-rishinr 914a53c
Added .so file
quic-rishinr 0ae3d06
Lint and format
quic-rishinr 1c1fdef
Added header files for cpp files
quic-rishinr 90c4b1d
Added code comment
quic-rishinr 14bbf50
Merge branch 'main' into custom_op
quic-hemagnih File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
examples/onboarding_guide/customop/CustomGELU/src/customgelu_aic.cpp
This file contains hidden or 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,23 @@ | ||
| //----------------------------------------------------------------------------- | ||
| // | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| #include "CustomOpAICInterface.h" | ||
| #include "stddef.h" | ||
|
|
||
| extern "C" { | ||
|
|
||
| /* The AIC compilation target supports an API similar to the Interpreter API. | ||
| Additionally, threadId, which is the AIC thread ID, is passed. | ||
| Kernel is invoked by four AIC threads with threadId equal to 0, 1, 2, and 3. */ | ||
|
|
||
| void CustomGELUAIC( | ||
| const CustomOpContext *ctx, | ||
| const int32_t threadId) | ||
| { | ||
| } | ||
|
|
||
| } | ||
74 changes: 74 additions & 0 deletions
74
examples/onboarding_guide/customop/CustomGELU/src/customgelu_functions.cpp
This file contains hidden or 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,74 @@ | ||
| //----------------------------------------------------------------------------- | ||
| // | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| #include "CustomOpFunctions.h" | ||
| #include "CustomOpInterpreterInterface.h" | ||
| #include "CustomOpTileConfigHelpers.h" | ||
| #include "CustomOpTypes.h" | ||
|
|
||
| #include <string.h> | ||
|
|
||
| extern "C" { | ||
| bool customOpVerify( | ||
| const CustomOpPropertiesHandle *const opProp) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| const char * customOpSelectImpl( | ||
| const CustomOpPropertiesHandle *const opProp, | ||
| const CustomOpKernelInfo *const kernelInfos, | ||
| const int32_t numKernels, | ||
| const char *backend) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| /* For AIC pick '<OpName>AIC', for Interpreter pick '<OpName>Interpreter' */ | ||
| if (strcmp(backend, "AIC") == 0) | ||
quic-rishinr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return ""; | ||
| } | ||
| else if (strcmp(backend, "Interpreter") == 0) | ||
| { | ||
| return ""; | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| bool customOpInferShape( | ||
| CustomOpPropertiesHandle *const opProp) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool customOpSetProperties( | ||
| CustomOpPropertiesHandle *opProp) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| bool customOpMapTiles( | ||
| CustomOpPropertiesHandle *opProp) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| return false; | ||
| } | ||
| void customOpDeallocateMemory( | ||
| CustomOpPropertiesHandle *opProp) | ||
| { | ||
| /* Refer to function declaration at CustomOpFunctions.h for usage. */ | ||
|
|
||
| CustomOpTileConfigHelpers::destroyTileConfigsAndMergeConfigs(opProp); | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
examples/onboarding_guide/customop/CustomGELU/src/customgelu_interpreter.cpp
This file contains hidden or 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,33 @@ | ||
| //----------------------------------------------------------------------------- | ||
| // | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| /* | ||
| * This file can be compiled separately and can be loaded using dlopen | ||
| * Compilation command: (tried with gcc 5.5) | ||
| * g++ -shared -std=c++11 -fPIC -o <opName>_lib.so <opName_functions>.cpp <opName_interpreter>.cpp -I/opt/qti-aic/dev/inc | ||
| * for example: g++ -shared -std=c++11 -fPIC -o reluop_lib.so reluop_functions.cpp reluop_interpreter.cpp -I/opt/qti-aic/dev/inc | ||
| */ | ||
|
|
||
| #include "CustomOpInterpreterInterface.h" | ||
|
|
||
| extern "C" { | ||
| void CustomGELUInterpreter( | ||
| CustomOpContext *ctx) | ||
| { | ||
| /* The interpreter implementation is provided to the compiler as a shared library | ||
| (or collection of shared libraries). Each shared library can contain multiple | ||
| versions (flavors) of implementations of the operation, refered onwards as kernels. | ||
| A kernel is selected at model compilation time by the selection function. The | ||
| developer is responsible for compilation of these shared libraries. As the interface | ||
| is C, the shared libraries can be compiled by various compilers (GCC, CLANG, etc). | ||
| In addition, as these shared libraries are running on the Host CPU, the developer | ||
| can open files, dump results, use stdout/stderr for printing debug messages, etc. | ||
| This makes the Interpreter implementation a very effective way for debugging the | ||
| operation functionality as part of model execution. The signature of the | ||
| kernel (implementation) is generic, and fits any custom operation. */ | ||
| } | ||
| } |
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please double check the copyrights, I could see the following copyrights used in CPP files.
Can you please check this once from Jeff.
//-----------------------------------------------------------------------------
//
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
// Confidential and Proprietary - Qualcomm Technologies, Inc. and/or its subsidiaries.
//
//-----------------------------------------------------------------------------