当前位置: 首页 > news >正文

大理如何做百度的网站百度点击软件名风

大理如何做百度的网站,百度点击软件名风,流媒体网站开发教程,帝国网站教程程序通过流来管理并发,每个流按顺序执行操作,不同流之间可能并行也可能乱序执行。流的作用是使一个流的计算与另一个流的传输同时进行,能有效提高对GPU的利用率。 流的定义方法,是创建一个cudaStream_t对象,并在启动内…

程序通过流来管理并发,每个流按顺序执行操作,不同流之间可能并行也可能乱序执行。流的作用是使一个流的计算与另一个流的传输同时进行,能有效提高对GPU的利用率。
流的定义方法,是创建一个cudaStream_t对象,并在启动内核和进行memcpy时将该对象作为参数传入。
在运用流时必然会用到异步执行,异步执行就是CPU主机端的API函数和内核函数启动的结束和GPU端真正完成这些操作是异步的。通过函数的异步,CPU可以在GPU端进行运算或数据传输时进行其他操作,更加有效地利用系统中的计算资源。
在用流进行处理时,流处理的对象必须为pinned memory才能实现并行;
流处理有几个API函数:
cudaStreamCreate,创建流;
cudaStreamDestory,释放流;
cudaStreamQuery,查询流完成的状态,所有都完成返回cudaSuccess;否则返回cudaErrorNotReady;
cudaStreamSynchronize,等待所有流任务的完成;
流在CUDASDK中有一个简单的例子samplestream:

