Difference between revisions of "Iced Cakes Pipeline"

From CSE231 Wiki
Jump to navigation Jump to search
 
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=Where To Start=
+
[[File:KitchenAid Stand Mixer.jpg|thumb|KitchenAid Stand Mixer]] [[File:Jean-François Millet (II) 005.jpg|thumb|Jean-François Millet (II) 005]] [[File:Piping buttercream onto cake.JPG|thumb|Piping buttercream onto cake]]
  
==Test Suite==
+
=Motivation=
In <code>src/test/java</code> in package <code>opencv.pipeline.studio</code> you will find <code>PipelineFaceDetectionTestSuite</code>.
+
Pipelines can increase throughput when processing a stream of data. We will gain additional experience with Phasers by building a software pipeline.
  
==Studio==
+
=Perhaps Outdated Lecture=
In <code>src/main/java</code> in package <code>opencv.pipeline.studio</code> you will find <code>ParallelPipelineFaceDetectionProducer</code>.
+
{{CollapsibleYouTube|Perhaps Outdated Pipeline Lecture|<youtube>umTGnCc9cGU</youtube>}}
  
[https://www.cs.rice.edu/~vs3/hjlib/code/course-materials/demo-files/PhaserPipeline.java RiceX Pipeline Demo]
+
=Code To Use=
 +
==Mixer==
 +
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Mixer.html class Mixer]
 +
:[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Mixer.html#mix-int- mix(int cakeIndex)]
 +
==Oven==
 +
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Oven.html class Oven]
 +
