/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/host_utility/stream_utility.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/host_utility/stream_utility.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck/host_utility/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 
8 #include "ck/stream_config.hpp"
10 
11 static 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: hip_check_error.hpp:10
Definition: stream_config.hpp:10
hipStream_t stream_id_
Definition: stream_config.hpp:11