Skip to content

Commit

Permalink
Add curriculum builder script (codeplaysoftware#256)
Browse files Browse the repository at this point in the history
This script allows a reduced curriculum to be made from all of the
sections in the main branch.

Previously, new branches would be made for each tutorial with a reduced
chapter set from main. Once these branches were made in the leadup to a
particular tutorial, lots of generic changes would be made to these
branches which were then lost on these isolated, workshop specific
branches.

This curriculum builder script allows those preparing for a tutorial or
workshop to make improvements or patches to the `main` branch, and then
make a reduced curriculum at the last minute in an automated fashion.

Also renames Lesson_Materials/Enqueuing_a_Kernel to
Lesson_Materials/Enqueueing_a_Kernel, and Code_Exercises/SYCL_Reduction
to Code_Exercises/More_SYCL_Features.
  • Loading branch information
hdelan authored Apr 3, 2024
1 parent 5c16812 commit bfdf3de
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Code_Exercises/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ add_subdirectory(Handling_Errors)
add_subdirectory(Device_Discovery)
add_subdirectory(Data_Parallelism)
add_subdirectory(Introduction_to_USM)
add_subdirectory(USM_Data_Parallelism)
add_subdirectory(Using_USM)
add_subdirectory(Asynchronous_Execution)
add_subdirectory(Data_and_Dependencies)
add_subdirectory(In_Order_Queue)
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions Lesson_Materials/Coalesced_Global_Memory/DEPS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Image_Convolution
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<!--Slide 1-->
<section>
<div class="hbox" data-markdown>
## Enqueuing a Kernel
## Enqueueing a Kernel
</div>
</section>
<!--Slide 2-->
Expand Down Expand Up @@ -228,7 +228,7 @@
<!--Slide 12-->
<section>
<div class="hbox" data-markdown>
#### Enqueuing SYCL Kernel Functions
#### Enqueueing SYCL Kernel Functions
</div>
<div class="container">
<div class="col">
Expand Down
1 change: 1 addition & 0 deletions Lesson_Materials/Local_Memory_Tiling/DEPS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Image_Convolution
1 change: 1 addition & 0 deletions Lesson_Materials/Vectors/DEPS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Image_Convolution
1 change: 1 addition & 0 deletions Lesson_Materials/Work_Group_Sizes/DEPS.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Image_Convolution
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ may not match completely.
| 14 | ND Range Kernels | [slides][lesson-14-slides] | [exercise][lesson-14-exercise] | [source][lesson-14-source] | [solution][lesson-14-solution] | Yes | Yes |
| 15 | Image Convolution | [slides][lesson-15-slides] | [exercise][lesson-15-exercise] | | [solution][lesson-15-solution] | Yes | Yes |
| 16 | Coalesced Global Memory | [slides][lesson-16-slides] | [exercise][lesson-16-exercise] | [source][lesson-16-source] | [solution][lesson-16-solution] | Yes | Yes |
| 17 | Vectorization | [slides][lesson-17-slides] | [exercise][lesson-17-exercise] | [source][lesson-17-source] | [solution][lesson-17-solution] | Yes | Yes |
| 17 | Vectors | [slides][lesson-17-slides] | [exercise][lesson-17-exercise] | [source][lesson-17-source] | [solution][lesson-17-solution] | Yes | Yes |
| 18 | Local Memory Tiling | [slides][lesson-18-slides] | [exercise][lesson-18-exercise] | [source][lesson-18-source] | [solution][lesson-18-solution] | Yes | Yes |
| 19 | Further Optimisations | [slides][lesson-19-slides] | [exercise][lesson-19-exercise] | [source][lesson-19-source] | [solution][lesson-19-solution] | Yes | Yes |
| 20 | Matrix Transpose | [slides][lesson-20-slides] | [exercise][lesson-20-exercise] | [source][lesson-20-source] | [solution][lesson-20-solution] | Yes | Yes |
Expand Down Expand Up @@ -356,7 +356,7 @@ cmake ../ "-GUnix Makefiles" -DSYCL_ACADEMY_USE_DPCPP=ON -DSYCL_ACADEMY_ENABLE_S
[lesson-1-source]: ./Code_Exercises/What_is_SYCL/source.cpp
[lesson-1-solution]: ./Code_Exercises/What_is_SYCL/solution.cpp

[lesson-2-slides]: ./Lesson_Materials/Enqueuing_a_Kernel/
[lesson-2-slides]: ./Lesson_Materials/Enqueueing_a_Kernel/
[lesson-2-exercise]: ./Code_Exercises/Enqueueing_a_Kernel/README.md
[lesson-2-source]: ./Code_Exercises/Enqueueing_a_Kernel/source.cpp
[lesson-2-solution]: ./Code_Exercises/Enqueueing_a_Kernel/solution.cpp
Expand Down
182 changes: 182 additions & 0 deletions generate-curriculum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
#!/bin/bash

# TODO this bash script calls `sed` in the linux way, not compatible with the
# macOS usage. Add a wrapper func to make a cross platform sed.

# TODO The index of chapters does not reorder chapters, if needed. Automate this

# This script can be used to generate a SYCL curriculum from some subset of
# all of the chapters in SYCLacademy. The usage is best explained in the usage()
# func.

usage() {
echo "Usage: ./generate-curriculum.sh [OPTIONS] [CHAPTERS]"
echo "This script generates a curriculum of SYCLAcademy using all of the"
echo "chapters that are listed as args"
echo
echo "Options:"
echo " -h, --help Show this help message and exit."
echo " -e, --exclude-deps Exclude dependent chapters"
echo
echo "Arguments:"
echo " CHAPTERS: A list of chapter names, as spelled in Lesson_Materials."
echo
echo "Example:"
echo " ./generate-curriculum.sh Why_Parallel_and_Heterogeneous Managing_Data Data_Parallelism"
echo " Will generate a 3 chapter curriculum, numbered from 1-3 where"
echo " chapter 1 corresponds to Why_Parallel_and_Heterogeneous from main"
echo " chapter 2 corresponds to Managing_Data from main"
echo " chapter 3 corresponds to Data_Parallelism from main"
echo
echo "The default behaviour is for a curriculum to be built with"
echo "dependencies. So if chapter 18 depends on chapter 15, the built"
echo "curriculum will instead be:"
echo
echo " ./generate-curriculum.sh Why_Parallel_and_Heterogeneous Managing_Data Vectors"
echo " Will generate a 4 chapter curriculum, numbered from 1-3 where"
echo " chapter 1 corresponds to Why_Parallel_and_Heterogeneous from main"
echo " chapter 2 corresponds to Managing_Data from main"
echo " chapter 3 corresponds to Image_Convolution from main"
echo " (Defined as a DEP of Vectors)"
echo " chapter 4 corresponds to Vectors from main"
echo
echo "Dependencies are defined in Lesson_Materials/*/DEPS.txt and"
echo "can be omitted using the "-e" flag."
exit 0
}

getValidChapters() {
validChapters=($(ls Lesson_Materials | grep -v common-revealjs))
}

parseArgs() {
# Iterate over each command line argument
for arg in "$@"; do
# Check if argument is an integer and between 1 and maxChapter
if [[ $arg == '-h' || $arg == '--help' ]]; then
usage
fi
if [[ $arg == '-e' || $arg == '--exclude-deps' ]]; then
excludeDependencies="true"
fi

strArg="$arg"
# Prepend single digit numbers with 0
if [[ ${#strArg} -eq 1 ]]; then
strArg="0$strArg"
fi

# Check if arg is a valid chapter
valid="false"
for validChapter in "${validChapters[@]}"; do
if [[ "$strArg" == $validChapter ]]; then
chosenChapters+=($strArg)
valid="true"
break
fi
done

if [[ $valid == "false" && $arg != "-e" ]]; then
echo "Invalid argument: $arg. Chapter should be a directory in Lesson_Materials."
exit 1
fi
done
}

# If chapter A depends on chapter B, chapter B will always be before chapter B
# in the curriculum
getDependentChapters() {
for chapter in ${chosenChapters[@]}; do
if [[ -f Lesson_Materials/$chapter/DEPS.txt ]]; then
while IFS= read -r line; do
dependentChapters+=("$line")
echo "Chapter $chapter is dependent on chapter $line => Adding chapter $line to curriculum"
echo "(Run with flag -e to exclude dependent chapters from curriculum)"
done < Lesson_Materials/$chapter/DEPS.txt
fi
dependentChapters+=("$chapter")
done
chosenChapters=("${dependentChapters[@]}")
echo
}

getToDeleteChapters() {
for chapter in ${validChapters[@]}; do
toDelete=true
for chosenChapter in ${chosenChapters[@]}; do
if [[ $chosenChapter == $chapter ]]; then
toDelete=false
break
fi
done
if $toDelete; then
chaptersToDelete+=("$chapter")
fi
done
}

if [[ $# -eq 0 ]]; then
usage
fi

validChapters=() # Valid chapters that can be used
chosenChapters=() # Chapters that will be used in curriculum
chaptersToDelete=() # Chapters that will be used in curriculum
dependentChapters=() # Chosen chapters plus dependencies

getValidChapters
parseArgs $@
# Get dep chapters if -e flag not passed
[[ -z $excludeDependencies ]] && getDependentChapters
getToDeleteChapters
echo "Have ${#chaptersToDelete[@]} chapters to delete"

for toDelete in ${chaptersToDelete[@]}; do
# Swap underscores for spaces
toDeleteNoUnderscores="${toDelete//_/ }"
echo $toDeleteNoUnderscores
# Remove links to old chapters in the README
sed -i "/| $toDeleteNoUnderscores |/d" README.md
sed -i "s/| [0-9][0-9]/| /g" README.md
sed -i "/${toDelete}/d" Code_Exercises/CMakeLists.txt

if [[ $toDelete != "common-revealjs" ]]; then
# Delete unused sections
rm -fr Code_Exercises/${toDelete}
rm -fr Lesson_Materials/${toDelete}
fi
done

for ((i=0; i<${#chosenChapters[@]}; i++)); do
newSectionDirName="Section_$((i+1))_${chosenChapters[$i]}"
# Number Code Exercises
cd Code_Exercises
if [[ -d ${chosenChapters[$i]} ]]; then
mv ${chosenChapters[$i]} $newSectionDirName
sed -i "s/${chosenChapters[$i]}/${newSectionDirName}/g" $newSectionDirName/README.md $newSectionDirName/CMakeLists.txt CMakeLists.txt
fi

# Number Lesson Materials
cd ../Lesson_Materials
if [[ -d ${chosenChapters[$i]} ]]; then
mv ${chosenChapters[$i]} $newSectionDirName
[[ -f $newSectionDirName/$lessonSectionToMove.pdf ]] && mv $newSectionDirName/$newSectionDirName.pdf $newSectionDirName/$newSectionDirName.pdf
[[ -f $newSectionDirName/index.html ]] && sed -i "s/${chosenChapters[$i]}/${newSectionDirName}/g" $newSectionDirName/index.html
fi
cd ..

# Update the links to the new chapter numbers in README and CMakeLists.txt
sed -i "s/${chosenChapters[$i]}/${newSectionDirName}/g" README.md
done

echo "Have generated curriculum with"
echo
echo "Code exercises:"
echo "==============="
echo
echo "$(ls Code_Exercises | grep Section | sort)"
echo
echo "Lesson materials:"
echo "================="
echo
echo "$(ls Lesson_Materials | grep Section | sort )"

0 comments on commit bfdf3de

Please sign in to comment.