From 02461acafd41bc381eff30e1b10f8ffe97bbe593 Mon Sep 17 00:00:00 2001
From: Adel Ejjeh <aejjeh@tyler.cs.illinois.edu>
Date: Fri, 24 Jan 2020 12:57:36 -0600
Subject: [PATCH] fixed issue in findplatform in runtime

---
 hpvm/projects/hpvm-rt/hpvm-rt.cpp | 33 ++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/hpvm/projects/hpvm-rt/hpvm-rt.cpp b/hpvm/projects/hpvm-rt/hpvm-rt.cpp
index 266d6296dc..20af30fdfa 100644
--- a/hpvm/projects/hpvm-rt/hpvm-rt.cpp
+++ b/hpvm/projects/hpvm-rt/hpvm-rt.cpp
@@ -16,6 +16,7 @@
 #endif
 #include "hpvm-rt.h"
 
+#define DEBUG_BUILD
 #ifndef DEBUG_BUILD
 #define DEBUG(s)                                                               \
   {}
@@ -1396,8 +1397,9 @@ cl_platform_id findPlatform(const char *platform_name_search) {
 
     if (name.find(search) != std::string::npos) {
       // Found!
+      cl_platform_id pid = pids[i];
       free(pids);
-      return pids[i];
+      return pid;
     }
   }
 
@@ -1439,9 +1441,36 @@ void *llvm_hpvm_ocl_initContext(enum hpvm::Target T) {
   cl_platform_id platformId;
   if (T == hpvm::GPU_TARGET) {
     platformId = findPlatform("nvidia");
+    char buffer[10240];
+    DEBUG(cout << "Found NVIDIA Device \n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_PROFILE, 10240, buffer, NULL);
+    DEBUG(cout << "\tPROFILE = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_VERSION, 10240, buffer, NULL);
+    DEBUG(cout << "\tVERSION = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_NAME, 10240, buffer, NULL);
+    DEBUG(cout << "\tNAME = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_VENDOR, 10240, buffer, NULL);
+    DEBUG(cout << "\tVENDOR = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer,
+                      NULL);
+    DEBUG(cout << "\tEXTENSIONS = " << buffer << flush << "\n");
   } else {
     platformId = findPlatform("intel");
+    char buffer[10240];
+    DEBUG(cout << "Found Intel Device \n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_PROFILE, 10240, buffer, NULL);
+    DEBUG(cout << "\tPROFILE = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_VERSION, 10240, buffer, NULL);
+    DEBUG(cout << "\tVERSION = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_NAME, 10240, buffer, NULL);
+    DEBUG(cout << "\tNAME = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_VENDOR, 10240, buffer, NULL);
+    DEBUG(cout << "\tVENDOR = " << buffer << flush << "\n");
+    clGetPlatformInfo(platformId, CL_PLATFORM_EXTENSIONS, 10240, buffer,
+                      NULL);
+    DEBUG(cout << "\tEXTENSIONS = " << buffer << flush << "\n");
   }
+  DEBUG(cout << "Found plarform with id: " << platformId << "\n");
   cl_context_properties properties[] = {CL_CONTEXT_PLATFORM, (long)platformId,
                                         0};
   globalOCLContext = clCreateContextFromType(
@@ -1454,6 +1483,8 @@ void *llvm_hpvm_ocl_initContext(enum hpvm::Target T) {
   errcode = clGetContextInfo(globalOCLContext, CL_CONTEXT_DEVICES, 0, NULL,
                              &dataBytes);
   checkErr(errcode, CL_SUCCESS, "Failure to get context info length");
+  
+  DEBUG(cout << "Got databytes: " << dataBytes << "\n");
 
   clDevices = (cl_device_id *)malloc(dataBytes);
   errcode |= clGetContextInfo(globalOCLContext, CL_CONTEXT_DEVICES, dataBytes,
-- 
GitLab