Skip to content

Commit 932f873

Browse files
Move matrix multiplication sample to open source repo (#46)
* Update simple add sample Signed-off-by: Maria, Moushumi <[email protected]> * Update make files Signed-off-by: Maria, Moushumi <[email protected]> * Update fpga make file Signed-off-by: Maria, Moushumi <[email protected]> * Add dpc_common.hpp * Update sample.json * Fix Makefile.win * Update Makefile.win * Update sample.json * Remove dpc_common.hpp * Update VS project file * Update README.md * Update sample.json * Add stb * Update read me file * Initial commit * Update License.txt * Change location of matrix multiplication sample Co-authored-by: JoeOster <[email protected]>
1 parent d535bed commit 932f873

File tree

9 files changed

+813
-0
lines changed

9 files changed

+813
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Copyright 2020 Intel Corporation
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.
8+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
DPCPP_CXX = dpcpp
2+
DPCPP_CXXFLAGS = -std=c++17 -g -o
3+
DPCPP_LDFLAGS =
4+
DPCPP_EXE_NAME = matrix_mul_dpc
5+
DPCPP_SOURCES = src/matrix_mul_dpcpp.cpp
6+
7+
CXX = icc
8+
OMP_CXXFLAGS = -qnextgen -fiopenmp -fopenmp-targets=spir64 -D__STRICT_ANSI__ -g -o
9+
OMP_LDFLAGS =
10+
OMP_EXE_NAME = matrix_mul_omp
11+
OMP_SOURCES = src/matrix_mul_omp.cpp
12+
13+
all:
14+
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)
15+
16+
build_dpcpp:
17+
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)
18+
19+
build_omp:
20+
$(CXX) $(OMP_CXXFLAGS) $(OMP_EXE_NAME) $(OMP_SOURCES) $(OMP_LDFLAGS)
21+
22+
23+
run:
24+
./$(DPCPP_EXE_NAME)
25+
26+
run_dpcpp:
27+
./$(DPCPP_EXE_NAME)
28+
29+
run_omp:
30+
./$(OMP_EXE_NAME)
31+
32+
33+
clean:
34+
rm -rf $(DPCPP_EXE_NAME) $(OMP_EXE_NAME)
35+
36+
37+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DPCPP_CXX = dpcpp-cl
2+
DPCPP_CXXFLAGS = /Zi /EHsc
3+
DPCPP_LDFLAGS =
4+
DPCPP_EXE_NAME = matrix_mul_dpcpp.exe
5+
DPCPP_SOURCES = src/matrix_mul_dpcpp.cpp
6+
7+
all:
8+
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) -o $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)
9+
10+
build_dpcpp:
11+
$(DPCPP_CXX) $(DPCPP_CXXFLAGS) -o $(DPCPP_EXE_NAME) $(DPCPP_SOURCES) $(DPCPP_LDFLAGS)
12+
13+
14+
run:
15+
$(DPCPP_EXE_NAME)
16+
17+
run_dpcpp:
18+
$(DPCPP_EXE_NAME)
19+
20+
21+
clean:
22+
del -rf $(DPCPP_EXE_NAME) *.pdb
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# matrix_mul sample
2+
matrix_mul is a simple program that multiplies together two large matrices and
3+
verifies the results. This program is implemented using two ways:
4+
1. Data Parallel C++ (DPC++)
5+
2. OpenMP (omp)
6+
7+
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.
8+
9+
| Optimized for | Description
10+
|:--- |:---
11+
| OS | Linux* Ubuntu* 18.04, Windows 10*
12+
| Hardware | Skylake with GEN9 or newer
13+
| Software | Intel&reg; oneAPI DPC++ Compiler beta, Intel&reg; C/C++ Compiler beta
14+
| What you will learn | Offloads computations on 2D arrays to GPU using Intel DPC++ and OpenMP
15+
| Time to complete | 15 minutes
16+
17+
### Purpose
18+
matrix_mul is a slightly more complex computation than vector_add by
19+
multiplying two large matrices. The code will attempt to run the calculation
20+
on both the GPU and CPU, and then verifies the results. The size of the
21+
computation can be adjusted for heavier workloads (defined below). If
22+
successful, the name of the offload device and a success message are
23+
displayed.
24+
25+
This sample uses buffers to manage memory. For more information regarding
26+
different memory management options, refer to the vector_add sample.
27+
28+
matrix_mul includes C++ implementations of both Data Parallel (DPC++) and
29+
OpenMP; each is contained in its own .cpp file. This provides a way to compare
30+
existing offload techniques such as OpenMP with Data Parallel C++ within a
31+
relatively simple sample. The default will build the DPC++ application.
32+
Separate OpenMP build instructions are provided below. Note: matrix_mul does not
33+
support OpenMP on Windows.
34+
35+
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.
36+
37+
## Key implementation details
38+
SYCL implementation explained.
39+
OpenMP offload implementation explained.
40+
41+
## License
42+
This code sample is licensed under MIT license.
43+
44+
## Building the `matrrix_mul` Program for DPC++ and OpenMP
45+
46+
## Include Files
47+
The include folder is located at "%ONEAPI_ROOT%\dev-utilities\latest\include" on your development system.
48+
49+
### Running Samples In DevCloud
50+
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/)
51+
52+
### How to build for DPC++ on Linux
53+
* Build the program using Make
54+
cd matrix_mul &&
55+
make all
56+
57+
* Run the program
58+
make run
59+
60+
* Clean the program
61+
make clean
62+
63+
### How to Build for OpenMP on Linux
64+
* Build the program using Make
65+
cd matrix_mul &&
66+
make build_omp
67+
68+
* Run the program
69+
make run_omp
70+
71+
* Clean the program
72+
make clean
73+
74+
### How to build for DPC++ on Windows
75+
The OpenMP offload target is not supported on Windows yet.
76+
77+
#### Command Line using MSBuild
78+
* MSBuild matrix_mul.sln /t:Rebuild /p:Configuration="release"
79+
80+
#### Command Line using nmake
81+
Build matrix_mul DPCPP version
82+
* nmake -f Makefile.win build_dpcpp
83+
* nmake -f Makefile.win run_dpcpp
84+
85+
#### Visual Studio IDE
86+
* Open Visual Studio 2017
87+
* Select Menu "File > Open > Project/Solution", find "matrix_mul" folder and select "matrix_mul.sln"
88+
* Select Menu "Project > Build" to build the selected configuration
89+
* Select Menu "Debug > Start Without Debugging" to run the program
90+
91+
### How to build for OpenMP on Windows
92+
The OpenMP offload target is not supported on Windows at this time.
93+
94+
## Running the Sample
95+
96+
### Application Parameters
97+
You can modify the size of the computation by adjusting the size parameter
98+
(must be in multiples of 8) in the dpcpp and omp .cpp files. The configurable parameters include:
99+
size = m_size = 150*8; // Must be a multiple of 8.
100+
M = m_size / 8;
101+
N = m_size / 4;
102+
P = m_size / 2;
103+
104+
### Example of Output
105+
#### DPC++
106+
```
107+
./matrix_mul_dpc
108+
Running on device: Intel(R) Gen9 HD Graphics NEO
109+
Problem size: c(150,600) = a(150,300) * b(300,600)
110+
Result of matrix multiplication using DPC++: Success - The results are correct!
111+
```
112+
113+
#### OpenMP
114+
```
115+
./matrix_mul_omp
116+
Problem size: c(150,600) = a(150,300) * b(300,600)
117+
Running on 1 device(s)
118+
The default device id: 0
119+
Result of matrix multiplication using OpenMP: Success - The results are correct!
120+
Result of matrix multiplication using GPU offloading: Success - The results are correct!
121+
```
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.136
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "matrix_mul_dpcpp", "matrix_mul_dpcpp.vcxproj", "{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x64.ActiveCfg = Debug|x64
17+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x64.Build.0 = Debug|x64
18+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Debug|x86.ActiveCfg = Debug|x64
19+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x64.ActiveCfg = Release|x64
20+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x64.Build.0 = Release|x64
21+
{F8B26A6E-0121-4F4C-8FA9-9784852574C3}.Release|x86.ActiveCfg = Release|x64
22+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x64.ActiveCfg = Debug|x64
23+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x64.Build.0 = Debug|x64
24+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Debug|x86.ActiveCfg = Debug|x64
25+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x64.ActiveCfg = Release|x64
26+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x64.Build.0 = Release|x64
27+
{D41BAFBF-46E8-4BF6-AC99-5A311221E7C5}.Release|x86.ActiveCfg = Release|x64
28+
EndGlobalSection
29+
GlobalSection(SolutionProperties) = preSolution
30+
HideSolutionNode = FALSE
31+
EndGlobalSection
32+
GlobalSection(ExtensibilityGlobals) = postSolution
33+
SolutionGuid = {7AC5E5BB-5E3D-4F82-8BBD-90BE285EEE77}
34+
EndGlobalSection
35+
EndGlobal
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|x64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>x64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|x64">
9+
<Configuration>Release</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<Text Include="License.txt" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<None Include="README.md" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<ClCompile Include="src\matrix_mul_dpcpp.cpp">
21+
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
22+
</AdditionalIncludeDirectories>
23+
</ClCompile>
24+
</ItemGroup>
25+
<PropertyGroup Label="Globals">
26+
<VCProjectVersion>15.0</VCProjectVersion>
27+
<ProjectGuid>{d41bafbf-46e8-4bf6-ac99-5a311221e7c5}</ProjectGuid>
28+
<Keyword>Win32Proj</Keyword>
29+
<RootNamespace>matrix_mul_dpcpp</RootNamespace>
30+
<WindowsTargetPlatformVersion>$(WindowsSDKVersion.Replace("\",""))</WindowsTargetPlatformVersion>
31+
</PropertyGroup>
32+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
34+
<ConfigurationType>Application</ConfigurationType>
35+
<UseDebugLibraries>true</UseDebugLibraries>
36+
<PlatformToolset>oneAPI Data Parallel C++ Compiler</PlatformToolset>
37+
<CharacterSet>Unicode</CharacterSet>
38+
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
40+
<ConfigurationType>Application</ConfigurationType>
41+
<UseDebugLibraries>false</UseDebugLibraries>
42+
<PlatformToolset>oneAPI Data Parallel C++ Compiler</PlatformToolset>
43+
<WholeProgramOptimization>true</WholeProgramOptimization>
44+
<CharacterSet>Unicode</CharacterSet>
45+
</PropertyGroup>
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
47+
<ConfigurationType>Application</ConfigurationType>
48+
<UseDebugLibraries>true</UseDebugLibraries>
49+
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler</PlatformToolset>
50+
<CharacterSet>Unicode</CharacterSet>
51+
</PropertyGroup>
52+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
53+
<ConfigurationType>Application</ConfigurationType>
54+
<UseDebugLibraries>false</UseDebugLibraries>
55+
<PlatformToolset>Intel(R) oneAPI DPC++ Compiler</PlatformToolset>
56+
<WholeProgramOptimization>true</WholeProgramOptimization>
57+
<CharacterSet>Unicode</CharacterSet>
58+
</PropertyGroup>
59+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
60+
<ImportGroup Label="ExtensionSettings">
61+
</ImportGroup>
62+
<ImportGroup Label="Shared">
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
71+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
72+
</ImportGroup>
73+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
74+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
75+
</ImportGroup>
76+
<PropertyGroup Label="UserMacros" />
77+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
78+
<LinkIncremental>true</LinkIncremental>
79+
</PropertyGroup>
80+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
81+
<LinkIncremental>true</LinkIncremental>
82+
</PropertyGroup>
83+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
84+
<LinkIncremental>false</LinkIncremental>
85+
</PropertyGroup>
86+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
87+
<LinkIncremental>false</LinkIncremental>
88+
</PropertyGroup>
89+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
90+
<ClCompile>
91+
<PrecompiledHeader>Use</PrecompiledHeader>
92+
<WarningLevel>Level3</WarningLevel>
93+
<Optimization>Disabled</Optimization>
94+
<SDLCheck>true</SDLCheck>
95+
<ConformanceMode>true</ConformanceMode>
96+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
97+
</ClCompile>
98+
<Link>
99+
<SubSystem>Console</SubSystem>
100+
<GenerateDebugInformation>true</GenerateDebugInformation>
101+
</Link>
102+
</ItemDefinitionGroup>
103+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<ClCompile>
105+
<PrecompiledHeader>Use</PrecompiledHeader>
106+
<WarningLevel>Level3</WarningLevel>
107+
<Optimization>Disabled</Optimization>
108+
<SDLCheck>true</SDLCheck>
109+
<ConformanceMode>true</ConformanceMode>
110+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
111+
<SYCLWarningLevel>DisableAllWarnings</SYCLWarningLevel>
112+
<AdditionalIncludeDirectories>$(ONEAPI_ROOT)dev-utilities\latest\include</AdditionalIncludeDirectories>
113+
</ClCompile>
114+
<Link>
115+
<SubSystem>Console</SubSystem>
116+
<GenerateDebugInformation>true</GenerateDebugInformation>
117+
</Link>
118+
</ItemDefinitionGroup>
119+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
120+
<ClCompile>
121+
<PrecompiledHeader>Use</PrecompiledHeader>
122+
<WarningLevel>Level3</WarningLevel>
123+
<Optimization>MaxSpeed</Optimization>
124+
<FunctionLevelLinking>true</FunctionLevelLinking>
125+
<IntrinsicFunctions>true</IntrinsicFunctions>
126+
<SDLCheck>true</SDLCheck>
127+
<ConformanceMode>true</ConformanceMode>
128+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
129+
</ClCompile>
130+
<Link>
131+
<SubSystem>Console</SubSystem>
132+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
133+
<OptimizeReferences>true</OptimizeReferences>
134+
<GenerateDebugInformation>true</GenerateDebugInformation>
135+
</Link>
136+
</ItemDefinitionGroup>
137+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
138+
<ClCompile>
139+
<PrecompiledHeader>Use</PrecompiledHeader>
140+
<WarningLevel>Level3</WarningLevel>
141+
<Optimization>MaxSpeed</Optimization>
142+
<FunctionLevelLinking>true</FunctionLevelLinking>
143+
<IntrinsicFunctions>true</IntrinsicFunctions>
144+
<SDLCheck>true</SDLCheck>
145+
<ConformanceMode>true</ConformanceMode>
146+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
147+
<SYCLWarningLevel>DisableAllWarnings</SYCLWarningLevel>
148+
<AdditionalIncludeDirectories>$(ONEAPI_ROOT)dev-utilities\latest\include</AdditionalIncludeDirectories>
149+
</ClCompile>
150+
<Link>
151+
<SubSystem>Console</SubSystem>
152+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
153+
<OptimizeReferences>true</OptimizeReferences>
154+
<GenerateDebugInformation>true</GenerateDebugInformation>
155+
</Link>
156+
</ItemDefinitionGroup>
157+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
158+
<ImportGroup Label="ExtensionTargets">
159+
</ImportGroup>
160+
</Project>

0 commit comments

Comments
 (0)