Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 76956dc

Browse files
feat: AMD hardware API (#1797)
* feat: add amd gpu windows * chore: remove unused code * feat: get amd gpus * fix: clean * chore: cleanup * fix: set activate * fix: build windows * feat: linux * fix: add patches * fix: map cuda gpus * fix: build * chore: docs * fix: build * chore: clean up * fix: build * fix: build * chore: pack vulkan windows * chore: vulkan linux --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent f8c1df6 commit 76956dc

31 files changed

+9598
-37
lines changed

docs/docs/architecture/cortex-db.mdx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import TabItem from "@theme/TabItem";
1414
This document outlines the architecture of the database designed to store and manage various types of entities and their associated metadata.
1515

1616
## Table Structure
17+
### schema Table
18+
The `schema` table is designed to hold schema version for cortex database. Below is the structure of the table:
19+
20+
| Column Name | Data Type | Description |
21+
|--------------------|-----------|---------------------------------------------------------|
22+
| schema_version | INTEGER | A unique schema version for database. |
23+
1724
### models Table
1825
The `models` table is designed to hold metadata about various AI models. Below is the structure of the table:
1926

@@ -22,4 +29,23 @@ The `models` table is designed to hold metadata about various AI models. Below i
2229
| model_id | TEXT | A unique identifier for each model (Primary Key). |
2330
| author_repo_id | TEXT | The identifier for the repository where the model is stored. |
2431
| branch_name | TEXT | The branch name in the repository that contains the model. |
25-
| path_to_model_yaml | TEXT | The file path to the YAML configuration file for the model. |
32+
| path_to_model_yaml | TEXT | The file path to the YAML configuration file for the model. |
33+
| model_alias | TEXT | The optional alias or friendly name for the model. |
34+
| model_format | TEXT | The format or type of the model (e.g., TensorFlow, PyTorch, GGUF, etc.). |
35+
| model_source | TEXT | The source or origin of the model (e.g., a URL or file path). |
36+
| status | TEXT | Current status of the model (e.g., "downloaded", "downloadable").. |
37+
| engine | TEXT | The name or identifier of the engine or framework used for running or deploying the model.. |
38+
| metadata | TEXT | Additional metadata or information about the model, such as a JSON string containing various attributes or properties. |
39+
40+
### hardware Table
41+
The `hardware` table is designed to hold metadata about hardware information. Below is the structure of the table:
42+
43+
| Column Name | Data Type | Description |
44+
|--------------------|-----------|---------------------------------------------------------|
45+
| uuid | TEXT | the primary key for the table, meaning that each row must have a unique value in this column. |
46+
| type | TEXT | The type of hardware. |
47+
| hardware_id | INTEGER | An integer value representing the hardware ID. |
48+
| software_id | INTEGER | An integer value representing the software ID associated with the hardware. |
49+
| activated | INTEGER | A boolean value (0 or 1) indicating whether the hardware is activated or not. |
50+
| priority | INTEGER | An integer value representing the priority associated with the hardware. |
51+

engine/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*.so
3333
*.so.*
3434
*.dylib
35+
!**/libvulkan.so
3536

3637
# Executables
3738
*.exe

engine/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ endif()
6868

6969
add_subdirectory(cli)
7070

71+
72+
7173
find_package(jsoncpp CONFIG REQUIRED)
7274
find_package(Drogon CONFIG REQUIRED)
7375
find_package(yaml-cpp CONFIG REQUIRED)

engine/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ ifeq ($(OS),Windows_NT)
7373
@powershell -Command "mkdir -p cortex;"
7474
@powershell -Command "cp build\cortex-server.exe .\cortex\$(DESTINATION_BINARY_SERVER_NAME).exe;"
7575
@powershell -Command "cp build\cortex.exe .\cortex\$(DESTINATION_BINARY_NAME).exe;"
76+
@powershell -Command "cp ..\engine\deps\windows\vulkan-1.dll .\cortex\;"
7677
@powershell -Command "cp ..\.github\patches\windows\msvcp140.dll .\cortex\;"
7778
@powershell -Command "cp ..\.github\patches\windows\vcruntime140_1.dll .\cortex\;"
7879
@powershell -Command "cp ..\.github\patches\windows\vcruntime140.dll .\cortex\;"
7980
else ifeq ($(shell uname -s),Linux)
8081
@mkdir -p cortex; \
8182
cp build/cortex-server cortex/$(DESTINATION_BINARY_SERVER_NAME); \
82-
cp build/cortex cortex/$(DESTINATION_BINARY_NAME);
83+
cp build/cortex cortex/$(DESTINATION_BINARY_NAME); \
84+
cp ../engine/deps/linux/libvulkan.so cortex/libvulkan.so;
8385
else
8486
@mkdir -p cortex; \
8587
cp build/cortex-server cortex/$(DESTINATION_BINARY_SERVER_NAME); \

engine/cli/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,9 @@ set_target_properties(${TARGET_NAME} PROPERTIES
140140
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
141141
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
142142
)
143+
144+
if(UNIX AND NOT APPLE)
145+
configure_file("${PROJECT_SOURCE_DIR}/../deps/linux/libvulkan.so" "${CMAKE_BINARY_DIR}/libvulkan.so" COPYONLY)
146+
elseif(MSVC)
147+
configure_file("${PROJECT_SOURCE_DIR}/../deps/windows/vulkan-1.dll" "${CMAKE_BINARY_DIR}/vulkan-1.dll" COPYONLY)
148+
endif()

engine/cli/commands/hardware_list_cmd.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ bool HardwareListCmd::Exec(const std::string& host, int port,
130130
std::get<cortex::hw::NvidiaAddInfo>(gpu.add_info).compute_cap);
131131
row.emplace_back(gpu.is_activated ? "Yes" : "No");
132132
table.add_row({row.begin(), row.end()});
133+
count++;
133134
}
134135

