Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,6 @@ install: $(LIB_DIR)/libHalide.a $(BIN_DIR)/libHalide.$(SHARED_EXT) $(INCLUDE_DIR
cp $(ROOT_DIR)/tutorial/figures/*.jpg $(PREFIX)/share/halide/tutorial/figures
cp $(ROOT_DIR)/tutorial/figures/*.mp4 $(PREFIX)/share/halide/tutorial/figures
cp $(ROOT_DIR)/tutorial/*.cpp $(PREFIX)/share/halide/tutorial
cp $(ROOT_DIR)/tutorial/*.h $(PREFIX)/share/halide/tutorial
cp $(ROOT_DIR)/tutorial/*.sh $(PREFIX)/share/halide/tutorial
cp $(ROOT_DIR)/tools/GenGen.cpp $(PREFIX)/share/halide/tools
cp $(ROOT_DIR)/tools/RunGen.h $(PREFIX)/share/halide/tools
Expand Down Expand Up @@ -2477,7 +2476,6 @@ $(DISTRIB_DIR)/lib/libHalide.$(SHARED_EXT): \
cp $(ROOT_DIR)/tutorial/figures/*.jpg $(DISTRIB_DIR)/tutorial/figures
cp $(ROOT_DIR)/tutorial/figures/*.mp4 $(DISTRIB_DIR)/tutorial/figures
cp $(ROOT_DIR)/tutorial/*.cpp $(DISTRIB_DIR)/tutorial
cp $(ROOT_DIR)/tutorial/*.h $(DISTRIB_DIR)/tutorial
cp $(ROOT_DIR)/tutorial/*.sh $(DISTRIB_DIR)/tutorial
cp $(ROOT_DIR)/tools/GenGen.cpp $(DISTRIB_DIR)/tools
cp $(ROOT_DIR)/tools/RunGen.h $(DISTRIB_DIR)/tools
Expand Down
4 changes: 0 additions & 4 deletions python_bindings/tutorial/lesson_01_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates basic usage of Halide as a JIT compiler for imaging.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_01_basics
# in a shell with the current directory at python_bindings/

import halide as hl


Expand Down
4 changes: 0 additions & 4 deletions python_bindings/tutorial/lesson_02_input_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

# This lesson demonstrates how to pass in input images.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_02_input_image
# in a shell with the current directory at python_bindings/

import halide as hl
import numpy as np
import halide.imageio
Expand Down
4 changes: 0 additions & 4 deletions python_bindings/tutorial/lesson_03_debugging_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# This lesson demonstrates how to inspect what the Halide compiler is
# producing.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_03_debugging_1
# in a shell with the current directory at python_bindings/

import halide as hl


Expand Down
13 changes: 4 additions & 9 deletions python_bindings/tutorial/lesson_04_debugging_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates how to follow what Halide is doing at runtime.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_04_debugging_2
# in a shell with the current directory at python_bindings/

import halide as hl


Expand Down Expand Up @@ -44,16 +40,15 @@ def main():
# that describes the algorithm.

# Now we tell Halide to use a parallel for loop over the y
# coordinate. On linux we run this using a thread pool and a task
# queue. On os x we call into grand central dispatch, which does
# the same thing for us.
# coordinate. Halide's runtime maintains its own pool of worker
# threads and a task queue.
parallel_gradient.parallel(y)

# This time the printfs should come out of order, because each
# scanline is potentially being processed in a different
# thread. The number of threads should adapt to your system, but
# on linux you can control it manually using the environment
# variable HL_NUMTHREADS.
# you can control it manually using the environment variable
# HL_NUM_THREADS.
print("\nEvaluating parallel_gradient")
parallel_gradient.realize([8, 8])

Expand Down
3 changes: 0 additions & 3 deletions python_bindings/tutorial/lesson_05_scheduling_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
# evaluate pixels in a hl.Func, including vectorization,
# parallelization, unrolling, and tiling.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_05_scheduling_1
# in a shell with the current directory at python_bindings/
import halide as hl


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# This lesson demonstrates how to evaluate a hl.Func over a domain that
# does not start at (0, 0).

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_06_realizing_over_shifted_domains
# in a shell with the current directory at python_bindings/

import halide as hl


Expand Down Expand Up @@ -78,7 +74,8 @@ def main():
# fact read out-of-bounds and probably crash.

# What if we want to evaluate our hl.Func over some region that
# isn't rectangular? Too bad. Halide only does rectangles :)
# isn't rectangular? Unfortunately, we can't. Halide only supports
# rectangular domains.

print("Success!")
return 0
Expand Down
6 changes: 1 addition & 5 deletions python_bindings/tutorial/lesson_07_multi_stage_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates how express multi-stage pipelines.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_07_multi_stage_pipelines
# in a shell with the current directory at python_bindings/

import halide as hl

import halide.imageio
Expand Down Expand Up @@ -92,7 +88,7 @@ def main():
print("Created blurry_parrot_1.png")

# This is usually the fastest way to deal with boundaries:
# don't write code that reads out of bounds :) The more
# avoid reading out of bounds in the first place. The more
# general solution is our next example.

# The same pipeline, with a boundary condition on the input.
Expand Down
10 changes: 2 additions & 8 deletions python_bindings/tutorial/lesson_08_scheduling_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates how schedule multi-stage pipelines.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_08_scheduling_2
# in a shell with the current directory at python_bindings/

import halide as hl
import numpy as np
import math
Expand Down Expand Up @@ -441,7 +437,7 @@ def main():
# iterations are lying around for us to reuse. This assumes that
# previous values of x or y happened earlier in time and have
# finished. This is not true if you parallelize or vectorize
# either loop. Darn. If you parallelize, Halide won't inject the
# either loop. If you parallelize, Halide won't inject the
# optimizations that skip work already done if there's a parallel
# loop in between the store_at level and the compute_at level,
# and won't fold the storage down into a circular buffer either,
Expand Down Expand Up @@ -659,8 +655,6 @@ def main():
consumer.print_loop_nest()
print()

# Look on my code, ye mighty, and despair!

# Let's check the C result against the Halide result. Doing
# this I found several bugs in my C implementation, which
# should tell you something.
Expand All @@ -675,7 +669,7 @@ def main():
# This stuff is hard. We ended up in a three-way trade-off
# between memory bandwidth, redundant work, and
# parallelism. Halide can't make the correct choice for you
# automatically (sorry). Instead it tries to make it easier for
# automatically. Instead it tries to make it easier for
# you to explore various options, without messing up your
# program. In fact, Halide promises that scheduling calls like
# compute_root won't change the meaning of your algorithm -- you
Expand Down
3 changes: 0 additions & 3 deletions python_bindings/tutorial/lesson_09_update_definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
# This lesson demonstrates how to define a hl.Func in multiple passes,
# including scattering.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_09_update_definitions
# in a shell with the current directory at python_bindings/
import halide as hl

import halide.imageio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
# uses that object file to actually run the pipeline. This means that
# compiling this code is a multi-step process.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_10_aot_compilation_generate
# in a shell with the current directory at python_bindings/

# This will generate a file lesson_10_halide.py.cpp that still needs
# to be compiled. Use
# make test_tutorial_lesson_10_aot_compilation_run
# to generate and run a Python module called "lesson_10_halide".

# The benefits of this approach are that the final program:
# - Doesn't do any jit compilation at runtime, so it's fast.
# - Doesn't depend on libHalide at all, so it's a small, easy-to-deploy binary.
Expand Down
4 changes: 0 additions & 4 deletions python_bindings/tutorial/lesson_11_cross_compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates how to use Halide as a cross-compiler.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_11_cross_compilation
# in a shell with the current directory at python_bindings/

import halide as hl
from struct import unpack

Expand Down
6 changes: 0 additions & 6 deletions python_bindings/tutorial/lesson_12_using_the_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@

# This lesson demonstrates how to use Halide to run code on a GPU.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_12_using_the_gpu
# in a shell with the current directory at python_bindings/

import halide as hl

import halide.imageio
Expand Down Expand Up @@ -285,8 +281,6 @@ def find_gpu_target():
features_to_try.append(hl.TargetFeature.D3D12Compute)
features_to_try.append(hl.TargetFeature.OpenCL)
elif target.os == hl.TargetOS.OSX:
# OS X doesn't update its OpenCL drivers, so they tend to be broken.
# CUDA would also be a fine choice on machines with NVidia GPUs.
features_to_try.append(hl.TargetFeature.Metal)
else:
features_to_try.append(hl.TargetFeature.OpenCL)
Expand Down
4 changes: 0 additions & 4 deletions python_bindings/tutorial/lesson_13_tuples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
# This lesson describes how to write Funcs that evaluate to multiple
# values.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_13_tuples
# in a shell with the current directory at python_bindings/

import math

import halide as hl
Expand Down
5 changes: 0 additions & 5 deletions python_bindings/tutorial/lesson_14_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

# This lesson more precisely describes Halide's type system.

# This lesson can be built by invoking the command:
# make test_tutorial_lesson_14_types
# in a shell with the current directory at python_bindings/


import halide as hl


Expand Down
6 changes: 3 additions & 3 deletions tools/halide_thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ThreadPool {
// we'll use assert, not internal_assert.
assert(desired_num_threads > 0);

std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock lock(mutex);

// Create all the threads.
for (size_t i = 0; i < desired_num_threads; ++i) {
Expand All @@ -104,7 +104,7 @@ class ThreadPool {
~ThreadPool() {
// Wake everyone up and tell them the party's over and it's time to go home
{
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock lock(mutex);
shutting_down = true;
wakeup_threads.notify_all();
}
Expand All @@ -117,7 +117,7 @@ class ThreadPool {

template<typename Func, typename... Args>
std::future<T> async(Func func, Args... args) {
std::lock_guard<std::mutex> lock(mutex);
std::scoped_lock lock(mutex);

Job job;
// Don't use std::forward here: we never want args passed by reference,
Expand Down
22 changes: 3 additions & 19 deletions tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
find_package(OpenMP)

configure_file(images/gray.png images/gray.png COPYONLY)
configure_file(images/rgb.png images/rgb.png COPYONLY)

function(add_tutorial source_file)
set(options WITH_IMAGE_IO WITH_OPENMP)
set(options WITH_IMAGE_IO)
set(oneValueArgs)
set(multiValueArgs SRCS GROUPS)
cmake_parse_arguments(args "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
Expand Down Expand Up @@ -34,20 +32,6 @@ function(add_tutorial source_file)
if (args_WITH_IMAGE_IO)
target_link_libraries(${name} PRIVATE Halide::ImageIO)
endif ()

if (args_WITH_OPENMP)
if (TARGET OpenMP::OpenMP_CXX)
target_link_libraries(${name} PRIVATE OpenMP::OpenMP_CXX)
else ()
# Compile anyway but suppress warnings about unrecognised pragmas
target_compile_options(
"${name}"
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/Wd4068>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wno-unknown-pragmas>
)
endif ()
endif ()
endfunction()

# Declare tutorials
Expand All @@ -73,8 +57,8 @@ endif ()

add_tutorial(lesson_06_realizing_over_shifted_domains.cpp)
add_tutorial(lesson_07_multi_stage_pipelines.cpp WITH_IMAGE_IO)
add_tutorial(lesson_08_scheduling_2.cpp WITH_IMAGE_IO WITH_OPENMP GROUPS multithreaded)
add_tutorial(lesson_09_update_definitions.cpp WITH_IMAGE_IO WITH_OPENMP GROUPS multithreaded)
add_tutorial(lesson_08_scheduling_2.cpp WITH_IMAGE_IO GROUPS multithreaded)
add_tutorial(lesson_09_update_definitions.cpp WITH_IMAGE_IO GROUPS multithreaded)

if ("NVPTX" IN_LIST Halide_LLVM_COMPONENTS)
if (Halide_TARGET MATCHES "wasm")
Expand Down
16 changes: 0 additions & 16 deletions tutorial/clock.h

This file was deleted.

18 changes: 6 additions & 12 deletions tutorial/lesson_01_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
// This lesson demonstrates basic usage of Halide as a JIT compiler for imaging.

// On linux, you can compile and run it like so:
// g++ lesson_01*.cpp -g -I <path/to/Halide.h> -L <path/to/libHalide.so> -lHalide -lpthread -ldl -o lesson_01 -std=c++17
// LD_LIBRARY_PATH=<path/to/libHalide.so> ./lesson_01

// On os x:
// g++ lesson_01*.cpp -g -I <path/to/Halide.h> -L <path/to/libHalide.so> -lHalide -o lesson_01 -std=c++17
// DYLD_LIBRARY_PATH=<path/to/libHalide.dylib> ./lesson_01

// If you have the entire Halide source tree, you can also build it by
// running:
// make tutorial_lesson_01_basics
// in a shell with the current directory at the top of the halide
// source tree.
// g++ lesson_01*.cpp -g -I <path/to/include> -L <path/to/lib> -lHalide -lpthread -ldl -o lesson_01 -std=c++17
// LD_LIBRARY_PATH=<path/to/lib> ./lesson_01

// On macOS:
// g++ lesson_01*.cpp -g -I <path/to/include> -L <path/to/lib> -lHalide -o lesson_01 -std=c++17
// DYLD_LIBRARY_PATH=<path/to/lib> ./lesson_01

// The only Halide header file you need is Halide.h. It includes all of Halide.
#include "Halide.h"
Expand Down
18 changes: 6 additions & 12 deletions tutorial/lesson_02_input_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@
// them.

// On linux, you can compile and run it like so:
// g++ lesson_02*.cpp -g -I <path/to/Halide.h> -I <path/to/tools/halide_image_io.h> -L <path/to/libHalide.so> -lHalide `libpng-config --cflags --ldflags` -ljpeg -lpthread -ldl -o lesson_02 -std=c++17
// LD_LIBRARY_PATH=<path/to/libHalide.so> ./lesson_02

// On os x:
// g++ lesson_02*.cpp -g -I <path/to/Halide.h> -I <path/to/tools/halide_image_io.h> -L <path/to/libHalide.so> -lHalide `libpng-config --cflags --ldflags` -ljpeg -o lesson_02 -std=c++17
// DYLD_LIBRARY_PATH=<path/to/libHalide.dylib> ./lesson_02

// If you have the entire Halide source tree, you can also build it by
// running:
// make tutorial_lesson_02_input_image
// in a shell with the current directory at the top of the halide
// source tree.
// g++ lesson_02*.cpp -g -I <path/to/include> -I <path/to/tools> -L <path/to/lib> -lHalide $(pkg-config --cflags --libs libpng libjpeg) -lpthread -ldl -o lesson_02 -std=c++17
// LD_LIBRARY_PATH=<path/to/lib> ./lesson_02

// On macOS:
// g++ lesson_02*.cpp -g -I <path/to/include> -I <path/to/tools> -L <path/to/lib> -lHalide $(pkg-config --cflags --libs libpng libjpeg) -o lesson_02 -std=c++17
// DYLD_LIBRARY_PATH=<path/to/lib> ./lesson_02

// The only Halide header file you need is Halide.h. It includes all of Halide.
#include "Halide.h"
Expand Down
Loading
Loading