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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Copyright 2020 Intel Corporation

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.

37 changes: 37 additions & 0 deletions DirectProgramming/DPC++/DenseLinearAlgebra/matrix_mul/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
DPCPP_CXX = dpcpp
DPCPP_CXXFLAGS = -std=c++17 -g -o
DPCPP_LDFLAGS =
DPCPP_EXE_NAME = matrix_mul_dpc
DPCPP_SOURCES = src/matrix_mul_dpcpp.cpp

CXX = icc
OMP_CXXFLAGS = -qnextgen -fiopenmp -fopenmp-targets=spir64 -D__STRICT_ANSI__ -g -o
OMP_LDFLAGS =
OMP_EXE_NAME = matrix_mul_omp
OMP_SOURCES = src/matrix_mul_omp.cpp

all:
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)

build_dpcpp:
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)

build_omp:
$(CXX) $(OMP_CXXFLAGS) $(OMP_EXE_NAME) $(OMP_SOURCES) $(OMP_LDFLAGS)


run:
./$(DPCPP_EXE_NAME)

run_dpcpp:
./$(DPCPP_EXE_NAME)

run_omp:
./$(OMP_EXE_NAME)


clean:
rm -rf $(DPCPP_EXE_NAME) $(OMP_EXE_NAME)



22 changes: 22 additions & 0 deletions DirectProgramming/DPC++/DenseLinearAlgebra/matrix_mul/Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DPCPP_CXX = dpcpp-cl
DPCPP_CXXFLAGS = /Zi /EHsc
DPCPP_LDFLAGS =
DPCPP_EXE_NAME = matrix_mul_dpcpp.exe
DPCPP_SOURCES = src/matrix_mul_dpcpp.cpp

all:
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) -o $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)

build_dpcpp:
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) -o $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)


run:
$(DPCPP_EXE_NAME)

run_dpcpp:
$(DPCPP_EXE_NAME)


clean:
del -rf $(DPCPP_EXE_NAME) *.pdb
121 changes: 121 additions & 0 deletions DirectProgramming/DPC++/DenseLinearAlgebra/matrix_mul/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# matrix_mul sample
matrix_mul is a simple program that multiplies together two large matrices and
verifies the results. This program is implemented using two ways:
1. Data Parallel C++ (DPC++)
2. OpenMP (omp)

For comprehensive instructions regarding DPC++ Programming, go to https://software.intel.com/en-us/oneapi-programming-guide and search based on relevant terms noted in the comments.

| Optimized for | Description
|:--- |:---
| OS | Linux* Ubuntu* 18.04, Windows 10*
| Hardware | Skylake with GEN9 or newer
| Software | Intel® oneAPI DPC++ Compiler beta, Intel® C/C++ Compiler beta
| What you will learn | Offloads computations on 2D arrays to GPU using Intel DPC++ and OpenMP
| Time to complete | 15 minutes

### Purpose
matrix_mul is a slightly more complex computation than vector_add by
multiplying two large matrices. The code will attempt to run the calculation
on both the GPU and CPU, and then verifies the results. The size of the
computation can be adjusted for heavier workloads (defined below). If
successful, the name of the offload device and a success message are
displayed.

This sample uses buffers to manage memory. For more information regarding
different memory management options, refer to the vector_add sample.

matrix_mul includes C++ implementations of both Data Parallel (DPC++) and
OpenMP; each is contained in its own .cpp file. This provides a way to compare
existing offload techniques such as OpenMP with Data Parallel C++ within a
relatively simple sample. The default will build the DPC++ application.
Separate OpenMP build instructions are provided below. Note: matrix_mul does not
support OpenMP on Windows.

The code will attempt first to execute on an available GPU and fallback to the system's CPU if a compatible GPU is not detected. The device used for compilation is displayed in the output.

## Key implementation details
SYCL implementation explained.
OpenMP offload implementation explained.

## License
This code sample is licensed under MIT license.

## Building the `matrrix_mul` Program for DPC++ and OpenMP

