function compute_target_info

%   Copyright 1995-2023 The MathWorks, Inc.

global gTargetInfo gMachineInfo %#ok<GVMIS>

gTargetInfo.codingLibrary = sf('get',sf('get',gTargetInfo.target,'target.machine'),'machine.isLibrary');

targetName = sf('get',gMachineInfo.parentTarget,'target.name');
gTargetInfo.codingMakeDebug = coder_options('debugBuilds');
gTargetInfo.codingCoverage = false;
gTargetInfo.codingSFunction = strcmp(targetName,'sfun');
gTargetInfo.codingRTW = strcmp(targetName,'rtw');
gTargetInfo.codingIRConstructionForRTW = false;
gTargetInfo.codingHDL = strcmp(targetName,'slhdlc');
gTargetInfo.codingMEX = 0;
gTargetInfo.codingOpenMP = 0;
gTargetInfo.codingCustom = ~gTargetInfo.codingSFunction && ...
                           ~gTargetInfo.codingRTW && ...
                           ~gTargetInfo.codingHDL && ...
                           ~gTargetInfo.codingMEX;
% An experimental custom target based code generation for test sequence 
% scenarios to help with SLTest real time testing effort. Not a shipping
% feature.
gTargetInfo.codingDllTargetForSLTest =  strcmp(targetName,'dll');


mainMachineName = sf('get', gMachineInfo.mainMachineId, '.name');

gTargetInfo.codingDeveloper = sf('Feature','Developer');

gTargetInfo.codingExportChartNames = 0;
gTargetInfo.codingPreserveNames = 0;
gTargetInfo.codingPreserveNamesWithParent=0;

relevantMachineName = sf('get',get_relevant_machine,'machine.name');

gTargetInfo.mdlrefInfo = get_model_reference_info(relevantMachineName);
gTargetInfo.isErtMultiInstanced = is_ert_multi_instance(relevantMachineName) || gTargetInfo.mdlrefInfo.isMultiInst;
gTargetInfo.ertMultiInstanceErrCode = get_ert_multi_instance_errcode(relevantMachineName);

gTargetInfo.gencpp = sfprivate('compute_target_cpp_flag', relevantMachineName, gMachineInfo.target, gMachineInfo.parentTarget);

allFlags = all_flags(gMachineInfo.parentTarget);
gTargetInfo.codingDebug = ~sfc('coder_options', 'forceDebugOff');
gTargetInfo.codingOverflow = flag_value(allFlags,'overflow');
gTargetInfo.codingSaturate = flag_value(allFlags,'saturate');
gTargetInfo.codingNoEcho = ~flag_value(allFlags,'echo');
gTargetInfo.codingBLAS = true;
gTargetInfo.codingFasterRun = CGXE.Utils.isSimOptimizationsOn(mainMachineName);
gTargetInfo.codingExportChartNames = flag_value(allFlags,'exportcharts');
gTargetInfo.codingMultiInstance     = flag_value(allFlags,'multiinstanced');
gTargetInfo.codingStateBitsets = flag_value(allFlags,'statebitsets');
gTargetInfo.codingDataBitsets = flag_value(allFlags,'databitsets');
gTargetInfo.rapidAccelIntegrityChecks = flag_value(allFlags, 'rapidAccelIntegrityChecks');
gTargetInfo.codingComments = flag_value(allFlags,'comments');
gTargetInfo.codingEmitObjectDescriptions = flag_value(allFlags,'emitdescriptions');
gTargetInfo.codingEmitTestSequenceDescriptions = flag_value(allFlags,'emitdescriptions');
gTargetInfo.codingConstantFolding = flag_value(allFlags,'constantfolding');
gTargetInfo.codingRedundantElim = flag_value(allFlags,'redundantloadelimination');
gTargetInfo.codingEmitObjectRequirements = 0;
gTargetInfo.codingIntegerCodeOnly = 0;
gTargetInfo.codingRealCodeOnly = 0;
gTargetInfo.codingExtMode = 0;
gTargetInfo.xpcExtModeAnimation = 0;
gTargetInfo.maximumIdentifierLength = 64;
gTargetInfo.dynamicStringBufferSize = 32767;
gTargetInfo.parenthesesLevel = 1;
gTargetInfo.codingBlockComments = 0;
gTargetInfo.isBlockPathComment = 0;
gTargetInfo.codingMATLABSourceComments = 0;
gTargetInfo.codingMATLABFcnDesc = 0;
gTargetInfo.ignoreTestpoints = 0;

