本文整理汇总了C++中Net::set_thread_num方法的典型用法代码示例。如果您正苦于以下问题:C++ Net::set_thread_num方法的具体用法?C++ Net::set_thread_num怎么用?C++ Net::set_thread_num使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net
的用法示例。
在下文中一共展示了Net::set_thread_num方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lock
JNIEXPORT jboolean JNICALL Java_com_baidu_mdl_demo_MDL_validate(JNIEnv *env, jclass thiz) {
std::lock_guard<std::mutex> lock(shared_mutex);
LOGI("jni validate invoked");
bool success = false;
double sum = -1;
double sign = 0;
EXCEPTION_HEADER
Loader *loader = Loader::shared_instance();
if (!loader->get_loaded()) {
throw_exception("loader is not loaded yet");
}
Net *net = get_net_instance(loader->_model);
net->set_thread_num(1);
vector<float> cpp_result = net->forward_from_to(nullptr, 0, 1, true);
int cpp_result_count = cpp_result.size();
if (cpp_result_count > 0) {
sum = 0;
for (int i = 0; i < cpp_result_count; i++) {
sum += cpp_result[i];
}
}
sign = loader->_model["meta"]["first_layer_sign"].number_value();
if (abs(sum - sign) < 0.5) {
success = true;
}
EXCEPTION_FOOTER
LOGI("jni validate returned: %s, calculated sign: %lf, expected sign: %lf", (success ? "true" : "false"), sum, sign);
return success ? JNI_TRUE : JNI_FALSE;
}
示例2:
JNIEXPORT void JNICALL Java_com_baidu_mdl_demo_MDL_setThreadNum(
JNIEnv *env, jclass thiz, jint num) {
EXCEPTION_HEADER
Loader *loader = Loader::shared_instance();
if (!loader->get_loaded()) {
throw_exception("loader is not loaded yet");
}
Net *net = get_net_instance(loader->_model);
net->set_thread_num(num);
if (num > Gemmer::gemmers.size()) {
for (int i = 0; i < num - Gemmer::gemmers.size(); i++) {
Gemmer::gemmers.push_back(new mdl::Gemmer());
}
}
EXCEPTION_FOOTER
}