Newer
Older
# Radiation of disc : BlackBody or Monochromatic
BlackBody = False
# Size of image
# No output as image
NoImage = False
# Threads in CUDA
Threads = 32
# Trackpoints of trajectories
TrackSave = False
HowToUse = "%s -h [Help] -b [BlackBodyEmission] -j [TrackSave] -n [NoImage] -p <Einstein/Newton> -s <SizeInPixels> -m <Mass> -i <DiscInternalRadius> -x <DiscExternalRadius> -a <AngleAboveDisc> -d <DeviceId> -c <Greyscale/Red2Yellow> -g <CUDA/OpenCL> -o <EachPixel/TrajectoCircle/TrajectoPixel/EachCircle/Original> -t <ThreadsInCuda> -v <FP32/FP64> -k <TrackPoints>" # noqa: E501
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
opts, args = getopt.getopt(
sys.argv[1:],
"hbnjs:m:i:x:a:d:g:v:o:t:c:p:k:",
[
"tracksave",
"blackbody",
"noimage",
"camera",
"size=",
"mass=",
"internal=",
"external=",
"angle=",
"device=",
"gpustyle=",
"variabletype=",
"method=",
"threads=",
"colors=",
"physics=",
"trackpoints=",
],
)
except getopt.GetoptError:
print(HowToUse % sys.argv[0])
sys.exit(2)
# List of Devices
print("\nInformations about devices detected under OpenCL API:")
# For PyOpenCL import
try:
for platform in cl.get_platforms():
for device in platform.get_devices():
# deviceType=cl.device_type.to_string(device.type)
deviceType = "xPU"
print(
"Device #%i from %s of type %s : %s"
% (
Id,
platform.vendor.lstrip(),
deviceType,
device.name.lstrip(),
)
)
Id = Id + 1
except Exception:
print("Your platform does not seem to support OpenCL")
print("\nInformations about devices detected under CUDA API:")
cuda.init()
for Id in range(cuda.Device.count()):
device = cuda.Device(Id)
print("Device #%i of type GPU : %s" % (Id, device.name()))
# Devices.append(int(arg))
Device = int(arg)
elif opt in ("-g", "--gpustyle"):
GpuStyle = arg
elif opt in ("-v", "--variabletype"):
VariableType = arg
elif opt in ("-s", "--size"):
Size = int(arg)
elif opt in ("-k", "--trackpoints"):
TrackPoints = int(arg)
elif opt in ("-m", "--mass"):
Mass = float(arg)
elif opt in ("-i", "--internal"):
InternalRadius = float(arg)
elif opt in ("-e", "--external"):
ExternalRadius = float(arg)
elif opt in ("-a", "--angle"):
Angle = numpy.pi / 180.0 * (90.0 - float(arg))
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
elif opt in ("-b", "--blackbody"):
BlackBody = True
elif opt in ("-j", "--tracksave"):
TrackSave = True
elif opt in ("-n", "--noimage"):
NoImage = True
elif opt in ("-o", "--method"):
Method = arg
elif opt in ("-t", "--threads"):
Threads = int(arg)
elif opt in ("-c", "--colors"):
Colors = arg
elif opt in ("-p", "--physics"):
Physics = arg
print("Device Identification selected : %s" % Device)
print("GpuStyle used : %s" % GpuStyle)
print("VariableType : %s" % VariableType)
print("Size : %i" % Size)
print("Mass : %f" % Mass)
print("Internal Radius : %f" % InternalRadius)
print("External Radius : %f" % ExternalRadius)
print("Angle with normal of (in radians) : %f" % Angle)
print("Black Body Disc Emission (monochromatic instead) : %s" % BlackBody)
print("Method of resolution : %s" % Method)
print("Colors for output images : %s" % Colors)
print("Physics used for Trajectories : %s" % Physics)
print("Trackpoints of Trajectories : %i" % TrackPoints)
print("Tracksave of Trajectories : %i" % TrackSave)
if GpuStyle == "CUDA":
print("\nSelection of CUDA device")
try:
# For PyCUDA import
import pycuda.driver as cuda
cuda.init()
for Id in range(cuda.Device.count()):
device = cuda.Device(Id)
print("Device #%i of type GPU : %s" % (Id, device.name()))
except ImportError:
print("Platform does not seem to support CUDA")
if GpuStyle == "OpenCL":
print("\nSelection of OpenCL device")
try:
# For PyOpenCL import
import pyopencl as cl
for platform in cl.get_platforms():
for device in platform.get_devices():
# deviceType=cl.device_type.to_string(device.type)
deviceType = "xPU"
print(
"Device #%i from %s of type %s : %s"
% (
Id,
platform.vendor.lstrip().rstrip(),
deviceType,
device.name.lstrip().rstrip(),
)
)
# Set the Alu as detected Device Type
Alu[Id] = deviceType
Id = Id + 1
except ImportError:
print("Platform does not seem to support OpenCL")
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
zImage = numpy.zeros((Size, Size), dtype=numpy.float32)
fImage = numpy.zeros((Size, Size), dtype=numpy.float32)
InputCL = {}
InputCL["Device"] = Device
InputCL["GpuStyle"] = GpuStyle
InputCL["VariableType"] = VariableType
InputCL["Size"] = Size
InputCL["Mass"] = Mass
InputCL["InternalRadius"] = InternalRadius
InputCL["ExternalRadius"] = ExternalRadius
InputCL["Angle"] = Angle
InputCL["BlackBody"] = BlackBody
InputCL["Method"] = Method
InputCL["TrackPoints"] = TrackPoints
InputCL["Physics"] = Physics
InputCL["Threads"] = Threads
InputCL["NoImage"] = NoImage
InputCL["TrackSave"] = TrackSave
if GpuStyle == "OpenCL":
duration = BlackHoleCL(zImage, fImage, InputCL)
duration = BlackHoleCUDA(zImage, fImage, InputCL)
Hostname = gethostname()
Date = time.strftime("%Y%m%d_%H%M%S")
ImageInfo = "%s_Device%i_%s_%s" % (Method, Device, Hostname, Date)
ImageOutput(zImage, "TrouNoirZ_%s" % ImageInfo, Colors)
ImageOutput(fImage, "TrouNoirF_%s" % ImageInfo, Colors)