From 20b8f630b262c0ccc7e42181ff5fa86a3c6f45e2 Mon Sep 17 00:00:00 2001 From: gejin Date: Wed, 24 Jun 2020 18:09:36 +0800 Subject: [PATCH] Add link to examples in README Signed-off-by: gejin --- README.md | 3 + examples/.gitignore | 0 .../dpcpp_gamma_correction/CMakeLists.txt | 12 -- examples/dpcpp_gamma_correction/README.md | 44 ---- .../dpcpp_gamma_correction/src/CMakeLists.txt | 25 --- examples/dpcpp_gamma_correction/src/main.cpp | 102 --------- examples/dpcpp_gamma_correction/src/utils.hpp | 17 -- .../dpcpp_gamma_correction/src/utils/Img.hpp | 204 ------------------ .../src/utils/ImgAlgorithm.hpp | 50 ----- .../src/utils/ImgFormat.hpp | 98 --------- .../src/utils/ImgPixel.hpp | 40 ---- .../src/utils/Other.hpp | 31 --- examples/stable_sort_by_key/CMakeLists.txt | 12 -- examples/stable_sort_by_key/README.md | 47 ---- .../stable_sort_by_key/src/CMakeLists.txt | 24 --- examples/stable_sort_by_key/src/main.cpp | 78 ------- 16 files changed, 3 insertions(+), 784 deletions(-) delete mode 100644 examples/.gitignore delete mode 100644 examples/dpcpp_gamma_correction/CMakeLists.txt delete mode 100644 examples/dpcpp_gamma_correction/README.md delete mode 100644 examples/dpcpp_gamma_correction/src/CMakeLists.txt delete mode 100644 examples/dpcpp_gamma_correction/src/main.cpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils.hpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils/Img.hpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils/ImgAlgorithm.hpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils/ImgFormat.hpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils/ImgPixel.hpp delete mode 100644 examples/dpcpp_gamma_correction/src/utils/Other.hpp delete mode 100644 examples/stable_sort_by_key/CMakeLists.txt delete mode 100644 examples/stable_sort_by_key/README.md delete mode 100644 examples/stable_sort_by_key/src/CMakeLists.txt delete mode 100644 examples/stable_sort_by_key/src/main.cpp diff --git a/README.md b/README.md index 1967a3a1dde..9c384a784aa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ oneDPL is licensed under [Apache License Version 2.0 with LLVM exceptions](https ## Documentation See [Library Guide](https://software.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top.html) with oneDPL. +## Examples +You can find oneDPL examples in [Examples](https://github.com/intel/BaseKit-code-samples/tree/master/DPC++Compiler/oneDPL). + ## Support and contribution Please report issues and suggestions via [GitHub issues](https://github.com/oneapi-src/oneDPL/issues). diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/examples/dpcpp_gamma_correction/CMakeLists.txt b/examples/dpcpp_gamma_correction/CMakeLists.txt deleted file mode 100644 index 415e4595008..00000000000 --- a/examples/dpcpp_gamma_correction/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -set(CMAKE_CXX_COMPILER "dpcpp") -# Set default build type to RelWithDebInfo if not specified -if (NOT CMAKE_BUILD_TYPE) - message (STATUS "Default CMAKE_BUILD_TYPE not set using Release with Debug Info") - set (CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE - STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" - FORCE) -endif() - -cmake_minimum_required (VERSION 3.0) -project(gamma_correction LANGUAGES CXX) -add_subdirectory (src) diff --git a/examples/dpcpp_gamma_correction/README.md b/examples/dpcpp_gamma_correction/README.md deleted file mode 100644 index a01566419ac..00000000000 --- a/examples/dpcpp_gamma_correction/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# Gamma Correction sample - -This example demonstrates gamma correction - a nonlinear operation used to encode and decode the luminance of each image pixel. See https://en.wikipedia.org/wiki/Gamma_correction for more information. - -The example creates a fractal image in memory and performs gamma correction on it. The output of the example application is a BMP image with corrected luminance. - -The computations are performed using DPC++ backend of Parallel STL. - - -| Optimized for | Description | -|---------------------------------|-----------------------------------------------------------------| -| OS | Linux Ubuntu 18.04 | -| Hardware | SKL with GEN9 or newer | -| Software | Intel Data Parallel C++ Compiler beta | -| What you will learn | How to offoad the computation to GPU using Intel DPC++ Compiler | -| Time to complete | 5 minutes | - -## License - -This code sample is licensed under MIT license. - -## How to build - -```bash -# To this point you should have -# - TBB and Parallel STL installed and -# - environment variables set up to use them - -# Configure, build and run the example -mkdir build && cd build # execute in this directory -CXX=clang++ cmake .. -cmake --build . # or "make" -cmake --build . --target run # or "make run" -``` - -You can also pass - -- options during the configuration: - ```bash - CXX=clang++ cmake .. - cmake --build . # or "make" - cmake --build . --target run # or "make run" - ``` - diff --git a/examples/dpcpp_gamma_correction/src/CMakeLists.txt b/examples/dpcpp_gamma_correction/src/CMakeLists.txt deleted file mode 100644 index aa6c71db381..00000000000 --- a/examples/dpcpp_gamma_correction/src/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -if (NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 11) -endif() - -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE RelWithDebInfo) -endif() - -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") - -# Add an executable target from source files -add_executable(${PROJECT_NAME} main.cpp) - -# Specify compilation flags for the target -target_compile_options(${PROJECT_NAME} PRIVATE -fsycl -fsycl-unnamed-lambda) - -# Specify compilation definitions for the target -target_compile_definitions(${PROJECT_NAME} PRIVATE -D_PSTL_BACKEND_SYCL) - -# Specify libraries to link with -target_link_libraries(${PROJECT_NAME} OpenCL sycl) - -# Add custom target for running -add_custom_target(run ./${PROJECT_NAME}) diff --git a/examples/dpcpp_gamma_correction/src/main.cpp b/examples/dpcpp_gamma_correction/src/main.cpp deleted file mode 100644 index cb760091fa9..00000000000 --- a/examples/dpcpp_gamma_correction/src/main.cpp +++ /dev/null @@ -1,102 +0,0 @@ -//============================================================== -// Copyright © 2019 Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#include -#include - -#include - -#include -#include -#include - -#include "utils.hpp" - -#if !__SYCL_UNNAMED_LAMBDA__ -// In case of missing the -fsycl-unnamed-lambda option or using -// the -fno-sycl-unnamed-lambda option in command line -// we should name policy explicitly. -// Policy names are below -class Gamma; -#endif - -int main() { - // Image size is width x height - int width = 2560; - int height = 1600; - - Img image{width, height}; - ImgFractal fractal{width, height}; - - // Lambda to process image with gamma = 2 - auto gamma_f = [](ImgPixel& pixel) { - float v = (0.3f * pixel.r + 0.59f * pixel.g + 0.11f * pixel.b) / 255.0f; - - std::uint8_t gamma_pixel = static_cast(255 * v * v); - if (gamma_pixel > 255) gamma_pixel = 255; - pixel.set(gamma_pixel, gamma_pixel, gamma_pixel, gamma_pixel); - }; - - // fill image with created fractal - int index = 0; - image.fill([&index, width, &fractal](ImgPixel& pixel) { - int x = index % width; - int y = index / width; - - auto fractal_pixel = fractal(x, y); - if (fractal_pixel < 0) fractal_pixel = 0; - if (fractal_pixel > 255) fractal_pixel = 255; - pixel.set(fractal_pixel, fractal_pixel, fractal_pixel, fractal_pixel); - - ++index; - }); - - Img image2 = image; - image.write("fractal_original.bmp"); - - // call standard serial function for correctness check - image.fill(gamma_f); - image.write("fractal_gamma.bmp"); - - // create a queue for tasks, sent to the device - cl::sycl::queue queue(cl::sycl::default_selector{}); - - // We need to have the scope to have data in image2 after buffer's destruction - { - // create a buffer, being responsible for moving data around and counting - // dependencies - cl::sycl::buffer buffer(image2.data(), - image2.width() * image2.height()); - - // create iterator to pass buffer to the algorithm - auto buffer_begin = dpstd::begin(buffer); - auto buffer_end = dpstd::end(buffer); - - // choose policy we will provide to the algorithm -#if __SYCL_UNNAMED_LAMBDA__ - auto new_policy = dpstd::execution::default_policy; -#else - // create named policy from queue - auto new_policy = dpstd::execution::make_device_policy(queue); -#endif - // call std::for_each with DPC++ support - std::for_each(new_policy, buffer_begin, buffer_end, gamma_f); - } - - // check correctness - if (check(image.begin(), image.end(), image2.begin())) { - std::cout << "success"; - } else { - std::cout << "fail"; - } - std::cout << ". Run on " - << queue.get_device().get_info() - << std::endl; - - image.write("fractal_gamma_pstlwithsycl.bmp"); - - return 0; -} diff --git a/examples/dpcpp_gamma_correction/src/utils.hpp b/examples/dpcpp_gamma_correction/src/utils.hpp deleted file mode 100644 index 3042d464002..00000000000 --- a/examples/dpcpp_gamma_correction/src/utils.hpp +++ /dev/null @@ -1,17 +0,0 @@ -//============================================================== -// Copyright © 2019 Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#ifndef _GAMMA_UTILS_HPP -#define _GAMMA_UTILS_HPP - -#include "utils/Img.hpp" -#include "utils/ImgAlgorithm.hpp" -#include "utils/ImgFormat.hpp" -#include "utils/ImgPixel.hpp" - -#include "utils/Other.hpp" - -#endif // _GAMMA_UTILS_HPP diff --git a/examples/dpcpp_gamma_correction/src/utils/Img.hpp b/examples/dpcpp_gamma_correction/src/utils/Img.hpp deleted file mode 100644 index c775b37defc..00000000000 --- a/examples/dpcpp_gamma_correction/src/utils/Img.hpp +++ /dev/null @@ -1,204 +0,0 @@ -//============================================================== -// Copyright © 2019 Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#ifndef _GAMMA_UTILS_IMG_HPP -#define _GAMMA_UTILS_IMG_HPP - -#include "ImgPixel.hpp" - -#include -#include -#include -#include - -// Image class definition -template -class Img { - private: - Format _format; - std::int32_t _width; - std::int32_t _height; - std::vector _pixels; - - using Iterator = std::vector::iterator; - using ConstIterator = std::vector::const_iterator; - - public: - ///////////////////// - // SPECIAL METHODS // - ///////////////////// - - Img(std::int32_t width, std::int32_t height); - - void reset(std::int32_t width, std::int32_t height); - - /////////////// - // ITERATORS // - /////////////// - - Iterator begin() noexcept; - Iterator end() noexcept; - ConstIterator begin() const noexcept; - ConstIterator end() const noexcept; - ConstIterator cbegin() const noexcept; - ConstIterator cend() const noexcept; - - ///////////// - // GETTERS // - ///////////// - - std::int32_t width() const noexcept; - std::int32_t height() const noexcept; - - ImgPixel const* data() const noexcept; - ImgPixel* data() noexcept; - - /////////////////// - // FUNCTIONALITY // - /////////////////// - - void write(std::string const& filename) const; - - template - void fill(Functor f); - void fill(ImgPixel pixel); - void fill(ImgPixel pixel, std::int32_t row, std::int32_t col); -}; - -/////////////////////////////////////////////// -// IMG CLASS IMPLEMENTATION: SPECIAL METHODS // -/////////////////////////////////////////////// - -template -Img::Img(std::int32_t width, std::int32_t height) - : _format(width, height) { - _pixels.resize(width * height); - - _width = width; - _height = height; -} - -template -void Img::reset(std::int32_t width, std::int32_t height) { - _pixels.resize(width * height); - - _width = width; - _height = height; - - _format.reset(width, height); -} - -///////////////////////////////////////// -// IMG CLASS IMPLEMENTATION: ITERATORS // -///////////////////////////////////////// - -template -typename Img::Iterator Img::begin() noexcept { - return _pixels.begin(); -} - -template -typename Img::Iterator Img::end() noexcept { - return _pixels.end(); -} - -template -typename Img::ConstIterator Img::begin() const noexcept { - return _pixels.begin(); -} - -template -typename Img::ConstIterator Img::end() const noexcept { - return _pixels.end(); -} - -template -typename Img::ConstIterator Img::cbegin() const noexcept { - return _pixels.begin(); -} - -template -typename Img::ConstIterator Img::cend() const noexcept { - return _pixels.end(); -} - -/////////////////////////////////////// -// IMG CLASS IMPLEMENTATION: GETTERS // -/////////////////////////////////////// - -template -std::int32_t Img::width() const noexcept { - return _width; -} - -template -std::int32_t Img::height() const noexcept { - return _height; -} - -template -ImgPixel const* Img::data() const noexcept { - return _pixels.data(); -} - -template -ImgPixel* Img::data() noexcept { - return _pixels.data(); -} - -///////////////////////////////////////////// -// IMG CLASS IMPLEMENTATION: FUNCTIONALITY // -///////////////////////////////////////////// - -template -void Img::write(std::string const& filename) const { - if (_pixels.empty()) { - std::cerr << "Img::write:: image is empty" << std::endl; - return; - } - - std::ofstream filestream(filename, std::ios::binary); - - _format.write(filestream, *this); -} - -template -template -void Img::fill(Functor f) { - if (_pixels.empty()) { - std::cerr << "Img::fill(Functor): image is empty" << std::endl; - return; - } - - for (auto& pixel : _pixels) f(pixel); -} - -template -void Img::fill(ImgPixel pixel) { - if (_pixels.empty()) { - std::cerr << "Img::fill(ImgPixel): image is empty" << std::endl; - return; - } - - std::fill(_pixels.begin(), _pixels.end(), pixel); -} - -template -void Img::fill(ImgPixel pixel, int row, int col) { - if (_pixels.empty()) { - std::cerr << "Img::fill(ImgPixel): image is empty" << std::endl; - return; - } - - if (row >= _height || row < 0 || col >= _width || col < 0) { - std::cerr << "Img::fill(ImgPixel, int, int): out of range" << std::endl; - return; - } - - _pixels.at(row * _width + col) = pixel; -} - -#endif // _GAMMA_UTILS_IMG_HPP diff --git a/examples/dpcpp_gamma_correction/src/utils/ImgAlgorithm.hpp b/examples/dpcpp_gamma_correction/src/utils/ImgAlgorithm.hpp deleted file mode 100644 index 1da3bf941de..00000000000 --- a/examples/dpcpp_gamma_correction/src/utils/ImgAlgorithm.hpp +++ /dev/null @@ -1,50 +0,0 @@ -//============================================================== -// Copyright © 2019 Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#ifndef _GAMMA_UTILS_IMGALGORITHM_HPP -#define _GAMMA_UTILS_IMGALGORITHM_HPP - -#include -#include - -// struct to store fractal that image will fill from -class ImgFractal { - private: - const std::int32_t _width; - const std::int32_t _height; - - double _cx = -0.7436; - double _cy = 0.1319; - - double _magn = 2000000.0; - int _maxIterations = 1000; - - public: - ImgFractal(std::int32_t width, std::int32_t height) - : _width(width), _height(height) {} - - double operator()(std::int32_t x, std::int32_t y) const { - double fx = (double(x) - double(_width) / 2) * (1 / _magn) + _cx; - double fy = (double(y) - double(_height) / 2) * (1 / _magn) + _cy; - - double res = 0; - double nx = 0; - double ny = 0; - double val = 0; - - for (int i = 0; nx * nx + ny * ny <= 4 && i < _maxIterations; ++i) { - val = nx * nx - ny * ny + fx; - ny = 2 * nx * ny + fy; - nx = val; - - res += std::exp(-std::sqrt(nx * nx + ny * ny)); - } - - return res; - } -}; - -#endif // _GAMMA_UTILS_IMGALGORITHM_HPP diff --git a/examples/dpcpp_gamma_correction/src/utils/ImgFormat.hpp b/examples/dpcpp_gamma_correction/src/utils/ImgFormat.hpp deleted file mode 100644 index 6e0c1c4dfb8..00000000000 --- a/examples/dpcpp_gamma_correction/src/utils/ImgFormat.hpp +++ /dev/null @@ -1,98 +0,0 @@ -//============================================================== -// Copyright © 2019 Intel Corporation -// -// SPDX-License-Identifier: MIT -// ============================================================= - -#ifndef _GAMMA_UTILS_IMGFORMAT_HPP -#define _GAMMA_UTILS_IMGFORMAT_HPP - -#include "ImgPixel.hpp" - -#include - -namespace ImgFormat { - -// struct to store an image in BMP format -struct BMP { - private: - using FileHeader = struct { - // not from specification - // was added for alignemt - // store size of rest of the fields - std::uint16_t sizeRest; // file header size in bytes - - std::uint16_t type; - std::uint32_t size; // file size in bytes - std::uint32_t reserved; - std::uint32_t offBits; // cumulative header size in bytes - }; - - using InfoHeader = struct { - // from specification - // store size of rest of the fields - std::uint32_t size; // info header size in bytes - - std::int32_t width; // image width in pixels - std::int32_t height; // image height in pixels - std::uint16_t planes; - std::uint16_t bitCount; // color depth - std::uint32_t compression; // compression - std::uint32_t sizeImage; // image map size in bytes - std::int32_t xPelsPerMeter; // pixel per metre (y axis) - std::int32_t yPelsPerMeter; // pixel per metre (y axis) - std::uint32_t clrUsed; // color pallete (0 is default) - std::uint32_t clrImportant; - }; - - FileHeader _fileHeader; - InfoHeader _infoHeader; - - public: - BMP(std::int32_t width, std::int32_t height) noexcept { - reset(width, height); - } - - void reset(std::int32_t width, std::int32_t height) noexcept { - uint32_t padSize = (4 - (width * sizeof(ImgPixel)) % 4) % 4; - uint32_t mapSize = width * height * sizeof(ImgPixel) + height * padSize; - uint32_t allSize = mapSize + _fileHeader.sizeRest + _infoHeader.size; - - _fileHeader.sizeRest = 14; // file header size in bytes - _fileHeader.type = 0x4d42; - _fileHeader.size = allSize; // file size in bytes - _fileHeader.reserved = 0; - _fileHeader.offBits = 54; // sizeRest + size -> 14 + 40 -> 54 - - _infoHeader.size = 40; // info header size in bytes - _infoHeader.width = width; // image width in pixels - _infoHeader.height = height; // image height in pixels - _infoHeader.planes = 1; - _infoHeader.bitCount = 32; // color depth - _infoHeader.compression = 0; // compression - _infoHeader.sizeImage = mapSize; // image map size in bytes - _infoHeader.xPelsPerMeter = 0; // pixel per metre (x axis) - _infoHeader.yPelsPerMeter = 0; // pixel per metre (y axis) - _infoHeader.clrUsed = 0; // color pallete (0 is default) - _infoHeader.clrImportant = 0; - } - - template