stream_utility.hpp Source File

stream_utility.hpp Source File#

Composable Kernel: stream_utility.hpp Source File
stream_utility.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
6#include <hip/hip_runtime.h>
7
10
11static inline int getAvailableComputeUnitCount(const StreamConfig& stream_config)
12{
13 constexpr int MAX_MASK_DWORDS = 64;
14
15 // assume at most 64*32 = 2048 CUs
16 uint32_t cuMask[MAX_MASK_DWORDS];
17
18 for(int i = 0; i < MAX_MASK_DWORDS; i++)
19 cuMask[i] = 0;
20
21 auto countSetBits = [](uint32_t dword) {
22 int count = 0;
23
24 while(dword != 0)
25 {
26 if(dword & 0x1)
27 count++;
28
29 dword = dword >> 1;
30 };
31
32 return (count);
33 };
34
35 hip_check_error(hipExtStreamGetCUMask(stream_config.stream_id_, MAX_MASK_DWORDS, &cuMask[0]));
36
37 int ret = 0;
38
39 for(int i = 0; i < MAX_MASK_DWORDS; i++)
40 ret += countSetBits(cuMask[i]);
41
42 return (ret);
43};
void hip_check_error(hipError_t x)
Definition host_utility/hip_check_error.hpp:10
unsigned int uint32_t
Definition stdint.h:126
Definition ck/stream_config.hpp:10
hipStream_t stream_id_
Definition ck/stream_config.hpp:11