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

个人的小说网站如何做微信公众号优惠和网站绑定怎么做

个人的小说网站如何做,微信公众号优惠和网站绑定怎么做,wordpress流量赚钱,怎样做的英文网站在上一篇文章#xff1a;第一个Cuda程序#xff0c;矩阵相乘代码#xff0c;我们设计了一种并行的矩阵乘法程序#xff0c;效果和使用CPU计算的一样#xff0c;但时间有了很大的降低#xff0c;然而#xff0c;这只是最基本的一种方法#xff0c;事实上我们完全可以让程…在上一篇文章第一个Cuda程序矩阵相乘代码我们设计了一种并行的矩阵乘法程序效果和使用CPU计算的一样但时间有了很大的降低然而这只是最基本的一种方法事实上我们完全可以让程序变得更快 仔细看看会发现我们使用的是global memory而share memory的访问速度要远远大于global memory所以我们将使用share memory优化矩阵乘法让程序更快 #include stdio.h#includestdlib.h#include cuda.h#include cuda_runtime.h#include device_launch_parameters.h#include device_functions.h # define BLOCK_SIZE 8# define M 6# define N 8# define K 6__managed__ float a[M * N];__managed__ float b[N*K];__managed__ float c_gpu[M * K];__managed__ float c_cpu[M * K];__global__ void gpu_matrix(float* a, float* b, float* c, const int m, const int n, const int k){ __shared__ float sub_a[BLOCK_SIZE][BLOCK_SIZE]; __shared__ float sub_b[BLOCK_SIZE][BLOCK_SIZE]; int x threadIdx.x blockIdx.x * blockDim.x; int y threadIdx.y blockIdx.y * blockDim.y; float temp 0.0; int step, i; for (step 0; step N / BLOCK_SIZE; step) { if ((step * BLOCK_SIZE threadIdx.x) N || y M) { sub_a[threadIdx.y][threadIdx.x] 0.0; } else { sub_a[threadIdx.y][threadIdx.x] a[y * N (step * BLOCK_SIZE threadIdx.x)]; }if ((step * BLOCK_SIZE threadIdx.y) N || x K) { sub_b[threadIdx.y][threadIdx.x] 0.0;} else { sub_b[threadIdx.y][threadIdx.x] b[(step * BLOCK_SIZE threadIdx.y) * K x]; } __syncthreads(); for (i 0; i BLOCK_SIZE; i) { temp temp sub_a[threadIdx.y][i] * sub_b[i][threadIdx.x]; } __syncthreads();if (x K y M) { c[y * K x] temp; } }} void cpu_matrix(float* a, float* b, float* c, const int m, const int n, const int k){ int y, x, step; float temp; for (y 0; y M; y) { for (x 0; x K; x) { temp 0; for (step 0; step N; step) { temp a[y * N step] * b[step * K x]; } c[y * K x] temp; } }} int main(){ int x,y; float item1; //初始化矩阵 for (y 0; y M; y) { for (x 0; x N; x) { item1 x y; a[y * N x] item1;}} for (y 0; y N; y) { for (x 0; x K; x) { item1 x y; b[y * K x] item1;} } printf(-----------------两个矩阵-#--------------\n); for (y 0; y M; y) {for (x 0; x N; x) { printf(%f , a[y * N x]); } printf(\n); } for (y 0; y N; y) { for (x 0; x K; x) { printf(%f , b[y * K x]); } printf(\n); } unsigned int grid_rows (M BLOCK_SIZE - 1) / BLOCK_SIZE; unsigned int grid_cols (K BLOCK_SIZE - 1) / BLOCK_SIZE;dim3 dimGrid(grid_rows, grid_cols); dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE);gpu_matrix dimGrid, dimBlock (a, b, c_gpu, M, N, K);cudaDeviceSynchronize();cpu_matrix(a, b, c_cpu, M, N, K); // //打印cpu计算结果 printf(---------------cpu计算结果---------#------------------\n);for (y 0; y M; y) { for (x 0; x K; x) { printf(%f , c_cpu[y * K x]); } printf(\n);}printf(------------------gpu计算结果------#------------------\n); //打印GPU计算结果 for (y 0; y M; y) { for (x 0; x K; x) { printf(%f , c_gpu[y * K x]); } printf(\n); } return 0;} -----------------两个矩阵-#--------------0.000000 1.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.0000001.000000 2.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.0000002.000000 3.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.0000003.000000 4.000000 5.000000 6.000000 7.000000 8.000000 9.000000 10.0000004.000000 5.000000 6.000000 7.000000 8.000000 9.000000 10.000000 11.0000005.000000 6.000000 7.000000 8.000000 9.000000 10.000000 11.000000 12.0000000.000000 1.000000 2.000000 3.000000 4.000000 5.0000001.000000 2.000000 3.000000 4.000000 5.000000 6.0000002.000000 3.000000 4.000000 5.000000 6.000000 7.0000003.000000 4.000000 5.000000 6.000000 7.000000 8.0000004.000000 5.000000 6.000000 7.000000 8.000000 9.0000005.000000 6.000000 7.000000 8.000000 9.000000 10.0000006.000000 7.000000 8.000000 9.000000 10.000000 11.0000007.000000 8.000000 9.000000 10.000000 11.000000 12.000000---------------cpu计算结果---------#------------------140.000000 168.000000 196.000000 224.000000 252.000000 280.000000168.000000 204.000000 240.000000 276.000000 312.000000 348.000000196.000000 240.000000 284.000000 328.000000 372.000000 416.000000224.000000 276.000000 328.000000 380.000000 432.000000 484.000000252.000000 312.000000 372.000000 432.000000 492.000000 552.000000280.000000 348.000000 416.000000 484.000000 552.000000 620.000000------------------gpu计算结果------#------------------140.000000 168.000000 196.000000 224.000000 252.000000 280.000000168.000000 204.000000 240.000000 276.000000 312.000000 348.000000196.000000 240.000000 284.000000 328.000000 372.000000 416.000000224.000000 276.000000 328.000000 380.000000 432.000000 484.000000252.000000 312.000000 372.000000 432.000000 492.000000 552.000000280.000000 348.000000 416.000000 484.000000 552.000000 620.000000 到了这里我们能够使得矩阵乘法变得相当快与仅使用CPU计算相比这在实际应用中非常重要尤其是数据计算量非常大的情况。 也许到了这里这两个程序你并没有完全了解但不要担心先把这些代码运行一下体会使用GPU计算的魅力为以后的学习打下基础。
http://www.pierceye.com/news/905545/