## Include Files
The include folder is located at "%ONEAPI_ROOT%\dev-utilities\latest\include" on your development system.

### Running Samples In DevCloud
If running a sample in the Intel DevCloud, remember that you must specify the compute node (CPU, GPU, FPGA) as well whether to run in batch or interactive mode. For more information see the Intel® oneAPI Base Toolkit Get Started Guide (https://devcloud.intel.com/oneapi/get-started/hpc-toolkit/)

### How to build for DPC++ on Linux
* Build the program using Make
cd matrix_mul &&
make all

* Run the program
make run

* Clean the program
make clean

### How to Build for OpenMP on Linux
* Build the program using Make
cd matrix_mul &&
make build_omp

* Run the program
make run_omp

* Clean the program
make clean

### How to build for DPC++ on Windows
The OpenMP offload target is not supported on Windows yet.

#### Command Line using MSBuild
* MSBuild matrix_mul.sln /t:Rebuild /p:Configuration="release"

#### Command Line using nmake
Build matrix_mul DPCPP version
* nmake -f Makefile.win build_dpcpp
* nmake -f Makefile.win run_dpcpp

#### Visual Studio IDE
* Open Visual Studio 2017
* Select Menu "File > Open > Project/Solution", find "matrix_mul" folder and select "matrix_mul.sln"
* Select Menu "Project > Build" to build the selected configuration
* Select Menu "Debug > Start Without Debugging" to run the program

### How to build for OpenMP on Windows
The OpenMP offload target is not supported on Windows at this time.

## Running the Sample

### Application Parameters
You can modify the size of the computation by adjusting the size parameter
(must be in multiples of 8) in the dpcpp and omp .cpp files. The configurable parameters include:
size = m_size = 150*8; // Must be a multiple of 8.
M = m_size / 8;
N = m_size / 4;
P = m_size / 2;

### Example of Output
#### DPC++
```
./matrix_mul_dpc
Running on device: Intel(R) Gen9 HD Graphics NEO
Problem size: c(150,600) = a(150,300) * b(300,600)
Result of matrix multiplication using DPC++: Success - The results are correct!
```

#### OpenMP
```
./matrix_mul_omp
Problem size: c(150,600) = a(150,300) * b(300,600)
Running on 1 device(s)
The default device id: 0
Result of matrix multiplication using OpenMP: Success - The results are correct!
Result of matrix multiplication using GPU offloading: Success - The results are correct!
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "matrix_mul_dpcpp", "matrix_mul_dpcpp.vcxproj", "{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x64.ActiveCfg = Debug|x64
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x64.Build.0 = Debug|x64
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x86.ActiveCfg = Debug|x64
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x64.ActiveCfg = Release|x64
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x64.Build.0 = Release|x64
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x86.ActiveCfg = Release|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x64.ActiveCfg = Debug|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x64.Build.0 = Debug|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x86.ActiveCfg = Debug|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x64.ActiveCfg = Release|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x64.Build.0 = Release|x64
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x86.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7AC5E5BB-5E3D-4F82-8BBD-90BE285EEE77}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<Text Include="License.txt" />
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\matrix_mul_dpcpp.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
</AdditionalIncludeDirectories>
</ClCompile>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{d41bafbf-46e8-4bf6-ac99-5a311221e7c5}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>matrix_mul_dpcpp</RootNamespace>
<WindowsTargetPlatformVersion>$(WindowsSDKVersion.Replace("\",""))</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>oneAPI Data Parallel C++ Compiler</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>oneAPI Data Parallel C++ Compiler</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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 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 Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<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'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<SYCLWarningLevel>DisableAllWarnings</SYCLWarningLevel>
<AdditionalIncludeDirectories>$(ONEAPI_ROOT)dev-utilities\latest\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<SYCLWarningLevel>DisableAllWarnings</SYCLWarningLevel>
<AdditionalIncludeDirectories>$(ONEAPI_ROOT)dev-utilities\latest\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
Loading