osg + cuda
- #include <osg/Notify>
- #include <osgViewer/Viewer>
- #include <osgCompute/Memory>
- #include <osgCompute/Module>
- #include <osgCuda/Memory>
- #include <memory.h>
- #include <iostream>
- #pragma comment(lib, "osgViewerd.lib")
- #pragma comment(lib, "osgComputed.lib")
- #pragma comment(lib, "osgCudad.lib")
- #pragma comment(lib, "osgd.lib")
- extern "C"
- void MyCudaTest(unsigned int numBlocks, unsigned int numThreads, void * bytes1, void * bytes2, void * bytes3);
- class MyModule : public osgCompute::Module
- {
- public:
- MyModule()
- :osgCompute::Module()
- {
- clearLocal();
- }
- META_Object(osgCompute,MyModule)
- virtual bool init()
- {
- _numThreads = ;
- _numBlocks = _buffer1->getDimension()/_numThreads;
- return osgCompute::Module::init();
- }
- virtual void clear()
- {
- clearLocal();
- osgCompute::Module::clear();
- }
- virtual void launch()
- {
- MyCudaTest(_numBlocks, _numThreads, _buffer1->map(), _buffer2->map(), _buffer3->map());
- }
- inline void setBuffer1(osgCompute::Memory * buffer)
- {
- _buffer1 = buffer;
- }
- inline void setBuffer2(osgCompute::Memory * buffer)
- {
- _buffer2 = buffer;
- }
- inline void setBuffer3(osgCompute::Memory * buffer)
- {
- _buffer3 = buffer;
- }
- protected:
- virtual ~MyModule()
- {
- clearLocal();
- }
- virtual void clearLocal()
- {
- _buffer1 = NULL;
- _buffer2 = NULL;
- _buffer3 = NULL;
- }
- protected:
- unsigned int _numThreads;
- unsigned int _numBlocks;
- osg::ref_ptr<osgCompute::Memory> _buffer1;
- osg::ref_ptr<osgCompute::Memory> _buffer2;
- osg::ref_ptr<osgCompute::Memory> _buffer3;
- private:
- MyModule(const MyModule &, const osg::CopyOp &)
- {
- }
- inline MyModule & operator = (const MyModule &)
- {
- return *this;
- }
- };
- int main()
- {
- unsigned int a[] = {, , };
- unsigned int b[] = {, , };
- unsigned int c[] = {, , };
- unsigned int num = sizeof(a)/sizeof(unsigned int);
- osg::ref_ptr<osgCuda::Memory> buffer1 = new osgCuda::Memory;
- buffer1->setElementSize(sizeof(int));
- buffer1->setDimension(, num);
- buffer1->init();
- osg::ref_ptr<osgCuda::Memory> buffer2 = new osgCuda::Memory;
- buffer2->setElementSize(sizeof(int));
- buffer2->setDimension(, num);
- buffer2->init();
- osg::ref_ptr<osgCuda::Memory> buffer3 = new osgCuda::Memory;
- buffer3->setElementSize(sizeof(int));
- buffer3->setDimension(, num);
- buffer3->init();
- osg::ref_ptr<MyModule> module = new MyModule;
- module->setBuffer1(buffer1.get());
- module->setBuffer2(buffer2.get());
- module->setBuffer3(buffer3.get());
- module->init();
- unsigned int * bufferPtr1 = (unsigned int *)(buffer1->map(osgCompute::MAP_HOST_TARGET));
- memcpy(bufferPtr1, a, sizeof(a));
- unsigned int * bufferPtr2 = (unsigned int *)(buffer2->map(osgCompute::MAP_HOST_TARGET));
- memcpy(bufferPtr2, b, sizeof(b));
- unsigned int * bufferPtr3 = (unsigned int *)(buffer3->map(osgCompute::MAP_HOST_TARGET));
- memcpy(bufferPtr3, c, sizeof(c));
- module->launch();
- bufferPtr3 = (unsigned int *)(buffer3->map(osgCompute::MAP_HOST_SOURCE));
- std::cout << "并行计算:(1, 2, 3)于(4, 5, 6)的和:"<< std::endl;
- for (unsigned int i = ; i < buffer3->getDimension(); ++i)
- {
- std::cout << bufferPtr3[i] << std::endl;
- }
- }
- #include <cuda_runtime.h>
- __global__ void addKernel(int * bytes1, int * bytes2, int * bytes3)
- {
- int tid = blockIdx.x;
- bytes3[tid] = bytes2[tid] + bytes1[tid];
- }
- extern "C"
- void MyCudaTest(unsigned int numBlocks, unsigned int numThreads, void * bytes1, void * bytes2, void * bytes3)
- {
- addKernel<<<numBlocks, numThreads>>>((int *)bytes1, (int *)bytes2, (int *)bytes3);
- }
osg + cuda的更多相关文章
- 朱丽叶—Cuda+OSG
#include <cuda_runtime.h> #include <osg/Image> ; typedef struct cuComplex { float r; flo ...
- CUDA[2] Hello,World
Section 0:Hello,World 这次我们亲自尝试一下如何用粗(CU)大(DA)写程序 CUDA最新版本是7.5,然而即使是最新版本也不兼容VS2015 ...推荐使用VS2012 进入VS ...
- CUDA[1] Introductory
Section 0 :Induction of CUDA CUDA是啥?CUDA®: A General-Purpose Parallel Computing Platform and Program ...
- Couldn't open CUDA library cublas64_80.dll etc. tensorflow-gpu on windows
I c:\tf_jenkins\home\workspace\release-win\device\gpu\os\windows\tensorflow\stream_executor\dso_load ...
- OSG计时器与时间戳
static osg::Timer* sendMsgTimer = new osg::Timer; if (sendMsgTimer->time_m()>100)//100ms {// d ...
- ubuntu 16.04 + N驱动安装 +CUDA+Qt5 + opencv
Nvidia driver installation(after download XX.run installation file) 1. ctrl+Alt+F1 //go to virtual ...
- OSG消息机制之消息分析
OSG消息接收在头文件有各种事件的相关参数
- OSG消息机制之事件处理概述
OSG的消息机制包括好多个头文件预定义及多个类. 首先,消息接收相关的类当属osgGA::GUIEventHandler和osgGA::GUIEventAdapter这两个类了.前者处理OSG程序与用 ...
- OSG 3D场景渲染编程概述
OSG是Open Scene Graphic的缩写,是基于C++平台的使用OpenGL技术的开源3D场景开发. vs环境安装或者是在Ubuntu中环境的安装网上教程很多,都是大同小异的,认真操作容易成 ...
随机推荐
- 给Unity3d添加一个漂亮的标题栏
我们在做好一个小Unity3d APP,我们一般都会兴致勃勃的导出一个exe,尝试着玩我们的app.感觉还不错,有板有眼的了.然而事与愿违,我们APP里面的内容挺漂亮的,但是它的标题栏是windows ...
- Unity3d请求webservice
我们在对接第三方sdk时,第三方sdk通常会以一个webservice接口的形式供我们来调用.而这些接口会以提供我们get,post,soap等协议来进行访问.get,post方法相信大家都比较熟悉了 ...
- shrio配置说明
1.引入Shiro的Maven依赖 <!-- Spring 整合Shiro需要的依赖 --> <dependency> <groupId>org.apache.sh ...
- Web网页数据抓取(C/S)
通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在根据得到的数据进行数据分析.为业务提供参考数据. 为了完成以上的需求,我们 ...
- 【IIS】windows2008 ii7 设置访问网站提示帐号密码登录
3个步骤: 1.添加windows身份验证: windows2008默认是不启用的,需要我们自己去启动,在管理工具 - 服务器管理- 角色 ,拉下去,下面有个[添加角色服务],安全性- Windows ...
- apache bench(ab)压力测试模拟POSt请求
ab命令格式: -N|--count 总请求数,缺省 : 5w -C|--clients 并发数, 缺省 : 100 -R|--rounds 测试次数, 缺省 : 10 次 -S|-sleeptime ...
- Tiny6410之控制icache驱动
什么是cache: 基于程序访问的局限性,在主存和CPU通用寄存器之间设置了一类高速的.容量较小的存储器,把正在执行的指令地址附件的一部分指令或数据从主存调入这类存储器,供CPU 在一段时间内使 ...
- ResScope (软件资源分析)V1.94 绿色版
软件名称:ResScope (软件资源分析)V1.94 绿色版软件类别:国产软件运行环境:Windows软件语言:简体中文授权方式:免费版软件大小:1.47 MB软件等级:整理时间:2015-01-0 ...
- moodle笔记之-权限api
<?php//权限定义$capabilities = array( 'mod/mytest:managefiles' => array(//具体的权限:插件类型/插件名/权限 这里是增加一 ...
- 移动HTML 5前端性能优化指南(转载)
前端工程师的菜!最近移动Html 5越来越火,想有一个体验流畅的Html 5 应用,这篇优化指南就别放过咯.腾讯的同学将关键的注意点与优化方法都总结出来,全文高能干货,非常值得深度学习 >> ...