135136
std::cout << table << std::endl;

engine/common/hardware_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct AmdAddInfo {};
6464
using GPUAddInfo = std::variant<NvidiaAddInfo, AmdAddInfo>;
6565
struct GPU {
6666
std::string id;
67+
uint32_t device_id;
6768
std::string name;
6869
std::string version;
6970
GPUAddInfo add_info;
@@ -77,7 +78,7 @@ inline Json::Value ToJson(const std::vector<GPU>& gpus) {
7778
Json::Value res(Json::arrayValue);
7879
for (size_t i = 0; i < gpus.size(); i++) {
7980
Json::Value gpu;
80-
gpu["id"] = std::to_string(i);
81+
gpu["id"] = gpus[i].id;
8182
gpu["name"] = gpus[i].name;
8283
gpu["version"] = gpus[i].version;
8384
Json::Value add_info;

engine/database/hardware.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,41 @@ cpp::result<bool, std::string> Hardware::DeleteHardwareEntry(
9898
return cpp::fail(e.what());
9999
}
100100
}
101+
102+
bool Hardware::HasHardwareEntry(const std::string& id) {
103+
try {
104+
SQLite::Statement query(db_,
105+
"SELECT COUNT(*) FROM hardware WHERE uuid = ?");
106+
query.bind(1, id);
107+
if (query.executeStep()) {
108+
return query.getColumn(0).getInt() > 0;
109+
}
110+
return false;
111+
} catch (const std::exception& e) {
112+
CTL_WRN(e.what());
113+
return false;
114+
}
115+
}
116+
117+
cpp::result<bool, std::string> Hardware::UpdateHardwareEntry(const std::string& id,
118+
int hw_id,
119+
int sw_id) const {
120+
try {
121+
SQLite::Statement upd(
122+
db_,
123+
"UPDATE hardware "
124+
"SET hardware_id = ?, software_id = ? "
125+
"WHERE uuid = ?");
126+
upd.bind(1, hw_id);
127+
upd.bind(2, sw_id);
128+
upd.bind(3, id);
129+
if (upd.exec() == 1) {
130+
CTL_INF("Updated: " << id << " " << hw_id << " " << sw_id);
131+
return true;
132+
}
133+
return false;
134+
} catch (const std::exception& e) {
135+
return cpp::fail(e.what());
136+
}
137+
}
101138
} // namespace cortex::db

engine/database/hardware.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ class Hardware {
4343
cpp::result<bool, std::string> UpdateHardwareEntry(
4444
const std::string& id, const HardwareEntry& updated_entry);
4545
cpp::result<bool, std::string> DeleteHardwareEntry(const std::string& id);
46+
bool HasHardwareEntry(const std::string& id);
47+
cpp::result<bool, std::string> UpdateHardwareEntry(const std::string& id,
48+
int hw_id,
49+
int sw_id) const;
4650
};
4751
} // namespace cortex::db

engine/deps/linux/libvulkan.so

3.41 MB
Binary file not shown.

0 commit comments

Comments
 (0)