Skip to content

Commit 8a1fe00

Browse files
committed
Host targets device from config
1 parent cff1e2f commit 8a1fe00

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

hls4ml/templates/vitis_accelerator/myproject_host.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,24 @@ int main(int argc, char **argv) {
6161
return EXIT_FAILURE;
6262
}
6363

64+
std::string target_device = "myplatform";
65+
auto device_type = target_device.substr(0, target_device.size() - 17);
66+
std::cout << "Device type: " << device_type << std::endl;
67+
std::cout << "xrt::device size " << sizeof(xrt::device) << std::endl;
68+
for (int i = 0; i < sizeof(xrt::device); i++){
69+
std::cout << "device[" << i << "] name: " << xrt::device(i).get_info<xrt::info::device::name>() << "\n";
70+
std::cout << "device[" << i << "] bdf: " << xrt::device(i).get_info<xrt::info::device::bdf>() << "\n\n";
71+
size_t found = xrt::device(i).get_info<xrt::info::device::name>().find(device_type);
72+
if (found != std::string::npos){
73+
std::cout << "Device: " << xrt::device(i).get_info<xrt::info::device::name>() << " found." << std::endl;
74+
device_index = i;
75+
std::cout << "Device index in loop: " <<device_index << std::endl;
76+
break;
77+
}
78+
else{
79+
std::cout << "Device not found" << std::endl;
80+
}
81+
}
6482
std::cout << "Open the device" << device_index << std::endl;
6583
auto device = xrt::device(device_index);
6684
std::cout << "Load the xclbin " << binaryFile << std::endl;

hls4ml/writer/vitis_accelerator_writer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def write_host(self, model):
113113
Args:
114114
model (ModelGraph): the hls4ml model.
115115
"""
116+
from hls4ml.backends import VitisAcceleratorConfig
117+
vitis_accelerator_config = VitisAcceleratorConfig(model.config)
116118

117119
filedir = os.path.dirname(os.path.abspath(__file__))
118120
f = open(os.path.join(filedir, '../templates/vitis_accelerator/myproject_host.cpp'))
@@ -127,6 +129,8 @@ def write_host(self, model):
127129
newline = line.replace('myproject_kernel', format(model.config.get_project_name(), '_kernel'))
128130
elif 'output_dir' in line:
129131
newline = line.replace('output_dir', format(model.config.get_output_dir()))
132+
elif 'myplatform' in line:
133+
newline = line.replace('myplatform', format(vitis_accelerator_config.get_platform()))
130134
else:
131135
newline = line
132136
fout.write(newline)

0 commit comments

Comments
 (0)