Browse Source

Common code in separate project

master
Daniel Gyulai 3 years ago
parent
commit
0b1def7772
  1. 208
      Common/Common.cpp
  2. 0
      Common/Common.h
  3. 157
      Common/Common.vcxproj
  4. 39
      Common/Common.vcxproj.filters
  5. 85
      Common/OpenCLHandler.cpp
  6. 16
      Common/OpenCLHandler.h
  7. 2
      Common/Tests.h
  8. 12937
      Common/cl.hpp
  9. 5
      Linear/Linear.vcxproj
  10. 26
      Primitives.sln
  11. 26
      Primitives/Common.cpp
  12. 2
      Primitives/OpenCLHandler.h
  13. 2
      Primitives/Primitives.cpp
  14. 15
      Primitives/Primitives.vcxproj
  15. 20
      Primitives/Primitives.vcxproj.filters
  16. 2
      Primitives/primitives/Compact.cpp
  17. 2
      Primitives/primitives/ExclusiveScan.cpp
  18. 2
      Primitives/primitives/Histogram.cpp
  19. 2
      Primitives/primitives/ReduceAdd.cpp
  20. 2
      Primitives/primitives/Square.cpp

208
Common/Common.cpp

@ -0,0 +1,208 @@
#include "Common.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include "cl.hpp"
#pragma warning( disable : 4996 )
void printTimeStats(cl_event event)
{
cl_int err = CL_SUCCESS;
if (event == NULL)
{
std::cerr << "No event object returned!" << std::endl;
}
else
{
clWaitForEvents(1, &event);
}
cl_ulong execStart, execEnd;
err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &execStart, NULL);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START [" << err << "]." << std::endl;
}
err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &execEnd, NULL);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END [" << err << "]." << std::endl;
}
std::cout << "[start] " << execStart << " [end] " << execEnd << " [time] " << (execEnd - execStart) / 1e+06 << "ms." << std::endl;
}
void WriteTGA_RGB(const char* filename, unsigned char* data, unsigned int width, unsigned int height)
{
FILE* f = fopen(filename, "wb");
if (!f) {
fprintf(stderr, "Unable to create output TGA image `%s'\n", filename);
exit(EXIT_FAILURE);
}
fputc(0x00, f); /* ID Length, 0 => No ID */
fputc(0x00, f); /* Color Map Type, 0 => No color map included */
fputc(0x02, f); /* Image Type, 2 => Uncompressed, True-color Image */
fputc(0x00, f); /* Next five bytes are about the color map entries */
fputc(0x00, f); /* 2 bytes Index, 2 bytes length, 1 byte size */
fputc(0x00, f);
fputc(0x00, f);
fputc(0x00, f);
fputc(0x00, f); /* X-origin of Image */
fputc(0x00, f);
fputc(0x00, f); /* Y-origin of Image */
fputc(0x00, f);
fputc(width & 0xff, f); /* Image Width */
fputc((width >> 8) & 0xff, f);
fputc(height & 0xff, f); /* Image Height */
fputc((height >> 8) & 0xff, f);
fputc(0x18, f); /* Pixel Depth, 0x18 => 24 Bits */
fputc(0x20, f); /* Image Descriptor */
for (int y = height - 1; y >= 0; y--) {
for (size_t x = 0; x < width; x++) {
const size_t i = (y * width + x) * 3;
fputc(data[i + 2], f); /* write blue */
fputc(data[i + 1], f); /* write green */
fputc(data[i], f); /* write red */
}
}
}
std::string FileToString(const std::string& path) {
std::ifstream file(path, std::ios::in | std::ios::binary);
if (file)
{
std::ostringstream contents;
contents << file.rdbuf();
file.close();
return(contents.str());
}
return std::string();
}
const char* getErrorString(cl_int error)
{
switch (error) {
// run-time and JIT compiler errors
case 0: return "CL_SUCCESS";
case -1: return "CL_DEVICE_NOT_FOUND";
case -2: return "CL_DEVICE_NOT_AVAILABLE";
case -3: return "CL_COMPILER_NOT_AVAILABLE";
case -4: return "CL_MEM_OBJECT_ALLOCATION_FAILURE";
case -5: return "CL_OUT_OF_RESOURCES";
case -6: return "CL_OUT_OF_HOST_MEMORY";
case -7: return "CL_PROFILING_INFO_NOT_AVAILABLE";
case -8: return "CL_MEM_COPY_OVERLAP";
case -9: return "CL_IMAGE_FORMAT_MISMATCH";
case -10: return "CL_IMAGE_FORMAT_NOT_SUPPORTED";
case -11: return "CL_BUILD_PROGRAM_FAILURE";
case -12: return "CL_MAP_FAILURE";
case -13: return "CL_MISALIGNED_SUB_BUFFER_OFFSET";
case -14: return "CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST";
case -15: return "CL_COMPILE_PROGRAM_FAILURE";
case -16: return "CL_LINKER_NOT_AVAILABLE";
case -17: return "CL_LINK_PROGRAM_FAILURE";
case -18: return "CL_DEVICE_PARTITION_FAILED";
case -19: return "CL_KERNEL_ARG_INFO_NOT_AVAILABLE";
// compile-time errors
case -30: return "CL_INVALID_VALUE";
case -31: return "CL_INVALID_DEVICE_TYPE";
case -32: return "CL_INVALID_PLATFORM";
case -33: return "CL_INVALID_DEVICE";
case -34: return "CL_INVALID_CONTEXT";
case -35: return "CL_INVALID_QUEUE_PROPERTIES";
case -36: return "CL_INVALID_COMMAND_QUEUE";
case -37: return "CL_INVALID_HOST_PTR";
case -38: return "CL_INVALID_MEM_OBJECT";
case -39: return "CL_INVALID_IMAGE_FORMAT_DESCRIPTOR";
case -40: return "CL_INVALID_IMAGE_SIZE";
case -41: return "CL_INVALID_SAMPLER";
case -42: return "CL_INVALID_BINARY";
case -43: return "CL_INVALID_BUILD_OPTIONS";
case -44: return "CL_INVALID_PROGRAM";
case -45: return "CL_INVALID_PROGRAM_EXECUTABLE";
case -46: return "CL_INVALID_KERNEL_NAME";
case -47: return "CL_INVALID_KERNEL_DEFINITION";
case -48: return "CL_INVALID_KERNEL";
case -49: return "CL_INVALID_ARG_INDEX";
case -50: return "CL_INVALID_ARG_VALUE";
case -51: return "CL_INVALID_ARG_SIZE";
case -52: return "CL_INVALID_KERNEL_ARGS";
case -53: return "CL_INVALID_WORK_DIMENSION";
case -54: return "CL_INVALID_WORK_GROUP_SIZE";
case -55: return "CL_INVALID_WORK_ITEM_SIZE";
case -56: return "CL_INVALID_GLOBAL_OFFSET";
case -57: return "CL_INVALID_EVENT_WAIT_LIST";
case -58: return "CL_INVALID_EVENT";
case -59: return "CL_INVALID_OPERATION";
case -60: return "CL_INVALID_GL_OBJECT";
case -61: return "CL_INVALID_BUFFER_SIZE";
case -62: return "CL_INVALID_MIP_LEVEL";
case -63: return "CL_INVALID_GLOBAL_WORK_SIZE";
case -64: return "CL_INVALID_PROPERTY";
case -65: return "CL_INVALID_IMAGE_DESCRIPTOR";
case -66: return "CL_INVALID_COMPILER_OPTIONS";
case -67: return "CL_INVALID_LINKER_OPTIONS";
case -68: return "CL_INVALID_DEVICE_PARTITION_COUNT";
// extension errors
case -1000: return "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR";
case -1001: return "CL_PLATFORM_NOT_FOUND_KHR";
case -1002: return "CL_INVALID_D3D10_DEVICE_KHR";
case -1003: return "CL_INVALID_D3D10_RESOURCE_KHR";
case -1004: return "CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR";
case -1005: return "CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR";
default: return "Unknown OpenCL error";
}
}
bool CheckCLError(cl_int err)
{
if (err != CL_SUCCESS)
{
std::cout << "OpenCL error: " << getErrorString(err) << std::endl;
return false;
}
return true;
}
void Timer::start()
{
t_start = std::chrono::high_resolution_clock::now();
}
void Timer::end(unsigned int nRuns)
{
auto t_end = std::chrono::high_resolution_clock::now();
std::cout << "CPU [time] " <<
std::chrono::duration_cast<std::chrono::nanoseconds>(t_end - t_start).count() / 1e+06
/ nRuns << " ms" << std::endl;
}
void Timer::measure(const std::function<void(void)>& program, unsigned int nRuns)
{
start();
for (unsigned int i = 0; i < nRuns; ++i)
{
program();
}
end(nRuns);
}
std::chrono::time_point<std::chrono::high_resolution_clock> Timer::t_start;

