簡體   English   中英

如何在CUDA的塊中返回其他線程?

[英]How do I return other threads in a block in CUDA?

我正在嘗試訪問同一塊中的其他線程,但我想返回一些線程。 我想做這樣的事情:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>

__global__ void returnKernel()
{
    if (blockIdx.x == threadIdx.x)
    {
        //exit/return thread 1
    }
}

int main()
{
    returnKernel<<<4, 4>>>();
    return 0;
}

提前致謝!

沒有辦法“殺死”其他正在運行的線程,它們需要自己“投降”。 這是您問題中的修改為從線程1退出的代碼:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>

__global__ void returnKernel()
{
    if (blockIdx.x < blockDim.x && threadIdx.x == 1)
    {
        return;
    }
}

int main()
{
    returnKernel<<<4, 4>>>();
    return 0;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM