thread_group.hpp 1.53 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
2
3
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.

Chao Liu's avatar
Chao Liu committed
4
#pragma once
Chao Liu's avatar
Chao Liu committed
5

Chao Liu's avatar
Chao Liu committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "get_id.hpp"

namespace ck {

template <index_t ThreadPerBlock>
struct ThisThreadBlock
{
    static constexpr index_t kNumThread_ = ThreadPerBlock;

    __device__ static constexpr index_t GetNumOfThread() { return kNumThread_; }

    __device__ static constexpr bool IsBelong() { return true; }

    __device__ static index_t GetThreadId() { return get_thread_local_1d_id(); }
};

Anthony Chang's avatar
Anthony Chang committed
22
23
24
25
26
27
28
29
30
template <index_t ThreadPerBlock>
struct SubThreadBlock
{
    static constexpr index_t kNumThread_ = ThreadPerBlock;

    __device__ SubThreadBlock(int mwave, int nwave) : mwave_(mwave), nwave_(nwave) {}

    __device__ static constexpr index_t GetNumOfThread() { return kNumThread_; }

31
32
    template <typename TupleArg1, typename TupleArg2>
    __device__ constexpr bool IsBelong(const TupleArg1& mwave_range, const TupleArg2& nwave_range)
Anthony Chang's avatar
Anthony Chang committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
    {
        // wave_range[I0] inclusive, wave_range[I1] exclusive
        if(mwave_ < mwave_range[I0])
            return false;
        else if(mwave_ >= mwave_range[I1])
            return false;
        else if(nwave_ < nwave_range[I0])
            return false;
        else if(nwave_ >= nwave_range[I1])
            return false;
        else
            return true;
    }

    __device__ static index_t GetThreadId() { return get_thread_local_1d_id(); }

    private:
    index_t mwave_, nwave_;
    static constexpr auto I0 = Number<0>{};
    static constexpr auto I1 = Number<1>{};
};

Chao Liu's avatar
Chao Liu committed
55
} // namespace ck