国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

課桌公司網(wǎng)站建設(shè)百度seo搜索引擎優(yōu)化

課桌公司網(wǎng)站建設(shè),百度seo搜索引擎優(yōu)化,鄭州哪個(gè)網(wǎng)站建設(shè)最好,網(wǎng)站虛擬主機(jī)虛擬空間CUD Stream https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-language-extensions 中指出在kenel的調(diào)用函數(shù)中最后一個(gè)可選參數(shù)表示該核函數(shù)處在哪個(gè)流之中。 - 參數(shù)Dg用于定義整個(gè)grid的維度和尺寸,即一個(gè)grid有多少個(gè)block。為dim3類型?!?article class="baidu_pl">

CUD Stream

  • https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-language-extensions
    中指出在kenel的調(diào)用函數(shù)中最后一個(gè)可選參數(shù)表示該核函數(shù)處在哪個(gè)流之中。
    在這里插入圖片描述
- 參數(shù)Dg用于定義整個(gè)grid的維度和尺寸,即一個(gè)grid有多少個(gè)block。為dim3類型。Dim3 Dg(Dg.x, Dg.y, 1)表示grid中每行有Dg.x個(gè)block,每列有Dg.y個(gè)block,第三維恒為1(目前一個(gè)核函數(shù)只有一個(gè)grid)。整個(gè)grid中共有Dg.x*Dg.y個(gè)block,其中Dg.x和Dg.y最大值為65535。
- 參數(shù)Db用于定義一個(gè)block的維度和尺寸,即一個(gè)block有多少個(gè)thread。為dim3類型。Dim3 Db(Db.x, Db.y, Db.z)表示整個(gè)block中每行有Db.x個(gè)thread,每列有Db.y個(gè)thread,高度為Db.z。Db.x和Db.y最大值為512,Db.z最大值為62。 一個(gè)block中共有Db.x*Db.y*Db.z個(gè)thread。計(jì)算能力為1.0,1.1的硬件該乘積的最大值為768,計(jì)算能力為1.2,1.3的硬件支持的最大值為1024。
- Ns 的類型為 size_t,用于設(shè)置每個(gè)block除了靜態(tài)分配的shared Memory以外,最多能動(dòng)態(tài)分配的shared memory大小,單位為byte。不需要?jiǎng)討B(tài)分配時(shí)該值為0或省略不寫。如[__shared__](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared)中所述,此動(dòng)態(tài)分配的內(nèi)存由聲明為外部數(shù)組的任何變量使用; 
- 參數(shù)S是一個(gè)cudaStream_t類型的可選參數(shù),初始值為零,表示該核函數(shù)處在哪個(gè)流之中。
  • CUDA編程中,默認(rèn)使用默認(rèn)流非并行執(zhí)行kernel,每個(gè)kernel由許多thread并行的執(zhí)行在GPU上。Stream的概念是相對(duì)Grid level來說的,使得kernel在一個(gè)device上同時(shí)執(zhí)行。
    https://developer.download.nvidia.com/CUDA/training/StreamsAndConcurrencyWebinar.pdf

  • 官方提供的用例

// https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#streams
cudaStream_t stream[2];
for (int i = 0; i < 2; ++i)cudaStreamCreate(&stream[i]);
float* hostPtr;
cudaMallocHost(&hostPtr, 2 * size);
// 以下代碼示例將其中每個(gè)流定義為從主機(jī)到設(shè)備的一個(gè)內(nèi)存副本、一個(gè)內(nèi)核啟動(dòng)和一個(gè)從設(shè)備到主機(jī)的內(nèi)存副本的序列:
for (int i = 0; i < 2; ++i) {cudaMemcpyAsync(inputDevPtr + i * size, hostPtr + i * size,size, cudaMemcpyHostToDevice, stream[i]);MyKernel <<<100, 512, 0, stream[i]>>>(outputDevPtr + i * size, inputDevPtr + i * size, size);cudaMemcpyAsync(hostPtr + i * size, outputDevPtr + i * size,size, cudaMemcpyDeviceToHost, stream[i]);
}
// 通過調(diào)用 釋放流
for (int i = 0; i < 2; ++i)cudaStreamDestroy(stream[i]);

