Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:48:48

0001 #!/usr/bin/env python
0002 #
0003 # Copyright (c) 2019 Opticks Team. All Rights Reserved.
0004 #
0005 # This file is part of Opticks
0006 # (see https://bitbucket.org/simoncblyth/opticks).
0007 #
0008 # Licensed under the Apache License, Version 2.0 (the "License"); 
0009 # you may not use this file except in compliance with the License.  
0010 # You may obtain a copy of the License at
0011 #
0012 #   http://www.apache.org/licenses/LICENSE-2.0
0013 #
0014 # Unless required by applicable law or agreed to in writing, software 
0015 # distributed under the License is distributed on an "AS IS" BASIS, 
0016 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
0017 # See the License for the specific language governing permissions and 
0018 # limitations under the License.
0019 #
0020 
0021 
0022 import os, sys, numpy as np
0023 from collections import OrderedDict as odict 
0024 
0025 decode_ = lambda v:"".join(map( lambda c:str(unichr(c)), filter(None,map(lambda i:(int(v) >> i*8) & 0xff, range(8))) ))
0026 
0027 
0028 class NGPU(object):
0029     def __init__(self, path):
0030         a = np.load(os.path.expandvars(path))
0031         d = odict()
0032         tot_bytes = 0
0033         for i in range(len(a)):
0034             name, owner, note = map(decode_, a[i,:3])
0035             loc = "/".join([name, owner, note])
0036             num_bytes = a[i,3]
0037             d[loc] = num_bytes 
0038             tot_bytes += num_bytes
0039         pass
0040         self.d = d 
0041         self.a = a 
0042         self.tot_bytes = tot_bytes
0043         self.path = path 
0044 
0045     def __str__(self):
0046         return "\n".join([" %30s : %s " % (k,self.brief(k)) for k, v in self.d.items()]) 
0047     def __repr__(self):
0048         return "%10d : %15d : %6.2f : %s " % ( len(self.d), self.tot_bytes, float(self.tot_bytes)/1e6, self.path  )  
0049 
0050     def brief(self, loc):
0051         nb = self.d.get(loc, -1)
0052         return " %15d : %6.2f  " % ( nb, float(nb)/1e6 ) if nb > -1 else ""
0053 
0054     def index(self, loc):
0055         return self.d.keys().index(loc) if self.d.has_key(loc) else -1 
0056 
0057 
0058 
0059 if __name__ == '__main__':
0060 
0061      #a_name = "OKTest"
0062      a_name = "OTracerTest"
0063      b_name = "OKX4Test"
0064  
0065      a_path = sys.argv[1] if len(sys.argv) > 1 else "$TMP/%s_GPUMon.npy" % a_name
0066      b_path = sys.argv[2] if len(sys.argv) > 2 else "$TMP/%s_GPUMon.npy" % b_name
0067      
0068      a = NGPU(a_path)
0069      b = NGPU(b_path)
0070 
0071      print repr(a)
0072      print repr(b)
0073 
0074      locs = set(a.d.keys()).union(set(b.d.keys()))
0075 
0076      fmt = " %30s :  %30s  :  %30s   "
0077      print fmt % ( len(locs) , a_path , b_path )  
0078      for loc in sorted(locs, key=lambda loc:max(a.index(loc), b.index(loc))):
0079          print fmt % ( loc, a.brief(loc),  b.brief(loc) ) 
0080      pass
0081 
0082 
0083 
0084