Lines 1-4
Link Here
|
1 |
--- lib/CL/devices/cpuinfo.c.orig 2017-04-05 14:15:40 UTC |
1 |
--- lib/CL/devices/cpuinfo.c.orig 2017-12-18 18:45:53 UTC |
2 |
+++ lib/CL/devices/cpuinfo.c |
2 |
+++ lib/CL/devices/cpuinfo.c |
3 |
@@ -34,6 +34,12 @@ |
3 |
@@ -34,6 +34,12 @@ |
4 |
#include "config.h" |
4 |
#include "config.h" |
Lines 13-25
Link Here
|
13 |
static const char* cpuinfo = "/proc/cpuinfo"; |
13 |
static const char* cpuinfo = "/proc/cpuinfo"; |
14 |
#define MAX_CPUINFO_SIZE 64*1024 |
14 |
#define MAX_CPUINFO_SIZE 64*1024 |
15 |
//#define DEBUG_POCL_CPUINFO |
15 |
//#define DEBUG_POCL_CPUINFO |
16 |
@@ -153,8 +159,51 @@ pocl_cpuinfo_detect_max_clock_frequency( |
16 |
@@ -153,8 +159,51 @@ pocl_cpuinfo_detect_max_clock_frequency() |
17 |
} |
17 |
} |
18 |
return -1; |
18 |
return -1; |
19 |
} |
19 |
} |
20 |
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
20 |
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
21 |
+/** |
21 |
+/** |
22 |
+ * Detects the maximum clock frequency of the CPU. |
22 |
+ * Detects the maximum clock frequency of the CPU |
23 |
+ * |
23 |
+ * |
24 |
+ * Assumes all cores have the same max clock freq. |
24 |
+ * Assumes all cores have the same max clock freq. |
25 |
+ * |
25 |
+ * |
Lines 35-42
Link Here
|
35 |
+ char *value = NULL; |
35 |
+ char *value = NULL; |
36 |
|
36 |
|
37 |
+ if (!sysctlbyname(mib1, NULL, &size, NULL, 0) && |
37 |
+ if (!sysctlbyname(mib1, NULL, &size, NULL, 0) && |
38 |
+ (value = (char*)malloc(++size)) && |
38 |
+ (value = (char*)malloc(++size)) && |
39 |
+ !sysctlbyname(mib1, (void*)value, &size, NULL, 0)) |
39 |
+ !sysctlbyname(mib1, (void*)value, &size, NULL, 0)) |
40 |
+ { |
40 |
+ { |
41 |
+ value[size] = '\0'; |
41 |
+ value[size] = '\0'; |
42 |
+ sscanf(value, "%d/%*d", &clockrate); |
42 |
+ sscanf(value, "%d/%*d", &clockrate); |
Lines 43-49
Link Here
|
43 |
+ } |
43 |
+ } |
44 |
+ else |
44 |
+ else |
45 |
+ { |
45 |
+ { |
46 |
+ size = sizeof(clockrate); |
46 |
+ size = sizeof(clockrate); |
47 |
+ sysctlbyname(mib2, (void*)&clockrate, &size, NULL, 0); |
47 |
+ sysctlbyname(mib2, (void*)&clockrate, &size, NULL, 0); |
48 |
+ } |
48 |
+ } |
49 |
+ if (value) |
49 |
+ if (value) |
Lines 54-60
Link Here
|
54 |
+/** |
54 |
+/** |
55 |
+ * Unimplemented for other platforms. |
55 |
+ * Unimplemented for other platforms. |
56 |
+ */ |
56 |
+ */ |
57 |
+ int |
57 |
+int |
58 |
+pocl_cpuinfo_detect_max_clock_frequency() |
58 |
+pocl_cpuinfo_detect_max_clock_frequency() |
59 |
+{ |
59 |
+{ |
60 |
+ return 0; |
60 |
+ return 0; |
Lines 76-82
Link Here
|
76 |
+ * |
76 |
+ * |
77 |
+ * @return The number of hardware threads. |
77 |
+ * @return The number of hardware threads. |
78 |
+ */ |
78 |
+ */ |
79 |
+ int |
79 |
+int |
80 |
+pocl_cpuinfo_detect_compute_unit_count() |
80 |
+pocl_cpuinfo_detect_compute_unit_count() |
81 |
+{ |
81 |
+{ |
82 |
+ return sysconf(_SC_NPROCESSORS_ONLN); |
82 |
+ return sysconf(_SC_NPROCESSORS_ONLN); |
Lines 85-99
Link Here
|
85 |
|
85 |
|
86 |
#ifdef POCL_ANDROID |
86 |
#ifdef POCL_ANDROID |
87 |
|
87 |
|
88 |
@@ -270,6 +332,7 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
88 |
@@ -326,6 +388,7 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_device_id devi |
89 |
* short_name is in the .data anyways.*/ |
89 |
* short_name is in the .data anyways.*/ |
90 |
device->long_name = device->short_name; |
90 |
device->long_name = device->short_name; |
91 |
|
91 |
|
92 |
+#ifdef __linux__ |
92 |
+#ifdef __linux__ |
93 |
/* default vendor and vendor_id, in case it cannot be found by other means */ |
93 |
/* default vendor and vendor_id, in case it cannot be found by other means */ |
94 |
device->vendor = cpuvendor_default; |
94 |
device->vendor = cpuvendor_default; |
95 |
if (device->vendor_id == 0) |
95 |
if (device->vendor_id == 0) |
96 |
@@ -318,7 +381,25 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
96 |
@@ -425,6 +488,25 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_device_id devi |
97 |
char *new_name = (char*)malloc (len); |
97 |
char *new_name = (char*)malloc (len); |
98 |
snprintf (new_name, len, "%s-%s", device->short_name, start); |
98 |
snprintf (new_name, len, "%s-%s", device->short_name, start); |
99 |
device->long_name = new_name; |
99 |
device->long_name = new_name; |
Lines 101-107
Link Here
|
101 |
+ int mib[2]; |
101 |
+ int mib[2]; |
102 |
+ size_t len = 0; |
102 |
+ size_t len = 0; |
103 |
+ char *model; |
103 |
+ char *model; |
104 |
|
104 |
+ |
105 |
+ mib[0] = CTL_HW; |
105 |
+ mib[0] = CTL_HW; |
106 |
+ mib[1] = HW_MODEL; |
106 |
+ mib[1] = HW_MODEL; |
107 |
+ if (sysctl(mib, 2, NULL, &len, NULL, 0)) |
107 |
+ if (sysctl(mib, 2, NULL, &len, NULL, 0)) |