Esempio n. 1
0
int InitializeProblemManager(unsigned int maxnumproblems)
{
  unsigned int i, probcount;

  if (maxnumproblems == 0 || probmanstatics.probtable != ((Problem **)0))
    return -1;
  if (maxnumproblems > (16*1024))
    maxnumproblems = (16*1024);     // XXX
                                    // a comment to explain this magic
                                    // number would be nice.  Why not 128
                                    // as in GetMaxCrunchersPermitted() ?
                                    // a #define for magic numbers would be
                                    // good.

  probmanstatics.probtable=(Problem **)
                            malloc(maxnumproblems * sizeof(Problem *));
  if (probmanstatics.probtable == ((Problem **)0))
    return -1;

  probmanstatics.tablesize = maxnumproblems;
  memset((void *)probmanstatics.probtable,0,
         (maxnumproblems * sizeof(Problem *)));

  probcount = 0;
  for (i=0; i<maxnumproblems; i++)
  {
    probmanstatics.probtable[i]=ProblemAlloc(i);
    if (probmanstatics.probtable[i]==((Problem *)0))
      break;
    probcount++;
  }
  if (probcount != maxnumproblems)
  {
    unsigned int j;

    for(j=0; j<probcount; j++)
      ProblemFree(probmanstatics.probtable[j]);

    free((void *)probmanstatics.probtable);
    probmanstatics.probtable = ((Problem **)0);
    probmanstatics.probcount = 0;
    probmanstatics.tablesize = 0;
    return -1;
  }
  probmanstatics.probcount = probcount;
  return (int)(probmanstatics.probcount);
}
Esempio n. 2
0
int DeinitializeProblemManager(void)
{
  Problem **probtable = probmanstatics.probtable;

  if (probtable != ((Problem **)0))
  {
    for (; probmanstatics.probcount>0; probmanstatics.probcount--)
    {
      if (probtable[probmanstatics.probcount-1])
        ProblemFree(probtable[probmanstatics.probcount-1]);
      probtable[probmanstatics.probcount-1] = ((Problem *)0);
    }
    free((void *)probtable);
  }

  probmanstatics.probcount = 0;
  probmanstatics.tablesize = 0;
  probmanstatics.probtable = ((Problem **)0);
  return 0;
}
Esempio n. 3
0
static long __bench_or_test( Client *client, int which, 
                            unsigned int cont_i, unsigned int benchsecs, int in_corenum )
{
  long rc = -1;
  /* FIXME: without -devicenum, test/bench will be run on GPU 0 only */
  int device = hackGetUsedDeviceIndex(client, 0);

  if (selcore_initlev > 0                  /* core table is initialized? */
      && cont_i < CONTEST_COUNT)           /* valid contest id? */
  {
    /* save current state */
    int user_cputype = selcorestatics.user_cputype[cont_i];
    int corenum = selcorestatics.corenum[cont_i];
    int coreidx, corecount = corecount_for_contest( cont_i );
    int fastest = -1;
    int hardcoded = selcoreGetPreselectedCoreForProject(cont_i, device);
    u32 bestrate_hi = 0, bestrate_lo = 0, refrate_hi = 0, refrate_lo = 0;

    rc = 0; /* assume nothing done */
    for (coreidx = 0; coreidx < corecount; coreidx++)
    {
      /* only bench/test cores that won't be automatically substituted */
      if (apply_selcore_substitution_rules(cont_i, coreidx, device) == coreidx)
      {
        if (in_corenum < 0)
            selcorestatics.user_cputype[cont_i] = coreidx; /* as if user set it */
        else
        {
          if( in_corenum < corecount )
          {
            selcorestatics.user_cputype[cont_i] = in_corenum;
            coreidx = corecount;
          }
          else  /* invalid core selection, test them all */
          {
            selcorestatics.user_cputype[cont_i] = coreidx;
            in_corenum = -1;
          }
        }
        selcorestatics.corenum[cont_i] = -1; /* reset to show name */

        if (which == 't') /* selftest */
          rc = SelfTest( client, cont_i );
        else if (which == 's') /* stresstest */
          rc = StressTest( client, cont_i );
        else {
          u32 temprate_hi, temprate_lo;
          rc = TBenchmark( client, cont_i, benchsecs, 0, &temprate_hi, &temprate_lo );
          if (rc > 0 && selcorestatics.corenum[cont_i] == hardcoded) {
            refrate_hi = temprate_hi;
            refrate_lo = temprate_lo;
          }
          if (rc > 0 && (temprate_hi > bestrate_hi || (temprate_hi == bestrate_hi && temprate_lo > bestrate_lo))) {
            bestrate_hi = temprate_hi;
            bestrate_lo = temprate_lo;
            fastest     = selcorestatics.corenum[cont_i];
          }
        }
        #if (CLIENT_OS != OS_WIN32 || !defined(SMC))
        if (rc <= 0) /* failed (<0) or not supported (0) */
          break; /* stop */
        #else
        // HACK! to ignore failed benchmark for x86 rc5 smc core #7 if
        // started from menu and another cruncher is active in background.
        if (rc <= 0) /* failed (<0) or not supported (0) */
        {
          if ( which == 'b' &&  cont_i == RC5 && coreidx == 7 )
            ; /* continue */
          else
            break; /* stop */
        }
        #endif
      }
    } /* for (coreidx = 0; coreidx < corecount; coreidx++) */

    selcorestatics.user_cputype[cont_i] = user_cputype;
    selcorestatics.corenum[cont_i] = corenum;

    /* Summarize the results if multiple cores have been benchmarked (#4108) */
#if (CLIENT_CPU != CPU_CELLBE)
    /* Not applicable for Cell due to PPU/SPU core selection hacks */
    if (in_corenum < 0 && fastest >= 0 && (bestrate_hi != 0 || bestrate_lo != 0)) {
      double percent = 100.0 * ((double)refrate_hi  * 4294967296.0 + (double)refrate_lo) /
                               ((double)bestrate_hi * 4294967296.0 + (double)bestrate_lo);
      char bestrate_str[32], refrate_str[32];

      U64stringify(bestrate_str, sizeof(bestrate_str), bestrate_hi, bestrate_lo, 2, CliGetContestUnitFromID(cont_i));
      U64stringify(refrate_str,  sizeof(refrate_str),  refrate_hi,  refrate_lo,  2, CliGetContestUnitFromID(cont_i));

      Log("%s benchmark summary :\n"
          "Default core : #%d (%s) %s/sec\n"
          "Fastest core : #%d (%s) %s/sec\n",
          CliGetContestNameFromID(cont_i), hardcoded,
          (hardcoded >= 0 ? selcoreGetDisplayName(cont_i, hardcoded) : "undefined"),
          refrate_str,
          fastest, selcoreGetDisplayName(cont_i, fastest), bestrate_str);
          
      if (percent < 100 && hardcoded >= 0 && hardcoded != fastest) {
        if (percent >= 97) {
          Log("Core #%d is marginally faster than the default core.\n"
              "Testing variability might lead to pick one or the other.\n",
              fastest);
        }
        else {
          Log("Core #%d is significantly faster than the default core.\n"
#if (CLIENT_CPU != CPU_CUDA && CLIENT_CPU != CPU_ATI_STREAM && CLIENT_CPU != CPU_OPENCL)
              "Please file a bug report along with the output of\n-cpuinfo.\n"
#else
              "The GPU core selection has been made as a tradeoff between core speed\n"
              "and responsiveness of the graphical desktop.\n"
              "Please file a bug report along with the output of -gpuinfo\n"
              "only if the the faster core selection does not degrade graphics performance.\n"
#endif
              "Changes in cores and selection are frequently made,\n"
              "so be sure to test with the latest client version,\n"
              "typically a pre-release, before filing a bug report.\n",
              fastest);
        }
      }
    }
#endif // CPU_CELLBE

#if (CLIENT_OS == OS_RISCOS) && defined(HAVE_X86_CARD_SUPPORT)
    if (rc > 0 && cont_i == RC5 && 
          GetNumberOfDetectedProcessors() > 1) /* have x86 card */
    {
      Problem *prob = ProblemAlloc(); /* so bench/test gets threadnum+1 */ /* FIXME: not true anymore */
      rc = -1; /* assume alloc failed */
      if (prob)
      {
        Log("RC5: using x86 core.\n" );
        if (which != 's') /* bench */
          rc = TBenchmark( client, cont_i, benchsecs, 0 );
        else
          rc = SelfTest( client, cont_i );
        ProblemFree(prob);
      }
    }
    #endif

  } /* if (cont_i < CONTEST_COUNT) */

  return rc;
}
Esempio n. 4
0
// returns 0 if not supported, <0 on failed or break
static long SelfTestInternal( Client *client, unsigned int contest, int stress )
{
  int threadpos, threadcount = 1;
  long successes = 0L;
  const char *contname;
  int userbreak = 0;
  unsigned long runtime_sec, runtime_usec;

  if (CheckExitRequestTrigger())
    return 0;

  if (contest >= CONTEST_COUNT)
  {
    Log("test::error. invalid contest %u\n", contest );
    return 0;
  }
  if (!IsProblemLoadPermitted(-1, contest)) /* also checks HAVE_xxx_CORES */
    return 0;

  contname = CliGetContestNameFromID( contest );
  for ( threadpos = 0; 
        !userbreak && successes >= 0L && threadpos < threadcount;
        threadpos++ )
  {
    char lastmsg[100];
    unsigned int testnum;

    ClientEventSyncPost( CLIEVENT_SELFTEST_STARTED, &contest, sizeof(contest) );
    successes = 0L;
    lastmsg[0] = '\0';

    runtime_sec = runtime_usec = 0;
    for ( testnum = 0 ; !userbreak && testnum < TEST_CASE_COUNT ; testnum++ )
    {
      const u32 (*test_cases)[TEST_CASE_COUNT][TEST_CASE_DATA] = NULL;
      u32 expectedsolution_hi, expectedsolution_mid, expectedsolution_lo;
      ContestWork contestwork;
      Problem *thisprob;

      memset(&contestwork, 0, sizeof(contestwork));
      expectedsolution_lo = expectedsolution_mid = expectedsolution_hi = 0; /* shaddup compiler */
#if defined(HAVE_RC5_72_CORES)
      if (contest == RC5_72)
      {
        test_cases = (const u32 (*)[TEST_CASE_COUNT][TEST_CASE_DATA])rc5_72_test_cases;
        expectedsolution_hi  = (*test_cases)[testnum][0];
        expectedsolution_mid = (*test_cases)[testnum][1];
        expectedsolution_lo  = (*test_cases)[testnum][2];
        contestwork.bigcrypto.key.hi  = expectedsolution_hi;
        contestwork.bigcrypto.key.mid = expectedsolution_mid;
        contestwork.bigcrypto.key.lo  = expectedsolution_lo & 0xFFFF0000L;
        if (testnum>1 && testnum<=7)
        {
          contestwork.bigcrypto.key.lo -= 0x00010000;
          if ((expectedsolution_lo & 0xFFFF0000L) == 0)
          {
            contestwork.bigcrypto.key.mid--;
            if (!~contestwork.bigcrypto.key.mid)
              contestwork.bigcrypto.key.hi--;
          }
        }
      }
#endif
#if defined(HAVE_OGR_CORES)
      if (contest == OGR_NG)
      {
        test_cases = (const u32 (*)[TEST_CASE_COUNT][TEST_CASE_DATA])ogr_test_cases;
        expectedsolution_lo = (*test_cases)[testnum][0];
      }
#endif
#if defined(HAVE_OGR_PASS2)
      if (contest == OGR_P2)
      {
        test_cases = (const u32 (*)[TEST_CASE_COUNT][TEST_CASE_DATA])ogrp2_test_cases;
        expectedsolution_lo = (*test_cases)[testnum][0];
      }
#endif
      //if (0)
      //{
      //  PROJECT_NOT_HANDLED(contest);
      //}

      switch (contest) 
      {
        #if defined(HAVE_CRYPTO_V2)
        case RC5_72:
        {
          contestwork.bigcrypto.iv.lo =  ( (*test_cases)[testnum][3] );
          contestwork.bigcrypto.iv.hi =  ( (*test_cases)[testnum][4] );
          contestwork.bigcrypto.plain.lo = ( (*test_cases)[testnum][5] );
          contestwork.bigcrypto.plain.hi = ( (*test_cases)[testnum][6] );
          contestwork.bigcrypto.cypher.lo = ( (*test_cases)[testnum][7] );
          contestwork.bigcrypto.cypher.hi = ( (*test_cases)[testnum][8] );
          contestwork.bigcrypto.keysdone.lo = ( 0 );
          contestwork.bigcrypto.keysdone.hi = ( 0 );
          contestwork.bigcrypto.iterations.lo = ( 0x00020000L ); // 17 bits instead of 16
          contestwork.bigcrypto.iterations.hi = ( 0 );
          contestwork.bigcrypto.randomsubspace = ( 0xFFFF ); // not defined (invalid)
          break;
        }
        #endif
        #if defined(HAVE_OGR_PASS2)
        case OGR_P2:
        {
          int tcd;
          contestwork.ogr_p2.workstub.stub.marks = (u16)((*test_cases)[testnum][1]);
          contestwork.ogr_p2.minpos              = (u32)((*test_cases)[testnum][2]);
          contestwork.ogr_p2.workstub.stub.length = 0;
          for (tcd = 0; tcd < TEST_CASE_DATA-3; tcd++) 
          {
            contestwork.ogr_p2.workstub.stub.diffs[tcd] = (u16)((*test_cases)[testnum][3+tcd]);
            if (contestwork.ogr_p2.workstub.stub.diffs[tcd] == 0)
              break;
            contestwork.ogr_p2.workstub.stub.length++;  
          }
          contestwork.ogr_p2.workstub.worklength = 0;
          contestwork.ogr_p2.nodes.lo = contestwork.ogr_p2.nodes.hi = 0;
          break;
        }  
        #endif
        #if defined(HAVE_OGR_CORES)
        case OGR_NG: 
        {
          int tcd;
          contestwork.ogr_ng.workstub.stub.marks = (u16)((*test_cases)[testnum][1]);
          contestwork.ogr_ng.workstub.stub.length = 0;
          for (tcd = 0; tcd < TEST_CASE_DATA-2; tcd++) 
          {
            contestwork.ogr_ng.workstub.stub.diffs[tcd] = (u16)((*test_cases)[testnum][2+tcd]);
            if (contestwork.ogr_ng.workstub.stub.diffs[tcd] == 0)
              break;
            contestwork.ogr_ng.workstub.stub.length++;  
          }
          contestwork.ogr_ng.workstub.worklength = 0;
          contestwork.ogr_ng.nodes.lo = contestwork.ogr_ng.nodes.hi = 0;
          contestwork.ogr_ng.workstub.collapsed = 0;
          break;
        }  
        #endif
        default:
          PROJECT_NOT_HANDLED(contest);
          userbreak = 1;
          break;
      } /* switch */

      if (userbreak)
        break;

      thisprob = ProblemAlloc();
      if (thisprob)
      {
        u32 tslice = 0x4000;
        u32 sec = 0;
        int non_preemptive_env = 0;
        int resultcode;

        #if (CLIENT_OS == OS_NETWARE)
        non_preemptive_env = (!nwCliIsPreemptiveEnv());
        if (non_preemptive_env)
          tslice = 2048;
        #elif (CLIENT_OS == OS_WIN16 || CLIENT_OS == OS_WIN32) || (CLIENT_OS == OS_WIN64) /* or win32s */
        non_preemptive_env = (winGetVersion() < 400);
        if (non_preemptive_env)
          tslice = 2048;
        #elif (CLIENT_OS == OS_RISCOS)
        non_preemptive_env = riscos_check_taskwindow();
        if (non_preemptive_env)
          tslice = 32768;
        #endif
        #if defined(HAVE_OGR_CORES)
        if (contest == OGR_NG && stress)
          tslice = 1;
        #endif

        if (ProblemLoadState( thisprob, &contestwork,
                              contest, tslice, 0, 0, 0, 0, client ) == 0)
        {
          ClientEventSyncPost( CLIEVENT_SELFTEST_TESTBEGIN, (void *)thisprob, -1 );
          do
          {
            if (non_preemptive_env)
            {
              #if (CLIENT_OS == OS_WIN16) || (CLIENT_OS == OS_WIN32) || (CLIENT_OS == OS_WIN64) /* or win32s */
              w32Yield(); /* pump waiting messages */
              #elif (CLIENT_OS == OS_RISCOS)
              riscos_upcall_6();
              #elif (CLIENT_OS == OS_NETWARE)
              ThreadSwitchLowPriority();
              #endif
            }

            if (CheckExitRequestTrigger())
            {
              userbreak = 1;
              break;
            }

            if (contest == OGR_P2 || contest == OGR_NG) {
              /* show /some/ activity (the time changes) */
              if (thisprob->pub_data.runtime_sec >= sec) {
                LogScreen("\r%s: Test %02d working...", contname, testnum + 1 );
                sec = thisprob->pub_data.runtime_sec + 1;
              }
            }
          } while ( ProblemRun(thisprob) == RESULT_WORKING );

          resultcode = RESULT_WORKING;
          if (!userbreak)
          {
            const char *resulttext = NULL;
            resultcode = ProblemRetrieveState( thisprob, &contestwork, NULL, 1, 0 );

            runtime_sec += thisprob->pub_data.runtime_sec;
            runtime_usec += thisprob->pub_data.runtime_usec;
            if (runtime_usec >= 1000000ul)
            {
              runtime_sec++;
              runtime_usec-=1000000ul;
            }

            switch (contest)
            {
              #ifdef HAVE_CRYPTO_V2
              case RC5_72:
              {
                int expected_cmc_count = (int)(*test_cases)[testnum][9];
                    // may be <= 0 if no solution, but perhaps some cmc key(s)
                int logMode;

                resulttext = NULL; /* assume success by default */
                if ( expected_cmc_count == 0 &&        /* expect no solution and no cmc */
                     ( resultcode != RESULT_NOTHING || 
                       contestwork.bigcrypto.check.count != 0 ) )
                {
                  contestwork.bigcrypto.key.lo  =
                  contestwork.bigcrypto.key.mid = contestwork.bigcrypto.key.hi = 0;
                  resulttext = "FAILED0";
                }
                else if ( expected_cmc_count < 0 &&       /* expect no solution but cmc */
                          ( resultcode != RESULT_NOTHING || 
                            contestwork.bigcrypto.check.count != (u32)(-expected_cmc_count)) )
                {
                  //contestwork.bigcrypto.key.lo  =
                  //contestwork.bigcrypto.key.mid = contestwork.bigcrypto.key.hi = 0;
                  resulttext = "FAILED1";
                }
                else if ( expected_cmc_count > 0 && resultcode != RESULT_FOUND )     /* no solution */
                {
                  contestwork.bigcrypto.key.lo  =
                  contestwork.bigcrypto.key.mid = contestwork.bigcrypto.key.hi = 0;
                  resulttext = "FAILED2";
                }
                else if ( expected_cmc_count > 0 &&
                          ( contestwork.bigcrypto.key.hi  != expectedsolution_hi  ||
                            contestwork.bigcrypto.key.mid != expectedsolution_mid ||
                            contestwork.bigcrypto.key.lo  != expectedsolution_lo ) )
                {                                                  /* wrong solution */
                  resulttext = "FAILED3";
                }
                else if ( expected_cmc_count > 0 && 
                          contestwork.bigcrypto.check.count != (u32)expected_cmc_count )
                {
                  resulttext = "FAILED4";
                }
                else if ( expected_cmc_count != 0 &&
                          ( contestwork.bigcrypto.check.hi  != expectedsolution_hi  ||
                            contestwork.bigcrypto.check.mid != expectedsolution_mid ||
                            contestwork.bigcrypto.check.lo  != expectedsolution_lo ) )
                {                                          /* wrong partial solution */
                  resulttext = "FAILED5";
                }
                else if ( expected_cmc_count <= 0 )         /* correct 'no' solution */
                {
                  expectedsolution_lo = contestwork.bigcrypto.key.lo;
                }
                else                                             /* correct solution */
                {
                  // fallthru to success
                }

                if (resulttext == NULL)
                {
                  resulttext = "passed";
                  successes++;
                  logMode = LOGAS_LOGSCREEN;
                }
                else
                {
                  resultcode = -1;
                  logMode = LOGAS_LOG;
                }
                LogTo( logMode, "\r%s: Test %02d %s: %02X:%08X:%08X-%02X:%08X:%08X\n",
                   contname, testnum + 1, resulttext, contestwork.bigcrypto.key.hi,
                   contestwork.bigcrypto.key.mid, contestwork.bigcrypto.key.lo,
                   expectedsolution_hi, expectedsolution_mid, expectedsolution_lo );
                break;
              }
              #endif
              #ifdef HAVE_OGR_PASS2
              case OGR_P2:
              {
                if (expectedsolution_lo & 0x80000000)  // no solution
                {
                  expectedsolution_lo = ~expectedsolution_lo;
                  if (resultcode != RESULT_NOTHING ||
                    contestwork.ogr_p2.nodes.lo != expectedsolution_lo)
                  {
                    resulttext = "FAILED";
                    resultcode = -1;
                  }
                  else
                  {
                    resulttext = "passed";
                    successes++;
                  }
                }
                else if (resultcode != RESULT_FOUND ||
                    contestwork.ogr_p2.nodes.lo != expectedsolution_lo)
                {
                  resulttext = "FAILED";
                  resultcode = -1;
                }
                else
                {
                  resulttext = "passed";
                  successes++;
                }
                LogScreen( "\r%s: Test %02d %s: %s %08X-%08X\n",
                                  contname, testnum + 1, resulttext,
                                  ogr_stubstr(&contestwork.ogr_p2.workstub.stub),
                                  contestwork.ogr_p2.nodes.lo, expectedsolution_lo );
                break;
              }
              #endif
              #ifdef HAVE_OGR_CORES
              case OGR_NG:
              {
                int logTo;

                resulttext = NULL; // assume success
                if (expectedsolution_lo & 0x80000000)  // no solution
                {
                  expectedsolution_lo = ~expectedsolution_lo;
                  if (resultcode != RESULT_NOTHING ||
                    contestwork.ogr_ng.nodes.lo != expectedsolution_lo)
                  {
                    resulttext = "FAILED1";
                  }
                }
                else if (resultcode != RESULT_FOUND ||
                    contestwork.ogr_ng.nodes.lo != expectedsolution_lo)
                {
                  resulttext = "FAILED2";
                }

                if (resulttext == NULL)
                {
                  resulttext = "passed ";
                  successes++;
                  logTo = LOGAS_LOGSCREEN;  /* same as LogScreen() */
                }
                else
                {
                  resultcode = -1;
                  logTo = LOGAS_LOG; /* same as Log() */
                }

                LogTo( logTo, "\r%s: Test %02d %s: %s %08X-%08X\n",
                                     contname, testnum + 1, resulttext,
                                     ogrng_stubstr(&contestwork.ogr_ng.workstub),
                                     contestwork.ogr_ng.nodes.lo, expectedsolution_lo );
                break;
              }
              #endif
              default:
              {
                PROJECT_NOT_HANDLED(contest);
                break;
              }
            } /* switch */

          } /* if (!userbreak) */

          ClientEventSyncPost( CLIEVENT_SELFTEST_TESTEND, &resultcode, sizeof(resultcode) );
        } /* if load state ok */
        else {
          Log( "\r%s: Test %02d load failed\n", contname, testnum + 1);
        }
        ProblemFree(thisprob);
      } /* if ProblemAlloc() */
      #ifdef HAVE_OGR_CORES
      if (contest == OGR_NG) {
        // Release cached limits once they are no longer required. We assume the
        // tests are sorted by number of marks.
        if (testnum == TEST_CASE_COUNT - 1 || (*test_cases)[testnum][1] != (*test_cases)[testnum+1][1]) {
          ogr_cleanup_cache();
        }
      }
      #endif
    } /* for ( testnum = 0 ; testnum < TEST_CASE_COUNT ; testnum++ ) */

    if (userbreak)
      successes = -1L;
    else  
    {
      if (successes > 0L)
      {
        Log( "%s: %ld/%ld Tests Passed (%lu.%06lu seconds)\n", contname,
           successes, (long) TEST_CASE_COUNT, runtime_sec, runtime_usec );
      }
      if (successes != ((long)TEST_CASE_COUNT))
      {
        Log( "%s: WARNING WARNING WARNING: %ld Tests FAILED!!!\n", 
          contname, (((long)TEST_CASE_COUNT) - successes) );
        successes = -1L;
      }
    }
    ClientEventSyncPost( CLIEVENT_SELFTEST_FINISHED, &successes, sizeof(successes) );

  } /* for ( threadpos = 0; threadpos < threadcount; threadpos++ ) */

  return (successes);
}