Skip to content

Commit dd7a6dc

Browse files
committed
feat[shared_library]: shared library works in python but not with jupyter
1 parent 7e1933c commit dd7a6dc

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

hls4ml/templates/vitis_accelerator/libs/DataBatcher.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@ template <class T, class U> class DataBatcher {
251251
profilingResultsDump.clear();
252252
}
253253

254+
/**
255+
* \brief Returns results to a shared buffer.
256+
* \param data_out Pointer to the shared buffer where results will be written
257+
* \param size Size of the shared buffer in bytes
258+
*/
259+
void returnSharedResults(double* data_out, uint64_t size) {
260+
if (size == 0 || data_out == nullptr) {
261+
throw std::runtime_error("No data to return");
262+
}
263+
264+
if (size != storedEvalResults.size()) {
265+
throw std::runtime_error("Size mismatch: " + std::to_string(size) + " != " + std::to_string(storedEvalResults.size()));
266+
}
267+
268+
for (uint64_t i = 0; i < size; i++) {
269+
data_out[i] = static_cast<double>(storedEvalResults[i]);
270+
}
271+
272+
std::cout << "Returning " << size << " results to memory buffer" << std::endl;
273+
}
274+
254275
uint64_t getSampleCount() { return originalSampleCount; }
255276

256277
uint64_t getPaddedSampleCount() { return numBatches * _batchsize; }

hls4ml/templates/vitis_accelerator/libs/FpgaObj.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,18 @@ template <class T, class U> class FpgaObj {
232232
db->closeFile();
233233
}
234234

235+
/**
236+
* \brief Returns results to a shared buffer.
237+
* \param data_out Pointer to the shared buffer where results will be written
238+
* \param size Size of the shared buffer in bytes
239+
*/
240+
void returnSharedResults(double* data_out, uint64_t size) {
241+
if (db == nullptr) {
242+
throw std::runtime_error("No data loaded");
243+
}
244+
db->returnSharedResults(data_out, size);
245+
}
246+
235247
private:
236248
int _batchsize;
237249
int _sampleInputSize;

hls4ml/templates/vitis_accelerator/myproject_host_cl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" void predict(double *input, uint64_t input_size, double *output, uint
2323

2424
fpga.checkResults(params.referenceFilename);
2525

26-
fpga.saveResults(params.outputFilename);
26+
fpga.returnSharedResults(output, output_size);
2727
}
2828

2929
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)