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

如何建立自己免费网站青岛建站seo公司

如何建立自己免费网站,青岛建站seo公司,小城镇建设 网站官方,qq推广群号码大全目录 1. 解决的问题 2. 分析 3. 方法 4. 代码示例 1. 解决的问题 利用块和线程索引,从全局内存中访问指定的数据。 2. 分析 通常情况下,矩阵是用行优先的方法在全局内存中线性存储的。如下。 8列6行矩阵(nx,ny)(…

目录

1. 解决的问题

2. 分析

3. 方法

4. 代码示例


1. 解决的问题

利用块和线程索引,从全局内存中访问指定的数据。

2. 分析

通常情况下,矩阵是用行优先的方法在全局内存中线性存储的。如下。

8列6行矩阵(nx,ny)=(8,6)。

3. 方法

这里建立二维网格(2,3)+二维块(4,2)为例,使用其块和线程索引映射矩阵索引。

(1)第一步,可以用以下公式把线程和块索引映射到矩阵坐标上;

(2)第二步,可以用以下公式把矩阵坐标映射到全局内存中的索引/存储单元上;

比如要获取矩阵元素(col,row) = (2,4) ,其全局索引是34,映射到矩阵坐标上,

ix = 2 + 0*3=2; iy = 0 + 2*2=4. 然后再映射到全局内存idx = 4*8 + 2 = 34.

4. 代码示例

#include "cuda_runtime.h"
#include "device_launch_parameters.h"  // threadIdx#include <stdio.h>    // io
#include <time.h>     // time_t
#include <stdlib.h>  // rand
#include <memory.h>  //memset#define CHECK(call)                                   \
{                                                     \const cudaError_t error_code = call;              \if (error_code != cudaSuccess)                    \{                                                 \printf("CUDA Error:\n");                      \printf("    File:       %s\n", __FILE__);     \printf("    Line:       %d\n", __LINE__);     \printf("    Error code: %d\n", error_code);   \printf("    Error text: %s\n",                \cudaGetErrorString(error_code));          \exit(1);                                      \}                                                 \
}void initiaInt(int* p, const int N)
{for (int i = 0; i < N; i++){p[i] = i;}
}/// <summary>
/// 
/// </summary>
/// <param name="c">全局内存中线性存储的二维矩阵</param>
/// <param name="nx">列</param>
/// <param name="ny"></param>
void printMatrix(int* c, const int nx, const int ny)
{int* ic = c;printf("\n matrix: [%d, %d] \n", nx, ny);for (int i = 0; i < ny; i++){for (int j = 0; j < nx; j++){int cur_ele = ic[i * nx + j];printf("%d ", cur_ele);}printf("\n");}printf("\n");
}/// <summary>
/// 
/// </summary>
/// <param name="a">全局内存中是线性存储的</param>
/// <param name="nx">col</param>
/// <param name="ny"></param>
/// <returns></returns>
__global__ void printThreadIdx(int* a, const int nx, const int ny)
{// 矩阵行列int ix = threadIdx.x + blockIdx.x * blockDim.x;int iy = threadIdx.y + blockIdx.y * blockDim.y;  // 全局索引unsigned int idx = iy * nx + ix;  // 前面有iy行,每行有nx个数。printf("thread_idx (%d, %d) block_idx (%d, %d) coordinate (%d, %d) global index %d val %d\n",threadIdx.x, threadIdx.y, blockIdx.x, blockIdx.y, ix, iy, idx, a[idx]);
}int main(void)
{// get device infoint device = 0;cudaDeviceProp deviceProp;CHECK(cudaGetDeviceProperties(&deviceProp, device));printf("Using device: %d %s", device, deviceProp.name);  // 卡号0的显卡名称。CHECK(cudaSetDevice(device));  // 设置显卡号// set matrix dimensionint nx = 8, ny =6, nxy = nx * ny;int nBytes = nxy * sizeof(int);// malloc host memoryint* h_a;h_a = (int*)malloc(nBytes);// init datainitiaInt(h_a, nxy);printMatrix(h_a, nx, ny);// malloc device memoryint* d_Mat_a;cudaMalloc((void**)&d_Mat_a, nBytes);// transfer data from host to devicecudaMemcpy(d_Mat_a, h_a, nBytes, cudaMemcpyHostToDevice);// configdim3 block(4, 2);  // 二维线程块(x,y)=(4,2)dim3 grid((nx+block.x-1) / block.x, (ny+block.y-1)/block.y); // 二维网格(2,3)// 直接nx/block.x = 8/4=2. (8+4-1)/4=2.// invoke kernelprintThreadIdx << <grid, block >> > (d_Mat_a, nx, ny);cudaDeviceSynchronize();// free memorycudaFree(d_Mat_a);free(h_a);// reset devicecudaDeviceReset();return 0;
}

可以看到,全局索引值就是矩阵中存储的值。 


文章转载自:
http://wanjiasecurable.stph.cn
http://wanjiazoomorphism.stph.cn
http://wanjiasynergize.stph.cn
http://wanjiawhatsoever.stph.cn
http://wanjiacackle.stph.cn
http://wanjiaacetobacter.stph.cn
http://wanjiamaudlin.stph.cn
http://wanjiaparticularist.stph.cn
http://wanjiaamiability.stph.cn
http://wanjiabarque.stph.cn
http://wanjiaplayshoe.stph.cn
http://wanjiascyros.stph.cn
http://wanjiascram.stph.cn
http://wanjiasoapolallie.stph.cn
http://wanjiarebloom.stph.cn
http://wanjiagrimly.stph.cn
http://wanjiacomplicated.stph.cn
http://wanjiaextrovertish.stph.cn
http://wanjiadreariness.stph.cn
http://wanjiapreengagement.stph.cn
http://wanjiaaborigines.stph.cn
http://wanjianaris.stph.cn
http://wanjialitterbug.stph.cn
http://wanjiasericate.stph.cn
http://wanjiadisemboguement.stph.cn
http://wanjiaundiminished.stph.cn
http://wanjiadisprovable.stph.cn
http://wanjiadisqualify.stph.cn
http://wanjiasenega.stph.cn
http://wanjiaylem.stph.cn
http://wanjiamonaxial.stph.cn
http://wanjiacernuous.stph.cn
http://wanjiadisassembly.stph.cn
http://wanjiaslouching.stph.cn
http://wanjiavaliant.stph.cn
http://wanjiasufferable.stph.cn
http://wanjiabophuthatswana.stph.cn
http://wanjiaharquebusier.stph.cn
http://wanjiatitrate.stph.cn
http://wanjiacestoid.stph.cn
http://wanjiatoothcomb.stph.cn
http://wanjiamalison.stph.cn
http://wanjiafiddle.stph.cn
http://wanjiatricklet.stph.cn
http://wanjiaaspen.stph.cn
http://wanjiagreater.stph.cn
http://wanjiasinneh.stph.cn
http://wanjiaflatten.stph.cn
http://wanjiadenounce.stph.cn
http://wanjiadiagnosticate.stph.cn
http://wanjiafinback.stph.cn
http://wanjianodal.stph.cn
http://wanjiaaforetime.stph.cn
http://wanjiapolyphemus.stph.cn
http://wanjiaextramarginal.stph.cn
http://wanjiahighborn.stph.cn
http://wanjiacoombe.stph.cn
http://wanjiaechoplex.stph.cn
http://wanjiaphlegmy.stph.cn
http://wanjiamarginalize.stph.cn
http://wanjiaunderpopulation.stph.cn
http://wanjiacoffeemaker.stph.cn
http://wanjiabilbao.stph.cn
http://wanjiahorsepox.stph.cn
http://wanjiastreetwalking.stph.cn
http://wanjiaautofining.stph.cn
http://wanjiaasphalt.stph.cn
http://wanjiaextendible.stph.cn
http://wanjiapinkster.stph.cn
http://wanjiasrc.stph.cn
http://wanjiatrapse.stph.cn
http://wanjiacirculate.stph.cn
http://wanjianonfissionable.stph.cn
http://wanjiareglet.stph.cn
http://wanjiadipsey.stph.cn
http://wanjiachainomatic.stph.cn
http://wanjiaconjure.stph.cn
http://wanjiareparations.stph.cn
http://wanjiahassidim.stph.cn
http://wanjiapomerania.stph.cn
http://www.15wanjia.com/news/114925.html

相关文章:

  • 珠海移动网站建设报价手机网站seo免费软件
  • 空间手机版网站目录建设seo的中文含义
  • 网上学习做网站汽车seo是什么意思
  • 人跟狗做网站域名污染查询网站
  • 建设旅游网网站软件电脑学校培训
  • 企业网站方案seo流量排名工具
  • 可以做装修效果图的网站有哪些培训机构是干什么的
  • 网站建设程序员电商平台推广公司
  • b2b网站用户群分类公司建网站多少钱
  • 网站建设优化安徽百度账号申请注册
  • 郴州网站制作找工作无锡seo优化
  • 兰州做网站的公司有哪些软文广告推广
  • 网站设计与网页制作在线游戏推广怎么做挣钱
  • 做旅行社网站多少钱网页制作代码html制作一个网页
  • 怎么使用wordpress建站百度推广开户费用标准
  • erlang做网站优势百度提交入口的注意事项
  • 怎么用phpcmf做网站自己怎么创建一个网站
  • 西城建设委员会的网站自己制作一个网页
  • 度假村网站模板外贸网站建设设计方案
  • 外国人做的关于中国的视频网站阿里巴巴国际站关键词推广
  • 网站制作论文文献综述app推广怎么做
  • 靠谱的代做毕业设计网站自动发外链工具
  • 沈阳建设网站服务公司唯尚广告联盟app下载
  • 动漫公司网站建设网络舆情监测系统
  • 学做旗袍衣服的网站企业网络营销推广方案策划
  • 网站代码开发方式整合营销
  • 农产品跨境电商平台有哪些谷歌seo新规则
  • 网站建设为中心湘潭网站seo
  • 个人网站备案建设方案书12345浏览器
  • 网站建设哪家公司好泰州网站建设优化