gTargetInfo.leavingIntegrityChecks = flag_value(allFlags,'integrity');
gTargetInfo.leavingCtrlCChecks = flag_value(allFlags,'ctrlc');
gTargetInfo.genImportedTypeDefs = 0;

gTargetInfo.codingSupportVariableSizeSignals = true;

ioformat = flag_value(allFlags,'ioformat');
switch(ioformat)
    case 0
        gTargetInfo.codingGlobalIO = 1;
        gTargetInfo.codingPackedIO = 0;
    case 1
        gTargetInfo.codingGlobalIO = 0;
        gTargetInfo.codingPackedIO = 1;
    case 2
        gTargetInfo.codingGlobalIO = 0;
        gTargetInfo.codingPackedIO = 0;
    otherwise
        gTargetInfo.codingGlobalIO = 1;
        gTargetInfo.codingPackedIO = 0;
end

gTargetInfo.modelReferenceSimTarget = 0;
gTargetInfo.modelReferenceRTWTarget = 0;

gTargetInfo.codingMemcpy = 0;
gTargetInfo.codingMemcpyThreshold = 0;
gTargetInfo.codingMemsetDouble = 0;
gTargetInfo.codingGenerateSFunction = 0;
gTargetInfo.codingConvertIfToSwitch = 0;
gTargetInfo.codingSupressUnreachableDefaultCases = 0;
gTargetInfo.codingUseSpecifiedMinMax = false;