相关文章:

  • 北京婚纱摄影网站珠海网站建设怎样
  • 用什么软件来做网站域名网安备案
  • 能打开各种网站的浏览器推荐制作小网站
  • 山东公司网站开发好看的个人博客主页
  • 长沙优化网站获客软件最新网页游戏排行榜2021
  • 学校网站 建设网络系统管理与维护电大考试题
  • 中文域名转码网站琼筑网站是哪家做的
  • iis 网站访问权限毕设做网站的过程
  • 俱乐部网站模板有什么外贸网站
  • 补习吧 一家专门做家教的网站wordpress繁体字插件
  • 北京西站附近景点网络运营工作内容
  • 网站开发文档模板flask网站开发源码
  • 东莞清洁服务网站建设wordpress收费主题
  • 微网站如何做门户网站建设成都
  • 厦门网络推广建网站前端做图表的网站
  • 河南郑州网站设计公司手机自助建网站
  • 做网站的公司主要做shm有域名了网站怎么做
  • 竭诚网络网站建设价格贺兰网站建设
  • 部门网站管理建设工作汇报wordpress一键生成app
  • 帝国视频网站模板做网站的环境配置
  • 龙采科技做网站多少钱域名如何申请
  • 中国银行全球门户网站wordpress 分类下排序
  • 网站费用怎么做帐张北网站建设
  • 郑州专业网站制作泉州网络推广专员
  • 此网站可能有优化大师班级
  • 用html表格做的网站钦州建站哪家好
  • 做任务可以给钱的网站ps怎么做电商网站
  • 建设单位网站的重要性设计官网需要留言吗
  • 网站推广关键词排名优化做网站虚拟主机和云服务器吗
  • seo如何推广网站深圳网站的做网站公司