Skip to content

Commit

Permalink
Use data directly for streaming (#1121)
Browse files Browse the repository at this point in the history
  • Loading branch information
amehra-ni authored Nov 18, 2024
1 parent d1770af commit b5a65e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 69 deletions.
66 changes: 12 additions & 54 deletions generated/nifpga/nifpga_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,10 @@ ::grpc::Status MonikerReadArrayDbl(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<double>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArrayDbl(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand Down Expand Up @@ -543,17 +536,10 @@ ::grpc::Status MonikerReadArrayI32(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<int32_t>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArrayI32(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand All @@ -571,17 +557,10 @@ ::grpc::Status MonikerReadArrayI64(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<int64_t>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArrayI64(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand Down Expand Up @@ -626,17 +605,10 @@ ::grpc::Status MonikerReadArraySgl(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<float>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArraySgl(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand Down Expand Up @@ -681,17 +653,10 @@ ::grpc::Status MonikerReadArrayU32(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<uint32_t>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArrayU32(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand All @@ -709,17 +674,10 @@ ::grpc::Status MonikerReadArrayU64(void* data, google::protobuf::Arena& arena, g
auto indicator = function_data->indicator;
auto size = function_data->size;

auto array_storage = std::vector<uint64_t>(size);
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(size, 0);
auto array = function_data->data.mutable_value()->mutable_data();
auto status = library->ReadArrayU64(session, indicator, array, size);
if (status >= 0) {
std::transform(
array,
array + size,
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}

Expand Down
19 changes: 4 additions & 15 deletions source/codegen/templates/service_helpers.mako
Original file line number Diff line number Diff line change
Expand Up @@ -376,33 +376,22 @@ std::vector<${data_type}> array(${size}, ${data_type}());
% elif is_coerced:
std::vector<${data_type}> array(${size});
% else:
auto array_storage = std::vector<${data_type}>(${size});
auto array = array_storage.data();
function_data->data.mutable_value()->Resize(${size}, 0);
auto array = function_data->data.mutable_value()->mutable_data();
% endif
auto status = library->${c_api_name}(${arg_string});
% if is_coerced or common_helpers.supports_standard_copy_conversion_routines(streaming_param):
if (status >= 0) {
% if is_coerced or common_helpers.supports_standard_copy_conversion_routines(streaming_param):
std::transform(
array.begin(),
array.begin() + ${size},
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
% endif
packedData.PackFrom(function_data->data);
}
% else:
if (status >= 0) {
std::transform(
array,
array + ${size},
function_data->data.mutable_value()->begin(),
[&](auto x) {
return x;
});
packedData.PackFrom(function_data->data);
}
% endif
</%def>

<%def name="streaming_handle_out_direction_scaler(c_api_name, arg_string, streaming_type)">\
Expand Down

0 comments on commit b5a65e5

Please sign in to comment.