+
+ Intermediate_tensors
+
+
+
+ This option cannot be with 'search delegate'
+
+
+
+
+
+ Show Operations
+
+
+
+ Print the log showing operations that mapped to the Edge TPU.
+
+
+
+
+
+ Search Delegate
+
+
+
+ Enable repeated search for a new compilation stopping point earlier in the graph, to avoid rare compiler failures when it encounters an unsupported operation.
+
+
+
+
+
+ Delegate Search Step
+
+
+
+ Specify a step size (the number of ops to move backward)
+ Default size is 1 and the mindest size is also 1.
+
+
+
+
+
+
+
+
+
+
diff --git a/media/EdgeTPUCfgEditor/displaycfg.js b/media/EdgeTPUCfgEditor/displaycfg.js
new file mode 100644
index 00000000..f0a0cf60
--- /dev/null
+++ b/media/EdgeTPUCfgEditor/displaycfg.js
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export function displayCfgToEditor(cfg) {
+ const edgeTPUCompiler = cfg["edgetpu-compiler"];
+ document.getElementById("checkboxEdgeTPUCompile").checked = cfgBoolean(
+ edgeTPUCompiler["edgetpu-compile"]
+ );
+ document.getElementById("checkboxEdgeTPUProfile").checked = cfgBoolean(
+ edgeTPUCompiler["edgetpu-profile"]
+ );
+
+ const edgeTPUCompile = cfg["edgetpu-compile"];
+ document.getElementById("EdgeTPUInputPath").value = cfgString(
+ edgeTPUCompile?.["input_path"]
+ );
+ document.getElementById("EdgeTPUOutputPath").value = cfgString(
+ edgeTPUCompile?.["output_path"]
+ );
+ document.getElementById("EdgeTPUIntermediateTensorsInputArrays").value =
+ cfgString(edgeTPUCompile?.["intermediate_tensors"]);
+ document.getElementById("EdgeTPUShowOperations").checked = cfgBoolean(
+ edgeTPUCompile?.["show_operations"]
+ );
+ document.getElementById("EdgeTPUSearchDelegate").checked = cfgBoolean(
+ edgeTPUCompile?.["search_delegate"]
+ );
+ document.getElementById("EdgeTPUDelegateSearchStep").value = cfgString(
+ edgeTPUCompile?.["delegate_search_step"],
+ "1"
+ );
+}
+
+function cfgString(str, defaultStr = "") {
+ if (str === null || str === undefined) {
+ return defaultStr;
+ }
+ return str.trim();
+}
+
+function cfgBoolean(str) {
+ if (str === null || str === undefined) {
+ return false;
+ }
+
+ if (str === "True") {
+ return true;
+ }
+
+ return false;
+}
diff --git a/media/EdgeTPUCfgEditor/index.js b/media/EdgeTPUCfgEditor/index.js
new file mode 100644
index 00000000..44cad82f
--- /dev/null
+++ b/media/EdgeTPUCfgEditor/index.js
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { displayCfgToEditor } from "./displaycfg.js";
+import {
+ applyUpdates,
+ updateEdgeTPUStep,
+ updateEdgeTPUCompile,
+} from "./updateContent.js";
+import { updateStepUI } from "./updateUI.js";
+import { postMessageToVsCode } from "./vscodeapi.js";
+
+// Just like a regular webpage we need to wait for the webview
+// DOM to load before we can reference any of the HTML elements
+// or toolkit components
+window.addEventListener("load", main);
+
+// Main function that gets executed once the webview DOM loads
+function main() {
+ registerCompilerStep();
+ registerCompileOptions();
+ registerCodiconEvents();
+
+ // event from vscode extension
+ window.addEventListener("message", (event) => {
+ const message = event.data;
+ switch (message.type) {
+ case "displayCfgToEditor":
+ displayCfgToEditor(message.text);
+ break;
+ case "setDefaultEdgetpuValues":
+ setDefaultEdgetpuValues(message.name);
+ break;
+ case "applyDialogPath":
+ document.getElementById(message.elemID).value = message.path;
+ switch (message.step) {
+ case "EdgeTPUCompile":
+ updateEdgeTPUCompile();
+ break;
+ default:
+ break;
+ }
+ applyUpdates();
+ break;
+ default:
+ break;
+ }
+ });
+
+ postMessageToVsCode({ type: "requestDisplayCfg" });
+}
+
+function setDefaultEdgetpuValues(name) {
+ // EdgeTPu COmpiler steps
+ document.getElementById("checkboxEdgeTPUCompile").checked = true;
+
+ updateEdgeTPUStep();
+
+ // compile step
+ let compiledName = name + ".tflite";
+ let compiledExt = name + "_edgetpu.tflite";
+ document.getElementById("EdgeTPUInputPath").value = compiledName;
+ document.getElementById("EdgeTPUOutputPath").value = compiledExt;
+
+ updateEdgeTPUCompile();
+
+ // apply
+ applyUpdates();
+}
+
+function registerCompilerStep() {
+ const checkboxEdgeTPUCompile = document.getElementById(
+ "checkboxEdgeTPUCompile"
+ );
+ const checkboxEdgeTPUProfile = document.getElementById(
+ "checkboxEdgeTPUProfile"
+ );
+ const stepEdgeTPUCompile = document.getElementById("stepEdgeTPUCompile");
+ const stepEdgeTPUProfile = document.getElementById("stepEdgeTPUProfile");
+
+ checkboxEdgeTPUCompile.addEventListener("click", function () {
+ updateEdgeTPUStep();
+ applyUpdates();
+ });
+ checkboxEdgeTPUProfile.addEventListener("click", function () {
+ updateEdgeTPUStep();
+ applyUpdates();
+ });
+
+ stepEdgeTPUCompile.addEventListener("click", function () {
+ updateStepUI("EdgeTPUCompile");
+ });
+ stepEdgeTPUProfile.addEventListener("click", function () {
+ updateStepUI("EdgeTPUProfile");
+ });
+}
+
+function registerCompileOptions() {
+ const edgeTPUInputPath = document.getElementById("EdgeTPUInputPath");
+ const edgeTPUIntermediateTensors = document.getElementById(
+ "EdgeTPUIntermediateTensorsInputArrays"
+ );
+ const edgeTPUShowOperations = document.getElementById(
+ "EdgeTPUShowOperations"
+ );
+ const edgeTPUSearchDelegate = document.getElementById(
+ "EdgeTPUSearchDelegate"
+ );
+ const edgeTPUDelegateSearchStep = document.getElementById(
+ "EdgeTPUDelegateSearchStep"
+ );
+ const edgeTPUDelegateSearchStepDiv = document.getElementById(
+ "EdgeTPUDelegateSearchStepDiv"
+ );
+
+ edgeTPUInputPath.addEventListener("input", function () {
+ updateEdgeTPUCompile();
+ applyUpdates();
+ });
+ edgeTPUIntermediateTensors.addEventListener("input", function () {
+ if (edgeTPUSearchDelegate.checked) {
+ edgeTPUSearchDelegate.checked = false;
+ edgeTPUDelegateSearchStepDiv.style.display = "none";
+ }
+ updateEdgeTPUCompile();
+ applyUpdates();
+ });
+ edgeTPUShowOperations.addEventListener("click", function () {
+ updateEdgeTPUCompile();
+ applyUpdates();
+ });
+ edgeTPUSearchDelegate.addEventListener("click", function () {
+ if (edgeTPUSearchDelegate.checked) {
+ edgeTPUIntermediateTensors.value = "";
+ edgeTPUDelegateSearchStepDiv.style.display = "block";
+ } else {
+ edgeTPUDelegateSearchStepDiv.style.display = "none";
+ }
+ updateEdgeTPUCompile();
+ applyUpdates();
+ });
+ edgeTPUDelegateSearchStep.addEventListener("input", function () {
+ edgeTPUDelegateSearchStep.value =
+ edgeTPUDelegateSearchStep.value < 1
+ ? "1"
+ : edgeTPUDelegateSearchStep.value;
+ updateEdgeTPUCompile();
+ applyUpdates();
+ });
+}
+
+function registerCodiconEvents() {
+ document
+ .getElementById("EdgeTPUInputPathSearch")
+ .addEventListener("click", function () {
+ postMessageToVsCode({
+ type: "getPathByDialog",
+ isFolder: false,
+ ext: ["tflite"],
+ oldPath: document.getElementById("EdgeTPUInputPath").value,
+ postStep: "EdgeTPUCompile",
+ postElemID: "EdgeTPUInputPath",
+ });
+ });
+}
diff --git a/media/EdgeTPUCfgEditor/updateContent.js b/media/EdgeTPUCfgEditor/updateContent.js
new file mode 100644
index 00000000..f4dee594
--- /dev/null
+++ b/media/EdgeTPUCfgEditor/updateContent.js
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { postMessageToVsCode } from "./vscodeapi.js";
+
+function iniKeyValueString(iniKey, iniValue, noEffectValue = undefined) {
+ if (iniValue === null || iniValue === undefined) {
+ return "";
+ }
+
+ if (iniValue === false) {
+ return "";
+ } else if (iniValue === true) {
+ return iniKey + "=True\n";
+ }
+
+ const trimmedValue = iniValue.trim();
+ if (trimmedValue === "" || trimmedValue === noEffectValue) {
+ return "";
+ }
+
+ return iniKey + "=" + trimmedValue + "\n";
+}
+
+export function applyUpdates() {
+ postMessageToVsCode({ type: "updateDocument" });
+}
+
+export function updateEdgeTPUStep() {
+ postMessageToVsCode({
+ type: "setParam",
+ section: "edgetpu-compiler",
+ param: "edgetpu-compile",
+ value: document.getElementById("checkboxEdgeTPUCompile").checked
+ ? "True"
+ : "False",
+ });
+ postMessageToVsCode({
+ type: "setParam",
+ section: "edgetpu-compiler",
+ param: "edgetpu-profile",
+ value: document.getElementById("checkboxEdgeTPUProfile").checked
+ ? "True"
+ : "False",
+ });
+}
+
+function addPostfixToFileName(filePath = "", postfix = "") {
+ if (filePath.trim() === "") {
+ return "";
+ }
+ const parts = filePath.split(".");
+ let newFilePath = "";
+ if (parts.length < 2) {
+ newFilePath = `${filePath}${postfix}`;
+ } else {
+ const fileName = parts.slice(0, -1).join(".");
+ const fileExtension = parts[parts.length - 1];
+ const newFileName = `${fileName}${postfix}`;
+ newFilePath = `${newFileName}.${fileExtension}`;
+ }
+
+ return newFilePath;
+}
+
+export function updateEdgeTPUCompile() {
+ let content = "";
+ content += iniKeyValueString(
+ "input_path",
+ document.getElementById("EdgeTPUInputPath").value
+ );
+ content += iniKeyValueString(
+ "output_path",
+ addPostfixToFileName(
+ document.getElementById("EdgeTPUInputPath").value,
+ "_edgetpu"
+ )
+ );
+ content += iniKeyValueString(
+ "intermediate_tensors",
+ document.getElementById("EdgeTPUIntermediateTensorsInputArrays").value
+ );
+ content += iniKeyValueString(
+ "show_operations",
+ document.getElementById("EdgeTPUShowOperations").checked
+ );
+ content += iniKeyValueString(
+ "search_delegate",
+ document.getElementById("EdgeTPUSearchDelegate").checked
+ );
+ content += iniKeyValueString(
+ "delegate_search_step",
+ document.getElementById("EdgeTPUSearchDelegate").checked
+ ? document.getElementById("EdgeTPUDelegateSearchStep").value < 1
+ ? "1"
+ : document.getElementById("EdgeTPUDelegateSearchStep").value
+ : undefined
+ );
+
+ postMessageToVsCode({
+ type: "setSection",
+ section: "edgetpu-compile",
+ param: content,
+ });
+}
+
+export function updateEdgeTPUProfile() {
+ let content = "";
+
+ postMessageToVsCode({
+ type: "setSection",
+ section: "edgetpu-profile",
+ param: content,
+ });
+}
diff --git a/media/EdgeTPUCfgEditor/updateUI.js b/media/EdgeTPUCfgEditor/updateUI.js
new file mode 100644
index 00000000..2f3f7e0a
--- /dev/null
+++ b/media/EdgeTPUCfgEditor/updateUI.js
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export function updateStepUI(step) {
+ const allOptionPanels = document.querySelectorAll(".optionPanel .options");
+ allOptionPanels.forEach(function (panel) {
+ panel.style.display = "none";
+ });
+
+ const optionPanel = document.getElementById("option" + step);
+ optionPanel.style.display = "block";
+
+ const edgeTPUSearchDelegate = document.getElementById(
+ "EdgeTPUSearchDelegate"
+ );
+ const edgeTPUDelegateSearchStepDiv = document.getElementById(
+ "EdgeTPUDelegateSearchStepDiv"
+ );
+ const edgeTPUIntermediateTensors = document.getElementById(
+ "EdgeTPUIntermediateTensors"
+ );
+
+ if (edgeTPUSearchDelegate.checked) {
+ edgeTPUIntermediateTensors.value = "";
+ edgeTPUDelegateSearchStepDiv.style.display = "block";
+ } else {
+ edgeTPUDelegateSearchStepDiv.style.display = "none";
+ }
+
+ const allSteps = document.querySelectorAll(".statusbar .steps .step");
+ allSteps.forEach(function (step) {
+ step.classList.remove("current");
+ });
+
+ const stepbar = document.getElementById("stepbar" + step);
+ stepbar.classList.add("current");
+}
+
+export function updateEdgeTPUCompileUI() {
+ const allOptionPanels = document.querySelectorAll(".optionPanel .options");
+ allOptionPanels.forEach(function (panel) {
+ panel.style.display = "none";
+ });
+
+ const edgeTPUBasicOptions = document.getElementById(
+ "optionImportEdgeTPUBasic"
+ );
+ const edgeTPUAdvancedOptions = document.getElementById(
+ "optionImportEdgeTPUAdvanced"
+ );
+ const edgeTPUSearchDelegate = document.getElementById(
+ "EdgeTPUSearchDelegate"
+ );
+ const edgeTPUDelegateSearchStepDiv = document.getElementById(
+ "EdgeTPUDelegateSearchStepDiv"
+ );
+
+ edgeTPUBasicOptions.style.display = "none";
+ edgeTPUAdvancedOptions.style.display = "none";
+
+ edgeTPUDelegateSearchStepDiv.style.display = edgeTPUSearchDelegate.checked
+ ? "block"
+ : "none";
+ edgeTPUBasicOptions.style.display = "block";
+ edgeTPUAdvancedOptions.style.display = "block";
+}
diff --git a/media/EdgeTPUCfgEditor/vscodeapi.js b/media/EdgeTPUCfgEditor/vscodeapi.js
new file mode 100644
index 00000000..6cdfaf35
--- /dev/null
+++ b/media/EdgeTPUCfgEditor/vscodeapi.js
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+const vscode = acquireVsCodeApi();
+
+export function postMessageToVsCode(msg) {
+ vscode.postMessage(msg);
+}