static void timer_handler(int) { char buf[MSG_CHANNEL_SIZE]; GRAPHICS_MSG m; BOINC_STATUS boinc_status; if (*g_bmsp->app_client_shmp) { if ((*g_bmsp->app_client_shmp)->shm->graphics_request.get_msg(buf)) { (*g_bmsp->app_client_shmp)->decode_graphics_msg(buf, m); switch (m.mode) { case MODE_REREAD_PREFS: //only reread graphics prefs if we have a window open // switch (current_graphics_mode){ case MODE_WINDOW: case MODE_FULLSCREEN: app_graphics_reread_prefs(); break; } break; case MODE_HIDE_GRAPHICS: case MODE_WINDOW: case MODE_FULLSCREEN: case MODE_BLANKSCREEN: if (strlen(m.display)) { setenv("DISPLAY",m.display,1); } set_mode(m.mode); break; } } if (acked_graphics_mode != current_graphics_mode) { bool sent = (*g_bmsp->app_client_shmp)->shm->graphics_reply.send_msg( xml_graphics_modes[current_graphics_mode] ); if (sent) acked_graphics_mode = current_graphics_mode; } } boinc_get_status(&boinc_status); if (! boinc_status.suspended) suspend_render = false; if (suspend_render) { glutTimerFunc(TIMER_INTERVAL_SUSPENDED_MSEC, timer_handler, 0); } else { maybe_render(); glutTimerFunc(TIMER_INTERVAL_MSEC, timer_handler, 0); } return; }
void update_shmem() { if (!shmem) return; // always do this; otherwise a graphics app will immediately // assume we're not alive shmem->update_time = dtime(); // Check whether a graphics app is running, // and don't bother updating shmem if so. // This doesn't matter here, // but may be worth doing if updating shmem is expensive. // if (shmem->countdown > 0) { // the graphics app sets this to 5 every time it renders a frame shmem->countdown--; } else { return; } shmem->fraction_done = boinc_get_fraction_done(); shmem->cpu_time = boinc_worker_thread_cpu_time();; boinc_get_status(&shmem->status); }
// maybe_render() can be called directly by GLUT when a window is // uncovered, so we let that happen even if suspend_render is true. static void maybe_render() { int width, height; BOINC_STATUS boinc_status; if (visible && (current_graphics_mode != MODE_HIDE_GRAPHICS)) { width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); if (throttled_app_render(width, height, dtime())) { glutSwapBuffers(); #ifdef __APPLE__ switch (current_graphics_mode) { case MODE_WINDOW: MacGLUTFix(false); if (need_show) { glutShowWindow(); need_show = false; } break; case MODE_FULLSCREEN: case MODE_BLANKSCREEN: MacGLUTFix(true); if (need_show) { glutShowWindow(); need_show = false; } break; } #endif // Always render once after app is suspended in case app displays // different graphics when suspended, then stop rendering boinc_get_status(&boinc_status); if (boinc_status.suspended) suspend_render = true; } } }
int main(int argc, char **argv) { int retval; double fd; char output_path[512]; //, chkpt_path[512]; //FILE* state; retval = boinc_init(); if (retval) { fprintf(stderr, "boinc_init returned %d\n", retval); exit(retval); } // extract a --device option std::vector<char*> argVec; int cudaDevice = -1; for(int ii = 0; ii < argc; ii++) { if(cudaDevice < 0 && strcmp(argv[ii], "--device") == 0 && ii + 1 < argc) cudaDevice = atoi(argv[++ii]); else argVec.push_back(argv[ii]); } argc = (int)argVec.size(); argv = &argVec[0]; if(cudaDevice < 0) cudaDevice = 0; boinc_begin_critical_section(); // set the cuda device if ( rcuda::SetCudaDevice(cudaDevice) != 0 ) { fprintf(stderr, "Error setting device %u. Temporary exiting for 60 secs\n", cudaDevice); boinc_temporary_exitHack(); } cudaDeviceProp deviceProp; if(cudaGetDeviceProperties(&deviceProp, cudaDevice) == cudaErrorInvalidDevice) { fprintf(stderr, "Error querying device %u. Temporary exiting for 60 secs\n", cudaDevice); boinc_temporary_exitHack(); } #ifdef WIN32 SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); #endif int buffCount = 0x2000; int chainSize = 100; if(deviceProp.major == 1) { /* buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor buffCount *= deviceProp.maxThreadsPerBlock / 64; // (BLOCK_X_SIZE) // buffCount *= 24; if(deviceProp.minor <= 1) buffCount *= 24; // 24 warps per multiprocessor for compute 1.0 and 1.1 else buffCount *= 32; // 32 warps per multiprocessor for compute 1.2 and 1.3 */ buffCount = 0x2000; } else if(deviceProp.major == 2) { chainSize = 200; /* buffCount = deviceProp.multiProcessorCount * 8;// 8 blocks per multiprocessor buffCount *= deviceProp.maxThreadsPerBlock / 64; //(BLOCK_X_SIZE) buffCount *= 32; // 48 warps per multiprocessor for compute 2.x /* if(deviceProp.minor == 1) { buffCount *= 2; } */ buffCount = 0x4000; } if(cudaDevice > 0) { chainSize = 1000; } if(argc < 10) { fprintf(stderr, "Not enough parameters"); return -1; } std::string sHashRoutineName, sCharsetName, sSalt, sCheckPoints; uint32 nRainbowChainCount, nPlainLenMin, nPlainLenMax, nRainbowTableIndex, nRainbowChainLen; uint64 nChainStart; sHashRoutineName = argv[1]; sCharsetName = argv[2]; nPlainLenMin = atoi(argv[3]); nPlainLenMax = atoi(argv[4]); nRainbowTableIndex = atoi(argv[5]); nRainbowChainLen = atoi(argv[6]); nRainbowChainCount = atoi(argv[7]); #ifdef _WIN32 nChainStart = _atoi64(argv[8]); #else nChainStart = atoll(argv[8]); #endif sCheckPoints = argv[9]; std::vector<int> vCPPositions; char *cp = strtok((char *)sCheckPoints.c_str(), ","); while(cp != NULL) { vCPPositions.push_back(atoi(cp)); cp = strtok(NULL, ","); } if(argc == 11) { sSalt = argv[10]; } //std::cout << "Starting ChainGenerator" << std::endl; // Setup CChainWalkContext //std::cout << "ChainGenerator started." << std::endl; if (!CChainWalkContext::SetHashRoutine(sHashRoutineName)) { fprintf(stderr, "hash routine %s not supported\n", sHashRoutineName.c_str()); return 1; } //std::cout << "Hash routine validated" << std::endl; if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax)) { std::cerr << "charset " << sCharsetName << " not supported" << std::endl; return 2; } //std::cout << "Plain charset validated" << std::endl; if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex)) { std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl; return 3; } //std::cout << "Rainbowtable index validated" << std::endl; if(sHashRoutineName == "mscache")// || sHashRoutineName == "lmchall" || sHashRoutineName == "halflmchall") { // Convert username to unicode const char *szSalt = sSalt.c_str(); int salt_length = strlen(szSalt); unsigned char cur_salt[256]; for (int i=0; i<salt_length; i++) { cur_salt[i*2] = szSalt[i]; cur_salt[i*2+1] = 0x00; } CChainWalkContext::SetSalt(cur_salt, salt_length*2); } else if(sHashRoutineName == "halflmchall") { // The salt is hardcoded into the hash routine // CChainWalkContext::SetSalt((unsigned char*)&salt, 8); } else if(sHashRoutineName == "oracle") { CChainWalkContext::SetSalt((unsigned char *)sSalt.c_str(), sSalt.length()); } //std::cout << "Opening chain file" << std::endl; // Open file boinc_resolve_filename("result", output_path, sizeof(output_path)); fclose(boinc_fopen(output_path, "a")); FILE *outfile = boinc_fopen(output_path, "r+b"); if (outfile == NULL) { std::cerr << "failed to create " << output_path << std::endl; return 4; } // Check existing chains unsigned int nDataLen = (unsigned int)GetFileLen(outfile); // Round to boundary nDataLen = nDataLen / 10 * 10; if (nDataLen == nRainbowChainCount * 10) { std::cerr << "precomputation of this rainbow table already finished" << std::endl; fclose(outfile); return 0; } fseek(outfile, nDataLen, SEEK_SET); //XXX size_t isn't 32/64 clean size_t nReturn; CChainWalkContext cwc; uint64 nIndex[2]; //time_t tStart = time(NULL); // std::cout << "Starting to generate chains" << std::endl; int maxCalcBuffSize = rcuda::GetChainsBufferSize( buffCount ); std::cerr << "maxCalcBuffSize - estimated: " << buffCount << ". Chosen: " << maxCalcBuffSize << std::endl; uint64 *calcBuff = new uint64[2*maxCalcBuffSize]; int ii; CudaCWCExtender ex(&cwc); rcuda::RCudaTask cuTask; ex.Init(); for(int nCurrentCalculatedChains = nDataLen / 10, calcSize; nCurrentCalculatedChains < nRainbowChainCount; ) { fd = (double)nCurrentCalculatedChains / (double)nRainbowChainCount; boinc_fraction_done(fd); cuTask.hash = ex.GetHash(); cuTask.startIdx = nChainStart + nCurrentCalculatedChains; cuTask.idxCount = std::min<int>(nRainbowChainCount - nCurrentCalculatedChains, maxCalcBuffSize); cuTask.dimVec = ex.GetPlainDimVec(); cuTask.dimVecSize = ex.GetPlainDimVecSize()/2; cuTask.charSet = ex.GetCharSet(); cuTask.charSetSize = ex.GetCharSetSize(); cuTask.cpPositions = &vCPPositions[0]; cuTask.cpPosSize = vCPPositions.size(); cuTask.reduceOffset = ex.GetReduceOffset(); cuTask.plainSpaceTotal = ex.GetPlainSpaceTotal(); cuTask.rainbowChainLen = nRainbowChainLen; cuTask.kernChainSize = chainSize; for(ii = 0; ii < cuTask.idxCount; ii++) { calcBuff[2*ii] = cuTask.startIdx + ii; calcBuff[2*ii+1] = 0; } calcSize = rcuda::CalcChainsOnCUDA(&cuTask, calcBuff); BOINC_STATUS boinc_status; boinc_get_status(&boinc_status); if (boinc_status.quit_request || boinc_status.abort_request) { boinc_end_critical_section(); while (1) boinc_sleep(1); } if(calcSize > 0) { nCurrentCalculatedChains += calcSize; for(ii = 0; ii < cuTask.idxCount; ii++) { nIndex[0] = cuTask.startIdx + ii; // nReturn = fwrite(nIndex, 1, 8, outfile); nReturn = fwrite(calcBuff+(2*ii), 1, 8, outfile); nReturn += fwrite(calcBuff+(2*ii+1), 1, 2, outfile); if(nReturn != 10) { std::cerr << "disk write fail" << std::endl; fclose(outfile); return 9; } } } else { std::cerr << "Calculations on CUDA failed!" << std::endl; fclose(outfile); return -1; } } delete [] calcBuff; #ifdef _DEBUG std::cout << "Generation completed" << std::endl; #endif fclose(outfile); boinc_fraction_done(1); boinc_finish(0); }
int main(int argc, char** argv) { BOINC_OPTIONS boinc_options; BOINC_STATUS boinc_status; char buf[256]; int retval; memset(&boinc_options, 0, sizeof(boinc_options)); boinc_options.main_program = true; boinc_options.check_heartbeat = true; boinc_options.handle_process_control = true; boinc_init_options(&boinc_options); fprintf( stderr, "%s vboxwrapper: starting\n", boinc_msg_prefix(buf, sizeof(buf)) ); retval = parse_job_file(); if (retval) { fprintf( stderr, "%s can't parse job file: %d\n", boinc_msg_prefix(buf, sizeof(buf)), retval ); boinc_finish(retval); } retval = vm.run(); if (retval) { boinc_finish(retval); } while (1) { vm.poll(); boinc_get_status(&boinc_status); if (boinc_status.no_heartbeat || boinc_status.quit_request) { vm.stop(); boinc_temporary_exit(0); } if (boinc_status.abort_request) { vm.cleanup(); boinc_finish(EXIT_ABORTED_BY_CLIENT); } if (!vm.is_running()) { vm.cleanup(); boinc_finish(0); } if (boinc_status.suspended) { if (!vm.suspended) { vm.pause(); } } else { if (vm.suspended) { vm.resume(); } } boinc_sleep(POLL_PERIOD); } return 0; }