将oclMat发送到函数会在运行时产生巨大差异(sending oclMat to function creates huge difference in runtime)
我用3个输入写了一个函数(masking):
- inputOCL - 一个oclMat
- comparisonValue - 双精度值
- method - 确定比较方法的int变量
对于我的例子,我选择了method = 1,它代表CMP_GT,测试inputOCL> comparisonValue是否元素。
该函数的目的是将inputOCL中不符合给定copma的所有元素清零。
这是功能屏蔽:
void masking(cv::ocl::oclMat inputOCL, double comparisonValue, int method){ // NOTE: method can be set to 1-->5 corresponding to (==, >, >=, <, <=, !=) cv::ocl::oclMat valueOCL(inputOCL.size(), inputOCL.type()); valueOCL.setTo(cv::Scalar(comparisonValue)); cv::ocl::oclMat logicalOCL; cv::ocl::compare(inputOCL, valueOCL, logicalOCL, method); logicalOCL.convertTo(logicalOCL, inputOCL.type()); cv::ocl::multiply(logicalOCL, inputOCL, inputOCL); cv::ocl::multiply(1 / 255.0, inputOCL, inputOCL); }
在对函数进行计时时,我发现运行函数或运行以下代码时直接运行计算时运行时间差异很大:
int main(int argc, char** argv){ double value1 = 1.23456789012345; double value2 = 1.23456789012344; // initialize matrix cv::Mat I(5000, 5000, CV_64F, cv::Scalar(value1)); // copy input to GPU cv::ocl::oclMat inputOCL(I); int method = 1; static double start_TIMER; // computation done in function start_TIMER = cv::getTickCount(); masking(inputOCL, value2, method); std::cout << "\nFunction runtime = " << ((double)(cv::getTickCount() - start_TIMER)) / cv::getTickFrequency() << " Seconds\n"; // direct computation start_TIMER = cv::getTickCount(); cv::ocl::oclMat valueOCL(inputOCL.size(), inputOCL.type()); valueOCL.setTo(cv::Scalar(value2)); cv::ocl::oclMat logicalOCL; cv::ocl::compare(inputOCL, valueOCL, logicalOCL, method); logicalOCL.convertTo(logicalOCL, inputOCL.type()); cv::ocl::multiply(logicalOCL, inputOCL, inputOCL); cv::ocl::multiply(1 / 255.0, inputOCL, inputOCL); std::cout << "\nDirect runtime = " << ((double)(cv::getTickCount() - start_TIMER)) / cv::getTickFrequency() << " Seconds\n"; }
运行时可以在此屏幕截图中看到:
为什么运行时有这么大的差异?
I wrote a function (masking) with 3 inputs:
- inputOCL - an oclMat
- comparisonValue - a double value
- method - an int variable determining the comparison method
For my example I chose method=1, which stands for CMP_GT, testing if inputOCL>comparisonValue element-wise.
The purpose of the function is to zero out all the elements in inputOCL that don't comply with the given copmarison.
Here is the function masking:
void masking(cv::ocl::oclMat inputOCL, double comparisonValue, int method){ // NOTE: method can be set to 1-->5 corresponding to (==, >, >=, <, <=, !=) cv::ocl::oclMat valueOCL(inputOCL.size(), inputOCL.type()); valueOCL.setTo(cv::Scalar(comparisonValue)); cv::ocl::oclMat logicalOCL; cv::ocl::compare(inputOCL, valueOCL, logicalOCL, method); logicalOCL.convertTo(logicalOCL, inputOCL.type()); cv::ocl::multiply(logicalOCL, inputOCL, inputOCL); cv::ocl::multiply(1 / 255.0, inputOCL, inputOCL); }
When timing the function I find a very large difference in runtime between running the function or running the computation directly when running the following code:
int main(int argc, char** argv){ double value1 = 1.23456789012345; double value2 = 1.23456789012344; // initialize matrix cv::Mat I(5000, 5000, CV_64F, cv::Scalar(value1)); // copy input to GPU cv::ocl::oclMat inputOCL(I); int method = 1; static double start_TIMER; // computation done in function start_TIMER = cv::getTickCount(); masking(inputOCL, value2, method); std::cout << "\nFunction runtime = " << ((double)(cv::getTickCount() - start_TIMER)) / cv::getTickFrequency() << " Seconds\n"; // direct computation start_TIMER = cv::getTickCount(); cv::ocl::oclMat valueOCL(inputOCL.size(), inputOCL.type()); valueOCL.setTo(cv::Scalar(value2)); cv::ocl::oclMat logicalOCL; cv::ocl::compare(inputOCL, valueOCL, logicalOCL, method); logicalOCL.convertTo(logicalOCL, inputOCL.type()); cv::ocl::multiply(logicalOCL, inputOCL, inputOCL); cv::ocl::multiply(1 / 255.0, inputOCL, inputOCL); std::cout << "\nDirect runtime = " << ((double)(cv::getTickCount() - start_TIMER)) / cv::getTickFrequency() << " Seconds\n"; }
The runtimes can be seen in this screenshot:
Why is there such a large difference in runtimes?
原文:https://stackoverflow.com/questions/30319096
最满意答案
最简单的例子是SDK中的ArrayBuffer示例(examples / api / var_array_buffer)。
ArrayBuffer的内存由pp :: VarArrayBuffer拥有,因此只要你有一个引用(并且你没有调用pp :: VarArrayBuffer :: Unmap ),你就不必复制记忆。
pp :: Var变量会自动引用计数,因此您无需显式调用AddRef 。
The simplest example of this is the ArrayBuffer example in the SDK (examples/api/var_array_buffer).
The memory for the ArrayBuffer is owned by the pp::VarArrayBuffer, so as long as you have a reference to that (and you haven't called pp::VarArrayBuffer::Unmap) you don't have to make a copy of the memory.
pp::Var variables are automatically reference counted, so you don't need to explicitly call AddRef.
相关问答
更多-
我认为最简单的方法是在服务器端创建一个包含JS模型相同属性的MyInfoModel ,并将其传递给服务器方法。 通常,SignalR和ASP.NET应该处理数据的序列化,让您发送和接收复杂的对象。 (请注意,我没有测试过,这只是一个有根据的猜测)。 由于您可以轻松地将复杂对象从服务器发送到客户端,因此我认为您无法将其从客户端发送到服务器。 如果第一种方法(在服务器上创建模型并使服务器方法接受模型)不起作用,则可以序列化对象,将其作为字符串发送并在集线器上反序列化(您仍需要模型来反序列化)。 如果这些都不起作 ...
-
您在客户端中设置属性,但服务器上明显抛出异常。 你是如何启动服务器的? 您似乎正在使用Grizzly独立 - 如果您这样做,您可以尝试使用TyrusWebSocketEngine#INCOMING_BUFFER_SIZE属性设置为17_000_000或您想要的任何值来启动服务器。 (这可以通过使用Server(Map,Class ...)或其他构造函数创建服务器来完成。有关更多详细信息,请参阅Server类javadoc 。 You are setting the property in the clien ...
-
如何从Native客户端和javascript中发送数组缓冲区(how to send array buffer from and to in Native client and javascript)[2023-01-16]
最简单的例子是SDK中的ArrayBuffer示例(examples / api / var_array_buffer)。 ArrayBuffer的内存由pp :: VarArrayBuffer拥有,因此只要你有一个引用(并且你没有调用pp :: VarArrayBuffer :: Unmap ),你就不必复制记忆。 pp :: Var变量会自动引用计数,因此您无需显式调用AddRef 。 The simplest example of this is the ArrayBuffer example in ... -
几个问题: 在您的服务器中,您执行此操作: new_sock = malloc(1); 你只分配1个字节来保存一个int这个空间不够。 由于newsock指向一个int ,你应该为一个分配足够的空间: new_sock = malloc(sizeof(int)); 同样在服务器中,您在从客户端读取消息后执行此操作: fd = open (PROCESSLIST, O_RDONLY); puts("file open has taken place"); read(fd, buff ...
-
你可以像这样创建一个类型化的数组: [obj1.in1,obj1.in2,obj1.out,obj2.in1,...] 有一个对象: var arr=Int8Array.from(myObject.in.concat(myObject.out)); 使用对象数组: var ObjArr=[obj1,obj2]; var arr=new Int8Array(ObjArr.length*3); for(var i=0;i
Javascript异步缓冲区副本(Javascript Async buffer copy)[2023-05-14]
有什么方法可以异步复制缓冲区吗? 不,在其他代码运行时无法复制缓冲区,否则可能存在访问/写入缓冲区元素的竞争条件。 但是,如果复制花费了异常的时间并且分块没有帮助,那么你可以做的是将缓冲区传输给后台工作者,在那里复制它,然后将两者都传回主线程。 这当然意味着缓冲区在复制时不能使用。 Is there any way I could copy a buffer asynchronously? No, a buffer cannot be copied while other code is running a ...我当时想做类似的动作,但没有找到任何答案。 经过一些试验和错误,我似乎已经弄明白了。 在您的请求选项中添加选项encoding: null ,这将从原始源获取base64格式的图像。 request({ url: yoururl, method: 'GET', encoding: null }, function (error, response, body) { if (!error && response.statusCode === 200) { res ...即使缓冲区尚未填充,您也调用bytesRead < count (如果bytesRead < count )。 考虑切换到await应用程序的异步部分。 这摆脱了可怕的回调递归。 You're calling OnMessageReceived even if the buffer has not been filled (in case bytesRead < count). Consider switching to await for the async part of the application ...TCP是流协议(如使用SOCK_STREAM )。 这意味着没有数据包的开始或结束,它只是一个字节流。 这也意味着单个接收呼叫的读取次数可能会少于使用单个发送呼叫发送的次数,或者是以多次(包括尾随部分)发送呼叫发送的次数。 为了处理它,你需要提出一个更高级的协议来放在TCP之上。 它需要包含发送数据的长度(采用固定长度格式),或者您需要有其他方式来知道消息的开始或至少是结束。 TCP is a streaming protocol (as indicated by the use of SOCK_STREA ...Firebase Cloud Messaging for Web(简称FCM.js)取决于浏览器用于传输消息的Web Push实现。 React Native应用程序非常不是基于浏览器的应用程序。 所以你不能使用FCM.js在你的React Native应用程序中接收消息(除非有人不顾一切地在应用程序中嵌入兼容的浏览器)。 Firebase Cloud Messaging for the Web (FCM.js for short) depends on the browser's implementati ...相关文章
更多- 如何在runtime重载javascript alert函数
- 两种js function 声明方式
- function-Oceanus配置说明
- storm工程在本地运行可以通过,发送到集群中就报错
- error C2668: 'M' : ambiguous call to overloaded function
- 运行时编译执行一段代码
- Professional Android 4 Application Development
- C程序访问Hadoop运行时遇到的各种问题以及解决方案
- Hadoop运行时错误:Task process exit with nonzero status of 1
- [翻译]性别差异:对女性的误解(Differences between the sexes:The mismeasure of woman)
最新问答
更多- 带有简单redis应用程序的Node.js抛出“未处理的错误”(Node.js with simple redis application throwing 'unhandled error')
- 高考完可以去做些什么?注意什么?
- Allauth不会保存其他字段(Allauth will not save additional fields)
- Flask中的自定义中止映射/异常(Custom abort mapping/exceptions in Flask)
- sed没有按预期工作,从字符串中间删除特殊字符(sed not working as expected, removing special character from middle of string)
- 怎么在《我的世界》游戏里面编程
- .NET可移植可执行文件VS .NET程序集(.NET Portable Executable File VS .NET Assembly)
- 搜索字符串从视图中键入两个字段的“名字”和“姓氏”组合(Search Strings Typed from View for Two Fields 'First Name' and 'Last Name' Combined)
- 我可以通过配置切换.Net缓存提供程序(Can I switch out .Net cache provider through configuration)
- 在鼠标悬停或调整浏览器大小之前,内容不会加载(Content Does Not Load Until Mouse Hover or Resizing Browser)
- 未捕获的TypeError:auth.get不是函数(Uncaught TypeError: auth.get is not a function)
- 如何使用变量值创建参数类(How to create a parameter class with variant value)
- 在std :: deque上并行化std :: replace(Parallelizing std::replace on std::deque)
- 单元测试返回Connection对象的方法(Unit Test for a method that returns a Connection object)
- rails:上传图片时ios中的服务器内部错误(rails: server internal error in ios while uploading image)
- 如何在Android中构建应用程序警报[关闭](How build an application Alarm in Android [closed])
- 以编程方式连接到Windows Mobile上的蓝牙耳机(Programmatically connect to bluetooth headsets on Windows Mobile)
- 在两个不同的SharedPreference中编写并获得相同的结果(Writing in two different SharedPreference and getting the same result)
- CSS修复容器和溢出元素(CSS Fix container and overflow elements)
- 在'x','y','z'迭代上追加数组(Append array on 'x', 'y', 'z' iteration)
- 我在哪里可以看到使用c ++源代码的UML方案示例[关闭](Where I can see examples of UML schemes with c++ source [closed])
- SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
- 位字段并集的大小,其成员数多于其大小(Size of bit-field union which has more members than its size)
- 我安装了熊猫,但它不起作用(I installed pandas but it is not working)
- Composer - 更改它在env中使用的PHP版本(Composer - Changing the version of PHP it uses in the env)
- 使用JavaFX和Event获取鼠标位置(Getting a mouse position with JavaFX and Event)
- 函数调用可以重新排序(Can function calls be reordered)
- 关于“一对多”关系的NoSQL数据建模(NoSQL Data Modeling about “one to many” relationships)
- 如何解释SBT错误消息(How to interpret SBT error messages)
- 调试模式下的Sqlite编译器错误“初始化程序不是常量”(Sqlite compiler errors in Debug mode “initializer is not a constant”)