Zhu-FaceOnLive
commited on
Commit
•
2ded60b
1
Parent(s):
1accf5d
Initial commit.
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +14 -0
- Dockerfile +19 -0
- app.py +115 -0
- facewrapper/dict/data1.bin +3 -0
- facewrapper/dict/data2.bin +3 -0
- facewrapper/dict/data3.bin +3 -0
- facewrapper/facewrapper.py +31 -0
- facewrapper/libs/libimutils.so +0 -0
- facewrapper/libs/libimutils.so_for_ubuntu22 +0 -0
- facewrapper/libs/libttvfaceengine7.so +3 -0
- gradio/demo.py +32 -0
- gradio/examples/1.jpg +0 -0
- gradio/examples/2.jpg +0 -0
- gradio/examples/3.jpg +0 -0
- gradio/examples/4.jpg +0 -0
- openvino/cache.json +0 -0
- openvino/libgna.so +3 -0
- openvino/libgna.so.2 +3 -0
- openvino/libgna.so.3.0.0.1455 +3 -0
- openvino/libopenvino.so +3 -0
- openvino/libopenvino_auto_batch_plugin.so +0 -0
- openvino/libopenvino_auto_plugin.so +0 -0
- openvino/libopenvino_c.so +0 -0
- openvino/libopenvino_gapi_preproc.so +3 -0
- openvino/libopenvino_hetero_plugin.so +0 -0
- openvino/libopenvino_intel_cpu_plugin.so +3 -0
- openvino/libopenvino_intel_gna_plugin.so +3 -0
- openvino/libopenvino_intel_hddl_plugin.so +3 -0
- openvino/libopenvino_intel_myriad_plugin.so +3 -0
- openvino/libopenvino_ir_frontend.so +0 -0
- openvino/libopenvino_onnx_frontend.so +3 -0
- openvino/libopenvino_paddle_frontend.so +0 -0
- openvino/libopenvino_tensorflow_fe.so +3 -0
- openvino/pcie-ma2x8x.mvcmd +3 -0
- openvino/plugins.xml +27 -0
- openvino/usb-ma2x8x.mvcmd +3 -0
- openvino/vpu_custom_kernels/binarization.bin +3 -0
- openvino/vpu_custom_kernels/binarization.cl +67 -0
- openvino/vpu_custom_kernels/binary_convolution.bin +3 -0
- openvino/vpu_custom_kernels/binary_convolution.cl +95 -0
- openvino/vpu_custom_kernels/binary_convolution1x1.bin +3 -0
- openvino/vpu_custom_kernels/binary_convolution1x1.cl +117 -0
- openvino/vpu_custom_kernels/binary_convolution3x3.bin +3 -0
- openvino/vpu_custom_kernels/binary_convolution3x3.cl +278 -0
- openvino/vpu_custom_kernels/convolution1x1_chw.bin +3 -0
- openvino/vpu_custom_kernels/convolution1x1_chw.cl +114 -0
- openvino/vpu_custom_kernels/convolution1x1_hwc.bin +3 -0
- openvino/vpu_custom_kernels/convolution1x1_hwc.cl +126 -0
- openvino/vpu_custom_kernels/convolution3x3.bin +3 -0
- openvino/vpu_custom_kernels/convolution3x3.cl +158 -0
.gitattributes
CHANGED
@@ -33,3 +33,17 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
facewrapper/libs/libttvfaceengine7.so filter=lfs diff=lfs merge=lfs -text
|
37 |
+
openvino/libgna.so filter=lfs diff=lfs merge=lfs -text
|
38 |
+
openvino/libgna.so.2 filter=lfs diff=lfs merge=lfs -text
|
39 |
+
openvino/libgna.so.3.0.0.1455 filter=lfs diff=lfs merge=lfs -text
|
40 |
+
openvino/libopenvino_gapi_preproc.so filter=lfs diff=lfs merge=lfs -text
|
41 |
+
openvino/libopenvino_intel_cpu_plugin.so filter=lfs diff=lfs merge=lfs -text
|
42 |
+
openvino/libopenvino_intel_gna_plugin.so filter=lfs diff=lfs merge=lfs -text
|
43 |
+
openvino/libopenvino_intel_hddl_plugin.so filter=lfs diff=lfs merge=lfs -text
|
44 |
+
openvino/libopenvino_intel_myriad_plugin.so filter=lfs diff=lfs merge=lfs -text
|
45 |
+
openvino/libopenvino_onnx_frontend.so filter=lfs diff=lfs merge=lfs -text
|
46 |
+
openvino/libopenvino_tensorflow_fe.so filter=lfs diff=lfs merge=lfs -text
|
47 |
+
openvino/libopenvino.so filter=lfs diff=lfs merge=lfs -text
|
48 |
+
openvino/pcie-ma2x8x.mvcmd filter=lfs diff=lfs merge=lfs -text
|
49 |
+
openvino/usb-ma2x8x.mvcmd filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ubuntu:20.04
|
2 |
+
RUN ln -snf /usr/share/zoneinfo/$CONTAINER_TIMEZONE /etc/localtime && echo $CONTAINER_TIMEZONE > /etc/timezone
|
3 |
+
RUN apt-get update -y
|
4 |
+
RUN apt-get install -y python3 python3-pip python3-opencv
|
5 |
+
RUN apt-get install -y libcurl4-openssl-dev libssl-dev
|
6 |
+
RUN mkdir -p /home/FaceOnLive_v7
|
7 |
+
RUN mkdir -p /home/FaceOnLive_v7/facewrapper
|
8 |
+
WORKDIR /home/FaceOnLive_v7
|
9 |
+
COPY ./facewrapper ./facewrapper
|
10 |
+
COPY ./facewrapper/libs/libimutils.so /usr/lib
|
11 |
+
COPY ./gradio ./gradio
|
12 |
+
COPY ./openvino /usr/lib
|
13 |
+
COPY ./app.py ./app.py
|
14 |
+
COPY ./run.sh .
|
15 |
+
COPY ./requirements.txt ./requirements.txt
|
16 |
+
RUN pip3 install -r requirements.txt
|
17 |
+
RUN chmod a+x run.sh
|
18 |
+
CMD ["./run.sh"]
|
19 |
+
EXPOSE 9000
|
app.py
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
sys.path.append('.')
|
3 |
+
|
4 |
+
from flask import Flask, request, jsonify
|
5 |
+
from time import gmtime, strftime
|
6 |
+
import os
|
7 |
+
import base64
|
8 |
+
import json
|
9 |
+
import cv2
|
10 |
+
import numpy as np
|
11 |
+
|
12 |
+
from facewrapper.facewrapper import ttv_version
|
13 |
+
from facewrapper.facewrapper import ttv_get_hwid
|
14 |
+
from facewrapper.facewrapper import ttv_init
|
15 |
+
from facewrapper.facewrapper import ttv_init_offline
|
16 |
+
from facewrapper.facewrapper import ttv_detect_face
|
17 |
+
|
18 |
+
app = Flask(__name__)
|
19 |
+
|
20 |
+
app.config['SITE'] = "http://0.0.0.0:8000/"
|
21 |
+
app.config['DEBUG'] = False
|
22 |
+
|
23 |
+
licenseKey = os.environ.get("LICENSE_KEY")
|
24 |
+
licensePath = "license.txt"
|
25 |
+
modelFolder = os.path.abspath(os.path.dirname(__file__)) + '/facewrapper/dict'
|
26 |
+
|
27 |
+
version = ttv_version()
|
28 |
+
print("version: ", version.decode('utf-8'))
|
29 |
+
|
30 |
+
ret = ttv_init(modelFolder.encode('utf-8'), licenseKey.encode('utf-8'))
|
31 |
+
if ret != 0:
|
32 |
+
print(f"online init failed: {ret}");
|
33 |
+
|
34 |
+
hwid = ttv_get_hwid()
|
35 |
+
print("hwid: ", hwid.decode('utf-8'))
|
36 |
+
|
37 |
+
ret = ttv_init_offline(modelFolder.encode('utf-8'), licensePath.encode('utf-8'))
|
38 |
+
if ret != 0:
|
39 |
+
print(f"offline init failed: {ret}")
|
40 |
+
exit(-1)
|
41 |
+
else:
|
42 |
+
print(f"offline init ok")
|
43 |
+
|
44 |
+
else:
|
45 |
+
print(f"online init ok")
|
46 |
+
|
47 |
+
@app.route('/api/liveness', methods=['POST'])
|
48 |
+
def check_liveness():
|
49 |
+
file = request.files['image']
|
50 |
+
image = cv2.imdecode(np.fromstring(file.read(), np.uint8), cv2.IMREAD_COLOR)
|
51 |
+
|
52 |
+
faceRect = np.zeros([4], dtype=np.int32)
|
53 |
+
livenessScore = np.zeros([1], dtype=np.double)
|
54 |
+
angles = np.zeros([3], dtype=np.double)
|
55 |
+
ret = ttv_detect_face(image, image.shape[1], image.shape[0], faceRect, livenessScore, angles)
|
56 |
+
if ret == -1:
|
57 |
+
result = "license error!"
|
58 |
+
elif ret == -2:
|
59 |
+
result = "init error!"
|
60 |
+
elif ret == 0:
|
61 |
+
result = "no face detected!"
|
62 |
+
elif ret > 1:
|
63 |
+
result = "multiple face detected!"
|
64 |
+
elif faceRect[0] < 0 or faceRect[1] < 0 or faceRect[2] >= image.shape[1] or faceRect[2] >= image.shape[0]:
|
65 |
+
result = "faace is in boundary!"
|
66 |
+
elif livenessScore[0] > 0.5:
|
67 |
+
result = "genuine"
|
68 |
+
else:
|
69 |
+
result = "spoof"
|
70 |
+
|
71 |
+
status = "ok"
|
72 |
+
response = jsonify({"status": status, "data": {"result": result, "face_rect": {"x": int(faceRect[0]), "y": int(faceRect[1]), "w": int(faceRect[2] - faceRect[0] + 1), "h" : int(faceRect[3] - faceRect[1] + 1)}, "liveness_score": livenessScore[0],
|
73 |
+
"angles": {"yaw": angles[0], "roll": angles[1], "pitch": angles[2]}}})
|
74 |
+
|
75 |
+
response.status_code = 200
|
76 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
77 |
+
return response
|
78 |
+
|
79 |
+
@app.route('/api/liveness_base64', methods=['POST'])
|
80 |
+
def check_liveness_base64():
|
81 |
+
content = request.get_json()
|
82 |
+
imageBase64 = content['image']
|
83 |
+
image = cv2.imdecode(np.frombuffer(base64.b64decode(imageBase64), dtype=np.uint8), cv2.IMREAD_COLOR)
|
84 |
+
|
85 |
+
faceRect = np.zeros([4], dtype=np.int32)
|
86 |
+
livenessScore = np.zeros([1], dtype=np.double)
|
87 |
+
angles = np.zeros([3], dtype=np.double)
|
88 |
+
ret = ttv_detect_face(image, image.shape[1], image.shape[0], faceRect, livenessScore, angles)
|
89 |
+
if ret == -1:
|
90 |
+
result = "license error!"
|
91 |
+
elif ret == -2:
|
92 |
+
result = "init error!"
|
93 |
+
elif ret == 0:
|
94 |
+
result = "no face detected!"
|
95 |
+
elif ret > 1:
|
96 |
+
result = "multiple face detected!"
|
97 |
+
elif faceRect[0] < 0 or faceRect[1] < 0 or faceRect[2] >= image.shape[1] or faceRect[2] >= image.shape[0]:
|
98 |
+
result = "faace is in boundary!"
|
99 |
+
elif livenessScore[0] > 0.5:
|
100 |
+
result = "genuine"
|
101 |
+
else:
|
102 |
+
result = "spoof"
|
103 |
+
|
104 |
+
status = "ok"
|
105 |
+
response = jsonify({"status": status, "data": {"result": result, "face_rect": {"x": int(faceRect[0]), "y": int(faceRect[1]), "w": int(faceRect[2] - faceRect[0] + 1), "h" : int(faceRect[3] - faceRect[1] + 1)}, "liveness_score": livenessScore[0],
|
106 |
+
"angles": {"yaw": angles[0], "roll": angles[1], "pitch": angles[2]}}})
|
107 |
+
|
108 |
+
response.status_code = 200
|
109 |
+
response.headers["Content-Type"] = "application/json; charset=utf-8"
|
110 |
+
return response
|
111 |
+
|
112 |
+
|
113 |
+
if __name__ == '__main__':
|
114 |
+
port = int(os.environ.get("PORT", 8000))
|
115 |
+
app.run(host='0.0.0.0', port=port)
|
facewrapper/dict/data1.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:36cf5fcc49345989a86839a53529314ec1fe5d621c377a1952bc7538d55e7f1b
|
3 |
+
size 16255630
|
facewrapper/dict/data2.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6fa65c4b7df14f0c96c174868a1b1c675adc8c4a11e3c0807009f3d0cad51f5a
|
3 |
+
size 280076956
|
facewrapper/dict/data3.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f25fb0cd3d70cb84c258e7109620f411c087e0875828d6ab86cc9c4838d49bec
|
3 |
+
size 11875339
|
facewrapper/facewrapper.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import ctypes, ctypes.util
|
2 |
+
from ctypes import *
|
3 |
+
from numpy.ctypeslib import ndpointer
|
4 |
+
import sys
|
5 |
+
import os
|
6 |
+
sys.path.append('/opt/intel/openvino_2022/runtime/lib/intel64')
|
7 |
+
|
8 |
+
lib_path = os.path.abspath(os.path.dirname(__file__)) + '/libs/libttvfaceengine7.so'
|
9 |
+
liveness_engine = cdll.LoadLibrary(lib_path)
|
10 |
+
|
11 |
+
ttv_version = liveness_engine.ttv_version
|
12 |
+
ttv_version.argtypes = []
|
13 |
+
ttv_version.restype = ctypes.c_char_p
|
14 |
+
|
15 |
+
ttv_get_hwid = liveness_engine.ttv_get_hwid
|
16 |
+
ttv_get_hwid.argtypes = []
|
17 |
+
ttv_get_hwid.restype = ctypes.c_char_p
|
18 |
+
|
19 |
+
ttv_init = liveness_engine.ttv_init
|
20 |
+
ttv_init.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
|
21 |
+
ttv_init.restype = ctypes.c_int32
|
22 |
+
|
23 |
+
ttv_init_offline = liveness_engine.ttv_init_offline
|
24 |
+
ttv_init_offline.argtypes = [ctypes.c_char_p, ctypes.c_char_p]
|
25 |
+
ttv_init_offline.restype = ctypes.c_int32
|
26 |
+
|
27 |
+
|
28 |
+
ttv_detect_face = liveness_engine.ttv_detect_face
|
29 |
+
ttv_detect_face.argtypes = [ndpointer(ctypes.c_ubyte, flags='C_CONTIGUOUS'), ctypes.c_int32, ctypes.c_int32, ndpointer(ctypes.c_int32, flags='C_CONTIGUOUS'), ndpointer(ctypes.c_double, flags='C_CONTIGUOUS'), ndpointer(ctypes.c_double, flags='C_CONTIGUOUS')]
|
30 |
+
ttv_detect_face.restype = ctypes.c_int32
|
31 |
+
|
facewrapper/libs/libimutils.so
ADDED
Binary file (412 kB). View file
|
|
facewrapper/libs/libimutils.so_for_ubuntu22
ADDED
Binary file (412 kB). View file
|
|
facewrapper/libs/libttvfaceengine7.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b3d6f12326c8bd60242dd7366cfebeef69d25a296bdd9d329d3033e8b70e782f
|
3 |
+
size 3664979
|
gradio/demo.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
|
5 |
+
def face_liveness(frame):
|
6 |
+
url = "http://127.0.0.1:8000/api/liveness"
|
7 |
+
files = None
|
8 |
+
if frame is None:
|
9 |
+
return ['', None]
|
10 |
+
|
11 |
+
files = {'image': open(frame, 'rb')}
|
12 |
+
r = requests.post(url=url, files=files)
|
13 |
+
return r.json()
|
14 |
+
|
15 |
+
with gr.Blocks() as demo:
|
16 |
+
gr.Markdown(
|
17 |
+
"""
|
18 |
+
# Face Liveness Detection
|
19 |
+
"""
|
20 |
+
)
|
21 |
+
with gr.Row():
|
22 |
+
with gr.Column(scale=5):
|
23 |
+
image_input = gr.Image(type='filepath')
|
24 |
+
gr.Examples(['gradio/examples/1.jpg', 'gradio/examples/2.jpg', 'gradio/examples/3.jpg', 'gradio/examples/4.jpg'],
|
25 |
+
inputs=image_input)
|
26 |
+
face_liveness_button = gr.Button("Check Liveness")
|
27 |
+
with gr.Column(scale=5):
|
28 |
+
liveness_result_output = gr.JSON()
|
29 |
+
|
30 |
+
face_liveness_button.click(face_liveness, inputs=image_input, outputs=liveness_result_output)
|
31 |
+
|
32 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
gradio/examples/1.jpg
ADDED
gradio/examples/2.jpg
ADDED
gradio/examples/3.jpg
ADDED
gradio/examples/4.jpg
ADDED
openvino/cache.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
openvino/libgna.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:22441d86dca92b00ae7fb9d315bcb1c6a8a213ac4fe86396489753ebe76f869e
|
3 |
+
size 3120536
|
openvino/libgna.so.2
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:22441d86dca92b00ae7fb9d315bcb1c6a8a213ac4fe86396489753ebe76f869e
|
3 |
+
size 3120536
|
openvino/libgna.so.3.0.0.1455
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:22441d86dca92b00ae7fb9d315bcb1c6a8a213ac4fe86396489753ebe76f869e
|
3 |
+
size 3120536
|
openvino/libopenvino.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fd216848c1ba78e62360c12c9684df0c160f6962f3d900e5918cc042b42b2b46
|
3 |
+
size 13495416
|
openvino/libopenvino_auto_batch_plugin.so
ADDED
Binary file (391 kB). View file
|
|
openvino/libopenvino_auto_plugin.so
ADDED
Binary file (371 kB). View file
|
|
openvino/libopenvino_c.so
ADDED
Binary file (305 kB). View file
|
|
openvino/libopenvino_gapi_preproc.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3ac5ce0a8f3acefb41e8aa8161f78035dafff25c4b8c3485ebc541573b2b15f0
|
3 |
+
size 1312920
|
openvino/libopenvino_hetero_plugin.so
ADDED
Binary file (367 kB). View file
|
|
openvino/libopenvino_intel_cpu_plugin.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:afe05ada6d5b11495a21787fa6ab0162fc40f7a9ab97be78f7b7185126d15b18
|
3 |
+
size 33299880
|
openvino/libopenvino_intel_gna_plugin.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ef15b623e7f81788160c4056ccd5e887a8184affe381e84a906646ef36cae1ab
|
3 |
+
size 4067016
|
openvino/libopenvino_intel_hddl_plugin.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:96362327fbc404e88583bdcd2a526ccbf4ca26d4ecdb8898234be7986d9b8b2b
|
3 |
+
size 5894680
|
openvino/libopenvino_intel_myriad_plugin.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e596436002565356b80400e0d7e50093d53d338f623b171f658de527477852de
|
3 |
+
size 6120168
|
openvino/libopenvino_ir_frontend.so
ADDED
Binary file (343 kB). View file
|
|
openvino/libopenvino_onnx_frontend.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0770ed09d471b20bffcf4ef57ab1fb002db04c4404598bd5c52a4418a67f5441
|
3 |
+
size 3781640
|
openvino/libopenvino_paddle_frontend.so
ADDED
Binary file (987 kB). View file
|
|
openvino/libopenvino_tensorflow_fe.so
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2dadbcd8ba32cec02873caf8dcc644d1d8856cdcd2978c603e5bac169e01bb9
|
3 |
+
size 2723864
|
openvino/pcie-ma2x8x.mvcmd
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f03146453508f2bcab1589907bccaa429b48db6123a7b8a428d6ce221d1fbb4d
|
3 |
+
size 2099248
|
openvino/plugins.xml
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<ie>
|
2 |
+
<plugins>
|
3 |
+
<plugin name="AUTO" location="libopenvino_auto_plugin.so">
|
4 |
+
<properties>
|
5 |
+
<property key="MULTI_WORK_MODE_AS_AUTO" value="YES"/>
|
6 |
+
</properties>
|
7 |
+
</plugin>
|
8 |
+
<plugin name="BATCH" location="libopenvino_auto_batch_plugin.so">
|
9 |
+
</plugin>
|
10 |
+
<plugin name="CPU" location="libopenvino_intel_cpu_plugin.so">
|
11 |
+
</plugin>
|
12 |
+
<plugin name="GNA" location="libopenvino_intel_gna_plugin.so">
|
13 |
+
</plugin>
|
14 |
+
<plugin name="GPU" location="libopenvino_intel_gpu_plugin.so">
|
15 |
+
</plugin>
|
16 |
+
<plugin name="HETERO" location="libopenvino_hetero_plugin.so">
|
17 |
+
</plugin>
|
18 |
+
<plugin name="MULTI" location="libopenvino_auto_plugin.so">
|
19 |
+
</plugin>
|
20 |
+
<plugin name="MYRIAD" location="libopenvino_intel_myriad_plugin.so">
|
21 |
+
</plugin>
|
22 |
+
<plugin name="HDDL" location="libopenvino_intel_hddl_plugin.so">
|
23 |
+
</plugin>
|
24 |
+
<plugin name="VPUX" location="libopenvino_intel_vpux_plugin.so">
|
25 |
+
</plugin>
|
26 |
+
</plugins>
|
27 |
+
</ie>
|
openvino/usb-ma2x8x.mvcmd
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:faf33388b88708177a358fcb4704eba04b1cf9e88d6a047f90c833d686140a2e
|
3 |
+
size 2298632
|
openvino/vpu_custom_kernels/binarization.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e0de6082c7bacca2ff5ad131f0afc44304fc792a6d99e7829399eb61491a0ac
|
3 |
+
size 19632
|
openvino/vpu_custom_kernels/binarization.cl
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
__kernel void binarization(
|
9 |
+
const __global half *__restrict src_data,
|
10 |
+
const __global half *__restrict input_low_high,
|
11 |
+
const __global half *__restrict dst_data,
|
12 |
+
int switch_out,
|
13 |
+
int input_low_high_size,
|
14 |
+
int W,
|
15 |
+
int H)
|
16 |
+
{
|
17 |
+
__local half local_src[15 * 1024];
|
18 |
+
__local half local_dst[15 * 1024];
|
19 |
+
|
20 |
+
event_t e1 = async_work_group_copy(local_src, src_data + get_group_id(2) * W * H, W * H, 0);
|
21 |
+
wait_group_events(1, &e1);
|
22 |
+
|
23 |
+
int c = get_global_id(2);
|
24 |
+
int C = get_global_size(2);
|
25 |
+
|
26 |
+
half dst_low = switch_out ? 1.h : -1.h;
|
27 |
+
half dst_high = switch_out ? -1.h : 1.h;
|
28 |
+
|
29 |
+
half s_ilow_ihigh = input_low_high_size == 1 ? input_low_high[0] : input_low_high[c];
|
30 |
+
|
31 |
+
for (int h = 0; h < H; h++) {
|
32 |
+
|
33 |
+
__local const half *__restrict addr_src = local_src + h * W;
|
34 |
+
__local half *__restrict addr_dst = local_dst + h * W;
|
35 |
+
|
36 |
+
#if 1
|
37 |
+
for (int w = 0; w < W / 8; w++) {
|
38 |
+
|
39 |
+
half8 h_src_val8 = (*((__local half8 *)addr_src + w));
|
40 |
+
|
41 |
+
short8 cond1;
|
42 |
+
cond1.s0 = (h_src_val8.s0 <= s_ilow_ihigh);
|
43 |
+
cond1.s1 = (h_src_val8.s1 <= s_ilow_ihigh);
|
44 |
+
cond1.s2 = (h_src_val8.s2 <= s_ilow_ihigh);
|
45 |
+
cond1.s3 = (h_src_val8.s3 <= s_ilow_ihigh);
|
46 |
+
cond1.s4 = (h_src_val8.s4 <= s_ilow_ihigh);
|
47 |
+
cond1.s5 = (h_src_val8.s5 <= s_ilow_ihigh);
|
48 |
+
cond1.s6 = (h_src_val8.s6 <= s_ilow_ihigh);
|
49 |
+
cond1.s7 = (h_src_val8.s7 <= s_ilow_ihigh);
|
50 |
+
|
51 |
+
cond1 = ~(cond1 - (short8)1);
|
52 |
+
|
53 |
+
short8 res = cond1 & as_short8((half8)dst_low) | ~cond1 & as_short8((half8)dst_high);
|
54 |
+
|
55 |
+
*((__local half8 *)addr_dst + w) = as_half8(res);
|
56 |
+
}
|
57 |
+
#endif
|
58 |
+
for (int w = W & (~0x7); w < W; w++) {
|
59 |
+
addr_dst[w] = (addr_src[w] <= s_ilow_ihigh) ? dst_low : dst_high;
|
60 |
+
}
|
61 |
+
}
|
62 |
+
|
63 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
64 |
+
|
65 |
+
event_t e2 = async_work_group_copy(dst_data + get_group_id(2) * W * H, local_dst, W * H, 0);
|
66 |
+
wait_group_events(1, &e2);
|
67 |
+
}
|
openvino/vpu_custom_kernels/binary_convolution.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:12c349d6f73c233b158e1d67af31715c7b8bda79f191b1e759476e01e65bb64a
|
3 |
+
size 10764
|
openvino/vpu_custom_kernels/binary_convolution.cl
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
|
7 |
+
int extract_weights(uchar val, int bit) { return ((val >> bit) & 1); }
|
8 |
+
|
9 |
+
__kernel void binary_convolution(
|
10 |
+
const __global half *restrict src_data,
|
11 |
+
const __global uchar *restrict weights_data,
|
12 |
+
__global half *restrict dst_data,
|
13 |
+
float pad_value,
|
14 |
+
|
15 |
+
int IW,
|
16 |
+
int IH,
|
17 |
+
int IC,
|
18 |
+
|
19 |
+
int DW,
|
20 |
+
int DH,
|
21 |
+
|
22 |
+
int GC,
|
23 |
+
|
24 |
+
int KW,
|
25 |
+
int KH,
|
26 |
+
|
27 |
+
int PW,
|
28 |
+
int PH,
|
29 |
+
|
30 |
+
int SW,
|
31 |
+
int SH)
|
32 |
+
{
|
33 |
+
int ipad_value = ((pad_value > 0.f) ? 1 : 0);
|
34 |
+
int c = get_global_id(2);
|
35 |
+
int y = get_global_id(1);
|
36 |
+
int x = get_global_id(0);
|
37 |
+
|
38 |
+
int OC = get_global_size(2);
|
39 |
+
int OH = get_global_size(1);
|
40 |
+
int OW = get_global_size(0);
|
41 |
+
|
42 |
+
int KD = 1;
|
43 |
+
int SD = 0;
|
44 |
+
int DD = 0;
|
45 |
+
int PD = 0;
|
46 |
+
int ID = 1;
|
47 |
+
int OD = 1;
|
48 |
+
|
49 |
+
int nbits = 8;
|
50 |
+
|
51 |
+
int g = c % GC;
|
52 |
+
int oc = c / GC;
|
53 |
+
int oh = y;
|
54 |
+
int ow = x;
|
55 |
+
|
56 |
+
for (int od = 0; od < OD; od++) {
|
57 |
+
int oidx = g * OC / GC * OD * OH * OW + oc * OD * OH * OW + od * OH * OW + oh * OW + ow;
|
58 |
+
|
59 |
+
int res = 0;
|
60 |
+
|
61 |
+
for (int ic = 0; ic < IC / GC; ic++) {
|
62 |
+
for (int kd = 0; kd < KD; kd++) {
|
63 |
+
for (int kh = 0; kh < KH; kh++) {
|
64 |
+
for (int kw = 0; kw < KW; kw++) {
|
65 |
+
int widx = g * OC / GC * IC / GC * KD * KH * KW
|
66 |
+
+ oc * IC / GC * KD * KH * KW + ic * KD * KH * KW + kd * KH * KW
|
67 |
+
+ kh * KW + kw;
|
68 |
+
|
69 |
+
int w = extract_weights(weights_data[widx / nbits], (widx % nbits));
|
70 |
+
|
71 |
+
int s;
|
72 |
+
|
73 |
+
int iw = ow * SW - PW + kw * DW;
|
74 |
+
int ih = oh * SH - PH + kh * DH;
|
75 |
+
int id = od * SD - PD + kd * DD;
|
76 |
+
|
77 |
+
if (iw < 0 || iw >= (int)IW || ih < 0 || ih >= (int)IH || id < 0
|
78 |
+
|| id >= (int)ID) {
|
79 |
+
s = ipad_value;
|
80 |
+
} else {
|
81 |
+
int iidx = g * IC / GC * ID * IH * IW + ic * ID * IH * IW + id * IH * IW
|
82 |
+
+ ih * IW + iw;
|
83 |
+
|
84 |
+
s = ((src_data[iidx] > 0.f) ? 1 : 0);
|
85 |
+
}
|
86 |
+
|
87 |
+
res += s ^ w;
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
dst_data[oidx] = (half)(IC / GC * KD * KH * KW - 2 * res);
|
94 |
+
}
|
95 |
+
}
|
openvino/vpu_custom_kernels/binary_convolution1x1.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6deff31d62aa84c643fbeba77e7dcd4ae5d9b488c1c98e07fffeb58ff8e9b945
|
3 |
+
size 76316
|
openvino/vpu_custom_kernels/binary_convolution1x1.cl
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
ushort extract_weights(uchar val, int bit) { return ((val >> bit) & 1); }
|
9 |
+
|
10 |
+
__kernel void binary_convolution(
|
11 |
+
const __global half *restrict src_data,
|
12 |
+
const __global uchar *restrict weights_data,
|
13 |
+
__global half *restrict dst_data,
|
14 |
+
float pad_value,
|
15 |
+
|
16 |
+
int IW,
|
17 |
+
int IH,
|
18 |
+
int IC,
|
19 |
+
|
20 |
+
int DW,
|
21 |
+
int DH,
|
22 |
+
|
23 |
+
int GC,
|
24 |
+
|
25 |
+
int KW,
|
26 |
+
int KH,
|
27 |
+
|
28 |
+
int PW,
|
29 |
+
int PH,
|
30 |
+
|
31 |
+
int SW,
|
32 |
+
int SH,
|
33 |
+
|
34 |
+
int OW)
|
35 |
+
{
|
36 |
+
__local half src_local[32 * 1024];
|
37 |
+
__local half dst_local[2 * 1024];
|
38 |
+
|
39 |
+
const int oh = get_group_id(0);
|
40 |
+
const int oc = get_group_id(1);
|
41 |
+
const int OH = get_global_size(0);
|
42 |
+
const int OC = get_global_size(1);
|
43 |
+
|
44 |
+
const int gc = oc / (OC / GC);
|
45 |
+
|
46 |
+
if (oh * SH >= 0 && oh * SH <= IH - 1) {
|
47 |
+
const __global half *src = src_data + (gc * IC / GC) * IW * IH + (SH * oh) * IW;
|
48 |
+
|
49 |
+
event_t e1 = async_work_group_copy_2D2D(
|
50 |
+
src_local, // dst
|
51 |
+
src, // src
|
52 |
+
IW, // num_elements_per_line,
|
53 |
+
IC / GC, // num_lines,
|
54 |
+
IH * IW - IW, // src_line_stride,
|
55 |
+
0, // dst_line_stride,
|
56 |
+
0);
|
57 |
+
wait_group_events(1, &e1);
|
58 |
+
}
|
59 |
+
|
60 |
+
half pad_value_half = convert_half(pad_value);
|
61 |
+
|
62 |
+
//padding row
|
63 |
+
if (oh * SH > IH - 1) {
|
64 |
+
__local half *dst = src_local;
|
65 |
+
for (int c = 0; c < IC / GC; c++) {
|
66 |
+
#pragma unroll 8
|
67 |
+
for (int j = 0; j < IW; j++) {
|
68 |
+
dst[j] = pad_value_half;
|
69 |
+
}
|
70 |
+
dst += IW;
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
int OWS = SW * OW;
|
75 |
+
ushort8 in;
|
76 |
+
|
77 |
+
for (int ows8 = 0; ows8 < (OWS + 7) / 8; ows8++) {
|
78 |
+
ushort8 val = {0, 0, 0, 0, 0, 0, 0, 0};
|
79 |
+
for (int ic = 0; ic < IC / GC; ++ic) {
|
80 |
+
__local half *src = (__local half *)((__local half8 *)(src_local + ic * IW) + ows8);
|
81 |
+
int weight_pos = oc * IC / GC + ic;
|
82 |
+
ushort w =
|
83 |
+
extract_weights(weights_data[((weight_pos + 0)) / 8], ((weight_pos + 0) % 8));
|
84 |
+
|
85 |
+
if ((ows8 * 8) <= IW - 1) {
|
86 |
+
in = *((__local ushort8 *)(src));
|
87 |
+
}
|
88 |
+
|
89 |
+
//padding column
|
90 |
+
if (ows8 * 8 + 7 > IW - 1) {
|
91 |
+
int boundary = (IW - 1) - ows8 * 8 + 1;
|
92 |
+
boundary = boundary < 0 ? 0 : boundary;
|
93 |
+
for (int offset = boundary; offset < 8; offset++) {
|
94 |
+
*((half *)(&in) + offset) = pad_value_half;
|
95 |
+
}
|
96 |
+
}
|
97 |
+
|
98 |
+
ushort8 w8 = (ushort8)(w);
|
99 |
+
|
100 |
+
ushort8 cond =
|
101 |
+
(((in) < (ushort8)0x8000) && (in > (ushort8)0x0000)) ? (ushort8)(1) : (ushort8)(0);
|
102 |
+
|
103 |
+
val += (cond ^ w8);
|
104 |
+
}
|
105 |
+
|
106 |
+
ushort8 val_shift = val << 1;
|
107 |
+
int boundary = (ows8 * 8 + 7) / SW < OW - 1 ? (ows8 * 8 + 7) / SW : OW - 1;
|
108 |
+
for (int ow = (ows8 * 8 + SW - 1) / SW; ow <= boundary; ow++) {
|
109 |
+
*(dst_local + ow) = (half)(IC / GC - *((ushort *)(&val_shift) + ow * SW - ows8 * 8));
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
114 |
+
|
115 |
+
event_t e2 = async_work_group_copy(dst_data + oc * OW * OH + oh * OW, dst_local, OW, 0);
|
116 |
+
wait_group_events(1, &e2);
|
117 |
+
}
|
openvino/vpu_custom_kernels/binary_convolution3x3.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:55e3c3f8863ff7a3583bcc7340d1e226775f5f14cfb11dd32bd671764570f7cb
|
3 |
+
size 104136
|
openvino/vpu_custom_kernels/binary_convolution3x3.cl
ADDED
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
ushort extract_weights(uchar val, int bit) { return ((val >> bit) & 1); }
|
9 |
+
|
10 |
+
__kernel void binary_convolution(
|
11 |
+
const __global half *restrict src_data,
|
12 |
+
const __global uchar *restrict weights_data,
|
13 |
+
const __global half *restrict dst_data,
|
14 |
+
float pad_value,
|
15 |
+
|
16 |
+
int IW,
|
17 |
+
int IH,
|
18 |
+
int IC,
|
19 |
+
|
20 |
+
int DW,
|
21 |
+
int DH,
|
22 |
+
|
23 |
+
int GC,
|
24 |
+
|
25 |
+
int KW,
|
26 |
+
int KH,
|
27 |
+
|
28 |
+
int PW,
|
29 |
+
int PH,
|
30 |
+
|
31 |
+
int SW,
|
32 |
+
int SH,
|
33 |
+
|
34 |
+
int OW)
|
35 |
+
{
|
36 |
+
__local half src_local[32 * 1024];
|
37 |
+
__local half dst_local[2 * 1024];
|
38 |
+
|
39 |
+
const int oh = get_group_id(0);
|
40 |
+
const int oc = get_group_id(1);
|
41 |
+
const int OH = get_global_size(0);
|
42 |
+
const int OC = get_global_size(1);
|
43 |
+
|
44 |
+
const int gc = oc / (OC / GC);
|
45 |
+
|
46 |
+
if (oh * SH - 1 >= 0 && oh * SH + DH + DH - 1 <= IH - 1) //dma for 3 rows
|
47 |
+
{
|
48 |
+
event_t e = async_work_group_copy_3D3D(
|
49 |
+
src_local, // dst
|
50 |
+
src_data + (gc * IC / GC) * IW * IH + (SH * oh - 1) * IW, // src
|
51 |
+
IW, // num_elements_per_line
|
52 |
+
3, // num_lines
|
53 |
+
DH * IW - IW, // src_line_stride
|
54 |
+
0, // dst_line_stride
|
55 |
+
IC / GC, // num planes
|
56 |
+
IH * IW - 3 * DH * IW, // src plane stride
|
57 |
+
0, // dst plane stride
|
58 |
+
0);
|
59 |
+
wait_group_events(1, &e);
|
60 |
+
} else {
|
61 |
+
int ih = oh * SH - 1;
|
62 |
+
if (ih >= 0 && ih <= IH - 1) //dma for first row
|
63 |
+
{
|
64 |
+
event_t e = async_work_group_copy_2D2D(
|
65 |
+
src_local, // dst
|
66 |
+
src_data + (gc * IC / GC) * IW * IH + ih * IW, // src
|
67 |
+
IW, // num_elements_per_line,
|
68 |
+
IC / GC, // num_lines,
|
69 |
+
IH * IW - IW, // src_line_stride,
|
70 |
+
2 * IW, // dst_line_stride,
|
71 |
+
0);
|
72 |
+
|
73 |
+
wait_group_events(1, &e);
|
74 |
+
}
|
75 |
+
ih = oh * SH - 1 + DH;
|
76 |
+
if (ih >= 0 && ih <= IH - 1) //dma for second row
|
77 |
+
{
|
78 |
+
event_t e = async_work_group_copy_2D2D(
|
79 |
+
src_local + IW, // dst
|
80 |
+
src_data + (gc * IC / GC) * IW * IH + ih * IW, // src
|
81 |
+
IW, // num_elements_per_line,
|
82 |
+
IC / GC, // num_lines,
|
83 |
+
IH * IW - IW, // src_line_stride,
|
84 |
+
2 * IW, // dst_line_stride,
|
85 |
+
0);
|
86 |
+
wait_group_events(1, &e);
|
87 |
+
}
|
88 |
+
ih = oh * SH - 1 + 2 * DH;
|
89 |
+
if (ih >= 0 && ih <= IH - 1) //dma for third row
|
90 |
+
{
|
91 |
+
event_t e = async_work_group_copy_2D2D(
|
92 |
+
src_local + 2 * IW, // dst
|
93 |
+
src_data + (gc * IC / GC) * IW * IH + ih * IW, // src
|
94 |
+
IW, // num_elements_per_line,
|
95 |
+
IC / GC, // num_lines,
|
96 |
+
IH * IW - IW, // src_line_stride,
|
97 |
+
2 * IW, // dst_line_stride,
|
98 |
+
0);
|
99 |
+
wait_group_events(1, &e);
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
half pad_value_half = convert_half(pad_value);
|
104 |
+
|
105 |
+
//padding row
|
106 |
+
if (oh * SH - 1 < 0 || oh * SH - 1 > IH - 1) {
|
107 |
+
__local half *dst = src_local;
|
108 |
+
for (int c = 0; c < IC / GC; c++) {
|
109 |
+
#pragma unroll 8
|
110 |
+
for (int j = 0; j < IW; j++) {
|
111 |
+
dst[j] = pad_value_half;
|
112 |
+
}
|
113 |
+
dst += 3 * IW;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
if (oh * SH + DH - 1 > IH - 1) {
|
117 |
+
__local half *dst = src_local + IW;
|
118 |
+
for (int c = 0; c < IC / GC; c++) {
|
119 |
+
#pragma unroll 8
|
120 |
+
for (int j = 0; j < IW; j++) {
|
121 |
+
dst[j] = pad_value_half;
|
122 |
+
}
|
123 |
+
dst += 3 * IW;
|
124 |
+
}
|
125 |
+
}
|
126 |
+
if (oh * SH + DH + DH - 1 > IH - 1) {
|
127 |
+
__local half *dst = src_local + 2 * IW;
|
128 |
+
for (int c = 0; c < IC / GC; c++) {
|
129 |
+
#pragma unroll 8
|
130 |
+
for (int j = 0; j < IW; j++) {
|
131 |
+
dst[j] = pad_value_half;
|
132 |
+
}
|
133 |
+
dst += 3 * IW;
|
134 |
+
}
|
135 |
+
}
|
136 |
+
|
137 |
+
int OWS = SW * OW;
|
138 |
+
|
139 |
+
ushort8 in00;
|
140 |
+
ushort8 in01;
|
141 |
+
ushort8 in02;
|
142 |
+
ushort8 in10;
|
143 |
+
ushort8 in11;
|
144 |
+
ushort8 in12;
|
145 |
+
ushort8 in20;
|
146 |
+
ushort8 in21;
|
147 |
+
ushort8 in22;
|
148 |
+
|
149 |
+
for (int ows8 = 0; ows8 < (OWS + 7) / 8; ows8++) {
|
150 |
+
ushort8 val = {0, 0, 0, 0, 0, 0, 0, 0};
|
151 |
+
for (int ic = 0; ic < IC / GC; ++ic) {
|
152 |
+
__local half *src =
|
153 |
+
(__local half *)((__local half8 *)(src_local + ic * IW * 3 + IW + DW - 1) + ows8);
|
154 |
+
int weight_pos = oc * IC / GC * 3 * 3 + ic * 3 * 3;
|
155 |
+
ushort w0 = extract_weights(weights_data[((weight_pos + 0)) / 8], ((weight_pos + 0) % 8));
|
156 |
+
ushort w1 = extract_weights(weights_data[((weight_pos + 1)) / 8], ((weight_pos + 1) % 8));
|
157 |
+
ushort w2 = extract_weights(weights_data[((weight_pos + 2)) / 8], ((weight_pos + 2) % 8));
|
158 |
+
ushort w3 = extract_weights(weights_data[((weight_pos + 3)) / 8], ((weight_pos + 3) % 8));
|
159 |
+
ushort w4 = extract_weights(weights_data[((weight_pos + 4)) / 8], ((weight_pos + 4) % 8));
|
160 |
+
ushort w5 = extract_weights(weights_data[((weight_pos + 5)) / 8], ((weight_pos + 5) % 8));
|
161 |
+
ushort w6 = extract_weights(weights_data[((weight_pos + 6)) / 8], ((weight_pos + 6) % 8));
|
162 |
+
ushort w7 = extract_weights(weights_data[((weight_pos + 7)) / 8], ((weight_pos + 7) % 8));
|
163 |
+
ushort w8 = extract_weights(weights_data[((weight_pos + 8)) / 8], ((weight_pos + 8) % 8));
|
164 |
+
|
165 |
+
if ((ows8 * 8) - 1 <= IW - 1) {
|
166 |
+
in00 = *((__local ushort8 *)(src - IW - DW));
|
167 |
+
in01 = *((__local ushort8 *)(src - IW));
|
168 |
+
in02 = *((__local ushort8 *)(src - IW + DW));
|
169 |
+
|
170 |
+
in10 = *((__local ushort8 *)(src - DW));
|
171 |
+
in11 = *((__local ushort8 *)(src));
|
172 |
+
in12 = *((__local ushort8 *)(src + DW));
|
173 |
+
|
174 |
+
in20 = *((__local ushort8 *)(src + IW - DW));
|
175 |
+
in21 = *((__local ushort8 *)(src + IW));
|
176 |
+
in22 = *((__local ushort8 *)(src + IW + DW));
|
177 |
+
}
|
178 |
+
|
179 |
+
//padding column
|
180 |
+
if (ows8 * 8 - 1 < 0) {
|
181 |
+
int boundary = 1 - ows8 * 8;
|
182 |
+
boundary = boundary > 8 ? 8 : boundary;
|
183 |
+
for (int offset = 0; offset < boundary; offset++) {
|
184 |
+
*((half *)(&in00) + offset) = pad_value_half;
|
185 |
+
*((half *)(&in10) + offset) = pad_value_half;
|
186 |
+
*((half *)(&in20) + offset) = pad_value_half;
|
187 |
+
}
|
188 |
+
}
|
189 |
+
if ((ows8 * 8 + 7) + DW + DW - 1 > IW - 1) {
|
190 |
+
int boundary = (IW - DW - 1 - DW + 1) - ows8 * 8 + 1;
|
191 |
+
boundary = boundary < 0 ? 0 : boundary;
|
192 |
+
for (int offset = boundary; offset < 8; offset++) {
|
193 |
+
*((half *)(&in02) + offset) = pad_value_half;
|
194 |
+
*((half *)(&in12) + offset) = pad_value_half;
|
195 |
+
*((half *)(&in22) + offset) = pad_value_half;
|
196 |
+
}
|
197 |
+
}
|
198 |
+
if ((ows8 * 8 + 7) + DW - 1 > IW - 1) {
|
199 |
+
int boundary = (IW - 1 - DW + 1) - ows8 * 8 + 1;
|
200 |
+
boundary = boundary < 0 ? 0 : boundary;
|
201 |
+
for (int offset = boundary; offset < 8; offset++) {
|
202 |
+
*((half *)(&in01) + offset) = pad_value_half;
|
203 |
+
*((half *)(&in11) + offset) = pad_value_half;
|
204 |
+
*((half *)(&in21) + offset) = pad_value_half;
|
205 |
+
}
|
206 |
+
}
|
207 |
+
if ((ows8 * 8 + 7) - 1 > IW - 1) {
|
208 |
+
int boundary = (IW - 1 + 1) - ows8 * 8 + 1;
|
209 |
+
boundary = boundary < 0 ? 0 : boundary;
|
210 |
+
for (int offset = boundary; offset < 8; offset++) {
|
211 |
+
*((half *)(&in00) + offset) = pad_value_half;
|
212 |
+
*((half *)(&in10) + offset) = pad_value_half;
|
213 |
+
*((half *)(&in20) + offset) = pad_value_half;
|
214 |
+
}
|
215 |
+
}
|
216 |
+
|
217 |
+
ushort8 w00 = (ushort8)(w0);
|
218 |
+
ushort8 w01 = (ushort8)(w1);
|
219 |
+
ushort8 w02 = (ushort8)(w2);
|
220 |
+
ushort8 w10 = (ushort8)(w3);
|
221 |
+
ushort8 w11 = (ushort8)(w4);
|
222 |
+
ushort8 w12 = (ushort8)(w5);
|
223 |
+
ushort8 w20 = (ushort8)(w6);
|
224 |
+
ushort8 w21 = (ushort8)(w7);
|
225 |
+
ushort8 w22 = (ushort8)(w8);
|
226 |
+
|
227 |
+
ushort8 cond0 = (((in00) < (ushort8)0x8000) && (in00 > (ushort8)0x0000)) ?
|
228 |
+
(ushort8)(1) :
|
229 |
+
(ushort8)(0);
|
230 |
+
ushort8 cond1 = (((in01) < (ushort8)0x8000) && (in01 > (ushort8)0x0000)) ?
|
231 |
+
(ushort8)(1) :
|
232 |
+
(ushort8)(0);
|
233 |
+
ushort8 cond2 = (((in02) < (ushort8)0x8000) && (in02 > (ushort8)0x0000)) ?
|
234 |
+
(ushort8)(1) :
|
235 |
+
(ushort8)(0);
|
236 |
+
ushort8 cond3 = (((in10) < (ushort8)0x8000) && (in10 > (ushort8)0x0000)) ?
|
237 |
+
(ushort8)(1) :
|
238 |
+
(ushort8)(0);
|
239 |
+
ushort8 cond4 = (((in11) < (ushort8)0x8000) && (in11 > (ushort8)0x0000)) ?
|
240 |
+
(ushort8)(1) :
|
241 |
+
(ushort8)(0);
|
242 |
+
ushort8 cond5 = (((in12) < (ushort8)0x8000) && (in12 > (ushort8)0x0000)) ?
|
243 |
+
(ushort8)(1) :
|
244 |
+
(ushort8)(0);
|
245 |
+
ushort8 cond6 = (((in20) < (ushort8)0x8000) && (in20 > (ushort8)0x0000)) ?
|
246 |
+
(ushort8)(1) :
|
247 |
+
(ushort8)(0);
|
248 |
+
ushort8 cond7 = (((in21) < (ushort8)0x8000) && (in21 > (ushort8)0x0000)) ?
|
249 |
+
(ushort8)(1) :
|
250 |
+
(ushort8)(0);
|
251 |
+
ushort8 cond8 = (((in22) < (ushort8)0x8000) && (in22 > (ushort8)0x0000)) ?
|
252 |
+
(ushort8)(1) :
|
253 |
+
(ushort8)(0);
|
254 |
+
|
255 |
+
val += (cond0 ^ w00);
|
256 |
+
val += (cond1 ^ w01);
|
257 |
+
val += (cond2 ^ w02);
|
258 |
+
val += (cond3 ^ w10);
|
259 |
+
val += (cond4 ^ w11);
|
260 |
+
val += (cond5 ^ w12);
|
261 |
+
val += (cond6 ^ w20);
|
262 |
+
val += (cond7 ^ w21);
|
263 |
+
val += (cond8 ^ w22);
|
264 |
+
}
|
265 |
+
|
266 |
+
ushort8 val_shift = val << 1;
|
267 |
+
int boundary = (ows8 * 8 + 7) / SW <= OW - 1 ? (ows8 * 8 + 7) / SW : OW - 1;
|
268 |
+
for (int ow = (ows8 * 8 + SW - 1) / SW; ow <= boundary; ow++) {
|
269 |
+
*(dst_local + ow) =
|
270 |
+
(half)(IC / GC * KH * KW - *((ushort *)(&val_shift) + ow * SW - ows8 * 8));
|
271 |
+
}
|
272 |
+
}
|
273 |
+
|
274 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
275 |
+
|
276 |
+
event_t e2 = async_work_group_copy(dst_data + oc * OW * OH + oh * OW, dst_local, OW, 0);
|
277 |
+
wait_group_events(1, &e2);
|
278 |
+
}
|
openvino/vpu_custom_kernels/convolution1x1_chw.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8717c8429d41a69337007871137f06a9e6b38c685b5b3fecc634fade0eaa7e7f
|
3 |
+
size 9220
|
openvino/vpu_custom_kernels/convolution1x1_chw.cl
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
__kernel void Convolution1x1_NCHW(
|
9 |
+
const __global half *in,
|
10 |
+
const __global half *out,
|
11 |
+
const __global half *w,
|
12 |
+
int IW,
|
13 |
+
int IH,
|
14 |
+
int IC,
|
15 |
+
int OW,
|
16 |
+
int OH,
|
17 |
+
int OC)
|
18 |
+
{
|
19 |
+
__local half in_local[8 * 1024];
|
20 |
+
__local half out_local[8 * 1024];
|
21 |
+
|
22 |
+
event_t e1 = async_work_group_copy_2D2D(
|
23 |
+
in_local, // dst
|
24 |
+
in + get_group_id(0) * IW, // src
|
25 |
+
IW, // num_elements_per_line,
|
26 |
+
IC, // num_lines,
|
27 |
+
IW * IH - IW, // src_line_stride,
|
28 |
+
0, // dst_line_stride,
|
29 |
+
0);
|
30 |
+
wait_group_events(1, &e1);
|
31 |
+
|
32 |
+
int oh = get_global_id(0);
|
33 |
+
int oc = get_global_id(1);
|
34 |
+
|
35 |
+
int stride;
|
36 |
+
int write_output = 0;
|
37 |
+
__global half *src;
|
38 |
+
|
39 |
+
__global half8 *w8 = (__global half8 *)(&w[oc * IC]);
|
40 |
+
__global half *w1 = (__global half *)(&w[oc * IC]);
|
41 |
+
|
42 |
+
for (uint ow = 0; ow < (OW & (~0x7)); ow += 8) {
|
43 |
+
uint iw = ow;
|
44 |
+
uint ih = oh;
|
45 |
+
|
46 |
+
half8 val8_0 = 0.0f;
|
47 |
+
|
48 |
+
__local half8 *in8_0 = (__local half8 *)(&in_local[iw + 0 * IW]);
|
49 |
+
__local half8 *in8_1 = (__local half8 *)(&in_local[iw + 1 * IW]);
|
50 |
+
__local half8 *in8_2 = (__local half8 *)(&in_local[iw + 2 * IW]);
|
51 |
+
__local half8 *in8_3 = (__local half8 *)(&in_local[iw + 3 * IW]);
|
52 |
+
__local half8 *in8_4 = (__local half8 *)(&in_local[iw + 4 * IW]);
|
53 |
+
__local half8 *in8_5 = (__local half8 *)(&in_local[iw + 5 * IW]);
|
54 |
+
__local half8 *in8_6 = (__local half8 *)(&in_local[iw + 6 * IW]);
|
55 |
+
__local half8 *in8_7 = (__local half8 *)(&in_local[iw + 7 * IW]);
|
56 |
+
|
57 |
+
for (uint ic = 0; ic < IC / 8; ic++) {
|
58 |
+
val8_0 += (in8_0[ic * IW]) * ((half8)w8[ic].s0);
|
59 |
+
val8_0 += (in8_1[ic * IW]) * ((half8)w8[ic].s1);
|
60 |
+
val8_0 += (in8_2[ic * IW]) * ((half8)w8[ic].s2);
|
61 |
+
val8_0 += (in8_3[ic * IW]) * ((half8)w8[ic].s3);
|
62 |
+
val8_0 += (in8_4[ic * IW]) * ((half8)w8[ic].s4);
|
63 |
+
val8_0 += (in8_5[ic * IW]) * ((half8)w8[ic].s5);
|
64 |
+
val8_0 += (in8_6[ic * IW]) * ((half8)w8[ic].s6);
|
65 |
+
val8_0 += (in8_7[ic * IW]) * ((half8)w8[ic].s7);
|
66 |
+
}
|
67 |
+
|
68 |
+
for (uint ic = (IC & (~0x7)); ic < IC; ++ic) {
|
69 |
+
val8_0 += *((__local half8 *)(&in_local[iw + ic * IW])) * ((half8)w1[ic]);
|
70 |
+
}
|
71 |
+
*((__local half8 *)&out_local[ow + 0]) = (val8_0);
|
72 |
+
}
|
73 |
+
|
74 |
+
uint iw = (OW & (~0x7));
|
75 |
+
uint ih = oh;
|
76 |
+
|
77 |
+
half8 val8_0 = 0.0f;
|
78 |
+
|
79 |
+
__local half8 *in8_0 = (__local half8 *)(&in_local[iw + 0 * IW]);
|
80 |
+
__local half8 *in8_1 = (__local half8 *)(&in_local[iw + 1 * IW]);
|
81 |
+
__local half8 *in8_2 = (__local half8 *)(&in_local[iw + 2 * IW]);
|
82 |
+
__local half8 *in8_3 = (__local half8 *)(&in_local[iw + 3 * IW]);
|
83 |
+
__local half8 *in8_4 = (__local half8 *)(&in_local[iw + 4 * IW]);
|
84 |
+
__local half8 *in8_5 = (__local half8 *)(&in_local[iw + 5 * IW]);
|
85 |
+
__local half8 *in8_6 = (__local half8 *)(&in_local[iw + 6 * IW]);
|
86 |
+
__local half8 *in8_7 = (__local half8 *)(&in_local[iw + 7 * IW]);
|
87 |
+
|
88 |
+
for (uint ic = 0; ic < IC / 8; ic++) {
|
89 |
+
val8_0 += (in8_0[ic * IW]) * ((half8)w8[ic].s0);
|
90 |
+
val8_0 += (in8_1[ic * IW]) * ((half8)w8[ic].s1);
|
91 |
+
val8_0 += (in8_2[ic * IW]) * ((half8)w8[ic].s2);
|
92 |
+
val8_0 += (in8_3[ic * IW]) * ((half8)w8[ic].s3);
|
93 |
+
val8_0 += (in8_4[ic * IW]) * ((half8)w8[ic].s4);
|
94 |
+
val8_0 += (in8_5[ic * IW]) * ((half8)w8[ic].s5);
|
95 |
+
val8_0 += (in8_6[ic * IW]) * ((half8)w8[ic].s6);
|
96 |
+
val8_0 += (in8_7[ic * IW]) * ((half8)w8[ic].s7);
|
97 |
+
}
|
98 |
+
|
99 |
+
for (uint ic = (IC & (~0x7)); ic < IC; ++ic) {
|
100 |
+
val8_0 += *((__local half8 *)(&in_local[iw + ic * IW])) * ((half8)w1[ic]);
|
101 |
+
}
|
102 |
+
for (uint ow = (OW & (~0x7)); ow < OW; ow++) {
|
103 |
+
out_local[ow + 0] = (val8_0[ow % 8]);
|
104 |
+
}
|
105 |
+
|
106 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
107 |
+
|
108 |
+
event_t e2 = async_work_group_copy(
|
109 |
+
out + get_group_id(1) * OW * OH + get_group_id(0) * OW,
|
110 |
+
out_local,
|
111 |
+
OW,
|
112 |
+
0);
|
113 |
+
wait_group_events(1, &e2);
|
114 |
+
}
|
openvino/vpu_custom_kernels/convolution1x1_hwc.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5b6122a6bf6f50d2c7fc612d4e286559f9c96746e166892d192e1264e1ce5a2c
|
3 |
+
size 4304
|
openvino/vpu_custom_kernels/convolution1x1_hwc.cl
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
__kernel void Convolution1x1_NHWC(
|
9 |
+
const __global half *in,
|
10 |
+
const __global half *out,
|
11 |
+
const __global half *w,
|
12 |
+
int IW,
|
13 |
+
int IH,
|
14 |
+
int IC,
|
15 |
+
int OW,
|
16 |
+
int OH,
|
17 |
+
int OC)
|
18 |
+
{
|
19 |
+
|
20 |
+
__local half in_local[8 * 1024];
|
21 |
+
__local half out_local[8 * 1024];
|
22 |
+
|
23 |
+
const int sizeAct = IW * IC;
|
24 |
+
|
25 |
+
event_t e1 = async_work_group_copy(in_local, in + get_group_id(0) * sizeAct, sizeAct, 0);
|
26 |
+
wait_group_events(1, &e1);
|
27 |
+
|
28 |
+
int oh = get_global_id(0);
|
29 |
+
int oc = get_global_id(1);
|
30 |
+
|
31 |
+
int stride;
|
32 |
+
int write_output = 0;
|
33 |
+
__global half *src;
|
34 |
+
|
35 |
+
__global half8 *w8 = (__global half8 *)(&w[oc * IC]);
|
36 |
+
__global half *w1 = (__global half *)(&w[oc * IC]);
|
37 |
+
|
38 |
+
for (uint ow = 0; ow < (OW & (~0x7)); ow += 8) {
|
39 |
+
uint iw = ow;
|
40 |
+
uint ih = oh;
|
41 |
+
|
42 |
+
half8 val8_0 = 0.0f;
|
43 |
+
half8 val8_1 = 0.0f;
|
44 |
+
half8 val8_2 = 0.0f;
|
45 |
+
half8 val8_3 = 0.0f;
|
46 |
+
half8 val8_4 = 0.0f;
|
47 |
+
half8 val8_5 = 0.0f;
|
48 |
+
half8 val8_6 = 0.0f;
|
49 |
+
half8 val8_7 = 0.0f;
|
50 |
+
|
51 |
+
__local half8 *in8_0 = (__local half8 *)(&in_local[(iw + 0) * IC]);
|
52 |
+
__local half8 *in8_1 = (__local half8 *)(&in_local[(iw + 1) * IC]);
|
53 |
+
__local half8 *in8_2 = (__local half8 *)(&in_local[(iw + 2) * IC]);
|
54 |
+
__local half8 *in8_3 = (__local half8 *)(&in_local[(iw + 3) * IC]);
|
55 |
+
__local half8 *in8_4 = (__local half8 *)(&in_local[(iw + 4) * IC]);
|
56 |
+
__local half8 *in8_5 = (__local half8 *)(&in_local[(iw + 5) * IC]);
|
57 |
+
__local half8 *in8_6 = (__local half8 *)(&in_local[(iw + 6) * IC]);
|
58 |
+
__local half8 *in8_7 = (__local half8 *)(&in_local[(iw + 7) * IC]);
|
59 |
+
|
60 |
+
for (uint ic = 0; ic < IC / 8; ++ic) {
|
61 |
+
val8_0 += (in8_0[ic]) * (w8[ic]);
|
62 |
+
val8_1 += (in8_1[ic]) * (w8[ic]);
|
63 |
+
val8_2 += (in8_2[ic]) * (w8[ic]);
|
64 |
+
val8_3 += (in8_3[ic]) * (w8[ic]);
|
65 |
+
val8_4 += (in8_4[ic]) * (w8[ic]);
|
66 |
+
val8_5 += (in8_5[ic]) * (w8[ic]);
|
67 |
+
val8_6 += (in8_6[ic]) * (w8[ic]);
|
68 |
+
val8_7 += (in8_7[ic]) * (w8[ic]);
|
69 |
+
}
|
70 |
+
|
71 |
+
half val_0 = 0.0f;
|
72 |
+
half val_1 = 0.0f;
|
73 |
+
half val_2 = 0.0f;
|
74 |
+
half val_3 = 0.0f;
|
75 |
+
half val_4 = 0.0f;
|
76 |
+
half val_5 = 0.0f;
|
77 |
+
half val_6 = 0.0f;
|
78 |
+
half val_7 = 0.0f;
|
79 |
+
for (uint ic = IC & (~0x7); ic < IC; ++ic) {
|
80 |
+
val_0 += *((__local half *)in8_0 + ic) * (*((__global half *)w8 + ic));
|
81 |
+
val_1 += *((__local half *)in8_1 + ic) * (*((__global half *)w8 + ic));
|
82 |
+
val_2 += *((__local half *)in8_2 + ic) * (*((__global half *)w8 + ic));
|
83 |
+
val_3 += *((__local half *)in8_3 + ic) * (*((__global half *)w8 + ic));
|
84 |
+
val_4 += *((__local half *)in8_4 + ic) * (*((__global half *)w8 + ic));
|
85 |
+
val_5 += *((__local half *)in8_5 + ic) * (*((__global half *)w8 + ic));
|
86 |
+
val_6 += *((__local half *)in8_6 + ic) * (*((__global half *)w8 + ic));
|
87 |
+
val_7 += *((__local half *)in8_7 + ic) * (*((__global half *)w8 + ic));
|
88 |
+
}
|
89 |
+
out_local[ow + 0] = __builtin_shave_sau_sumx_f16_r(val8_0) + val_0;
|
90 |
+
out_local[ow + 1] = __builtin_shave_sau_sumx_f16_r(val8_1) + val_1;
|
91 |
+
out_local[ow + 2] = __builtin_shave_sau_sumx_f16_r(val8_2) + val_2;
|
92 |
+
out_local[ow + 3] = __builtin_shave_sau_sumx_f16_r(val8_3) + val_3;
|
93 |
+
out_local[ow + 4] = __builtin_shave_sau_sumx_f16_r(val8_4) + val_4;
|
94 |
+
out_local[ow + 5] = __builtin_shave_sau_sumx_f16_r(val8_5) + val_5;
|
95 |
+
out_local[ow + 6] = __builtin_shave_sau_sumx_f16_r(val8_6) + val_6;
|
96 |
+
out_local[ow + 7] = __builtin_shave_sau_sumx_f16_r(val8_7) + val_7;
|
97 |
+
}
|
98 |
+
for (uint ow = (OW & (~0x7)); ow < OW; ow++) {
|
99 |
+
|
100 |
+
uint iw = ow;
|
101 |
+
uint ih = oh;
|
102 |
+
|
103 |
+
half8 val8 = 0.0f;
|
104 |
+
|
105 |
+
__local half8 *in8 = (__local half8 *)(&in_local[iw * IC]);
|
106 |
+
|
107 |
+
for (uint ic = 0; ic < IC / 8; ++ic) {
|
108 |
+
val8 += (in8[ic]) * (w8[ic]);
|
109 |
+
}
|
110 |
+
|
111 |
+
half val = 0.0f;
|
112 |
+
for (uint ic = (IC & (~0x7)); ic < IC; ++ic) {
|
113 |
+
val += (*((__local half *)in8 + ic)) * (*((__global half *)w8 + ic));
|
114 |
+
}
|
115 |
+
out_local[ow] = __builtin_shave_sau_sumx_f16_r(val8) + val;
|
116 |
+
}
|
117 |
+
|
118 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
119 |
+
|
120 |
+
event_t e2 = async_work_group_copy(
|
121 |
+
out + get_group_id(1) * OW * OH + get_group_id(0) * OW,
|
122 |
+
out_local,
|
123 |
+
OW,
|
124 |
+
0);
|
125 |
+
wait_group_events(1, &e2);
|
126 |
+
}
|
openvino/vpu_custom_kernels/convolution3x3.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:021bb40840ff35506972e6f6a7dea1b5f40a8db0927aaa9a6c116b152e386851
|
3 |
+
size 5748
|
openvino/vpu_custom_kernels/convolution3x3.cl
ADDED
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Copyright (C) 2018-2022 Intel Corporation
|
2 |
+
// SPDX-License-Identifier: Apache-2.0
|
3 |
+
//
|
4 |
+
|
5 |
+
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
|
6 |
+
#pragma OPENCL EXTENSION cl_khr_extended_async_copies : enable
|
7 |
+
|
8 |
+
__kernel void Convolution3x3(
|
9 |
+
const __global half *in_param,
|
10 |
+
const __global half *out,
|
11 |
+
const __global half *w,
|
12 |
+
int IW,
|
13 |
+
int IH,
|
14 |
+
int IC,
|
15 |
+
int OW,
|
16 |
+
int OH,
|
17 |
+
int OC,
|
18 |
+
int KX,
|
19 |
+
int KY,
|
20 |
+
int stride_x,
|
21 |
+
int stride_y,
|
22 |
+
int pad_x,
|
23 |
+
int pad_y,
|
24 |
+
int dilation_x,
|
25 |
+
int dilation_y)
|
26 |
+
{
|
27 |
+
__local half in_local[8 * 1024];
|
28 |
+
__local half out_local[8 * 1024];
|
29 |
+
__local half w_local[8 * 1024];
|
30 |
+
|
31 |
+
const int sizePlane = IW * IH;
|
32 |
+
event_t e1 = async_work_group_copy_2D2D(
|
33 |
+
in_local, // dst
|
34 |
+
in_param + get_group_id(0) * stride_y * IW, // src
|
35 |
+
3 * IW, // num_elements_per_line,
|
36 |
+
IC, // num_lines,
|
37 |
+
IW * IH - 3 * IW, // src_line_stride,
|
38 |
+
0, // dst_line_stride,
|
39 |
+
0);
|
40 |
+
wait_group_events(1, &e1);
|
41 |
+
|
42 |
+
const int sizeWeight = IC * 3 * 3;
|
43 |
+
e1 = async_work_group_copy(w_local, w + get_group_id(1) * sizeWeight, sizeWeight, 0);
|
44 |
+
wait_group_events(1, &e1);
|
45 |
+
|
46 |
+
int oh = get_global_id(0);
|
47 |
+
int oc = get_global_id(1);
|
48 |
+
|
49 |
+
__local half *in = (__local half *)in_local + 1;
|
50 |
+
|
51 |
+
int stride;
|
52 |
+
int write_output = 0;
|
53 |
+
__local half *src;
|
54 |
+
|
55 |
+
if ((stride_x == 1) && (stride_y == 1)) {
|
56 |
+
stride = OW / 8;
|
57 |
+
write_output = 1;
|
58 |
+
}
|
59 |
+
if ((stride_x == 2) && (stride_y == 2)) {
|
60 |
+
stride = OW / 4;
|
61 |
+
write_output = 2;
|
62 |
+
}
|
63 |
+
|
64 |
+
for (int ow = 0; ow < stride; ow++) {
|
65 |
+
float8 val = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
|
66 |
+
for (int ic = 0; ic < IC; ++ic) {
|
67 |
+
src = (__local half *)((__local half8 *)(in + ic * IW * 3) + ow);
|
68 |
+
__local half *k = (__local half *)(w_local + ic * 3 * 3);
|
69 |
+
|
70 |
+
half8 aux_in00 = *((__local half8 *)src - 1);
|
71 |
+
half8 aux_in01 = *((__local half8 *)src + 0);
|
72 |
+
half8 aux_in02 = *((__local half8 *)src + 1);
|
73 |
+
half8 aux_in10 = *((__local half8 *)(src + IW) - 1);
|
74 |
+
half8 aux_in11 = *((__local half8 *)(src + IW) + 0);
|
75 |
+
half8 aux_in12 = *((__local half8 *)(src + IW) + 1);
|
76 |
+
half8 aux_in20 = *((__local half8 *)(src + IW * 2) - 1);
|
77 |
+
half8 aux_in21 = *((__local half8 *)(src + IW * 2) + 0);
|
78 |
+
half8 aux_in22 = *((__local half8 *)(src + IW * 2) + 1);
|
79 |
+
|
80 |
+
short8 in00 = *((short8 *)&aux_in00);
|
81 |
+
short8 in01 = *((short8 *)&aux_in01);
|
82 |
+
short8 in02 = *((short8 *)&aux_in02);
|
83 |
+
short8 in10 = *((short8 *)&aux_in10);
|
84 |
+
short8 in11 = *((short8 *)&aux_in11);
|
85 |
+
short8 in12 = *((short8 *)&aux_in12);
|
86 |
+
short8 in20 = *((short8 *)&aux_in20);
|
87 |
+
short8 in21 = *((short8 *)&aux_in21);
|
88 |
+
short8 in22 = *((short8 *)&aux_in22);
|
89 |
+
|
90 |
+
short8 aux_aux00 = __builtin_shave_cmu_alignvec_rri_short8(in00, in01, 14);
|
91 |
+
short8 aux_aux01 = in01;
|
92 |
+
short8 aux_aux02 = __builtin_shave_cmu_alignvec_rri_short8(in01, in02, 2);
|
93 |
+
short8 aux_aux10 = __builtin_shave_cmu_alignvec_rri_short8(in10, in11, 14);
|
94 |
+
short8 aux_aux11 = in11;
|
95 |
+
short8 aux_aux12 = __builtin_shave_cmu_alignvec_rri_short8(in11, in12, 2);
|
96 |
+
short8 aux_aux20 = __builtin_shave_cmu_alignvec_rri_short8(in20, in21, 14);
|
97 |
+
short8 aux_aux21 = in21;
|
98 |
+
short8 aux_aux22 = __builtin_shave_cmu_alignvec_rri_short8(in21, in22, 2);
|
99 |
+
|
100 |
+
half8 aux00 = *((half8 *)&aux_aux00);
|
101 |
+
half8 aux01 = *((half8 *)&aux_aux01);
|
102 |
+
half8 aux02 = *((half8 *)&aux_aux02);
|
103 |
+
half8 aux10 = *((half8 *)&aux_aux10);
|
104 |
+
half8 aux11 = *((half8 *)&aux_aux11);
|
105 |
+
half8 aux12 = *((half8 *)&aux_aux12);
|
106 |
+
half8 aux20 = *((half8 *)&aux_aux20);
|
107 |
+
half8 aux21 = *((half8 *)&aux_aux21);
|
108 |
+
half8 aux22 = *((half8 *)&aux_aux22);
|
109 |
+
|
110 |
+
half8 w00 = (half8)(*(k + 0));
|
111 |
+
half8 w01 = (half8)(*(k + 1));
|
112 |
+
half8 w02 = (half8)(*(k + 2));
|
113 |
+
half8 w10 = (half8)(*(k + 3));
|
114 |
+
half8 w11 = (half8)(*(k + 4));
|
115 |
+
half8 w12 = (half8)(*(k + 5));
|
116 |
+
half8 w20 = (half8)(*(k + 6));
|
117 |
+
half8 w21 = (half8)(*(k + 7));
|
118 |
+
half8 w22 = (half8)(*(k + 8));
|
119 |
+
|
120 |
+
val += convert_float8(aux00) * convert_float8(w00);
|
121 |
+
val += convert_float8(aux01) * convert_float8(w01);
|
122 |
+
val += convert_float8(aux02) * convert_float8(w02);
|
123 |
+
val += convert_float8(aux10) * convert_float8(w10);
|
124 |
+
val += convert_float8(aux11) * convert_float8(w11);
|
125 |
+
val += convert_float8(aux12) * convert_float8(w12);
|
126 |
+
val += convert_float8(aux20) * convert_float8(w20);
|
127 |
+
val += convert_float8(aux21) * convert_float8(w21);
|
128 |
+
val += convert_float8(aux22) * convert_float8(w22);
|
129 |
+
}
|
130 |
+
if (write_output == 2) *((__local half4 *)(out_local) + ow) = convert_half4(val.s0246);
|
131 |
+
if (write_output == 1) *((__local half8 *)(out_local) + ow) = convert_half8(val);
|
132 |
+
}
|
133 |
+
|
134 |
+
for (int ow = OW & ~(0x7); ow < OW; ow++) {
|
135 |
+
float val = 0.0f;
|
136 |
+
for (int ic = 0; ic < IC; ++ic) {
|
137 |
+
for (int ky = 0; ky < 3; ++ky) {
|
138 |
+
for (int kx = 0; kx < 3; ++kx) {
|
139 |
+
int iw = ow * stride_x - pad_x + kx * dilation_x;
|
140 |
+
int ih = oh * stride_y - pad_y + ky * dilation_y;
|
141 |
+
|
142 |
+
val += convert_float(in[ic * IW * 3 + (ky * dilation_y) * IW + iw])
|
143 |
+
* convert_float(w_local[ic * 3 * 3 + ky * 3 + kx]);
|
144 |
+
}
|
145 |
+
}
|
146 |
+
}
|
147 |
+
out_local[ow] = convert_half(val);
|
148 |
+
}
|
149 |
+
|
150 |
+
barrier(CLK_LOCAL_MEM_FENCE);
|
151 |
+
|
152 |
+
event_t e2 = async_work_group_copy(
|
153 |
+
out + get_group_id(1) * OW * OH + get_group_id(0) * OW,
|
154 |
+
out_local,
|
155 |
+
OW,
|
156 |
+
0);
|
157 |
+
wait_group_events(1, &e2);
|
158 |
+
}
|