if gTargetInfo.codingRTW
    targetProps = rtw_target_props(relevantMachineName);
    gTargetInfo.codingDebug = 0;
    gTargetInfo.codingOverflow = 0;
    gTargetInfo.codingSaturate = 0;
    gTargetInfo.codingNoEcho = 1;
    gTargetInfo.codingBLAS = ~isempty(get_param(relevantMachineName, 'CustomBLASCallback'));
    if slfeature('RTWCGMultiThread') > 0 && strcmp(get_param(relevantMachineName, 'MultiThreadedLoops'), 'on')
        gTargetInfo.codingOpenMP = 1;
    else
        gTargetInfo.codingOpenMP = 0;
    end
    
    gTargetInfo.codingMultiInstance = 0;

    gTargetInfo.codingStateBitsets = targetProps.codingStateBitsets;
    gTargetInfo.codingDataBitsets = targetProps.codingDataBitsets;
    gTargetInfo.codingComments = targetProps.codingComments;
    gTargetInfo.rapidAccelIntegrityChecks = targetProps.rapidAccelIntegrityChecks;

    gTargetInfo.codingEmitObjectDescriptions = targetProps.codingEmitObjectDescriptions;
    gTargetInfo.codingEmitTestSequenceDescriptions = targetProps.codingEmitTestSequenceDescriptions;
    gTargetInfo.codingRedundantElim = targetProps.codingRedundantElim;
    gTargetInfo.codingElseIfDetection = 1;
    gTargetInfo.codingConstantFolding = 1;

    gTargetInfo.codingEmitObjectRequirements = targetProps.codingEmitObjectRequirements;
    gTargetInfo.codingExtMode = targetProps.codingExtMode;
    gTargetInfo.xpcExtModeAnimation = targetProps.xpcExtModeAnimation;
    gTargetInfo.codingConvertIfToSwitch = targetProps.codingConvertIfToSwitch;
    gTargetInfo.codingSupressUnreachableDefaultCases = targetProps.codingSupressUnreachableDefaultCases;

    % Bitsets have to be disabled for extmode, which requires all dwork data to be addressable
    if gTargetInfo.codingExtMode && (gTargetInfo.codingStateBitsets || gTargetInfo.codingDataBitsets)
        gTargetInfo.codingStateBitsets = 0;
        gTargetInfo.codingDataBitsets = 0;
        MSLDiagnostic('Stateflow:cdr:ExternalModeBitSet').reportAsWarning;
    end

    gTargetInfo.rtwProps = targetProps;
    gTargetInfo.modelReferenceSimTarget = model_reference_sim_target(relevantMachineName);
    gTargetInfo.modelReferenceRTWTarget = model_reference_rtw_target(relevantMachineName);
    gTargetInfo.codingIntegerCodeOnly = targetProps.codingIntegerCodeOnly;
    gTargetInfo.codingRealCodeOnly = targetProps.codingRealCodeOnly;
    gTargetInfo.maximumIdentifierLength = targetProps.maximumIdentifierLength;
    gTargetInfo.dynamicStringBufferSize = targetProps.dynamicStringBufferSize;
    gTargetInfo.parenthesesLevel = targetProps.parenthesesLevel;
    gTargetInfo.codingBlockComments = targetProps.codingBlockComments;
    gTargetInfo.isBlockPathComment = targetProps.isBlockPathComment;
    gTargetInfo.codingMATLABSourceComments = targetProps.codingMATLABSourceComments;
    gTargetInfo.codingMATLABFcnDesc = targetProps.codingMATLABFcnDesc;
    gTargetInfo.codingMemcpy = targetProps.codingMemcpy;
    gTargetInfo.codingMemcpyThreshold = targetProps.codingMemcpyThreshold;
    gTargetInfo.codingMemsetDouble = targetProps.codingMemsetDouble;
    gTargetInfo.ignoreTestpoints = targetProps.ignoreTestpoints && ...
                                   ~gTargetInfo.modelReferenceSimTarget && ...
                                   ~gTargetInfo.codingExtMode && ...
                                   strcmpi(get_param(relevantMachineName, 'RapidAcceleratorSimStatus'), 'inactive');

    gTargetInfo.codingUseSpecifiedMinMax = targetProps.codingUseSpecifiedMinMax;
    modelH = get_param(relevantMachineName, 'Handle');
    hModelCodegenMgr = coder.internal.ModelCodegenMgr.getInstance(modelH);
    if ~isempty(hModelCodegenMgr)
        if(strcmp(hModelCodegenMgr.CodeFormatForStateflow,'S-Function'))
            gTargetInfo.codingGenerateSFunction = 1;
        end
    end

    if gTargetInfo.modelReferenceSimTarget
        gTargetInfo.codingCoverage = SlCov.CoverageAPI.isCovAccelSimSFSupport(relevantMachineName) && ...
                                     SlCov.CoverageAPI.isSfCoverageOn(relevantMachineName);
                                      
    else
        gTargetInfo.codingSupportVariableSizeSignals = targetProps.codingSupportVariableSizeSignals;
    end

elseif gTargetInfo.codingSFunction
    gTargetInfo.codingNoComments = 1;
    gTargetInfo.codingEmitObjectDescriptions = 0;
    gTargetInfo.codingEmitTestSequenceDescriptions = 0;
    gTargetInfo.codingRedundantElim = 1;
    gTargetInfo.codingElseIfDetection = 1;
    gTargetInfo.codingConstantFolding = 1;
    [gTargetInfo.codingExtMode, gTargetInfo.xpcExtModeAnimation] = get_machine_extmode_setting(relevantMachineName);
    gTargetInfo.genImportedTypeDefs = strcmp(get_param(relevantMachineName, 'SimGenImportedTypeDefs'), 'on');
    gTargetInfo.codingCoverage = SlCov.CoverageAPI.isSfCoverageOn(relevantMachineName);