0
Primitives/Common.h → Common/Common.h

157
Common/Common.vcxproj

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{f66311cb-c60d-43de-890c-7e6d8179ca44}</ProjectGuid>
<RootNamespace>Common</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</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)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(CUDA_PATH)\include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>OpenCL.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(CUDA_PATH)\lib\Win32\</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Common.cpp" />
<ClCompile Include="OpenCLHandler.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="cl.hpp" />
<ClInclude Include="Common.h" />
<ClInclude Include="OpenCLHandler.h" />
<ClInclude Include="Tests.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

39
Common/Common.vcxproj.filters

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="OpenCLHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cl.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OpenCLHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Common.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Tests.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

85
Common/OpenCLHandler.cpp

@ -0,0 +1,85 @@
#include "Common.h"
#include "OpenCLHandler.h"
#include <iostream>
void OpenCLHandler::printTimeStats(cl::Event& event)
{
cl_int err = CL_SUCCESS;
event.wait();
cl_ulong execStart, execEnd;
execStart = event.getProfilingInfo<CL_PROFILING_COMMAND_START>(&err);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START ["
<< err << "]." << std::endl;
}
execEnd = event.getProfilingInfo<CL_PROFILING_COMMAND_END>(&err);
if (err != CL_SUCCESS)
{
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END ["
<< err << "]." << std::endl;
}
//std::cout << "[start] " << execStart << " [end] " << execEnd
// << " [time] " << (execEnd - execStart) / 1e+06 << "ms." << std::endl;
std::cout << "GPU [time] " << (execEnd - execStart) / 1e+06 << " ms" <<
std::endl;
}
OpenCLHandler::OpenCLHandler()
{
cl_int err = CL_SUCCESS;
// Get a platform ID
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.size() == 0)
{
std::cout << "Unable to find suitable platform." << std::endl;
exit(-1);
}
std::cout << "Running on: " << platforms[0].getInfo<CL_PLATFORM_NAME>() << std::endl;
// Create a context
cl_context_properties properties[] =
{ CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0 };
context = cl::Context(CL_DEVICE_TYPE_GPU, properties);
// Enumerate the devices
std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
std::cout << "Global memory: " << devices[0].getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>() << std::endl;
max_workgroup_size = devices[0].getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>();
std::cout << "Max workgroup: " << max_workgroup_size << std::endl << std::endl;
// Create the command queue
cl::Event event;
queue = cl::CommandQueue(context, devices[0], CL_QUEUE_PROFILING_ENABLE, &err);
// Create the OpenCL program
std::string programSource = FileToString("../kernels/programs.cl");
program = cl::Program(context, programSource);
program.build(devices);
}
bool OpenCLHandler::run_test(TestCase* test)
{
cl::Event gpuEvent;
test->gpu_compute(&context, &queue, &program, &gpuEvent);
Timer::measure([&]() {
test->cpu_compute();
}, 5);
printTimeStats(gpuEvent);
test->collect_results(&queue);
return test->validate_results();
}
size_t OpenCLHandler::get_max_size()
{
return max_workgroup_size;
}

