Skip to content

Commit 281d502

Browse files
authored
Initial commit of Complex multiplication sample. Modified sample.Json to include citests and guid, updated readme and latest code sample (oneapi-src#10)
* Signed-off-by: praveenkk123 <[email protected]> adding complex multiplication sample to the repo * Updated Readme, and uploaded the complex multiplication example <[email protected]> * changed id from 'i' to 'idx', moved the dpc_common.hpp to common folder, changed the variable of custom_device_selector, updated year in the license file and changed the output format similar to vector-add * removed the local copy of dpc_common.hpp and using from the oneapi path and updated the source code to use it accordingly * fixed complex.hpp licensing
1 parent 6350ca0 commit 281d502

File tree

11 files changed

+572
-0
lines changed

11 files changed

+572
-0
lines changed

DirectProgramming/DPC++/DenseLinearAlgebra/complex_mult/.gitkeep

Whitespace-only changes.
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CXX = dpcpp
2+
CXXFLAGS = -std=c++17 -g -o
3+
LDFLAGS =
4+
EXE_NAME = complex_mult.exe
5+
SOURCES = src/complex_mult.cpp
6+
7+
all: main
8+
9+
main:
10+
$(CXX) $(CXXFLAGS) $(EXE_NAME) $(SOURCES) $(LDFLAGS)
11+
12+
run:
13+
./$(EXE_NAME)
14+
15+
clean:
16+
rm -rf $(EXE_NAME)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Complex Multiplication sample
2+
3+
complex multiplication is a program that multiplies two large vectors of
4+
Complex numbers in parallel and verifies the results. It also implements
5+
custom device selector to target a specific vendor device. This program is
6+
implemented using C++ and DPC++ language for Intel CPU and accelerators.
7+
The Complex class is a custom class and this program shows how we can use
8+
custom types of classes in a DPC++ program
9+
10+
| Optimized for | Description
11+
|:--- |:---
12+
| OS | Linux Ubuntu 18.04, Windows 10
13+
| Hardware | Skylake with GEN9 or newer
14+
| Software | Intel&reg; oneAPI DPC++ Compiler (beta)
15+
| What you will learn | Using custom type classes and offloads complex number computations to GPU using Intel DPC++
16+
| Time to complete | 15 minutes
17+
18+
19+
## Purpose
20+
21+
Complex multiplication multiplies two vectors with complex numbers. The
22+
code will attempt to run the calculation on both the GPU and CPU, and then
23+
verifies the results. The size of the computation can be adjusted for
24+
heavier workloads. If successful, the name of the offload device and a
25+
success message are displayed.
26+
27+
This sample uses buffers to manage memory. For more information regarding
28+
different memory management options, refer to the vector_add sample.
29+
30+
complex multiplication includes C++ implementations of both Data Parallel
31+
(DPC++).
32+
33+
This program shows how to create a custom device selector and to target
34+
GPU or CPU of a specific vendor. The program also shows how to pass in a
35+
vector of custom Complex class objects that you can do the parallel
36+
executions on the device. The device used for compilation is displayed in
37+
the output.
38+
39+
40+
## Key implementation details
41+
42+
This program shows how we can use custom types of classes in a DPC++
43+
program and explains the basic DPC++ implementation including device
44+
selector, buffer, accessor, kernel and command group.
45+
46+
47+
## License
48+
49+
This code sample is licensed under MIT license.
50+
51+
## Building the complex_mult Program for CPU and GPU
52+
53+
### Running Samples In DevCloud
54+
If running a sample in the Intel DevCloud, remember that you must specify
55+
the compute node (CPU, GPU, FPGA) as well whether to run in batch or
56+
interactive mode. For more information see the Intel® oneAPI Base Toolkit
57+
Get Started Guide (https://devcloud.intel.com/oneapi/get-started/base-toolkit/)
58+
59+
### On a Linux* System
60+
* Build the program using Make
61+
make all
62+
63+
* Run the program
64+
make run
65+
66+
* Clean the program
67+
make clean
68+
69+
### On a Windows* System Using Visual Studio* Version 2017 or Newer
70+
* Build the program using VS2017 or VS2019
71+
Right click on the solution file and open using either VS2017 or
72+
VS2019 IDE.
73+
Right click on the project in Solution explorer and select Rebuild.
74+
From top menu select Debug -> Start without Debugging.
75+
76+
* Build the program using MSBuild
77+
Open "x64 Native Tools Command Prompt for VS2017" or "x64 Native
78+
Tools Command Prompt for VS2019"
79+
Run - MSBuild complex_mult.sln /t:Rebuild /p:Configuration="debug"
80+
81+
82+
## Running the Sample
83+
84+
### Application Parameters
85+
There are no editable parameters for this sample.
86+
87+
### Example of Output
88+
89+
```
90+
Target Device: Intel(R) Gen9
91+
92+
****************************************Multiplying Complex numbers in Parallel********************************************************
93+
[0] (2 : 4i) * (4 : 6i) = (-16 : 28i)
94+
[1] (3 : 5i) * (5 : 7i) = (-20 : 46i)
95+
[2] (4 : 6i) * (6 : 8i) = (-24 : 68i)
96+
[3] (5 : 7i) * (7 : 9i) = (-28 : 94i)
97+
[4] (6 : 8i) * (8 : 10i) = (-32 : 124i)
98+
...
99+
[9999] (10001 : 10003i) * (10003 : 10005i) = (-40012 : 200120014i)
100+
Complex multiplication successfully run on the device
101+
102+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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}") = "complex_mult", "complex_mult.vcxproj", "{3CF8E9FF-1C80-49EF-B0B4-CCF78A79DDE0}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Release|x64 = Release|x64
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3CF8E9FF-1C80-49EF-B0B4-CCF78A79DDE0}.Debug|x64.ActiveCfg = Debug|x64
15+
{3CF8E9FF-1C80-49EF-B0B4-CCF78A79DDE0}.Debug|x64.Build.0 = Debug|x64
16+
{3CF8E9FF-1C80-49EF-B0B4-CCF78A79DDE0}.Release|x64.ActiveCfg = Release|x64
17+
{3CF8E9FF-1C80-49EF-B0B4-CCF78A79DDE0}.Release|x64.Build.0 = Release|x64
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8600ACC4-94A1-4279-AC12-BA45B87E762E}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
<ClInclude Include="src\Complex.hpp" />
15+
</ItemGroup>
16+
<ItemGroup>
17+
<ClCompile Include="src\complex_mult.cpp" />
18+
</ItemGroup>
19+
<ItemGroup>
20+
<Text Include="License.txt" />
21+
</ItemGroup>
22+
<ItemGroup>
23+
<None Include="Readme.md" />
24+
</ItemGroup>
25+
<PropertyGroup Label="Globals">
26+
<VCProjectVersion>15.0</VCProjectVersion>
27+
<ProjectGuid>{3cf8e9ff-1c80-49ef-b0b4-ccf78a79dde0}</ProjectGuid>
28+
<Keyword>Win32Proj</Keyword>
29+
<RootNamespace>complex_mult</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+
</ClCompile>
112+
<Link>
113+
<SubSystem>Console</SubSystem>
114+
<GenerateDebugInformation>true</GenerateDebugInformation>
115+
</Link>
116+
</ItemDefinitionGroup>
117+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
118+
<ClCompile>
119+
<PrecompiledHeader>Use</PrecompiledHeader>
120+
<WarningLevel>Level3</WarningLevel>
121+
<Optimization>MaxSpeed</Optimization>
122+
<FunctionLevelLinking>true</FunctionLevelLinking>
123+
<IntrinsicFunctions>true</IntrinsicFunctions>
124+
<SDLCheck>true</SDLCheck>
125+
<ConformanceMode>true</ConformanceMode>
126+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
127+
</ClCompile>
128+
<Link>
129+
<SubSystem>Console</SubSystem>
130+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
131+
<OptimizeReferences>true</OptimizeReferences>
132+
<GenerateDebugInformation>true</GenerateDebugInformation>
133+
</Link>
134+
</ItemDefinitionGroup>
135+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
136+
<ClCompile>
137+
<PrecompiledHeader>Use</PrecompiledHeader>
138+
<WarningLevel>Level3</WarningLevel>
139+
<Optimization>MaxSpeed</Optimization>
140+
<FunctionLevelLinking>true</FunctionLevelLinking>
141+
<IntrinsicFunctions>true</IntrinsicFunctions>
142+
<SDLCheck>true</SDLCheck>
143+
<ConformanceMode>true</ConformanceMode>
144+
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
145+
</ClCompile>
146+
<Link>
147+
<SubSystem>Console</SubSystem>
148+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
149+
<OptimizeReferences>true</OptimizeReferences>
150+
<GenerateDebugInformation>true</GenerateDebugInformation>
151+
</Link>
152+
</ItemDefinitionGroup>
153+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
154+
<ImportGroup Label="ExtensionTargets">
155+
</ImportGroup>
156+
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="src\complex_mult.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="src\Complex.hpp">
24+
<Filter>Header Files</Filter>
25+
</ClInclude>
26+
</ItemGroup>
27+
<ItemGroup>
28+
<Text Include="License.txt" />
29+
</ItemGroup>
30+
<ItemGroup>
31+
<None Include="Readme.md" />
32+
</ItemGroup>
33+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"guid": "D725E06E-0ECE-44F8-910D-AD1A8C89ED89",
3+
"name": "Complex number Multiplication",
4+
"categories": [ "Toolkit/Intel® oneAPI Base Toolkit/oneAPI DPC++ Compiler/CPU and GPU" ],
5+
"description": "program that computes the multiplication of a Complex number",
6+
"toolchain": [ "dpcpp" ],
7+
"languages": [ { "cpp": { "properties": { "projectOptions": [ { "projectType": "makefile" } ] } } } ],
8+
"targetDevice": [ "CPU", "GPU"],
9+
"os": [ "linux", "windows" ],
10+
"builder": [ "ide", "make" ],
11+
"ciTests": {
12+
"linux": [
13+
{
14+
"steps": [
15+
"make all",
16+
"make run",
17+
"make clean"
18+
]
19+
}
20+
],
21+
"windows": [
22+
{
23+
"steps": [
24+
"MSBuild complex_mult.sln /t:Rebuild /p:Configuration=\"debug\"",
25+
"cd x64\\Debug",
26+
"complex_mult.exe"
27+
]
28+
}
29+
]
30+
}
31+
}

0 commit comments

Comments
 (0)