[Beignet] [PATCH 01/19] Backend: Add ProfilingInfo class to ir.

junyan.he at inbox.com junyan.he at inbox.com
Tue Sep 8 17:00:52 PDT 2015


From: Junyan He <junyan.he at linux.intel.com>

ProfilingInfo will play important role in output
the profiling log. It will record the profiling
information and generate the logs after clfinish.

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/CMakeLists.txt   |    2 +
 backend/src/ir/profiling.cpp |   70 ++++++++++++++++++++++
 backend/src/ir/profiling.hpp |  132 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 backend/src/ir/profiling.cpp
 create mode 100644 backend/src/ir/profiling.hpp

diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index c0d0c23..daab320 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -66,6 +66,8 @@ set (GBE_SRC
     ir/value.hpp
     ir/lowering.cpp
     ir/lowering.hpp
+    ir/profiling.cpp
+    ir/profiling.hpp
     ir/printf.cpp
     ir/printf.hpp
     ir/immediate.hpp
diff --git a/backend/src/ir/profiling.cpp b/backend/src/ir/profiling.cpp
new file mode 100644
index 0000000..fe449e6
--- /dev/null
+++ b/backend/src/ir/profiling.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+/**
+ * \file profiling.cpp
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "ir/profiling.hpp"
+#include "src/cl_device_data.h"
+
+namespace gbe
+{
+namespace ir
+{
+  pthread_mutex_t ProfilingInfo::lock = PTHREAD_MUTEX_INITIALIZER;
+
+  void ProfilingInfo::outputProfilingInfo(void * logBuf)
+  {
+    LockOutput lock;
+    uint32_t logNum = *reinterpret_cast<uint32_t*>(logBuf);
+    printf("Total log number is %u\n", logNum);
+    ProfilingReportItem* log = reinterpret_cast<ProfilingReportItem*>((char*)logBuf + 4);
+    for (int i = 0; i < (int)logNum; i++) {
+      GBE_ASSERT(log->simdType == ProfilingSimdType8 || log->simdType == ProfilingSimdType16);
+      uint32_t simd = log->simdType == ProfilingSimdType16 ? 16 : 8;
+      printf(" ------------------------ Log %-6d -----------------------\n", i);
+      printf(" | fix functions id:%4d     simd: %4d   kernel id: %4d  |\n", log->fixedFunctionID,
+          simd, log->kernelID);
+      if (IS_IVYBRIDGE(deviceID)) {
+        printf(" | thread id:       %4d     EU id:%4d   half slice id:%2d |\n", log->genInfo.gen7.thread_id,
+            log->genInfo.gen7.eu_id, log->genInfo.gen7.half_slice_id);
+      } else if (IS_HASWELL(deviceID)) {
+        printf(" | thread id: %4d  EU id:%4d half slice id:%2d slice id%2d |\n", log->genInfo.gen7.thread_id,
+            log->genInfo.gen7.eu_id, log->genInfo.gen7.half_slice_id, log->genInfo.gen7.slice_id);
+      } else if (IS_BROADWELL(deviceID)) {
+        printf(" | thread id: %4d  EU id:%4d  sub slice id:%2d slice id%2d |\n", log->genInfo.gen8.thread_id,
+            log->genInfo.gen8.eu_id, log->genInfo.gen8.subslice_id, log->genInfo.gen8.slice_id);
+      }
+      printf(" | dispatch Mask:%4x prolog:%10lu  epilog:%10lu |\n", log->dispatchMask,
+          *reinterpret_cast<uint64_t*>(&(log->timestampPrologLo)),
+          *reinterpret_cast<uint64_t*>(&(log->timestampEpilogLo)));
+      printf(" | globalX:%4d~%4d  globalY:%4d~%4d  globalZ:%4d~%4d |\n", log->gidXStart, log->gidXEnd,
+          log->gidYStart, log->gidYEnd, log->gidZStart, log->gidZEnd);
+      for (uint32_t i = 0; i < MaxTimestampProfilingPoints - 2; i += 3) {
+        printf(" |  ts%-2d:%10u  | ts%-2d:%10u  | ts%-2d:%10u  |\n", i, log->userTimestamp[i],
+            i + 1, log->userTimestamp[i + 1], i + 2, log->userTimestamp[i + 2]);
+      }
+      printf(" |  ts18:%10u  | ts19:%10u  |                  |\n", log->userTimestamp[18], log->userTimestamp[19]);
+      log++;
+    }
+  }
+}
+}
diff --git a/backend/src/ir/profiling.hpp b/backend/src/ir/profiling.hpp
new file mode 100644
index 0000000..ce9866f
--- /dev/null
+++ b/backend/src/ir/profiling.hpp
@@ -0,0 +1,132 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+/**
+ * \file profiling.hpp
+ *
+ */
+#ifndef __GBE_IR_PROFILING_HPP__
+#define __GBE_IR_PROFILING_HPP__
+
+#include <string.h>
+#include "sys/map.hpp"
+#include "sys/vector.hpp"
+#include "unit.hpp"
+
+namespace gbe
+{
+  namespace ir
+  {
+    class Context;
+    class ProfilingInfo //: public Serializable
+    {
+    public:
+      const static uint32_t MaxTimestampProfilingPoints = 20;
+      enum {
+        ProfilingSimdType1,
+        ProfilingSimdType8,
+        ProfilingSimdType16,
+      };
+
+      typedef struct {
+        uint32_t fixedFunctionID:4;
+        uint32_t simdType:4;
+        uint32_t kernelID:24;
+        union GenInfo {
+          struct Gen7Info {
+            uint16_t thread_id:3;
+            uint16_t reserved1:5;
+            uint16_t eu_id:4;
+            uint16_t half_slice_id:1;
+            uint16_t slice_id:2;
+            uint16_t reserved0:1;
+          } gen7;
+          struct Gen8Info {
+            uint16_t thread_id:3;
+            uint16_t reserved1:5;
+            uint16_t eu_id:4;
+            uint16_t subslice_id:2;
+            uint16_t slice_id:2;
+          } gen8;
+        } genInfo;
+        uint16_t dispatchMask;
+        uint32_t gidXStart;
+        uint32_t gidXEnd;
+        uint32_t gidYStart;
+        uint32_t gidYEnd;
+        uint32_t gidZStart;
+        uint32_t gidZEnd;
+        uint32_t userTimestamp[MaxTimestampProfilingPoints];
+        uint32_t timestampPrologLo;
+        uint32_t timestampPrologHi;
+        uint32_t timestampEpilogLo;
+        uint32_t timestampEpilogHi;
+      } ProfilingReportItem;
+
+      ProfilingInfo(const ProfilingInfo& other) {
+        this->bti = other.bti;
+        this->profilingType = other.profilingType;
+        this->deviceID = other.deviceID;
+      }
+
+      ProfilingInfo(void) {
+        this->bti = 0;
+        this->profilingType = 0;
+        this->deviceID = 0;
+      }
+      struct LockOutput {
+        LockOutput(void) {
+          pthread_mutex_lock(&lock);
+        }
+
+        ~LockOutput(void) {
+          pthread_mutex_unlock(&lock);
+        }
+      };
+
+      void setBTI(uint32_t b) {
+        bti = b;
+      }
+      uint32_t getBTI() const {
+        return bti;
+      }
+      void setProfilingType(uint32_t t) {
+        profilingType = t;
+      }
+      uint32_t getProfilingType() const {
+        return profilingType;
+      }
+      void setDeviceID(uint32_t id) {
+        deviceID = id;
+      }
+      uint32_t getDeviceID() const {
+        return deviceID;
+      }
+      void outputProfilingInfo(void* logBuf);
+
+    private:
+      uint32_t bti;
+      uint32_t profilingType;
+      uint32_t deviceID;
+      friend struct LockOutput;
+      static pthread_mutex_t lock;
+      GBE_CLASS(ProfilingInfo);
+    };
+  } /* namespace ir */
+} /* namespace gbe */
+
+#endif /* __GBE_IR_PROFILING_HPP__ */
-- 
1.7.9.5





More information about the Beignet mailing list