#!/bin/bash -e
#
# Apache v2 license
# Copyright (C) 2023 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

WORKLOAD=${WORKLOAD:-stream}
INSTRUCTION_SET=${1:-sse}
NTIMES=${NTIMES:-${2:-500}}
CLOUDFLAG=${CLOUDFLAG:-false}
NO_OF_STREAM_ITERATIONS=${NO_OF_STREAM_ITERATIONS:-1}
THP_ENABLE=${THP_ENABLE:-always}
STREAM_ARRAY_SIZE=${STREAM_ARRAY_SIZE:-}

# Logs Setting
DIR="$(cd "$(dirname "$0")" &>/dev/null && pwd)"
. "$DIR/../../script/overwrite.sh"

#adding EVENT_TRACE_PARAMS
EVENT_TRACE_PARAMS="roi,start benchmark,end benchmark"
# Workload Setting
WORKLOAD_PARAMS=(INSTRUCTION_SET NTIMES CLOUDFLAG NO_OF_STREAM_ITERATIONS  ENABLE_PRIVILEGED_MODE THP_ENABLE STREAM_ARRAY_SIZE)

DOCKER_IMAGE="$DIR/Dockerfile.1.${WORKLOAD//_/.}"

REQUIRED_RESOURCES=""
if [ "${ENABLE_PRIVILEGED_MODE}" == "true" ]; then
    REQUIRED_RESOURCES="--privileged"
fi



DOCKER_OPTIONS="$REQUIRED_RESOURCES -e ENABLE_PRIVILEGED_MODE=${ENABLE_PRIVILEGED_MODE} -e STREAM_ARRAY_SIZE=${STREAM_ARRAY_SIZE} -e THP_ENABLE=${THP_ENABLE}   -e NO_OF_STREAM_ITERATIONS=${NO_OF_STREAM_ITERATIONS}  -e INSTRUCTION_SET=${INSTRUCTION_SET} -e NTIMES=${NTIMES} -e WORKLOAD=$WORKLOAD -e PLATFORM=$PLATFORM -e CLOUDFLAG=$CLOUDFLAG"
# Kubernetes Setting
RECONFIG_OPTIONS="-DDOCKER_IMAGE=${DOCKER_IMAGE}  -DTHP_ENABLE=${THP_ENABLE} -DSTREAM_ARRAY_SIZE=${STREAM_ARRAY_SIZE} -DNO_OF_STREAM_ITERATIONS=${NO_OF_STREAM_ITERATIONS} -DENABLE_PRIVILEGED_MODE=${ENABLE_PRIVILEGED_MODE} -DINSTRUCTION_SET=${INSTRUCTION_SET} -DNTIMES=${NTIMES} -DWORKLOAD=${WORKLOAD} -DPLATFORM=$PLATFORM -DCLOUDFLAG=${CLOUDFLAG} "
JOB_FILTER="job-name=benchmark"

. "$DIR/../../script/validate.sh"
