Skip to content

Commit

Permalink
update cortex-cpp run path and engines directory - support vulkan
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Jul 9, 2024
1 parent e976635 commit 7c01b8a
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 183 deletions.
14 changes: 14 additions & 0 deletions cortex-cpp/addon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "cortex-common/cortexpythoni.h"
#include "utils/cortex_utils.h"
#include "utils/dylib.h"
#include <stdlib.h>

#if defined(__APPLE__) && defined(__MACH__)
#include <libgen.h> // for dirname()
Expand Down Expand Up @@ -59,6 +60,19 @@ void stop() {
Napi::Value Start(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();

LOG_INFO << "set env";
Napi::Object objs = info[0].As<Napi::Value>().ToObject();
Napi::Array props = objs.GetPropertyNames();

for (unsigned int i = 0; i < props.Length(); i++)
{
Napi::Value key = props.Get(i);
LOG_INFO << key.ToString().Utf8Value();
LOG_INFO << objs.Get(key).ToString().Utf8Value();
setenv(key.ToString().Utf8Value().c_str(), objs.Get(key).ToString().Utf8Value().c_str(), 1);
}

start();
return Napi::String::New(env, "Server started successfully");
}
Expand Down
4 changes: 2 additions & 2 deletions cortex-cpp/binding/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

/// <reference types="node" />
declare module "cortex-cpp" {
start();
stop();
export function start();
export function stop();
}
12 changes: 8 additions & 4 deletions cortex-cpp/controllers/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ void server::FineTuning(
if (engines_.find(engine_type) == engines_.end()) {
try {
std::string abs_path =
cortex_utils::GetCurrentPath() + cortex_utils::kPythonRuntimeLibPath;
(getenv("ENGINE_PATH") ? getenv("ENGINE_PATH")
: cortex_utils::GetCurrentPath()) +
cortex_utils::kPythonRuntimeLibPath;
engines_[engine_type].dl =
std::make_unique<cortex_cpp::dylib>(abs_path, "engine");
} catch (const cortex_cpp::dylib::load_error& e) {
Expand Down Expand Up @@ -262,9 +264,9 @@ void server::LoadModel(const HttpRequestPtr& req,
auto get_engine_path = [](std::string_view e) {
if (e == kLlamaEngine) {
return cortex_utils::kLlamaLibPath;
} else if(e == kOnnxEngine) {
} else if (e == kOnnxEngine) {
return cortex_utils::kOnnxLibPath;
} else if(e == kTensorrtLlmEngine) {
} else if (e == kTensorrtLlmEngine) {
return cortex_utils::kTensorrtLlmPath;
}
return cortex_utils::kLlamaLibPath;
Expand All @@ -277,7 +279,9 @@ void server::LoadModel(const HttpRequestPtr& req,
}

std::string abs_path =
cortex_utils::GetCurrentPath() + get_engine_path(engine_type);
(getenv("ENGINE_PATH") ? getenv("ENGINE_PATH")
: cortex_utils::GetCurrentPath()) +
get_engine_path(engine_type);
engines_[engine_type].dl =
std::make_unique<cortex_cpp::dylib>(abs_path, "engine");

Expand Down
1 change: 1 addition & 0 deletions cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cli-progress": "^3.12.0",
"cortex-cpp": "^0.4.23",
"cortexso-node": "^0.0.4",
"cpu-instructions": "^0.0.11",
"decompress": "^4.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ export class ModelStartCommand extends CommandRunner {
if (
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
) {
const engineSpinner = ora('Installing engine...').start();
await this.initUsecases.installEngine(undefined, 'latest', engine);
engineSpinner.succeed();
}

// Attached - stdout logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export class RunCommand extends CommandRunner {
if (
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
) {
const engineSpinner = ora('Installing engine...').start();
await this.initUsecases.installEngine(undefined, 'latest', engine);
engineSpinner.succeed('Engine installed');
}

return this.cortexUsecases
Expand Down
Loading

0 comments on commit 7c01b8a

Please sign in to comment.