summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJeff Donahue <jeff.donahue@gmail.com>2014-08-05 16:01:11 -0700
committerJeff Donahue <jeff.donahue@gmail.com>2014-08-12 12:43:41 -0700
commit9572a68b8832a09f716017742fbd3b4f1da3d131 (patch)
tree48582d90d5cff5bb3c030a268a5eda6aff2cdd38 /scripts
parentdd883bdda70c11101badf194661770d7f358577c (diff)
downloadcaffeonacl-9572a68b8832a09f716017742fbd3b4f1da3d131.tar.gz
caffeonacl-9572a68b8832a09f716017742fbd3b4f1da3d131.tar.bz2
caffeonacl-9572a68b8832a09f716017742fbd3b4f1da3d131.zip
Add caffe/alt_fn rule to lint checks to check for functions (like memset
& memcpy) with caffe_* alternatives that should be used instead.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cpp_lint.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/cpp_lint.py b/scripts/cpp_lint.py
index 3f80e723..61b8b0cd 100755
--- a/scripts/cpp_lint.py
+++ b/scripts/cpp_lint.py
@@ -154,6 +154,7 @@ _ERROR_CATEGORIES = [
'build/namespaces',
'build/printf_format',
'build/storage_class',
+ 'caffe/alt_fn',
'caffe/random_fn',
'legal/copyright',
'readability/alt_tokens',
@@ -1559,6 +1560,37 @@ def CheckForMultilineCommentsAndStrings(filename, clean_lines, linenum, error):
'Use C++11 raw strings or concatenation instead.')
+caffe_alt_function_list = (
+ ('memset', ['caffe_set', 'caffe_memset']),
+ ('cudaMemset', ['caffe_gpu_set', 'caffe_gpu_memset']),
+ ('memcpy', ['caffe_copy', 'caffe_memcpy']),
+ ('cudaMemcpy', ['caffe_copy', 'caffe_gpu_memcpy']),
+ )
+
+
+def CheckCaffeAlternatives(filename, clean_lines, linenum, error):
+ """Checks for C(++) functions for which a Caffe substitute should be used.
+
+ For certain native C functions (memset, memcpy), there is a Caffe alternative
+ which should be used instead.
+
+ Args:
+ filename: The name of the current file.
+ clean_lines: A CleansedLines instance containing the file.
+ linenum: The number of the line to check.
+ error: The function to call with any errors found.
+ """
+ line = clean_lines.elided[linenum]
+ for function, alts in caffe_alt_function_list:
+ ix = line.find(function + '(')
+ if ix >= 0 and (ix == 0 or (not line[ix - 1].isalnum() and
+ line[ix - 1] not in ('_', '.', '>'))):
+ disp_alts = ['%s(...)' % alt for alt in alts]
+ error(filename, linenum, 'caffe/alt_fn', 2,
+ 'Use Caffe function %s instead of %s(...).' %
+ (' or '.join(disp_alts), function))
+
+
c_random_function_list = (
'rand(',
'rand_r(',
@@ -4560,6 +4592,7 @@ def ProcessLine(filename, file_extension, clean_lines, line,
CheckForNonStandardConstructs(filename, clean_lines, line,
nesting_state, error)
CheckVlogArguments(filename, clean_lines, line, error)
+ CheckCaffeAlternatives(filename, clean_lines, line, error)
CheckCaffeRandom(filename, clean_lines, line, error)
CheckPosixThreading(filename, clean_lines, line, error)
CheckInvalidIncrement(filename, clean_lines, line, error)