elseif gTargetInfo.codingHDL
    gTargetInfo.codingDebug = 0;
elseif(gTargetInfo.codingDllTargetForSLTest)
    gTargetInfo.codingMultiInstance     = false;
    gTargetInfo.codingStateBitsets = false;
    gTargetInfo.codingDataBitsets = false;    
    gTargetInfo.codingGlobalIO = 0;
    gTargetInfo.codingPackedIO = 1;
    gTargetInfo.codingDebug = 0;
    gTargetInfo.codingExportChartNames = 1;
else
    gTargetInfo.codingDebug = 0;
end

% Set some target specific flags for use with the verify keyword transforms
gTargetInfo.codingRapidAccel = ~strcmpi(get_param(mainMachineName, 'RapidAcceleratorSimStatus'), 'inactive');
gTargetInfo.codingSIL = gTargetInfo.codingRTW && strcmpi(get_param(mainMachineName, 'SimulationMode'), 'software-in-the-loop (sil)');
gTargetInfo.codingPIL = gTargetInfo.codingRTW && strcmpi(get_param(mainMachineName, 'SimulationMode'), 'processor-in-the-loop (pil)');
gTargetInfo.codingSLRT = (gTargetInfo.codingRTW || gTargetInfo.codingExtMode || gTargetInfo.codingDllTargetForSLTest) && (strcmpi(get_param(mainMachineName, 'SystemTargetFile'), 'slrt.tlc') || strcmpi(get_param(mainMachineName, 'IsSLRTTarget'), 'on'));
gTargetInfo.codingSVDPI =  (gTargetInfo.codingRTW || gTargetInfo.codingExtMode) && (strcmpi(get_param(mainMachineName, 'SystemTargetFile'), 'systemverilog_dpi_grt.tlc') || strcmpi(get_param(mainMachineName, 'SystemTargetFile'), 'systemverilog_dpi_ert.tlc'));
gTargetInfo.codingSLCI = gTargetInfo.codingRTW && ~isempty(regexp(get_param(mainMachineName, 'AdvancedOptControl'), '(\W|^)\-SLCI(\W|$)', 'once'));
gTargetInfo.codingAUTOSAR = gTargetInfo.codingRTW && strcmpi(get_param(mainMachineName, 'AutosarCompliant'), 'on');
gTargetInfo.codingRSIM = gTargetInfo.codingRTW && (strcmpi(get_param(mainMachineName, 'SystemTargetFile'), 'rsim.tlc'));
gTargetInfo.capiDisabledSLRT = gTargetInfo.codingSLRT && (strcmpi(get_param(mainMachineName, 'RTWCAPISignals'), 'off')) && (strcmpi(get_param(mainMachineName, 'RTWCAPIParams'), 'off')) && (strcmpi(get_param(mainMachineName, 'RTWCAPIStates'), 'off')) && (strcmpi(get_param(mainMachineName, 'RTWCAPIRootIO'), 'off'));

