/* Get string of options to pass to the CL compiler. Result must be freed */ char* getCompilerFlags(const CLInfo* ci, const AstronomyParameters* ap, cl_bool useILKernel) { const DevInfo* di = &ci->di; std::string flagStr; const char* str; std::stringstream flags(std::stringstream::out); flags.precision(15); if (DOUBLEPREC) { flags << "-D DOUBLEPREC=1 "; } else { flags << "-D DOUBLEPREC=0 -cl-single-precision-constant "; } /* Math options for CL compiler */ flags << "-cl-mad-enable "; flags << "-cl-no-signed-zeros "; flags << "-cl-strict-aliasing "; flags << "-cl-finite-math-only "; /* Get constant definitions */ flags << "-D BACKGROUND_PROFILE=" << ap->background_profile << " "; flags << "-D AUX_BG_PROFILE=" << ap->aux_bg_profile << " "; flags << "-D NSTREAM=" << ap->number_streams << " "; flags << "-D CONVOLVE=" << ap->convolve << " "; flags << "-D R0=" << ap->r0 << " "; flags << "-D SUN_R0=" << ap->sun_r0 << " "; flags << "-D Q_INV_SQR=" << ap->q_inv_sqr << " "; flags << "-D BG_A=" << ap->bg_a << " "; flags << "-D BG_B=" << ap->bg_b << " "; flags << "-D BG_C=" << ap->bg_c << " "; flags << "-D ALPHA=" << ap->alpha << " "; flags << "-D ALPHA_DELTA_3=" << ap->alpha_delta3 << " "; /* FIXME: Device vendor not necessarily the platform vendor */ if (mwHasNvidiaCompilerFlags(di)) { flags << "-cl-nv-verbose "; flags << getNvidiaRegCount(di); } if (useILKernel) { /* Options to only emit AMD IL in the binary */ flags << "-fno-bin-exe -fno-bin-llvmir -fno-bin-source -fbin-amdil "; } flagStr = flags.str(); str = flagStr.c_str(); return str ? strdup(str) : NULL; }
/* Get string of options to pass to the CL compiler. */ static char* getCompilerFlags(const AstronomyParameters* ap, const DevInfo* di, cl_bool useImages) { char* compileFlags = NULL; char cwd[1024] = ""; char extraFlags[1024] = ""; char includeFlags[1024] = ""; char precBuf[1024] = ""; char kernelDefBuf[4096] = ""; /* Math options for CL compiler */ const char mathFlags[] = "-cl-mad-enable " "-cl-no-signed-zeros " "-cl-strict-aliasing " "-cl-finite-math-only "; /* Extra flags for different compilers */ const char nvidiaOptFlags[] = "-cl-nv-verbose "; const char atiOptFlags[] = ""; const char kernelDefStr[] = "-DFAST_H_PROB=%d " "-DAUX_BG_PROFILE=%d " "-DNSTREAM=%u " "-DCONVOLVE=%u " "-DR0=%.15f " "-DSUN_R0=%.15f " "-DQ_INV_SQR=%.15f " "-DUSE_IMAGES=%d "; const char includeStr[] = "-I%s " "-I%s/../include "; if (snprintf(kernelDefBuf, sizeof(kernelDefBuf), kernelDefStr, ap->fast_h_prob, ap->aux_bg_profile, ap->number_streams, ap->convolve, ap->r0, ap->sun_r0, ap->q_inv_sqr, useImages) < 0) { warn("Error getting kernel constant definitions\n"); return NULL; } snprintf(precBuf, sizeof(precBuf), "-DDOUBLEPREC=%d %s ", DOUBLEPREC, DOUBLEPREC ? "" : "-cl-single-precision-constant"); /* FIXME: Device vendor not necessarily the platform vendor */ if (di->vendorID == MW_NVIDIA) { if (snprintf(extraFlags, sizeof(extraFlags), "%s %s ", nvidiaOptFlags, getNvidiaRegCount(di)) < 0) { warn("Error getting extra Nvidia flags\n"); return NULL; } } else if (di->vendorID == MW_AMD_ATI) { if (snprintf(extraFlags, sizeof(extraFlags), "%s", atiOptFlags) < 0) { warn("Error getting extra ATI flags\n"); return NULL; } } else warn("Unknown vendor ID: 0x%x\n", di->vendorID); if (!inlinedIntegralKernelSrc) { if (!getcwd(cwd, sizeof(cwd))) { warn("Failed to get header directory\n"); return NULL; } if (snprintf(includeFlags, sizeof(includeFlags), includeStr, cwd, cwd) < 0) { warn("Failed to get include flags\n"); return NULL; } } if (asprintf(&compileFlags, "%s%s%s%s%s ", includeFlags, mathFlags, extraFlags, precBuf, kernelDefBuf) < 0) { warn("Failed to get compile flags\n"); return NULL; } return compileFlags; }