drm/amdkfd: helper to convert gpu id and idx
authorAlex Sierra <alex.sierra@amd.com>
Wed, 8 Apr 2020 04:08:45 +0000 (23:08 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 21 Apr 2021 01:46:07 +0000 (21:46 -0400)
svm range uses gpu bitmap to store which GPU svm range maps to.
Application pass driver gpu id to specify GPU, the helper is needed to
convert gpu id to gpu bitmap idx.

Access through kfd_process_device pointers array from kfd_process.

Signed-off-by: Alex Sierra <alex.sierra@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdkfd/kfd_priv.h
drivers/gpu/drm/amd/amdkfd/kfd_process.c

index c6357ceb247d1a2831f6252760596dc4c36b2d42..f887f2eb0a663e66f64cc317da0b4fe131a41c33 100644 (file)
@@ -842,6 +842,17 @@ struct kfd_process *kfd_create_process(struct file *filep);
 struct kfd_process *kfd_get_process(const struct task_struct *);
 struct kfd_process *kfd_lookup_process_by_pasid(u32 pasid);
 struct kfd_process *kfd_lookup_process_by_mm(const struct mm_struct *mm);
+
+int kfd_process_gpuidx_from_gpuid(struct kfd_process *p, uint32_t gpu_id);
+static inline int kfd_process_gpuid_from_gpuidx(struct kfd_process *p,
+                               uint32_t gpuidx, uint32_t *gpuid) {
+       return gpuidx < p->n_pdds ? p->pdds[gpuidx]->dev->id : -EINVAL;
+}
+static inline struct kfd_process_device *kfd_process_device_from_gpuidx(
+                               struct kfd_process *p, uint32_t gpuidx) {
+       return gpuidx < p->n_pdds ? p->pdds[gpuidx] : NULL;
+}
+
 void kfd_unref_process(struct kfd_process *p);
 int kfd_process_evict_queues(struct kfd_process *p);
 int kfd_process_restore_queues(struct kfd_process *p);
index 0a53794396424575079017b517b379e721a295b3..d40cd6c10096b6859dcec9081cf5b0f9bbce1759 100644 (file)
@@ -1602,6 +1602,16 @@ int kfd_process_restore_queues(struct kfd_process *p)
        return ret;
 }
 
+int kfd_process_gpuidx_from_gpuid(struct kfd_process *p, uint32_t gpu_id)
+{
+       int i;
+
+       for (i = 0; i < p->n_pdds; i++)
+               if (p->pdds[i] && gpu_id == p->pdds[i]->dev->id)
+                       return i;
+       return -EINVAL;
+}
+
 static void evict_process_worker(struct work_struct *work)
 {
        int ret;