Back to home page

EIC code displayed by LXR

 
 

    


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

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 """
0023 import numpy as np, math 
0024 import matplotlib.pyplot as plt
0025 from matplotlib.patches import Rectangle, Circle, Ellipse, PathPatch
0026 
0027 
0028 def make_rect(xy , wh, **kwa ):
0029     """
0030     :param xy: center of rectangle
0031     :param wh: halfwidth, halfheight
0032     """
0033     ll = ( xy[0] - wh[0], xy[1] - wh[1] )
0034     return Rectangle( ll,  2.*wh[0], 2.*wh[1], **kwa  )
0035 
0036 def rep0(ax, sz, N, x):
0037     for i in range(N):
0038         r = make_rect( [x,(i-N/2)], sz )
0039         ax.add_patch(r) 
0040     pass
0041 
0042 def rep1(ax, sz, N, x):
0043     r = make_rect( [x,0], [sz[0],N/2] )
0044     ax.add_patch(r) 
0045     pass
0046 
0047 
0048 
0049 def try0(ax):
0050 
0051 
0052     #gpu = False
0053     gpu = True
0054 
0055     sy = 4000 if gpu else 10  
0056     sx = sy
0057 
0058     ax.set_ylim([-sy,sy])
0059     ax.set_xlim([-sx,sx])
0060 
0061     xx = [-sx*0.9,-sx*0.5,0]
0062     cc = [1,8,16]
0063 
0064     if gpu:
0065         xx.append(sx*0.5)
0066         cc.append(5120)
0067     pass
0068 
0069     sz = [sx*0.1,sx*0.1]
0070 
0071     for i in range(len(xx)):
0072         rep0(ax, sz, cc[i], xx[i])
0073     pass
0074 
0075 
0076 def try1(ax):
0077 
0078     r = make_rect( [-9,0], [1,1] )
0079     ax.add_patch(r)   
0080 
0081     r = make_rect( [-5,0], [1,4] )
0082     ax.add_patch(r)   
0083 
0084     r = make_rect( [ 0,0], [1,8] )
0085     ax.add_patch(r)   
0086 
0087     r = make_rect( [ 5,0], [1,5120] )
0088     ax.add_patch(r)   
0089 
0090 
0091 def try2(ax):
0092 
0093 
0094     # sy = 3000
0095     #sx = 10 
0096 
0097     ax.set_ylim([0,6000])
0098     ax.set_xlim([0,16])
0099 
0100 
0101     #ax.set_yscale('log')
0102 
0103     x = np.arange(0,13)
0104     y = np.power(2,x)
0105 
0106     plt.plot( x, y , drawstyle="steps-mid")
0107     
0108     plt.plot( [0,14], [5120,5120] )
0109     plt.annotate( "5120 CUDA cores", xy=[0,5120+100] )
0110 
0111     plt.plot( [x[4]], [y[4]], marker="*") 
0112 
0113     plt.plot( [0,14], [16,16] )
0114     plt.annotate( "16 CPU cores", xy=[0,16+100] )
0115 
0116 
0117 
0118 
0119 if __name__ == "__main__":
0120 
0121     plt.ion()
0122     fig = plt.figure(figsize=(6,5.5))
0123     plt.title("\"Shape\" of CPU vs GPU ")
0124 
0125     ax = fig.add_subplot(111)
0126 
0127     s = 1.4
0128 
0129     v0 = 5120.
0130     qv0 = np.sqrt(v0)
0131     ax.set_ylim([-s*qv0, s*qv0])
0132     ax.set_xlim([-s*qv0, s*qv0])
0133 
0134 
0135     c0 = Circle( [0,0], radius=qv0 )
0136     ax.add_patch(c0)
0137     plt.annotate( "Area ~ 5120", xy=[0,0], horizontalalignment='center', fontsize=16 )
0138 
0139     v1 = 16 
0140     qv1 = np.sqrt(v1)
0141     c1 = Circle( [0, qv0+10], radius=qv1 )
0142     ax.add_patch(c1)
0143     plt.annotate( "Area ~ 16", xy=[0, qv0+15], horizontalalignment='center', fontsize=16 )
0144 
0145 
0146     v2 = 1 
0147     qv2 = np.sqrt(v2)
0148     c2 = Circle( [0, -(qv0+10)], radius=qv2 )
0149     ax.add_patch(c2)
0150     plt.annotate( "Area ~ 1", xy=[0, -(qv0+20)], horizontalalignment='center', fontsize=16 )
0151 
0152 
0153 
0154 
0155 
0156     fig.show()
0157