HIP icon indicating copy to clipboard operation
HIP copied to clipboard

question about cache line size

Open jinz2014 opened this issue 1 year ago • 5 comments

Is there a HIP API for the query of cache line size ? Thanks.

jinz2014 avatar Jun 06 '23 13:06 jinz2014

No. There is no cache line query on HIP side.

If you are curious about cache line size on your GPU, you can use CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE on OpenCL.

jatinx avatar Jun 06 '23 13:06 jatinx

Will a HIP API be added for that ? In general, will APIs be added for other properties that are only available in OpenCL ? Thanks.

jinz2014 avatar Jun 06 '23 14:06 jinz2014

Are there some general rules about the size ? Is the size based on discrete or integrated, consumer or data center, etc ? Most people couldn't buy all AMD GPU products.

jinz2014 avatar Jun 06 '23 16:06 jinz2014

HIP does have a cache-line query. Can you please explain what are you trying to do with cache size, maybe we can find a way to work around it.

cjatin avatar Aug 24 '23 13:08 cjatin

There is a cache-line size query in SYCL. Then the query can be supported in the HIP backend of the SYCL. Thank you.

jinz2014 avatar Aug 24 '23 14:08 jinz2014

@jinz2014 Is this issue resolved for you? Thanks!

ppanchad-amd avatar Apr 25 '24 17:04 ppanchad-amd

No, Thanks.

jinz2014 avatar Apr 25 '24 18:04 jinz2014

HIP will not add the query.

Although there are ways to get this information from other parts of ROCm stack. For example if you are on linux and HSA you can use the cacheline query:

#include <hsa/hsa.h>
#include <hsa/hsa_ext_amd.h>

#include <iostream>
#include <vector>

#define check(hsa_call)                                                        \
  {                                                                            \
    auto res = hsa_call;                                                       \
    if (res != HSA_STATUS_SUCCESS) {                                           \
      std::cout << "failed in hsa call: " << #hsa_call << std::endl;           \
      std::abort();                                                            \
    }                                                                          \
  }

hsa_status_t agent_callback(hsa_agent_t agent, void *data) {
  hsa_device_type_t dev_type = HSA_DEVICE_TYPE_CPU;
  auto agents = reinterpret_cast<std::vector<hsa_agent_t> *>(data);

  hsa_status_t stat =
      hsa_agent_get_info(agent, HSA_AGENT_INFO_DEVICE, &dev_type);

  if (dev_type == HSA_DEVICE_TYPE_GPU) {
    agents->push_back(agent);
  }

  return stat;
}

std::vector<hsa_agent_t> get_hsa_agents() {
  std::vector<hsa_agent_t> agents;
  check(hsa_iterate_agents(agent_callback, (void *)(&agents)));
  return agents;
}

std::string get_agent_name(hsa_agent_t agent) {
  std::string name(64, 0);
  check(hsa_agent_get_info(
      agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_PRODUCT_NAME),
      name.data()));
  return name;
}

unsigned int get_agent_cache_line_size(hsa_agent_t agent) {
  unsigned int csize = 0;
  check(hsa_agent_get_info(
      agent, static_cast<hsa_agent_info_t>(HSA_AMD_AGENT_INFO_CACHELINE_SIZE),
      &csize));
  return csize;
}

int main() {
  check(hsa_init());

  auto agents = get_hsa_agents();
  if (agents.size() == 0) {
    std::cerr << "No gpus found..." << std::endl;
    std::abort();
  }

  for (auto &agent : agents) {
    auto name = get_agent_name(agent);
    auto cache_line_size = get_agent_cache_line_size(agent);
    std::cout << "Agent: " << name
              << " has cache line size of: " << cache_line_size << std::endl;
  }

  check(hsa_shut_down());
}

To compile: g++ file.cpp -I /opt/rocm/include -L /opt/rocm/lib -lhsa-runtime64 -o out

cjatin avatar Apr 26 '24 00:04 cjatin

Thank you for the example, anyway.

jinz2014 avatar Apr 26 '24 15:04 jinz2014