-
Notifications
You must be signed in to change notification settings - Fork 863
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
cpp backend logging and load model #1814
Changes from 4 commits
ff16d76
2b04ffb
7df655f
63109e5
4ff1617
f2da658
c4cb79c
438088e
f80d679
95a68b0
9c21cf5
e9b42f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,50 @@ | ||
#include <arpa/inet.h> | ||
#include <sys/socket.h> | ||
#include <glog/logging.h> | ||
|
||
#include "src/backends/protocol/otf_message.hh" | ||
|
||
namespace torchserve { | ||
byte_buffer OTFMessage::CreateLoadModelResponse(StatusCode code, const std::string& message) { | ||
LoadModelResponse response = { | ||
code, | ||
static_cast<int>(message.length()), | ||
message | ||
}; | ||
std::byte msg[sizeof(LoadModelResponse)]; | ||
std::memcpy(msg, &response, sizeof(LoadModelResponse)); | ||
byte_buffer response_byte_buffer; | ||
std::copy(response_byte_buffer.begin(), response_byte_buffer.end(), msg); | ||
return response_byte_buffer; | ||
bool OTFMessage::SendAll(Socket conn, char *data, size_t length) { | ||
char* pkt = data; | ||
while (length > 0) { | ||
ssize_t pkt_size = send(conn, pkt, length, 0); | ||
if (pkt_size < 0) { | ||
return false; | ||
} | ||
pkt += pkt_size; | ||
length -= pkt_size; | ||
} | ||
return true; | ||
} | ||
|
||
void OTFMessage::CreateLoadModelResponse(std::unique_ptr<torchserve::LoadModelResponse> response, char* data) { | ||
char* p = data; | ||
// Serialize response code | ||
int32_t s_code = htonl(response->code); | ||
memcpy(p, &s_code, sizeof(s_code)); | ||
p += sizeof(s_code); | ||
// Serialize response message length | ||
int32_t resp_length = htonl(response->length); | ||
memcpy(p, &resp_length, sizeof(resp_length)); | ||
p += sizeof(resp_length); | ||
// Serialize response message | ||
strcpy(p, response->buf.c_str()); | ||
p += response->length; | ||
// Expectation from frontend deserializer is a -1 | ||
// at the end of a LoadModelResponse | ||
int32_t no_predict = htonl(response->predictions); | ||
memcpy(p, &no_predict, sizeof(no_predict)); | ||
p += sizeof(no_predict); | ||
} | ||
|
||
bool OTFMessage::SendLoadModelResponse(Socket client_socket_, std::unique_ptr<torchserve::LoadModelResponse> response) { | ||
char *data = new char[sizeof(LoadModelResponse)]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix this |
||
torchserve::OTFMessage::CreateLoadModelResponse(std::move(response), data); | ||
if(!torchserve::OTFMessage::SendAll(client_socket_, data, sizeof(LoadModelResponse))) { | ||
return false; | ||
} | ||
delete[] data; | ||
maaquib marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
} | ||
|
||
char OTFMessage::RetrieveCmd(Socket conn) { | ||
|
@@ -62,7 +91,7 @@ namespace torchserve { | |
RetrieveBuffer(conn, length, data); | ||
std::string handler(data, length); | ||
delete[] data; | ||
LOG(INFO) << "Received handler in message, will be ignored: " << handler; | ||
TS_LOGF(INFO, "Received handler in message, will be ignored: {}", handler); | ||
|
||
// GPU ID | ||
auto gpu_id = RetrieveInt(conn); | ||
|
@@ -77,13 +106,13 @@ namespace torchserve { | |
// Limit max image pixels | ||
auto limit_max_image_pixels = RetrieveBool(conn); | ||
|
||
LOG(INFO) << "Model Name: " << model_name; | ||
LOG(INFO) << "Model path: " << model_dir; | ||
LOG(INFO) << "Batch size: " << batch_size; | ||
LOG(INFO) << "Handler: " << handler; | ||
LOG(INFO) << "GPU_id: " << gpu_id; | ||
LOG(INFO) << "Envelope: " << envelope; | ||
LOG(INFO) << "Limit max image pixels: " << limit_max_image_pixels; | ||
TS_LOGF(DEBUG, "Model Name: {}", model_name); | ||
TS_LOGF(DEBUG, "Model dir: {}", model_dir); | ||
TS_LOGF(DEBUG, "Batch size: {}", batch_size); | ||
TS_LOGF(DEBUG, "Handler: {}", handler); | ||
TS_LOGF(DEBUG, "GPU_id: {}", gpu_id); | ||
TS_LOGF(DEBUG, "Envelope: {}", envelope); | ||
TS_LOGF(DEBUG, "Limit max image pixels: {}", limit_max_image_pixels); | ||
|
||
return std::make_shared<LoadModelRequest>( | ||
model_dir, model_name, gpu_id, handler, | ||
|
@@ -95,7 +124,7 @@ namespace torchserve { | |
while (length > 0) { | ||
ssize_t pkt_size = recv(conn, pkt, length, 0); | ||
if (pkt_size == 0) { | ||
LOG(INFO) << "Frontend disconnected."; | ||
TS_LOG(INFO, "Frontend disconnected."); | ||
exit(0); | ||
} | ||
pkt += pkt_size; | ||
|
@@ -119,4 +148,4 @@ namespace torchserve { | |
std::memcpy(&value, data, BOOL_STD_SIZE); | ||
return value; | ||
} | ||
} //namespace torchserve | ||
} //namespace torchserve |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: do you think we can move adding integer to data pointer to a util function and re-use later below?