forked from libxsmm/parlooper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_utils.h
67 lines (62 loc) · 1.77 KB
/
common_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/******************************************************************************
* Copyright (c) Intel Corporation - All rights reserved. *
* This file is part of the LIBXSMM library. *
* *
* For information on the license, see the LICENSE file. *
* Further information: https://github.com/libxsmm/libxsmm/ *
* SPDX-License-Identifier: BSD-3-Clause *
******************************************************************************/
#include <stdio.h>
#include <array>
#include <cassert>
#include <fstream>
#include <initializer_list>
#include <iostream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <functional>
#include <omp.h>
#include "jit_compile.h"
#include "par_loop_cost_estimator.h"
#include "par_loop_generator.h"
#include "threaded_loops.h"
#include <cstring>
#include <unistd.h>
#include <libxsmm.h>
#include <dnn_common.h>
double ifreq;
static __inline__ unsigned long long rdtsc(void) {
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}
inline double getFreq() {
long long int s = rdtsc();
sleep(1);
long long int e = rdtsc();
return (e - s) * 1.0;
}
inline double getTime() {
return rdtsc() * ifreq;
}
void find_prime_factors(long num, std::vector<long>& res) {
long n = num;
if (n == 1) {
res.push_back(n);
}
while (n % 2 == 0) {
res.push_back(2);
n = n/2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
res.push_back(i);
n = n/i;
}
}
if (n > 2) {
res.push_back(n);
}
return;
}