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 2018-01-08 09:13:55 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-22
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 |
@@ -154,7 +160,51 @@ pocl_cpuinfo_detect_max_clock_frequency( |
17 |
} |
|
|
18 |
return -1; |
17 |
return -1; |
19 |
} |
18 |
} |
|
|
19 |
|
20 |
- |
20 |
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
21 |
+#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) |
21 |
+/** |
22 |
+/** |
22 |
+ * Detects the maximum clock frequency of the CPU. |
23 |
+ * Detects the maximum clock frequency of the CPU. |
Lines 25-31
Link Here
|
25 |
+ * |
26 |
+ * |
26 |
+ * @return The clock frequency in MHz. |
27 |
+ * @return The clock frequency in MHz. |
27 |
+ */ |
28 |
+ */ |
28 |
+int |
29 |
+static int |
29 |
+pocl_cpuinfo_detect_max_clock_frequency() |
30 |
+pocl_cpuinfo_detect_max_clock_frequency() |
30 |
+{ |
31 |
+{ |
31 |
+ const char mib1[] = "dev.cpu.0.freq_levels"; |
32 |
+ const char mib1[] = "dev.cpu.0.freq_levels"; |
Lines 33-39
Link Here
|
33 |
+ int clockrate = 0; |
34 |
+ int clockrate = 0; |
34 |
+ size_t size = 0; |
35 |
+ size_t size = 0; |
35 |
+ char *value = NULL; |
36 |
+ char *value = NULL; |
36 |
|
37 |
+ |
37 |
+ if (!sysctlbyname(mib1, NULL, &size, NULL, 0) && |
38 |
+ if (!sysctlbyname(mib1, NULL, &size, NULL, 0) && |
38 |
+ (value = (char*)malloc(++size)) && |
39 |
+ (value = (char*)malloc(++size)) && |
39 |
+ !sysctlbyname(mib1, (void*)value, &size, NULL, 0)) |
40 |
+ !sysctlbyname(mib1, (void*)value, &size, NULL, 0)) |
Lines 54-74
Link Here
|
54 |
+/** |
55 |
+/** |
55 |
+ * Unimplemented for other platforms. |
56 |
+ * Unimplemented for other platforms. |
56 |
+ */ |
57 |
+ */ |
57 |
+ int |
58 |
+static int |
58 |
+pocl_cpuinfo_detect_max_clock_frequency() |
59 |
+pocl_cpuinfo_detect_max_clock_frequency() |
59 |
+{ |
60 |
+{ |
60 |
+ return 0; |
61 |
+ return -1; |
61 |
+} |
62 |
+} |
62 |
+#endif |
63 |
+#endif |
63 |
|
64 |
+ |
64 |
+#ifdef __linux__ |
65 |
+#ifdef __linux__ |
65 |
/** |
66 |
/** |
66 |
* Detects the number of parallel hardware threads supported by |
67 |
* Detects the number of parallel hardware threads supported by |
67 |
* the CPU by parsing the cpuinfo. |
68 |
* the CPU by parsing the cpuinfo. |
68 |
@@ -232,6 +281,19 @@ pocl_cpuinfo_detect_compute_unit_count() |
69 |
@@ -233,6 +283,20 @@ pocl_cpuinfo_detect_compute_unit_count() |
69 |
} |
|
|
70 |
return -1; |
70 |
return -1; |
71 |
} |
71 |
} |
|
|
72 |
|
72 |
+#else |
73 |
+#else |
73 |
+/** |
74 |
+/** |
74 |
+ * Detects the number of parallel hardware threads supported by |
75 |
+ * Detects the number of parallel hardware threads supported by |
Lines 76-107
Link Here
|
76 |
+ * |
77 |
+ * |
77 |
+ * @return The number of hardware threads. |
78 |
+ * @return The number of hardware threads. |
78 |
+ */ |
79 |
+ */ |
79 |
+ int |
80 |
+static int |
80 |
+pocl_cpuinfo_detect_compute_unit_count() |
81 |
+pocl_cpuinfo_detect_compute_unit_count() |
81 |
+{ |
82 |
+{ |
82 |
+ return sysconf(_SC_NPROCESSORS_ONLN); |
83 |
+ return sysconf(_SC_NPROCESSORS_ONLN); |
83 |
+} |
84 |
+} |
84 |
+#endif |
85 |
+#endif |
85 |
|
86 |
+ |
86 |
#ifdef POCL_ANDROID |
87 |
#ifdef POCL_ANDROID |
87 |
|
88 |
|
88 |
@@ -270,6 +332,7 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
89 |
#define SYSFS_CPU_NUM_CORES_NODE "/sys/devices/system/cpu/possible" |
|
|
90 |
@@ -326,6 +390,7 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
89 |
* short_name is in the .data anyways.*/ |
91 |
* short_name is in the .data anyways.*/ |
90 |
device->long_name = device->short_name; |
92 |
device->long_name = device->short_name; |
91 |
|
93 |
|
92 |
+#ifdef __linux__ |
94 |
+#ifdef __linux__ |
93 |
/* default vendor and vendor_id, in case it cannot be found by other means */ |
95 |
/* default vendor and vendor_id, in case it cannot be found by other means */ |
94 |
device->vendor = cpuvendor_default; |
96 |
device->vendor = cpuvendor_default; |
95 |
if (device->vendor_id == 0) |
97 |
if (device->vendor_id == 0) |
96 |
@@ -318,7 +381,25 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
98 |
@@ -425,6 +490,25 @@ pocl_cpuinfo_get_cpu_name_and_vendor(cl_ |
97 |
char *new_name = (char*)malloc (len); |
99 |
char *new_name = (char*)malloc (len); |
98 |
snprintf (new_name, len, "%s-%s", device->short_name, start); |
100 |
snprintf (new_name, len, "%s-%s", device->short_name, start); |
99 |
device->long_name = new_name; |
101 |
device->long_name = new_name; |
100 |
+#elif defined(HAVE_SYSCTL_H) |
102 |
+ #elif defined(HAVE_SYSCTL_H) |
101 |
+ int mib[2]; |
103 |
+ int mib[2]; |
102 |
+ size_t len = 0; |
104 |
+ size_t len = 0; |
103 |
+ char *model; |
105 |
+ char *model; |
104 |
|
106 |
+ |
105 |
+ mib[0] = CTL_HW; |
107 |
+ mib[0] = CTL_HW; |
106 |
+ mib[1] = HW_MODEL; |
108 |
+ mib[1] = HW_MODEL; |
107 |
+ if (sysctl(mib, 2, NULL, &len, NULL, 0)) |
109 |
+ if (sysctl(mib, 2, NULL, &len, NULL, 0)) |