Skip to content

Commit

Permalink
Merge pull request #317 from anarkiwi/lj
Browse files Browse the repository at this point in the history
less copying json
  • Loading branch information
anarkiwi authored Sep 14, 2024
2 parents 955b643 + e8caece commit 77c2e6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
18 changes: 6 additions & 12 deletions lib/iq_inference_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,8 @@ void iq_inference_impl::run_inference_(torchserve_client *client) {

output_json["predictions"] = results_json;
output_json["metadata"] = metadata_json;
const std::string output_json_str = output_json.dump();
if (output_json_str.size() < MAX_JSON_SIZE) {
json_result_type output_json_chars;
std::copy(output_json_str.begin(), output_json_str.end(),
output_json_chars.data());
json_q_.push(output_json_chars);
} else {
d_logger->error("output json size too large");
}
std::string *output_json_str = new std::string(output_json.dump());
json_q_.push(output_json_str);
delete_output_item_(output_item);
}
}
Expand Down Expand Up @@ -466,10 +459,11 @@ void iq_inference_impl::process_tags_(COUNT_T in_first,
}

void iq_inference_impl::pub_json_() {
json_result_type json;
while (json_q_.pop(json)) {
std::string *output_json_str;
while (json_q_.pop(output_json_str)) {
++predictions_;
message_port_pub(INFERENCE_KEY, string_to_pmt(std::string(json.data())));
message_port_pub(INFERENCE_KEY, string_to_pmt(*output_json_str));
delete output_json_str;
}
}

Expand Down
5 changes: 1 addition & 4 deletions lib/iq_inference_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ namespace gr {
namespace iqtlabs {

const COUNT_T MAX_INFERENCE = 5;
const COUNT_T MAX_JSON_SIZE = 8192;

typedef struct output_item {
FREQ_T rx_freq;
Expand All @@ -236,8 +235,6 @@ typedef struct output_item {
COUNT_T serial;
} output_item_type;

typedef std::array<char, MAX_JSON_SIZE> json_result_type;

class iq_inference_impl : public iq_inference, base_impl {
private:
pmt::pmt_t tag_;
Expand All @@ -255,7 +252,7 @@ class iq_inference_impl : public iq_inference, base_impl {
boost::lockfree::queue<output_item_type,
boost::lockfree::capacity<MAX_INFERENCE>>
inference_q_;
boost::lockfree::queue<json_result_type,
boost::lockfree::queue<std::string *,
boost::lockfree::capacity<MAX_INFERENCE>>
json_q_;
boost::shared_ptr<boost::asio::io_service> io_service_;
Expand Down

0 comments on commit 77c2e6b

Please sign in to comment.