:[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Oven.html#bake-int-pipeline.cake.core.MixedIngredients- bake(int cakeIndex, MixedIngredients mixedIngredients)]
 +
==Icer==
 +
[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Icer.html class Icer]
 +
:[https://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/pipeline/cake/core/Icer.html#ice-int-pipeline.cake.core.BakedCake- ice(int cakeIndex, BakedCake bakedCake)]
  
 +
==Phasers==
 +
<youtube>whPAPmylbEU</youtube>
 +
 +
[[Reference_Page#Phasers|Our reference page's phasers section]]
 +
 +
[https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Phaser.html class Phaser] ([http://www.baeldung.com/java-phaser Guide to the Java Phaser])
 +
: [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Phaser.html#register-- register]
 +
: [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Phaser.html#arrive-- arrive]
 +
: [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Phaser.html#awaitAdvance-int- awaitAdvance] use via PhaserUtils.awaitAdvanceForPhase(phaser, phase)
 +
 +
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/concurrent/PhaserUtils.html PhaserUtils]
 +
: [http://www.cse.wustl.edu/~cosgroved/courses/cse231/current/apidocs/edu/wustl/cse231s/concurrent/PhaserUtils.html#awaitAdvanceForPhase-java.util.concurrent.Phaser-int- awaitAdvanceForPhase]
 +
 +
=Code To Implement=
 +
==Required Code==
 +
{{CodeToImplement|CakePipeline|mixBakeAndIceCakes|pipeline.cake.studio}}
 +
 +
{{Parallel|public static IcedCake[] mixBakeAndIceCakes(Mixer mixer, Oven oven, Icer icer, int cakeCount)}}
 +
 +
Design a simple pipeline using Phasers. In order to have a finished cake, you need to first mix the ingredients, then bake the cake, and finally ice it with frosting. Although you only have one tool for each step (one whisk, one oven, and one icing spatula), there's no problem with icing one cake while another is baking in the oven. That's where the parallelism comes in. Answering the above questions should give you all the information you need to set up this method. Remember that this needs to be able work for any number of cakes passed through!
 +
 +
Note that icer.ice() returns an object of IcedCake. Collect all the 'IcedCake's you make, and return them in an array.
 +
 +
{{Warning|Do not forget to ensure that all of your tasks (mix, bake, and ice) complete before you return. }}
 +
 +
[[File:CakePipeline.svg | 600px]]
 +
 +
==Optional Challenge==
 +
{{CodeToImplement|MultiOvenCakePipeline|mixBakeAndIceCakes|pipeline.cake.challenge}}
 +
 +
{{Parallel|public static IcedCake[] mixBakeAndIceCakes(Mixer mixer, List<Oven> ovens, Icer icer, int cakeCount)}}
 +
 +
As we've discussed in class, not all steps of the pipeline always take the same amount of time to complete. In this example, baking a cake in the oven usually takes much longer than simply mixing the ingredients or icing the cake. The Oven is the bottleneck on the performance of this pipeline. One way to further improve the process then is to simply more ovens. This time, build a similar pipeline to what you made earlier, but use all of the Ovens passed to you in order to speed things up. Here's a couple things to take note of:
 +
*How have the tasks changed? How does this additional oven affect the number of tasks your program will use?
 +
<!--
 +
*Assume that the only way to get a second oven is to buy an old, used one. It can't get as hot, so it will need more time to bake a cake. Because of this, it is better to set up your solution such that when a set of ingredients has been mixed, it sends them to any open oven, rather than just alternating between the two ovens.
 +
*Make sure that only one of the two ovens bakes any given cake. Use baker.inUse() and baker.numberAlreadyBaked() to help keep track of which oven has done which cakes.
 +
-->
 +
 +
{{Alert|<br/>Recall that [https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Phaser.html#awaitAdvance-int- awaitAdvance(phase)]'s returns immediately if the current phase is not the given phase.<br/>It is often better to use [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/concurrent/PhaserUtils.html#awaitAdvanceForPhase(java.util.concurrent.Phaser,int) PhaserUtils.awaitAdvanceForPhase(phaser, phase)].}}
 +
 +
=Testing Your Solution=
 
==Visualization==
 
==Visualization==
In <code>src/visualization/java</code> in package <code>opencv.pipeline.viz</code> you will find <code>PipelineFaceDetectionApp</code>.
+
{{Viz|CakePipelineVizApp|pipeline.cake.viz}}
 +
 
 +
[[File:CakePipelineGIF.gif]]
 +
 
 +
The viz below is for the challenge assignment.
  
[[File:OpencvPipelineViz.png|600px]]
+
[[File:TwoOvenPipelineGIF.gif]]
  
=Research=
+
==Correctness==
==Voila-Jones==
+
{{TestSuite|_CakePipelineTestSuite| pipeline.cake.exercise}}
[https://en.wikipedia.org/wiki/Viola%E2%80%93Jones_object_detection_framework Wikipedia: Viola–Jones object detection framework]
 
  
[https://www.cs.cmu.edu/~efros/courses/LBMV07/Papers/viola-cvpr-01.pdf CVPR 2001: Rapid Object Detection using a Boosted Cascade of Simple Features]
+
=Pledge, Acknowledgments, Citations=
 +
{{Pledge|exercise-cake-pipeline}}

Latest revision as of 03:13, 26 April 2023

KitchenAid Stand Mixer
Jean-François Millet (II) 005
Piping buttercream onto cake

Motivation

Pipelines can increase throughput when processing a stream of data. We will gain additional experience with Phasers by building a software pipeline.

Perhaps Outdated Lecture

Video: Perhaps Outdated Pipeline Lecture  

Code To Use

Mixer

class Mixer

mix(int cakeIndex)

Oven

class Oven

bake(int cakeIndex, MixedIngredients mixedIngredients)

Icer

class Icer

ice(int cakeIndex, BakedCake bakedCake)

Phasers

Our reference page's phasers section

class Phaser (Guide to the Java Phaser)

register
arrive
awaitAdvance use via PhaserUtils.awaitAdvanceForPhase(phaser, phase)

PhaserUtils

awaitAdvanceForPhase

Code To Implement

Required Code

class: CakePipeline.java Java.png
methods: mixBakeAndIceCakes
package: pipeline.cake.studio
source folder: student/src/main/java

method: public static IcedCake[] mixBakeAndIceCakes(Mixer mixer, Oven oven, Icer icer, int cakeCount) Parallel.svg (parallel implementation required)

Design a simple pipeline using Phasers. In order to have a finished cake, you need to first mix the ingredients, then bake the cake, and finally ice it with frosting. Although you only have one tool for each step (one whisk, one oven, and one icing spatula), there's no problem with icing one cake while another is baking in the oven. That's where the parallelism comes in. Answering the above questions should give you all the information you need to set up this method. Remember that this needs to be able work for any number of cakes passed through!

Note that icer.ice() returns an object of IcedCake. Collect all the 'IcedCake's you make, and return them in an array.

Attention niels epting.svg Warning:Do not forget to ensure that all of your tasks (mix, bake, and ice) complete before you return.

CakePipeline.svg

Optional Challenge

class: MultiOvenCakePipeline.java Java.png
methods: mixBakeAndIceCakes
package: pipeline.cake.challenge
source folder: student/src/main/java

method: public static IcedCake[] mixBakeAndIceCakes(Mixer mixer, List<Oven> ovens, Icer icer, int cakeCount) Parallel.svg (parallel implementation required)

As we've discussed in class, not all steps of the pipeline always take the same amount of time to complete. In this example, baking a cake in the oven usually takes much longer than simply mixing the ingredients or icing the cake. The Oven is the bottleneck on the performance of this pipeline. One way to further improve the process then is to simply more ovens. This time, build a similar pipeline to what you made earlier, but use all of the Ovens passed to you in order to speed things up. Here's a couple things to take note of:

  • How have the tasks changed? How does this additional oven affect the number of tasks your program will use?
Attention niels epting.svg Alert:
Recall that awaitAdvance(phase)'s returns immediately if the current phase is not the given phase.
It is often better to use PhaserUtils.awaitAdvanceForPhase(phaser, phase).

Testing Your Solution

Visualization

class: CakePipelineVizApp.java VIZ
package: pipeline.cake.viz
source folder: student/src//java

CakePipelineGIF.gif

The viz below is for the challenge assignment.

TwoOvenPipelineGIF.gif

Correctness

class: _CakePipelineTestSuite.java Junit.png
package: pipeline.cake.exercise
source folder: testing/src/test/java

Pledge, Acknowledgments, Citations

file: exercise-cake-pipeline-pledge-acknowledgments-citations.txt

More info about the Honor Pledge