FREDMPC Basic Tutorial
Start this tutorial by opening the following FRED file: <FRED Installation Directory>\Resources\Samples\Tutorials & Examples\FREDmpc_Basic_Tutorial.frd. After opening the file and expanding the object tree to reveal the elements in the Geometry folder, you should observe that the system consists only of an ideal lens element and a pipe object representing the lens housing. In order to use this model with FREDMPC, we will be adding a source representation, a detector entity and a directional analysis entity.
GPU Raytracing Modes
Before starting on the model additions, let us first discuss the two different modalities of GPU raytracing. An understanding of the basic differences between the GPU raytrace modes can affect the choices we make when constructing models appropriately for FREDMPC.
The two different modes of GPU raytracing are the following:
Completing the Model
In this tutorial we will use the "MPC Trace GPU Rays" mode described in the previous section, since this offers the best GPU performance. One limitation of this mode, as noted in the previous section, is that the source construction must obey specific rules in order for the source to be generated by the GPU.
The Sources section of the Supported Features itemizes specific source attributes and Source Primitive constructs that are supported by the GPUs. An inspection of that help topic will show that a Lambertian Plane type of Source Primitive with a single wavelength satisfies the GPU source creation requirements. In this example, we will create the Lambertian Plane type of Source Primitive as shown in the images below and it will be located at the global origin.
After configuring the source as shown above and clicking OK, you should see the source primitive appear as a new node in the Optical Sources folder and in the 3D view at the global origin.
When using the MPC Trace GPU Rays mode of operation, Irradiance and Intensity calculations are generated by inserting Detector Entities and Directional Analysis Entities into the model. Start by right mouse clicking on the Analysis Surface(s) folder to add a Plane type Detector Entity.
Specifically note that the CalcTiming parameter of the detector entity has been set to "During Trace". When the CalcTiming parameter is set to either "During Trace" or "At Trace End", the requested Irradiance calculation will be computed by the GPU and the resulting distribution will be stored as an Analysis Results Node (ARN) in the Analysis Results folder of the object tree at the end of the raytrace. We also note that while we aren't using them in this example, Ray Selection filters can also be applied to the Detector Entity and Directional Analysis Entity constructs.
After configuring the detector entity and pressing OK on the dialog, you should see the new object in the 3D view and as a new node within the Analysis Surface(s) folder of your object tree.
Next, we will add a Directional Analysis Entity construct in order to generate an Intensity distribution as part of the GPU raytrace. After the GPU raytrace finishes, an Analysis Results Node containing the results of the Intensity calculation will be generated and added to the Analysis Results folder of the object tree. Right mouse click on the Analysis Surface(s) folder to add a new Directional Analysis Entity.
Configure the Directional Analysis Entity to consider +/-15 deg in both Polar and Azimuthal directions, with 45 divisions for each, and then locate it in the coordinate system of the Detector Entity. The Ray Selection filter should be set to only consider rays that end up on the detector entity at the end of the raytrace.
After clicking OK, you should see the directional analysis entity appear in the 3D view. Note that the "rendering radius" is only for visual appearance and has no effect on the Intensity calculation itself, since the binning of the rays is performed purely in an angle space pixel grid.
At this point, the model construction is complete and we are ready to proceed with GPU raytracing.
Performing GPU Raytracing
The two standard GPU raytrace options, MPC Trace CPU Rays and MPC Trace GPU Rays can be accessed from both the toolbar and from the MPC menu item.
In this example, we have specifically configured our source model to be supported by the MPC Trace GPU Rays mode of raytracing. Selecting the toolbar button or MPC menu item for MPC Trace GPU Rays will trigger the following sequence of events: •The GPU device is initialized •The FRED model is loaded into the GPU device(s) •The raytrace pipeline is prepared •Rays are generated by the GPU •Rays are traced ("launched") by the GPU •The analysis data accumulated by the Detector Entity and Directional Analysis Entity are stored in analysis results nodes on the FRED tree at the end of the trace
GPU Device Initialization The GPU device needs to be initialized one time for each FRED document after that document has been opened. The initialization step occurs on the first request to load the document into the GPU and the process can sometimes take up to several minutes to complete for very complex models. However, device initialization information is automatically cached and generally will not occur again as long as the document remains open (and even between FRED sessions, in some cases). During the initialization process, various tasks are performed relating to database construction, buffer construction, loading node intersection routines, etc.
Note: It can be the case that for complex models the user will observe the status message similar to that shown below for some length of time (up to several minutes, for some models). During this step, CUDA code necessary to perform the GPU raytrace is being compiled. After the initial compilation is completed, this step will not be performed during subsequent raytrace calls.
Model Load The FRED model is not dynamically updated or maintained on the GPUs while the model is being edited. Model load happens automatically once the GPU raytrace is requested. The model load time varies depending on the contents of the FRED file, and the status bar will be updated to show the current step in the model loading process. A summary of the model load process is reported to the Output Window after this process has completed.
The sum total of the “memory (bytes)” column on the right hand side in the output window indicates how much memory on the GPU device is consumed by the model representation and can be compared to the “global memory” value reported by the $cudainfo command (GPU Hardware Configuration).
Raytrace In the Output Window, underneath the Document Load we see the progress of the GPU raytrace. Each group of 3 lines with the same <n> index detail a single batch of 1,048,576 rays being traced.
The figure above was generated with an RTX 3070 GPU Board and shows that the GPU raytrace and analysis of 10 million rays was completed in 0.65 seconds.
Viewing the Analysis Results The Irradiance and Intensity data is calculated during the GPU raytrace and automatically stored as Analysis Results Nodes (ARNs) in the Analysis Results folder of the Tree at the conclusion of the raytrace. In the screenshot below we see that there is one analysis results node corresponding to the detector entity and the directional analysis entity (the name of the ARNs corresponds to the name of the analysis construct that generated them).
Double click on an ARN in order to open the result and display it in a chart window. Below, we can see the results of the Irradiance calculation (Top) and Intensity calculation (Bottom).
As a data point for comparison, tracing the same model on the CPU (6 x core i7-10750H, 2.6GHz, 12 threads) takes about 5 seconds for source ray generation and another 5 seconds to perform the raytrace. In total, the MPC Trace GPU Rays mode is faster than the multi-threaded CPU on this simple model by a factor of (10 s / 0.65 s ) = 16x. For more complex model geometries and larger ray counts, the speed up factor will likely be significantly higher.
Using an Unsupported Source In the previous sections we used the Lambertian Plane type of Source Primitive because its specific construction is natively supported for ray generation directly on the GPUs themselves (see the Sources section of the Supported Features page) and we could therefore use the MPC Trace GPU Rays mode of operation. When a source is not natively supported by the GPUs, the MPC Trace CPU Rays mode of operation will be used in order to trace the rays from that source on the GPUs. The content that follows works through the addition of a source type that is unsupported by the GPUs for ray creation, how to identify this scenario from the information printed by FREDMPC in the output window, and how to perform the appropriate MPC Trace CPU Rays mode of GPU raytracing.
From the top menu, select File > Import > Import CAD and chose the file “Luxeon Z ES.stp” from the directory, <FRED Installation Directory>\Resources\Samples\Tutorials & Examples\. The STP file being imported is a CAD model of the geometry for a Luxeon LED that will be turned into an emitter.
On the import dialog, Select the option to set the Surface Drawing Mode to be Shaded surface, and click Create. Then, after the structure is imported, click Dismiss on the dialog. The LED structure is shown in the 2D View at the global origin.
Next, right mouse click on the source from the previous section, "Lambertian Plane 1", and toggle the Traceable option on the context menu to turn the source off. Then, create a new Lambertian Surface type of Source Primitive by right moues clicking on the Optical Sources folder and choosing, "Create New Source Primitive".
Configure the source dialog as shown below, making sure to specify surface "Geometry.luxeon z es.Fillet1 65 1.TrimSurf 209" for both the Emission Surface and the starting coordinate system for the source's Location/Orientation. The TrimSurf 209 surface is the emitting face of the LED. Once done, click OK.
Trace CPU Rays Mode First, lets attempt to use the MPC Trace GPU Rays mode with our new source by pressing the corresponding toolbar button (
This message indicates that the rays of this source can’t be generated directly on the GPU. So, we need to use the Trace CPU Rays mode in order to raytrace this source on the GPUs. Recall that in this mode of operation, the source rays are generated by the CPU, passed to the GPU for raytracing, and then passed back to the CPU ray buffer.
Click the MPC Trace CPU Rays button
After the CPU has finished generating the starting rayset, the GPU raytrace begins.
Notice that the Pre-launch and the Post-launch phases take longer than when we previously used the MPC Trace GPU Rays mode of operation. This additional time is the result of moving ray data between the CPU ray buffer and the GPU device before and after each block of rays is traced on the GPU. As in the previous case, the two detectors auto-create ARNs containing the calculated results that can be double-clicked to view the data in Chart.
In addition to allowing the raytrace of all source types, the MPC Trace CPU Rays mode has another significant advantage - ray data is available in the CPU ray buffer for post-processing. The user could, for example, add an Analysis Surface and calculate quantities such as the Positions Spot Diagram, or the Color Image. Or, even, use a script to loop over the rays and perform a customized analysis.
When to use FREDMPC Where the GPU raytrace will really pay dividends is when large ray counts are involved (tens of millions, hundreds of millions, billions), and also if a model contains lots of geometry elements (for example, imported CAD or triangle mesh objects). More discussions on this topic can be found on the Overview page.
Next: MPC Advanced Tutorial In the MPC Advanced Tutorial users will learn how to check that a more complex model is appropriately represented by FREDMPC and then modify the model to ensure that all properties and attributes are correctly represented on the GPU.
|