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

Commit 6e96a08

Browse files
committed
Add log for AVX2 and create log_utils
1 parent 8f6bddc commit 6e96a08

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

controllers/llamaCPP.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
#include <fstream>
44
#include <iostream>
55
#include "log.h"
6+
#include "utils/nitro_utils.h"
7+
#include "utils/logging_utils.h"
68

79
// External
810
#include "common.h"
911
#include "llama.h"
1012

11-
#include "log.h"
12-
#include "utils/nitro_utils.h"
13-
1413
using namespace inferences;
1514
using json = nlohmann::json;
1615

@@ -189,7 +188,7 @@ void llamaCPP::InferenceImpl(
189188
inferences::ChatCompletionRequest&& completion,
190189
std::function<void(const HttpResponsePtr&)>& callback) {
191190
std::string formatted_output = pre_prompt;
192-
int request_id = ++no_of_inference_requests;
191+
int request_id = ++no_of_requests;
193192
LOG_INFO_REQUEST(request_id) << "Generating reponse for inference request";
194193

195194
json data;
@@ -464,7 +463,7 @@ void llamaCPP::Embedding(
464463
void llamaCPP::EmbeddingImpl(
465464
std::shared_ptr<Json::Value> jsonBody,
466465
std::function<void(const HttpResponsePtr&)>& callback) {
467-
int request_id = ++no_of_inference_requests;
466+
int request_id = ++no_of_requests;
468467
LOG_INFO_REQUEST(request_id) << "Generating reponse for embedding request";
469468
// Queue embedding task
470469
auto state = create_inference_state(this);
@@ -559,6 +558,9 @@ void llamaCPP::LoadModel(
559558
return;
560559
}
561560

561+
if (!nitro_utils::isAVX2Supported() && ggml_cpu_has_avx2())
562+
LOG_ERROR << "AVX2 is not supported by your processor, please download and replace the correct Nitro asset version";
563+
562564
const auto& jsonBody = req->getJsonObject();
563565
if (!LoadModelImpl(jsonBody)) {
564566
// Error occurred during model loading

controllers/llamaCPP.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
#define SERVER_VERBOSE 1
2828
#endif
2929

30-
#define LOG_INFO_REQUEST(RID) LOG_INFO << "Request " << RID << ": "
31-
#define LOG_WARN_REQUEST(RID) LOG_WARN << "Request " << RID << ": "
32-
#define LOG_ERROR_REQUEST(RID) LOG_ERROR << "Request " << RID << ": "
33-
3430
using json = nlohmann::json;
3531

3632
using namespace drogon;
@@ -89,7 +85,7 @@ class llamaCPP : public drogon::HttpController<llamaCPP>,
8985
std::string pre_prompt;
9086
int repeat_last_n;
9187
bool caching_enabled;
92-
std::atomic<int> no_of_inference_requests = 0;
88+
std::atomic<int> no_of_requests = 0;
9389
std::atomic<int> no_of_chats = 0;
9490
int clean_cache_threshold;
9591
std::string grammar_file_content;

utils/logging_utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#define LOG_INFO_REQUEST(RID) LOG_INFO << "Request " << RID << ": "
4+
#define LOG_WARN_REQUEST(RID) LOG_WARN << "Request " << RID << ": "
5+
#define LOG_ERROR_REQUEST(RID) LOG_ERROR << "Request " << RID << ": "

utils/nitro_utils.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
#include <ostream>
1111
#include <regex>
1212
#include <vector>
13-
// Include platform-specific headers
13+
14+
#if defined(__GNUC__) || defined(__clang__)
15+
#include <cpuid.h>
16+
#elif defined(_MSC_VER)
17+
#include <intrin.h>
18+
#endif
19+
1420
#ifdef _WIN32
1521
#include <winsock2.h>
1622
#include <windows.h>
@@ -174,6 +180,25 @@ inline std::string generate_random_string(std::size_t length) {
174180
return random_string;
175181
}
176182

183+
inline bool isAVX2Supported() {
184+
#if defined(__GNUC__) || defined(__clang__)
185+
unsigned eax, ebx, ecx, edx;
186+
if (__get_cpuid_max(0, nullptr) < 7) return false;
187+
188+
__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx);
189+
return (ebx & (1 << 5)) != 0;
190+
#elif defined(_MSC_VER)
191+
int cpuInfo[4];
192+
__cpuid(cpuInfo, 0);
193+
int nIds = cpuInfo[0];
194+
if (nIds >= 7) {
195+
__cpuidex(cpuInfo, 7, 0);
196+
return (cpuInfo[1] & (1 << 5)) != 0;
197+
}
198+
return false;
199+
#endif
200+
}
201+
177202
inline void nitro_logo() {
178203
std::string rainbowColors[] = {
179204
"\033[93m", // Yellow

0 commit comments

Comments
 (0)