Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56379 - in sandbox/numeric_bindings/libs/numeric/bindings/tools: . templates
From: rutger_at_[hidden]
Date: 2009-09-25 03:39:29


Author: rutger
Date: 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
New Revision: 56379
URL: http://svn.boost.org/trac/boost/changeset/56379

Log:
updated cblas and cublas parsers

Added:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/cblas.py (contents, props changed)
   sandbox/numeric_bindings/libs/numeric/bindings/tools/cublas.py (contents, props changed)
Text files modified:
   sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py | 37 ++++++++++++++++++++++++++++++++-----
   sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py | 4 ++--
   sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py | 2 +-
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp | 24 +++++++++++++++++++++---
   sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/lapack.hpp | 2 +-
   5 files changed, 57 insertions(+), 12 deletions(-)

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/blas_generator.py 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 #
 # Copyright (c) 2008 Thomas Klimpel and Rutger ter Borg
 #
@@ -9,6 +10,8 @@
 
 import netlib
 import bindings
+import cblas
+import cublas
 
 import re, os.path, copy
 from types import StringType
@@ -51,7 +54,6 @@
     includes = [
       '#include <boost/numeric/bindings/traits/traits.hpp>',
       '#include <boost/numeric/bindings/traits/type_traits.hpp>',
- '#include <boost/numeric/bindings/blas/detail/blas.h>',
       '#include <boost/mpl/bool.hpp>',
       '#include <boost/type_traits/is_same.hpp>',
       '#include <boost/static_assert.hpp>' ]
@@ -68,12 +70,28 @@
       # add the argument list here
       arg_list = []
       lapack_arg_list = []
+ cblas_arg_list = []
       for arg in info_map[ subroutine ][ 'arguments' ]:
+ print "Subroutine ", subroutine, " arg ", arg
         arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'level_0' ] ]
- lapack_arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'call_c_header' ] ]
+ lapack_arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'call_blas_header' ] ]
+ cblas_arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'call_cblas_header' ] ]
       sub_template = sub_template.replace( "$LEVEL0", ", ".join( arg_list ) )
- sub_template = sub_template.replace( "$CALL_C_HEADER", ", ".join( lapack_arg_list ) )
+ sub_template = sub_template.replace( "$CALL_BLAS_HEADER", ", ".join( lapack_arg_list ) )
+ sub_template = sub_template.replace( "$CALL_CBLAS_HEADER", ", ".join( cblas_arg_list ) )
       sub_template = sub_template.replace( "$SUBROUTINE", subroutine )
+ if 'cblas_routine' in info_map[ subroutine ]:
+ cblas_routine = info_map[ subroutine ][ 'cblas_routine' ]
+ else:
+ cblas_routine = '//TODO'
+ sub_template = sub_template.replace( "$CBLAS_ROUTINE", cblas_routine )
+
+ if 'cublas_routine' in info_map[ subroutine ]:
+ cublas_routine = info_map[ subroutine ][ 'cublas_routine' ]
+ else:
+ cublas_routine = '//TODO'
+ sub_template = sub_template.replace( "$CUBLAS_ROUTINE", cublas_routine )
+
       sub_template = sub_template.replace( '$groupname', group_name.lower() )
       sub_template = sub_template.replace( '$RETURN_TYPE', info_map[ subroutine ][ 'return_value_type' ] )
       sub_template = sub_template.replace( '$RETURN_STATEMENT', info_map[ subroutine ][ 'return_statement' ] )
@@ -291,10 +309,16 @@
   return result
 
 lapack_src_path = './blas-1.2/src'
+cblas_h_path = './blas-1.2/cblas/src/cblas.h'
+cublas_h_path = './cublas.h'
 template_src_path = './templates'
 bindings_target_path = '../../../../boost/numeric/bindings/blas/'
 test_target_path = '../test/lapack/'
 
+# Unable to find zdrot in cblas.h and cublas.h
+# Unable to find crotg, csrot, in cblas.h
+skip_blas_files = [ 'zdrot.f', 'crotg.f', 'zrotg.f', 'csrot.f' ]
+
 templates = {}
 templates[ 'PARSERMODE' ] = 'BLAS'
 for root, dirs, files in os.walk( template_src_path ):
@@ -308,13 +332,16 @@
 function_info_map = {}
 for lapack_file in os.listdir( lapack_src_path ):
   right_file = re.compile( '^[cdsz].+\.f$' )
