中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

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

課桌公司網(wǎng)站建設,百度seo搜索引擎優(yōu)化,鄭州哪個網(wǎng)站建設最好,網(wǎng)站虛擬主機虛擬空間CUD Stream https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#c-language-extensions 中指出在kenel的調(diào)用函數(shù)中最后一個可選參數(shù)表示該核函數(shù)處在哪個流之中。 - 參數(shù)Dg用于定義整個grid的維度和尺寸,即一個grid有多少個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ù)中最后一個可選參數(shù)表示該核函數(shù)處在哪個流之中。
    在這里插入圖片描述
- 參數(shù)Dg用于定義整個grid的維度和尺寸,即一個grid有多少個block。為dim3類型。Dim3 Dg(Dg.x, Dg.y, 1)表示grid中每行有Dg.x個block,每列有Dg.y個block,第三維恒為1(目前一個核函數(shù)只有一個grid)。整個grid中共有Dg.x*Dg.y個block,其中Dg.x和Dg.y最大值為65535- 參數(shù)Db用于定義一個block的維度和尺寸,即一個block有多少個thread。為dim3類型。Dim3 Db(Db.x, Db.y, Db.z)表示整個block中每行有Db.x個thread,每列有Db.y個thread,高度為Db.z。Db.x和Db.y最大值為512,Db.z最大值為62。 一個block中共有Db.x*Db.y*Db.z個thread。計算能力為1.0,1.1的硬件該乘積的最大值為768,計算能力為1.2,1.3的硬件支持的最大值為1024。
- Ns 的類型為 size_t,用于設置每個block除了靜態(tài)分配的shared Memory以外,最多能動態(tài)分配的shared memory大小,單位為byte。不需要動態(tài)分配時該值為0或省略不寫。如[__shared__](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#shared)中所述,此動態(tài)分配的內(nèi)存由聲明為外部數(shù)組的任何變量使用; 
- 參數(shù)S是一個cudaStream_t類型的可選參數(shù),初始值為零,表示該核函數(shù)處在哪個流之中。
  • CUDA編程中,默認使用默認流非并行執(zhí)行kernel,每個kernel由許多thread并行的執(zhí)行在GPU上。Stream的概念是相對Grid level來說的,使得kernel在一個device上同時執(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);
// 以下代碼示例將其中每個流定義為從主機到設備的一個內(nèi)存副本、一個內(nèi)核啟動和一個從設備到主機的內(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中,默認情況下,GPU上的操作是在默認流(default stream)中執(zhí)行的。默認流是一個序列化的流,其中的操作按照它們出現(xiàn)的順序逐個執(zhí)行。這意味著在沒有顯式指定其他流的情況下,所有的操作都會在默認流中執(zhí)行。

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

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

import torchdevice = torch.device('cuda')# 創(chuàng)建一個默認流
default_stream = torch.cuda.current_stream()# 創(chuàng)建一個自定義流
custom_stream = torch.cuda.Stream()# 在默認流中執(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

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

錯誤示例

  • 沒有使用 synchronize() 或者 wait_stream()進行同步,可能導致再未完成歸一化前執(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

多設備

// 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://www.risenshineclean.com/news/33241.html

相關文章:

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