Esempio n. 1
0
int W_matrix::get_integrals(double** W_container, double** Wsh_container,
        const double distance) {
    for (int iter = 0; iter < integralList.size(); iter++) {
        if (abs(integralList[iter].distance - distance) <= 0.01*distance) {
            *W_container = integralList[iter].W_container;
            *Wsh_container = integralList[iter].Wsh_container;
            return 0;
        }
    }

    integralContainer newIntegral(distance);
    calculateIntegrals(&newIntegral, distance);

    integralList.push_back(newIntegral);
    for (int iter = 0; iter < integralList.size(); iter++) {
        if (abs(integralList[iter].distance - distance) <= 0.01*distance) {
            *W_container = integralList[iter].W_container;
            *Wsh_container = integralList[iter].Wsh_container;
            return 0;
        }
    }
    return 0;
}
int evaluate(SeparationResults* results,
             const AstronomyParameters* ap,
             const IntegralArea* ias,
             const Streams* streams,
             const StreamConstants* sc,
             const char* star_points_file,
             const CLRequest* clr,
             int do_separation,
             int ignoreCheckpoint,
             const char* separation_outfile)
{
    int rc = 0;
    EvaluationState* es;
    StreamGauss sg;
    GPUInfo ci;
    StarPoints sp = EMPTY_STAR_POINTS;
    int useImages = FALSE; /* Only applies to CL version */
#ifdef ANDROID
    StreamConstantsIntFp* sci;
    int armExt = mwDetectARMExt();
#endif
    
    memset(&ci, 0, sizeof(ci));

    probabilityFunctionDispatch(ap, clr);

    es = newEvaluationState(ap);
    sg = getStreamGauss(ap->convolve);

  #if SEPARATION_GRAPHICS
    if (separationInitSharedEvaluationState(es))
        warn("Failed to initialize shared evaluation state\n");
  #endif /* SEPARATION_GRAPHICS */

    if (!ignoreCheckpoint)
    {
        if (resolveCheckpoint())
            fail("Failed to resolve checkpoint file '%s'\n", CHECKPOINT_FILE);

        if (maybeResume(es))
            fail("Failed to resume checkpoint\n");
    }

  #if SEPARATION_OPENCL
    if (setupSeparationCL(&ci, ap, ias, clr, &useImages) != CL_SUCCESS)
        fail("Failed to setup CL\n");
  #elif SEPARATION_CAL
    if (separationCALInit(&ci, clr) != CAL_RESULT_OK)
        fail("Failed to setup CAL\n");
  #endif

#ifdef ANDROID
    if (armExt==ARM_CPU_NOVFP && ap->fast_h_prob)
    {
        int i=0;
        unsigned int nstreams = ap->number_streams;
        unsigned int convolve = ap->convolve;
        warn("Use IntFp Engine\n");
        sci = (StreamConstantsIntFp*) mwMallocA(sizeof(StreamConstantsIntFp) * ap->number_streams);
        for (i=0; i < nstreams; i++)
        {
            fp_to_intfp(sc[i].a.x,&(sci[i].a[0]));
            fp_to_intfp(sc[i].a.y,&sci[i].a[1]);
            fp_to_intfp(sc[i].a.z,&sci[i].a[2]);
            fp_to_intfp(sc[i].a.w,&sci[i].a[3]);
            fp_to_intfp(-sc[i].c.x,&sci[i].c[0]);
            fp_to_intfp(-sc[i].c.y,&sci[i].c[1]);
            fp_to_intfp(-sc[i].c.z,&sci[i].c[2]);
            fp_to_intfp(-sc[i].c.w,&sci[i].c[3]);
            fp_to_intfp(sc[i].sigma_sq2_inv,&sci[i].sigma_sq2_inv);
        }
    }
#endif
       
#ifdef ANDROID
    if (armExt == ARM_CPU_NOVFP && ap->fast_h_prob)
        calculateIntegralsIntFp(ap, ias, sci, sg, es, clr, &ci, useImages);
    else
        calculateIntegrals(ap, ias, sc, sg, es, clr, &ci, useImages);
#else
    calculateIntegrals(ap, ias, sc, sg, es, clr, &ci, useImages);
#endif

    if (!ignoreCheckpoint)
    {
        finalCheckpoint(es);
    }

    getFinalIntegrals(results, es, ap->number_streams, ap->number_integrals);
    freeEvaluationState(es);

    if (readStarPoints(&sp, star_points_file))
    {
        rc = 1;
        warn("Failed to read star points file\n");
    }
    else
    {
        /* TODO: likelihood on GPU with OpenCL. Make this less of a
         * mess. The different versions should appear to be the
         * same. */

      #if SEPARATION_CAL
        if (do_separation)
        {
            /* No separation on GPU */
            rc = likelihood(results, ap, &sp, sc, streams, sg, do_separation, separation_outfile);
        }
        else
        {
            //rc = likelihoodCAL(results, ap, &sp, sc, streams, sg, clr, &ci);
            rc = likelihood(results, ap, &sp, sc, streams, sg, do_separation, separation_outfile);
        }
      #else
#ifdef ANDROID
        if (armExt == ARM_CPU_NOVFP && ap->fast_h_prob)
            rc = likelihood_intfp(results, ap, &sp, sci, streams, sg, do_separation, separation_outfile);
        else
            rc = likelihood(results, ap, &sp, sc, streams, sg, do_separation, separation_outfile);
#else
        rc = likelihood(results, ap, &sp, sc, streams, sg, do_separation, separation_outfile);
#endif
      #endif /* SEPARATION_CAL */

        rc |= checkSeparationResults(results, ap->number_streams);
    }

    freeStarPoints(&sp);
    freeStreamGauss(sg);

  #if SEPARATION_OPENCL
    mwDestroyCLInfo(&ci);
  #elif SEPARATION_CAL
    mwCALShutdown(&ci);
  #endif

#ifdef ANDROID
    if (armExt == ARM_CPU_NOVFP && ap->fast_h_prob)
        mwFreeA(sci);
#endif
    
    return rc;
}