gTargetInfo.layoutIsRowMajor = strcmpi(get_param(mainMachineName, 'ArrayLayout'), 'Row-major');
gTargetInfo.systemTargetIsAUTOSAR = strcmpi(get_param(mainMachineName, 'SystemTargetFile'), 'autosar.tlc');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Option to indicate this is an SLDV code generation
% (replaces old gTargetInfo.codingForTestGen)
if ~gTargetInfo.codingSFunction && (get_param(relevantMachineName, 'RTWExternMdlXlate') == 1)
    gTargetInfo.codingForAutoVerifier = 1;

    % If SLDV is being invoked, set the flags regarding analysis options in gTargetInfo. These
    % flags will be copied to ctxInfo in private/construct_context_for_machine.m, which in turn
    % will be used to initialize CdrCtxInfo->ctx.fSldvOptions in cdr/cdr_semantics_vars.cpp.
    % Note: This logic is no longer needed as ctxInfo is already copied from RTWContext 
    % by invocation of getRtwContextFor in cdr_construct_context method in cdr/cdr_semantics_vars.cpp.
    % So,this code will be deleted as a part of g2338985 


    if isfield(targetProps, 'DVoptMinmaxConstr')
        gTargetInfo.DVoptMinmaxConstr = targetProps.DVoptMinmaxConstr;
    end
    if isfield(targetProps, 'DVoptMode')
        gTargetInfo.DVoptMode = targetProps.DVoptMode;
    end
    if isfield(targetProps, 'DVoptRelBoundary')
        gTargetInfo.DVoptRelBoundary = targetProps.DVoptRelBoundary;
    end
    if isfield(targetProps, 'DVoptCoverageObj')
        gTargetInfo.DVoptCoverageObj = targetProps.DVoptCoverageObj;
    end
    if isfield(targetProps, 'DVoptDeadLogic')
        gTargetInfo.DVoptDeadLogic = targetProps.DVoptDeadLogic;
    end
    if isfield(targetProps, 'DVoptActiveLogic')
        gTargetInfo.DVoptActiveLogic = targetProps.DVoptActiveLogic;
    end
    if isfield(targetProps, 'DVoptDivByZero')
        gTargetInfo.DVoptDivByZero = targetProps.DVoptDivByZero;
    end
    if isfield(targetProps, 'DVoptIntOvf')
        gTargetInfo.DVoptIntOvf = targetProps.DVoptIntOvf;
    end
    if isfield(targetProps, 'DVoptMinmaxCheck')
        gTargetInfo.DVoptMinmaxCheck = targetProps.DVoptMinmaxCheck;
    end
    if isfield(targetProps, 'DVoptOutOfBound')
        gTargetInfo.DVoptOutOfBound = targetProps.DVoptOutOfBound;
    end
    if isfield(targetProps, 'DVoptDetectDSMAccessViolations')
        gTargetInfo.DVoptDetectDSMAccessViolations = targetProps.DVoptDetectDSMAccessViolations;
    end
    if isfield(targetProps, 'DVoptFloatInf')
        gTargetInfo.DVoptFloatInf = targetProps.DVoptFloatInf;
    end
    if isfield(targetProps, 'DVoptFloatNaN')
        gTargetInfo.DVoptFloatNaN = targetProps.DVoptFloatNaN;
    end
    if isfield(targetProps, 'DVoptFloatSubnormal')
        gTargetInfo.DVoptFloatSubnormal = targetProps.DVoptFloatSubnormal;
    end
    
    gTargetInfo.codingForRangeAnalysis = targetProps.codingForRangeAnalysis ;
else
    gTargetInfo.codingForAutoVerifier = 0;
    gTargetInfo.codingForRangeAnalysis = 0;
end

if( ~gTargetInfo.codingSFunction && get_param(relevantMachineName,'RTWExternMdlXlate') == 2)
    gTargetInfo.codingPLC = 1;
    plcOptions = plcprivate('plc_options', relevantMachineName);
    gTargetInfo.codingPLCTargetIDE = plcOptions.TargetIDE;
else
    gTargetInfo.codingPLC = 0;
    gTargetInfo.codingPLCTargetIDE = '';
end

gTargetInfo.codingROWMajor = slfeature('RowMajorDimensionSupport') && ~gTargetInfo.codingRSIM && ...
                             ~gTargetInfo.codingHDL && ~gTargetInfo.codingPLC && ~gTargetInfo.codingRapidAccel && ...
                             ~gTargetInfo.modelReferenceSimTarget && ...
                             (gTargetInfo.codingRTW || (gTargetInfo.codingForAutoVerifier && slfeature('SldvRowMajor'))) && ...
                             (strcmpi(get_param(mainMachineName, 'RowMajorDimensionSupport'), 'on') || strcmpi(get_param(mainMachineName, 'ArrayLayout'), 'Row-major'));

