Skip to content

Commit 2846b98

Browse files
Add custom op examples and documentation (#638)
Added step by step instructions for adding custom op in Qeff --------- Signed-off-by: Rishin Raj <rishinr@qti.qualcomm.com> Co-authored-by: Hem Agnihotri <hemagnih@qti.qualcomm.com>
1 parent 337757c commit 2846b98

File tree

8 files changed

+640
-0
lines changed

8 files changed

+640
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//-----------------------------------------------------------------------------
2+
//
3+
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
// SPDX-License-Identifier: BSD-3-Clause
5+
//
6+
//-----------------------------------------------------------------------------
7+
8+
#include "CustomOpAICInterface.h"
9+
#include "stddef.h"
10+
11+
extern "C" {
12+
13+
/* The AIC compilation target supports an API similar to the Interpreter API.
14+
Additionally, threadId, which is the AIC thread ID, is passed.
15+
Kernel is invoked by four AIC threads with threadId equal to 0, 1, 2, and 3. */
16+
17+
void CustomGELUAIC(
18+
const CustomOpContext *ctx,
19+
const int32_t threadId)
20+
{
21+
}
22+
23+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
//-----------------------------------------------------------------------------
2+
//
3+
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
// SPDX-License-Identifier: BSD-3-Clause
5+
//
6+
//-----------------------------------------------------------------------------
7+
8+
#include "CustomOpFunctions.h"
9+
#include "CustomOpInterpreterInterface.h"
10+
#include "CustomOpTileConfigHelpers.h"
11+
#include "CustomOpTypes.h"
12+
13+
#include <string.h>
14+
15+
extern "C" {
16+
bool customOpVerify(
17+
const CustomOpPropertiesHandle *const opProp)
18+
{
19+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
20+
21+
return true;
22+
}
23+
24+
const char * customOpSelectImpl(
25+
const CustomOpPropertiesHandle *const opProp,
26+
const CustomOpKernelInfo *const kernelInfos,
27+
const int32_t numKernels,
28+
const char *backend)
29+
{
30+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
31+
32+
/* For AIC pick '<OpName>AIC', for Interpreter pick '<OpName>Interpreter' */
33+
if (strcmp(backend, "AIC") == 0)
34+
{
35+
return "";
36+
}
37+
else if (strcmp(backend, "Interpreter") == 0)
38+
{
39+
return "";
40+
}
41+
return nullptr;
42+
}
43+
44+
bool customOpInferShape(
45+
CustomOpPropertiesHandle *const opProp)
46+
{
47+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
48+
49+
return false;
50+
}
51+
52+
bool customOpSetProperties(
53+
CustomOpPropertiesHandle *opProp)
54+
{
55+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
56+
57+
return false;
58+
}
59+
60+
bool customOpMapTiles(
61+
CustomOpPropertiesHandle *opProp)
62+
{
63+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
64+
65+
return false;
66+
}
67+
void customOpDeallocateMemory(
68+
CustomOpPropertiesHandle *opProp)
69+
{
70+
/* Refer to function declaration at CustomOpFunctions.h for usage. */
71+
72+
CustomOpTileConfigHelpers::destroyTileConfigsAndMergeConfigs(opProp);
73+
}
74+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//-----------------------------------------------------------------------------
2+
//
3+
// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
4+
// SPDX-License-Identifier: BSD-3-Clause
5+
//
6+
//-----------------------------------------------------------------------------
7+
8+
/*
9+
* This file can be compiled separately and can be loaded using dlopen
10+
* Compilation command: (tried with gcc 5.5)
11+
* g++ -shared -std=c++11 -fPIC -o <opName>_lib.so <opName_functions>.cpp <opName_interpreter>.cpp -I/opt/qti-aic/dev/inc
12+
* for example: g++ -shared -std=c++11 -fPIC -o reluop_lib.so reluop_functions.cpp reluop_interpreter.cpp -I/opt/qti-aic/dev/inc
13+
*/
14+
15+
#include "CustomOpInterpreterInterface.h"
16+
17+
extern "C" {
18+
void CustomGELUInterpreter(
19+
CustomOpContext *ctx)
20+
{
21+
/* The interpreter implementation is provided to the compiler as a shared library
22+
(or collection of shared libraries). Each shared library can contain multiple
23+
versions (flavors) of implementations of the operation, refered onwards as kernels.
24+
A kernel is selected at model compilation time by the selection function. The
25+
developer is responsible for compilation of these shared libraries. As the interface
26+
is C, the shared libraries can be compiled by various compilers (GCC, CLANG, etc).
27+
In addition, as these shared libraries are running on the Host CPU, the developer
28+
can open files, dump results, use stdout/stderr for printing debug messages, etc.
29+
This makes the Interpreter implementation a very effective way for debugging the
30+
operation functionality as part of model execution. The signature of the
31+
kernel (implementation) is generic, and fits any custom operation. */
32+
}
33+
}
Binary file not shown.

0 commit comments

Comments
 (0)