#//<copyright-disclaimer-start>
#//  **************************************************************************************************************
#//  * © 2026 Advanced Micro Devices, Inc. All rights reserved.                                                   *
#//  * DISCLAIMER                                                                                                 *
#//  * The information contained herein is for informational purposes only, and is subject to change              *
#//  * without notice. While every precaution has been taken in the preparation of this document, it              *
#//  * may contain technical inaccuracies, omissions and typographical errors, and AMD is under no                *
#//  * obligation to update or otherwise correct this information.  Advanced Micro Devices, Inc. makes            *
#//  * no representations or warranties with respect to the accuracy or completeness of the contents of           *
#//  * this document, and assumes no liability of any kind, including the implied warranties of noninfringement,  *
#//  * merchantability or fitness for particular purposes, with respect to the operation or use of AMD            *
#//  * hardware, software or other products described herein.  No license, including implied or                   *
#//  * arising by estoppel, to any intellectual property rights is granted by this document.  Terms and           *
#//  * limitations applicable to the purchase or use of AMD’s products are as set forth in a signed agreement     *
#//  * between the parties or in AMD's Standard Terms and Conditions of Sale. GD-18                               *
#//  *                                                                                                            *
#//  **************************************************************************************************************
#//<copyright-disclaimer-end>

AIE_SIM_ONLY      := false

SIM_FIFO          := false

MY_APP            := gemm_16x32x8_app
MY_SOURCES        := ${MY_APP}.cpp gemm_16x32x8_graph.h

PART	:= xc2ve3858-ssva2112-1LP-e-S

CHECK_FIFO        := --aie.evaluate-fifo-depth --aie.Xrouter=disablePathBalancing

DSPLIB_OPTS 	  := --include=${DSPLIB_ROOT}/L2/include/aie \
		     --include=${DSPLIB_ROOT}/L1/include/aie \
		     --include=${DSPLIB_ROOT}/L1/src/aie

AIE_OUTPUT := libadf.a

AIE_FLAGS :=	${DSPLIB_OPTS} --part=${PART} ${MY_APP}.cpp --aie.output-archive=${AIE_OUTPUT}

ifeq (${SIM_FIFO}, true)
	AIE_FLAGS := ${AIE_FLAGS} ${CHECK_FIFO}
endif
ifeq (${AIE_SIM_ONLY},true)
	AIE_FLAGS := ${AIE_FLAGS} --aie.Xpreproc="-DAIE_SIM_ONLY"
endif


.PHONY: help clean x86 x86sim aie aiesim profile throughput

help::
	@echo "Makefile Usage:"
	@echo "  make all"
	@echo "      Command to generate everything for this design"
	@echo ""
	@echo "  make compile"
	@echo "      Run AIE compiler and build the design"
	@echo ""
	@echo "  make profile"
	@echo "      Run AIE simulator with profiling and generate outputs suitable for Vitis Analyzer"
	@echo ""
	@echo "  make analyze"
	@echo "      Run Vitis Analyzer to inspect results"
	@echo ""
	@echo "  make clean"
	@echo "      Command to remove all the generated files."

gen_vectors:
	matlab -batch "gen_vectors"

aie:	${MY_SOURCES}
	v++ --compile --config aie.cfg --mode aie --target=hw ${AIE_FLAGS} |& tee log

x86:
	v++ --compile --config aie.cfg --mode aie --target=x86sim ${AIE_FLAGS} |& tee log

aiesim:
	aiesimulator --online -wdb -text --profile |& tee -a log

x86sim:
	x86simulator |& tee -a log

profile:
	aiesimulator --online -wdb -text --profile |& tee -a log

trace:
	aiesimulator --online -wdb -text |& tee -a log


check_sim_output_x86:
	matlab -batch "regression"
 
check_sim_output_aie:
	matlab -batch "regression(0)"	

analyze:
	vitis_analyzer aiesimulator_output/default.aierun_summary

clean:
	rm -rf .Xil Work libadf.a
	rm -rf aiesimulator_output* aiesimulator*.log
	rm -rf x86simulator_output*
	rm -rf log log*
	rm -rf *.xpe *.elf *.db *.soln Map_* xnw* *.lp *.log .xil .Xil *.lp *.db *.log *.exe *.vcd *.json
	rm -rf vitis_analyzer* pl_sample_counts* pl_sample_count_*
	rm -rf temp ISS_RPC_SERVER_PORT .crashReporter .AIE_SIM_CMD_LINE_OPTIONS
	rm -rf system*.* trdata.aiesim function_wdb_dir .wsdata

