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

[EdgeTPU] Bind CFG creation to backend #1743

Draft
wants to merge 2 commits into
base: main
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
50 changes: 29 additions & 21 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 @@ -1138,19 +1139,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 @@ -1165,7 +1155,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 @@ -1176,19 +1165,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 @@ -1204,13 +1208,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