- if right_file.match( lapack_file ) != None:
+ if right_file.match( lapack_file ) != None and lapack_file not in skip_blas_files:
     print "Parsing", lapack_file, "..."
     key, value = netlib.parse_file( os.path.join( lapack_src_path, lapack_file ), templates )
     if key != None and value != None:
- print "Adding LAPACK subroutine", key
+ print "Adding BLAS subroutine", key
       function_info_map[ key ] = value
 
+cblas.parse_file( cblas_h_path, function_info_map, templates )
+cublas.parse_file( cublas_h_path, function_info_map, templates )
+
 print "Grouping subroutines..."
 
 value_type_groups = {}

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/cblas.py
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/cblas.py 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -0,0 +1,81 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2009 Rutger ter Borg
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import netlib
+
+import re, os.path, copy
+from types import StringType
+
+# for debugging purposes
+import pprint
+
+def parse_file( filename, info_map, template_map ):
+ pp = pprint.PrettyPrinter( indent = 2 )
+ source = open( filename ).read()
+
+ for match in re.compile( '(void|float|double) +cblas_([^\(]+)\(([^\)]+)\)', re.M | re.S ).findall( source ):
+ return_type = match[0]
+ blas_routine = match[1].split("_sub")[0].upper().strip()
+ print "CBLAS routine: ", blas_routine
+ arguments = {}
+ for arg in match[2].replace('\n','').split( ',' ):
+ arg = arg.strip()
+ arg_name = arg.split( " " )[-1].replace( "*", "" ).strip().upper()
+ arguments[ arg_name ] = {}
+ arguments[ arg_name ][ "original" ] = arg
+ arguments[ arg_name ][ "pointer" ] = "*" in arg
+
+ pp.pprint( arguments )
+
+ if blas_routine in info_map:
+ print "Found ", blas_routine, " in Fortran info_map."
+ info_map[ blas_routine ][ "cblas_routine" ] = 'cblas_' + match[1]
+
+ # read aliases, if they are there
+ my_key = blas_routine[ 1: ].lower() + '.all.cblas_alias'
+ alias_map = {}
+ print my_key
+ if netlib.my_has_key( my_key, template_map ) != None:
+ print "Has key.."
+ for line in template_map[ netlib.my_has_key( my_key, template_map ) ].splitlines():
+ print "Line:", line
+ alias_map[ line.split( "," )[0] ] = line.split(",")[1]
+
+ print alias_map
+
+ # Try to match and insert arguments
+ for arg in info_map[ blas_routine ][ 'argument_map' ]:
+ cblas_arg = ''
+ if arg in arguments:
+ cblas_arg = arg
+ if arg in alias_map:
+ if alias_map[ arg ] in arguments:
+ cblas_arg = alias_map[ arg ]
+ print "Looking for argument ", arg, " CBLAS equivalent: ", cblas_arg
+ if cblas_arg in arguments:
+ print "Found matching argument, inserting call_cblas_header stuff"
+ call_cblas_header = info_map[ blas_routine ][ "argument_map" ][ arg ][ "code" ][ "call_blas_header" ]
+ print "Original: ", call_cblas_header
+ if not arguments[ cblas_arg ][ "pointer" ]:
+ call_cblas_header = call_cblas_header.replace( "&", "" )
+
+ call_cblas_header = call_cblas_header.replace( "complex_ptr", "void_ptr" );
+
+ print "Result: ", call_cblas_header
+ info_map[ blas_routine ][ "argument_map" ][ arg ][ "code" ][ "call_cblas_header" ] = call_cblas_header
+ else:
+ exit(0)
+
+
+
+
+
+
+

Added: sandbox/numeric_bindings/libs/numeric/bindings/tools/cublas.py
==============================================================================
--- (empty file)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/cublas.py 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2009 Rutger ter Borg
+#
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+#
+
+import re, os.path, copy
+from types import StringType
+
+# for debugging purposes
+import pprint
+
+def parse_file( filename, info_map, template_map ):
+ pp = pprint.PrettyPrinter( indent = 2 )
+ source = open( filename ).read()
+
+ for match in re.compile( '(float|double|void) ?CUBLASAPI ?cublas([SDCZ][a-z0-9]+) ?\(([^\(]+)\(([^\)]+)\)', re.M | re.S ).findall( source ):
+ blas_routine = match[1].upper()
+
+ if blas_routine in info_map:
+ print "FOUND!"
+ info_map[ blas_routine ][ "cublas_routine" ] = 'cublas' + match[1]
+ pp.pprint( info_map[ blas_routine ] )
+
+ #print blas_routine
+ #print match[0], match[1]
+
+ #print match
+
+
+
+
+
+
+ #print info_map.keys
+
+
+ #print source
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#parse_file( "./cublas.h", dict() )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/lapack_generator.py 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -78,9 +78,9 @@
       lapack_arg_list = []
       for arg in info_map[ subroutine ][ 'arguments' ]:
         arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'level_0' ] ]
