Skip to content

Commit 46e1761

Browse files
authored
[k2] add KML support (#1411)
Previously, we've added a prediction kernel for xgboost and catboost, KML (see #983). It wasn't supported in runtime-light till the current pull request. It includes: * move the main inference logic into runtime-common dir * get rid of exceptions * gather required globals (mutable buffer, loaded model information) into context * add php_info() function to write non-warning logs in runtime-common * make KML functions and types depend on allocator Co-authored-by: Alexander Polyakov <al.polyakov@vk.team>
1 parent eeee03e commit 46e1761

71 files changed

Lines changed: 2864 additions & 1777 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
// ===== UNSUPPORTED =====
4-
5-
/** @kphp-extern-func-info stub generation-required */
6-
function kml_get_custom_property(string $model_name, string $property_name): ?string;
7-
/** @kphp-extern-func-info stub generation-required */
83
function kml_xgboost_predict_matrix(string $model_name, float[][] $features_map_matrix): ?float[];
94

10-
/** @kphp-extern-func-info stub generation-required */
5+
function kml_catboost_predict_vectors(string $model_name, float[] $float_features, string[] $cat_features): ?float;
6+
function kml_catboost_predict_vectors_multi(string $model_name, float[] $float_features, string[] $cat_features): ?float[];
7+
function kml_catboost_predict_ht(string $model_name, float[] $features_map): ?float;
8+
function kml_catboost_predict_ht_multi(string $model_name, float[] $features_map): ?float[];
9+
1110
function kml_model_exists(string $model_name): bool;
11+
function kml_available_models(): string[];
1212

13-
/** @kphp-extern-func-info stub generation-required */
14-
function kml_catboost_predict_ht(string $model_name, float[] $features_map): ?float;
13+
function kml_get_feature_names(string $model_name): ?string[];
14+
function kml_get_custom_property(string $model_name, string $property_name): ?string;

common/kprintf.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void kprintf_multiprocessing_mode_enable() {
176176
kprintf_multiprocessing_mode = 1;
177177
}
178178

179-
void kprintf_(const char* file, int line, const char* format, ...) {
179+
void kvprintf_(const char* file, int line, const char* format, va_list ap) {
180180
const int old_errno = errno;
181181
struct tm t;
182182
struct timeval tv;
@@ -201,10 +201,7 @@ void kprintf_(const char* file, int line, const char* format, ...) {
201201
t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec, (int)tv.tv_usec, file, line);
202202
if (n < sizeof(mp_kprintf_buf) - 1) {
203203
errno = old_errno;
204-
va_list ap;
205-
va_start(ap, format);
206204
n += vsnprintf(mp_kprintf_buf + n, sizeof(mp_kprintf_buf) - n, format, ap);
207-
va_end(ap);
208205
}
209206
if (n >= sizeof(mp_kprintf_buf)) {
210207
n = sizeof(mp_kprintf_buf) - 1;
@@ -221,13 +218,17 @@ void kprintf_(const char* file, int line, const char* format, ...) {
221218
fprintf(stderr, "[%d][%4d-%02d-%02d %02d:%02d:%02d.%06d %s %4d] ", getpid(), t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec,
222219
(int)tv.tv_usec, file, line);
223220
errno = old_errno;
224-
va_list ap;
225-
va_start(ap, format);
226221
vfprintf(stderr, format, ap);
227-
va_end(ap);
228222
}
229223
}
230224

225+
void kprintf_(const char* file, int line, const char* format, ...) {
226+
va_list args;
227+
va_start(args, format);
228+
kvprintf_(file, line, format, args);
229+
va_end(args);
230+
}
231+
231232
void send_message_to_assertion_chat_va_list(const char* message, va_list arg_ptr) {
232233
fprintf(stderr, " Assertion (just warning): ");
233234
vfprintf(stderr, message, arg_ptr);

common/kprintf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ void vkprintf(int verbosity, const char* format, ...) __attribute__((format(prin
2828
#else
2929
// print message with timestamp
3030
void kprintf_(const char* file, int line, const char* format, ...) __attribute__((format(printf, 3, 4)));
31+
void kvprintf_(const char* file, int line, const char* format, va_list ap);
3132
#define kprintf(...) kprintf_(__FILE__, __LINE__, __VA_ARGS__)
33+
#define kvprintf(format, ap) kvprintf_(__FILE__, __LINE__, format, ap)
3234
#define vkprintf(verbosity_level, format, ...) \
3335
do { \
3436
if ((verbosity_level) > verbosity) { \

runtime-common/core/utils/kphp-assert-core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
// For reporting php logic related errors happened during script execution
88
void php_debug(char const* message, ...) __attribute__((format(printf, 1, 2)));
9+
void php_info(char const* message, ...) __attribute__((format(printf, 1, 2)));
910
void php_notice(char const* message, ...) __attribute__((format(printf, 1, 2)));
1011
void php_warning(char const* message, ...) __attribute__((format(printf, 1, 2)));
1112
void php_error(char const* message, ...) __attribute__((format(printf, 1, 2)));

0 commit comments

Comments
 (0)