% Code Generation preserves dimensions for Stateflow local data in AUTOSAR target.
gTargetInfo.codingPreserveStateflowLocalDataDimensions = gTargetInfo.codingROWMajor && (strcmpi(get_param(mainMachineName, 'PreserveStateflowLocalDataDimensions'), 'on'));

if(gTargetInfo.codingPreserveNamesWithParent)
    gTargetInfo.codingPreserveNames = 1;
end


if(gTargetInfo.codingLibrary && (gTargetInfo.codingSFunction || gTargetInfo.codingRTW))
    gTargetInfo.codingMultiInstance  = 1;
end

gTargetInfo.codingTMW = 0;

compute_compiler_info;

compilerInfo = gTargetInfo.compilerInfo;

if gTargetInfo.codingBLAS && ...
    ~coderprivate.compiler_supports_eml_blas(compilerInfo.compilerName)
    gTargetInfo.codingBLAS = false;
    MSLDiagnostic('Coder:reportGen:noCompilerBlasSupport',compilerInfo.compilerName).reportAsWarning;
end

if gTargetInfo.codingOpenMP
    if ~coderprivate.compiler_supports_eml_openmp(compilerInfo.compilerName)
        gTargetInfo.codingOpenMP = false;
    else
        % xxx: disabling debugging when parallelization is enabled. Bound checks, ctrl-c
        % checks and echo are disabled internally. Parallelization is disabled by default.
        if ~gTargetInfo.codingRTW
            gTargetInfo.codingDebug = false;
            gTargetInfo.codingNoEcho = true;
        end
    end
end
gTargetInfo.codingSLCCVariadic = ismember(compilerInfo.compilerName, cgxeprivate('supportedPCCompilers','microsoft'));

% Set GPU Coder flag
gTargetInfo.codingGPU = getCodingGPU(mainMachineName);

% Add buildInfo for GPU Coder
gTargetInfo.buildInfo = RTW.BuildInfo;

% Set DL parameters
setDLParams(mainMachineName);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function setDLParams(mainMachineName)
global gTargetInfo %#ok<GVMIS>
if ~gTargetInfo.gencpp
    gTargetInfo.dlTargetLib = 'none';
elseif gTargetInfo.codingSFunction
    gTargetInfo.dlTargetLib = lower(get_param(mainMachineName, 'SimDLTargetLibrary'));
else
    gTargetInfo.dlTargetLib = lower(get_param(mainMachineName, 'DLTargetLibrary'));
end
% TODO: Remove it after 'mkl-dnn' is renamed 'mkldnn' in configset.
if strcmpi(gTargetInfo.dlTargetLib, 'mkl-dnn')
    gTargetInfo.dlTargetLib = 'mkldnn';
elseif strcmpi(gTargetInfo.dlTargetLib, 'one-dnn')
    gTargetInfo.dlTargetLib = 'onednn';
end
gTargetInfo.dlAutoTuning = strcmpi(get_param(mainMachineName, 'SimDLAutoTuning'), 'on');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function codingGPU = getCodingGPU(mainMachineName)
global gTargetInfo %#ok<GVMIS>
codingGPU = false;

if gTargetInfo.codingSFunction
    codingGPU = strcmpi(get_param(mainMachineName, 'GPUAcceleration'), 'on');
    if codingGPU
        % Check for any GPU Parameters that are enabled without license
        [licStatus, licMsg] = builtin('license', 'checkout', 'GPU_Coder');
        if ~licStatus
            throw(MSLException([],...
                message('gpucoder:system:GPUAccelerationOnWithNoLicense', licMsg, mainMachineName)));
        end

        % MAC OS is not supported.
        if ismac
            error(message('gpucoder:system:unsupported_macos'));
        end
        [status, errorMsg] = coder.internal.validateGpuDevice();
        if ~status
            warning(message('gpucoder:system:incompatible_gpu_driver', errorMsg));
        end
    end
