int opp_factory_destroy_and_remove_profile(struct opp_factory*src) { RETURN_IF_PROFILER_OFF(0); if(check_stop(1,0)) return 0; opp_factory_profiler_visit(opp_factory_profiler_visit_to_prune, src); if(check_stop(0,1)) return 0; return 0; }
void opp_factory_profiler_get_total_memory(int*grasped,int*really_allocated) { *grasped = 0; *really_allocated = 0; RETURN_IF_PROFILER_OFF(); int linked_memory = 0; if(check_stop(1,0)) return; opp_factory_profiler_visit(opp_factory_profiler_visit_to_get_total_memory, &linked_memory); if(check_stop(0,1)) return; *grasped = linked_memory; *really_allocated = prof.total_allocated; }
bool play(const char *filename, VFSFile &file) { force_apply = true; try { MPTWrap mpt(file); open_audio(FMT_FLOAT, 44100, 2); while(!check_stop()) { unsigned char buffer[65536]; std::int64_t n; int seek_value = check_seek(); if(seek_value >= 0) mpt.seek(seek_value); if(force_apply) { mpt.set_interpolator(aud_get_int(PACKAGE, SETTING_INTERPOLATOR)); mpt.set_stereo_separation(aud_get_int(PACKAGE, SETTING_STEREO_SEPARATION)); force_apply = false; } n = mpt.read(buffer, sizeof buffer); if(n == 0) break; write_audio(buffer, n); } return true; } catch(MPTWrap::InvalidFile) { return false; } }
/* -----------------------------------------------------------------------------------*/ void Process3(void){ struct stop_error_type c_s; APEX_BYTE data[MAX_LENGTH]; char sal_code[MAX_CAD]; PROCESS_ID_TYPE procMainId2; RETURN_CODE_TYPE retCode; BLACKBOARD_ID_TYPE bbId; printf("Process 3 starts ... \n"); strcpy(data, "OK"); /* To get the procMainId2 value */ GET_PROCESS_ID("tProc2", &procMainId2, &retCode); CHECK_CODE(": GET_PROCESS_ID Process 2", retCode, sal_code); printf("%s\n", sal_code); /* To check stop process 2 */ c_s = check_stop(procMainId2, NO_ERROR); GET_BLACKBOARD_ID(BLACKBOARD_NAME_0, &bbId, &retCode); CHECK_CODE(": GET_BLACKBOARD_ID_0 by Process3", retCode, sal_code); printf("%s\n", sal_code); DISPLAY_BLACKBOARD (bbId, data, 3, &retCode); CHECK_CODE(": DISPLAY_BLACKBOARD B1 in Process 3", retCode, sal_code); printf("%s\n", sal_code); START(procMainId2, &retCode); CHECK_CODE(": START Process 2", retCode, sal_code); printf("%s\n", sal_code); show_results(c_s); STOP_SELF (); }
std::tuple<arma::fmat, arma::fmat, arma::fmat> Worker::factorize(float lambda, bool clamp, bool reg, int reg_thr, int stop_tol) { feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW); petuum::RowAccessor rowacc; // Initialize tables with random values //arma::arma_rng::set_seed_random(); gaml::util::table::randomizeTable(usertable, rank, Ruser.n_rows, useroffset); gaml::util::table::randomizeTable(prodtable, rank, Rprod.n_cols, prodoffset); gaml::util::table::randomizeTable(wordtable, rank, Rword.n_words, wordoffset); float last_se_train=0; float last_se_vali=0; setable.Inc(1, id*2, Rvali.n_nz); setable.Inc(1, id*2+1, Rtest.n_nz); petuum::PSTableGroup::GlobalBarrier(); // Fetch U, P and T auto U = gaml::util::table::loadMatrix(usertable, Rword.n_rows, rank); auto P = gaml::util::table::loadMatrix(prodtable, Rword.n_cols, rank); auto T = gaml::util::table::loadMatrix(wordtable, Ruser.n_words, rank); auto sum_sizes = read_split_sum(1); auto vali_size = std::get<0>(sum_sizes); auto test_size = std::get<1>(sum_sizes); for (int round = 0; round < iterations; round++) { /////// // Compute gradient for U /////// arma::fmat Ugrad(Ruser.n_rows, rank, arma::fill::zeros); arma::fmat Unum(Ruser.n_rows, rank, arma::fill::zeros); arma::fmat Udenom(Ruser.n_rows, rank, arma::fill::zeros); // iterate over all up pairs in Ruser for (std::size_t i = 0; i != Ruser.n_nz; ++i) { int userind = Ruser.rows[i]; int prodind = Ruser.cols[i]; auto wordbag = Ruser.getWordBagAt(i); Unum.row(userind - useroffset) += P.row(prodind) % (wordbag * T); Udenom.row(userind - useroffset) += P.row(prodind) % ((U.row(userind) % P.row(prodind) * T.t()) * T); } arma::fmat Ulocal = U.rows(useroffset, useroffset + Ruser.n_rows - 1); // prevent div by zero Udenom += 10E-16f; Ugrad = (Ulocal % Unum / Udenom) - Ulocal; if(reg && round > reg_thr) { Ugrad = Ugrad - lambda * Ulocal % Ulocal / Udenom; } // Update U table gaml::util::table::updateMatrixSlice(Ugrad, usertable, Ugrad.n_rows, Ugrad.n_cols, useroffset); petuum::PSTableGroup::GlobalBarrier(); // Fetch updated U U = gaml::util::table::loadMatrix(usertable, U.n_rows, U.n_cols); if(clamp){ U = arma::clamp(U, 0.0, std::numeric_limits<float>::max()); } /////// // Compute gradient for P /////// arma::fmat Pgrad(Rprod.n_cols, rank, arma::fill::zeros); arma::fmat Pnum(Rprod.n_cols, rank, arma::fill::zeros); arma::fmat Pdenom(Rprod.n_cols, rank, arma::fill::zeros); // iterate over all up pairs in Rprod for (std::size_t i = 0; i != Rprod.n_nz; ++i) { int userind = Rprod.rows[i]; int prodind = Rprod.cols[i]; auto wordbag = Rprod.getWordBagAt(i); Pnum.row(prodind - prodoffset) += U.row(userind) % (wordbag * T); Pdenom.row(prodind - prodoffset) += U.row(userind) % ((U.row(userind) % P.row(prodind) * T.t()) * T); } arma::fmat Plocal = P.rows(prodoffset, prodoffset + Rprod.n_cols - 1); Pdenom += 10E-16f; Pgrad = (Plocal % Pnum / Pdenom) - Plocal; if(reg && round > reg_thr) { Pgrad = Pgrad - lambda * Plocal % Plocal / Pdenom; } // Update P table gaml::util::table::updateMatrixSlice(Pgrad, prodtable, Pgrad.n_rows, Pgrad.n_cols, prodoffset); petuum::PSTableGroup::GlobalBarrier(); // Fetch updated P P = gaml::util::table::loadMatrix(prodtable, P.n_rows, P.n_cols); if(clamp) { P = arma::clamp(P, 0.0, std::numeric_limits<float>::max()); } /////// // Compute gradient for T /////// arma::fmat Tgrad(Rword.n_words, rank, arma::fill::zeros); arma::fmat Tnum(Rword.n_words, rank, arma::fill::zeros); arma::fmat Tdenom(Rword.n_words, rank, arma::fill::zeros); arma::fmat Tlocal = T.rows(wordoffset, Rword.n_words + wordoffset - 1); // iterate over all uv pairs in Rword for (std::size_t i = 0; i != Rword.n_nz; ++i) { int userind = Rword.rows[i]; int prodind = Rword.cols[i]; auto wordbag = Rword.getWordBagAt(i); arma::frowvec user_times_prod = (U.row(userind) % P.row(prodind)); arma::frowvec pred = user_times_prod * Tlocal.t(); Tnum += wordbag.t() * user_times_prod; Tdenom += pred.t() * user_times_prod; } Tdenom += 10E-16f; Tgrad = (Tlocal % Tnum / Tdenom) - Tlocal; if(reg && round > reg_thr) { Tgrad = Tgrad - lambda * Tlocal % Tlocal / Tdenom; } // Update T table gaml::util::table::updateMatrixSlice(Tgrad, wordtable, Tgrad.n_rows, Tgrad.n_cols, wordoffset); petuum::PSTableGroup::GlobalBarrier(); // Fetch updated T T = gaml::util::table::loadMatrix(wordtable, T.n_rows, T.n_cols); if(clamp) { T = arma::clamp(T, 0.0, std::numeric_limits<float>::max()); } update_setable(U, P, T, round, last_se_train, last_se_vali); petuum::PSTableGroup::GlobalBarrier(); update_mse(round); if(id == 0) { output(round+1, se_train_vec[round % mse_log] / Rword.n_nz, se_vali_vec[round % mse_log] / vali_size); } if(check_stop(round, stop_tol)) { break; } } float se_test = eval(U, P, T, Rtest); setable.Inc(2, id, se_test); petuum::PSTableGroup::GlobalBarrier(); if(id == 0) { std::vector<float> se_test_vec; const auto& row = setable.Get<petuum::DenseRow<float>>(2, &rowacc); row.CopyToVector(&se_test_vec); float mse_test = std::accumulate(se_test_vec.begin(), se_test_vec.end(), 0.0f); std::cout << "MSE test: " << mse_test / test_size << std::endl; } return std::make_tuple(U, P, T); }