Example - 2023.2 English

Vitis Libraries

Release Date
2023-12-20
Version
2023.2 English
#include "xf_graph_L3.hpp"
#include <cstring>

#define DT float

//----------------- Setup shortestPathFloat thread -------------
std::string opName;
std::string kernelName;
int requestLoad;
std::string xclbinPath;
int deviceNeeded;

xf::graph::L3::Handle::singleOP op0;
op0.operationName = (char*)opName.c_str();
op0.setKernelName((char*)kernelName.c_str());
op0.requestLoad = requestLoad;
op0.xclbinPath = xclbinPath;
op0.deviceNeeded = deviceNeeded;

xf::graph::L3::Handle handle0;
handle0.addOp(op0);
handle0.setUp();

//----------------- Readin Graph data ---------------------------
uint32_t numVertices;
uint32_t numEdges;
xf::graph::Graph<uint32_t, DT> g("CSR", numVertices, numEdges);

//----------------- Load Graph ----------------------------------
(handle0.opsp)->loadGraph(g);

//---------------- Run L3 API -----------------------------------
bool weighted = 1;
uint32_t nSource = 1;
uint32_t sourceID = 10;
uint32_t length = ((numVertices + 1023) / 1024) * 1024;
DT** result;
uint32_t** pred;
result = new DT*[nSource];
pred = new uint32_t*[nSource];
for (int i = 0; i < nSource; ++i) {
    result[i] = xf::graph::L3::aligned_alloc<DT>(length);
    pred[i] = xf::graph::L3::aligned_alloc<uint32_t>(length);
}
auto ev = xf::graph::L3::shortestPath(handle0, nSource, &sourceID, weighted, g, result, pred);
int ret = ev.wait();

//--------------- Free and delete -----------------------------------
handle0.free();
g.freeBuffers();

for (int i = 0; i < nSource; ++i) {
    free(result[i]);
    free(pred[i]);
}
delete[] result;
delete[] pred;