PyTorch Stream

  • 在PyTorch中,默認(rèn)情況下,GPU上的操作是在默認(rèn)流(default stream)中執(zhí)行的。默認(rèn)流是一個(gè)序列化的流,其中的操作按照它們出現(xiàn)的順序逐個(gè)執(zhí)行。這意味著在沒有顯式指定其他流的情況下,所有的操作都會(huì)在默認(rèn)流中執(zhí)行。

  • 然而,PyTorch還提供了功能可以將操作提交到其他流中執(zhí)行,以充分利用GPU的并行性。這對(duì)于并行處理多個(gè)任務(wù)或同時(shí)執(zhí)行多個(gè)獨(dú)立操作非常有用。

  • 您可以使用torch.cuda.Stream()來創(chuàng)建其他流,并使用torch.cuda.current_stream()來獲取當(dāng)前流。然后,您可以將操作提交到指定的流中執(zhí)行,例如:

import torchdevice = torch.device('cuda')# 創(chuàng)建一個(gè)默認(rèn)流
default_stream = torch.cuda.current_stream()# 創(chuàng)建一個(gè)自定義流
custom_stream = torch.cuda.Stream()# 在默認(rèn)流中執(zhí)行操作
with torch.cuda.stream(default_stream):# 執(zhí)行操作...# 在自定義流中執(zhí)行操作
with torch.cuda.stream(custom_stream):# 執(zhí)行操作...

例子

import torch
s1 = torch.cuda.Stream()
s2 = torch.cuda.Stream()
# Initialise cuda tensors here. E.g.:
A = torch.rand(1000, 1000, device = 'cuda')
B = torch.rand(1000, 1000, device = 'cuda')
# Wait for the above tensors to initialise.
torch.cuda.synchronize()
with torch.cuda.stream(s1):C = torch.mm(A, A)
with torch.cuda.stream(s2):D = torch.mm(B, B)
# Wait for C and D to be computed.
torch.cuda.synchronize()
# Do stuff with C and D.
print(C)
print(D)
// https://stackoverflow.com/questions/70128833/why-and-when-to-use-torch-cuda-stream

這樣可以利用多個(gè)流來并行執(zhí)行計(jì)算,并在計(jì)算和數(shù)據(jù)傳輸之間實(shí)現(xiàn)重疊。這對(duì)于提高GPU利用率和加速訓(xùn)練或推理過程非常有幫助。

錯(cuò)誤示例

  • 沒有使用 synchronize() 或者 wait_stream()進(jìn)行同步,可能導(dǎo)致再未完成歸一化前執(zhí)行求和
// https://pytorch.org/docs/stable/notes/cuda.html
cuda = torch.device('cuda')
s = torch.cuda.Stream()  # Create a new stream.
A = torch.empty((100, 100), device=cuda).normal_(0.0, 1.0)
with torch.cuda.stream(s):# sum() may start execution before normal_() finishes!B = torch.sum(A)

CG

  • https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#streams

  • https://pytorch.org/docs/stable/notes/cuda.html#multistream-capture

  • https://pytorch.org/cppdocs/notes/tensor_cuda_stream.html

  • https://pypi.org/project/pytorch-stream/

  • CUDA 的 Stream and Event https://zhuanlan.zhihu.com/p/369367933

  • GITHUBGIST Gist就是小型代碼片段的分享https://www.cnblogs.com/leader755/p/14284716.html

  • [JIT] 在 TorchScript 中支持 CUDA 流 https://github.com/pytorch/pytorch/issues/41355

  • https://pytorch.org/docs/stable/notes/cuda.html#cuda-semantics

  • https://github.com/pytorch/pytorch/issues/41355

多設(shè)備

