Skip to content

Commit

Permalink
More comprehensive IOCTL PC sampling checks (mi200 and mi300) (#1045)
Browse files Browse the repository at this point in the history
* More comprehensive IOCTL PC sampling checks (mi200 and mi300)

* PC sampling tests: formatting
  • Loading branch information
vlaindic authored Sep 6, 2024
1 parent 93e8266 commit 8bf2ce6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
37 changes: 25 additions & 12 deletions source/lib/rocprofiler-sdk/pc_sampling/ioctl/ioctl_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ get_pc_sampling_ioctl_version(uint32_t kfd_gpu_id, pc_sampling_ioctl_version_t&
* Other values informs users about the reason why PC sampling is not supported.
*/
rocprofiler_status_t
is_pc_sampling_supported(uint32_t kfd_gpu_id)
is_pc_sampling_supported(const rocprofiler_agent_t* agent)
{
auto kfd_gpu_id = agent->gpu_id;
std::string_view agent_name = agent->name;
// Verify KFD 1.16 version
rocprofiler_ioctl_version_info_t ioctl_version = {.major_version = 0, .minor_version = 0};
auto status = get_ioctl_version(ioctl_version);
Expand All @@ -213,7 +215,7 @@ is_pc_sampling_supported(uint32_t kfd_gpu_id)
}

// TODO: remove once KFD is upstreamed
// Verify PC sampling IOCTL 0.1 version
// Verify PC sampling IOCTL version
pc_sampling_ioctl_version_t pcs_ioctl_version = {.major_version = 0, .minor_version = 0};
status = get_pc_sampling_ioctl_version(kfd_gpu_id, pcs_ioctl_version);
if(status != ROCPROFILER_STATUS_SUCCESS)
Expand All @@ -226,16 +228,27 @@ is_pc_sampling_supported(uint32_t kfd_gpu_id)
// that support this feature.
return status;
}
else if(pcs_ioctl_version.major_version < 1 && pcs_ioctl_version.minor_version < 1)
else if(agent_name == "gfx90a")
{
// The PC sampling IOCTL version is the same for all available devices.
// Thus, emit the message and skip all tests and samples on the system in use.
ROCP_ERROR << "PC sampling unavailable\n";
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
// For gfx90a, we expect PC sampling IOCTL to be at least 0.1.
if(pcs_ioctl_version.major_version > 0 || pcs_ioctl_version.minor_version >= 1)
return ROCPROFILER_STATUS_SUCCESS;
else
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
}
else if(agent_name.find("gfx94") == 0)
{
// We expect PC sampling IOCTL to be at least 0.3 for gfx940, gfx941, gfx942, etc.
if(pcs_ioctl_version.major_version > 0 || pcs_ioctl_version.minor_version >= 3)
return ROCPROFILER_STATUS_SUCCESS;
else
return ROCPROFILER_STATUS_ERROR_INCOMPATIBLE_KERNEL;
}
else
{
// The agent does not support PC sampling.
return ROCPROFILER_STATUS_ERROR_NOT_AVAILABLE;
}

// PC sampling is supported on the device with `kfd_gpu_id`.
return ROCPROFILER_STATUS_SUCCESS;
}

/**
Expand Down Expand Up @@ -342,7 +355,7 @@ convert_ioctl_pcs_config_to_rocp(const rocprofiler_ioctl_pc_sampling_info_t& ioc
rocprofiler_status_t
ioctl_query_pcs_configs(const rocprofiler_agent_t* agent, rocp_pcs_cfgs_vec_t& rocp_configs)
{
if(auto status = is_pc_sampling_supported(agent->gpu_id); status != ROCPROFILER_STATUS_SUCCESS)
if(auto status = is_pc_sampling_supported(agent); status != ROCPROFILER_STATUS_SUCCESS)
return status;

uint32_t kfd_gpu_id = agent->gpu_id;
Expand Down Expand Up @@ -444,7 +457,7 @@ ioctl_pcs_create(const rocprofiler_agent_t* agent,
uint64_t interval,
uint32_t* ioctl_pcs_id)
{
if(auto status = is_pc_sampling_supported(agent->gpu_id); status != ROCPROFILER_STATUS_SUCCESS)
if(auto status = is_pc_sampling_supported(agent); status != ROCPROFILER_STATUS_SUCCESS)
return status;

rocprofiler_ioctl_pc_sampling_info_t ioctl_cfg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "lib/common/utility.hpp"

#include <rocprofiler-sdk/buffer.h>
#include <rocprofiler-sdk/fwd.h>
#include <rocprofiler-sdk/internal_threading.h>
Expand Down Expand Up @@ -322,9 +324,11 @@ TEST(pc_sampling, rocprofiler_configure_pc_sampling_service)
static_cast<void*>(&cb_data->gpu_pcs_agents)),
"Failed to find GPU agents");

// TODO-VLAINDIC: Can we dynamically skip the test if the underlying
// HW does not support PC sampling
if(cb_data->gpu_pcs_agents.size() == 0) exit(0);
if(cb_data->gpu_pcs_agents.size() == 0)
{
ROCP_ERROR << "PC sampling unavailable\n";
exit(0);
}

ROCPROFILER_CALL(rocprofiler_create_context(&cb_data->client_ctx),
"failed to create context");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include "lib/common/utility.hpp"

#include <gtest/gtest.h>
#include <rocprofiler-sdk/buffer.h>
#include <rocprofiler-sdk/fwd.h>
Expand Down Expand Up @@ -243,9 +245,11 @@ TEST(pc_sampling, query_configs_after_service_setup)
static_cast<void*>(&cb_data->gpu_pcs_agents)),
"Failed to find GPU agents");

// TODO-VLAINDIC: Can we dynamically skip the test if the underlying
// HW does not support PC sampling
if(cb_data->gpu_pcs_agents.size() == 0) exit(0);
if(cb_data->gpu_pcs_agents.size() == 0)
{
ROCP_ERROR << "PC sampling unavailable\n";
exit(0);
}

int query_cb_data = USER_DATA_VAL;
const auto* agent = cb_data->gpu_pcs_agents.at(0);
Expand Down

0 comments on commit 8bf2ce6

Please sign in to comment.