16
Common/OpenCLHandler.h

@ -0,0 +1,16 @@
#pragma once
#include "Tests.h"
class OpenCLHandler {
private:
cl::Program program;
cl::Context context;
cl::CommandQueue queue;
size_t max_workgroup_size;
void printTimeStats(cl::Event& event);
public:
OpenCLHandler();
bool run_test(TestCase* test);
size_t get_max_size();
};

2
Primitives/primitives/Tests.h → Common/Tests.h

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
#include "../cl.hpp" #include "cl.hpp"
class TestCase { class TestCase {
protected: protected:

12937
Common/cl.hpp

File diff suppressed because it is too large

5
Linear/Linear.vcxproj

@ -79,6 +79,11 @@
<ItemGroup> <ItemGroup>
<None Include="..\kernels\linear.cl" /> <None Include="..\kernels\linear.cl" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.vcxproj">
<Project>{f66311cb-c60d-43de-890c-7e6d8179ca44}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

26
Primitives.sln

@ -4,23 +4,49 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.1.32210.238 VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Primitives", "Primitives\Primitives.vcxproj", "{54072875-46AD-4C09-AE1A-2E7E70B30414}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Primitives", "Primitives\Primitives.vcxproj", "{54072875-46AD-4C09-AE1A-2E7E70B30414}"
ProjectSection(ProjectDependencies) = postProject
{F66311CB-C60D-43DE-890C-7E6D8179CA44} = {F66311CB-C60D-43DE-890C-7E6D8179CA44}
EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Linear", "Linear\Linear.vcxproj", "{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Linear", "Linear\Linear.vcxproj", "{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}"
ProjectSection(ProjectDependencies) = postProject
{F66311CB-C60D-43DE-890C-7E6D8179CA44} = {F66311CB-C60D-43DE-890C-7E6D8179CA44}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "Common\Common.vcxproj", "{F66311CB-C60D-43DE-890C-7E6D8179CA44}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32 Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32 Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|Win32.ActiveCfg = Debug|Win32 {54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|Win32.ActiveCfg = Debug|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|Win32.Build.0 = Debug|Win32 {54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|Win32.Build.0 = Debug|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|x64.ActiveCfg = Debug|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Debug|x64.Build.0 = Debug|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|Win32.ActiveCfg = Release|Win32 {54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|Win32.ActiveCfg = Release|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|Win32.Build.0 = Release|Win32 {54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|Win32.Build.0 = Release|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|x64.ActiveCfg = Release|Win32
{54072875-46AD-4C09-AE1A-2E7E70B30414}.Release|x64.Build.0 = Release|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|Win32.ActiveCfg = Debug|Win32 {FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|Win32.ActiveCfg = Debug|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|Win32.Build.0 = Debug|Win32 {FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|Win32.Build.0 = Debug|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|x64.ActiveCfg = Debug|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Debug|x64.Build.0 = Debug|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|Win32.ActiveCfg = Release|Win32 {FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|Win32.ActiveCfg = Release|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|Win32.Build.0 = Release|Win32 {FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|Win32.Build.0 = Release|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|x64.ActiveCfg = Release|Win32
{FD14D4C8-8321-4451-A5DA-68E3FCCFCAC8}.Release|x64.Build.0 = Release|Win32
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Debug|Win32.ActiveCfg = Debug|Win32
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Debug|Win32.Build.0 = Debug|Win32
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Debug|x64.ActiveCfg = Debug|x64
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Debug|x64.Build.0 = Debug|x64
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Release|Win32.ActiveCfg = Release|Win32
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Release|Win32.Build.0 = Release|Win32
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Release|x64.ActiveCfg = Release|x64
{F66311CB-C60D-43DE-890C-7E6D8179CA44}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

26
Primitives/Common.cpp

@ -12,56 +12,34 @@
#pragma warning( disable : 4996 ) #pragma warning( disable : 4996 )
void printTimeStats(cl_event event) void printTimeStats(cl_event event)
{ {
cl_int err = CL_SUCCESS; cl_int err = CL_SUCCESS;
if(event == NULL) if(event == NULL)
{ {
std::cerr << "No event object returned!" << std::endl; std::cerr << "No event object returned!" << std::endl;
} }
else else
{ {
clWaitForEvents(1, &event); clWaitForEvents(1, &event);
} }
cl_ulong execStart, execEnd; cl_ulong execStart, execEnd;
err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &execStart, NULL);
err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START,
sizeof(cl_ulong), &execStart, NULL);
if(err != CL_SUCCESS) if(err != CL_SUCCESS)
{ {
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START [" << err << "]." << std::endl; std::cerr << "Error during profile query: CL_PROFILING_COMMAND_START [" << err << "]." << std::endl;
} }
err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, err = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &execEnd, NULL);
sizeof(cl_ulong), &execEnd, NULL);
if(err != CL_SUCCESS) if(err != CL_SUCCESS)
{ {
std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END [" << err << "]." << std::endl; std::cerr << "Error during profile query: CL_PROFILING_COMMAND_END [" << err << "]." << std::endl;
} }
std::cout << "[start] " << execStart << " [end] " << execEnd << " [time] " << (execEnd - execStart) / 1e+06 << "ms." << std::endl; std::cout << "[start] " << execStart << " [end] " << execEnd << " [time] " << (execEnd - execStart) / 1e+06 << "ms." << std::endl;
} }

2
Primitives/OpenCLHandler.h

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "primitives/Tests.h" #include "Tests.h"
class OpenCLHandler { class OpenCLHandler {

2
Primitives/Primitives.cpp

@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
#include "Common.h" #include "Common.h"
#include "OpenCLHandler.h" #include "OpenCLHandler.h"
#include "primitives/Tests.h" #include "Tests.h"
// OpenCL C API // OpenCL C API
#include <CL/opencl.h> #include <CL/opencl.h>

15
Primitives/Primitives.vcxproj

@ -45,7 +45,7 @@
<ClCompile> <ClCompile>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(CUDA_PATH)\include</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>..\Common;$(CUDA_PATH)\include</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<Link> <Link>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
@ -71,14 +71,6 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="cl.hpp" />
<ClCompile Include="Common.cpp" />
<ClInclude Include="Common.h" />
<ClInclude Include="OpenCLHandler.h" />
<ClInclude Include="primitives\Tests.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="OpenCLHandler.cpp" />
<ClCompile Include="Primitives.cpp" /> <ClCompile Include="Primitives.cpp" />
<ClCompile Include="primitives\Compact.cpp" /> <ClCompile Include="primitives\Compact.cpp" />
<ClCompile Include="primitives\ExclusiveScan.cpp" /> <ClCompile Include="primitives\ExclusiveScan.cpp" />
@ -89,6 +81,11 @@
<ItemGroup> <ItemGroup>
<None Include="..\kernels\programs.cl" /> <None Include="..\kernels\programs.cl" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.vcxproj">
<Project>{f66311cb-c60d-43de-890c-7e6d8179ca44}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

20
Primitives/Primitives.vcxproj.filters

@ -17,20 +17,6 @@
<UniqueIdentifier>{fd13ccc5-a98b-4e30-9eba-12f62c7dd566}</UniqueIdentifier> <UniqueIdentifier>{fd13ccc5-a98b-4e30-9eba-12f62c7dd566}</UniqueIdentifier>
</Filter> </Filter>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ClInclude Include="cl.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="primitives\Tests.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="OpenCLHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Common.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Primitives.cpp"> <ClCompile Include="Primitives.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
@ -38,12 +24,6 @@
<ClCompile Include="primitives\Square.cpp"> <ClCompile Include="primitives\Square.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="OpenCLHandler.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Common.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="primitives\Histogram.cpp"> <ClCompile Include="primitives\Histogram.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>

2
Primitives/primitives/Compact.cpp

@ -1,5 +1,5 @@
#include <iostream> #include <iostream>
#include "../Common.h" #include "Common.h"
#include "Tests.h" #include "Tests.h"
#include <random> #include <random>

2
Primitives/primitives/ExclusiveScan.cpp

@ -1,5 +1,5 @@
#include <iostream> #include <iostream>
#include "../Common.h" #include "Common.h"
#include "Tests.h" #include "Tests.h"
#include <random> #include <random>

2
Primitives/primitives/Histogram.cpp

@ -1,5 +1,5 @@
#include <iostream> #include <iostream>
#include "../Common.h" #include "Common.h"
#include "Tests.h" #include "Tests.h"
#include <random> #include <random>

2
Primitives/primitives/ReduceAdd.cpp

@ -1,6 +1,6 @@
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include "../Common.h" #include "Common.h"
#include "Tests.h" #include "Tests.h"
#include <random> #include <random>
#include <stdlib.h> #include <stdlib.h>

2
Primitives/primitives/Square.cpp

@ -1,5 +1,5 @@
#include <iostream> #include <iostream>
#include "../Common.h" #include "Common.h"
#include "Tests.h" #include "Tests.h"
#include <random> #include <random>

Loading…
Cancel
Save