// https://pytorch.org/docs/stable/notes/cuda.html#cuda-semantics
cuda = torch.device('cuda')     # Default CUDA device
cuda0 = torch.device('cuda:0')
cuda2 = torch.device('cuda:2')  # GPU 2 (these are 0-indexed)x = torch.tensor([1., 2.], device=cuda0)
# x.device is device(type='cuda', index=0)
y = torch.tensor([1., 2.]).cuda()
# y.device is device(type='cuda', index=0)with torch.cuda.device(1):# allocates a tensor on GPU 1a = torch.tensor([1., 2.], device=cuda)# transfers a tensor from CPU to GPU 1b = torch.tensor([1., 2.]).cuda()# a.device and b.device are device(type='cuda', index=1)# You can also use ``Tensor.to`` to transfer a tensor:b2 = torch.tensor([1., 2.]).to(device=cuda)# b.device and b2.device are device(type='cuda', index=1)c = a + b# c.device is device(type='cuda', index=1)z = x + y# z.device is device(type='cuda', index=0)# even within a context, you can specify the device# (or give a GPU index to the .cuda call)d = torch.randn(2, device=cuda2)e = torch.randn(2).to(cuda2)f = torch.randn(2).cuda(cuda2)# d.device, e.device, and f.device are all device(type='cuda', index=2)
http://m.aloenet.com.cn/news/33241.html

相關(guān)文章:

  • 前段模板的網(wǎng)站企業(yè)培訓(xùn)機(jī)構(gòu)
  • 攝影設(shè)計(jì)網(wǎng)站百度知道官網(wǎng)登錄入口
  • 做網(wǎng)站需注意事項(xiàng)湛江今日頭條新聞
  • 做彩妝網(wǎng)站的公司建站教程
  • 網(wǎng)站建設(shè)的招聘要求張家口網(wǎng)站seo
  • 什么軟件 做短視頻網(wǎng)站好北京百度推廣優(yōu)化排名
  • 高德地圖有外資背景嗎seo優(yōu)化技術(shù)廠家
  • 網(wǎng)站建設(shè)制作公司哪家打開百度網(wǎng)頁
  • 如何建立一個(gè)網(wǎng)站根目錄山東企業(yè)網(wǎng)站建設(shè)
  • 848給我做一下88網(wǎng)站人工智能培訓(xùn)機(jī)構(gòu)哪個(gè)好
  • 蘇州招聘網(wǎng)站建設(shè)bt磁力搜索
  • 在線做抽獎(jiǎng)網(wǎng)站營銷的四種方式
  • 專業(yè)的網(wǎng)站建設(shè)官網(wǎng)山西百度推廣開戶
  • seo聯(lián)盟平臺(tái)seo教程自學(xué)入門教材
  • 佛山多語網(wǎng)站制作百度搜索關(guān)鍵詞技巧
  • 免費(fèi)網(wǎng)站模板怎么做網(wǎng)站無錫營銷型網(wǎng)站建站
  • 廣西網(wǎng)站制作b站推廣入口在哪
  • 萬網(wǎng)域名查詢工具廣州seo效果
  • 企業(yè)網(wǎng)站建設(shè)官網(wǎng)搜索引擎關(guān)鍵詞排名
  • 國內(nèi)外設(shè)計(jì)網(wǎng)站做企業(yè)推廣的公司
  • 做網(wǎng)站bbs是什么意思北京網(wǎng)站推廣營銷策劃
  • 正規(guī)制作網(wǎng)站公司哪家好西安全網(wǎng)優(yōu)化
  • 泉州做媽祖雕像網(wǎng)站常用的網(wǎng)絡(luò)營銷工具
  • 有什么值得做的網(wǎng)站企業(yè)網(wǎng)頁設(shè)計(jì)公司
  • 建購物網(wǎng)站怎么建呀微商怎么做推廣加好友
  • 廣州響應(yīng)網(wǎng)站建設(shè)網(wǎng)頁設(shè)計(jì)友情鏈接怎么做
  • 深圳方維網(wǎng)站建設(shè)公司百度推廣運(yùn)營公司
  • 我們的愛情網(wǎng)站制作網(wǎng)絡(luò)推廣外包聯(lián)系方式
  • 物流網(wǎng)站畢業(yè)論文如何做網(wǎng)站搜索引擎優(yōu)化
  • 渭南房產(chǎn)網(wǎng)站制作搜索引擎營銷策略有哪些