elseif gTargetInfo.codingRTW && ~gTargetInfo.codingPLC && ~gTargetInfo.codingHDL && ~gTargetInfo.modelReferenceSimTarget
    codingGPU = strcmpi(get_param(mainMachineName, 'GenerateGPUCode'), 'CUDA');
    if codingGPU 
        % Check for any GPU Parameters that are enabled without license
        [licStatus, licMsg] = builtin('license', 'checkout', 'GPU_Coder');
        if ~licStatus
            throw(MSLException([],...
                message('gpucoder:system:GenerateGPUCodeOnWithNoLicense', licMsg, mainMachineName)));
        end
        % MAC OS is not supported.    
        if ismac
            error(message('gpucoder:system:unsupported_macos'));
        end
    end
end

if codingGPU
    % Check compiler
    if gTargetInfo.codingSFunction && ~gTargetInfo.codingMSVCMakefile && ~gTargetInfo.codingUnixMakefile
        compName = gTargetInfo.compilerInfo.compilerName;
        error(message('gpucoder:common:NoValidMexGpuCompiler',compName));
    end
    gTargetInfo.codingDebug = 0;
    gTargetInfo.leavingCtrlCChecks = 0;
    gTargetInfo.leavingIntegrityChecks = 0;
    gTargetInfo.codingOverflow = 0;
    gTargetInfo.codingSaturation = 0;
     
    %%%% Sim parameters %%%%
    mallocThreshold = get_param(mainMachineName, 'SimGPUMallocThreshold');
    if mallocThreshold > 0
        gTargetInfo.gpuMallocThreshold = mallocThreshold;
    else
        gTargetInfo.gpuMallocThreshold = 200;
    end
    
    maximumBlocksPerKernel = get_param(mainMachineName, 'SimGPUMaximumBlocksPerKernel');
    if maximumBlocksPerKernel > 0 && maximumBlocksPerKernel < 65536
        gTargetInfo.gpuMaximumBlocksPerKernel = maximumBlocksPerKernel;
    else
        gTargetInfo.gpuMaximumBlocksPerKernel = 65535;
    end

    enforce1DKernels = strcmpi(get_param(mainMachineName, 'SimGPUEnforce1DKernels'), 'on');
    gTargetInfo.gpuEnforce1DKernels = enforce1DKernels;

    gpuStackLimitPerThread = get_param(mainMachineName, 'SimGPUStackLimitPerThread');
    
    if gpuStackLimitPerThread > 0
        gTargetInfo.gpuStackLimitPerThread = gpuStackLimitPerThread;
    else
        gTargetInfo.gpuStackLimitPerThread = 1024;
    end

    gTargetInfo.gpuErrorChecks = strcmpi(get_param(mainMachineName, 'SimGPUErrorChecks'), 'on');
    gTargetInfo.gpuCustomComputeCapability = get_param(mainMachineName, 'SimGPUCustomComputeCapability');
    gTargetInfo.gpuCompilerFlags = get_param(mainMachineName, 'SimGPUCompilerFlags');
    if gTargetInfo.codingSFunction || CGXE.Utils.isRaccelOrMdfRefSimTarget(mainMachineName)
        gTargetInfo.gpuComputeCapability = getDeviceCompute;
    else
        gTargetInfo.gpuComputeCapability = get_param(mainMachineName, 'GPUComputeCapability');
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function cc = getDeviceCompute
try
    cc   = gpucoder.internal.getBestComputeCapability();
catch e
    cc = coder.GpuCodeConfig.DefaultComputeCapability;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function result = all_flags(target)
result = sfprivate('target_methods','codeflags',target);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function result = flag_value(flags,str)
flagNames = {flags.name};
index = find(strcmp(flagNames,str));
if(~isempty(index))
    result = flags(index).value;
else
    result = 0;
end
