Skip to content

Commit 51e9fd5

Browse files
axiotiskQuentin Berthet
authored andcommitted
Backend and Makefile fixes for emulation
1 parent 236e7db commit 51e9fd5

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

hls4ml/backends/vitis_accelerator/vitis_accelerator_backend.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,15 @@ def dat_to_numpy(self, model):
112112
y = np.loadtxt(output_file, dtype=float).reshape(-1, expected_shape)
113113
return y
114114

115-
def hardware_predict(self, model, x, target="hw"):
115+
def hardware_predict(self, model, x, target="hw", debug=False):
116+
if debug:
117+
command = "DEBUG=1 "
116118
self._validate_target(target)
117119
self.numpy_to_dat(model, x)
118120
currdir = os.getcwd()
119121
os.chdir(model.config.get_output_dir())
120-
os.system(f"TARGET={target} make run")
122+
command += "TARGET=" + target + " make run"
123+
os.system(command)
121124
os.chdir(currdir)
122125

123126
return self.dat_to_numpy(model)

hls4ml/templates/vitis_accelerator/Makefile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ PWD := $(shell pwd)
2525
# Target (hw, hw_emu, sw_emu)
2626
TARGET ?= hw
2727

28-
# Define emulation mode variable
29-
ifneq($(TARGET), hw)
30-
XCL_EMULATION_MODE=$(TARGET)
31-
endif
32-
3328
# Accelerator card configuration file
3429
CARD_CFG ?= accelerator_card.cfg
3530

@@ -126,9 +121,14 @@ host: $(KERNEL_NAME)_host_cl.cpp libs/xcl2.cpp
126121
# Execute program #############################################################
127122

128123
run: ./host $(BUILD_DIR)/$(WRAPPER_NAME).xclbin
129-
cd firmware
130-
./host $(BUILD_DIR)/$(WRAPPER_NAME).xclbin
131-
cd ..
124+
ifeq ($(TARGET), hw)
125+
@echo "TARGET is hw, not setting XCL_EMULATION_MODE"
126+
$(eval EMULATION_MODE :=)
127+
else
128+
@echo "Setting XCL_EMULATION_MODE to $(TARGET)"
129+
$(eval EMULATION_MODE := XCL_EMULATION_MODE=$(TARGET))
130+
endif
131+
@cd firmware && $(EMULATION_MODE) ../host ../$(BUILD_DIR)/$(WRAPPER_NAME).xclbin
132132

133133
# Cleanup #####################################################################
134134

0 commit comments

Comments
 (0)