Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fc971dfbe2 | ||
|
|
6af931c537 |
@@ -2,6 +2,32 @@
|
||||
The list of most significant changes made over time in
|
||||
Intel(R) Threading Building Blocks (Intel(R) TBB).
|
||||
|
||||
Intel TBB 2018 Update 2
|
||||
TBB_INTERFACE_VERSION == 10002
|
||||
|
||||
Changes (w.r.t. Intel TBB 2018 Update 1):
|
||||
|
||||
- Added support for Android* NDK r16, macOS* 10.13, Fedora* 26.
|
||||
- Binaries for Universal Windows Driver (vc14_uwd) now link with static
|
||||
Microsoft* runtime libraries, and are only available in commercial
|
||||
releases.
|
||||
- Extended flow graph documentation with more code samples.
|
||||
|
||||
Preview Features:
|
||||
|
||||
- Added a Python* module for multi-processing computations in numeric
|
||||
Python* libraries.
|
||||
|
||||
Bugs fixed:
|
||||
|
||||
- Fixed constructors of concurrent_hash_map to be exception-safe.
|
||||
- Fixed auto-initialization in the main thread to be cleaned up at
|
||||
shutdown.
|
||||
- Fixed a crash when tbbmalloc_proxy is used together with dbghelp.
|
||||
- Fixed static_partitioner to assign tasks properly in case of nested
|
||||
parallelism.
|
||||
|
||||
------------------------------------------------------------------------
|
||||
Intel TBB 2018 Update 1
|
||||
TBB_INTERFACE_VERSION == 10001
|
||||
|
||||
|
||||
@@ -50,13 +50,11 @@ rml: mkdir
|
||||
$(MAKE) -C "$(work_dir)_debug" -r -f $(tbb_root)/build/Makefile.rml cfg=debug
|
||||
$(MAKE) -C "$(work_dir)_release" -r -f $(tbb_root)/build/Makefile.rml cfg=release
|
||||
|
||||
|
||||
examples: tbb tbbmalloc
|
||||
$(MAKE) -C examples -r -f Makefile tbb_root=.. release test
|
||||
|
||||
python: mkdir
|
||||
$(MAKE) -C "$(work_dir)_release" -r -f $(tbb_root)/build/Makefile.tbb cfg=release
|
||||
bash -c ". $(work_dir)_release$(SLASH)tbbvars.sh && $(MAKE) -rC '$(full_tbb_root)/python' CXX=$(compiler) install test-install"
|
||||
python: tbb
|
||||
$(MAKE) -C "$(work_dir)_release" -rf $(tbb_root)/python/Makefile install
|
||||
|
||||
.PHONY: clean clean_examples mkdir info
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# Intel(R) Threading Building Blocks 2018 Update 1
|
||||
# Intel(R) Threading Building Blocks 2018 Update 2
|
||||
[](https://github.com/01org/tbb/releases/tag/2018_U2)
|
||||
[](LICENSE)
|
||||
|
||||
Intel(R) Threading Building Blocks (Intel(R) TBB) lets you easily write parallel C++ programs that take
|
||||
@@ -11,10 +12,16 @@ Here are the latest [Changes](CHANGES) and [Release Notes](doc/Release_Notes.txt
|
||||
This release provides additional TBB examples for workshops, conferences, etc.
|
||||
Head revision contains tutorials for all events and code base for the latest event. To get tutorials with original code base, please use specific tags.
|
||||
|
||||
* [PPoPP 2018](https://ppopp18.sigplan.org/) - code base: TBB 2018 U2 - tag: [tutorials_ppopp18](https://github.com/01org/tbb/tree/tutorials_ppopp18)
|
||||
* [examples/ppopp18](examples/ppopp18): exercises 3, 4 and 5 depend on OpenCL\* (lab2)
|
||||
* [SC 17](https://sc17.supercomputing.org/) - code base: TBB 2018 U1 - tag: [tutorials_sc17](https://github.com/01org/tbb/tree/tutorials_sc17)
|
||||
* [doc/sc17_slides](doc/sc17_slides)
|
||||
* [examples/sc17_hands_on](examples/sc17_hands_on): exercises depend on OpenCV 3.1.0, exercise 2 requires a video file (sc17_hands_on/input/input.avi) that is not part of this branch
|
||||
* [examples/sc17_hetero](examples/sc17_hetero): exercises 3, 4 and 5 depend on OpenCL\*
|
||||
* [EURO-PAR 2017](https://europar2017.usc.es/) - code base: TBB 2017 U3 - tag: [tutorials_europar17](https://github.com/01org/tbb/tree/tutorials_europar17)
|
||||
* [examples/europar17](examples/europar17)
|
||||
* [PPoPP 2017](https://ppopp18.sigplan.org/) - code base: TBB 2017 U3 - tag: [tutorials_ppopp17](https://github.com/01org/tbb/tree/tutorials_ppopp17)
|
||||
* [examples/ppopp17](examples/ppopp17)
|
||||
|
||||
## Documentation
|
||||
* Intel(R) TBB [tutorial](https://software.intel.com/en-us/tbb-tutorial)
|
||||
|
||||
+13
-1
@@ -68,8 +68,20 @@ ifeq (0, $(dynamic_load))
|
||||
endif
|
||||
|
||||
# Paths to the NDK prebuilt tools and libraries
|
||||
CPLUS_FLAGS += --sysroot=$(SYSROOT)
|
||||
ifneq (,$(findstring $(ndk_version),r16 r16b))
|
||||
# Since Android* NDK r16 another sysroot and isystem paths have to be specified
|
||||
CPLUS_FLAGS += --sysroot=$(NDK_ROOT)/sysroot -isystem $(NDK_ROOT)/sysroot/usr/include/$(TRIPLE)
|
||||
# Android* version flag required since r16
|
||||
CPLUS_FLAGS += -D__ANDROID_API__=$(API_LEVEL)
|
||||
else
|
||||
CPLUS_FLAGS += --sysroot=$(SYSROOT)
|
||||
endif
|
||||
|
||||
# Library sysroot flag
|
||||
LIB_LINK_FLAGS += --sysroot=$(SYSROOT)
|
||||
# Flag for test executables
|
||||
LINK_FLAGS += --sysroot=$(SYSROOT)
|
||||
|
||||
LIBS = -L$(CPLUS_LIB_PATH) -lc++_shared
|
||||
ifeq (,$(findstring $(ndk_version),$(foreach v, 7 8 9 10 11,r$(v) r$(v)b r$(v)c r$(v)d r$(v)e)))
|
||||
LIBS += -lc++abi
|
||||
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Provides unified tool for preparing TBB for packaging
|
||||
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import shutil
|
||||
import platform
|
||||
import argparse
|
||||
from glob import glob
|
||||
from collections import OrderedDict
|
||||
|
||||
jp = os.path.join
|
||||
is_win = (platform.system() == 'Windows')
|
||||
is_lin = (platform.system() == 'Linux')
|
||||
is_mac = (platform.system() == 'Darwin')
|
||||
|
||||
default_prefix = os.getenv('PREFIX', 'install_prefix')
|
||||
if is_win:
|
||||
default_prefix = jp(default_prefix, 'Library') # conda-specific by default on Windows
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--tbbroot', default='.', help='Take Intel TBB from here')
|
||||
parser.add_argument('--prefix', default=default_prefix, help='Prefix')
|
||||
parser.add_argument('--no-rebuild', default=False, action='store_true', help='do not rebuild')
|
||||
parser.add_argument('--install', default=False, action='store_true', help='install all')
|
||||
parser.add_argument('--install-libs', default=False, action='store_true', help='install libs')
|
||||
parser.add_argument('--install-devel', default=False, action='store_true', help='install devel')
|
||||
parser.add_argument('--install-docs', default=False, action='store_true', help='install docs')
|
||||
parser.add_argument('--install-python',default=False, action='store_true', help='install python module')
|
||||
parser.add_argument('--make-tool', default='make', help='Use different make command instead')
|
||||
parser.add_argument('--copy-tool', default=None, help='Use this command for copying ($ tool file dest-dir)')
|
||||
parser.add_argument('--build-args', default="", help='specify extra build args')
|
||||
parser.add_argument('--build-prefix', default='local', help='build dir prefix')
|
||||
if is_win:
|
||||
parser.add_argument('--msbuild', default=False, action='store_true', help='Use msbuild')
|
||||
parser.add_argument('--vs', default="2012", help='select VS version for build')
|
||||
parser.add_argument('--vs-platform', default="x64", help='select VS platform for build')
|
||||
parser.add_argument('ignore', nargs='?', help="workaround conda-build issue #2512")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.install:
|
||||
args.install_libs = True
|
||||
args.install_devel = True
|
||||
args.install_docs = True
|
||||
args.install_python= True
|
||||
|
||||
def custom_cp(src, dst):
|
||||
assert os.system(' '.join([args.copy_tool, src, dst])) == 0
|
||||
|
||||
if args.copy_tool:
|
||||
install_cp = custom_cp # e.g. to use install -p -D -m 755 on Linux
|
||||
else:
|
||||
install_cp = shutil.copy
|
||||
|
||||
bin_dir = jp(args.prefix, "bin")
|
||||
lib_dir = jp(args.prefix, "lib")
|
||||
inc_dir = jp(args.prefix, 'include')
|
||||
doc_dir = jp(args.prefix, 'share', 'doc', 'tbb')
|
||||
if is_win:
|
||||
os.environ["OS"] = "Windows_NT" # make sure TBB will interpret it corretly
|
||||
libext = '.dll'
|
||||
libpref = ''
|
||||
dll_dir = bin_dir
|
||||
else:
|
||||
libext = '.dylib' if is_mac else '.so.2'
|
||||
libpref = 'lib'
|
||||
dll_dir = lib_dir
|
||||
|
||||
tbb_names = ["tbb", "tbbmalloc", "tbbmalloc_proxy"]
|
||||
|
||||
##############################################################
|
||||
|
||||
os.chdir(args.tbbroot)
|
||||
if is_win and args.msbuild:
|
||||
preview_release_dir = release_dir = jp(args.tbbroot, 'build', 'vs'+args.vs, args.vs_platform, 'Release')
|
||||
if not args.no_rebuild or not os.path.isdir(release_dir):
|
||||
assert os.system('msbuild /m /p:Platform=%s /p:Configuration=Release %s build/vs%s/makefile.sln'% \
|
||||
(args.vs_platform, args.build_args, args.vs)) == 0
|
||||
preview_debug_dir = debug_dir = jp(args.tbbroot, 'build', 'vs'+args.vs, args.vs_platform, 'Debug')
|
||||
if not args.no_rebuild or not os.path.isdir(debug_dir):
|
||||
assert os.system('msbuild /m /p:Platform=%s /p:Configuration=Debug %s build/vs%s/makefile.sln'% \
|
||||
(args.vs_platform, args.build_args, args.vs)) == 0
|
||||
else:
|
||||
release_dir = jp(args.tbbroot, 'build', args.build_prefix+'_release')
|
||||
debug_dir = jp(args.tbbroot, 'build', args.build_prefix+'_debug')
|
||||
if not args.no_rebuild or not (os.path.isdir(release_dir) and os.path.isdir(debug_dir)):
|
||||
assert os.system('%s -j tbb_build_prefix=%s %s'% \
|
||||
(args.make_tool, args.build_prefix, args.build_args)) == 0
|
||||
preview_release_dir = jp(args.tbbroot, 'build', args.build_prefix+'_preview_release')
|
||||
preview_debug_dir = jp(args.tbbroot, 'build', args.build_prefix+'_preview_debug')
|
||||
if not args.no_rebuild or not (os.path.isdir(preview_release_dir) and os.path.isdir(preview_debug_dir)):
|
||||
assert os.system('%s -j tbb_build_prefix=%s_preview %s tbb_cpf=1 tbb'% \
|
||||
(args.make_tool, args.build_prefix, args.build_args)) == 0
|
||||
|
||||
|
||||
filemap = OrderedDict()
|
||||
def append_files(files, dst):
|
||||
global filemap
|
||||
filemap.update(dict(zip(files, [dst]*len(files))))
|
||||
|
||||
if args.install_libs:
|
||||
files = [jp(release_dir, libpref+f+libext) for f in tbb_names]
|
||||
append_files(files, dll_dir)
|
||||
|
||||
if args.install_devel:
|
||||
dll_files = [jp(debug_dir, libpref+f+'_debug'+libext) for f in tbb_names] # adding debug libraries
|
||||
if not is_win or not args.msbuild:
|
||||
dll_files += [jp(preview_release_dir, libpref+"tbb_preview"+libext),
|
||||
jp(preview_debug_dir, libpref+"tbb_preview_debug"+libext)]
|
||||
if is_win:
|
||||
dll_files += sum( [glob(jp(d, 'tbb*.pdb')) for d in # copying debug info
|
||||
(release_dir, debug_dir, preview_release_dir, preview_debug_dir)], [])
|
||||
if is_lin:
|
||||
dll_files += sum( [glob(jp(d, 'libtbb*.so')) for d in # copying linker scripts
|
||||
(release_dir, debug_dir, preview_release_dir, preview_debug_dir)], [])
|
||||
# symlinks .so -> .so.2 should not be created instead
|
||||
# since linking with -ltbb when using links can result in
|
||||
# incorrect dependence upon unversioned .so files
|
||||
append_files(dll_files, dll_dir)
|
||||
if is_win:
|
||||
lib_files = sum([glob(jp(d,e)) for d in (release_dir, debug_dir) for e in ('*.lib', '*.def')], [])
|
||||
append_files(lib_files, lib_dir) # copying linker libs and defs
|
||||
for rootdir, dirnames, filenames in os.walk(jp(args.tbbroot,'include')):
|
||||
files = [jp(rootdir, f) for f in filenames if not '.html' in f]
|
||||
append_files(files, jp(inc_dir, rootdir.split('include')[1][1:]))
|
||||
|
||||
if args.install_python:
|
||||
assert os.system('%s -j tbb_build_prefix=%s %s python'% \
|
||||
(args.make_tool, args.build_prefix, args.build_args)) == 0
|
||||
if is_lin:
|
||||
append_files([jp(release_dir, 'libirml.so.1')], dll_dir)
|
||||
|
||||
if args.install_docs:
|
||||
files = [jp(args.tbbroot, *f) for f in (
|
||||
('CHANGES',),
|
||||
('LICENSE',),
|
||||
('README',),
|
||||
('README.md',),
|
||||
('doc','Release_Notes.txt'),
|
||||
)]
|
||||
append_files(files, doc_dir)
|
||||
|
||||
for f in filemap.keys():
|
||||
assert os.path.exists(f)
|
||||
assert os.path.isfile(f)
|
||||
|
||||
if filemap:
|
||||
print("Copying to prefix =", args.prefix)
|
||||
for f, dest in filemap.items():
|
||||
if not os.path.isdir(dest):
|
||||
os.makedirs(dest)
|
||||
print("+ %s to $prefix%s"%(f,dest.replace(args.prefix, '')))
|
||||
install_cp(f, dest)
|
||||
|
||||
print("done")
|
||||
@@ -63,7 +63,14 @@ ifeq ($(origin LIB_LINK_LIBS), undefined)
|
||||
LIB_LINK_LIBS = $(LIBDL) $(LIBS)
|
||||
endif
|
||||
|
||||
# Define C & C++ compilers according to platform defaults or CXX & CC environment variables
|
||||
ifneq (,$(findstring environment, $(origin CXX)))
|
||||
CPLUS = $(CXX)
|
||||
endif
|
||||
CONLY ?= $(CPLUS)
|
||||
ifneq (,$(findstring environment, $(origin CC)))
|
||||
CONLY = $(CC)
|
||||
endif
|
||||
|
||||
# The most generic rules
|
||||
#$(1) - is the target pattern
|
||||
|
||||
@@ -44,7 +44,7 @@ else
|
||||
CPLUS_FLAGS = -g -O0 -DTBB_USE_DEBUG
|
||||
endif
|
||||
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD $(ITT_NOTIFY)
|
||||
|
||||
# For Clang, we add the option to support RTM intrinsics *iff* xtest is found in <immintrin.h>
|
||||
ifneq (,$(shell grep xtest `echo "\#include<immintrin.h>" | clang -E -M - 2>&1 | grep immintrin.h` 2>/dev/null))
|
||||
@@ -57,12 +57,14 @@ ifneq (,$(stdlib))
|
||||
endif
|
||||
|
||||
ifeq (intel64,$(arch))
|
||||
ITT_NOTIFY = -DDO_ITT_NOTIFY
|
||||
CPLUS_FLAGS += -m64 $(RTM_KEY)
|
||||
LINK_FLAGS += -m64
|
||||
LIB_LINK_FLAGS += -m64
|
||||
endif
|
||||
|
||||
ifeq (ia32,$(arch))
|
||||
ITT_NOTIFY = -DDO_ITT_NOTIFY
|
||||
CPLUS_FLAGS += -m32 $(RTM_KEY)
|
||||
LINK_FLAGS += -m32
|
||||
LIB_LINK_FLAGS += -m32
|
||||
|
||||
+3
-1
@@ -44,15 +44,17 @@ else
|
||||
CPLUS_FLAGS = -g -O0 -DTBB_USE_DEBUG
|
||||
endif
|
||||
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD $(ITT_NOTIFY)
|
||||
|
||||
ifeq (intel64,$(arch))
|
||||
ITT_NOTIFY = -DDO_ITT_NOTIFY
|
||||
CPLUS_FLAGS += -m64
|
||||
LINK_FLAGS += -m64
|
||||
LIB_LINK_FLAGS += -m64
|
||||
endif
|
||||
|
||||
ifeq (ia32,$(arch))
|
||||
ITT_NOTIFY = -DDO_ITT_NOTIFY
|
||||
CPLUS_FLAGS += -m32
|
||||
LINK_FLAGS += -m32
|
||||
LIB_LINK_FLAGS += -m32
|
||||
|
||||
+2
-1
@@ -58,7 +58,8 @@ else
|
||||
CPLUS_FLAGS = -g -O0 -DTBB_USE_DEBUG
|
||||
endif
|
||||
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD
|
||||
ITT_NOTIFY = -DDO_ITT_NOTIFY
|
||||
CPLUS_FLAGS += -DUSE_PTHREAD $(ITT_NOTIFY)
|
||||
|
||||
ifneq (,$(codecov))
|
||||
CPLUS_FLAGS += -prof-gen=srcpos
|
||||
|
||||
+13
-5
@@ -43,6 +43,11 @@ else
|
||||
endif
|
||||
EH_FLAGS = $(if $(no_exceptions),/EHs-,/EHsc /GR)
|
||||
|
||||
# UWD binaries have to use static CRT linkage
|
||||
ifeq ($(target_app), uwd)
|
||||
MS_CRT_KEY = /MT$(if $(findstring debug,$(cfg)),d)
|
||||
endif
|
||||
|
||||
ifeq ($(cfg), release)
|
||||
CPLUS_FLAGS = $(MS_CRT_KEY) /O2 /Zi $(EH_FLAGS) /Zc:forScope /Zc:wchar_t /D__TBB_LIB_NAME=$(TBB.LIB)
|
||||
ASM_FLAGS =
|
||||
@@ -54,17 +59,20 @@ endif
|
||||
|
||||
ZW_KEY = /ZW:nostdlib
|
||||
|
||||
ifneq (,$(filter win8ui,$(target_app) $(target_ui)))
|
||||
CPLUS_FLAGS += $(ZW_KEY) /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP"
|
||||
# These flags are general for Windows* universal applications
|
||||
ifneq (,$(target_app))
|
||||
CPLUS_FLAGS += $(ZW_KEY) /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP"
|
||||
endif
|
||||
|
||||
ifeq ($(target_app), win8ui)
|
||||
_WIN32_WINNT = 0x0602
|
||||
else ifneq (,$(filter uwp,$(target_app) $(target_ui)))
|
||||
CPLUS_FLAGS += $(ZW_KEY) /D "_UNICODE" /D "UNICODE" /D "WINAPI_FAMILY=WINAPI_FAMILY_APP"
|
||||
else ifneq (,$(filter $(target_app),uwp uwd))
|
||||
_WIN32_WINNT = 0x0A00
|
||||
LIB_LINK_FLAGS += /NODEFAULTLIB:kernel32.lib OneCore.lib
|
||||
else
|
||||
CPLUS_FLAGS += /DDO_ITT_NOTIFY
|
||||
endif
|
||||
ifneq (,$(filter store,$(target_mode) $(target_ui_mode)))
|
||||
ifeq ($(target_mode), store)
|
||||
# it is necessary to source vcvars with 'store' argument in production
|
||||
LIB_LINK_FLAGS += /APPCONTAINER
|
||||
endif
|
||||
|
||||
@@ -66,7 +66,7 @@ Software - Supported Operating Systems
|
||||
Systems with Linux* operating systems
|
||||
CentOS 7.1
|
||||
Debian* 8, 9
|
||||
Fedora* 24, 25
|
||||
Fedora* 24, 25, 26
|
||||
Intel(R) Cluster Ready
|
||||
Red Hat* Enterprise Linux* 6, 7
|
||||
SuSE* Linux* Enterprise Server 11, 12
|
||||
@@ -75,9 +75,9 @@ Software - Supported Operating Systems
|
||||
Yocto 2.2, 2.3
|
||||
Systems with OS X* or macOS* operating systems
|
||||
OS X* 10.10, 10.11
|
||||
macOS* 10.12
|
||||
macOS* 10.12, 10.13
|
||||
Systems with Android* operating systems
|
||||
Android* 5.x, 6.x, 7.x
|
||||
Android* 5.x, 6.x, 7.x, 8.x
|
||||
|
||||
Software - Supported Compilers
|
||||
|
||||
@@ -94,8 +94,8 @@ Software - Supported Compilers
|
||||
version provided with that operating system is supported
|
||||
GNU Compilers (gcc) 4.1 - 7.1
|
||||
GNU C Library (glibc) version 2.4 - 2.19
|
||||
Xcode* 6.3 - 8.3
|
||||
Android* NDK r10e - r15b
|
||||
Xcode* 6.3 - 9.1
|
||||
Android* NDK r10e - r16
|
||||
|
||||
Software - Supported Performance Analysis Tools
|
||||
|
||||
|
||||
@@ -349,10 +349,10 @@ template<typename I > </td></tr>
|
||||
void </td><td class="memItemRight" valign="bottom"><a class="el" href="a00040.html#a0bc3593f82b3b4f9839fc051780212ab">internal_copy</a> (const <a class="el" href="a00040.html">concurrent_hash_map</a> &source)</td></tr>
|
||||
<tr class="memdesc:a0bc3593f82b3b4f9839fc051780212ab"><td class="mdescLeft"> </td><td class="mdescRight">Copy "source" to *this, where *this must start out empty. <br/></td></tr>
|
||||
<tr class="separator:a0bc3593f82b3b4f9839fc051780212ab"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a31e69cc4fd5adafb379e7c6de5660912"><td class="memTemplParams" colspan="2"><a class="anchor" id="a31e69cc4fd5adafb379e7c6de5660912"></a>
|
||||
<tr class="memitem:a76750c61ad670e130850148543f67147"><td class="memTemplParams" colspan="2"><a class="anchor" id="a76750c61ad670e130850148543f67147"></a>
|
||||
template<typename I > </td></tr>
|
||||
<tr class="memitem:a31e69cc4fd5adafb379e7c6de5660912"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><b>internal_copy</b> (I first, I last)</td></tr>
|
||||
<tr class="separator:a31e69cc4fd5adafb379e7c6de5660912"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:a76750c61ad670e130850148543f67147"><td class="memTemplItemLeft" align="right" valign="top">void </td><td class="memTemplItemRight" valign="bottom"><b>internal_copy</b> (I first, I last, size_type reserve_size)</td></tr>
|
||||
<tr class="separator:a76750c61ad670e130850148543f67147"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
<tr class="memitem:acbb5b18c097fb32f264b7b5fe8d9fdd4"><td class="memItemLeft" align="right" valign="top">const_pointer </td><td class="memItemRight" valign="bottom"><a class="el" href="a00040.html#acbb5b18c097fb32f264b7b5fe8d9fdd4">internal_fast_find</a> (const Key &key) const </td></tr>
|
||||
<tr class="memdesc:acbb5b18c097fb32f264b7b5fe8d9fdd4"><td class="mdescLeft"> </td><td class="mdescRight">Fast find when no concurrent erasure is used. For internal use inside TBB only! <a href="#acbb5b18c097fb32f264b7b5fe8d9fdd4">More...</a><br/></td></tr>
|
||||
<tr class="separator:acbb5b18c097fb32f264b7b5fe8d9fdd4"><td class="memSeparator" colspan="2"> </td></tr>
|
||||
|
||||
@@ -101,7 +101,7 @@
|
||||
<tr bgcolor="#f0f0f0" class="even"><td class="entry"><b>internal::hash_map_iterator</b> (defined in <a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a>)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">friend</span></td></tr>
|
||||
<tr bgcolor="#f0f0f0"><td class="entry"><b>internal::hash_map_range</b> (defined in <a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a>)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">friend</span></td></tr>
|
||||
<tr class="even"><td class="entry"><a class="el" href="a00040.html#a0bc3593f82b3b4f9839fc051780212ab">internal_copy</a>(const concurrent_hash_map &source)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
|
||||
<tr bgcolor="#f0f0f0"><td class="entry"><b>internal_copy</b>(I first, I last) (defined in <a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a>)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
|
||||
<tr bgcolor="#f0f0f0"><td class="entry"><b>internal_copy</b>(I first, I last, size_type reserve_size) (defined in <a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a>)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
|
||||
<tr class="even"><td class="entry"><a class="el" href="a00040.html#a8603f5288db63ec35a16844427e97e42">internal_equal_range</a>(const Key &key, I end) const </td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">protected</span></td></tr>
|
||||
<tr><td class="entry"><a class="el" href="a00040.html#acbb5b18c097fb32f264b7b5fe8d9fdd4">internal_fast_find</a>(const Key &key) const </td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">inline</span><span class="mlabel">protected</span></td></tr>
|
||||
<tr bgcolor="#f0f0f0" class="even"><td class="entry"><b>is_write_access_needed</b> (defined in <a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a>)</td><td class="entry"><a class="el" href="a00040.html">tbb::interface5::concurrent_hash_map< Key, T, HashCompare, A ></a></td><td class="entry"><span class="mlabel">friend</span></td></tr>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
Copyright (c) 2012-2014 MIT CSAIL, Google Inc., and other contributors
|
||||
|
||||
Developed by:
|
||||
|
||||
The Halide team
|
||||
http://halide-lang.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "lodepng.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct image_buffer {
|
||||
unsigned int width, height;
|
||||
std::shared_ptr< std::vector<unsigned char> > buffer; // smart pointer to the vector of raw pixels in RGBA format, 4 bytes per pixel
|
||||
};
|
||||
|
||||
image_buffer readPNGImage(const std::string& imageName) {
|
||||
image_buffer image;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >();
|
||||
|
||||
unsigned int error = lodepng::decode(*image.buffer, image.width, image.height, imageName.c_str());
|
||||
|
||||
if (error) {
|
||||
std::string exceptionMessage = "decoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
void readPNGImage(unsigned char* imageBuffer, unsigned int& width, unsigned int& height, const char* imageName) {
|
||||
unsigned int error = lodepng_decode32_file(&imageBuffer, &width, &height, imageName);
|
||||
|
||||
if (error) {
|
||||
std::string exceptionMessage = "decoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void writePNGImage(const image_buffer& image, const std::string& outputFile) {
|
||||
unsigned int error = lodepng::encode(outputFile, *image.buffer, image.width, image.height);
|
||||
if (error) {
|
||||
std::string exceptionMessage = "encoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void writePNGImage(unsigned char* imageBuffer, unsigned int& width, unsigned int& height, const std::string& outputFile) {
|
||||
unsigned int error = lodepng::encode(outputFile, imageBuffer, width, height);
|
||||
if (error) {
|
||||
std::string exceptionMessage = "encoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
image_buffer generatePNGImage() {
|
||||
image_buffer image;
|
||||
image.width = 1024;
|
||||
image.height = 1024;
|
||||
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(image.width * image.height * 4);
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
const int widthOffset = 4 * image.width;
|
||||
for (unsigned y = 0; y < image.height; y++) {
|
||||
for (unsigned x = 0; x < image.width; x++) {
|
||||
const int pixelOffset = widthOffset * y + 4 * x;
|
||||
buffer[pixelOffset] = 200 * !(x & y);
|
||||
buffer[pixelOffset + 1] = x ^ y;
|
||||
buffer[pixelOffset + 2] = x | y;
|
||||
buffer[pixelOffset + 3] = 255;
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
bool isFileExist(const std::string& fileName) {
|
||||
std::ifstream file(fileName);
|
||||
return file.good();
|
||||
}
|
||||
|
||||
bool isBothImagesExists(const std::string& firstFile, const std::string& secondFile) {
|
||||
return isFileExist(firstFile) && isFileExist(secondFile);
|
||||
}
|
||||
|
||||
image_buffer getOrGenerateImage(const std::string& fileName) {
|
||||
return fileName.empty() ? generatePNGImage() : readPNGImage(fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise0", "exercise0.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\stereo-serial.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\common\input\input1.png" />
|
||||
<Image Include="..\..\common\input\input2.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise0</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
"icpc stereo-serial.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../"
|
||||
|
||||
Simple image processing example to start with
|
||||
First task: execute example and note execution time.
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
buffer_t leftImageBuffer = utils::getOrGenerateImage(inputFileFirst);
|
||||
buffer_t rightImageBuffer = utils::getOrGenerateImage(inputFileSecond);
|
||||
|
||||
applyImageEffect(leftImageBuffer,redChannelOffset);
|
||||
applyImageEffect(rightImageBuffer,blueChannelOffset);
|
||||
|
||||
mergeImageBuffers(leftImageBuffer, rightImageBuffer);
|
||||
|
||||
utils::writePNGImage(rightImageBuffer, outputFile);
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc exercise01.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges two image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
int main() {
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
graph g;
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
//function node to apply red filter to left image
|
||||
function_node<buffer_t, buffer_t> left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
/* TODO: insert function node to implement blue filter on right image */
|
||||
|
||||
|
||||
|
||||
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join(g);
|
||||
|
||||
function_node<join_t::output_type, buffer_t> image_merge(g, unlimited, [](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, left_transform);
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
/* TODO: make edges.
|
||||
right_src -> right_transform);
|
||||
right_transform -> input_port<1>(image_join);
|
||||
image_join -> image_merge;
|
||||
image_merge -> image_display;
|
||||
*/
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise1", "exercise1.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\exercise01.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\common\input\input1.png" />
|
||||
<Image Include="..\..\common\input\input2.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise1</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Your task is to complete the composite node, which encapsulates the functionality from previous exercises.
|
||||
|
||||
Build instructions:
|
||||
icpc exercise02.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > base_type;
|
||||
graph &my_graph;
|
||||
function_node<buffer_t, buffer_t> left_transform;
|
||||
function_node<buffer_t, buffer_t> right_transform;
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join;
|
||||
function_node<join_t::output_type, buffer_t> image_merge;
|
||||
|
||||
public:
|
||||
stereo_node(graph &g) : my_graph(g), base_type(g),
|
||||
left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
right_transform(g,unlimited,[](buffer_t b) {
|
||||
/* TODO: apply right image effect */
|
||||
return b;
|
||||
}),
|
||||
image_join(g),
|
||||
image_merge(g, unlimited,
|
||||
[](const join_t::output_type &in) -> buffer_t {
|
||||
/* TODO: merge left and right image. Hint: see last exercise */
|
||||
buffer_t right = get<1>(in);
|
||||
|
||||
return right;
|
||||
}) {
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
set_external_ports(input_ports_type(left_transform, right_transform), output_ports_type(image_merge));
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
graph g;
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise2", "exercise2.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\exercise02.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\common\input\input1.png" />
|
||||
<Image Include="..\..\common\input\input2.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise2</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
Linux: icpc exercise03.cpp -o hello_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc exercise03.cpp -o hello_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
*/
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include <cstdio>
|
||||
|
||||
void chooseTargetDevice(opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
typedef opencl_buffer<cl_char> buffer_t;
|
||||
typedef int token_t;
|
||||
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
opencl_program<> program(g, "hello_world.cl");
|
||||
opencl_node<tuple<buffer_t>> gpu_node(g, program.get_kernel("print"));
|
||||
std::array<unsigned int, 1> range{1};
|
||||
gpu_node.set_range(range);
|
||||
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
typedef multifunction_node< token_t, tuple< buffer_t, buffer_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, [&]( const token_t &in, mfn_t::output_ports_type &ports ) {
|
||||
token_t tok = in;
|
||||
const char str[] = "Hello from ";
|
||||
buffer_t b( g, sizeof(str) );
|
||||
std::copy_n( str, sizeof(str), b.begin() );
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(b);
|
||||
} else {
|
||||
get<1>(ports).try_put(b);
|
||||
}
|
||||
});
|
||||
|
||||
function_node<buffer_t, token_t> cpu_node(g,unlimited,[](buffer_t b) {
|
||||
char *str = (char*)b.begin();
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("CPU!\n");
|
||||
return token_t(0);
|
||||
});
|
||||
|
||||
make_edge(token_buffer,dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), cpu_node);
|
||||
make_edge(output_port<1>(dispatch_node), gpu_node);
|
||||
|
||||
printf("Beginning\n");
|
||||
|
||||
/* feed two token into the graph to trigger both gpu and cpu print "Hello World!" */
|
||||
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__kernel void print( global char *str ) {
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("GPU!\n");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise3", "exercise3.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,169 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\exercise03.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\hello_world.cl" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise3</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Task: compile, run and compare resulting runtime to previous version of stereo.
|
||||
|
||||
Build instructions:
|
||||
Linux: icpc exercise04.cpp ../common/lodepng.cpp -o stereo_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc exercise04.cpp ../common/lodepng.cpp -o stereo_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
/* Begin: Duplicate preamble from previous stereo exercise
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
End: Duplicate from previous exercise */
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
#include "tbb/tick_count.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
typedef opencl_buffer<cl_uchar> OpenclImageBuffer;
|
||||
typedef std::array<unsigned int, 2> NDRange;
|
||||
typedef tuple< OpenclImageBuffer, cl_uint, NDRange > buffer_t;
|
||||
typedef tuple< OpenclImageBuffer, OpenclImageBuffer, cl_uint, NDRange > merge_buffer_t;
|
||||
|
||||
void fillOpenclBuffer(tbb::flow::opencl_buffer<cl_uchar>& openclBuffer, const std::vector<unsigned char>& sourceBuffer) {
|
||||
std::copy(sourceBuffer.begin(), sourceBuffer.end(), openclBuffer.begin());
|
||||
}
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > stereo_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
split_node<buffer_t> left_split;
|
||||
split_node<buffer_t> right_split;
|
||||
|
||||
opencl_node< buffer_t > left_transform;
|
||||
opencl_node< buffer_t > right_transform;
|
||||
|
||||
opencl_node< merge_buffer_t > image_merge;
|
||||
join_node< buffer_t > image_join;
|
||||
|
||||
public:
|
||||
stereo_node(opencl_graph &g) : my_graph(g), stereo_base_type(g),
|
||||
program(g, "stereo.cl"),
|
||||
left_transform(g, program.get_kernel("applyLeftImageEffect")),
|
||||
right_transform(g, program.get_kernel("applyRightImageEffect")),
|
||||
image_merge(g, program.get_kernel("mergeImages")),
|
||||
image_join(g),
|
||||
right_split(g),
|
||||
left_split(g) {
|
||||
make_edge(output_port<0>(left_split), input_port<0>(left_transform));
|
||||
make_edge(output_port<1>(left_split), input_port<1>(left_transform));
|
||||
make_edge(output_port<2>(left_split), input_port<2>(left_transform));
|
||||
make_edge(output_port<0>(right_split), input_port<0>(right_transform));
|
||||
make_edge(output_port<1>(right_split), input_port<1>(right_transform));
|
||||
make_edge(output_port<2>(right_split), input_port<2>(right_transform));
|
||||
|
||||
make_edge(output_port<0>(left_transform), input_port<0>(image_merge));
|
||||
make_edge(output_port<0>(right_transform), input_port<1>(image_merge));
|
||||
make_edge(output_port<1>(left_transform), input_port<2>(image_merge));
|
||||
make_edge(output_port<2>(left_transform), input_port<3>(image_merge));
|
||||
|
||||
make_edge(output_port<0>(image_merge), input_port<0>(image_join));
|
||||
make_edge(output_port<2>(image_merge), input_port<1>(image_join));
|
||||
make_edge(output_port<3>(image_merge), input_port<2>(image_join));
|
||||
|
||||
left_transform.set_args(port_ref<0, 1>());
|
||||
left_transform.set_range(port_ref<2>());
|
||||
|
||||
right_transform.set_args(port_ref<0, 1>());
|
||||
right_transform.set_range(port_ref<2>());
|
||||
|
||||
image_merge.set_args(port_ref<0, 2>());
|
||||
image_merge.set_range(port_ref<3>());
|
||||
|
||||
set_external_ports(input_ports_type(left_split, right_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
void chooseTargetDevice(tbb::flow::opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
utils::image_buffer src = utils::getOrGenerateImage(inputFileFirst);
|
||||
// Create and initialize opencl_buffer in order to pass it to mergeImages kernel
|
||||
OpenclImageBuffer oclImage(g, src.buffer->size());
|
||||
fillOpenclBuffer(oclImage, *src.buffer);
|
||||
NDRange rangeList = { src.width, src.height };
|
||||
v = std::make_tuple(oclImage, src.width, rangeList);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
utils::image_buffer src = utils::getOrGenerateImage(inputFileSecond);
|
||||
// Create and initialize opencl_buffer in order to pass it to mergeImages kernel
|
||||
OpenclImageBuffer oclImage(g, src.buffer->size());
|
||||
fillOpenclBuffer(oclImage, *src.buffer);
|
||||
NDRange rangeList = { src.width, src.height };
|
||||
v = std::make_tuple(oclImage, src.width, rangeList);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
// The result image have to be copied in order to be changed,
|
||||
// the second parameter - image size, can be taken by const reference
|
||||
OpenclImageBuffer imageBuffer = std::get<0>(b);
|
||||
const NDRange& imageSize = std::get<2>(b);
|
||||
unsigned int width = imageSize[0];
|
||||
unsigned int height = imageSize[1];
|
||||
|
||||
utils::writePNGImage(imageBuffer.data(), width, height, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise4", "exercise4.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,178 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\exercise04.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\stereo.cl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\common\input\input1.png" />
|
||||
<Image Include="..\..\common\input\input2.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise4</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
__constant int channelIncreaseValue = 10;
|
||||
|
||||
__kernel void mergeImages( __global uchar* bufferLeft, __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
bufferLeft[pixelGreenChannelIndex] = bufferRight[pixelGreenChannelIndex];
|
||||
bufferLeft[pixelBlueChannelIndex] = bufferRight[pixelBlueChannelIndex];
|
||||
}
|
||||
|
||||
__kernel void applyLeftImageEffect( __global uchar* bufferLeft, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelRedChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + redChannelOffset;
|
||||
|
||||
bufferLeft[pixelRedChannelIndex] = convert_uchar_sat(bufferLeft[pixelRedChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
__kernel void applyRightImageEffect( __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelBlueChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + blueChannelOffset;
|
||||
|
||||
bufferRight[pixelBlueChannelIndex] = convert_uchar_sat(bufferRight[pixelBlueChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
|
||||
uchar calc_one_pixel(float x0, float y0, int max_iterations, int size_x, int size_y, float magn, float cx, float cy, int gpu)
|
||||
{
|
||||
int iter;
|
||||
float fx0, fy0, xtemp, x, y, mu;
|
||||
|
||||
uchar color;
|
||||
|
||||
fx0 = x0 - size_x / 2.0f;
|
||||
fy0 = y0 - size_y / 2.0f;
|
||||
fx0 = fx0 / magn + cx;
|
||||
fy0 = fy0 / magn + cy;
|
||||
|
||||
iter = 0; x = 0; y = 0;
|
||||
|
||||
while ( ((x*x + y*y) <= 32) && (iter < max_iterations) ) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2 * x*y + fy0;
|
||||
x = xtemp;
|
||||
iter++;
|
||||
}
|
||||
|
||||
if ( iter == max_iterations ) {
|
||||
// point corresponds to the Mandelbrot set
|
||||
return 0;
|
||||
}
|
||||
|
||||
// compute again but with exponent calculation at each iteration
|
||||
// it's all for coloring point outside the Mandelbrot set
|
||||
iter = 0; x = 0; y = 0;
|
||||
mu = 0;
|
||||
|
||||
while ( ((x*x + y*y) <= 32) && (iter < max_iterations) ) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2 * x*y + fy0;
|
||||
x = xtemp;
|
||||
mu += exp(-sqrt(x*x + y*y));
|
||||
iter++;
|
||||
}
|
||||
|
||||
const uint b = convert_uint_sat(256 * mu);
|
||||
const uint g = (b / 8);
|
||||
const uint r = (g / 16);
|
||||
|
||||
const uchar gray = convert_uchar_sat(0.21f * r + 0.72f * g + 0.07f * b);
|
||||
return gray;
|
||||
}
|
||||
|
||||
__kernel void mono_mandelbrot( __global uchar* fractal_data_array, uint x0, uint x1, uint y0, uint y1, uint max_iterations, uint size_x, uint size_y, float magn, float cx, float cy) {
|
||||
const int x = get_global_id(0) + x0;
|
||||
const int y = get_global_id(1) + y0;
|
||||
|
||||
const int pixelIndex = channelsPerPixel * (x1 - x0) * (y - y0) + channelsPerPixel * (x - x0);
|
||||
const int pixelRedChannelIndex = pixelIndex + redChannelOffset;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
fractal_data_array[pixelRedChannelIndex] = fractal_data_array[pixelGreenChannelIndex] = fractal_data_array[pixelBlueChannelIndex] = calc_one_pixel(x, y, max_iterations, size_x, size_y, magn, cx, cy, 255);
|
||||
fractal_data_array[pixelIndex + 3] = 255;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "exercise5", "exercise5.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\fractal.cl" />
|
||||
<None Include="..\stereo.cl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\solution05_final.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>exercise5</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
#include "tbb/tick_count.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
typedef std::array<unsigned int, 2> NDRange;
|
||||
typedef tuple< cl_uint, cl_uint, cl_uint > fractal_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, cl_uint, cl_uint, cl_uint > fractal_cpu_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, cl_uint, cl_uint, cl_uint, NDRange > fractal_gpu_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, NDRange > buffer_t;
|
||||
|
||||
typedef tuple< opencl_buffer<cl_uchar>, opencl_buffer<cl_uchar>, cl_uint, NDRange > merge_buffer_t;
|
||||
|
||||
static const int image_size = 1024;
|
||||
static const int max_iterations = 256;
|
||||
|
||||
static const int divider = 2;
|
||||
static const int tile_width = image_size/divider;
|
||||
static const int tile_height = image_size/divider;
|
||||
|
||||
static const int channelsPerPixel = 4;
|
||||
|
||||
class color_fractal_cpu_node : public composite_node< tuple<fractal_data_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<fractal_data_t>, tuple<buffer_t> > fractal_cpu_base_type;
|
||||
opencl_graph &my_graph;
|
||||
function_node<fractal_data_t, buffer_t> calculate_fractal;
|
||||
|
||||
void calculate_pixel(unsigned char * pixel_ptr, int pixelOffset, int x0, int y0, int max_iterations, int size_x,int size_y, float magn, float cx, float cy) {
|
||||
unsigned int iter;
|
||||
double fx0, fy0, xtemp, x, y, mu;
|
||||
|
||||
fx0 = (double)x0 - (double) size_x / 2.0;
|
||||
fy0 = (double)y0 - (double) size_y / 2.0;
|
||||
fx0 = fx0 / magn + cx;
|
||||
fy0 = fy0 / magn + cy;
|
||||
|
||||
iter = 0; x = 0; y = 0;
|
||||
mu = 0;
|
||||
|
||||
while (((x*x + y*y) <= 32) && (iter < max_iterations)) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2*x*y + fy0;
|
||||
x = xtemp;
|
||||
mu += exp(-sqrt(x*x+y*y));
|
||||
iter++;
|
||||
}
|
||||
|
||||
if (iter == max_iterations) {
|
||||
// point corresponds to the mandelbrot set
|
||||
pixel_ptr[pixelOffset] = pixel_ptr[pixelOffset+1] = pixel_ptr[pixelOffset+2] = pixel_ptr[pixelOffset+3] = 255;
|
||||
return;
|
||||
}
|
||||
|
||||
int b = (int)(256*mu);
|
||||
int g = (b/8);
|
||||
int r = (g/16);
|
||||
|
||||
pixel_ptr[pixelOffset] = r>255 ? 255 : r;
|
||||
pixel_ptr[pixelOffset+1] = g>255 ? 255 : g;
|
||||
pixel_ptr[pixelOffset+2] = b>255 ? 255 : b;
|
||||
pixel_ptr[pixelOffset+3] = 255;
|
||||
}
|
||||
|
||||
public:
|
||||
color_fractal_cpu_node(opencl_graph &g) : my_graph(g), fractal_cpu_base_type(g),
|
||||
calculate_fractal( my_graph, unlimited, [&](fractal_data_t data) -> buffer_t {
|
||||
printf("color_fractal_cpu_node received %d\n", get<0>(data));
|
||||
opencl_buffer<cl_uchar> oclImage(g, tile_width*tile_height*channelsPerPixel);
|
||||
NDRange rangeList = { tile_width, tile_height };
|
||||
const int y0 = get<1>(data);
|
||||
const int x0 = get<0>(data);
|
||||
for(int y = y0; y < y0 + tile_height; ++y) {
|
||||
for(int x = x0; x < x0 + tile_width; ++x) {
|
||||
const int pixelOffset = ((y-y0) * tile_width + (x-x0)) * channelsPerPixel;
|
||||
calculate_pixel(oclImage.data(),pixelOffset,x,y,max_iterations,image_size,image_size, 400.0f, -.6f, .6f);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_tuple(oclImage, get<2>(data), rangeList);
|
||||
}) {
|
||||
set_external_ports(input_ports_type(calculate_fractal), output_ports_type(calculate_fractal));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class mono_fractal_gpu_node : public composite_node< tuple<fractal_gpu_data_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<fractal_gpu_data_t>, tuple<buffer_t> > fractal_gpu_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
|
||||
split_node<fractal_gpu_data_t> fractal_data_split;
|
||||
opencl_node<fractal_gpu_data_t> fractal_compute_node;
|
||||
join_node<buffer_t> image_join;
|
||||
|
||||
public:
|
||||
mono_fractal_gpu_node(opencl_graph &g, float shift) : my_graph(g), fractal_gpu_base_type(g),
|
||||
program(g, "fractal.cl"),
|
||||
fractal_compute_node(g, program.get_kernel("mono_mandelbrot")),
|
||||
image_join(g),
|
||||
fractal_data_split(g) {
|
||||
make_edge(output_port<0>(fractal_data_split), input_port<0>(fractal_compute_node));
|
||||
make_edge(output_port<1>(fractal_data_split), input_port<1>(fractal_compute_node));
|
||||
make_edge(output_port<2>(fractal_data_split), input_port<2>(fractal_compute_node));
|
||||
make_edge(output_port<3>(fractal_data_split), input_port<3>(fractal_compute_node));
|
||||
make_edge(output_port<4>(fractal_data_split), input_port<4>(fractal_compute_node));
|
||||
make_edge(output_port<5>(fractal_data_split), input_port<5>(fractal_compute_node));
|
||||
fractal_compute_node.set_args(port_ref<0>(), port_ref<1>(), port_ref<2>(), port_ref<3>(), port_ref<4>(), max_iterations, image_size, image_size, 400.0f, -.6f + shift, .6f);
|
||||
fractal_compute_node.set_range(port_ref<5>());
|
||||
make_edge(output_port<0>(fractal_compute_node), input_port<0>(image_join));
|
||||
make_edge(output_port<4>(fractal_compute_node), input_port<1>(image_join));
|
||||
make_edge(output_port<5>(fractal_compute_node), input_port<2>(image_join));
|
||||
set_external_ports(input_ports_type(fractal_data_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > stereo_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
split_node<buffer_t> left_split;
|
||||
split_node<buffer_t> right_split;
|
||||
|
||||
opencl_node< buffer_t > left_transform;
|
||||
opencl_node< buffer_t > right_transform;
|
||||
|
||||
opencl_node< merge_buffer_t > image_merge;
|
||||
join_node< buffer_t > image_join;
|
||||
|
||||
public:
|
||||
stereo_node(opencl_graph &g) : my_graph(g), stereo_base_type(g),
|
||||
program(g, "stereo.cl"),
|
||||
left_transform(g, program.get_kernel("applyLeftImageEffect")),
|
||||
right_transform(g, program.get_kernel("applyRightImageEffect")),
|
||||
image_merge(g, program.get_kernel("mergeImages")),
|
||||
image_join(g),
|
||||
right_split(g),
|
||||
left_split(g) {
|
||||
make_edge(output_port<0>(left_split), input_port<0>(left_transform));
|
||||
make_edge(output_port<1>(left_split), input_port<1>(left_transform));
|
||||
make_edge(output_port<2>(left_split), input_port<2>(left_transform));
|
||||
make_edge(output_port<0>(right_split), input_port<0>(right_transform));
|
||||
make_edge(output_port<1>(right_split), input_port<1>(right_transform));
|
||||
make_edge(output_port<2>(right_split), input_port<2>(right_transform));
|
||||
|
||||
make_edge(output_port<0>(left_transform), input_port<0>(image_merge));
|
||||
make_edge(output_port<0>(right_transform), input_port<1>(image_merge));
|
||||
make_edge(output_port<1>(left_transform), input_port<2>(image_merge));
|
||||
make_edge(output_port<2>(left_transform), input_port<3>(image_merge));
|
||||
|
||||
make_edge(output_port<0>(image_merge), input_port<0>(image_join));
|
||||
make_edge(output_port<2>(image_merge), input_port<1>(image_join));
|
||||
make_edge(output_port<3>(image_merge), input_port<2>(image_join));
|
||||
|
||||
left_transform.set_args(port_ref<0>(), tile_width);
|
||||
left_transform.set_range(port_ref<2>());
|
||||
|
||||
right_transform.set_args(port_ref<0>(), tile_width);
|
||||
right_transform.set_range(port_ref<2>());
|
||||
|
||||
image_merge.set_args(port_ref<0, 1>(), tile_width);
|
||||
image_merge.set_range(port_ref<3>());
|
||||
|
||||
set_external_ports(input_ports_type(left_split, right_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
void chooseTargetDevice(tbb::flow::opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const tbb::flow::opencl_device_list &devices = g.available_devices();
|
||||
tbb::flow::opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const tbb::flow::opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
|
||||
color_fractal_cpu_node render_fractal_cpu(g);
|
||||
mono_fractal_gpu_node render_left_fractal(g, -0.05f);
|
||||
mono_fractal_gpu_node render_right_fractal(g, 0.05f);
|
||||
stereo_node stereo(g);
|
||||
|
||||
std::string outputFile = "output";
|
||||
|
||||
source_node<fractal_data_t> tileSource(g, [&](fractal_data_t &v) -> bool {
|
||||
static int tag = 0;
|
||||
if ( tag < 4 ) {
|
||||
int x0 = 0, y0 = 0;
|
||||
|
||||
if (tag == 1 || tag == 3) x0 = 512;
|
||||
if (tag == 2 || tag == 3) y0 = 512;
|
||||
|
||||
v = std::make_tuple(x0, y0, tag);
|
||||
std::cout << "Hello from source node " << x0 << " ," << y0 << " ," << tag << std::endl;
|
||||
tag++;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
typedef multifunction_node< fractal_data_t, tuple< fractal_gpu_data_t, fractal_gpu_data_t, cl_uint > > stereo_mfn_t;
|
||||
stereo_mfn_t fractalInput(g, unlimited, [&]( const stereo_mfn_t::input_type &in, stereo_mfn_t::output_ports_type &ports ) {
|
||||
opencl_buffer<cl_uchar> oclImage1(g, tile_width*tile_height*channelsPerPixel);
|
||||
opencl_buffer<cl_uchar> oclImage2(g, tile_width*tile_height*channelsPerPixel);
|
||||
NDRange rangeList = { tile_width, tile_height };
|
||||
/* render left Image */
|
||||
get<0>(ports).try_put(std::make_tuple(oclImage1, get<0>(in), get<0>(in) + tile_width, get<1>(in), get<1>(in) + tile_height, rangeList ));
|
||||
/* redner right Image */
|
||||
get<1>(ports).try_put(std::make_tuple(oclImage2, get<0>(in), get<0>(in) + tile_width, get<1>(in), get<1>(in) + tile_height, rangeList ));
|
||||
/* forward tile-tag to token buffer */
|
||||
get<2>(ports).try_put(get<2>(in));
|
||||
});
|
||||
|
||||
typedef cl_uint token_t;
|
||||
typedef join_node< tuple<fractal_data_t, token_t>, reserving > rj_t;
|
||||
rj_t rj(g);
|
||||
|
||||
typedef multifunction_node< rj_t::output_type, tuple< fractal_data_t, fractal_data_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, []( const mfn_t::input_type &in, mfn_t::output_ports_type &ports ) {
|
||||
fractal_data_t d = get<0>(in);
|
||||
token_t tok = get<1>(in);
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(d);
|
||||
} else {
|
||||
get<1>(ports).try_put(d);
|
||||
}
|
||||
});
|
||||
|
||||
// generate token
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
make_edge(tileSource, input_port<0>(rj));
|
||||
make_edge(token_buffer, input_port<1>(rj));
|
||||
make_edge(rj, dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), render_fractal_cpu);
|
||||
make_edge(output_port<1>(dispatch_node), fractalInput);
|
||||
|
||||
static utils::image_buffer timeline;
|
||||
static utils::image_buffer image;
|
||||
|
||||
image.width = image_size;
|
||||
image.height = image_size;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(image.width * image.height * 4);
|
||||
timeline.width = 4 * tile_width;
|
||||
timeline.height = tile_height;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(timeline.width * timeline.height * 4);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, serial, [&](buffer_t b) {
|
||||
static int frame = 0;
|
||||
int tag = std::get<1>(b);
|
||||
|
||||
opencl_buffer<cl_uchar> tileBuffer = std::get<0>(b);
|
||||
const NDRange& imageSize = std::get<2>(b);
|
||||
unsigned int tile_width = imageSize[0];
|
||||
unsigned int tile_height = imageSize[1];
|
||||
|
||||
std::vector<unsigned char>& imageBuffer = *image.buffer;
|
||||
std::vector<unsigned char>& chronoBuffer = *timeline.buffer;
|
||||
|
||||
int x0 = 0, y0 = 0;
|
||||
|
||||
if (tag == 1 || tag == 3) x0 = 512;
|
||||
if (tag == 2 || tag == 3) y0 = 512;
|
||||
|
||||
for (unsigned y = y0; y < y0 + tile_height; y++) {
|
||||
/* over all rows */
|
||||
for (unsigned x = x0; x < x0 + tile_width; x++) {
|
||||
/* over all columns */
|
||||
for (unsigned i = 0; i < 4; ++i) {
|
||||
/* over all channels */
|
||||
imageBuffer.data()[4 * (image.width * y + x) + i] = tileBuffer.data()[4 * (tile_width * (y - y0) + (x - x0)) + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Hello from image node %d, %d, %d \n", x0, y0, tag);
|
||||
utils::writePNGImage(imageBuffer.data(), image.width, image.height, outputFile + std::to_string(frame) + ".png");
|
||||
frame++;
|
||||
return b;
|
||||
});
|
||||
|
||||
typedef join_node< tuple<buffer_t, cl_uint>, queueing > rj_token_t;
|
||||
|
||||
rj_token_t rj_gpu_token(g);
|
||||
|
||||
typedef multifunction_node< rj_token_t::output_type, tuple< buffer_t, token_t > > mfn_gpu_token_t;
|
||||
|
||||
mfn_gpu_token_t gpu_token_recycle(g, unlimited, [](const mfn_gpu_token_t::input_type &in, mfn_gpu_token_t::output_ports_type &ports) {
|
||||
const buffer_t& b = get<0>(in);
|
||||
const cl_uint& tag = get<1>(in);
|
||||
printf("Hello from token GPU recycler!");
|
||||
get<0>(ports).try_put(std::make_tuple( get<0>(b) ,tag , get<2>(b) ));
|
||||
get<1>(ports).try_put(token_t(1));
|
||||
});
|
||||
|
||||
make_edge( stereo, input_port<0>(rj_gpu_token)); // in: buffer_t
|
||||
make_edge( output_port<2>(fractalInput), input_port<1>(rj_gpu_token)); // in: token_t
|
||||
make_edge( rj_gpu_token, gpu_token_recycle); // in: buffer_t + token_t
|
||||
|
||||
make_edge( output_port<0>(gpu_token_recycle), image_display );
|
||||
make_edge( output_port<1>(gpu_token_recycle), token_buffer );
|
||||
|
||||
make_edge( output_port<0>(fractalInput), render_left_fractal);
|
||||
make_edge( output_port<1>(fractalInput), render_right_fractal);
|
||||
|
||||
make_edge( output_port<0>(render_left_fractal), input_port<0>(stereo));
|
||||
make_edge( output_port<0>(render_right_fractal), input_port<1>(stereo));
|
||||
|
||||
rj_token_t rj_cpu_token(g);
|
||||
|
||||
typedef multifunction_node< buffer_t, tuple< buffer_t, token_t > > mfn_cpu_token_t;
|
||||
mfn_cpu_token_t cpu_token_recycle(g, unlimited, [](const mfn_cpu_token_t::input_type &in, mfn_cpu_token_t::output_ports_type &ports) {
|
||||
const cl_uint& tag = get<1>(in);
|
||||
printf("Hello from token CPU recycler!");
|
||||
get<0>(ports).try_put(in);
|
||||
get<1>(ports).try_put(token_t(0));
|
||||
});
|
||||
|
||||
make_edge( render_fractal_cpu, cpu_token_recycle );
|
||||
|
||||
make_edge( output_port<0>(cpu_token_recycle), image_display );
|
||||
make_edge( output_port<1>(cpu_token_recycle), token_buffer );
|
||||
|
||||
printf("Beginning\n");
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
token_buffer.try_put(token_t(0));
|
||||
token_buffer.try_put(token_t(1));
|
||||
tileSource.activate();
|
||||
g.wait_for_all();
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
__constant int channelIncreaseValue = 10;
|
||||
|
||||
__kernel void mergeImages( __global uchar* bufferLeft, __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
bufferLeft[pixelGreenChannelIndex] = bufferRight[pixelGreenChannelIndex];
|
||||
bufferLeft[pixelBlueChannelIndex] = bufferRight[pixelBlueChannelIndex];
|
||||
}
|
||||
|
||||
__kernel void applyLeftImageEffect( __global uchar* bufferLeft, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelRedChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + redChannelOffset;
|
||||
|
||||
bufferLeft[pixelRedChannelIndex] = convert_uchar_sat(bufferLeft[pixelRedChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
__kernel void applyRightImageEffect( __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelBlueChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + blueChannelOffset;
|
||||
|
||||
bufferRight[pixelBlueChannelIndex] = convert_uchar_sat(bufferRight[pixelBlueChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "solution1", "solution1.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,163 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\solution01.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="..\..\common\input\input1.png" />
|
||||
<Image Include="..\..\common\input\input2.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>solution1</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc solution01.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
int main() {
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
graph g;
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
function_node<buffer_t, buffer_t> left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> right_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,blueChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join(g);
|
||||
|
||||
function_node<join_t::output_type, buffer_t> image_merge(g, unlimited, [](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, left_transform);
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_src, right_transform);
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
make_edge(image_merge, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "solution2", "solution2.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\common\lodepng.cpp" />
|
||||
<ClCompile Include="..\solution02.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\common\lodepng.h" />
|
||||
<ClInclude Include="..\..\common\utils.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>solution2</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc solution02.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > base_type;
|
||||
graph &my_graph;
|
||||
function_node<buffer_t, buffer_t> left_transform;
|
||||
function_node<buffer_t, buffer_t> right_transform;
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join;
|
||||
function_node<join_t::output_type, buffer_t> image_merge;
|
||||
|
||||
public:
|
||||
stereo_node(graph &g) : my_graph(g), base_type(g),
|
||||
left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
right_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,blueChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
image_join(g),
|
||||
image_merge(g, unlimited,
|
||||
[](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
}) {
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
set_external_ports(input_ports_type(left_transform, right_transform), output_ports_type(image_merge));
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
graph g;
|
||||
|
||||
#if _MSC_VER
|
||||
std::string inputFileFirst = "../../common/input/input1.png";
|
||||
std::string inputFileSecond = "../../common/input/input2.png";
|
||||
#else
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
#endif
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2017 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
run_cmd=
|
||||
PROG=stereo
|
||||
ARGS=
|
||||
PERF_RUN_ARGS=
|
||||
|
||||
# icpc by default
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icpc
|
||||
endif
|
||||
|
||||
# autodetect C++11 support
|
||||
include ../../common/examples-common.inc
|
||||
|
||||
# TBB libs
|
||||
TBBLIB=-ltbb
|
||||
TBBLIB_DEBUG=-ltbb_debug
|
||||
|
||||
# OpenCL lib
|
||||
OPENCL_LIB=-lOpenCL
|
||||
|
||||
ifeq ($(shell uname), Linux)
|
||||
ifeq ($(target), android)
|
||||
LIBS+= --sysroot=$(SYSROOT)
|
||||
run_cmd=../../common/android.linux.launcher.sh
|
||||
else
|
||||
LIBS+= -lrt
|
||||
endif
|
||||
else
|
||||
ifeq ($(shell uname),Darwin)
|
||||
override CXXFLAGS += -Wl,-rpath,$(TBBROOT)/lib
|
||||
override OPENCL_LIB=-framework OpenCL
|
||||
endif
|
||||
endif
|
||||
|
||||
all: release test
|
||||
|
||||
release: *.cpp
|
||||
$(CXX) -O2 -DNDEBUG $(CXXFLAGS) -o $(PROG) $^ ../common/lodepng.cpp -I../common $(TBBLIB) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
debug: *.cpp
|
||||
$(CXX) -O0 -g -DTBB_USE_DEBUG $(CXXFLAGS) -o $(PROG) $^ $(TBBLIB_DEBUG) $(OPENCL_LIB) $(LIBS) $(CXX0XFLAGS)
|
||||
|
||||
clean:
|
||||
$(RM) $(PROG) *.o *.d
|
||||
|
||||
test:
|
||||
$(run_cmd) ./$(PROG) $(ARGS)
|
||||
|
||||
perf_build: release
|
||||
|
||||
perf_run:
|
||||
$(run_cmd) ./$(PROG) $(PERF_RUN_ARGS)
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__kernel void print( global char *str ) {
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("GPU!\n");
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "solution3", "solution3.vcxproj", "{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Debug|x64.Build.0 = Debug|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|Win32.Build.0 = Release|Win32
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.ActiveCfg = Release|x64
|
||||
{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,169 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\hello_world.cl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\solution03.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9C777D75-70FF-4C24-AB74-EBCDF3328AB9}</ProjectGuid>
|
||||
<RootNamespace>solution3</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\</OutDir>
|
||||
<IntDir>$(SolutionDir)$(Platform)\$(ProjectName)\$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x86;$(TBBROOT)\lib\ia32\vc_mt;$(TBBROOT)\lib\ia32\vc12;$(SolutionDir)\..\..\..\..\lib\ia32\vc_mt;$(SolutionDir)\..\..\..\..\lib\ia32\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)..\..\..\..\include;$(INTELOCLSDKROOT)include;$(TBBROOT)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_MBCS;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(INTELOCLSDKROOT)lib\x64;$(TBBROOT)\lib\intel64\vc_mt;$(TBBROOT)\lib\intel64\vc12;$(SolutionDir)\..\..\..\..\lib\intel64\vc_mt;$(SolutionDir)\..\..\..\..\lib\intel64\vc12;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>tbb.lib;tbb_preview.lib;OpenCL.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>xcopy "$(ProjectDir)..\*.cl" "$(ProjectDir)" /Y /I</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
Linux: icpc solution03.cpp -o hello_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc solution03.cpp -o hello_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
*/
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include <cstdio>
|
||||
|
||||
void chooseTargetDevice(opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
typedef opencl_buffer<cl_char> buffer_t;
|
||||
typedef int token_t;
|
||||
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
opencl_program<> program(g, "hello_world.cl");
|
||||
opencl_node<tuple<buffer_t>> gpu_node(g, program.get_kernel("print"));
|
||||
std::array<unsigned int, 1> range{1};
|
||||
gpu_node.set_range(range);
|
||||
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
typedef multifunction_node< token_t, tuple< buffer_t, buffer_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, [&]( const token_t &in, mfn_t::output_ports_type &ports ) {
|
||||
token_t tok = in;
|
||||
const char str[] = "Hello from ";
|
||||
buffer_t b( g, sizeof(str) );
|
||||
std::copy_n( str, sizeof(str), b.begin() );
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(b);
|
||||
} else {
|
||||
get<1>(ports).try_put(b);
|
||||
}
|
||||
});
|
||||
|
||||
function_node<buffer_t, token_t> cpu_node(g,unlimited,[](buffer_t b) {
|
||||
char *str = (char*)b.begin();
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("CPU!\n");
|
||||
return token_t(0);
|
||||
});
|
||||
|
||||
make_edge(token_buffer,dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), cpu_node);
|
||||
make_edge(output_port<1>(dispatch_node), gpu_node);
|
||||
|
||||
printf("Beginning\n");
|
||||
|
||||
token_buffer.try_put(token_t(0));
|
||||
token_buffer.try_put(token_t(1));
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
#if _MSC_VER
|
||||
getchar();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.pdb" "%output_dir%"
|
||||
copy "%TBBROOT%\%interim_lib_path%\%vc_dir%\tbb%postfix%.lib" "%output_dir%"
|
||||
|
||||
:: Copying DAT-file
|
||||
echo Using DAT-file %dat_file%
|
||||
echo Using DAT-file %dat_file%
|
||||
if exist %dat_file% copy %dat_file% "%output_dir%\Assets\balls.dat"
|
||||
|
||||
goto end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.40629.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tbbTachyon", "tbbTachyon.vcxproj", "{E20CB432-6730-4021-A372-1C81A333518A}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E6DDEA39-7910-47F9-A0E3-56AD7E62ACBD}"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
@@ -30,27 +30,27 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<UseIntelTBB>true</UseIntelTBB>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<UseIntelTBB>true</UseIntelTBB>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<UseIntelTBB>true</UseIntelTBB>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<UseIntelTBB>true</UseIntelTBB>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
@@ -236,4 +236,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Page Include="Common\StandardStyles.xaml">
|
||||
<Filter>Resources\Common</Filter>
|
||||
@@ -212,4 +212,4 @@
|
||||
<Filter>Frontend</Filter>
|
||||
</AppxManifest>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
Copyright (c) 2012-2014 MIT CSAIL, Google Inc., and other contributors
|
||||
|
||||
Developed by:
|
||||
|
||||
The Halide team
|
||||
http://halide-lang.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
Copyright (c) 2005-2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "lodepng.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
struct image_buffer {
|
||||
unsigned int width, height;
|
||||
std::shared_ptr< std::vector<unsigned char> > buffer; // smart pointer to the vector of raw pixels in RGBA format, 4 bytes per pixel
|
||||
};
|
||||
|
||||
image_buffer readPNGImage(const std::string& imageName) {
|
||||
image_buffer image;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >();
|
||||
|
||||
unsigned int error = lodepng::decode(*image.buffer, image.width, image.height, imageName.c_str());
|
||||
|
||||
if (error) {
|
||||
std::string exceptionMessage = "decoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
void readPNGImage(unsigned char* imageBuffer, unsigned int& width, unsigned int& height, const char* imageName) {
|
||||
unsigned int error = lodepng_decode32_file(&imageBuffer, &width, &height, imageName);
|
||||
|
||||
if (error) {
|
||||
std::string exceptionMessage = "decoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void writePNGImage(const image_buffer& image, const std::string& outputFile) {
|
||||
unsigned int error = lodepng::encode(outputFile, *image.buffer, image.width, image.height);
|
||||
if (error) {
|
||||
std::string exceptionMessage = "encoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void writePNGImage(unsigned char* imageBuffer, unsigned int& width, unsigned int& height, const std::string& outputFile) {
|
||||
unsigned int error = lodepng::encode(outputFile, imageBuffer, width, height);
|
||||
if (error) {
|
||||
std::string exceptionMessage = "encoder error: " + std::string(lodepng_error_text(error));
|
||||
throw std::runtime_error(exceptionMessage);
|
||||
}
|
||||
}
|
||||
|
||||
image_buffer generatePNGImage() {
|
||||
image_buffer image;
|
||||
image.width = 1024;
|
||||
image.height = 1024;
|
||||
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(image.width * image.height * 4);
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
const int widthOffset = 4 * image.width;
|
||||
for (unsigned y = 0; y < image.height; y++) {
|
||||
for (unsigned x = 0; x < image.width; x++) {
|
||||
const int pixelOffset = widthOffset * y + 4 * x;
|
||||
buffer[pixelOffset] = 200 * !(x & y);
|
||||
buffer[pixelOffset + 1] = x ^ y;
|
||||
buffer[pixelOffset + 2] = x | y;
|
||||
buffer[pixelOffset + 3] = 255;
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
bool isFileExist(const std::string& fileName) {
|
||||
std::ifstream file(fileName);
|
||||
return file.good();
|
||||
}
|
||||
|
||||
bool isBothImagesExists(const std::string& firstFile, const std::string& secondFile) {
|
||||
return isFileExist(firstFile) && isFileExist(secondFile);
|
||||
}
|
||||
|
||||
image_buffer getOrGenerateImage(const std::string& fileName) {
|
||||
return fileName.empty() ? generatePNGImage() : readPNGImage(fileName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
"icpc stereo-serial.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../"
|
||||
|
||||
Simple image processing example to start with
|
||||
First task: execute example and note execution time.
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(std::min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
buffer_t leftImageBuffer = utils::getOrGenerateImage(inputFileFirst);
|
||||
buffer_t rightImageBuffer = utils::getOrGenerateImage(inputFileSecond);
|
||||
|
||||
applyImageEffect(leftImageBuffer,redChannelOffset);
|
||||
applyImageEffect(rightImageBuffer,blueChannelOffset);
|
||||
|
||||
mergeImageBuffers(leftImageBuffer, rightImageBuffer);
|
||||
|
||||
utils::writePNGImage(rightImageBuffer, outputFile);
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc exercise01.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(std::min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges two image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
int main() {
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
graph g;
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
//function node to apply red filter to left image
|
||||
function_node<buffer_t, buffer_t> left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
/* TODO: insert function node to implement blue filter on right image */
|
||||
|
||||
|
||||
|
||||
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join(g);
|
||||
|
||||
function_node<join_t::output_type, buffer_t> image_merge(g, unlimited, [](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, left_transform);
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
/* TODO: make edges.
|
||||
right_src -> right_transform);
|
||||
right_transform -> input_port<1>(image_join);
|
||||
image_join -> image_merge;
|
||||
image_merge -> image_display;
|
||||
*/
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc solution01.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(std::min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
int main() {
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
graph g;
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
function_node<buffer_t, buffer_t> left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> right_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,blueChannelOffset);
|
||||
return b;
|
||||
});
|
||||
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join(g);
|
||||
|
||||
function_node<join_t::output_type, buffer_t> image_merge(g, unlimited, [](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
});
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, left_transform);
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_src, right_transform);
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
make_edge(image_merge, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Your task is to complete the composite node, which encapsulates the functionality from previous exercises.
|
||||
|
||||
Build instructions:
|
||||
icpc exercise02.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(std::min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > base_type;
|
||||
graph &my_graph;
|
||||
function_node<buffer_t, buffer_t> left_transform;
|
||||
function_node<buffer_t, buffer_t> right_transform;
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join;
|
||||
function_node<join_t::output_type, buffer_t> image_merge;
|
||||
|
||||
public:
|
||||
stereo_node(graph &g) : my_graph(g), base_type(g),
|
||||
left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
right_transform(g,unlimited,[](buffer_t b) {
|
||||
/* TODO: apply right image effect */
|
||||
return b;
|
||||
}),
|
||||
image_join(g),
|
||||
image_merge(g, unlimited,
|
||||
[](const join_t::output_type &in) -> buffer_t {
|
||||
/* TODO: merge left and right image. Hint: see last exercise */
|
||||
buffer_t right = get<1>(in);
|
||||
|
||||
return right;
|
||||
}) {
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
set_external_ports(input_ports_type(left_transform, right_transform), output_ports_type(image_merge));
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
graph g;
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
icpc solution02.cpp ../common/lodepng.cpp -o stereo -ltbb_preview -std=c++11 -I../
|
||||
|
||||
Begin: Duplicate preamble from previous exercise */
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
void applyImageEffect(buffer_t& image, const int channelOffset) {
|
||||
const int heighBase = channelsPerPixel * image.width;
|
||||
std::vector<unsigned char>& buffer = *image.buffer;
|
||||
|
||||
// Increase selected color channel by a predefined value
|
||||
for (unsigned int y = 0; y < image.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < image.width; x++) {
|
||||
int pixelOffset = heightOffset + channelsPerPixel * x + channelOffset;
|
||||
buffer[pixelOffset] = static_cast<uint8_t>(std::min(buffer[pixelOffset] + channelIncreaseValue, 255));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function merges to image buffers into the first buffer (leftImageBuffer as a destination)
|
||||
void mergeImageBuffers(buffer_t& leftImage, const buffer_t& rightImage) {
|
||||
const int heighBase = channelsPerPixel * leftImage.width;
|
||||
std::vector<unsigned char>& leftImageBuffer = *leftImage.buffer;
|
||||
std::vector<unsigned char>& rightImageBuffer = *rightImage.buffer;
|
||||
|
||||
// Apply stereoscopic merge using algorithm: R: left image, G:, B: right image
|
||||
for (unsigned int y = 0; y < leftImage.height; y++) {
|
||||
const int heightOffset = heighBase * y;
|
||||
for (unsigned int x = 0; x < leftImage.width; x++) {
|
||||
const int pixelOffset = heightOffset + channelsPerPixel * x;
|
||||
const int redChannelIndex = pixelOffset + redChannelOffset;
|
||||
rightImageBuffer[redChannelIndex] = leftImageBuffer[redChannelIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* End: Duplicate from previous exercise */
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > base_type;
|
||||
graph &my_graph;
|
||||
function_node<buffer_t, buffer_t> left_transform;
|
||||
function_node<buffer_t, buffer_t> right_transform;
|
||||
typedef join_node< tuple<buffer_t, buffer_t>, queueing > join_t;
|
||||
join_t image_join;
|
||||
function_node<join_t::output_type, buffer_t> image_merge;
|
||||
|
||||
public:
|
||||
stereo_node(graph &g) : my_graph(g), base_type(g),
|
||||
left_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,redChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
right_transform(g,unlimited,[](buffer_t b) {
|
||||
applyImageEffect(b,blueChannelOffset);
|
||||
return b;
|
||||
}),
|
||||
image_join(g),
|
||||
image_merge(g, unlimited,
|
||||
[](const join_t::output_type &in) -> buffer_t {
|
||||
buffer_t left = get<0>(in);
|
||||
buffer_t right = get<1>(in);
|
||||
mergeImageBuffers(left, right);
|
||||
return right;
|
||||
}) {
|
||||
make_edge(left_transform, input_port<0>(image_join));
|
||||
make_edge(right_transform, input_port<1>(image_join));
|
||||
make_edge(image_join, image_merge);
|
||||
set_external_ports(input_ports_type(left_transform, right_transform), output_ports_type(image_merge));
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
graph g;
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileFirst);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
v = utils::getOrGenerateImage(inputFileSecond);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
utils::writePNGImage(b, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
Linux: icpc exercise03.cpp -o hello_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc exercise03.cpp -o hello_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
*/
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include <cstdio>
|
||||
|
||||
void chooseTargetDevice(opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
typedef opencl_buffer<cl_char> buffer_t;
|
||||
typedef int token_t;
|
||||
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
opencl_program<> program(g, "hello_world.cl");
|
||||
opencl_node<tuple<buffer_t>> gpu_node(g, program.get_kernel("print"));
|
||||
std::array<unsigned int, 1> range{1};
|
||||
gpu_node.set_range(range);
|
||||
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
typedef multifunction_node< token_t, tuple< buffer_t, buffer_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, [&]( const token_t &in, mfn_t::output_ports_type &ports ) {
|
||||
token_t tok = in;
|
||||
const char str[] = "Hello from ";
|
||||
buffer_t b( g, sizeof(str) );
|
||||
std::copy_n( str, sizeof(str), b.begin() );
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(b);
|
||||
} else {
|
||||
get<1>(ports).try_put(b);
|
||||
}
|
||||
});
|
||||
|
||||
function_node<buffer_t, token_t> cpu_node(g,unlimited,[](buffer_t b) {
|
||||
char *str = (char*)b.begin();
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("CPU!\n");
|
||||
return token_t(0);
|
||||
});
|
||||
|
||||
make_edge(token_buffer,dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), cpu_node);
|
||||
make_edge(output_port<1>(dispatch_node), gpu_node);
|
||||
|
||||
printf("Beginning\n");
|
||||
|
||||
/* feed two token into the graph to trigger both gpu and cpu print "Hello World!" */
|
||||
|
||||
|
||||
g.wait_for_all();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__kernel void print( global char *str ) {
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("GPU!\n");
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* Build instructions:
|
||||
Linux: icpc solution03.cpp -o hello_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc solution03.cpp -o hello_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
*/
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include <cstdio>
|
||||
|
||||
void chooseTargetDevice(opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
typedef opencl_buffer<cl_char> buffer_t;
|
||||
typedef int token_t;
|
||||
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
opencl_program<> program(g, "hello_world.cl");
|
||||
opencl_node<tuple<buffer_t>> gpu_node(g, program.get_kernel("print"));
|
||||
std::array<unsigned int, 1> range{1};
|
||||
gpu_node.set_range(range);
|
||||
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
typedef multifunction_node< token_t, tuple< buffer_t, buffer_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, [&]( const token_t &in, mfn_t::output_ports_type &ports ) {
|
||||
token_t tok = in;
|
||||
const char str[] = "Hello from ";
|
||||
buffer_t b( g, sizeof(str) );
|
||||
std::copy_n( str, sizeof(str), b.begin() );
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(b);
|
||||
} else {
|
||||
get<1>(ports).try_put(b);
|
||||
}
|
||||
});
|
||||
|
||||
function_node<buffer_t, token_t> cpu_node(g,unlimited,[](buffer_t b) {
|
||||
char *str = (char*)b.begin();
|
||||
for ( ; *str; ++str ) printf("%c", *str);
|
||||
printf("CPU!\n");
|
||||
return token_t(0);
|
||||
});
|
||||
|
||||
make_edge(token_buffer,dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), cpu_node);
|
||||
make_edge(output_port<1>(dispatch_node), gpu_node);
|
||||
|
||||
printf("Beginning\n");
|
||||
|
||||
token_buffer.try_put(token_t(0));
|
||||
token_buffer.try_put(token_t(1));
|
||||
|
||||
g.wait_for_all();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Task: compile, run and compare resulting runtime to previous version of stereo.
|
||||
|
||||
Build instructions:
|
||||
Linux: icpc exercise04.cpp ../common/lodepng.cpp -o stereo_cl -ltbb_preview -std=c++11 -lOpenCL
|
||||
MacOS: icpc exercise04.cpp ../common/lodepng.cpp -o stereo_cl -ltbb_preview -std=c++11 -framework OpenCL
|
||||
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
/* Begin: Duplicate preamble from previous stereo exercise
|
||||
|
||||
#include "tbb/tbb.h"
|
||||
|
||||
typedef utils::image_buffer buffer_t;
|
||||
|
||||
static const int redChannelOffset = 0;
|
||||
static const int greenChannelOffset = 1;
|
||||
static const int blueChannelOffset = 2;
|
||||
static const int channelsPerPixel = 4;
|
||||
static const int channelIncreaseValue = 10;
|
||||
|
||||
End: Duplicate from previous exercise */
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
#include "tbb/tick_count.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
typedef opencl_buffer<cl_uchar> OpenclImageBuffer;
|
||||
typedef std::array<unsigned int, 2> NDRange;
|
||||
typedef tuple< OpenclImageBuffer, cl_uint, NDRange > buffer_t;
|
||||
typedef tuple< OpenclImageBuffer, OpenclImageBuffer, cl_uint, NDRange > merge_buffer_t;
|
||||
|
||||
void fillOpenclBuffer(tbb::flow::opencl_buffer<cl_uchar>& openclBuffer, const std::vector<unsigned char>& sourceBuffer) {
|
||||
std::copy(sourceBuffer.begin(), sourceBuffer.end(), openclBuffer.begin());
|
||||
}
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > stereo_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
split_node<buffer_t> left_split;
|
||||
split_node<buffer_t> right_split;
|
||||
|
||||
opencl_node< buffer_t > left_transform;
|
||||
opencl_node< buffer_t > right_transform;
|
||||
|
||||
opencl_node< merge_buffer_t > image_merge;
|
||||
join_node< buffer_t > image_join;
|
||||
|
||||
public:
|
||||
stereo_node(opencl_graph &g) : my_graph(g), stereo_base_type(g),
|
||||
program(g, "stereo.cl"),
|
||||
left_transform(g, program.get_kernel("applyLeftImageEffect")),
|
||||
right_transform(g, program.get_kernel("applyRightImageEffect")),
|
||||
image_merge(g, program.get_kernel("mergeImages")),
|
||||
image_join(g),
|
||||
right_split(g),
|
||||
left_split(g) {
|
||||
make_edge(output_port<0>(left_split), input_port<0>(left_transform));
|
||||
make_edge(output_port<1>(left_split), input_port<1>(left_transform));
|
||||
make_edge(output_port<2>(left_split), input_port<2>(left_transform));
|
||||
make_edge(output_port<0>(right_split), input_port<0>(right_transform));
|
||||
make_edge(output_port<1>(right_split), input_port<1>(right_transform));
|
||||
make_edge(output_port<2>(right_split), input_port<2>(right_transform));
|
||||
|
||||
make_edge(output_port<0>(left_transform), input_port<0>(image_merge));
|
||||
make_edge(output_port<0>(right_transform), input_port<1>(image_merge));
|
||||
make_edge(output_port<1>(left_transform), input_port<2>(image_merge));
|
||||
make_edge(output_port<2>(left_transform), input_port<3>(image_merge));
|
||||
|
||||
make_edge(output_port<0>(image_merge), input_port<0>(image_join));
|
||||
make_edge(output_port<2>(image_merge), input_port<1>(image_join));
|
||||
make_edge(output_port<3>(image_merge), input_port<2>(image_join));
|
||||
|
||||
left_transform.set_args(port_ref<0, 1>());
|
||||
left_transform.set_range(port_ref<2>());
|
||||
|
||||
right_transform.set_args(port_ref<0, 1>());
|
||||
right_transform.set_range(port_ref<2>());
|
||||
|
||||
image_merge.set_args(port_ref<0, 2>());
|
||||
image_merge.set_range(port_ref<3>());
|
||||
|
||||
set_external_ports(input_ports_type(left_split, right_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
void chooseTargetDevice(tbb::flow::opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const opencl_device_list &devices = g.available_devices();
|
||||
opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
|
||||
std::string inputFileFirst = "../common/input/input1.png";
|
||||
std::string inputFileSecond = "../common/input/input2.png";
|
||||
std::string outputFile = "output.png";
|
||||
|
||||
const int left_limit = 2;
|
||||
int l = 1;
|
||||
source_node<buffer_t> left_src(g, [&](buffer_t &v) -> bool {
|
||||
if (l < left_limit) {
|
||||
utils::image_buffer src = utils::getOrGenerateImage(inputFileFirst);
|
||||
// Create and initialize opencl_buffer in order to pass it to mergeImages kernel
|
||||
OpenclImageBuffer oclImage(g, src.buffer->size());
|
||||
fillOpenclBuffer(oclImage, *src.buffer);
|
||||
NDRange rangeList = { src.width, src.height };
|
||||
v = std::make_tuple(oclImage, src.width, rangeList);
|
||||
l++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
const int right_limit = 3;
|
||||
int r = 2;
|
||||
source_node<buffer_t> right_src(g, [&](buffer_t &v) -> bool {
|
||||
if (r < right_limit) {
|
||||
utils::image_buffer src = utils::getOrGenerateImage(inputFileSecond);
|
||||
// Create and initialize opencl_buffer in order to pass it to mergeImages kernel
|
||||
OpenclImageBuffer oclImage(g, src.buffer->size());
|
||||
fillOpenclBuffer(oclImage, *src.buffer);
|
||||
NDRange rangeList = { src.width, src.height };
|
||||
v = std::make_tuple(oclImage, src.width, rangeList);
|
||||
r++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
stereo_node stereo(g);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, unlimited, [&](buffer_t b) {
|
||||
// The result image have to be copied in order to be changed,
|
||||
// the second parameter - image size, can be taken by const reference
|
||||
OpenclImageBuffer imageBuffer = std::get<0>(b);
|
||||
const NDRange& imageSize = std::get<2>(b);
|
||||
unsigned int width = imageSize[0];
|
||||
unsigned int height = imageSize[1];
|
||||
|
||||
utils::writePNGImage(imageBuffer.data(), width, height, outputFile);
|
||||
return b;
|
||||
});
|
||||
|
||||
make_edge(left_src, input_port<0>(stereo));
|
||||
make_edge(right_src, input_port<1>(stereo));
|
||||
make_edge(stereo, image_display);
|
||||
|
||||
std::cout << "Beginning" << std::endl;
|
||||
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
|
||||
left_src.activate();
|
||||
right_src.activate();
|
||||
|
||||
g.wait_for_all();
|
||||
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
__constant int channelIncreaseValue = 10;
|
||||
|
||||
__kernel void mergeImages( __global uchar* bufferLeft, __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
bufferLeft[pixelGreenChannelIndex] = bufferRight[pixelGreenChannelIndex];
|
||||
bufferLeft[pixelBlueChannelIndex] = bufferRight[pixelBlueChannelIndex];
|
||||
}
|
||||
|
||||
__kernel void applyLeftImageEffect( __global uchar* bufferLeft, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelRedChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + redChannelOffset;
|
||||
|
||||
bufferLeft[pixelRedChannelIndex] = convert_uchar_sat(bufferLeft[pixelRedChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
__kernel void applyRightImageEffect( __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelBlueChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + blueChannelOffset;
|
||||
|
||||
bufferRight[pixelBlueChannelIndex] = convert_uchar_sat(bufferRight[pixelBlueChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
|
||||
uchar calc_one_pixel(float x0, float y0, int max_iterations, int size_x, int size_y, float magn, float cx, float cy, int gpu)
|
||||
{
|
||||
int iter;
|
||||
float fx0, fy0, xtemp, x, y, mu;
|
||||
|
||||
uchar color;
|
||||
|
||||
fx0 = x0 - size_x / 2.0f;
|
||||
fy0 = y0 - size_y / 2.0f;
|
||||
fx0 = fx0 / magn + cx;
|
||||
fy0 = fy0 / magn + cy;
|
||||
|
||||
iter = 0; x = 0; y = 0;
|
||||
|
||||
while ( ((x*x + y*y) <= 32) && (iter < max_iterations) ) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2 * x*y + fy0;
|
||||
x = xtemp;
|
||||
iter++;
|
||||
}
|
||||
|
||||
if ( iter == max_iterations ) {
|
||||
// point corresponds to the Mandelbrot set
|
||||
return 0;
|
||||
}
|
||||
|
||||
// compute again but with exponent calculation at each iteration
|
||||
// it's all for coloring point outside the Mandelbrot set
|
||||
iter = 0; x = 0; y = 0;
|
||||
mu = 0;
|
||||
|
||||
while ( ((x*x + y*y) <= 32) && (iter < max_iterations) ) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2 * x*y + fy0;
|
||||
x = xtemp;
|
||||
mu += exp(-sqrt(x*x + y*y));
|
||||
iter++;
|
||||
}
|
||||
|
||||
const uint b = convert_uint_sat(256 * mu);
|
||||
const uint g = (b / 8);
|
||||
const uint r = (g / 16);
|
||||
|
||||
const uchar gray = convert_uchar_sat(0.21f * r + 0.72f * g + 0.07f * b);
|
||||
return gray;
|
||||
}
|
||||
|
||||
__kernel void mono_mandelbrot( __global uchar* fractal_data_array, uint x0, uint x1, uint y0, uint y1, uint max_iterations, uint size_x, uint size_y, float magn, float cx, float cy) {
|
||||
const int x = get_global_id(0) + x0;
|
||||
const int y = get_global_id(1) + y0;
|
||||
|
||||
const int pixelIndex = channelsPerPixel * (x1 - x0) * (y - y0) + channelsPerPixel * (x - x0);
|
||||
const int pixelRedChannelIndex = pixelIndex + redChannelOffset;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
fractal_data_array[pixelRedChannelIndex] = fractal_data_array[pixelGreenChannelIndex] = fractal_data_array[pixelBlueChannelIndex] = calc_one_pixel(x, y, max_iterations, size_x, size_y, magn, cx, cy, 255);
|
||||
fractal_data_array[pixelIndex + 3] = 255;
|
||||
}
|
||||
@@ -0,0 +1,375 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "../../common/utility/utility.h"
|
||||
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_NODES 1
|
||||
#define TBB_PREVIEW_FLOW_GRAPH_FEATURES 1
|
||||
|
||||
#include "tbb/flow_graph.h"
|
||||
#include "tbb/flow_graph_opencl_node.h"
|
||||
#include "tbb/tick_count.h"
|
||||
|
||||
#include "../common/utils.h"
|
||||
|
||||
using namespace tbb;
|
||||
using namespace tbb::flow;
|
||||
|
||||
typedef std::array<unsigned int, 2> NDRange;
|
||||
typedef tuple< cl_uint, cl_uint, cl_uint > fractal_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, cl_uint, cl_uint, cl_uint > fractal_cpu_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, cl_uint, cl_uint, cl_uint, NDRange > fractal_gpu_data_t;
|
||||
typedef tuple< opencl_buffer<cl_uchar>, cl_uint, NDRange > buffer_t;
|
||||
|
||||
typedef tuple< opencl_buffer<cl_uchar>, opencl_buffer<cl_uchar>, cl_uint, NDRange > merge_buffer_t;
|
||||
|
||||
static const int image_size = 1024;
|
||||
static const int max_iterations = 256;
|
||||
|
||||
static const int divider = 2;
|
||||
static const int tile_width = image_size/divider;
|
||||
static const int tile_height = image_size/divider;
|
||||
|
||||
static const int channelsPerPixel = 4;
|
||||
|
||||
class color_fractal_cpu_node : public composite_node< tuple<fractal_data_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<fractal_data_t>, tuple<buffer_t> > fractal_cpu_base_type;
|
||||
opencl_graph &my_graph;
|
||||
function_node<fractal_data_t, buffer_t> calculate_fractal;
|
||||
|
||||
void calculate_pixel(unsigned char * pixel_ptr, int pixelOffset, int x0, int y0, int max_iterations, int size_x,int size_y, float magn, float cx, float cy) {
|
||||
unsigned int iter;
|
||||
double fx0, fy0, xtemp, x, y, mu;
|
||||
|
||||
fx0 = (double)x0 - (double) size_x / 2.0;
|
||||
fy0 = (double)y0 - (double) size_y / 2.0;
|
||||
fx0 = fx0 / magn + cx;
|
||||
fy0 = fy0 / magn + cy;
|
||||
|
||||
iter = 0; x = 0; y = 0;
|
||||
mu = 0;
|
||||
|
||||
while (((x*x + y*y) <= 32) && (iter < max_iterations)) {
|
||||
xtemp = x*x - y*y + fx0;
|
||||
y = 2*x*y + fy0;
|
||||
x = xtemp;
|
||||
mu += exp(-sqrt(x*x+y*y));
|
||||
iter++;
|
||||
}
|
||||
|
||||
if (iter == max_iterations) {
|
||||
// point corresponds to the mandelbrot set
|
||||
pixel_ptr[pixelOffset] = pixel_ptr[pixelOffset+1] = pixel_ptr[pixelOffset+2] = pixel_ptr[pixelOffset+3] = 255;
|
||||
return;
|
||||
}
|
||||
|
||||
int b = (int)(256*mu);
|
||||
int g = (b/8);
|
||||
int r = (g/16);
|
||||
|
||||
pixel_ptr[pixelOffset] = r>255 ? 255 : r;
|
||||
pixel_ptr[pixelOffset+1] = g>255 ? 255 : g;
|
||||
pixel_ptr[pixelOffset+2] = b>255 ? 255 : b;
|
||||
pixel_ptr[pixelOffset+3] = 255;
|
||||
}
|
||||
|
||||
public:
|
||||
color_fractal_cpu_node(opencl_graph &g) : my_graph(g), fractal_cpu_base_type(g),
|
||||
calculate_fractal( my_graph, unlimited, [&](fractal_data_t data) -> buffer_t {
|
||||
printf("color_fractal_cpu_node received %d\n", get<0>(data));
|
||||
opencl_buffer<cl_uchar> oclImage(g, tile_width*tile_height*channelsPerPixel);
|
||||
NDRange rangeList = { tile_width, tile_height };
|
||||
const int y0 = get<1>(data);
|
||||
const int x0 = get<0>(data);
|
||||
for(int y = y0; y < y0 + tile_height; ++y) {
|
||||
for(int x = x0; x < x0 + tile_width; ++x) {
|
||||
const int pixelOffset = ((y-y0) * tile_width + (x-x0)) * channelsPerPixel;
|
||||
calculate_pixel(oclImage.data(),pixelOffset,x,y,max_iterations,image_size,image_size, 400.0f, -.6f, .6f);
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_tuple(oclImage, get<2>(data), rangeList);
|
||||
}) {
|
||||
set_external_ports(input_ports_type(calculate_fractal), output_ports_type(calculate_fractal));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class mono_fractal_gpu_node : public composite_node< tuple<fractal_gpu_data_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<fractal_gpu_data_t>, tuple<buffer_t> > fractal_gpu_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
|
||||
split_node<fractal_gpu_data_t> fractal_data_split;
|
||||
opencl_node<fractal_gpu_data_t> fractal_compute_node;
|
||||
join_node<buffer_t> image_join;
|
||||
|
||||
public:
|
||||
mono_fractal_gpu_node(opencl_graph &g, float shift) : my_graph(g), fractal_gpu_base_type(g),
|
||||
program(g, "fractal.cl"),
|
||||
fractal_compute_node(g, program.get_kernel("mono_mandelbrot")),
|
||||
image_join(g),
|
||||
fractal_data_split(g) {
|
||||
make_edge(output_port<0>(fractal_data_split), input_port<0>(fractal_compute_node));
|
||||
make_edge(output_port<1>(fractal_data_split), input_port<1>(fractal_compute_node));
|
||||
make_edge(output_port<2>(fractal_data_split), input_port<2>(fractal_compute_node));
|
||||
make_edge(output_port<3>(fractal_data_split), input_port<3>(fractal_compute_node));
|
||||
make_edge(output_port<4>(fractal_data_split), input_port<4>(fractal_compute_node));
|
||||
make_edge(output_port<5>(fractal_data_split), input_port<5>(fractal_compute_node));
|
||||
fractal_compute_node.set_args(port_ref<0>(), port_ref<1>(), port_ref<2>(), port_ref<3>(), port_ref<4>(), max_iterations, image_size, image_size, 400.0f, -.6f + shift, .6f);
|
||||
fractal_compute_node.set_range(port_ref<5>());
|
||||
make_edge(output_port<0>(fractal_compute_node), input_port<0>(image_join));
|
||||
make_edge(output_port<4>(fractal_compute_node), input_port<1>(image_join));
|
||||
make_edge(output_port<5>(fractal_compute_node), input_port<2>(image_join));
|
||||
set_external_ports(input_ports_type(fractal_data_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
class stereo_node : public composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > {
|
||||
typedef composite_node< tuple<buffer_t, buffer_t>, tuple<buffer_t> > stereo_base_type;
|
||||
opencl_graph &my_graph;
|
||||
opencl_program<> program;
|
||||
split_node<buffer_t> left_split;
|
||||
split_node<buffer_t> right_split;
|
||||
|
||||
opencl_node< buffer_t > left_transform;
|
||||
opencl_node< buffer_t > right_transform;
|
||||
|
||||
opencl_node< merge_buffer_t > image_merge;
|
||||
join_node< buffer_t > image_join;
|
||||
|
||||
public:
|
||||
stereo_node(opencl_graph &g) : my_graph(g), stereo_base_type(g),
|
||||
program(g, "stereo.cl"),
|
||||
left_transform(g, program.get_kernel("applyLeftImageEffect")),
|
||||
right_transform(g, program.get_kernel("applyRightImageEffect")),
|
||||
image_merge(g, program.get_kernel("mergeImages")),
|
||||
image_join(g),
|
||||
right_split(g),
|
||||
left_split(g) {
|
||||
make_edge(output_port<0>(left_split), input_port<0>(left_transform));
|
||||
make_edge(output_port<1>(left_split), input_port<1>(left_transform));
|
||||
make_edge(output_port<2>(left_split), input_port<2>(left_transform));
|
||||
make_edge(output_port<0>(right_split), input_port<0>(right_transform));
|
||||
make_edge(output_port<1>(right_split), input_port<1>(right_transform));
|
||||
make_edge(output_port<2>(right_split), input_port<2>(right_transform));
|
||||
|
||||
make_edge(output_port<0>(left_transform), input_port<0>(image_merge));
|
||||
make_edge(output_port<0>(right_transform), input_port<1>(image_merge));
|
||||
make_edge(output_port<1>(left_transform), input_port<2>(image_merge));
|
||||
make_edge(output_port<2>(left_transform), input_port<3>(image_merge));
|
||||
|
||||
make_edge(output_port<0>(image_merge), input_port<0>(image_join));
|
||||
make_edge(output_port<2>(image_merge), input_port<1>(image_join));
|
||||
make_edge(output_port<3>(image_merge), input_port<2>(image_join));
|
||||
|
||||
left_transform.set_args(port_ref<0>(), tile_width);
|
||||
left_transform.set_range(port_ref<2>());
|
||||
|
||||
right_transform.set_args(port_ref<0>(), tile_width);
|
||||
right_transform.set_range(port_ref<2>());
|
||||
|
||||
image_merge.set_args(port_ref<0, 1>(), tile_width);
|
||||
image_merge.set_range(port_ref<3>());
|
||||
|
||||
set_external_ports(input_ports_type(left_split, right_split), output_ports_type(image_join));
|
||||
}
|
||||
};
|
||||
|
||||
void chooseTargetDevice(tbb::flow::opencl_graph& g) {
|
||||
// Set your GPU device if available to execute kernel on
|
||||
const tbb::flow::opencl_device_list &devices = g.available_devices();
|
||||
tbb::flow::opencl_device_list::const_iterator it = std::find_if(devices.cbegin(), devices.cend(), [](const tbb::flow::opencl_device &d) {
|
||||
cl_device_type type;
|
||||
d.info(CL_DEVICE_TYPE, type);
|
||||
return CL_DEVICE_TYPE_GPU == type;
|
||||
});
|
||||
|
||||
if (it == devices.cend()) {
|
||||
std::cout << "Info: could not find any GPU devices. Choosing the first available device (default behaviour)." << std::endl;
|
||||
} else {
|
||||
// Init factory with GPU device
|
||||
g.opencl_factory().init({ *it });
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
opencl_graph g;
|
||||
chooseTargetDevice(g);
|
||||
|
||||
color_fractal_cpu_node render_fractal_cpu(g);
|
||||
mono_fractal_gpu_node render_left_fractal(g, -0.05f);
|
||||
mono_fractal_gpu_node render_right_fractal(g, 0.05f);
|
||||
stereo_node stereo(g);
|
||||
|
||||
std::string outputFile = "output";
|
||||
|
||||
source_node<fractal_data_t> tileSource(g, [&](fractal_data_t &v) -> bool {
|
||||
static int tag = 0;
|
||||
if ( tag < 4 ) {
|
||||
int x0 = 0, y0 = 0;
|
||||
|
||||
if (tag == 1 || tag == 3) x0 = 512;
|
||||
if (tag == 2 || tag == 3) y0 = 512;
|
||||
|
||||
v = std::make_tuple(x0, y0, tag);
|
||||
std::cout << "Hello from source node " << x0 << " ," << y0 << " ," << tag << std::endl;
|
||||
tag++;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}, false);
|
||||
|
||||
typedef multifunction_node< fractal_data_t, tuple< fractal_gpu_data_t, fractal_gpu_data_t, cl_uint > > stereo_mfn_t;
|
||||
stereo_mfn_t fractalInput(g, unlimited, [&]( const stereo_mfn_t::input_type &in, stereo_mfn_t::output_ports_type &ports ) {
|
||||
opencl_buffer<cl_uchar> oclImage1(g, tile_width*tile_height*channelsPerPixel);
|
||||
opencl_buffer<cl_uchar> oclImage2(g, tile_width*tile_height*channelsPerPixel);
|
||||
NDRange rangeList = { tile_width, tile_height };
|
||||
/* render left Image */
|
||||
get<0>(ports).try_put(std::make_tuple(oclImage1, get<0>(in), get<0>(in) + tile_width, get<1>(in), get<1>(in) + tile_height, rangeList ));
|
||||
/* redner right Image */
|
||||
get<1>(ports).try_put(std::make_tuple(oclImage2, get<0>(in), get<0>(in) + tile_width, get<1>(in), get<1>(in) + tile_height, rangeList ));
|
||||
/* forward tile-tag to token buffer */
|
||||
get<2>(ports).try_put(get<2>(in));
|
||||
});
|
||||
|
||||
typedef cl_uint token_t;
|
||||
typedef join_node< tuple<fractal_data_t, token_t>, reserving > rj_t;
|
||||
rj_t rj(g);
|
||||
|
||||
typedef multifunction_node< rj_t::output_type, tuple< fractal_data_t, fractal_data_t > > mfn_t;
|
||||
mfn_t dispatch_node(g, unlimited, []( const mfn_t::input_type &in, mfn_t::output_ports_type &ports ) {
|
||||
fractal_data_t d = get<0>(in);
|
||||
token_t tok = get<1>(in);
|
||||
printf("Dispatcher received %d\n", tok);
|
||||
if (tok == 0) {
|
||||
get<0>(ports).try_put(d);
|
||||
} else {
|
||||
get<1>(ports).try_put(d);
|
||||
}
|
||||
});
|
||||
|
||||
// generate token
|
||||
buffer_node<token_t> token_buffer(g);
|
||||
|
||||
make_edge(tileSource, input_port<0>(rj));
|
||||
make_edge(token_buffer, input_port<1>(rj));
|
||||
make_edge(rj, dispatch_node);
|
||||
make_edge(output_port<0>(dispatch_node), render_fractal_cpu);
|
||||
make_edge(output_port<1>(dispatch_node), fractalInput);
|
||||
|
||||
static utils::image_buffer timeline;
|
||||
static utils::image_buffer image;
|
||||
|
||||
image.width = image_size;
|
||||
image.height = image_size;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(image.width * image.height * 4);
|
||||
timeline.width = 4 * tile_width;
|
||||
timeline.height = tile_height;
|
||||
image.buffer = std::make_shared< std::vector<unsigned char> >(timeline.width * timeline.height * 4);
|
||||
|
||||
function_node<buffer_t, buffer_t> image_display(g, serial, [&](buffer_t b) {
|
||||
static int frame = 0;
|
||||
int tag = std::get<1>(b);
|
||||
|
||||
opencl_buffer<cl_uchar> tileBuffer = std::get<0>(b);
|
||||
const NDRange& imageSize = std::get<2>(b);
|
||||
unsigned int tile_width = imageSize[0];
|
||||
unsigned int tile_height = imageSize[1];
|
||||
|
||||
std::vector<unsigned char>& imageBuffer = *image.buffer;
|
||||
std::vector<unsigned char>& chronoBuffer = *timeline.buffer;
|
||||
|
||||
int x0 = 0, y0 = 0;
|
||||
|
||||
if (tag == 1 || tag == 3) x0 = 512;
|
||||
if (tag == 2 || tag == 3) y0 = 512;
|
||||
|
||||
for (unsigned y = y0; y < y0 + tile_height; y++) {
|
||||
/* over all rows */
|
||||
for (unsigned x = x0; x < x0 + tile_width; x++) {
|
||||
/* over all columns */
|
||||
for (unsigned i = 0; i < 4; ++i) {
|
||||
/* over all channels */
|
||||
imageBuffer.data()[4 * (image.width * y + x) + i] = tileBuffer.data()[4 * (tile_width * (y - y0) + (x - x0)) + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Hello from image node %d, %d, %d \n", x0, y0, tag);
|
||||
utils::writePNGImage(imageBuffer.data(), image.width, image.height, outputFile + std::to_string(frame) + ".png");
|
||||
frame++;
|
||||
return b;
|
||||
});
|
||||
|
||||
typedef join_node< tuple<buffer_t, cl_uint>, queueing > rj_token_t;
|
||||
|
||||
rj_token_t rj_gpu_token(g);
|
||||
|
||||
typedef multifunction_node< rj_token_t::output_type, tuple< buffer_t, token_t > > mfn_gpu_token_t;
|
||||
|
||||
mfn_gpu_token_t gpu_token_recycle(g, unlimited, [](const mfn_gpu_token_t::input_type &in, mfn_gpu_token_t::output_ports_type &ports) {
|
||||
const buffer_t& b = get<0>(in);
|
||||
const cl_uint& tag = get<1>(in);
|
||||
printf("Hello from token GPU recycler!");
|
||||
get<0>(ports).try_put(std::make_tuple( get<0>(b) ,tag , get<2>(b) ));
|
||||
get<1>(ports).try_put(token_t(1));
|
||||
});
|
||||
|
||||
make_edge( stereo, input_port<0>(rj_gpu_token)); // in: buffer_t
|
||||
make_edge( output_port<2>(fractalInput), input_port<1>(rj_gpu_token)); // in: token_t
|
||||
make_edge( rj_gpu_token, gpu_token_recycle); // in: buffer_t + token_t
|
||||
|
||||
make_edge( output_port<0>(gpu_token_recycle), image_display );
|
||||
make_edge( output_port<1>(gpu_token_recycle), token_buffer );
|
||||
|
||||
make_edge( output_port<0>(fractalInput), render_left_fractal);
|
||||
make_edge( output_port<1>(fractalInput), render_right_fractal);
|
||||
|
||||
make_edge( output_port<0>(render_left_fractal), input_port<0>(stereo));
|
||||
make_edge( output_port<0>(render_right_fractal), input_port<1>(stereo));
|
||||
|
||||
rj_token_t rj_cpu_token(g);
|
||||
|
||||
typedef multifunction_node< buffer_t, tuple< buffer_t, token_t > > mfn_cpu_token_t;
|
||||
mfn_cpu_token_t cpu_token_recycle(g, unlimited, [](const mfn_cpu_token_t::input_type &in, mfn_cpu_token_t::output_ports_type &ports) {
|
||||
const cl_uint& tag = get<1>(in);
|
||||
printf("Hello from token CPU recycler!");
|
||||
get<0>(ports).try_put(in);
|
||||
get<1>(ports).try_put(token_t(0));
|
||||
});
|
||||
|
||||
make_edge( render_fractal_cpu, cpu_token_recycle );
|
||||
|
||||
make_edge( output_port<0>(cpu_token_recycle), image_display );
|
||||
make_edge( output_port<1>(cpu_token_recycle), token_buffer );
|
||||
|
||||
printf("Beginning\n");
|
||||
tbb::tick_count mainStartTime = tbb::tick_count::now();
|
||||
token_buffer.try_put(token_t(0));
|
||||
token_buffer.try_put(token_t(1));
|
||||
tileSource.activate();
|
||||
g.wait_for_all();
|
||||
utility::report_elapsed_time((tbb::tick_count::now() - mainStartTime).seconds());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (c) 2017 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
__constant int redChannelOffset = 0;
|
||||
__constant int greenChannelOffset = 1;
|
||||
__constant int blueChannelOffset = 2;
|
||||
__constant int channelsPerPixel = 4;
|
||||
__constant int channelIncreaseValue = 10;
|
||||
|
||||
__kernel void mergeImages( __global uchar* bufferLeft, __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth;
|
||||
const int pixelGreenChannelIndex = pixelIndex + greenChannelOffset;
|
||||
const int pixelBlueChannelIndex = pixelIndex + blueChannelOffset;
|
||||
|
||||
bufferLeft[pixelGreenChannelIndex] = bufferRight[pixelGreenChannelIndex];
|
||||
bufferLeft[pixelBlueChannelIndex] = bufferRight[pixelBlueChannelIndex];
|
||||
}
|
||||
|
||||
__kernel void applyLeftImageEffect( __global uchar* bufferLeft, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelRedChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + redChannelOffset;
|
||||
|
||||
bufferLeft[pixelRedChannelIndex] = convert_uchar_sat(bufferLeft[pixelRedChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
__kernel void applyRightImageEffect( __global uchar* bufferRight, uint width) {
|
||||
const int indexWidth = get_global_id(0);
|
||||
const int indexHeight = get_global_id(1);
|
||||
|
||||
const int pixelBlueChannelIndex = channelsPerPixel * width * indexHeight + channelsPerPixel * indexWidth + blueChannelOffset;
|
||||
|
||||
bufferRight[pixelBlueChannelIndex] = convert_uchar_sat(bufferRight[pixelBlueChannelIndex] + channelIncreaseValue);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,77 @@
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# GNU Makefile that builds and runs example.
|
||||
|
||||
SRCDIR = ../src/
|
||||
|
||||
# The C++ compiler
|
||||
ifneq (,$(shell which icc 2>/dev/null))
|
||||
CXX=icc
|
||||
endif # icc
|
||||
|
||||
CXXFLAGS = -O3 -std=c++11
|
||||
TBBLIB = -ltbb
|
||||
LIBS+= -lrt
|
||||
|
||||
all:
|
||||
@echo "Usage: make <lab_step>"
|
||||
@echo "Example: make 00"
|
||||
@echo ""
|
||||
@echo "Possible values of <lab_step>:"
|
||||
@echo ""
|
||||
@echo " 01 : parallel_for"
|
||||
@echo " 01s : parallel_for_solution"
|
||||
@echo " 02 : reduction"
|
||||
@echo " 02s : reduction_solution"
|
||||
@echo " 03 : container"
|
||||
@echo " 03s : container_solution"
|
||||
@echo " 04 : flow_graph"
|
||||
@echo " 04s : flow_graph_solution"
|
||||
@echo " 05 : task"
|
||||
@echo " 05s : task_solution"
|
||||
|
||||
01: $(SRCDIR)/01_parallel_for.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 01_parallel_for $(SRCDIR)/01_parallel_for.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
01s: $(SRCDIR)/01_parallel_for_solution.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 01_parallel_for_solution $(SRCDIR)/01_parallel_for_solution.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
02: $(SRCDIR)/02_reduction.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 02_reduction $(SRCDIR)/02_reduction.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
02s: $(SRCDIR)/02_reduction_solution.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 02_reduction_solution $(SRCDIR)/02_reduction_solution.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
03: $(SRCDIR)/03_container.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 03_container $(SRCDIR)/03_container.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
03s: $(SRCDIR)/03_container_solution.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 03_container_solution $(SRCDIR)/03_container_solution.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
04: $(SRCDIR)/04_flow_graph.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 04_flow_graph $(SRCDIR)/04_flow_graph.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
04s: $(SRCDIR)/04_flow_graph_solution.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 04_flow_graph_solution $(SRCDIR)/04_flow_graph_solution.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
05: $(SRCDIR)/05_task.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 05_task $(SRCDIR)/05_task.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
05s: $(SRCDIR)/05_task_solution.cpp
|
||||
$(CXX) $(CXXFLAGS) -o 05_task_solution $(SRCDIR)/05_task_solution.cpp $(TBBLIB) $(LIBS)
|
||||
|
||||
clean:
|
||||
$(RM) *.o 00_getting_started 01_parallel_for 01_parallel_for_solution 02_reduction 02_reduction_solution 03_container 03_container_data 03_container_solution 04_flow_graph 04_flow_graph_solution 05_task 05_task_solution
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "
|
||||
Usage: ./build.sh <lab_step>
|
||||
Example: ./build.sh 00
|
||||
|
||||
Possible values of <lab_step>:
|
||||
|
||||
01 : parallel_for
|
||||
01s : parallel_for_solution
|
||||
02 : reduction
|
||||
02s : reduction_solution
|
||||
03 : container
|
||||
03s : container_solution
|
||||
04 : flow_graph
|
||||
04s : flow_graph_solution
|
||||
05 : task
|
||||
05s : task_solution"
|
||||
exit
|
||||
fi
|
||||
|
||||
# Setting Intel(R) Threading Building Blocks (Intel(R) TBB) environment
|
||||
if [ -z "$TBBROOT" ] # Intel(R) C++ Compiler 16.0 and above
|
||||
then
|
||||
. /opt/intel/compilers_and_libraries/linux/tbb/bin/tbbvars.sh intel64
|
||||
fi
|
||||
if [ -z "$TBBROOT" ] # # Older Intel(R) C++ Compiler version
|
||||
then
|
||||
. /opt/intel/composerxe/tbb/bin/tbbvars.sh intel64
|
||||
fi
|
||||
|
||||
make clean
|
||||
make $1
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
|
||||
template<typename T>
|
||||
void gemm(T* result, const T* a, const T* b, std::size_t arows, std::size_t acols, std::size_t bcols)
|
||||
{
|
||||
for (std::size_t i = 0; i < arows; ++i) {
|
||||
for (std::size_t j = 0; j < bcols; ++j) {
|
||||
result[i*bcols+j] = 0;
|
||||
}
|
||||
|
||||
for (std::size_t k = 0; k < acols; ++k) {
|
||||
for (std::size_t j = 0; j < bcols; ++j) {
|
||||
result[i*bcols+j] += a[i*acols+k] * b[k*bcols+j];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
const std::size_t arows = 1 < argc ? std::atol(argv[1]) : 512;
|
||||
const std::size_t acols = 2 < argc ? std::atol(argv[2]) : arows;
|
||||
const std::size_t bcols = 3 < argc ? std::atol(argv[3]) : arows;
|
||||
std::vector<T> r(arows * bcols), a(arows * acols), b(acols * bcols);
|
||||
std::for_each(a.begin(), a.end(), nrand<T>);
|
||||
std::for_each(b.begin(), b.end(), nrand<T>);
|
||||
|
||||
tick_count start = tick_count::now();
|
||||
gemm(&r[0], &a[0], &b[0], arows, acols, bcols);
|
||||
tick_count end = tick_count::now();
|
||||
|
||||
std::cout << "Time: " << 1000.0 * (end - start).seconds() << " ms\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
template<typename T>
|
||||
void gemm(T* result, const T* a, const T* b, std::size_t arows, std::size_t acols, std::size_t bcols)
|
||||
{
|
||||
using namespace tbb;
|
||||
|
||||
const blocked_range<std::size_t> range(0, arows);
|
||||
|
||||
parallel_for(range,
|
||||
[=](const blocked_range<std::size_t>& r) {
|
||||
const std::size_t end = r.end();
|
||||
for (std::size_t i = r.begin(); i < end; ++i) {
|
||||
for (std::size_t j = 0; j < bcols; ++j) {
|
||||
result[i*bcols+j] = 0;
|
||||
}
|
||||
|
||||
for (std::size_t k = 0; k < acols; ++k) {
|
||||
for (std::size_t j = 0; j < bcols; ++j) {
|
||||
result[i*bcols+j] += a[i*acols+k] * b[k*bcols+j];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
const std::size_t arows = 1 < argc ? std::atol(argv[1]) : 512;
|
||||
const std::size_t acols = 2 < argc ? std::atol(argv[2]) : arows;
|
||||
const std::size_t bcols = 3 < argc ? std::atol(argv[3]) : arows;
|
||||
|
||||
std::vector<T> r(arows * bcols), a(arows * acols), b(acols * bcols);
|
||||
std::for_each(a.begin(), a.end(), nrand<T>);
|
||||
std::for_each(b.begin(), b.end(), nrand<T>);
|
||||
|
||||
std::size_t nrepeat = 5;
|
||||
double min_time = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrepeat; ++i) {
|
||||
tick_count start = tick_count::now();
|
||||
gemm(&r[0], &a[0], &b[0], arows, acols, bcols);
|
||||
tick_count end = tick_count::now();
|
||||
min_time = std::min(min_time, (end - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "Time: " << (1000 * min_time) << " ms\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
template<typename T>
|
||||
struct tbb_sum_reduce {
|
||||
T result;
|
||||
|
||||
tbb_sum_reduce(): result(0) {}
|
||||
tbb_sum_reduce(const tbb_sum_reduce& /*other*/, tbb::split /*dummy*/): result(0) {}
|
||||
|
||||
template<typename I>
|
||||
void operator()(const tbb::blocked_range<I>& r) {
|
||||
const I end = r.end();
|
||||
for (I i = r.begin(); i != end; ++i) {
|
||||
result += *i;
|
||||
}
|
||||
}
|
||||
|
||||
void join(const tbb_sum_reduce& other) {
|
||||
result += other.result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename I>
|
||||
typename std::iterator_traits<I>::value_type sum_reduce(I begin, I end)
|
||||
{
|
||||
typedef typename std::iterator_traits<I>::value_type T;
|
||||
tbb_sum_reduce<T> sum;
|
||||
tbb::parallel_reduce(tbb::blocked_range<I>(begin, end), sum);
|
||||
return sum.result;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
std::size_t size = 1 < argc ? std::atol(argv[1]) : 4 * 1024 * 1024;
|
||||
std::size_t repeat = 2 < argc ? std::atol(argv[2]) : 5;
|
||||
|
||||
std::vector<T> values(size);
|
||||
std::for_each(values.begin(), values.end(), nrand<T>);
|
||||
|
||||
T result_tbb = 0;
|
||||
double time_tbb = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < repeat; ++i) {
|
||||
const tick_count start = tick_count::now();
|
||||
result_tbb = sum_reduce(&values[0], &values[0] + values.size());
|
||||
time_tbb = std::min(time_tbb, (tick_count::now() - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "TBB: " << result_tbb << " (" << time_tbb << " s)\n";
|
||||
|
||||
T result_seq = 0;
|
||||
double time_seq = std::numeric_limits<double>::max();
|
||||
std::vector<T>::iterator end = values.end();
|
||||
for (std::size_t i = 0; i < repeat; ++i) {
|
||||
result_seq = 0;
|
||||
const tick_count start = tick_count::now();
|
||||
for (std::vector<T>::iterator i = values.begin(); i != end; ++i) {
|
||||
result_seq += *i;
|
||||
}
|
||||
time_seq = std::min(time_seq, (tick_count::now() - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "SEQ: " << result_seq << " (" << time_seq << " s)\n";
|
||||
|
||||
if (0 != time_tbb) {
|
||||
std::cout << " speedup: " << (time_seq / time_tbb) << "x" << '\n';
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
template<typename T>
|
||||
struct tbb_sum_reduce {
|
||||
T result;
|
||||
|
||||
explicit tbb_sum_reduce(const T& init): result(init) {}
|
||||
tbb_sum_reduce(const tbb_sum_reduce& /*other*/, tbb::split /*dummy*/): result(0) {}
|
||||
|
||||
template<typename I>
|
||||
void operator()(const tbb::blocked_range<I>& r) {
|
||||
const I end = r.end();
|
||||
for (I i = r.begin(); i != end; ++i) {
|
||||
result += *i;
|
||||
}
|
||||
}
|
||||
|
||||
void join(const tbb_sum_reduce& other) {
|
||||
result += other.result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename I>
|
||||
typename std::iterator_traits<I>::value_type sum_reduce(I begin, I end)
|
||||
{
|
||||
typedef typename std::iterator_traits<I>::value_type T;
|
||||
tbb_sum_reduce<T> sum(0);
|
||||
tbb::parallel_deterministic_reduce(tbb::blocked_range<I>(begin, end, 8192), sum);
|
||||
// tbb::parallel_deterministic_reduce(tbb::blocked_range<I>(begin, end), sum);
|
||||
return sum.result;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
std::size_t size = 1 < argc ? std::atol(argv[1]) : 4 * 1024 * 1024;
|
||||
std::size_t repeat = 2 < argc ? std::atol(argv[2]) : 5;
|
||||
|
||||
std::vector<T> values(size);
|
||||
std::for_each(values.begin(), values.end(), nrand<T>);
|
||||
|
||||
T result_tbb = 0;
|
||||
double time_tbb = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < repeat; ++i) {
|
||||
const tick_count start = tick_count::now();
|
||||
result_tbb = sum_reduce(&values[0], &values[0] + values.size());
|
||||
time_tbb = std::min(time_tbb, (tick_count::now() - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "TBB: " << result_tbb << " (" << time_tbb << " s)\n";
|
||||
|
||||
T result_seq = 0;
|
||||
double time_seq = std::numeric_limits<double>::max();
|
||||
std::vector<T>::iterator end = values.end();
|
||||
for (std::size_t i = 0; i < repeat; ++i) {
|
||||
result_seq = 0;
|
||||
const tick_count start = tick_count::now();
|
||||
for (std::vector<T>::iterator i = values.begin(); i != end; ++i) {
|
||||
result_seq += *i;
|
||||
}
|
||||
time_seq = std::min(time_seq, (tick_count::now() - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "SEQ: " << result_seq << " (" << time_seq << " s)\n";
|
||||
|
||||
if (0 != time_tbb) {
|
||||
std::cout << " speedup: " << (time_seq / time_tbb) << "x" << '\n';
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include "03_container_data.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
//#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
#include <tbb/spin_mutex.h>
|
||||
|
||||
|
||||
struct hash {
|
||||
std::size_t operator()(const std::pair<const char*,const char*>& a) const {
|
||||
static const std::size_t M = 4 * sizeof(std::size_t);
|
||||
return ((a.first - *names_first) << M) | (a.second - *names_last);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct less {
|
||||
bool operator()(const std::pair<const char*,const char*>& a, const std::pair<const char*,const char*>& b) const {
|
||||
const int u = std::strcmp(a.first, b.first), v = std::strcmp(a.second, b.second);
|
||||
return u < 0 || (0 == u && v < 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct equal {
|
||||
bool operator()(const std::pair<const char*,const char*>& a, const std::pair<const char*,const char*>& b) const {
|
||||
const int u = std::strcmp(a.first, b.first), v = std::strcmp(a.second, b.second);
|
||||
return 0 == u && 0 == v;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef std::pair<const char*,const char*> key_type;
|
||||
typedef std::map<key_type,std::size_t,less> map_type;
|
||||
//typedef std::unordered_map<key_type,std::size_t,hash,equal> map_type;
|
||||
|
||||
const std::size_t size = 1 < argc ? std::atol(argv[1]) : 100;
|
||||
map_type result_serial, result_parallel;
|
||||
|
||||
std::cout << "Generating initial data...";
|
||||
const std::size_t M = sizeof(names_first) / sizeof(*names_first);
|
||||
const std::size_t N = sizeof(names_last) / sizeof(*names_last);
|
||||
std::vector<key_type> names;
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
names.push_back(std::make_pair(names_first[std::rand()%M], names_last[std::rand()%N]));
|
||||
}
|
||||
std::cout << " size: " << size << '\n';
|
||||
|
||||
std::cout << "Running serial algorithm...";
|
||||
tick_count start = tick_count::now();
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
++result_serial[names[i]];
|
||||
}
|
||||
const double time_serial = (tick_count::now() - start).seconds();
|
||||
std::cout << " time: " << time_serial << " s\n";
|
||||
|
||||
std::cout << "Running parallel algorithm...";
|
||||
spin_mutex lock; // use mutex to avoid data race
|
||||
start = tick_count::now();
|
||||
parallel_for(static_cast<std::size_t>(0), size, [&](std::size_t i) {
|
||||
// Data race! Uncomment the next line to fix
|
||||
// tbb::spin_mutex::scoped_lock scoped_lock(lock);
|
||||
++result_parallel[names[i]];
|
||||
});
|
||||
const double time_parallel = (tick_count::now() - start).seconds();
|
||||
std::cout << " time: " << time_parallel << " s\n";
|
||||
|
||||
std::cout << "Verifying results... ";
|
||||
if (result_serial.size() != result_parallel.size()) {
|
||||
throw std::runtime_error("size does not match!");
|
||||
}
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
if (result_serial[names[i]] != result_parallel[names[i]]) {
|
||||
throw std::runtime_error("entry does not match!");
|
||||
}
|
||||
}
|
||||
if (0 != time_parallel) {
|
||||
std::cout << " speedup: " << (time_serial / time_parallel) << "x";
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CONTAINER_DATA_HPP
|
||||
#define CONTAINER_DATA_HPP
|
||||
|
||||
|
||||
const char* names_first[] = { // first names
|
||||
"ALEXANDER", "IVAN", "ALEKSEI", "MIKHAIL", "IGOR", "ANDREY", "ARTEM",
|
||||
"DANIIL", "SERGEY", "VITALY", "EVGENY", "KONSTANTIN", "PAVEL", "ILYA",
|
||||
"RUSLAN", "ROMAN", "PETR", "STANISLAV", "ROSTISLAV", "NIKITA", "ANTON",
|
||||
"GLEB", "PHILIPP", "DMITRY", "TIMOFEY", "KIRILL", "ALBERT", "ARTUR",
|
||||
"PROHOR", "VADIM", "OLEG", "ILARION", "SEMYON", "SVYATOSLAV", "YAKOV",
|
||||
"NIKOLAY", "DENIS", "YAROSLAV", "NESTOR", "KIM", "VLADISLAV", "VALERY",
|
||||
"VASILY", "ARKHIP", "LEONID", "VALENTIN", "MAKSIM", "TIMUR", "FYODOR",
|
||||
"BORIS"
|
||||
};
|
||||
|
||||
|
||||
const char* names_last[] = { // family names
|
||||
"IVANOV", "PETROV", "SIDOROV", "ZAKHAROV", "MOTEIKO", "KUZNETSOV", "KAMAROV",
|
||||
"POPOV", "IGNATIEV", "SOKOLOV", "KOZLOV", "VOLKOV", "LEBEDEV", "EGOROV",
|
||||
"ORLOV", "STEPANOV", "NIKOLAEV", "ZAITSEV", "ANDREEV", "SOLOVIEV", "VOROBIEV",
|
||||
"KLEMENOV", "KISELEV", "KOVALEV", "ANTONOV", "ZHUKOV", "VORONOV", "SOFRONOV",
|
||||
"KRYUKOV", "DROZDOV", "LARIN", "NIKULIN", "SEROV", "MIRONOV", "ZOTOV",
|
||||
"GORBACHEV", "KOPYLOV", "LAPSHIN", "FEDOTOV", "POZDNYAKOV", "RUSAKOV", "ALYOSHIN",
|
||||
"NOSKOV", "OZEROV", "LITKOV", "DOLGOV", "SUSLOV", "SHEVTSOV", "CHEREPANOV",
|
||||
"GAGARIN", "KORCHAGIN", "FETISOV", "GORLOV", "ANTIPOV", "POSTNIKOV", "GUSCHIN",
|
||||
"RYABININ", "FEDOSOV", "SOMOV", "DOBRYNIN", "RAKOV", "KUTENKOV", "MOLODOV",
|
||||
"VERSHININ", "BEZRUKOV", "POLIKARPOV", "MORGUNOV", "VITSYN", "ERMOLOV", "KAZANTSEV",
|
||||
"CHERNYAEV", "GUROV", "GOREV", "AGAPOV", "TULUBAEV", "TURLAPOV", "KORNEV",
|
||||
"KOCHERGIN", "TRUSHANIN", "OLIFER", "PAUSHKIN", "KARDAKOV", "ZLOBIN", "HROMOV",
|
||||
"PUGACHEV", "IZMAILOV", "OKUNEV", "PCHYOLKIN", "SHIRYAEV", "KASYANOV", "CHIZHOV",
|
||||
"OSTROVSKY", "BASOV", "PASTUKHOV", "BYCHKOV", "VYSOTSKY", "GLEBOV", "DUROV",
|
||||
"BULATOV", "CHERNYSHEV"
|
||||
};
|
||||
|
||||
#endif // CONTAINER_DATA_HPP
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include "03_container_data.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
//#include <unordered_map>
|
||||
#include <map>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
#include <tbb/spin_mutex.h>
|
||||
|
||||
|
||||
struct hash {
|
||||
std::size_t operator()(const std::pair<const char*,const char*>& a) const {
|
||||
static const std::size_t M = 4 * sizeof(std::size_t);
|
||||
const std::size_t i = a.first - *names_first, j = a.second - *names_last;
|
||||
return (i << M) | j;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct less {
|
||||
bool operator()(const std::pair<const char*,const char*>& a, const std::pair<const char*,const char*>& b) const {
|
||||
const int u = std::strcmp(a.first, b.first), v = std::strcmp(a.second, b.second);
|
||||
return u < 0 || (0 == u && v < 0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct equal {
|
||||
bool operator()(const std::pair<const char*,const char*>& a, const std::pair<const char*,const char*>& b) const {
|
||||
const int u = std::strcmp(a.first, b.first), v = std::strcmp(a.second, b.second);
|
||||
return 0 == u && 0 == v;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef std::pair<const char*,const char*> key_type;
|
||||
//typedef std::map<key_type,std::size_t,less> map_type;
|
||||
//typedef std::unordered_map<key_type,std::size_t,hash,equal> map_type;
|
||||
typedef concurrent_unordered_map<key_type,atomic<std::size_t>,hash,equal> map_type;
|
||||
|
||||
const std::size_t size = 1 < argc ? std::atol(argv[1]) : 100;
|
||||
map_type result_serial, result_parallel;
|
||||
atomic<std::size_t> zero;
|
||||
zero = 0;
|
||||
|
||||
std::cout << "Generating initial data...";
|
||||
const std::size_t M = sizeof(names_first) / sizeof(*names_first);
|
||||
const std::size_t N = sizeof(names_last) / sizeof(*names_last);
|
||||
std::vector<key_type> names;
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
names.push_back(std::make_pair(names_first[std::rand()%M], names_last[std::rand()%N]));
|
||||
}
|
||||
std::cout << " size: " << size << '\n';
|
||||
|
||||
std::cout << "Running serial algorithm...";
|
||||
tick_count start = tick_count::now();
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
++(result_serial.insert(std::make_pair(names[i], zero)).first);
|
||||
}
|
||||
const double time_serial = (tick_count::now() - start).seconds();
|
||||
std::cout << " time: " << time_serial << " s\n";
|
||||
|
||||
std::cout << "Running parallel algorithm...";
|
||||
spin_mutex lock;
|
||||
start = tick_count::now();
|
||||
parallel_for(static_cast<std::size_t>(0), size, [&](std::size_t i) {
|
||||
//tbb::spin_mutex::scoped_lock scoped_lock(lock);
|
||||
++(result_parallel.insert(std::make_pair(names[i], zero)).first);
|
||||
});
|
||||
const double time_parallel = (tick_count::now() - start).seconds();
|
||||
std::cout << " time: " << time_parallel << " s\n";
|
||||
|
||||
std::cout << "Verifying results... ";
|
||||
if (result_serial.size() != result_parallel.size()) {
|
||||
throw std::runtime_error("size does not match!");
|
||||
}
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
if (result_serial[names[i]] != result_parallel[names[i]]) {
|
||||
throw std::runtime_error("entry does not match!");
|
||||
}
|
||||
}
|
||||
if (0 != time_parallel) {
|
||||
std::cout << " speedup: " << (time_serial / time_parallel) << "x";
|
||||
}
|
||||
std::cout << '\n';
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
#include <tbb/flow_graph.h>
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void dot(T& result, const T* a, const T* b, std::size_t size)
|
||||
{
|
||||
result = 0;
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
result += a[i] * b[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void gemv(T* result, const T* matrix, const T* vector, std::size_t nrows, std::size_t ncols)
|
||||
{
|
||||
for (std::size_t i = 0; i < nrows; ++i) {
|
||||
dot(result[i], matrix + i * ncols, vector, ncols);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class gemv_body {
|
||||
public:
|
||||
gemv_body(T* result, const T* matrix, std::size_t nrows, std::size_t ncols)
|
||||
: res(result), mat(matrix), m(nrows), n(ncols)
|
||||
{}
|
||||
|
||||
const T* operator()(const T* vector) const {
|
||||
gemv(res, mat, vector, m, n);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
T* res;
|
||||
const T* mat;
|
||||
std::size_t m, n;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class dot_body {
|
||||
public:
|
||||
dot_body(T& result, const T* vector, std::size_t size)
|
||||
: r(&result), t(vector), n(size)
|
||||
{}
|
||||
|
||||
const T operator()(const T* vector) const {
|
||||
dot(*r, t, vector, n);
|
||||
return *r;
|
||||
}
|
||||
|
||||
private:
|
||||
T* r;
|
||||
const T* t;
|
||||
std::size_t n;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
typedef std::vector<T> B; // buffer
|
||||
|
||||
std::size_t nrows = 1 < argc ? std::atol(argv[1]) : 512;
|
||||
std::size_t ncols = 2 < argc ? std::atol(argv[2]) : nrows;
|
||||
std::size_t nrept = 5;
|
||||
|
||||
B m[] = { B(nrows * ncols), B(nrows * ncols) };
|
||||
std::size_t matrices = sizeof(m) / sizeof(*m);
|
||||
for (std::size_t i = 0; i < matrices; ++i) {
|
||||
std::for_each(m[i].begin(), m[i].end(), nrand<T>);
|
||||
}
|
||||
|
||||
B v[] = { B(ncols), B(ncols), B(ncols) };
|
||||
std::size_t vectors = sizeof(v) / sizeof(*v);
|
||||
for (std::size_t i = 0; i < vectors; ++i) {
|
||||
std::for_each(v[i].begin(), v[i].end(), nrand<T>);
|
||||
}
|
||||
|
||||
// temporary/intermediate result vectors
|
||||
B t[] = { B(nrows), B(nrows), B(nrows), B(nrows), B(nrows), B(nrows) };
|
||||
T r[4];
|
||||
|
||||
std::cout << "Expression Evaluation (serial)\n";
|
||||
double min_time_serial = std::numeric_limits<double>::max();
|
||||
double min_time_short = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrept; ++i) {
|
||||
tick_count start = tick_count::now();
|
||||
gemv(&t[0][0], &m[0][0], &v[0][0], nrows, ncols);
|
||||
gemv(&t[1][0], &m[1][0], &t[0][0], nrows, ncols);
|
||||
dot(r[0], &v[2][0], &t[1][0], std::min(nrows, ncols));
|
||||
tick_count t1 = tick_count::now();
|
||||
gemv(&t[2][0], &m[0][0], &v[1][0], nrows, ncols);
|
||||
gemv(&t[3][0], &m[1][0], &t[2][0], nrows, ncols);
|
||||
dot(r[1], &v[2][0], &t[3][0], std::min(nrows, ncols));
|
||||
tick_count t2 = tick_count::now();
|
||||
gemv(&t[4][0], &m[1][0], &v[0][0], nrows, ncols);
|
||||
dot(r[2], &v[2][0], &t[4][0], std::min(nrows, ncols));
|
||||
gemv(&t[5][0], &m[1][0], &v[1][0], nrows, ncols);
|
||||
dot(r[3], &v[2][0], &t[5][0], std::min(nrows, ncols));
|
||||
tick_count end = tick_count::now();
|
||||
const double time = (end - start).seconds();
|
||||
min_time_serial = std::min(min_time_serial, time);
|
||||
std::cout << " Time " << (i + 1) << ": "<< (1000 * time) << " ms\n";
|
||||
min_time_short = std::min(min_time_short, 0.5 * ((end - t1) + (end - t2)).seconds());
|
||||
}
|
||||
std::cout << "Minimum: " << (1000 * min_time_serial) << " ms\n";
|
||||
std::cout << "Results: ";
|
||||
std::copy(r, r + sizeof(r) / sizeof(*r), std::ostream_iterator<T>(std::cout, " "));
|
||||
std::cout << "\n\n";
|
||||
|
||||
flow::graph g;
|
||||
|
||||
typedef flow::function_node<const T*, const T*> gemv_node_t;
|
||||
typedef flow::function_node<const T*, T> dot_node_t;
|
||||
|
||||
gemv_node_t g1(g, flow::unlimited, gemv_body<T>(&t[0][0], &m[0][0], nrows, ncols));
|
||||
gemv_node_t g2(g, flow::unlimited, gemv_body<T>(&t[1][0], &m[1][0], nrows, ncols));
|
||||
dot_node_t d1(g, flow::unlimited, dot_body<T>(r[0], &v[2][0], std::min(nrows, ncols)));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
#include <tbb/flow_graph.h>
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void dot(T& result, const T* a, const T* b, std::size_t size)
|
||||
{
|
||||
result = 0;
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
result += a[i] * b[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
void gemv(T* result, const T* matrix, const T* vector, std::size_t nrows, std::size_t ncols)
|
||||
{
|
||||
for (std::size_t i = 0; i < nrows; ++i) {
|
||||
dot(result[i], matrix + i * ncols, vector, ncols);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
class gemv_body {
|
||||
public:
|
||||
gemv_body(T* result, const T* matrix, std::size_t nrows, std::size_t ncols)
|
||||
: res(result), mat(matrix), m(nrows), n(ncols)
|
||||
{}
|
||||
|
||||
const T* operator()(const T* vector) const {
|
||||
gemv(res, mat, vector, m, n);
|
||||
return res;
|
||||
}
|
||||
|
||||
private:
|
||||
T* res;
|
||||
const T* mat;
|
||||
std::size_t m, n;
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
class dot_body {
|
||||
public:
|
||||
dot_body(T& result, const T* vector, std::size_t size)
|
||||
: r(&result), t(vector), n(size)
|
||||
{}
|
||||
|
||||
const T operator()(const T* vector) const {
|
||||
dot(*r, t, vector, n);
|
||||
return *r;
|
||||
}
|
||||
|
||||
private:
|
||||
T* r;
|
||||
const T* t;
|
||||
std::size_t n;
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
typedef std::vector<T> B; // buffer
|
||||
|
||||
std::size_t nrows = 1 < argc ? std::atol(argv[1]) : 512;
|
||||
std::size_t ncols = 2 < argc ? std::atol(argv[2]) : nrows;
|
||||
std::size_t nrept = 5;
|
||||
|
||||
B m[] = { B(nrows * ncols), B(nrows * ncols) };
|
||||
std::size_t matrices = sizeof(m) / sizeof(*m);
|
||||
for (std::size_t i = 0; i < matrices; ++i) {
|
||||
std::for_each(m[i].begin(), m[i].end(), nrand<T>);
|
||||
}
|
||||
|
||||
B v[] = { B(ncols), B(ncols), B(ncols) };
|
||||
std::size_t vectors = sizeof(v) / sizeof(*v);
|
||||
for (std::size_t i = 0; i < vectors; ++i) {
|
||||
std::for_each(v[i].begin(), v[i].end(), nrand<T>);
|
||||
}
|
||||
|
||||
// temporary/intermediate result vectors
|
||||
B t[] = { B(nrows), B(nrows), B(nrows), B(nrows), B(nrows), B(nrows) };
|
||||
T r[4];
|
||||
|
||||
std::cout << "Expression Evaluation (serial)\n";
|
||||
double min_time_serial = std::numeric_limits<double>::max();
|
||||
double min_time_short = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrept; ++i) {
|
||||
tick_count start = tick_count::now();
|
||||
gemv(&t[0][0], &m[0][0], &v[0][0], nrows, ncols);
|
||||
gemv(&t[1][0], &m[1][0], &t[0][0], nrows, ncols);
|
||||
dot(r[0], &v[2][0], &t[1][0], std::min(nrows, ncols));
|
||||
tick_count t1 = tick_count::now();
|
||||
gemv(&t[2][0], &m[0][0], &v[1][0], nrows, ncols);
|
||||
gemv(&t[3][0], &m[1][0], &t[2][0], nrows, ncols);
|
||||
dot(r[1], &v[2][0], &t[3][0], std::min(nrows, ncols));
|
||||
tick_count t2 = tick_count::now();
|
||||
gemv(&t[4][0], &m[1][0], &v[0][0], nrows, ncols);
|
||||
dot(r[2], &v[2][0], &t[4][0], std::min(nrows, ncols));
|
||||
gemv(&t[5][0], &m[1][0], &v[1][0], nrows, ncols);
|
||||
dot(r[3], &v[2][0], &t[5][0], std::min(nrows, ncols));
|
||||
tick_count end = tick_count::now();
|
||||
const double time = (end - start).seconds();
|
||||
min_time_serial = std::min(min_time_serial, time);
|
||||
std::cout << " Time " << (i + 1) << ": "<< (1000 * time) << " ms\n";
|
||||
min_time_short = std::min(min_time_short, 0.5 * ((end - t1) + (end - t2)).seconds());
|
||||
}
|
||||
std::cout << "Minimum: " << (1000 * min_time_serial) << " ms\n";
|
||||
std::cout << "Results: ";
|
||||
std::copy(r, r + sizeof(r) / sizeof(*r), std::ostream_iterator<T>(std::cout, " "));
|
||||
std::cout << "\n\n";
|
||||
|
||||
flow::graph g;
|
||||
|
||||
typedef flow::function_node<const T*, const T*> gemv_node_t;
|
||||
typedef flow::function_node<const T*, T> dot_node_t;
|
||||
|
||||
gemv_node_t g1(g, flow::unlimited, gemv_body<T>(&t[0][0], &m[0][0], nrows, ncols));
|
||||
gemv_node_t g2(g, flow::unlimited, gemv_body<T>(&t[1][0], &m[1][0], nrows, ncols));
|
||||
dot_node_t d1(g, flow::unlimited, dot_body<T>(r[0], &v[2][0], std::min(nrows, ncols)));
|
||||
|
||||
gemv_node_t g3(g, flow::unlimited, gemv_body<T>(&t[2][0], &m[0][0], nrows, ncols));
|
||||
gemv_node_t g4(g, flow::unlimited, gemv_body<T>(&t[3][0], &m[1][0], nrows, ncols));
|
||||
dot_node_t d2(g, flow::unlimited, dot_body<T>(r[1], &v[2][0], std::min(nrows, ncols)));
|
||||
|
||||
gemv_node_t g5(g, flow::unlimited, gemv_body<T>(&t[4][0], &m[1][0], nrows, ncols));
|
||||
dot_node_t d3(g, flow::unlimited, dot_body<T>(r[2], &v[2][0], std::min(nrows, ncols)));
|
||||
|
||||
gemv_node_t g6(g, flow::unlimited, gemv_body<T>(&t[5][0], &m[1][0], nrows, ncols));
|
||||
dot_node_t d4(g, flow::unlimited, dot_body<T>(r[3], &v[2][0], std::min(nrows, ncols)));
|
||||
|
||||
flow::make_edge(g1, g2); flow::make_edge(g2, d1);
|
||||
flow::make_edge(g3, g4); flow::make_edge(g4, d2);
|
||||
flow::make_edge(g5, d3);
|
||||
flow::make_edge(g6, d4);
|
||||
|
||||
std::cout << "Expression Evaluation (flow::graph)\n";
|
||||
double min_time_graph = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrept; ++i) {
|
||||
tick_count start = tick_count::now();
|
||||
g1.try_put(&v[0][0]);
|
||||
g3.try_put(&v[1][0]);
|
||||
g5.try_put(&v[0][0]);
|
||||
g6.try_put(&v[1][0]);
|
||||
g.wait_for_all();
|
||||
tick_count end = tick_count::now();
|
||||
const double time = (end - start).seconds();
|
||||
min_time_graph = std::min(min_time_graph, time);
|
||||
std::cout << " Time " << (i + 1) << ": "<< (1000 * time) << " ms\n";
|
||||
}
|
||||
std::cout << "Minimum: " << (1000 * min_time_graph) << " ms\n";
|
||||
std::cout << "Results: ";
|
||||
std::copy(r, r + sizeof(r) / sizeof(*r), std::ostream_iterator<T>(std::cout, " "));
|
||||
std::cout << "\n\n";
|
||||
|
||||
std::cout << "Comparison\n";
|
||||
std::cout << "Short Path: " << (1000 * min_time_short) << " ms\n";
|
||||
std::cout << "Graph Time: " << (1000 * min_time_graph) << " ms Speedup: ";
|
||||
std::cout << min_time_short / min_time_graph << "x\n";
|
||||
std::cout << '\n';
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
/// Pure Quicksort (e.g., tail recursion is not avoided).
|
||||
template<typename I>
|
||||
struct parallel_qsort {
|
||||
typedef typename std::iterator_traits<I>::value_type value_type;
|
||||
I begin, end;
|
||||
|
||||
parallel_qsort(I begin_, I end_): begin(begin_), end(end_) {}
|
||||
|
||||
void operator()() const {
|
||||
if (begin != end) {
|
||||
const I pivot = end - 1;
|
||||
const I middle = std::partition(begin, pivot, std::bind2nd(std::less<value_type>(), *pivot));
|
||||
std::swap(*pivot, *middle);
|
||||
tbb::parallel_invoke(
|
||||
parallel_qsort(begin, middle),
|
||||
parallel_qsort(middle + 1, end));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename I>
|
||||
void compare(I begin, I end, I expect, std::size_t& diff_count)
|
||||
{
|
||||
diff_count = 0;
|
||||
for (I i = begin; i != end; ++i, ++expect) {
|
||||
if (*i != *expect) {
|
||||
++diff_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
std::size_t size = 1 < argc ? std::atol(argv[1]) : 4 * 1024 * 1024;
|
||||
std::vector<T> values(size), result(size);
|
||||
std::for_each(values.begin(), values.end(), nrand<T>);
|
||||
|
||||
typedef parallel_qsort<std::vector<T>::iterator> qsort_type;
|
||||
const qsort_type qsort(result.begin(), result.end());
|
||||
|
||||
std::size_t nrepeat = 5;
|
||||
double min_time = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrepeat; ++i) {
|
||||
std::copy(values.begin(), values.end(), result.begin());
|
||||
tick_count start = tick_count::now();
|
||||
qsort();
|
||||
tick_count end = tick_count::now();
|
||||
min_time = std::min(min_time, (end - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "Time: " << min_time << " s";
|
||||
|
||||
std::size_t diff_count;
|
||||
tbb::parallel_sort(values.begin(), values.end());
|
||||
compare(result.begin(), result.end(), values.begin(), diff_count);
|
||||
|
||||
std::cout << " (ok=";
|
||||
const double correct = static_cast<double>(size - diff_count) / size;
|
||||
std::cout << static_cast<int>(100.0 * correct + 0.5) << "%)\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
Copyright (c) 2018 Intel Corporation
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
template<typename T> void nrand(T& a)
|
||||
{
|
||||
static const double scale = 1.0 / RAND_MAX;
|
||||
a = static_cast<T>(scale * (2 * std::rand() - RAND_MAX));
|
||||
}
|
||||
|
||||
|
||||
/// Pure Quicksort (e.g., tail recursion is not avoided).
|
||||
template<typename I>
|
||||
struct parallel_qsort: public tbb::task {
|
||||
typedef typename std::iterator_traits<I>::value_type value_type;
|
||||
I begin, end;
|
||||
|
||||
parallel_qsort(I begin_, I end_): begin(begin_), end(end_) {}
|
||||
|
||||
tbb::task* execute() {
|
||||
tbb::task* result = 0;
|
||||
if (begin != end) {
|
||||
const I pivot = end - 1;
|
||||
const I middle = std::partition(begin, pivot, std::bind2nd(std::less<value_type>(), *pivot));
|
||||
std::swap(*pivot, *middle);
|
||||
this->set_ref_count(3); // incl. this
|
||||
this->spawn(*new(this->allocate_child()) parallel_qsort(begin, middle));
|
||||
this->spawn(*new(this->allocate_child()) parallel_qsort(middle + 1, end));
|
||||
this->wait_for_all();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename I>
|
||||
void compare(I begin, I end, I expect, std::size_t& diff_count)
|
||||
{
|
||||
diff_count = 0;
|
||||
for (I i = begin; i != end; ++i, ++expect) {
|
||||
if (*i != *expect) {
|
||||
++diff_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
try {
|
||||
using namespace tbb;
|
||||
typedef float T;
|
||||
|
||||
std::size_t size = 1 < argc ? std::atol(argv[1]) : 4 * 1024 * 1024;
|
||||
std::vector<T> values(size), result(size);
|
||||
std::for_each(values.begin(), values.end(), nrand<T>);
|
||||
|
||||
typedef parallel_qsort<std::vector<T>::iterator> qsort_type;
|
||||
|
||||
std::size_t nrepeat = 5;
|
||||
double time_own = std::numeric_limits<double>::max();
|
||||
for (std::size_t i = 0; i < nrepeat; ++i) {
|
||||
std::copy(values.begin(), values.end(), result.begin());
|
||||
tick_count start = tick_count::now();
|
||||
qsort_type* qsort = new(tbb::task::allocate_root()) qsort_type(result.begin(), result.end());
|
||||
tbb::task::spawn_root_and_wait(*qsort);
|
||||
tick_count end = tick_count::now();
|
||||
time_own = std::min(time_own, (end - start).seconds());
|
||||
}
|
||||
|
||||
std::cout << "Time: " << time_own << " s";
|
||||
|
||||
std::size_t diff_count;
|
||||
tbb::parallel_sort(values.begin(), values.end());
|
||||
compare(result.begin(), result.end(), values.begin(), diff_count);
|
||||
|
||||
std::cout << " (ok=";
|
||||
const double correct = static_cast<double>(size - diff_count) / size;
|
||||
std::cout << static_cast<int>(100.0 * correct + 0.5) << "%)\n";
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::cerr << "Error: " << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Error: unknown exception caught!\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
@echo off
|
||||
REM
|
||||
REM Copyright (c) 2018 Intel Corporation
|
||||
REM
|
||||
REM Licensed under the Apache License, Version 2.0 (the "License");
|
||||
REM you may not use this file except in compliance with the License.
|
||||
REM You may obtain a copy of the License at
|
||||
REM
|
||||
REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
REM
|
||||
REM Unless required by applicable law or agreed to in writing, software
|
||||
REM distributed under the License is distributed on an "AS IS" BASIS,
|
||||
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
REM See the License for the specific language governing permissions and
|
||||
REM limitations under the License.
|
||||
REM
|
||||
|
||||
:: Getting parameters
|
||||
if ("%1") == ("") goto error0
|
||||
if ("%2") == ("") goto error0
|
||||
if ("%3") == ("") goto error0
|
||||
set arch=%1
|
||||
if ("%2") == ("debug") set postfix=_debug
|
||||
set output_dir=%3
|
||||
|
||||
:: Optional 4th parameter to set install root
|
||||
if ("%4") NEQ ("") set TBBROOT=%4
|
||||
:: Actually we can set install root by ourselves
|
||||
if ("%TBBROOT%") == ("") set TBBROOT=%~d0%~p0..\..\
|
||||
|
||||
:: Getting vs folders in case vc_mt binaries are not provided
|
||||
:: ordered from oldest to newest, so we end with newest available version
|
||||
if ("%VS110COMNTOOLS%") NEQ ("") set vc_dir=vc11
|
||||
if ("%VS120COMNTOOLS%") NEQ ("") set vc_dir=vc12
|
||||
if ("%VS140COMNTOOLS%") NEQ ("") set vc_dir=vc14
|
||||
:: To use Microsoft* Visual Studio* 2017 IDE, make sure the variable VS150COMNTOOLS is set in your IDE instance.
|
||||
:: If it is not, try running Microsoft Visual Studio 2018 from Microsoft* Developer Command Prompt* for VS 2017.
|
||||
:: For details, see https://developercommunity.visualstudio.com/content/problem/730/vs154-env-var-vs150comntools-missing-from-build-sy.html
|
||||
if ("%VS150COMNTOOLS%") NEQ ("") set vc_dir=vc14
|
||||
|
||||
:: Are we standalone/oss or inside compiler?
|
||||
if exist "%TBBROOT%\bin\%arch%\%vc_dir%\tbb%postfix%.dll" set interim_path=bin\%arch%
|
||||
if exist "%TBBROOT%\..\redist\%arch%\tbb\%vc_dir%\tbb%postfix%.dll" set interim_path=..\redist\%arch%\tbb
|
||||
if ("%interim_path%") == ("") goto error1
|
||||
|
||||
:: Do we provide vc_mt binaries?
|
||||
if exist "%TBBROOT%\%interim_path%\vc_mt\tbb%postfix%.dll" set vc_dir=vc_mt
|
||||
if ("%vc_dir%") == ("") goto error2
|
||||
|
||||
:: We know everything we wanted and there are no errors
|
||||
:: Copying binaries
|
||||
|
||||
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.dll" "%output_dir%"
|
||||
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb%postfix%.pdb" "%output_dir%"
|
||||
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.dll" "%output_dir%"
|
||||
copy "%TBBROOT%\%interim_path%\%vc_dir%\tbbmalloc%postfix%.pdb" "%output_dir%"
|
||||
if exist "%TBBROOT%\%interim_path%\%vc_dir%\tbb_preview%postfix%.dll" copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb_preview%postfix%.dll" "%output_dir%"
|
||||
if exist "%TBBROOT%\%interim_path%\%vc_dir%\tbb_preview%postfix%.pdb" copy "%TBBROOT%\%interim_path%\%vc_dir%\tbb_preview%postfix%.pdb" "%output_dir%"
|
||||
|
||||
goto end
|
||||
:error0
|
||||
echo number of parameters not correct
|
||||
exit /B 1
|
||||
:error1
|
||||
echo Could not determine path to Intel(R) Threading Building Blocks (Intel(R) TBB) libraries
|
||||
exit /B 1
|
||||
:error2
|
||||
echo Could not determine Visual Studio version
|
||||
exit /B 1
|
||||
|
||||
:end
|
||||
exit /B 0
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# Copyright (c) 2018 Intel Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# detect if a compiler can support C++11
|
||||
# If CXX0XFLAGS already set, do not change it
|
||||
ifneq (,$(findstring $(CXX), icc icpc clang++))
|
||||
# every supported icc or clang is OK
|
||||
CXX0XFLAGS ?= -std=c++0x
|
||||
else
|
||||
ifneq (,$(findstring $(CXX), g++ gcc))
|
||||
ifneq (, $(strip $(shell $(CXX) -v 2>&1 | grep "clang-")))
|
||||
# This is clang actually,
|
||||
# every supported clang is OK
|
||||
CXX0XFLAGS ?= -std=c++0x
|
||||
else
|
||||
# support of lambda started GCC 4.5
|
||||
ifneq (, $(strip $(shell g++ -dumpversion | egrep "^(4\.[5-9]|[5-9])")))
|
||||
CXX0XFLAGS ?= -std=c++0x
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user