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

DRAFT: Bind EdgeTPU features to the backend #1722

Draft
wants to merge 2 commits into
base: ssafy/2023
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/Backend/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const registerBackend = (backend: Backend) => {
// TODO: Consider better way to refresh toolchainView after backend's registration.
vscode.commands.executeCommand("one.toolchain.refresh");
vscode.commands.executeCommand("one.device.refresh");
vscode.commands.executeCommand("one.explorer.refresh");
};

export const API = {
Expand Down
63 changes: 33 additions & 30 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as fs from "fs";
import * as path from "path";
import * as vscode from "vscode";

import { BackendContext } from "../Backend/API";
import { obtainWorkspaceRoots } from "../Utils/Helpers";
import { Logger } from "../Utils/Logger";

Expand Down Expand Up @@ -198,15 +199,10 @@ class NodeFactory {
"Config nodes cannot have attributes"
);
const ext = path.extname(fpath);
switch (ext) {
case ".edgetpucfg": {
node = new ConfigNode(uri, parent, "one.editor.edgetpucfg");
break;
}
case ".cfg":
default: {
node = new ConfigNode(uri, parent);
}
if (BackendContext.isRegistered("EdgeTPU") && ext === ".edgetpucfg") {
node = new ConfigNode(uri, parent, "one.editor.edgetpucfg");
} else {
node = new ConfigNode(uri, parent);
}
break;
}
Expand Down Expand Up @@ -1027,19 +1023,8 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
});
}

/**
* Select the option for the configuration you want to create
* Return information about the selected option
*
* @param modelName A base model's name
* @param extName A base model's extension name
*
*/
private async generateCfgInfo(
modelName: string,
extName: string
): Promise<CfgInfo | undefined> {
//Options must be added according to extension
private async askCfgExt(extName: string): Promise<string | undefined> {
// Options must be added according to extension
const options: vscode.QuickPickItem[] = [
{ label: ".cfg", description: "configuration file of onecc compiler" },
];
Expand All @@ -1054,7 +1039,6 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
const placeHolder = options.map((option) => option.label).join(" / ");

let selectedLabel: string | undefined = ".cfg";
let cfgData: ICfgData | undefined = undefined;

//If options array only has the `.cfg` option, skip selecting it.
if (options.length !== 1) {
Expand All @@ -1065,19 +1049,34 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
selectedLabel = selectedOption?.label;
}

switch (selectedLabel) {
return selectedLabel;
}

/**
* Select the option for the configuration you want to create
* Return information about the selected option
*
* @param modelName A base model's name
* @param extName A base model's extension name
*/
private async generateCfgInfo(
modelName: string,
extName: string,
cfgExt: string
): Promise<CfgInfo> {
let cfgData: ICfgData | undefined = undefined;
switch (cfgExt) {
case ".cfg":
cfgData = new CfgData();
break;
case ".edgetpucfg":
cfgData = new EdgeTPUCfgData();
break;
default:
cfgData = undefined;
break;
throw Error("OneExplorer: Cannot reach here");
}

return cfgData?.generateCfgInfo(modelName, extName);
return cfgData!.generateCfgInfo(modelName, extName);
}

/**
Expand All @@ -1093,13 +1092,17 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
const modelName = path.parse(node.path).name;
const extName = path.parse(node.path).ext.slice(1);

const cfgInfo = await this.generateCfgInfo(modelName, extName);
const cfgExt = BackendContext.isRegistered("EdgeTPU")
? await this.askCfgExt(extName)
: ".cfg";

//When the user presses the ESC button, it is cancelled
if (cfgInfo === undefined) {
if (cfgExt === undefined) {
// When the user presses the ESC button, it is cancelled
return;
}

const cfgInfo = await this.generateCfgInfo(modelName, extName, cfgExt);

// TODO(dayo) Auto-configure more fields
const validateInputPath = (cfgName: string): string | undefined => {
const cfgPath: string = path.join(dirPath, cfgName);
Expand Down
3 changes: 2 additions & 1 deletion src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Logger } from "../Utils/Logger";

import { ConfigObj } from "./ConfigObject";
import { Node, NodeType } from "./OneExplorer";
import { BackendContext } from "../Backend/API";

export {
BaseModelToCfgMap as _unit_test_BaseModelToCfgMap,
Expand Down Expand Up @@ -244,7 +245,7 @@ export class OneStorage {
};

try {
const extList = [".cfg", ".edgetpucfg"];
const extList = BackendContext.isRegistered("EdgeTPU") ? [".cfg", ".edgetpucfg"] : [".cfg"];

return roots
.map((root) =>
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function activate(context: vscode.ExtensionContext) {
MPQSelectionPanel.register(context);

API.registerBackend(new OneToolchain());
API.registerBackend(new EdgeTPUToolchain());
//API.registerBackend(new EdgeTPUToolchain());

// returning backend registration function that will be called by backend extensions
return API;
Expand Down