#include<stdlib.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include<string.h>__global__ void init_array(int *g_data, int *factor, int num_iterations)
{int idx = blockIdx.x*blockDim.x + threadIdx.x;for (int i = 0; i < num_iterations; i++)g_data[idx] += *factor;
}int correct_data(int *a, const int n, const int c)
{for (int i = 0; i < n; i++){if (a[i] != c){printf("%d:%d %d\n", i, a[i], c);return 0;}}
}int main(int argc, char *argv[])
{int CUDA_device = 0;int nstream = 4;int nreps = 10;int n = 6 * 1024 * 1024;int nbytes = n*sizeof(int);dim3 threads, blocks;float elapsed_time, time_memcpy, time_kernel;int niterations;int num_devices = 0;cudaGetDeviceCount(&num_devices);cudaSetDevice(CUDA_device);cudaDeviceProp device_properties;cudaGetDeviceProperties(&device_properties, CUDA_device);niterations = 5;printf("running on: %s\n\n", device_properties.name);int c = 5;int *a = 0;cudaMallocHost((void**)&a, nbytes);int *d_a = 0, *d_c = 0;cudaMalloc((void**)&d_a, nbytes);cudaMalloc((void**)&d_c, sizeof(int));cudaMemcpy(d_c, &c, sizeof(int), cudaMemcpyHostToDevice);cudaStream_t *streams = (cudaStream_t *)malloc(nstream* sizeof(cudaStream_t));for (int i = 0; i < nstream; i++){cudaStreamCreate(&(streams[i]));}cudaEvent_t start_event, stop_event;cudaEventCreate(&start_event);cudaEventCreate(&stop_event);cudaEventRecord(start_event, 0);cudaMemcpyAsync(a, d_a, nbytes, cudaMemcpyDeviceToHost, streams[0]);cudaEventRecord(stop_event, 0);cudaEventSynchronize(stop_event);cudaEventElapsedTime(&time_memcpy, start_event, stop_event);printf("memcpy:\t%.2f\n", time_memcpy);threads = dim3(512, 1);blocks = dim3(n / threads.x, 1);cudaEventRecord(start_event, 0);init_array << <blocks, threads, 0, streams[0] >> >(d_a, d_c, niterations);cudaEventRecord(stop_event, 0);cudaEventSynchronize(stop_event);cudaEventElapsedTime(&time_kernel, start_event, stop_event);printf("kernel:\t\t%.2f\n", time_kernel);threads = dim3(512, 1);blocks = dim3(n / threads.x, 1);cudaEventRecord(start_event, 0);for (int i = 0; i < nreps; i++){init_array << <blocks, threads >> >(d_a, d_c, niterations);cudaMemcpy(a, d_a, nbytes, cudaMemcpyDeviceToHost);}cudaEventRecord(stop_event, 0);cudaEventSynchronize(stop_event);cudaEventElapsedTime(&elapsed_time, start_event, stop_event);printf("non-stream:\t%.2f(%.2f expected)\n", elapsed_time / nreps, time_kernel + time_memcpy);threads = dim3(512, 1);blocks = dim3(n / (nstream*threads.x), 1);memset(a, 255, nbytes);cudaMemset(d_a, 0, nbytes);cudaEventRecord(start_event, 0);for (int k = 0; k < nreps; k++){for (int i = 0; i < nstream; i++)init_array << <blocks, threads, 0, streams[i] >> >(d_a + i*n / nstream, d_c, niterations);//printf("1");for (int i = 0; i < nstream; i++)cudaMemcpyAsync(a + i*n / nstream, d_a + i*n / nstream, nbytes / nstream, cudaMemcpyDeviceToHost, streams[i]);}cudaEventRecord(stop_event, 0);cudaEventSynchronize(stop_event);cudaEventElapsedTime(&elapsed_time, start_event, stop_event);printf("%d streams:\t%.2f\n", nstream, elapsed_time / nreps);printf("--------------------------------\n");if (correct_data(a, n, c*nreps*niterations))printf("TEST PASSED\n");elseprintf("TEST FAILED\n");for (int i = 0; i < nstream; i++){cudaStreamDestroy(streams[i]);}cudaEventDestroy(start_event);cudaEventDestroy(stop_event);cudaFreeHost(a);cudaFree(d_a);cudaFree(d_c);getchar();cudaThreadExit();}

执行结果如下图所示:
这里写图片描述

第一个时间memcopy表示单次拷贝所需的时间;
第二个表示kernel函数进行计算所用的时间;
第三个non-streamed表示在不使用流的情况下计算与传输的时间;
第四个表示在使用n个流的情况下计算与传输所用的时间;
能看到用减少时间的效果。

http://www.lbrq.cn/news/2542555.html

相关文章:

  • 微信网站建设协议seo公司厦门
  • 询价网站哪个好电子商务专业就业方向
  • 青海省公路工程建设信息网站网站搭建模板
  • 网站建设之织梦后台熊掌号主页新网站seo外包
  • 河南旅游网站建设企业网站的类型
  • fomo3d 网站怎么做深圳网络推广营销公司
  • 绍兴的网站建设公司品牌推广的目的和意义
  • 华为认证培训机构排行榜seo联盟
  • 苏州城乡和住房建设局网站首页百度云网盘网页版
  • 黄冈网站免费投放平台免费下载合肥做网站推广
  • 网站正在建设中......小程序seo推广技巧
  • 重点专业建设网站 建设方案长沙网站制作推广
  • 做网站学哪方面知识如何建立网站
  • 什么是网络社交郑州seo多少钱
  • 在线做图表的网站百度seo费用
  • 东昌网站建设网店代运营靠谱吗
  • 模特公司网站源码百度网址大全网站大全
  • 免费印章在线制作免费seo网站优化工具
  • 品牌官方网站建设快速排名优化系统
  • 网站建设-易速通科技一站式海外推广平台
  • 怎么做企业功能网站友情链接图片
  • 必应收录提交入口邯郸seo优化
  • 房地产新闻最近怎么进行网站关键词优化
  • 网站制作哪家公司好写软文平台
  • 网站开发预算编制常见的搜索引擎
  • 靓号注册网站免费seo推广优化公司哪家好
  • 做网站还是微信小程序百度24小时人工电话
  • 北京网站设计公司哪家公司好互联网
  • wordpress+3.2.1漏洞seo优化技巧有哪些
  • 学校门户网站功能外贸平台排名
  • SQL语言学习(group by,having)
  • 网络安全基础知识【6】
  • wxPython 实践(六)对话框
  • 【机器学习】非线性分类算法详解(下):决策树(最佳分裂特征选择的艺术)与支持向量机(最大间隔和核技巧)
  • Java高性能编程实践指南
  • 社群团购市场选择与开源技术赋能下的下沉市场开拓策略研究——以开源AI智能名片、链动2+1模式与S2B2C商城小程序为例