Skip to content

Commit

Permalink
Fix lint, temporary add amaga back (apache#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
tqchen committed May 26, 2018
1 parent 8d0ffe3 commit cc8923e
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 3 deletions.
2 changes: 2 additions & 0 deletions nnvm/amalgamation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nnvm.d
nnvm.cc
32 changes: 32 additions & 0 deletions nnvm/amalgamation/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export NNVM_ROOT=`pwd`/..
export CFLAGS = -std=c++11 -Wall -O2 -Iinclude -fPIC

ifdef DMLC_CORE_PATH
CFLAGS += -I$(DMLC_CORE_PATH)/include
else
CFLAGS += -I$(CURDIR)/../dmlc-core/include
endif

.PHONY: all clean

all: libnnvm.a

nnvm.cc:
python generate.py $@

nnvm.d: nnvm.cc
${CXX} ${CFLAGS} -M -MT nnvm.o \
-I ${NNVM_ROOT}/ -I ${NNVM_ROOT}/include \
-D__MIN__=$(MIN) $+ > nnvm.d

nnvm-all.cc: nnvm.d nnvm.cc
python ./amalgamation.py $+ $@

nnvm-all.o: nnvm-all.cc
${CXX} ${CFLAGS} -fPIC -o $@ -c $+

libnnvm.a: nnvm-all.o
ar rcs $@ $+

clean:
rm -f *.d *.o *.so *.a nnvm-all.cc nnvm.cc
1 change: 1 addition & 0 deletions nnvm/amalgamation/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder is deprecated and will be deleted in the future.
100 changes: 100 additions & 0 deletions nnvm/amalgamation/amalgamation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import sys
import os.path, re, StringIO

blacklist = [
'Windows.h',
'mach/clock.h', 'mach/mach.h',
'malloc.h',
'glog/logging.h', 'io/azure_filesys.h', 'io/hdfs_filesys.h', 'io/s3_filesys.h',
'sys/stat.h', 'sys/types.h',
'omp.h', 'execinfo.h', 'packet/sse-inl.h'
]


def get_sources(def_file):
sources = []
files = []
visited = set()
mxnet_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), os.pardir))
for line in open(def_file):
files = files + line.strip().split(' ')

for f in files:
f = f.strip()
if not f or f.endswith('.o:') or f == '\\': continue
fn = os.path.relpath(f)
if os.path.abspath(f).startswith(mxnet_path) and fn not in visited:
sources.append(fn)
visited.add(fn)
return sources

sources = get_sources(sys.argv[1])

def find_source(name, start):
candidates = []
for x in sources:
if x == name or x.endswith('/' + name): candidates.append(x)
if not candidates: return ''
if len(candidates) == 1: return candidates[0]
for x in candidates:
if x.split('/')[1] == start.split('/')[1]: return x
return ''


re1 = re.compile('<([./a-zA-Z0-9_-]*)>')
re2 = re.compile('"([./a-zA-Z0-9_-]*)"')

sysheaders = []
history = set([])
out = StringIO.StringIO()

def expand(x, pending):
if x in history and x not in ['mshadow/mshadow/expr_scalar-inl.h']: # MULTIPLE includes
return

if x in pending:
#print 'loop found: %s in ' % x, pending
return

print >>out, "//===== EXPANDING: %s =====\n" %x
for line in open(x):
if line.find('#include') < 0:
out.write(line)
continue
if line.strip().find('#include') > 0:
print line
continue
m = re1.search(line)
if not m: m = re2.search(line)
if not m:
print line + ' not found'
continue
h = m.groups()[0].strip('./')
source = find_source(h, x)
if not source:
if (h not in blacklist and
h not in sysheaders and
'mkl' not in h and
'nnpack' not in h): sysheaders.append(h)
else:
expand(source, pending + [x])
print >>out, "//===== EXPANDED: %s =====\n" %x
history.add(x)


expand(sys.argv[2], [])

f = open(sys.argv[3], 'wb')



for k in sorted(sysheaders):
print >>f, "#include <%s>" % k

print >>f, ''
print >>f, out.getvalue()

for x in sources:
if x not in history and not x.endswith('.o'):
print 'Not processed:', x

18 changes: 18 additions & 0 deletions nnvm/amalgamation/generate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import sys

FOLDERS = ["core", "pass", "c_api"]

fo = open(sys.argv[1], "w")



for folder in FOLDERS:
path = str(os.path.join("../src", folder))
flst = os.listdir(path)
for f in flst:
if f.endswith(".cc") == True:
fo.write('#include "' + str(os.path.join("src", folder, f)) + '"\n')


fo.close()
5 changes: 2 additions & 3 deletions nnvm/include/nnvm/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,13 @@ struct hash<nnvm::TShape> {

namespace dmlc {
// avoid low version of MSVC
#if !defined(_MSC_VER) || _MSC_VER >= 1900
#if !defined(_MSC_VER)
template<typename T>
struct type_name_helper<nnvm::Tuple<T> > {
static inline std::string value() {
return "tuple of <" + type_name<T>() + ">";
}
};
#endif
}

} // namespace dmlc
#endif // NNVM_TUPLE_H_

0 comments on commit cc8923e

Please sign in to comment.