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

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

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