- lapack_arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'call_c_header' ] ]
+ lapack_arg_list += [ info_map[ subroutine ][ 'argument_map' ][ arg ][ 'code' ][ 'call_blas_header' ] ]
       sub_template = sub_template.replace( "$LEVEL0", ", ".join( arg_list ) )
- sub_template = sub_template.replace( "$CALL_C_HEADER", ", ".join( lapack_arg_list ) )
+ sub_template = sub_template.replace( "$CALL_BLAS_HEADER", ", ".join( lapack_arg_list ) )
       sub_template = sub_template.replace( "$SUBROUTINE", subroutine )
       sub_template = sub_template.replace( '$groupname', group_name.lower() )
       

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/netlib.py 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -1218,7 +1218,7 @@
   for argument_name, argument_properties in argument_map.iteritems():
     argument_properties[ 'code' ] = {}
     argument_properties[ 'code' ][ 'lapack_h' ] = c_type( argument_name, argument_properties )
- argument_properties[ 'code' ][ 'call_c_header' ] = call_c_type( argument_name, argument_properties )
+ argument_properties[ 'code' ][ 'call_blas_header' ] = call_c_type( argument_name, argument_properties )
     argument_properties[ 'code' ][ 'level_0' ] = cpp_type( argument_name, argument_properties )
     argument_properties[ 'code' ][ 'call_level_0' ] = call_level0_type( argument_name, argument_properties, argument_map )
     argument_properties[ 'code' ][ 'level_1' ] = level1_type( argument_name, argument_properties )

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/blas.hpp 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -15,6 +15,15 @@
 #ifndef BOOST_NUMERIC_BINDINGS_BLAS_$DIRNAME_$GROUPNAME_HPP
 #define BOOST_NUMERIC_BINDINGS_BLAS_$DIRNAME_$GROUPNAME_HPP
 
+// Include header of configured BLAS interface
+#if defined BOOST_NUMERIC_BINDINGS_BLAS_CBLAS
+#include <boost/numeric/bindings/blas/detail/cblas.h>
+#elif defined BOOST_NUMERIC_BINDINGS_BLAS_CUBLAS
+#include <boost/numeric/bindings/blas/detail/cublas.h>
+#else
+#include <boost/numeric/bindings/blas/detail/blas.h>
+#endif
+
 $INCLUDES
 
 namespace boost {
@@ -22,10 +31,13 @@
 namespace bindings {
 namespace blas {
 
-// overloaded functions to call blas
+// The detail namespace is used for overloads on value type,
+// and to dispatch to the right routine
+
 namespace detail {
 
-$OVERLOADS} // namespace detail
+$OVERLOADS
+} // namespace detail
 
 $LEVEL1
 $LEVEL2
@@ -37,7 +49,13 @@
 #endif
 $TEMPLATE[blas_overloads]
 inline $RETURN_TYPE $groupname( $LEVEL0 ) {
- $RETURN_STATEMENTBLAS_$SUBROUTINE( $CALL_C_HEADER );
+#if defined BOOST_NUMERIC_BINDINGS_BLAS_CBLAS
+ $RETURN_STATEMENT$CBLAS_ROUTINE( $CALL_CBLAS_HEADER );
+#elif defined BOOST_NUMERIC_BINDINGS_BLAS_CUBLAS
+ $RETURN_STATEMENT$CUBLAS_ROUTINE( ... ); // FIXME
+#else
+ $RETURN_STATEMENTBLAS_$SUBROUTINE( $CALL_BLAS_HEADER );
+#endif
 }
 
 $TEMPLATE[blas_level1]

Modified: sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/lapack.hpp
==============================================================================
--- sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/lapack.hpp (original)
+++ sandbox/numeric_bindings/libs/numeric/bindings/tools/templates/lapack.hpp 2009-09-25 03:39:28 EDT (Fri, 25 Sep 2009)
@@ -39,7 +39,7 @@
 #endif
 $TEMPLATE[lapack_overloads]
 inline void $groupname( $LEVEL0 ) {
- LAPACK_$SUBROUTINE( $CALL_C_HEADER );
+ LAPACK_$SUBROUTINE( $CALL_BLAS_HEADER );
 }
 
 $TEMPLATE[level1_pre_header]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk