├── GpuRamDrive ├── GpuRamDrive.rc ├── icon1.ico ├── icon2.ico ├── GpuRamDrive ├── resource.h ├── 3rdparty │ ├── lib │ │ ├── Win32 │ │ │ ├── OpenCL.lib │ │ │ └── imdisk.lib │ │ └── x64 │ │ │ ├── OpenCL.lib │ │ │ └── imdisk.lib │ └── inc │ │ ├── imdisk │ │ ├── imdiskver.h │ │ ├── devio.h │ │ ├── devio_types.h │ │ ├── imdproxy.h │ │ ├── wkmem.hpp │ │ ├── wio.hpp │ │ ├── wmem.hpp │ │ └── ntkmapi.h │ │ └── CL │ │ ├── opencl.h │ │ ├── cl_gl_ext.h │ │ ├── cl_d3d10_ext.h │ │ ├── cl_d3d11_ext.h │ │ ├── cl_d3d11.h │ │ ├── cl_d3d10.h │ │ ├── cl_dx9_media_sharing.h │ │ ├── cl_egl.h │ │ ├── cl_d3d9_ext.h │ │ ├── cl_gl.h │ │ └── cl_ext.h ├── stdafx.cpp ├── targetver.h ├── DebugTools.h ├── GpuRamTrayIcon.h ├── GpuRamDrive.log ├── TaskManager.h ├── CudaHandler.h ├── DataGridConfig.h ├── stdafx.h ├── DiskUtil.h ├── GpuRamTrayIcon.cpp ├── CudaHandler.cpp ├── ReadMe.txt ├── GpuRamGui.h ├── Config.h ├── GpuRamDrive.h ├── EntryPoint.cpp ├── DebugTools.cpp ├── DataGridConfig.cpp ├── GpuRamDrive.vcxproj.filters ├── TaskManager.cpp ├── Regkey.h ├── DataGrid.h ├── Config.cpp ├── DiskUtil.cpp └── GpuRamDrive.cpp ├── .gitignore ├── LICENSE ├── README.md └── GpuRamDrive.sln /GpuRamDrive/GpuRamDrive.rc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /GpuRamDrive/icon1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/icon1.ico -------------------------------------------------------------------------------- /GpuRamDrive/icon2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/icon2.ico -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamDrive: -------------------------------------------------------------------------------- 1 | <1264> Started<1264> Closed<1530> Started -------------------------------------------------------------------------------- /GpuRamDrive/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/resource.h -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/lib/Win32/OpenCL.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/3rdparty/lib/Win32/OpenCL.lib -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/lib/Win32/imdisk.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/3rdparty/lib/Win32/imdisk.lib -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/lib/x64/OpenCL.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/3rdparty/lib/x64/OpenCL.lib -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/lib/x64/imdisk.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsyahmi/GpuRamDrive/HEAD/GpuRamDrive/3rdparty/lib/x64/imdisk.lib -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | Debug 3 | Release 4 | Release-CUDA 5 | Release-* 6 | Debug-* 7 | ipch 8 | *.suo 9 | *.opensdf 10 | *.sdf 11 | *.user 12 | *.aps 13 | *.vc.* 14 | /.vs 15 | *.psess 16 | *.vspx 17 | *.vsp 18 | *.VC.db 19 | *.opendb 20 | *.pdb -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/imdiskver.h: -------------------------------------------------------------------------------- 1 | #define IMDISK_RC_VERSION_STR "2.0.9" 2 | #define IMDISK_MAJOR_VERSION 2 3 | #define IMDISK_MINOR_VERSION 0 4 | #define IMDISK_MINOR_LOW_VERSION 9 5 | 6 | #define IMDISK_RC_VERSION_FLD IMDISK_MAJOR_VERSION,IMDISK_MINOR_VERSION,IMDISK_MINOR_LOW_VERSION 7 | -------------------------------------------------------------------------------- /GpuRamDrive/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // GpuRamDrive.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /GpuRamDrive/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /GpuRamDrive/DebugTools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class DebugTools 4 | { 5 | private: 6 | LPTSTR pszFileName; 7 | 8 | public: 9 | DebugTools(LPCTSTR pszFileName); 10 | ~DebugTools(); 11 | void deb(wchar_t* msg, ...); 12 | wchar_t* fmterr(DWORD err = GetLastError()); 13 | void writeToFile(LPCTSTR filename, wchar_t* data); 14 | std::string getCurrentTimestamp(); 15 | }; -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamTrayIcon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class GpuRamTrayIcon 4 | { 5 | private: 6 | NOTIFYICONDATA m_Data; 7 | HICON m_hIcon; 8 | HICON m_hIconMounted; 9 | std::wstring m_Tooltip; 10 | 11 | public: 12 | GpuRamTrayIcon(); 13 | ~GpuRamTrayIcon(); 14 | 15 | bool CreateIcon(HWND hWnd, HICON hIcon, HICON hIconMounted, UINT callbackMsg); 16 | bool Destroy(); 17 | 18 | bool SetTooltip(const std::wstring& tooltip, boolean isMounted); 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamDrive.log: -------------------------------------------------------------------------------- 1 | 2020-12-08 21:13:30:108 - <73C> Started GpuRamDrive 2 | 2020-12-08 21:13:32:125 - <73C> OnEndSession start: 0 3 | 2020-12-08 21:13:32:125 - <73C> OnEndSession device 0 4 | 2020-12-08 21:13:32:125 - <73C> OnEndSession end 5 | 2020-12-08 21:13:32:125 - <73C> Closed GpuRamDrive 6 | -------------------------------------------------------------------------------- /GpuRamDrive/TaskManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if !defined(_WINDOWS_) 4 | #include 5 | #endif 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #pragma comment(lib, "taskschd.lib") 12 | #pragma comment(lib, "comsupp.lib") 13 | 14 | 15 | class TaskManager 16 | { 17 | private: 18 | 19 | public: 20 | TaskManager(); 21 | ~TaskManager(); 22 | 23 | bool ExistTaskJob(LPCTSTR pszTaskName); 24 | 25 | bool CreateTaskJob(LPCWSTR wszTaskName, wchar_t* nPath, wchar_t* nArguments); 26 | 27 | bool DeleteTaskJob(LPCWSTR wszTaskName); 28 | }; 29 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/devio.h: -------------------------------------------------------------------------------- 1 | typedef safeio_ssize_t (__cdecl *dllread_proc)(void *handle, 2 | void *buf, 3 | safeio_size_t size, 4 | off_t_64 offset); 5 | 6 | typedef safeio_ssize_t (__cdecl *dllwrite_proc)(void *handle, 7 | void *buf, 8 | safeio_size_t size, 9 | off_t_64 offset); 10 | 11 | typedef int (__cdecl *dllclose_proc)(void *handle); 12 | 13 | typedef void * (__cdecl *dllopen_proc)(const char *file, 14 | int read_only, 15 | dllread_proc *dllread, 16 | dllwrite_proc *dllwrite, 17 | dllclose_proc *dllclose, 18 | off_t_64 *size); 19 | 20 | -------------------------------------------------------------------------------- /GpuRamDrive/CudaHandler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define GPU_API_CUDA 1 3 | 4 | #if GPU_API == GPU_API_CUDA 5 | #include 6 | #include 7 | #include 8 | #include "DebugTools.h" 9 | 10 | class CudaHandler 11 | { 12 | private: 13 | static CudaHandler* pinstance_; 14 | static std::mutex mutex_; 15 | std::map contexts; 16 | std::map contextsMux; 17 | DebugTools debugTools; 18 | 19 | protected: 20 | CudaHandler(); 21 | ~CudaHandler(); 22 | 23 | public: 24 | CudaHandler(CudaHandler& other) = delete; 25 | void operator=(const CudaHandler&) = delete; 26 | static CudaHandler* GetInstance(); 27 | CUcontext getContext(cl_device_id clDeviceId); 28 | void removeContext(cl_device_id clDeviceId); 29 | }; 30 | #endif 31 | -------------------------------------------------------------------------------- /GpuRamDrive/DataGridConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if !defined(_WINDOWS_) 3 | #include 4 | #endif 5 | #include 6 | #include "GPURamDrive.h" 7 | #include "DataGrid.h" 8 | #include "Config.h" 9 | 10 | class DataGridConfig 11 | { 12 | private: 13 | CDataGrid m_hdataGrid; 14 | 15 | private: 16 | void add(Config config, DWORD deviceId, bool isMounted); 17 | 18 | public: 19 | DataGridConfig(); 20 | ~DataGridConfig(); 21 | 22 | void create(HWND hwnd, RECT rect); 23 | HWND getDataGridHandler(); 24 | void sendWinProcEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 25 | void reload(Config config, std::map &m_RamDrive); 26 | DWORD getSelectedDeviceId(); 27 | void setRowMount(DWORD deviceId, BOOL value); 28 | void resetSelection(); 29 | }; -------------------------------------------------------------------------------- /GpuRamDrive/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #define _CRT_SECURE_NO_WARNINGS 9 | 10 | #include "targetver.h" 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #pragma comment(lib, "imdisk.lib") 30 | #pragma comment(lib, "comctl32.lib") 31 | -------------------------------------------------------------------------------- /GpuRamDrive/DiskUtil.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #if !defined(_WINDOWS_) 3 | #include 4 | #endif 5 | 6 | #include "Regkey.h" 7 | 8 | class DiskUtil 9 | { 10 | private: 11 | LPVOID buffer; 12 | HANDLE hinput, houtput; 13 | xfc::RegKey obKey; 14 | 15 | public: 16 | DiskUtil(); 17 | ~DiskUtil(); 18 | 19 | BOOL checkDriveIsMounted(char letter, wchar_t* type); 20 | BOOL fileExists(LPCTSTR szPath); 21 | std::wstring chooserFile(const wchar_t* title, const wchar_t* filter); 22 | DWORD save(const wchar_t* source_device_name, const wchar_t* filename); 23 | DWORD restore(const wchar_t* filename, const wchar_t* target_device_name); 24 | void createDriveIcon(char letter); 25 | void removeDriveIcon(char letter); 26 | 27 | private: 28 | void throwError(const char* text); 29 | void freeResources(); 30 | 31 | }; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Syahmi Azhar. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GpuRamDrive 2 | Create a virtual drive backed by GPU RAM. 3 | 4 | ![Screenshot](https://repository-images.githubusercontent.com/302840646/59966600-3285-11eb-94aa-9c2c917da458) 5 | 6 | This application simply allocates a memory buffer inside GPU RAM and use it as virtual ram disk. The project is made possible by ImDisk and its proxy feature. 7 | 8 | Using GPU RAM isn't as fast as host main memory, however it is still faster than a regular HDD. The result below is taken on my system with GTX 850M and i7-4710MQ. As IO operation is happening between the CPU and GPU, the GPU can become active from idle state and might causes system to draw more power. This merely just a PoC, user who search for this kind of solution is advised to upgrade the RAM or buy a faster storage. 9 | 10 | ![Benchmark](https://cloud.githubusercontent.com/assets/1040494/20632692/65470470-b37a-11e6-908d-e08687a757d3.png) 11 | 12 | People who interested in this might also want to check BadMemory: https://github.com/prsyahmi/BadMemory 13 | 14 | ## Usage 15 | 1. Install ImDisk Virtual drive (https://www.ltr-data.se/opencode.html) 16 | 2. Download GpuRamDrive from https://github.com/prsyahmi/GpuRamDrive/releases 17 | 3. Run GpuRamDrive_x64.exe or GpuRamDrive-cuda_x64.exe according to your platform 18 | 19 | ## Compiling 20 | To compile, open the solution, configure the target platform and build the project. 21 | 22 | ## License 23 | This project is licensed under MIT. See LICENSE. 24 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/devio_types.h: -------------------------------------------------------------------------------- 1 | 2 | #if defined(_MSC_VER) && _MSC_VER < 1900 3 | 4 | #define PRIu64 "I64u" 5 | #define PRIi64 "I64i" 6 | 7 | typedef unsigned __int8 uint8_t; 8 | typedef unsigned __int16 uint16_t; 9 | typedef unsigned __int32 uint32_t; 10 | typedef unsigned __int64 uint64_t; 11 | 12 | typedef __int8 int8_t; 13 | typedef __int16 int16_t; 14 | typedef __int32 int32_t; 15 | typedef __int64 int64_t; 16 | 17 | #else 18 | 19 | #include 20 | 21 | #endif 22 | 23 | #define ULL_FMT "%" PRIu64 24 | #define SLL_FMT "%" PRIi64 25 | 26 | #ifdef _WIN32 27 | 28 | typedef ULONG safeio_size_t; 29 | typedef LONG safeio_ssize_t; 30 | typedef LONGLONG off_t_64; 31 | typedef int socklen_t; 32 | 33 | #define SIZ_FMT "%u" 34 | #define SSZ_FMT "%i" 35 | 36 | #else 37 | 38 | typedef size_t safeio_size_t; 39 | typedef ssize_t safeio_ssize_t; 40 | typedef off_t off_t_64; 41 | typedef int SOCKET; 42 | 43 | #define SIZ_FMT "%zu" 44 | #define SSZ_FMT "%zi" 45 | 46 | #define INVALID_SOCKET (-1) 47 | 48 | #define _lseeki64 lseek 49 | #define closesocket close 50 | #define _flushall flushall 51 | #define _open open 52 | #define _close close 53 | #define _stricmp strcasecmp 54 | #define _strnicmp strncasecmp 55 | 56 | #ifndef O_BINARY 57 | #define O_BINARY 0 58 | #endif 59 | 60 | #ifndef __cdecl 61 | #define __cdecl 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamTrayIcon.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "GpuRamTrayIcon.h" 3 | 4 | // Using GUID will causes an issue, see all the details here: https://github.com/electron/electron/pull/2882 5 | static const GUID TRAY_GUID = { 0xf5b95301, 0xd87e, 0x45fd, {0x96, 0xfb, 0xad, 0x4f, 0xfd, 0x08, 0x1d, 0xeb} }; 6 | 7 | GpuRamTrayIcon::GpuRamTrayIcon() 8 | { 9 | memset(&m_Data, 0, sizeof(m_Data)); 10 | m_Data.cbSize = sizeof(m_Data); 11 | m_Data.guidItem = TRAY_GUID; 12 | } 13 | 14 | 15 | GpuRamTrayIcon::~GpuRamTrayIcon() 16 | { 17 | Destroy(); 18 | } 19 | 20 | bool GpuRamTrayIcon::CreateIcon(HWND hWnd, HICON hIcon, HICON hIconMounted, UINT callbackMsg) 21 | { 22 | m_hIcon = hIcon; 23 | m_hIconMounted = hIconMounted; 24 | 25 | m_Data.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP/* | NIF_GUID*/; 26 | m_Data.hWnd = hWnd; 27 | wcsncpy_s(m_Data.szTip, ARRAYSIZE(m_Data.szTip), m_Tooltip.c_str(), min(ARRAYSIZE(m_Data.szTip), m_Tooltip.length())); 28 | m_Data.hIcon = m_hIcon; 29 | m_Data.uID = 1; 30 | m_Data.uCallbackMessage = callbackMsg; 31 | 32 | return Shell_NotifyIcon(NIM_ADD, &m_Data) > 0; 33 | } 34 | 35 | bool GpuRamTrayIcon::Destroy() 36 | { 37 | return Shell_NotifyIcon(NIM_DELETE, &m_Data) > 0; 38 | } 39 | 40 | bool GpuRamTrayIcon::SetTooltip(const std::wstring& tooltip, boolean isMounted) 41 | { 42 | if (isMounted) 43 | m_Data.hIcon = m_hIconMounted; 44 | else 45 | m_Data.hIcon = m_hIcon; 46 | m_Tooltip = tooltip; 47 | wcsncpy_s(m_Data.szTip, ARRAYSIZE(m_Data.szTip), m_Tooltip.c_str(), min(ARRAYSIZE(m_Data.szTip), m_Tooltip.length())); 48 | return Shell_NotifyIcon(NIM_MODIFY, &m_Data) > 0; 49 | } 50 | -------------------------------------------------------------------------------- /GpuRamDrive/CudaHandler.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CudaHandler.h" 3 | 4 | #if GPU_API == GPU_API_CUDA 5 | #pragma comment(lib, "cuda.lib") 6 | 7 | CudaHandler* CudaHandler::pinstance_{ nullptr }; 8 | std::mutex CudaHandler::mutex_; 9 | 10 | CudaHandler::CudaHandler() 11 | : contexts() 12 | , contextsMux() 13 | , debugTools(L"GpuRamDrive") 14 | { 15 | debugTools.deb(L"Cuda initialize"); 16 | cuInit(0); 17 | } 18 | 19 | CudaHandler::~CudaHandler() 20 | { 21 | for (auto const& x : contexts) 22 | { 23 | debugTools.deb(L"Cuda context %u destroy", x.first); 24 | if (x.second) cuCtxDestroy(x.second); 25 | } 26 | } 27 | 28 | CudaHandler* CudaHandler::GetInstance() 29 | { 30 | std::lock_guard lock(mutex_); 31 | if (pinstance_ == nullptr) 32 | { 33 | pinstance_ = new CudaHandler(); 34 | } 35 | return pinstance_; 36 | } 37 | 38 | 39 | CUcontext CudaHandler::getContext(cl_device_id clDeviceId) 40 | { 41 | CUdevice m_cuDev = (CUdevice)(UINT_PTR)(clDeviceId); 42 | if (contexts.find(m_cuDev) == contexts.end()) 43 | { 44 | debugTools.deb(L"Generating new context for cuda device: '%d'", m_cuDev); 45 | CUcontext m_cuCtx; 46 | cuDevicePrimaryCtxRetain(&m_cuCtx, m_cuDev); 47 | contexts[m_cuDev] = m_cuCtx; 48 | contextsMux[m_cuDev] = 1; 49 | } 50 | else 51 | { 52 | contextsMux[m_cuDev]++; 53 | } 54 | return contexts[m_cuDev]; 55 | } 56 | 57 | void CudaHandler::removeContext(cl_device_id clDeviceId) 58 | { 59 | CUdevice m_cuDev = (CUdevice)(UINT_PTR)(clDeviceId); 60 | contextsMux[m_cuDev]--; 61 | if (contextsMux[m_cuDev] == 0) 62 | { 63 | debugTools.deb(L"Destroying the context for cuda device: '%d'", m_cuDev); 64 | //cuCtxDestroy(contexts[m_cuDev]); 65 | cuDevicePrimaryCtxRelease(m_cuDev); 66 | contexts[m_cuDev] = nullptr; 67 | contexts.erase(m_cuDev); 68 | } 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /GpuRamDrive/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : GpuRamDrive Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this GpuRamDrive application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your GpuRamDrive application. 9 | 10 | 11 | GpuRamDrive.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | GpuRamDrive.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | GpuRamDrive.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named GpuRamDrive.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | 37 | AppWizard uses "TODO:" comments to indicate parts of the source code you 38 | should add to or customize. 39 | 40 | ///////////////////////////////////////////////////////////////////////////// 41 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/opencl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_H 27 | #define __OPENCL_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #ifdef __APPLE__ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #else 41 | 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #endif 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* __OPENCL_H */ 54 | 55 | -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamGui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "GpuRamDrive.h" 4 | #include "GpuRamTrayIcon.h" 5 | #include "DiskUtil.h" 6 | #include "Config.h" 7 | #include "DataGridConfig.h" 8 | #include "DebugTools.h" 9 | 10 | class GpuRamGui 11 | { 12 | private: 13 | std::map m_RamDrive; 14 | HWND m_hWnd; 15 | HINSTANCE m_Instance; 16 | GpuRamTrayIcon m_Tray; 17 | bool m_AutoMount; 18 | 19 | HICON m_Icon; 20 | HICON m_IconMounted; 21 | HWND m_CtlGpuList; 22 | HWND m_CtlMountBtn; 23 | HWND m_CtlMemSize; 24 | HWND m_CtlDriveLetter; 25 | HWND m_CtlDriveType; 26 | HWND m_CtlDriveRemovable; 27 | HWND m_CtlDriveLabel; 28 | HWND m_CtlDriveFormat; 29 | HWND m_CtlImageFile; 30 | HWND m_CtlChooseFileBtn; 31 | HWND m_CtlReadOnly; 32 | HWND m_CtlTempFolder; 33 | HWND m_CtlStartOnWindows; 34 | HWND m_CtlAddDeviceBtn; 35 | HWND m_CtlModifyDeviceBtn; 36 | HWND m_CtlRemoveDeviceBtn; 37 | bool m_UpdateState; 38 | 39 | LPCWSTR wszAppName; 40 | LPCWSTR wszTaskJobName; 41 | 42 | DiskUtil diskUtil; 43 | Config config; 44 | DataGridConfig dataGridConfig; 45 | DebugTools debugTools; 46 | 47 | public: 48 | GpuRamGui(); 49 | ~GpuRamGui(); 50 | 51 | bool Create(HINSTANCE hInst, const std::wstring& title, int nCmdShow, bool autoMount); 52 | bool CreateTryIcon(); 53 | int Loop(); 54 | void AutoMount(); 55 | void RestoreWindow(); 56 | 57 | private: 58 | void OnCreate(); 59 | void OnDestroy(); 60 | void OnEndSession(bool isShutdown); 61 | void OnResize(WORD width, WORD height, bool minimized); 62 | void ReloadDriveLetterList(); 63 | boolean IsAnyMounted(); 64 | void RestoreGuiParams(DWORD deviceId, DWORD suggestedRamSize); 65 | void SaveGuiParams(); 66 | void RemoveDevice(DWORD deviceId); 67 | void SetStartOnWindows(); 68 | void OnMountClicked(DWORD deviceId, bool isShutdown); 69 | void OnTrayInteraction(LPARAM lParam); 70 | void UpdateState(); 71 | 72 | ATOM MyRegisterClass(); 73 | static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); 74 | }; 75 | 76 | -------------------------------------------------------------------------------- /GpuRamDrive/Config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Regkey.h" 3 | 4 | class Config 5 | { 6 | private: 7 | xfc::RegKey obKey; 8 | LPTSTR pszKeyName; 9 | DWORD currentDeviceId; 10 | DWORD version; 11 | std::vector vectorDevices; 12 | 13 | private: 14 | void checkVersion(); 15 | void migrateVersion100(); 16 | 17 | bool getValue(LPCTSTR pszValueName, LPTSTR pszValue); 18 | bool getValue(DWORD gpu, LPCTSTR pszValueName, LPTSTR pszValue); 19 | 20 | bool getValue(LPCTSTR pszValueName, DWORD& dwValue); 21 | bool getValue(DWORD gpu, LPCTSTR pszValueName, DWORD& dwValue); 22 | 23 | bool setValue(LPCTSTR pszValueName, DWORD pszValue); 24 | bool setValue(DWORD gpu, LPCTSTR pszValueName, DWORD pszValue); 25 | 26 | bool setValue(LPCTSTR pszValueName, LPCTSTR pszValue); 27 | bool setValue(DWORD gpu, LPCTSTR pszValueName, LPCTSTR pszValue); 28 | 29 | bool existValue(LPCTSTR pszValueName); 30 | bool existValue(DWORD gpu, LPCTSTR pszValueName); 31 | 32 | bool deleteValue(LPCTSTR pszValueName); 33 | 34 | public: 35 | Config(LPCTSTR pszKeyName); 36 | ~Config(); 37 | 38 | const std::vector& getDeviceList(); 39 | BOOL existDevice(DWORD deviceId); 40 | DWORD getDeviceTempFolfer(); 41 | 42 | void saveOriginalTempEnvironment(); 43 | void setMountTempEnvironment(LPCTSTR pszValue); 44 | void restoreOriginalTempEnvironment(); 45 | 46 | DWORD getCurrentDeviceId(); 47 | void setCurrentDeviceId(DWORD deviceId); 48 | 49 | DWORD getGpuId(); 50 | DWORD getGpuId(DWORD deviceId); 51 | void setGpuId(DWORD pszValue); 52 | 53 | DWORD getDriveLetter(); 54 | DWORD getDriveLetter(DWORD deviceId); 55 | void setDriveLetter(DWORD pszValue); 56 | 57 | DWORD getDriveType(); 58 | void setDriveType(DWORD pszValue); 59 | 60 | DWORD getDriveRemovable(); 61 | void setDriveRemovable(DWORD pszValue); 62 | 63 | DWORD getDriveFormat(); 64 | void setDriveFormat(DWORD pszValue); 65 | 66 | DWORD getMemSize(); 67 | void setMemSize(DWORD pszValue); 68 | 69 | void getDriveLabel(LPTSTR pszValue); 70 | void setDriveLabel(LPCTSTR pszValue); 71 | 72 | void getImageFile(LPTSTR pszValue); 73 | void setImageFile(LPCTSTR pszValue); 74 | 75 | DWORD getReadOnly(); 76 | DWORD getReadOnly(DWORD deviceId); 77 | void setReadOnly(DWORD pszValue); 78 | 79 | DWORD getTempFolder(); 80 | DWORD getTempFolder(DWORD deviceId); 81 | void setTempFolder(DWORD pszValue); 82 | 83 | DWORD getStartOnWindows(); 84 | DWORD getStartOnWindows(DWORD deviceId); 85 | void setStartOnWindows(DWORD pszValue); 86 | 87 | bool deleteDevice(DWORD deviceId); 88 | }; -------------------------------------------------------------------------------- /GpuRamDrive.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GpuRamDrive", "GpuRamDrive\GpuRamDrive.vcxproj", "{2FBA5171-ABA1-47B1-92F8-F8E7362806D9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Debug-CUDA|x64 = Debug-CUDA|x64 13 | Debug-CUDA|x86 = Debug-CUDA|x86 14 | Debug-OpenCL|x64 = Debug-OpenCL|x64 15 | Debug-OpenCL|x86 = Debug-OpenCL|x86 16 | Release-CUDA|x64 = Release-CUDA|x64 17 | Release-CUDA|x86 = Release-CUDA|x86 18 | Release-OpenCL|x64 = Release-OpenCL|x64 19 | Release-OpenCL|x86 = Release-OpenCL|x86 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug|x64.ActiveCfg = Debug|x64 23 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug|x64.Build.0 = Debug|x64 24 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug|x86.ActiveCfg = Debug|Win32 25 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug|x86.Build.0 = Debug|Win32 26 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-CUDA|x64.ActiveCfg = Debug-CUDA|x64 27 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-CUDA|x64.Build.0 = Debug-CUDA|x64 28 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-CUDA|x86.ActiveCfg = Debug-CUDA|Win32 29 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-CUDA|x86.Build.0 = Debug-CUDA|Win32 30 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-OpenCL|x64.ActiveCfg = Debug-OpenCL|x64 31 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-OpenCL|x64.Build.0 = Debug-OpenCL|x64 32 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-OpenCL|x86.ActiveCfg = Debug-OpenCL|Win32 33 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Debug-OpenCL|x86.Build.0 = Debug-OpenCL|Win32 34 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-CUDA|x64.ActiveCfg = Release-CUDA|x64 35 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-CUDA|x64.Build.0 = Release-CUDA|x64 36 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-CUDA|x86.ActiveCfg = Release-CUDA|Win32 37 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-CUDA|x86.Build.0 = Release-CUDA|Win32 38 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-OpenCL|x64.ActiveCfg = Release|x64 39 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-OpenCL|x64.Build.0 = Release|x64 40 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-OpenCL|x86.ActiveCfg = Release|Win32 41 | {2FBA5171-ABA1-47B1-92F8-F8E7362806D9}.Release-OpenCL|x86.Build.0 = Release|Win32 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamDrive.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define GPU_API_HOSTMEM 0 4 | #define GPU_API_CUDA 1 5 | #define GPU_API_OPENCL 2 6 | 7 | #ifndef GPU_API 8 | #define GPU_API GPU_API_OPENCL 9 | #endif 10 | 11 | #if GPU_API == GPU_API_CUDA 12 | #include 13 | #endif 14 | 15 | #include "Config.h" 16 | #include "DiskUtil.h" 17 | #include "DebugTools.h" 18 | 19 | struct TGPUDevice 20 | { 21 | cl_platform_id platform_id{}; 22 | cl_device_id device_id{}; 23 | cl_ulong memsize = 0; 24 | std::string name; 25 | }; 26 | 27 | enum class EGpuRamDriveType 28 | { 29 | HD = IMDISK_DEVICE_TYPE_HD, 30 | FD = IMDISK_DEVICE_TYPE_FD, 31 | CD = IMDISK_DEVICE_TYPE_CD, 32 | RAW = IMDISK_DEVICE_TYPE_RAW, 33 | }; 34 | 35 | class GPURamDrive 36 | { 37 | private: 38 | std::vector m_Devices; 39 | EGpuRamDriveType m_DriveType; 40 | bool m_DriveRemovable; 41 | 42 | cl_platform_id m_clPlatformId; 43 | cl_device_id m_clDeviceId; 44 | DWORD m_DeviceId; 45 | bool m_TempFolderParam; 46 | size_t m_MemSize; 47 | size_t m_BufSize; 48 | std::wstring m_ServiceName; 49 | std::wstring m_MountPoint; 50 | std::thread m_GpuThread; 51 | std::function m_StateChangeCallback; 52 | 53 | cl_context m_Context; 54 | cl_command_queue m_Queue; 55 | cl_mem m_GpuMem; 56 | char* m_pBuff; 57 | 58 | HANDLE m_ImdDrive; 59 | HANDLE m_ShmHandle; 60 | HANDLE m_ShmMutexSrv; 61 | HANDLE m_ShmReqEvent; 62 | HANDLE m_ShmRespEvent; 63 | void* m_ShmView; 64 | 65 | void* m_BufStart; 66 | 67 | Config config; 68 | DebugTools debugTools; 69 | 70 | #if GPU_API == GPU_API_CUDA 71 | CUdeviceptr m_cuDevPtr; 72 | CUdevice m_cuDev; 73 | CUcontext m_cuCtx; 74 | #endif 75 | 76 | public: 77 | GPURamDrive(); 78 | ~GPURamDrive(); 79 | 80 | void RefreshGPUInfo(); 81 | const std::vector& GetGpuDevices(); 82 | 83 | void SetDriveType(EGpuRamDriveType type); 84 | void SetDriveType(const wchar_t* type); 85 | void SetRemovable(bool removable); 86 | void CreateRamDevice(cl_platform_id PlatformId, cl_device_id DeviceId, const std::wstring& ServiceName, size_t MemSize, const wchar_t* MountPoint, const std::wstring& FormatParam, const std::wstring& LabelParam, bool TempFolderParam); 87 | void ImdiskMountDevice(const wchar_t* MountPoint); 88 | void ImdiskUnmountDevice(); 89 | bool IsMounted(); 90 | void SetStateChangeCallback(const std::function callback); 91 | 92 | private: 93 | void Close(); 94 | void GpuAllocateRam(); 95 | safeio_ssize_t GpuWrite(void *buf, safeio_size_t size, off_t_64 offset); 96 | safeio_ssize_t GpuRead(void *buf, safeio_size_t size, off_t_64 offset); 97 | 98 | void ImdiskSetupComm(const std::wstring& ServiceName); 99 | void ImdiskHandleComm(); 100 | }; 101 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_gl_ext.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | /* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ 27 | /* OpenGL dependencies. */ 28 | 29 | #ifndef __OPENCL_CL_GL_EXT_H 30 | #define __OPENCL_CL_GL_EXT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | /* 43 | * For each extension, follow this template 44 | * cl_VEN_extname extension */ 45 | /* #define cl_VEN_extname 1 46 | * ... define new types, if any 47 | * ... define new tokens, if any 48 | * ... define new APIs, if any 49 | * 50 | * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header 51 | * This allows us to avoid having to decide whether to include GL headers or GLES here. 52 | */ 53 | 54 | /* 55 | * cl_khr_gl_event extension 56 | * See section 9.9 in the OpenCL 1.1 spec for more information 57 | */ 58 | #define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D 59 | 60 | extern CL_API_ENTRY cl_event CL_API_CALL 61 | clCreateEventFromGLsyncKHR(cl_context /* context */, 62 | cl_GLsync /* cl_GLsync */, 63 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif /* __OPENCL_CL_GL_EXT_H */ 70 | -------------------------------------------------------------------------------- /GpuRamDrive/EntryPoint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | GpuRamDrive proxy for ImDisk Virtual Disk Driver. 3 | 4 | Copyright (C) 2016 Syahmi Azhar. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include "stdafx.h" 29 | #include "GpuRamDrive.h" 30 | #include "GpuRamGui.h" 31 | 32 | const wchar_t GPU_HELP_STRING[] = L"Usage:\n" 33 | " GpuRamDrive.exe --autoMount --hide\n" 34 | "\n" 35 | "Options:\n" 36 | " --autoMount Mount all drivers with Start on windows\n" 37 | " --hide Hide GUI to tray\n" 38 | " --help Show this help\n"; 39 | 40 | int APIENTRY wWinMain( 41 | _In_ HINSTANCE hInstance, 42 | _In_opt_ HINSTANCE hPrevInstance, 43 | _In_ LPWSTR lpCmdLine, 44 | _In_ int nCmdShow) 45 | { 46 | GpuRamGui gui; 47 | 48 | LPWSTR *szArglist; 49 | int nArgs; 50 | szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); 51 | 52 | bool gpuMount = false; 53 | bool helpRequest = false; 54 | 55 | if (szArglist) { 56 | for (int i = 0; i < nArgs; i++) { 57 | if (_wcsicmp(szArglist[i], L"--autoMount") == 0) 58 | { 59 | gpuMount = true; 60 | } 61 | else if (_wcsicmp(szArglist[i], L"--hide") == 0) 62 | { 63 | nCmdShow = SW_HIDE; 64 | } 65 | else if (_wcsicmp(szArglist[i], L"--help") == 0 || 66 | _wcsicmp(szArglist[i], L"-h") == 0 || 67 | _wcsicmp(szArglist[i], L"/h") == 0 || 68 | _wcsicmp(szArglist[i], L"/?") == 0) 69 | { 70 | helpRequest = true; 71 | } 72 | } 73 | 74 | if (helpRequest) { 75 | if (GetConsoleWindow() == NULL) { 76 | MessageBoxW(NULL, GPU_HELP_STRING, L"GpuRamDrive help", MB_OK); 77 | } 78 | wprintf(GPU_HELP_STRING); 79 | return 0; 80 | } 81 | } 82 | 83 | if (!gui.Create(hInstance, L"GPU Ram Drive", nCmdShow, gpuMount)) { 84 | return -1; 85 | } 86 | 87 | return gui.Loop(); 88 | } -------------------------------------------------------------------------------- /GpuRamDrive/DebugTools.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DebugTools.h" 3 | #include "CudaHandler.h" 4 | 5 | DebugTools::DebugTools(LPCTSTR pszFileName) 6 | { 7 | this->pszFileName = new TCHAR[_tcslen(pszFileName) + 10]; 8 | _tcscpy(this->pszFileName, pszFileName); 9 | #if GPU_API == GPU_API_CUDA 10 | _tcscat(this->pszFileName, L"_CUDA"); 11 | #endif 12 | _tcscat(this->pszFileName, L".log"); 13 | } 14 | 15 | DebugTools::~DebugTools() {} 16 | 17 | void DebugTools::deb(wchar_t* msg, ...) 18 | { 19 | #if _DEBUG 20 | va_list ap; 21 | wchar_t string[2048] = {}; 22 | wchar_t stringout[4096] = {}; 23 | 24 | va_start(ap, msg); 25 | vswprintf(string, wcslen(string) - 1, msg, ap); 26 | va_end(ap); 27 | 28 | swprintf(stringout, wcslen(stringout) - 1, L"<%X> %s\n", GetCurrentThreadId(), string); 29 | OutputDebugString(stringout); 30 | writeToFile(this->pszFileName, stringout); 31 | #endif 32 | } 33 | 34 | wchar_t* DebugTools::fmterr(DWORD err) 35 | { 36 | LPVOID lpMsgBuf = NULL; 37 | static wchar_t szInternal[255] = { 0 }; 38 | 39 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 40 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); 41 | 42 | lstrcpy(szInternal, (wchar_t*)lpMsgBuf); 43 | LocalFree(lpMsgBuf); 44 | return szInternal; 45 | } 46 | 47 | void DebugTools::writeToFile(LPCTSTR filename, wchar_t* data) 48 | { 49 | wchar_t message[4096] = {}; 50 | _stprintf(message, L"%S - %s", getCurrentTimestamp().c_str(), data); 51 | 52 | HANDLE hFile; 53 | DWORD dwBytesToWrite = (DWORD)wcslen(message) * sizeof(wchar_t); 54 | DWORD dwBytesWritten; 55 | BOOL bErrorFlag = FALSE; 56 | 57 | hFile = CreateFile(filename, // name of the write 58 | FILE_APPEND_DATA, // open for appending 59 | FILE_SHARE_READ, // share for reading only 60 | NULL, // default security 61 | OPEN_ALWAYS, // open existing file or create new file 62 | FILE_ATTRIBUTE_NORMAL, // normal file 63 | NULL); // no attr. template 64 | 65 | if (hFile == INVALID_HANDLE_VALUE) return; 66 | 67 | while (dwBytesToWrite > 0) 68 | { 69 | bErrorFlag = WriteFile( 70 | hFile, // open file handle 71 | (LPVOID)message, // start of data to write 72 | dwBytesToWrite, // number of bytes to write 73 | &dwBytesWritten, // number of bytes that were written 74 | NULL); // no overlapped structure 75 | 76 | if (!bErrorFlag) break; 77 | 78 | data += dwBytesWritten; 79 | dwBytesToWrite -= dwBytesWritten; 80 | } 81 | 82 | CloseHandle(hFile); 83 | } 84 | 85 | std::string DebugTools::getCurrentTimestamp() 86 | { 87 | using std::chrono::system_clock; 88 | auto currentTime = std::chrono::system_clock::now(); 89 | char buffer[80]; 90 | 91 | auto transformed = currentTime.time_since_epoch().count() / 1000000; 92 | 93 | auto millis = transformed % 1000; 94 | 95 | std::time_t tt; 96 | tt = system_clock::to_time_t(currentTime); 97 | auto timeinfo = localtime(&tt); 98 | strftime(buffer, 80, "%F %H:%M:%S", timeinfo); 99 | sprintf(buffer, "%s:%03d", buffer, (int)millis); 100 | 101 | return std::string(buffer); 102 | } -------------------------------------------------------------------------------- /GpuRamDrive/DataGridConfig.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "DataGridConfig.h" 3 | 4 | DataGridConfig::DataGridConfig() 5 | { 6 | } 7 | 8 | DataGridConfig::~DataGridConfig() 9 | { 10 | } 11 | 12 | void DataGridConfig::create(HWND hwnd, RECT rect) 13 | { 14 | m_hdataGrid.Create(rect, hwnd, 8); 15 | // Set DataGrid column info 16 | m_hdataGrid.SetColumnInfo(0, L"Letter", 70, DGTA_CENTER); 17 | m_hdataGrid.SetColumnInfo(1, L"GpuId", 70, DGTA_CENTER); 18 | m_hdataGrid.SetColumnInfo(2, L"Format", 80, DGTA_CENTER); 19 | m_hdataGrid.SetColumnInfo(3, L"MemSize", 100, DGTA_CENTER); 20 | m_hdataGrid.SetColumnInfo(4, L"Label", 110, DGTA_CENTER); 21 | m_hdataGrid.SetColumnInfo(5, L"Temp", 70, DGTA_CENTER); 22 | m_hdataGrid.SetColumnInfo(6, L"Start", 70, DGTA_CENTER); 23 | m_hdataGrid.SetColumnInfo(7, L"Image", 80, DGTA_CENTER); 24 | 25 | ShowScrollBar(m_hdataGrid.GetWindowHandle(), SB_BOTH, FALSE ); 26 | 27 | LOGFONT lf; 28 | m_hdataGrid.GetColumnFont(&lf); 29 | _tcscpy(lf.lfFaceName, _T("Segoe UI")); 30 | m_hdataGrid.SetColumnFont(&lf); 31 | 32 | m_hdataGrid.GetRowFont(&lf); 33 | _tcscpy(lf.lfFaceName, _T("Segoe UI")); 34 | m_hdataGrid.SetRowFont(&lf); 35 | } 36 | 37 | HWND DataGridConfig::getDataGridHandler() 38 | { 39 | return m_hdataGrid.GetSafeHwnd(); 40 | } 41 | 42 | void DataGridConfig::sendWinProcEvent(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 43 | { 44 | m_hdataGrid.SubEditProc(hWnd, message, wParam, lParam); 45 | } 46 | 47 | void DataGridConfig::add(Config config, DWORD deviceId, bool isMounted) 48 | { 49 | int rowNumber = m_hdataGrid.GetRowNumber(); 50 | config.setCurrentDeviceId(deviceId); 51 | 52 | TCHAR szItem[MAX_PATH]; 53 | _stprintf(szItem, _T("%c:"), 'A' + deviceId); 54 | m_hdataGrid.InsertItem(szItem, DGTA_CENTER); 55 | m_hdataGrid.SetItemInfo(rowNumber, 0, szItem, DGTA_CENTER, true, deviceId); 56 | 57 | _stprintf(szItem, _T("%d"), config.getGpuId()); 58 | m_hdataGrid.SetItemInfo(rowNumber, 1, szItem, DGTA_CENTER, true); 59 | 60 | if (config.getDriveFormat() == 0) 61 | m_hdataGrid.SetItemInfo(rowNumber, 2, L"FAT32", DGTA_CENTER, true); 62 | else if (config.getDriveFormat() == 1) 63 | m_hdataGrid.SetItemInfo(rowNumber, 2, L"exFAT", DGTA_CENTER, true); 64 | else 65 | m_hdataGrid.SetItemInfo(rowNumber, 2, L"NTFS", DGTA_CENTER, true); 66 | 67 | _stprintf(szItem, _T("%d"), config.getMemSize()); 68 | m_hdataGrid.SetItemInfo(rowNumber, 3, szItem, DGTA_CENTER, true); 69 | 70 | config.getDriveLabel(szItem); 71 | m_hdataGrid.SetItemInfo(rowNumber, 4, szItem, DGTA_CENTER, true); 72 | 73 | if (config.getTempFolder()) 74 | m_hdataGrid.SetItemInfo(rowNumber, 5, L"True", DGTA_CENTER, true); 75 | else 76 | m_hdataGrid.SetItemInfo(rowNumber, 5, L"False", DGTA_CENTER, true); 77 | 78 | if (config.getStartOnWindows()) 79 | m_hdataGrid.SetItemInfo(rowNumber, 6, L"True", DGTA_CENTER, true); 80 | else 81 | m_hdataGrid.SetItemInfo(rowNumber, 6, L"False", DGTA_CENTER, true); 82 | 83 | config.getImageFile(szItem); 84 | if (wcslen(szItem) > 0) 85 | m_hdataGrid.SetItemInfo(rowNumber, 7, L"True", DGTA_CENTER, true); 86 | else 87 | m_hdataGrid.SetItemInfo(rowNumber, 7, L"False", DGTA_CENTER, true); 88 | 89 | setRowMount(deviceId, isMounted); 90 | m_hdataGrid.Update(); 91 | } 92 | 93 | void DataGridConfig::reload(Config config, std::map& m_RamDrive) 94 | { 95 | m_hdataGrid.RemoveAllItems(); 96 | auto devices = config.getDeviceList(); 97 | for (int i = 0; i < devices.size(); i++) 98 | { 99 | add(config, devices.at(i), m_RamDrive[devices.at(i)].IsMounted()); 100 | } 101 | resetSelection(); 102 | } 103 | 104 | DWORD DataGridConfig::getSelectedDeviceId() 105 | { 106 | int row = m_hdataGrid.GetSelectedRow(); 107 | if (row >= 0) 108 | return (DWORD)m_hdataGrid.GetItemData(row); 109 | return (DWORD)-1; 110 | } 111 | 112 | void DataGridConfig::setRowMount(DWORD deviceId, BOOL value) 113 | { 114 | m_hdataGrid.SetRowMount(deviceId, value); 115 | } 116 | 117 | void DataGridConfig::resetSelection() 118 | { 119 | m_hdataGrid.ResetSelection(); 120 | m_hdataGrid.Update(); 121 | } 122 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/imdproxy.h: -------------------------------------------------------------------------------- 1 | /* 2 | ImDisk Proxy Services. 3 | 4 | Copyright (C) 2005-2007 Olof Lagerkvist. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #ifndef _INC_IMDPROXY_ 29 | #define _INC_IMDPROXY_ 30 | 31 | #if !defined(_WIN32) && !defined(_NTDDK_) 32 | typedef int32_t LONG; 33 | typedef uint32_t ULONG; 34 | typedef int64_t LONGLONG; 35 | typedef uint64_t ULONGLONG; 36 | typedef u_short WCHAR; 37 | #endif 38 | 39 | #define IMDPROXY_SVC L"ImDskSvc" 40 | #define IMDPROXY_SVC_PIPE_DOSDEV_NAME L"\\\\.\\PIPE\\" IMDPROXY_SVC 41 | #define IMDPROXY_SVC_PIPE_NATIVE_NAME L"\\Device\\NamedPipe\\" IMDPROXY_SVC 42 | 43 | #define IMDPROXY_FLAG_RO 0x01 44 | #define IMDPROXY_FLAG_SUPPORTS_UNMAP 0x02 45 | #define IMDPROXY_FLAG_SUPPORTS_ZERO 0x04 46 | 47 | typedef enum _IMDPROXY_REQ 48 | { 49 | IMDPROXY_REQ_NULL, 50 | IMDPROXY_REQ_INFO, 51 | IMDPROXY_REQ_READ, 52 | IMDPROXY_REQ_WRITE, 53 | IMDPROXY_REQ_CONNECT, 54 | IMDPROXY_REQ_CLOSE, 55 | IMDPROXY_REQ_UNMAP, 56 | IMDPROXY_REQ_ZERO 57 | } IMDPROXY_REQ, *PIMDPROXY_REQ; 58 | 59 | typedef struct _IMDPROXY_CONNECT_REQ 60 | { 61 | ULONGLONG request_code; 62 | ULONGLONG flags; 63 | ULONGLONG length; 64 | } IMDPROXY_CONNECT_REQ, *PIMDPROXY_CONNECT_REQ; 65 | 66 | typedef struct _IMDPROXY_CONNECT_RESP 67 | { 68 | ULONGLONG error_code; 69 | ULONGLONG object_ptr; 70 | } IMDPROXY_CONNECT_RESP, *PIMDPROXY_CONNECT_RESP; 71 | 72 | typedef struct _IMDPROXY_INFO_RESP 73 | { 74 | ULONGLONG file_size; 75 | ULONGLONG req_alignment; 76 | ULONGLONG flags; 77 | } IMDPROXY_INFO_RESP, *PIMDPROXY_INFO_RESP; 78 | 79 | typedef struct _IMDPROXY_READ_REQ 80 | { 81 | ULONGLONG request_code; 82 | ULONGLONG offset; 83 | ULONGLONG length; 84 | } IMDPROXY_READ_REQ, *PIMDPROXY_READ_REQ; 85 | 86 | typedef struct _IMDPROXY_READ_RESP 87 | { 88 | ULONGLONG errorno; 89 | ULONGLONG length; 90 | } IMDPROXY_READ_RESP, *PIMDPROXY_READ_RESP; 91 | 92 | typedef struct _IMDPROXY_WRITE_REQ 93 | { 94 | ULONGLONG request_code; 95 | ULONGLONG offset; 96 | ULONGLONG length; 97 | } IMDPROXY_WRITE_REQ, *PIMDPROXY_WRITE_REQ; 98 | 99 | typedef struct _IMDPROXY_WRITE_RESP 100 | { 101 | ULONGLONG errorno; 102 | ULONGLONG length; 103 | } IMDPROXY_WRITE_RESP, *PIMDPROXY_WRITE_RESP; 104 | 105 | typedef struct _IMDPROXY_UNMAP_REQ 106 | { 107 | ULONGLONG request_code; 108 | ULONGLONG length; 109 | } IMDPROXY_UNMAP_REQ, *PIMDPROXY_UNMAP_REQ; 110 | 111 | typedef struct _IMDPROXY_UNMAP_RESP 112 | { 113 | ULONGLONG errorno; 114 | } IMDPROXY_UNMAP_RESP, *PIMDPROXY_UNMAP_RESP; 115 | 116 | typedef struct _IMDPROXY_ZERO_REQ 117 | { 118 | ULONGLONG request_code; 119 | ULONGLONG length; 120 | } IMDPROXY_ZERO_REQ, *PIMDPROXY_ZERO_REQ; 121 | 122 | typedef struct _IMDPROXY_ZERO_RESP 123 | { 124 | ULONGLONG errorno; 125 | } IMDPROXY_ZERO_RESP, *PIMDPROXY_ZERO_RESP; 126 | 127 | // For shared memory proxy communication only. Offset to data area in 128 | // shared memory. 129 | #define IMDPROXY_HEADER_SIZE 4096 130 | 131 | #endif // _INC_IMDPROXY_ 132 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/wkmem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | inline void *operator_new(size_t Size, UCHAR FillByte) 4 | { 5 | void * result = ExAllocatePoolWithTag(NonPagedPool, Size, POOL_TAG); 6 | 7 | if (result != NULL) 8 | { 9 | RtlFillMemory(result, Size, FillByte); 10 | } 11 | 12 | return result; 13 | } 14 | 15 | inline void * __CRTDECL operator new(size_t Size) 16 | { 17 | return operator_new(Size, 0); 18 | } 19 | 20 | inline void * __CRTDECL operator new[](size_t Size) 21 | { 22 | return operator_new(Size, 0); 23 | } 24 | 25 | inline void * __CRTDECL operator new(size_t Size, UCHAR FillByte) 26 | { 27 | return operator_new(Size, FillByte); 28 | } 29 | 30 | inline void operator_delete(void *Ptr) 31 | { 32 | if (Ptr != NULL) 33 | { 34 | ExFreePoolWithTag(Ptr, POOL_TAG); 35 | } 36 | } 37 | 38 | inline void __CRTDECL operator delete(void * Ptr) 39 | { 40 | operator_delete(Ptr); 41 | } 42 | 43 | inline void __CRTDECL operator delete(void * Ptr, size_t) 44 | { 45 | operator_delete(Ptr); 46 | } 47 | 48 | inline void __CRTDECL operator delete[](void * Ptr) 49 | { 50 | operator_delete(Ptr); 51 | } 52 | 53 | template class WPoolMem 54 | { 55 | protected: 56 | T *ptr; 57 | SIZE_T bytecount; 58 | 59 | explicit WPoolMem(T *pBlk, SIZE_T AllocationSize) 60 | : ptr(pBlk), 61 | bytecount(pBlk != NULL ? AllocationSize : 0) { } 62 | 63 | public: 64 | operator bool() 65 | { 66 | return ptr != NULL; 67 | } 68 | 69 | bool operator!() 70 | { 71 | return ptr == NULL; 72 | } 73 | 74 | operator T*() 75 | { 76 | return ptr; 77 | } 78 | 79 | T* operator ->() 80 | { 81 | return ptr; 82 | } 83 | 84 | T* operator+(int i) 85 | { 86 | return ptr + i; 87 | } 88 | 89 | T* operator-(int i) 90 | { 91 | return ptr - i; 92 | } 93 | 94 | T* operator =(T *pBlk) 95 | { 96 | Free(); 97 | return ptr = pBlk; 98 | } 99 | 100 | SIZE_T Count() const 101 | { 102 | return GetSize() / sizeof(T); 103 | } 104 | 105 | SIZE_T GetSize() const 106 | { 107 | return ptr != NULL ? bytecount : 0; 108 | } 109 | 110 | void Free() 111 | { 112 | if (ptr != NULL) 113 | { 114 | ExFreePoolWithTag(ptr, POOL_TAG); 115 | ptr = NULL; 116 | } 117 | } 118 | 119 | void Clear() 120 | { 121 | if ((ptr != NULL) && (bytecount > 0)) 122 | { 123 | RtlZeroMemory(ptr, bytecount); 124 | } 125 | } 126 | 127 | T* Abandon() 128 | { 129 | T* ab_ptr = ptr; 130 | ptr = NULL; 131 | bytecount = 0; 132 | return ab_ptr; 133 | } 134 | 135 | ~WPoolMem() 136 | { 137 | Free(); 138 | } 139 | 140 | void Initialize(SIZE_T AllocateSize) 141 | { 142 | ptr = (T*)ExAllocatePoolWithTag(pool_type, AllocateSize, POOL_TAG); 143 | bytecount = AllocateSize; 144 | } 145 | 146 | public: 147 | WPoolMem() : 148 | ptr(NULL), 149 | bytecount(0) { } 150 | 151 | explicit WPoolMem(SIZE_T AllocateSize) 152 | { 153 | Initialize(AllocateSize); 154 | } 155 | 156 | T* Alloc(SIZE_T AllocateSize) 157 | { 158 | Free(); 159 | Initialize(AllocateSize); 160 | return ptr; 161 | } 162 | }; 163 | 164 | class WHandle 165 | { 166 | private: 167 | HANDLE h; 168 | 169 | public: 170 | operator bool() 171 | { 172 | return h != NULL; 173 | } 174 | 175 | bool operator !() 176 | { 177 | return h == NULL; 178 | } 179 | 180 | operator HANDLE() 181 | { 182 | return h; 183 | } 184 | 185 | void Close() 186 | { 187 | if (h != NULL) 188 | { 189 | ZwClose(h); 190 | h = NULL; 191 | } 192 | } 193 | 194 | WHandle() : 195 | h(NULL) { } 196 | 197 | explicit WHandle(HANDLE h) : 198 | h(h) { } 199 | 200 | ~WHandle() 201 | { 202 | Close(); 203 | } 204 | }; 205 | 206 | -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamDrive.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | 65 | 66 | Source Files 67 | 68 | 69 | Source Files 70 | 71 | 72 | Source Files 73 | 74 | 75 | Source Files 76 | 77 | 78 | Source Files 79 | 80 | 81 | Source Files 82 | 83 | 84 | Source Files 85 | 86 | 87 | Source Files 88 | 89 | 90 | Source Files 91 | 92 | 93 | Source Files 94 | 95 | 96 | Source Files 97 | 98 | 99 | Source Files 100 | 101 | 102 | Source Files 103 | 104 | 105 | 106 | 107 | Resource Files 108 | 109 | 110 | 111 | 112 | Resource Files 113 | 114 | 115 | Resource Files 116 | 117 | 118 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_d3d10_ext.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2009 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_D3D10_EXT_H 25 | #define __OPENCL_CL_D3D10_EXT_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /****************************************************************************** 36 | * cl_nv_d3d10_sharing */ 37 | 38 | typedef cl_uint cl_d3d10_device_source_nv; 39 | typedef cl_uint cl_d3d10_device_set_nv; 40 | 41 | /******************************************************************************/ 42 | 43 | // Error Codes 44 | #define CL_INVALID_D3D10_DEVICE_NV -1002 45 | #define CL_INVALID_D3D10_RESOURCE_NV -1003 46 | #define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_NV -1004 47 | #define CL_D3D10_RESOURCE_NOT_ACQUIRED_NV -1005 48 | 49 | // cl_d3d10_device_source_nv 50 | #define CL_D3D10_DEVICE_NV 0x4010 51 | #define CL_D3D10_DXGI_ADAPTER_NV 0x4011 52 | 53 | // cl_d3d10_device_set_nv 54 | #define CL_PREFERRED_DEVICES_FOR_D3D10_NV 0x4012 55 | #define CL_ALL_DEVICES_FOR_D3D10_NV 0x4013 56 | 57 | // cl_context_info 58 | #define CL_CONTEXT_D3D10_DEVICE_NV 0x4014 59 | 60 | // cl_mem_info 61 | #define CL_MEM_D3D10_RESOURCE_NV 0x4015 62 | 63 | // cl_image_info 64 | #define CL_IMAGE_D3D10_SUBRESOURCE_NV 0x4016 65 | 66 | // cl_command_type 67 | #define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_NV 0x4017 68 | #define CL_COMMAND_RELEASE_D3D10_OBJECTS_NV 0x4018 69 | 70 | /******************************************************************************/ 71 | 72 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10NV_fn)( 73 | cl_platform_id platform, 74 | cl_d3d10_device_source_nv d3d_device_source, 75 | void * d3d_object, 76 | cl_d3d10_device_set_nv d3d_device_set, 77 | cl_uint num_entries, 78 | cl_device_id * devices, 79 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 80 | 81 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferNV_fn)( 82 | cl_context context, 83 | cl_mem_flags flags, 84 | ID3D10Buffer * resource, 85 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 86 | 87 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DNV_fn)( 88 | cl_context context, 89 | cl_mem_flags flags, 90 | ID3D10Texture2D * resource, 91 | UINT subresource, 92 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 93 | 94 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DNV_fn)( 95 | cl_context context, 96 | cl_mem_flags flags, 97 | ID3D10Texture3D * resource, 98 | UINT subresource, 99 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 100 | 101 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsNV_fn)( 102 | cl_command_queue command_queue, 103 | cl_uint num_objects, 104 | const cl_mem * mem_objects, 105 | cl_uint num_events_in_wait_list, 106 | const cl_event * event_wait_list, 107 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 108 | 109 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsNV_fn)( 110 | cl_command_queue command_queue, 111 | cl_uint num_objects, 112 | cl_mem * mem_objects, 113 | cl_uint num_events_in_wait_list, 114 | const cl_event * event_wait_list, 115 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif // __OPENCL_CL_D3D10_H 122 | 123 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_d3d11_ext.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2009 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_D3D11_EXT_H 25 | #define __OPENCL_CL_D3D11_EXT_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /****************************************************************************** 36 | * cl_nv_d3d11_sharing */ 37 | 38 | typedef cl_uint cl_d3d11_device_source_nv; 39 | typedef cl_uint cl_d3d11_device_set_nv; 40 | 41 | /******************************************************************************/ 42 | 43 | // Error Codes 44 | #define CL_INVALID_D3D11_DEVICE_NV -1006 45 | #define CL_INVALID_D3D11_RESOURCE_NV -1007 46 | #define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_NV -1008 47 | #define CL_D3D11_RESOURCE_NOT_ACQUIRED_NV -1009 48 | 49 | // cl_d3d11_device_source_nv 50 | #define CL_D3D11_DEVICE_NV 0x4019 51 | #define CL_D3D11_DXGI_ADAPTER_NV 0x401A 52 | 53 | // cl_d3d11_device_set_nv 54 | #define CL_PREFERRED_DEVICES_FOR_D3D11_NV 0x401B 55 | #define CL_ALL_DEVICES_FOR_D3D11_NV 0x401C 56 | 57 | // cl_context_info 58 | #define CL_CONTEXT_D3D11_DEVICE_NV 0x401D 59 | 60 | // cl_mem_info 61 | #define CL_MEM_D3D11_RESOURCE_NV 0x401E 62 | 63 | // cl_image_info 64 | #define CL_IMAGE_D3D11_SUBRESOURCE_NV 0x401F 65 | 66 | // cl_command_type 67 | #define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_NV 0x4020 68 | #define CL_COMMAND_RELEASE_D3D11_OBJECTS_NV 0x4021 69 | 70 | /******************************************************************************/ 71 | 72 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11NV_fn)( 73 | cl_platform_id platform, 74 | cl_d3d11_device_source_nv d3d_device_source, 75 | void * d3d_object, 76 | cl_d3d11_device_set_nv d3d_device_set, 77 | cl_uint num_entries, 78 | cl_device_id * devices, 79 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 80 | 81 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferNV_fn)( 82 | cl_context context, 83 | cl_mem_flags flags, 84 | ID3D11Buffer * resource, 85 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 86 | 87 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DNV_fn)( 88 | cl_context context, 89 | cl_mem_flags flags, 90 | ID3D11Texture2D * resource, 91 | UINT subresource, 92 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 93 | 94 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DNV_fn)( 95 | cl_context context, 96 | cl_mem_flags flags, 97 | ID3D11Texture3D * resource, 98 | UINT subresource, 99 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 100 | 101 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsNV_fn)( 102 | cl_command_queue command_queue, 103 | cl_uint num_objects, 104 | const cl_mem * mem_objects, 105 | cl_uint num_events_in_wait_list, 106 | const cl_event * event_wait_list, 107 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 108 | 109 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsNV_fn)( 110 | cl_command_queue command_queue, 111 | cl_uint num_objects, 112 | cl_mem * mem_objects, 113 | cl_uint num_events_in_wait_list, 114 | const cl_event * event_wait_list, 115 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 116 | 117 | #ifdef __cplusplus 118 | } 119 | #endif 120 | 121 | #endif // __OPENCL_CL_D3D11_H 122 | 123 | -------------------------------------------------------------------------------- /GpuRamDrive/TaskManager.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "TaskManager.h" 3 | 4 | TaskManager::TaskManager() 5 | { 6 | } 7 | 8 | TaskManager::~TaskManager() 9 | { 10 | } 11 | 12 | bool TaskManager::ExistTaskJob(LPCTSTR wszTaskName) 13 | { 14 | HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); 15 | hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL); 16 | ITaskService* pService = NULL; 17 | hr = CoCreateInstance(CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, IID_ITaskService, (void**)&pService); 18 | hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t()); 19 | ITaskFolder* pRootFolder = NULL; 20 | hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder); 21 | IRegisteredTask* pRegisteredTask = NULL; 22 | hr = pRootFolder->GetTask(_bstr_t(wszTaskName), &pRegisteredTask); 23 | bool exists = (hr >= 0); 24 | pRootFolder->Release(); 25 | CoUninitialize(); 26 | return exists; 27 | } 28 | 29 | bool TaskManager::CreateTaskJob(LPCWSTR wszTaskName, wchar_t* nFullPath, wchar_t* nArguments) 30 | { 31 | wchar_t pathName[MAX_PATH] = { 0 }; 32 | wcscpy(pathName, nFullPath); 33 | wchar_t* pos = wcsrchr(pathName, '\\'); 34 | *pos = '\0'; 35 | 36 | HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); 37 | hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL); 38 | ITaskService* pService = NULL; 39 | hr = CoCreateInstance(CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, IID_ITaskService, (void**)&pService); 40 | hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t()); 41 | ITaskFolder* pRootFolder = NULL; 42 | hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder); 43 | pRootFolder->DeleteTask(_bstr_t(wszTaskName), 0); 44 | 45 | ITaskDefinition* pTask = NULL; 46 | hr = pService->NewTask(0, &pTask); 47 | pService->Release(); 48 | 49 | IRegistrationInfo* pRegInfo = NULL; 50 | hr = pTask->get_RegistrationInfo(&pRegInfo); 51 | 52 | IPrincipal* pPrincipal = NULL; 53 | pTask->get_Principal(&pPrincipal); 54 | pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST); 55 | 56 | hr = pRegInfo->put_Author(L"GPURAMDRIVE"); 57 | pRegInfo->Release(); 58 | 59 | ITaskSettings* pSettings = NULL; 60 | hr = pTask->get_Settings(&pSettings); 61 | 62 | pSettings->put_AllowDemandStart(VARIANT_FALSE); 63 | pSettings->put_DisallowStartIfOnBatteries(VARIANT_FALSE); 64 | pSettings->put_StopIfGoingOnBatteries(VARIANT_FALSE); 65 | pSettings->put_MultipleInstances(TASK_INSTANCES_IGNORE_NEW); 66 | pSettings->put_ExecutionTimeLimit(_bstr_t(L"PT0S")); 67 | pSettings->put_StartWhenAvailable(VARIANT_TRUE); 68 | pSettings->Release(); 69 | 70 | ITriggerCollection* pTriggerCollection = NULL; 71 | hr = pTask->get_Triggers(&pTriggerCollection); 72 | 73 | ITrigger* pTrigger = NULL; 74 | hr = pTriggerCollection->Create(TASK_TRIGGER_LOGON, &pTrigger); 75 | pTriggerCollection->Release(); 76 | 77 | ILogonTrigger* pLogonTrigger = NULL; 78 | hr = pTrigger->QueryInterface(IID_ILogonTrigger, (void**)&pLogonTrigger); 79 | pTrigger->Release(); 80 | 81 | hr = pLogonTrigger->put_Id(_bstr_t(L"Trigger1")); 82 | //hr = pLogonTrigger->put_StartBoundary(_bstr_t(L"2020-01-01T12:05:00")); 83 | //hr = pLogonTrigger->put_EndBoundary(_bstr_t(L"2020-05-02T08:00:00")); 84 | //hr = pLogonTrigger->put_UserId(_bstr_t(L"DOMAIN\\UserName")); 85 | pLogonTrigger->Release(); 86 | 87 | IActionCollection* pActionCollection = NULL; 88 | hr = pTask->get_Actions(&pActionCollection); 89 | 90 | IAction* pAction = NULL; 91 | hr = pActionCollection->Create(TASK_ACTION_EXEC, &pAction); 92 | pActionCollection->Release(); 93 | 94 | IExecAction* pExecAction = NULL; 95 | // QI for the executable task pointer. 96 | hr = pAction->QueryInterface(IID_IExecAction, (void**)&pExecAction); 97 | pAction->Release(); 98 | 99 | hr = pExecAction->put_Path(_bstr_t(nFullPath)); 100 | pExecAction->put_Arguments(_bstr_t(nArguments)); 101 | pExecAction->put_WorkingDirectory(_bstr_t(pathName)); 102 | pExecAction->Release(); 103 | 104 | IRegisteredTask* pRegisteredTask = NULL; 105 | 106 | hr = pRootFolder->RegisterTaskDefinition( 107 | _bstr_t(wszTaskName), 108 | pTask, 109 | TASK_CREATE_OR_UPDATE, 110 | _variant_t(L"S-1-5-32-544"), 111 | _variant_t(), 112 | TASK_LOGON_GROUP, 113 | _variant_t(L""), 114 | &pRegisteredTask); 115 | 116 | pRootFolder->Release(); 117 | pTask->Release(); 118 | pRegisteredTask->Release(); 119 | CoUninitialize(); 120 | 121 | return true; 122 | } 123 | 124 | bool TaskManager::DeleteTaskJob(LPCWSTR wszTaskName) 125 | { 126 | HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); 127 | hr = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, 0, NULL); 128 | ITaskService* pService = NULL; 129 | hr = CoCreateInstance(CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, IID_ITaskService, (void**)&pService); 130 | hr = pService->Connect(_variant_t(), _variant_t(), _variant_t(), _variant_t()); 131 | ITaskFolder* pRootFolder = NULL; 132 | hr = pService->GetFolder(_bstr_t(L"\\"), &pRootFolder); 133 | pRootFolder->DeleteTask(_bstr_t(wszTaskName), 0); 134 | 135 | pRootFolder->Release(); 136 | CoUninitialize(); 137 | 138 | return true; 139 | } 140 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_d3d11.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_D3D11_H 27 | #define __OPENCL_CL_D3D11_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /****************************************************************************** 38 | * cl_khr_d3d11_sharing */ 39 | #define cl_khr_d3d11_sharing 1 40 | 41 | typedef cl_uint cl_d3d11_device_source_khr; 42 | typedef cl_uint cl_d3d11_device_set_khr; 43 | 44 | /******************************************************************************/ 45 | 46 | /* Error Codes */ 47 | #define CL_INVALID_D3D11_DEVICE_KHR -1006 48 | #define CL_INVALID_D3D11_RESOURCE_KHR -1007 49 | #define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 50 | #define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 51 | 52 | /* cl_d3d11_device_source */ 53 | #define CL_D3D11_DEVICE_KHR 0x4019 54 | #define CL_D3D11_DXGI_ADAPTER_KHR 0x401A 55 | 56 | /* cl_d3d11_device_set */ 57 | #define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B 58 | #define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C 59 | 60 | /* cl_context_info */ 61 | #define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D 62 | #define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D 63 | 64 | /* cl_mem_info */ 65 | #define CL_MEM_D3D11_RESOURCE_KHR 0x401E 66 | 67 | /* cl_image_info */ 68 | #define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F 69 | 70 | /* cl_command_type */ 71 | #define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 72 | #define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 73 | 74 | /******************************************************************************/ 75 | 76 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( 77 | cl_platform_id platform, 78 | cl_d3d11_device_source_khr d3d_device_source, 79 | void * d3d_object, 80 | cl_d3d11_device_set_khr d3d_device_set, 81 | cl_uint num_entries, 82 | cl_device_id * devices, 83 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 84 | 85 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( 86 | cl_context context, 87 | cl_mem_flags flags, 88 | ID3D11Buffer * resource, 89 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 90 | 91 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( 92 | cl_context context, 93 | cl_mem_flags flags, 94 | ID3D11Texture2D * resource, 95 | UINT subresource, 96 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | ID3D11Texture3D * resource, 102 | UINT subresource, 103 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 104 | 105 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( 106 | cl_command_queue command_queue, 107 | cl_uint num_objects, 108 | const cl_mem * mem_objects, 109 | cl_uint num_events_in_wait_list, 110 | const cl_event * event_wait_list, 111 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 112 | 113 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( 114 | cl_command_queue command_queue, 115 | cl_uint num_objects, 116 | const cl_mem * mem_objects, 117 | cl_uint num_events_in_wait_list, 118 | const cl_event * event_wait_list, 119 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif /* __OPENCL_CL_D3D11_H */ 126 | 127 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_d3d10.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_D3D10_H 27 | #define __OPENCL_CL_D3D10_H 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /****************************************************************************** 38 | * cl_khr_d3d10_sharing */ 39 | #define cl_khr_d3d10_sharing 1 40 | 41 | typedef cl_uint cl_d3d10_device_source_khr; 42 | typedef cl_uint cl_d3d10_device_set_khr; 43 | 44 | /******************************************************************************/ 45 | 46 | /* Error Codes */ 47 | #define CL_INVALID_D3D10_DEVICE_KHR -1002 48 | #define CL_INVALID_D3D10_RESOURCE_KHR -1003 49 | #define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 50 | #define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 51 | 52 | /* cl_d3d10_device_source_nv */ 53 | #define CL_D3D10_DEVICE_KHR 0x4010 54 | #define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 55 | 56 | /* cl_d3d10_device_set_nv */ 57 | #define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 58 | #define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 59 | 60 | /* cl_context_info */ 61 | #define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 62 | #define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C 63 | 64 | /* cl_mem_info */ 65 | #define CL_MEM_D3D10_RESOURCE_KHR 0x4015 66 | 67 | /* cl_image_info */ 68 | #define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 69 | 70 | /* cl_command_type */ 71 | #define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 72 | #define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 73 | 74 | /******************************************************************************/ 75 | 76 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( 77 | cl_platform_id platform, 78 | cl_d3d10_device_source_khr d3d_device_source, 79 | void * d3d_object, 80 | cl_d3d10_device_set_khr d3d_device_set, 81 | cl_uint num_entries, 82 | cl_device_id * devices, 83 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 84 | 85 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( 86 | cl_context context, 87 | cl_mem_flags flags, 88 | ID3D10Buffer * resource, 89 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 90 | 91 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( 92 | cl_context context, 93 | cl_mem_flags flags, 94 | ID3D10Texture2D * resource, 95 | UINT subresource, 96 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | ID3D10Texture3D * resource, 102 | UINT subresource, 103 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 104 | 105 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( 106 | cl_command_queue command_queue, 107 | cl_uint num_objects, 108 | const cl_mem * mem_objects, 109 | cl_uint num_events_in_wait_list, 110 | const cl_event * event_wait_list, 111 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 112 | 113 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( 114 | cl_command_queue command_queue, 115 | cl_uint num_objects, 116 | const cl_mem * mem_objects, 117 | cl_uint num_events_in_wait_list, 118 | const cl_event * event_wait_list, 119 | cl_event * event) CL_API_SUFFIX__VERSION_1_0; 120 | 121 | #ifdef __cplusplus 122 | } 123 | #endif 124 | 125 | #endif /* __OPENCL_CL_D3D10_H */ 126 | 127 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_dx9_media_sharing.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | /* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ 25 | 26 | #ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H 27 | #define __OPENCL_CL_DX9_MEDIA_SHARING_H 28 | 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /****************************************************************************** 37 | /* cl_khr_dx9_media_sharing */ 38 | #define cl_khr_dx9_media_sharing 1 39 | 40 | typedef cl_uint cl_dx9_media_adapter_type_khr; 41 | typedef cl_uint cl_dx9_media_adapter_set_khr; 42 | 43 | #if defined(_WIN32) 44 | #include 45 | typedef struct _cl_dx9_surface_info_khr 46 | { 47 | IDirect3DSurface9 *resource; 48 | HANDLE shared_handle; 49 | } cl_dx9_surface_info_khr; 50 | #endif 51 | 52 | 53 | /******************************************************************************/ 54 | 55 | /* Error Codes */ 56 | #define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 57 | #define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 58 | #define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 59 | #define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 60 | 61 | /* cl_media_adapter_type_khr */ 62 | #define CL_ADAPTER_D3D9_KHR 0x2020 63 | #define CL_ADAPTER_D3D9EX_KHR 0x2021 64 | #define CL_ADAPTER_DXVA_KHR 0x2022 65 | 66 | /* cl_media_adapter_set_khr */ 67 | #define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 68 | #define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 69 | 70 | /* cl_context_info */ 71 | #define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 72 | #define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 73 | #define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 74 | 75 | /* cl_mem_info */ 76 | #define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 77 | #define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 78 | 79 | /* cl_image_info */ 80 | #define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A 81 | 82 | /* cl_command_type */ 83 | #define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B 84 | #define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C 85 | 86 | /******************************************************************************/ 87 | 88 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( 89 | cl_platform_id platform, 90 | cl_uint num_media_adapters, 91 | cl_dx9_media_adapter_type_khr * media_adapter_type, 92 | void * media_adapters, 93 | cl_dx9_media_adapter_set_khr media_adapter_set, 94 | cl_uint num_entries, 95 | cl_device_id * devices, 96 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; 97 | 98 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( 99 | cl_context context, 100 | cl_mem_flags flags, 101 | cl_dx9_media_adapter_type_khr adapter_type, 102 | void * surface_info, 103 | cl_uint plane, 104 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; 105 | 106 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( 107 | cl_command_queue command_queue, 108 | cl_uint num_objects, 109 | const cl_mem * mem_objects, 110 | cl_uint num_events_in_wait_list, 111 | const cl_event * event_wait_list, 112 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 113 | 114 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( 115 | cl_command_queue command_queue, 116 | cl_uint num_objects, 117 | const cl_mem * mem_objects, 118 | cl_uint num_events_in_wait_list, 119 | const cl_event * event_wait_list, 120 | cl_event * event) CL_API_SUFFIX__VERSION_1_2; 121 | 122 | #ifdef __cplusplus 123 | } 124 | #endif 125 | 126 | #endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */ 127 | 128 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_egl.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2010 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_EGL_H 25 | #define __OPENCL_CL_EGL_H 26 | 27 | #ifdef __APPLE__ 28 | 29 | #else 30 | #include 31 | #include 32 | #include 33 | #endif 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | 40 | /* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ 41 | #define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F 42 | #define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D 43 | #define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E 44 | 45 | /* Error type for clCreateFromEGLImageKHR */ 46 | #define CL_INVALID_EGL_OBJECT_KHR -1093 47 | #define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 48 | 49 | /* CLeglImageKHR is an opaque handle to an EGLImage */ 50 | typedef void* CLeglImageKHR; 51 | 52 | /* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ 53 | typedef void* CLeglDisplayKHR; 54 | 55 | /* CLeglSyncKHR is an opaque handle to an EGLSync object */ 56 | typedef void* CLeglSyncKHR; 57 | 58 | /* properties passed to clCreateFromEGLImageKHR */ 59 | typedef intptr_t cl_egl_image_properties_khr; 60 | 61 | 62 | #define cl_khr_egl_image 1 63 | 64 | extern CL_API_ENTRY cl_mem CL_API_CALL 65 | clCreateFromEGLImageKHR(cl_context /* context */, 66 | CLeglDisplayKHR /* egldisplay */, 67 | CLeglImageKHR /* eglimage */, 68 | cl_mem_flags /* flags */, 69 | const cl_egl_image_properties_khr * /* properties */, 70 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 71 | 72 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( 73 | cl_context context, 74 | CLeglDisplayKHR egldisplay, 75 | CLeglImageKHR eglimage, 76 | cl_mem_flags flags, 77 | const cl_egl_image_properties_khr * properties, 78 | cl_int * errcode_ret); 79 | 80 | 81 | extern CL_API_ENTRY cl_int CL_API_CALL 82 | clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, 83 | cl_uint /* num_objects */, 84 | const cl_mem * /* mem_objects */, 85 | cl_uint /* num_events_in_wait_list */, 86 | const cl_event * /* event_wait_list */, 87 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 88 | 89 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( 90 | cl_command_queue command_queue, 91 | cl_uint num_objects, 92 | const cl_mem * mem_objects, 93 | cl_uint num_events_in_wait_list, 94 | const cl_event * event_wait_list, 95 | cl_event * event); 96 | 97 | 98 | extern CL_API_ENTRY cl_int CL_API_CALL 99 | clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, 100 | cl_uint /* num_objects */, 101 | const cl_mem * /* mem_objects */, 102 | cl_uint /* num_events_in_wait_list */, 103 | const cl_event * /* event_wait_list */, 104 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 105 | 106 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( 107 | cl_command_queue command_queue, 108 | cl_uint num_objects, 109 | const cl_mem * mem_objects, 110 | cl_uint num_events_in_wait_list, 111 | const cl_event * event_wait_list, 112 | cl_event * event); 113 | 114 | 115 | #define cl_khr_egl_event 1 116 | 117 | extern CL_API_ENTRY cl_event CL_API_CALL 118 | clCreateEventFromEGLSyncKHR(cl_context /* context */, 119 | CLeglSyncKHR /* sync */, 120 | CLeglDisplayKHR /* display */, 121 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 122 | 123 | typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( 124 | cl_context context, 125 | CLeglSyncKHR sync, 126 | CLeglDisplayKHR display, 127 | cl_int * errcode_ret); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif /* __OPENCL_CL_EGL_H */ 134 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_d3d9_ext.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008-2009 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_D3D9_EXT_H 25 | #define __OPENCL_CL_D3D9_EXT_H 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /****************************************************************************** 36 | * cl_nv_d3d9_sharing */ 37 | 38 | typedef cl_uint cl_d3d9_device_source_nv; 39 | typedef cl_uint cl_d3d9_device_set_nv; 40 | 41 | /******************************************************************************/ 42 | 43 | // Error Codes 44 | #define CL_INVALID_D3D9_DEVICE_NV -1010 45 | #define CL_INVALID_D3D9_RESOURCE_NV -1011 46 | #define CL_D3D9_RESOURCE_ALREADY_ACQUIRED_NV -1012 47 | #define CL_D3D9_RESOURCE_NOT_ACQUIRED_NV -1013 48 | 49 | // cl_d3d9_device_source_nv 50 | #define CL_D3D9_DEVICE_NV 0x4022 51 | #define CL_D3D9_ADAPTER_NAME_NV 0x4023 52 | 53 | // cl_d3d9_device_set_nv 54 | #define CL_PREFERRED_DEVICES_FOR_D3D9_NV 0x4024 55 | #define CL_ALL_DEVICES_FOR_D3D9_NV 0x4025 56 | 57 | // cl_context_info 58 | #define CL_CONTEXT_D3D9_DEVICE_NV 0x4026 59 | 60 | // cl_mem_info 61 | #define CL_MEM_D3D9_RESOURCE_NV 0x4027 62 | 63 | // cl_image_info 64 | #define CL_IMAGE_D3D9_FACE_NV 0x4028 65 | #define CL_IMAGE_D3D9_LEVEL_NV 0x4029 66 | 67 | // cl_command_type 68 | #define CL_COMMAND_ACQUIRE_D3D9_OBJECTS_NV 0x402A 69 | #define CL_COMMAND_RELEASE_D3D9_OBJECTS_NV 0x402B 70 | 71 | /******************************************************************************/ 72 | 73 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D9NV_fn)( 74 | cl_platform_id platform, 75 | cl_d3d9_device_source_nv d3d_device_source, 76 | void * d3d_object, 77 | cl_d3d9_device_set_nv d3d_device_set, 78 | cl_uint num_entries, 79 | cl_device_id * devices, 80 | cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; 81 | 82 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9VertexBufferNV_fn)( 83 | cl_context context, 84 | cl_mem_flags flags, 85 | IDirect3DVertexBuffer9 * resource, 86 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 87 | 88 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9IndexBufferNV_fn)( 89 | cl_context context, 90 | cl_mem_flags flags, 91 | IDirect3DIndexBuffer9 * resource, 92 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 93 | 94 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9SurfaceNV_fn)( 95 | cl_context context, 96 | cl_mem_flags flags, 97 | IDirect3DSurface9 * resource, 98 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 99 | 100 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9TextureNV_fn)( 101 | cl_context context, 102 | cl_mem_flags flags, 103 | IDirect3DTexture9 *resource, 104 | UINT miplevel, 105 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 106 | 107 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9CubeTextureNV_fn)( 108 | cl_context context, 109 | cl_mem_flags flags, 110 | IDirect3DCubeTexture9 * resource, 111 | D3DCUBEMAP_FACES facetype, 112 | UINT miplevel, 113 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 114 | 115 | typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D9VolumeTextureNV_fn)( 116 | cl_context context, 117 | cl_mem_flags flags, 118 | IDirect3DVolumeTexture9 * resource, 119 | UINT miplevel, 120 | cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; 121 | 122 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D9ObjectsNV_fn)( 123 | cl_command_queue command_queue, 124 | cl_uint num_objects, 125 | const cl_mem *mem_objects, 126 | cl_uint num_events_in_wait_list, 127 | const cl_event *event_wait_list, 128 | cl_event *event) CL_API_SUFFIX__VERSION_1_0; 129 | 130 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D9ObjectsNV_fn)( 131 | cl_command_queue command_queue, 132 | cl_uint num_objects, 133 | cl_mem *mem_objects, 134 | cl_uint num_events_in_wait_list, 135 | const cl_event *event_wait_list, 136 | cl_event *event) CL_API_SUFFIX__VERSION_1_0; 137 | 138 | #ifdef __cplusplus 139 | } 140 | #endif 141 | 142 | #endif // __OPENCL_CL_D3D9_H 143 | 144 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/wio.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | Win32 overlapped I/O API functions encapsulated in C++ classes. 3 | 4 | Copyright (C) 2005-2007 Olof Lagerkvist. 5 | */ 6 | 7 | #ifndef _WIO_HPP 8 | #define _WIO_HPP 9 | 10 | __inline LPSTR 11 | WideToByteAlloc(LPCWSTR lpSrc) 12 | { 13 | LPSTR lpDst; 14 | int iReqSize = 15 | WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, NULL, 0, NULL, NULL); 16 | if (iReqSize == 0) 17 | return NULL; 18 | 19 | lpDst = (LPSTR) malloc(iReqSize); 20 | if (lpDst == NULL) 21 | return NULL; 22 | 23 | if (WideCharToMultiByte(CP_ACP, 0, lpSrc, -1, lpDst, iReqSize, NULL, NULL) 24 | != iReqSize) 25 | { 26 | free(lpDst); 27 | return NULL; 28 | } 29 | 30 | return lpDst; 31 | } 32 | 33 | __inline SOCKET 34 | ConnectTCP(u_long ulAddress, u_short usPort) 35 | { 36 | // Open socket 37 | SOCKET sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 38 | if (sd == INVALID_SOCKET) 39 | return INVALID_SOCKET; 40 | 41 | sockaddr_in addr = { 0 }; 42 | addr.sin_family = AF_INET; 43 | addr.sin_port = usPort; 44 | addr.sin_addr.s_addr = ulAddress; 45 | 46 | if (connect(sd, (sockaddr*)&addr, sizeof addr) == SOCKET_ERROR) 47 | { 48 | int __h_errno = WSAGetLastError(); 49 | closesocket(sd); 50 | WSASetLastError(__h_errno); 51 | return INVALID_SOCKET; 52 | } 53 | 54 | return sd; 55 | } 56 | 57 | __inline SOCKET 58 | ConnectTCP(LPCWSTR wszServer, u_short usPort) 59 | { 60 | if (wszServer == NULL) 61 | return INVALID_SOCKET; 62 | 63 | if (usPort == 0) 64 | return INVALID_SOCKET; 65 | 66 | LPSTR szServer = WideToByteAlloc(wszServer); 67 | 68 | // Get server address 69 | u_long haddr = inet_addr(szServer); 70 | 71 | // Wasn't IP? Lookup host. 72 | if (haddr == INADDR_NONE) 73 | { 74 | hostent *hent = gethostbyname(szServer); 75 | if (hent == NULL) 76 | { 77 | free(szServer); 78 | return INVALID_SOCKET; 79 | } 80 | 81 | haddr = *(u_long*)hent->h_addr; 82 | } 83 | 84 | free(szServer); 85 | 86 | return ConnectTCP(haddr, usPort); 87 | } 88 | 89 | __inline SOCKET 90 | ConnectTCP(LPCWSTR wszServer, LPCWSTR wszService) 91 | { 92 | if (wszServer == NULL) 93 | return INVALID_SOCKET; 94 | 95 | if (wszService == NULL) 96 | return INVALID_SOCKET; 97 | 98 | u_short usPort = htons((u_short)wcstoul(wszService, NULL, 0)); 99 | if (usPort == 0) 100 | { 101 | // Get port name for service 102 | LPSTR szService = WideToByteAlloc(wszService); 103 | servent *service = getservbyname(szService, "tcp"); 104 | free(szService); 105 | if (service == NULL) 106 | return INVALID_SOCKET; 107 | 108 | usPort = service->s_port; 109 | } 110 | 111 | return ConnectTCP(wszServer, usPort); 112 | } 113 | 114 | /// Enhanced OVERLAPPED stucture with encapsulated API functions. 115 | struct WOverlapped : public OVERLAPPED 116 | { 117 | BOOL Read(HANDLE hFile, LPVOID lpBuf, DWORD dwLength, DWORDLONG dwStart = 0) 118 | { 119 | if (!ResetEvent()) 120 | return FALSE; 121 | 122 | Offset = (DWORD) dwStart; 123 | OffsetHigh = (DWORD) (dwStart >> 32); 124 | DWORD dw; 125 | return ReadFile(hFile, lpBuf, dwLength, &dw, this); 126 | } 127 | 128 | BOOL Write(HANDLE hFile, LPCVOID lpBuf, DWORD dwLength, 129 | DWORDLONG dwStart = 0) 130 | { 131 | if (!ResetEvent()) 132 | return FALSE; 133 | 134 | Offset = (DWORD) dwStart; 135 | OffsetHigh = (DWORD) (dwStart >> 32); 136 | DWORD dw; 137 | return WriteFile(hFile, lpBuf, dwLength, &dw, this); 138 | } 139 | 140 | DWORD BufRecv(HANDLE hFile, PVOID pBuf, DWORD dwBufSize) 141 | { 142 | DWORD dwDone = 0; 143 | bool bGood = true; 144 | 145 | for (PVOID ptr = pBuf; dwDone < dwBufSize; ) 146 | { 147 | if (!Read(hFile, ptr, dwBufSize-dwDone)) 148 | if (GetLastError() != ERROR_IO_PENDING) 149 | { 150 | bGood = false; 151 | break; 152 | } 153 | 154 | DWORD dwReadLen; 155 | if (!GetResult(hFile, &dwReadLen)) 156 | { 157 | bGood = false; 158 | break; 159 | } 160 | 161 | if (dwReadLen == 0) 162 | break; 163 | 164 | dwDone += dwReadLen; 165 | (*(LPBYTE*) &ptr) += dwReadLen; 166 | } 167 | 168 | if (bGood & (dwDone != dwBufSize)) 169 | SetLastError(ERROR_HANDLE_EOF); 170 | 171 | return dwDone; 172 | } 173 | 174 | BOOL BufSend(HANDLE hFile, const void *pBuf, DWORD dwBufSize) 175 | { 176 | DWORD dwDone = 0; 177 | for (const void *ptr = pBuf; dwDone < dwBufSize; ) 178 | { 179 | if (!Write(hFile, ptr, dwBufSize-dwDone)) 180 | if (GetLastError() != ERROR_IO_PENDING) 181 | break; 182 | 183 | DWORD dwWriteLen; 184 | if (!GetResult(hFile, &dwWriteLen)) 185 | break; 186 | 187 | if (dwWriteLen == 0) 188 | break; 189 | 190 | dwDone += dwWriteLen; 191 | *(CONST BYTE**) &ptr += dwWriteLen; 192 | } 193 | 194 | return dwDone == dwBufSize; 195 | } 196 | 197 | BOOL ConnectNamedPipe(HANDLE hNamedPipe) 198 | { 199 | return ::ConnectNamedPipe(hNamedPipe, this); 200 | } 201 | 202 | BOOL WaitCommEvent(HANDLE hFile, LPDWORD lpEvtMask) 203 | { 204 | return ::WaitCommEvent(hFile, lpEvtMask, this); 205 | } 206 | 207 | BOOL GetResult(HANDLE hFile, LPDWORD lpNumberOfBytesTransferred, 208 | BOOL bWait = TRUE) 209 | { 210 | return GetOverlappedResult(hFile, this, lpNumberOfBytesTransferred, bWait); 211 | } 212 | 213 | bool Wait(DWORD dwTimeout = INFINITE) 214 | { 215 | return WaitForSingleObject(hEvent, dwTimeout) == WAIT_OBJECT_0; 216 | } 217 | 218 | bool IsComplete() 219 | { 220 | return WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0; 221 | } 222 | 223 | BOOL SetEvent() 224 | { 225 | return ::SetEvent(hEvent); 226 | } 227 | 228 | BOOL ResetEvent() 229 | { 230 | return ::ResetEvent(hEvent); 231 | } 232 | 233 | BOOL PulseEvent() 234 | { 235 | return ::PulseEvent(hEvent); 236 | } 237 | 238 | operator bool() const 239 | { 240 | return hEvent != NULL; 241 | } 242 | 243 | bool operator!() const 244 | { 245 | return hEvent == NULL; 246 | } 247 | 248 | explicit WOverlapped(OVERLAPPED &ol) 249 | { 250 | *(OVERLAPPED*)this = ol; 251 | } 252 | 253 | explicit WOverlapped(BOOL bManualReset = true, BOOL bSignalled = false) 254 | { 255 | ZeroMemory(this, sizeof *this); 256 | hEvent = CreateEvent(NULL, bManualReset, bSignalled, NULL); 257 | } 258 | 259 | explicit WOverlapped(LPCTSTR lpName) 260 | { 261 | ZeroMemory(this, sizeof *this); 262 | hEvent = OpenEvent(EVENT_ALL_ACCESS, false, lpName); 263 | } 264 | 265 | ~WOverlapped() 266 | { 267 | if (hEvent != NULL) 268 | CloseHandle(hEvent); 269 | } 270 | }; 271 | 272 | #else // __cplusplus 273 | 274 | #endif // _WIO_HPP 275 | -------------------------------------------------------------------------------- /GpuRamDrive/Regkey.h: -------------------------------------------------------------------------------- 1 | #ifndef HDR_REGKEY_INCLUDE 2 | #define HDR_REGKEY_INCLUDE 3 | 4 | // Support for the Windows Registry 5 | 6 | // Version 5.10 (1st October) 7 | // License - Free for any purpose, just do not remove the copyright 8 | // Copyright (C) 1996-2006 - Jonathan Wilkes 9 | 10 | #if !defined(STRICT) 11 | #define STRICT 1 12 | #endif 13 | 14 | // Includes 15 | #if !defined(_WINDOWS_) 16 | #include 17 | #endif 18 | 19 | #include 20 | 21 | namespace xfc 22 | { 23 | class RegKey 24 | { 25 | private: 26 | DWORD iLastErrorCode_; // The error code for the last error that occurred 27 | 28 | HKEY hTheKey_; // The active key 29 | HKEY hBaseKey_; // The base key, either HKEY_LOCAL... or another machine 30 | 31 | bool bRemote_; // Connected to a remote machine ? 32 | TCHAR* pszComputerName_; // Which computer to connect to, NULL means local 33 | 34 | FILETIME obLastWriteTime_; // Last write time ( Used for Enumerate() functions ) 35 | 36 | bool IntSetValue(LPCTSTR pszValueName, const BYTE* pValue, DWORD dwValueLength, DWORD dwValueType); // Generic SetValue() 37 | bool IntGetValue(LPCTSTR pszValueName, BYTE& pValue, DWORD& dwValueLength); // Generic GetValue() 38 | 39 | bool ConnectRemote(HKEY hKeyToOpen, LPCTSTR pszComputerName); // Connect to a remote computer's registry 40 | 41 | static bool RecursiveDelete(RegKey* pTheCallingClass, HKEY hTheKey, LPCTSTR pszKeyName); 42 | 43 | public: 44 | RegKey(); 45 | ~RegKey(); 46 | 47 | // Can either use these (for more detailed control) or the Shortcut functions 48 | // In most cases, the shortcut functions will be enough 49 | 50 | // Opens/Creates a key and make it the active key 51 | bool OpenKey(LPCTSTR pszKeyName, bool bCreateIfNoExist = false, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 52 | 53 | // Creates and opens a new key - key becomes active key 54 | bool CreateKey(LPCTSTR pszKeyName, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 55 | 56 | void CloseKey(); // Close the active key, and remote key if necessary 57 | bool DeleteKey(LPCTSTR pszKeyName); // Deletes a key and all values and subkeys 58 | 59 | // Get all the subkeys for the active key, returns REG_NO_MORE_ITEMS when no more items 60 | bool EnumerateKeys(LPTSTR pszSubkeyName, const DWORD dwIndex); 61 | 62 | // Get information on active key 63 | bool QueryKey(DWORD& dwNumSubKeys, DWORD& dwMaxSubKeyName, DWORD& dwNumValues, DWORD& dwMaxValueName, DWORD& dwMaxValueDataSize, FILETIME& lastWriteTime); 64 | 65 | bool Flush(); // Flushes the active key ( Write to hard disk ) 66 | 67 | // Various Value functions 68 | bool QueryValue(LPCTSTR pszValueName, DWORD& dwValueLength, DWORD& dwValueType); // Retrieves the size and type of a value for the active key 69 | bool DeleteValue(LPCTSTR pszValueName); // Deletes a value from the currently open active key 70 | 71 | // Get all the values for the active key, returns REG_NO_MORE_ITEMS when no more items 72 | bool EnumerateValues(LPTSTR pszValueName, LPBYTE lpValue, DWORD& dwValueSize, DWORD& dwValueType, const DWORD dwIndex); 73 | 74 | // Set Value 75 | bool SetValue(LPCTSTR pszValueName, DWORD dwValue); // Sets a DWORD value for the active key 76 | bool SetValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwValueLength); // Sets a STRING value for the active key 77 | bool SetValue(LPCTSTR pszValueName, const BYTE* pValue, DWORD dwValueLength); // Sets a BINARY value for the active key 78 | bool SetValueEx(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwValueLength); // Sets an EXPANDED STRING value for the active key 79 | 80 | // Get Value 81 | bool GetValue(LPCTSTR pszValueName, DWORD& dwValue); // Gets a DWORD value for the active key 82 | bool GetValue(LPCTSTR pszValueName, LPTSTR pszValue, DWORD& dwValueLength); // Gets a STRING value for the active key 83 | bool GetValue(LPCTSTR pszValueName, BYTE& pValue, DWORD& dwValueLength); // Gets a BINARY value for the active key 84 | 85 | ////////////////////////// 86 | // Configuration functions 87 | 88 | // Saves a registry tree into the specified file/path from the specified key position 89 | bool SaveRegistry(LPCTSTR pszFileName, LPCTSTR pszKeyName, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 90 | 91 | // Restores a saved registry tree from the specified file to the specified key position 92 | bool RestoreRegistry(LPCTSTR pszFileName, LPCTSTR pszKeyName, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 93 | 94 | ///////////////// 95 | // Misc Functions 96 | 97 | // Notify user of a change in the registry ( Local computer only ) 98 | // The notification flags can be or'd together 99 | bool NotifyChange(LPCTSTR pszKeyName, DWORD dwNotifyfilter, bool bWatchSubKeys = false, HANDLE hEvent = NULL, HKEY hBaseKey = HKEY_CURRENT_USER); 100 | 101 | ///////////////////// 102 | // Shortcut functions 103 | // These functions perform an open automatically, and close if necessary 104 | // Saves having to do an Open(), Set(), Close() sequence. 105 | 106 | // Returns the size of the specified registry value (in bytes) 107 | DWORD GetSizeOfValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 108 | 109 | // Opens/Creates a key, sets a value within the key and makes it the active key if active = true, else closes the key 110 | bool SetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, DWORD dwValue 111 | , bool bCreateIfNoExist = false, bool bActive = false 112 | , HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 113 | 114 | bool SetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwValueLength 115 | , bool bCreateIfNoExist = false, bool bActive = false 116 | , HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 117 | 118 | bool SetKeyValueEx(LPCTSTR pszKeyName, LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwValueLength 119 | , bool bCreateIfNoExist = false, bool bActive = false 120 | , HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); // Expanded String 121 | 122 | bool SetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, const BYTE* pValue, DWORD dwValueLength 123 | , bool bCreateIfNoExist = false, bool bActive = false 124 | , HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 125 | 126 | // Opens a key and retrieves a value 127 | // Make it the active key if active = true, else close the key 128 | bool GetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, DWORD& dwValue 129 | , bool bActive = false, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 130 | 131 | bool GetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, LPTSTR pszValue, DWORD dwValueLength 132 | , bool bActive = false, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 133 | 134 | bool GetKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, BYTE& pValue, DWORD dwValueLength 135 | , bool bActive = false, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 136 | 137 | // Opens a key, deletes a value from the key and makes key active if required 138 | bool DeleteKeyValue(LPCTSTR pszKeyName, LPCTSTR pszValueName, bool bActive = false, HKEY hBaseKey = HKEY_CURRENT_USER, LPCTSTR pszMachineName = NULL); 139 | 140 | bool MoveKey(LPCTSTR pszSourceKey, LPCTSTR pszDestKey, HKEY hBaseKey = HKEY_CURRENT_USER); // Move a key, it's subkeys and all values 141 | 142 | // Delete a Key and all of the values and subkeys 143 | bool QuickDeleteKey(LPCTSTR pszKeyName, HKEY hBaseKey = HKEY_CURRENT_USER); 144 | 145 | // Support functions 146 | DWORD GetLastErrorCode() const { return iLastErrorCode_; }; 147 | }; 148 | } // end of namespace 149 | 150 | #endif // HDR_REGKEY_INCLUDE 151 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/wmem.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* 4 | WPreserveLastError 5 | 6 | An object of this class preserves value of Win32 GetLastError(). Constructor 7 | calls GetLastError() and saves returned value. Destructor calls SetLastError() 8 | with saved value. 9 | */ 10 | class WPreserveLastError 11 | { 12 | public: 13 | DWORD Value; 14 | 15 | WPreserveLastError() 16 | { 17 | Value = GetLastError(); 18 | } 19 | 20 | ~WPreserveLastError() 21 | { 22 | SetLastError(Value); 23 | } 24 | }; 25 | 26 | struct WSystemInfo : public SYSTEM_INFO 27 | { 28 | WSystemInfo() 29 | { 30 | GetSystemInfo(this); 31 | } 32 | }; 33 | 34 | #if _WIN32_WINNT >= 0x0501 35 | struct WNativeSystemInfo : public SYSTEM_INFO 36 | { 37 | WNativeSystemInfo() 38 | { 39 | GetNativeSystemInfo(this); 40 | } 41 | }; 42 | #endif 43 | 44 | struct WOSVersionInfo : public OSVERSIONINFO 45 | { 46 | WOSVersionInfo() 47 | { 48 | dwOSVersionInfoSize = sizeof(*this); 49 | 50 | #if _MSC_VER >= 1500 51 | #pragma warning(suppress: 4996) 52 | #endif 53 | GetVersionEx(this); 54 | } 55 | }; 56 | 57 | struct WOSVersionInfoEx : public OSVERSIONINFOEX 58 | { 59 | WOSVersionInfoEx() 60 | { 61 | dwOSVersionInfoSize = sizeof(*this); 62 | 63 | #if _MSC_VER >= 1500 64 | #pragma warning(suppress: 4996) 65 | #endif 66 | GetVersionEx((LPOSVERSIONINFO)this); 67 | } 68 | }; 69 | 70 | template class WMemHolder 71 | { 72 | protected: 73 | T *ptr; 74 | 75 | public: 76 | operator bool() const 77 | { 78 | return ptr != NULL; 79 | } 80 | 81 | bool operator!() const 82 | { 83 | return ptr == NULL; 84 | } 85 | 86 | operator T*() const 87 | { 88 | return ptr; 89 | } 90 | 91 | T* operator ->() const 92 | { 93 | return ptr; 94 | } 95 | 96 | T* operator+(int i) const 97 | { 98 | return ptr + i; 99 | } 100 | 101 | T* operator-(int i) const 102 | { 103 | return ptr - i; 104 | } 105 | 106 | T* operator =(T *pBlk) 107 | { 108 | Free(); 109 | return ptr = pBlk; 110 | } 111 | 112 | T* Abandon() 113 | { 114 | T* ab_ptr = ptr; 115 | ptr = NULL; 116 | return ab_ptr; 117 | } 118 | 119 | WMemHolder() 120 | : ptr(NULL) { } 121 | 122 | explicit WMemHolder(T *pBlk) 123 | : ptr(pBlk) 124 | { 125 | } 126 | }; 127 | 128 | class WEnvironmentStrings : public WMemHolder 129 | { 130 | public: 131 | WEnvironmentStrings() 132 | : WMemHolder(GetEnvironmentStrings()) 133 | { 134 | } 135 | 136 | BOOL Free() 137 | { 138 | if (ptr != NULL) 139 | { 140 | return FreeEnvironmentStrings(ptr); 141 | } 142 | else 143 | { 144 | return TRUE; 145 | } 146 | } 147 | 148 | ~WEnvironmentStrings() 149 | { 150 | Free(); 151 | } 152 | }; 153 | 154 | template class WMem : public WMemHolder 155 | { 156 | public: 157 | T* operator =(T *pBlk) 158 | { 159 | Free(); 160 | return ptr = pBlk; 161 | } 162 | 163 | DWORD_PTR Count() const 164 | { 165 | return GetSize() / sizeof(T); 166 | } 167 | 168 | DWORD_PTR GetSize() const 169 | { 170 | if (ptr == NULL) 171 | return 0; 172 | else 173 | return LocalSize(ptr); 174 | } 175 | 176 | /* WMem::ReAlloc() 177 | * 178 | * Note that this function uses LocalReAlloc() which makes it lose the 179 | * data if the block must be moved to increase. 180 | */ 181 | T* ReAlloc(DWORD dwAllocSize) 182 | { 183 | T *newblock = (T*)LocalReAlloc(ptr, dwAllocSize, LMEM_ZEROINIT); 184 | if (newblock != NULL) 185 | return ptr = newblock; 186 | else 187 | return NULL; 188 | } 189 | 190 | T* Free() 191 | { 192 | if (ptr == NULL) 193 | return NULL; 194 | else 195 | return ptr = (T*)LocalFree(ptr); 196 | } 197 | 198 | WMem() 199 | { 200 | } 201 | 202 | explicit WMem(DWORD dwAllocSize) 203 | : WMemHolder(LocalAlloc(LPTR, dwAllocSize)) 204 | { 205 | } 206 | 207 | explicit WMem(T *pBlk) 208 | : WMemHolder(pBlk) 209 | { 210 | } 211 | 212 | ~WMem() 213 | { 214 | Free(); 215 | } 216 | }; 217 | 218 | #ifdef _INC_MALLOC 219 | template class WCRTMem : public WMemHolder 220 | { 221 | public: 222 | T* operator =(T *pBlk) 223 | { 224 | Free(); 225 | return ptr = pBlk; 226 | } 227 | 228 | size_t Count() const 229 | { 230 | return GetSize() / sizeof(T); 231 | } 232 | 233 | size_t GetSize() const 234 | { 235 | if (ptr == NULL) 236 | return 0; 237 | else 238 | return _msize(ptr); 239 | } 240 | 241 | /* WHeapMem::ReAlloc() 242 | * 243 | * This function uses realloc() which makes it preserve the data if the 244 | * block must be moved to increase. 245 | */ 246 | T* ReAlloc(size_t dwAllocSize) 247 | { 248 | T *newblock = (T*)realloc(ptr, dwAllocSize); 249 | if (newblock != NULL) 250 | return ptr = newblock; 251 | else 252 | return NULL; 253 | } 254 | 255 | void Free() 256 | { 257 | if (ptr != NULL) 258 | { 259 | free(ptr); 260 | ptr = NULL; 261 | } 262 | } 263 | 264 | WCRTMem() 265 | { 266 | } 267 | 268 | explicit WCRTMem(size_t dwAllocSize) 269 | : WMemHolder((T*)malloc(dwAllocSize)) { } 270 | 271 | explicit WCRTMem(T *pBlk) 272 | : WMemHolder(pBlk) { } 273 | 274 | ~WCRTMem() 275 | { 276 | Free(); 277 | } 278 | }; 279 | #endif 280 | 281 | template class WHeapMem :public WMemHolder 282 | { 283 | public: 284 | T* operator =(T *pBlk) 285 | { 286 | Free(); 287 | return ptr = pBlk; 288 | } 289 | 290 | (WHeapMem &) operator =(WHeapMem &o) 291 | { 292 | Free(); 293 | ptr = o.ptr; 294 | o.ptr = NULL; 295 | return *this; 296 | } 297 | 298 | SIZE_T Count() const 299 | { 300 | return GetSize() / sizeof(T); 301 | } 302 | 303 | SIZE_T GetSize(DWORD dwFlags = 0) const 304 | { 305 | if (ptr == NULL) 306 | return 0; 307 | else 308 | return HeapSize(GetProcessHeap(), dwFlags, ptr); 309 | } 310 | 311 | /* WHeapMem::ReAlloc() 312 | * 313 | * This function uses HeapReAlloc() which makes it preserve the data if the 314 | * block must be moved to increase. 315 | */ 316 | T* ReAlloc(SIZE_T AllocSize, DWORD dwFlags = 0) 317 | { 318 | if (ptr == NULL) 319 | { 320 | return ptr = 321 | (T*)HeapAlloc(GetProcessHeap(), dwFlags, AllocSize); 322 | } 323 | 324 | T *newblock = (T*)HeapReAlloc(GetProcessHeap(), dwFlags, ptr, AllocSize); 325 | 326 | if (newblock != NULL) 327 | return ptr = newblock; 328 | else 329 | return NULL; 330 | } 331 | 332 | T *Free(DWORD dwFlags = 0) 333 | { 334 | if ((this == NULL) || (ptr == NULL)) 335 | return NULL; 336 | else if (HeapFree(GetProcessHeap(), dwFlags, ptr)) 337 | return ptr = NULL; 338 | else 339 | return ptr; 340 | } 341 | 342 | WHeapMem() 343 | { 344 | } 345 | 346 | explicit WHeapMem(SIZE_T dwAllocSize, DWORD dwFlags = 0) 347 | : WMemHolder((T*)HeapAlloc(GetProcessHeap(), dwFlags, dwAllocSize)) 348 | { 349 | } 350 | 351 | explicit WHeapMem(T *pBlk) 352 | : WMemHolder(pBlk) 353 | { 354 | } 355 | 356 | ~WHeapMem() 357 | { 358 | Free(); 359 | } 360 | }; 361 | 362 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_gl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Copyright (c) 2008 - 2012 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | **********************************************************************************/ 23 | 24 | #ifndef __OPENCL_CL_GL_H 25 | #define __OPENCL_CL_GL_H 26 | 27 | #ifdef __APPLE__ 28 | #include 29 | #else 30 | #include 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef cl_uint cl_gl_object_type; 38 | typedef cl_uint cl_gl_texture_info; 39 | typedef cl_uint cl_gl_platform_info; 40 | typedef struct __GLsync *cl_GLsync; 41 | 42 | /* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ 43 | #define CL_GL_OBJECT_BUFFER 0x2000 44 | #define CL_GL_OBJECT_TEXTURE2D 0x2001 45 | #define CL_GL_OBJECT_TEXTURE3D 0x2002 46 | #define CL_GL_OBJECT_RENDERBUFFER 0x2003 47 | #define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E 48 | #define CL_GL_OBJECT_TEXTURE1D 0x200F 49 | #define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 50 | #define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 51 | 52 | /* cl_gl_texture_info */ 53 | #define CL_GL_TEXTURE_TARGET 0x2004 54 | #define CL_GL_MIPMAP_LEVEL 0x2005 55 | #define CL_GL_NUM_SAMPLES 0x2012 56 | 57 | 58 | extern CL_API_ENTRY cl_mem CL_API_CALL 59 | clCreateFromGLBuffer(cl_context /* context */, 60 | cl_mem_flags /* flags */, 61 | cl_GLuint /* bufobj */, 62 | int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 63 | 64 | extern CL_API_ENTRY cl_mem CL_API_CALL 65 | clCreateFromGLTexture(cl_context /* context */, 66 | cl_mem_flags /* flags */, 67 | cl_GLenum /* target */, 68 | cl_GLint /* miplevel */, 69 | cl_GLuint /* texture */, 70 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; 71 | 72 | extern CL_API_ENTRY cl_mem CL_API_CALL 73 | clCreateFromGLRenderbuffer(cl_context /* context */, 74 | cl_mem_flags /* flags */, 75 | cl_GLuint /* renderbuffer */, 76 | cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; 77 | 78 | extern CL_API_ENTRY cl_int CL_API_CALL 79 | clGetGLObjectInfo(cl_mem /* memobj */, 80 | cl_gl_object_type * /* gl_object_type */, 81 | cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; 82 | 83 | extern CL_API_ENTRY cl_int CL_API_CALL 84 | clGetGLTextureInfo(cl_mem /* memobj */, 85 | cl_gl_texture_info /* param_name */, 86 | size_t /* param_value_size */, 87 | void * /* param_value */, 88 | size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; 89 | 90 | extern CL_API_ENTRY cl_int CL_API_CALL 91 | clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, 92 | cl_uint /* num_objects */, 93 | const cl_mem * /* mem_objects */, 94 | cl_uint /* num_events_in_wait_list */, 95 | const cl_event * /* event_wait_list */, 96 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 97 | 98 | extern CL_API_ENTRY cl_int CL_API_CALL 99 | clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, 100 | cl_uint /* num_objects */, 101 | const cl_mem * /* mem_objects */, 102 | cl_uint /* num_events_in_wait_list */, 103 | const cl_event * /* event_wait_list */, 104 | cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; 105 | 106 | 107 | /* Deprecated OpenCL 1.1 APIs */ 108 | extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 109 | clCreateFromGLTexture2D(cl_context /* context */, 110 | cl_mem_flags /* flags */, 111 | cl_GLenum /* target */, 112 | cl_GLint /* miplevel */, 113 | cl_GLuint /* texture */, 114 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 115 | 116 | extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL 117 | clCreateFromGLTexture3D(cl_context /* context */, 118 | cl_mem_flags /* flags */, 119 | cl_GLenum /* target */, 120 | cl_GLint /* miplevel */, 121 | cl_GLuint /* texture */, 122 | cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; 123 | 124 | /* cl_khr_gl_sharing extension */ 125 | 126 | #define cl_khr_gl_sharing 1 127 | 128 | typedef cl_uint cl_gl_context_info; 129 | 130 | /* Additional Error Codes */ 131 | #define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 132 | 133 | /* cl_gl_context_info */ 134 | #define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 135 | #define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 136 | 137 | /* Additional cl_context_properties */ 138 | #define CL_GL_CONTEXT_KHR 0x2008 139 | #define CL_EGL_DISPLAY_KHR 0x2009 140 | #define CL_GLX_DISPLAY_KHR 0x200A 141 | #define CL_WGL_HDC_KHR 0x200B 142 | #define CL_CGL_SHAREGROUP_KHR 0x200C 143 | 144 | extern CL_API_ENTRY cl_int CL_API_CALL 145 | clGetGLContextInfoKHR(const cl_context_properties * /* properties */, 146 | cl_gl_context_info /* param_name */, 147 | size_t /* param_value_size */, 148 | void * /* param_value */, 149 | size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; 150 | 151 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( 152 | const cl_context_properties * properties, 153 | cl_gl_context_info param_name, 154 | size_t param_value_size, 155 | void * param_value, 156 | size_t * param_value_size_ret); 157 | 158 | #ifdef __cplusplus 159 | } 160 | #endif 161 | 162 | #endif /* __OPENCL_CL_GL_H */ 163 | -------------------------------------------------------------------------------- /GpuRamDrive/DataGrid.h: -------------------------------------------------------------------------------- 1 | #ifndef _DATAGRID_H_ 2 | #define _DATAGRID_H_ 3 | //can be changed const 4 | //RGB colors like DGBGR_COLOR/DGTXT_COLOR/DGRONLY_COLOR 5 | //DG_ROWINCRESEONETIME used one time allocate multiple rows for grid, to avoid memory allocate so often 6 | //DG_MINTEXTLEN used to allocate cell maxium text length, also avoid allocate memory so often 7 | // 8 | //http://www.codeproject.com/KB/miscctrl/DataGridControl.aspx 9 | //http://www.codeguru.com/cpp/controls/controls/gridcontrol/article.php/c10319/CDataGrid-Control.htm 10 | //changed since origin version 11 | //fixed bug of memory leak in DestroyDGGrid/RemoveItem/RemoveAllItems() 12 | //changed code to support UNICODE/MultiByte by using TCHAR. 13 | //InsertItem allocate fixed size string to avoid memeory allocate too often ,#define DG_MINTEXTLEN 128 can be changed to suit your need 14 | //to avoid often allocate memory define DG_ROWINCRESEONETIME, so one time it will allocate DG_ROWINCRESEONETIME rows in grid. 15 | //add function SetItemData/GetItemData to support Item Data, so add variable LPARAM lParam 16 | //add OnEdited/OnUnEdited to support edit in grid 17 | //add help function ResetGridColumns/ResetContent to help quickly clean grid. 18 | //add help function SetItemInfo/GetItemInfo to help get Iteminfo plus ItemData 19 | //add help function InsertItem to insertitem with Readly option. 20 | //GetEditSafeHwnd/GetSafeHwnd to get Handle of Grid or Edit in the grid. 21 | 22 | #include 23 | // 24 | //#ifdef UNICODE 25 | //#define _tcslen wcslen 26 | //#define _tcscpy wcscpy 27 | //#define _tcscpy_s wcscpy_s 28 | //#define _tcsncpy wcsncpy 29 | //#define _tcsncpy_s wcsncpy_s 30 | //#define _tcscat wcscat 31 | //#define _tcscat_s wcscat_s 32 | //#define _tcsupr wcsupr 33 | //#define _tcsupr_s wcsupr_s 34 | //#define _tcslwr wcslwr 35 | //#define _tcslwr_s wcslwr_s 36 | //#define _stprintf_s swprintf_s 37 | //#define _stprintf swprintf 38 | //#define _tprintf wprintf 39 | //#define _vstprintf_s vswprintf_s 40 | //#define _vstprintf vswprintf 41 | //#define _tscanf wscanf 42 | //#define TCHAR wchar_t 43 | //#else 44 | //#define _tcslen strlen 45 | //#define _tcscpy strcpy 46 | //#define _tcscpy_s strcpy_s 47 | //#define _tcsncpy strncpy 48 | //#define _tcsncpy_s strncpy_s 49 | //#define _tcscat strcat 50 | //#define _tcscat_s strcat_s 51 | //#define _tcsupr strupr 52 | //#define _tcsupr_s strupr_s 53 | //#define _tcslwr strlwr 54 | //#define _tcslwr_s strlwr_s 55 | //#define _stprintf_s sprintf_s 56 | //#define _stprintf sprintf 57 | //#define _tprintf printf 58 | //#define _vstprintf_s vsprintf_s 59 | //#define _vstprintf vsprintf 60 | //#define _tscanf scanf 61 | //#define TCHAR char 62 | //#endif 63 | 64 | #define WM_CANCEL_EDIT WM_USER + 202 65 | #define WM_EDITED WM_USER + 203 66 | 67 | /* DataGrid definitions */ 68 | #define DG_MAXGRID 20 69 | #define DG_MAXCOLUMN 1000 70 | #define DG_MAXROW 32000 71 | #define DG_ROWINCRESEONETIME 50 //One time allocate rows 72 | #define DG_MINTEXTLEN 128 //one cell max text length 73 | #define DGTA_LEFT DT_LEFT 74 | #define DGTA_CENTER DT_CENTER 75 | #define DGTA_RIGHT DT_RIGHT 76 | #define DGBGR_COLOR RGB(255,255,255) 77 | #define DGTXT_COLOR RGB(0,0,0) 78 | #define DGRONLY_COLOR RGB(245,245,245) 79 | 80 | #define DGMOUNTROWBGR_COLOR RGB(225,45,45) 81 | #define DGSELROWBGR_COLOR RGB(45,150,200) 82 | #define DGSELROWTXT_COLOR RGB(0,0,0) 83 | 84 | /* DataGrid messages */ 85 | #define DGM_ITEMCHANGED 0x0001 86 | #define DGM_ITEMTEXTCHANGED 0x0002 87 | #define DGM_ITEMADDED 0x0003 88 | #define DGM_ITEMREMOVED 0x0004 89 | #define DGM_COLUMNRESIZED 0x0005 90 | #define DGM_COLUMNCLICKED 0x0006 91 | #define DGM_STARTSORTING 0x0007 92 | #define DGM_ENDSORTING 0x0008 93 | #define DGM_ITEMREMOVEDALL 0x0009 94 | 95 | 96 | /* Custom callback procedure */ 97 | typedef int(CALLBACK* DGCOMPARE)(TCHAR* item1, TCHAR* item2, int column); 98 | 99 | 100 | /* DataGrid column definition structure */ 101 | typedef struct _DG_COLUMN 102 | { 103 | TCHAR columnText[1024]; 104 | int columnWidth; 105 | int textAlign; 106 | bool pressed; 107 | 108 | } DG_COLUMN; 109 | 110 | 111 | /* DataGrid row definition structure */ 112 | typedef struct _DG_ROW 113 | { 114 | TCHAR** rowText; 115 | int* textAlign; 116 | bool selected; 117 | bool mounted; 118 | bool* readOnly; 119 | COLORREF bgColor; 120 | LPARAM lParam;//SetTtemData 121 | } DG_ROW; 122 | 123 | 124 | /* DataGrid enumerations */ 125 | enum DG_MASK { DG_TEXTEDIT, DG_TEXTALIGN, DG_TEXTHIGHLIGHT, DG_TEXTRONLY, DG_TEXTBGCOLOR, DG_ITEMDATA }; 126 | 127 | 128 | /* DataGrid item information structure */ 129 | typedef struct _DG_ITEMINFO 130 | { 131 | DG_MASK dgMask; 132 | int dgItem; 133 | int dgSubitem; 134 | TCHAR* dgText; 135 | int dgTextLen; 136 | int dgTextAlign; 137 | bool dgSelected; 138 | bool dgReadOnly; 139 | COLORREF dgBgColor; 140 | LPARAM lParam;//used by SetTtemData 141 | } DG_ITEMINFO; 142 | 143 | 144 | /* DataGrid definition */ 145 | typedef struct _DG_LIST 146 | { 147 | HWND dg_hWnd; 148 | HWND dg_hParent; 149 | DG_COLUMN* dg_Columns; 150 | DG_ROW* dg_Rows; 151 | int dg_ColumnNumber; 152 | int dg_RowNumber; 153 | int dg_RowPreAllocNumber;//one time allocate more rows, to avoid realloc 154 | int dg_Column; 155 | int dg_Row; 156 | int dg_SelectedColumn; 157 | int dg_SelectedRow; 158 | DG_ROW* dg_Selected; 159 | BOOL dg_Cursor; 160 | BOOL dg_Resize; 161 | BOOL dg_Click; 162 | HFONT dg_hColumnFont; 163 | HFONT dg_hRowFont; 164 | LOGFONT dg_LFColumnFont; 165 | LOGFONT dg_LFRowFont; 166 | HBRUSH dg_hBgBrush; 167 | HPEN dg_hCellPen; 168 | HBITMAP dg_hMemBitmap; 169 | HDC dg_hMemDC; 170 | HBITMAP dg_hOldMemBitmap; 171 | HWND dg_hEditWnd; 172 | RECT dg_EditRect; 173 | BOOL dg_Edit; 174 | BOOL dg_EnableEdit; 175 | BOOL dg_EnableSort; 176 | BOOL dg_EnableResize; 177 | BOOL dg_EnableGrid; 178 | DGCOMPARE dg_CompareFunc; 179 | COLORREF dg_ColumnTextColor; 180 | COLORREF dg_RowTextColor; 181 | struct _DG_LIST* next; 182 | } DG_LIST; 183 | 184 | 185 | /* DataGrid global procedures */ 186 | LRESULT CALLBACK DataGridProc(HWND, UINT, WPARAM, LPARAM); 187 | void DrawColumns(HWND hWnd); 188 | void DrawRows(HWND hWnd); 189 | BOOL CheckColumnResize(HWND hWnd, int x, int y, int* col, RECT* colRect); 190 | BOOL CheckColumnClick(HWND hWnd, int x, int y, int* col); 191 | BOOL CheckRows(HWND hWnd, int x, int y, int* row); 192 | void GetColumnRect(HWND hWnd, int col, RECT* colRect); 193 | void GetRowRect(HWND hWnd, int row, RECT* rowRect); 194 | void RecalcWindow(HWND hWnd); 195 | void SortDGItems(HWND hWnd, int column); 196 | void Sort(HWND hWnd, int col, int size); 197 | void SetDGSelection(HWND hWnd, int rowIndex, int columnIndex); 198 | void SelectNextItem(HWND hWnd, DG_ROW* item); 199 | void SelectPreviousItem(HWND hWnd, DG_ROW* item); 200 | void SelectNextSubitem(HWND hWnd); 201 | void SelectPreviousSubitem(HWND hWnd); 202 | void EnsureRowVisible(HWND hWnd, int rowIndex); 203 | void EnsureColumnVisible(HWND hWnd, int columnIndex); 204 | void EnsureVisible(HWND hWnd, int rowIndex, int colIndex); 205 | void GetCellRect(HWND hWnd, RECT* cellRect); 206 | BOOL GetDGItemText(HWND hWnd, int rowIndex, int columnIndex, TCHAR* buffer, int buffer_size); 207 | BOOL SetDGItemText(HWND hWnd, int rowIndex, int columnIndex, TCHAR* buffer); 208 | void InitDGGlobals(HWND hParent, HWND hWnd); 209 | BOOL AddDGGrid(HWND hWnd, HWND hParent); 210 | void DestroyDGGrid(HWND hWnd); 211 | DG_LIST* GetDGGrid(HWND hWnd); 212 | DG_LIST* DetachDGGrid(HWND hWnd); 213 | void SiftDown(HWND hWnd, int root, int bottom, int col); 214 | void OnEdited(HWND hwnd);//Cancel Edit Status 215 | void OnUnEdited(HWND hwnd);//On Edit Status 216 | 217 | 218 | class CDataGrid 219 | { 220 | private: 221 | /* DataGrid members */ 222 | HWND m_hWnd; 223 | HWND m_hParentWnd; 224 | HWND m_hEditWnd; 225 | RECT m_DGRect; 226 | 227 | public: 228 | /* Basic DataGrid methods */ 229 | CDataGrid(); 230 | virtual ~CDataGrid(); 231 | BOOL Create(RECT wndRect, HWND hParent, int numCols); 232 | void Resize(); 233 | void Update(); 234 | HWND GetWindowHandle(); 235 | HWND GetSafeHwnd() { return m_hWnd; }; 236 | 237 | HWND GetEditSafeHwnd() { return m_hEditWnd; }; 238 | /* General DataGrid methods */ 239 | BOOL InsertItem(TCHAR* itemText, int textAlign); 240 | BOOL InsertItem(TCHAR* itemText, int textAlign, bool readOnly);//added by jjwang 241 | void MoveNext() 242 | { 243 | // Select next item 244 | DG_LIST* dgList = GetDGGrid(m_hWnd); 245 | SelectNextItem(m_hWnd, dgList->dg_Selected); 246 | EnsureVisible(dgList->dg_SelectedRow, dgList->dg_SelectedColumn); 247 | }; 248 | BOOL RemoveItem(int row); 249 | void RemoveAllItems(); 250 | void EnableSort(BOOL enable); 251 | void EnableEdit(BOOL enable); 252 | void EnableResize(BOOL enable); 253 | void EnableGrid(BOOL enable); 254 | void EnsureVisible(int row, int column); 255 | void SelectItem(int row, int column); 256 | int GetResizedColumn(); 257 | int GetRowNumber(); 258 | int GetSelectedRow(); 259 | int GetSelectedColumn(); 260 | void ResetSelection(); 261 | void SetRowMount(DWORD deviceId, BOOL value); 262 | void SetCompareFunction(DGCOMPARE CompareFunction); 263 | 264 | /* DataGrid SET attribute methods */ 265 | BOOL SetColumnInfo(int columnIndex, TCHAR* columnText, int columnWidth, int textAlign); 266 | void SetColumnTxtColor(COLORREF txtColor); 267 | void SetColumnFont(LOGFONT* lf); 268 | BOOL SetItemInfo(int rowIndex, int columnIndex, TCHAR* itemText, int textAlign, bool readOnly); 269 | BOOL SetItemInfo(int rowIndex, int columnIndex, TCHAR* itemText, int textAlign, bool readOnly, LPARAM lParam); 270 | BOOL SetItemInfo(DG_ITEMINFO* itemInfo); 271 | void SetItemBgColor(int rowIndex, COLORREF bgColor); 272 | void SetRowFont(LOGFONT* lf); 273 | void SetRowTxtColor(COLORREF txtColor); 274 | void SetItemData(int rowIndex, LPARAM lParam); 275 | 276 | /* DataGrid GET attribute methods */ 277 | COLORREF GetColumnTxtColor(); 278 | void GetColumnFont(LOGFONT* lf); 279 | void GetItemInfo(DG_ITEMINFO* itemInfo); 280 | BOOL GetItemText(int rowIndex, int columnIndex, TCHAR* buffer, int buffer_size); 281 | void GetRowFont(LOGFONT* lf); 282 | COLORREF GetRowTxtColor(); 283 | LPARAM GetItemData(int rowIndex);//GetItemInfo can get value 284 | BOOL ResetGridColumns(int numNewCols); 285 | BOOL ResetContent(); 286 | BOOL SubEditProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);//Edit Ctl 287 | }; 288 | #endif //_DATAGRID_H_ -------------------------------------------------------------------------------- /GpuRamDrive/Config.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Config.h" 3 | #include "GpuRamDrive.h" 4 | 5 | Config::Config(LPCTSTR keyName) 6 | { 7 | currentDeviceId = 0; 8 | version = 100; 9 | this->pszKeyName = new TCHAR[_tcslen(L"Software\\") + _tcslen(keyName) + 1]; 10 | _tcscpy(this->pszKeyName, L"Software\\"); 11 | _tcscat(this->pszKeyName, keyName); 12 | #if GPU_API == GPU_API_CUDA 13 | _tcscat(this->pszKeyName, L"_CUDA"); 14 | #endif 15 | checkVersion(); 16 | } 17 | 18 | Config::~Config() 19 | { 20 | } 21 | 22 | void Config::checkVersion() 23 | { 24 | DWORD configVersion = 0; 25 | getValue(L"Version", configVersion); 26 | if (configVersion == 0) { 27 | migrateVersion100(); 28 | } 29 | } 30 | 31 | const std::vector& Config::getDeviceList() 32 | { 33 | vectorDevices.clear(); 34 | for (int c = 0; c <= 'Z' - 'A'; c++) 35 | { 36 | if (existValue(c, L"DriveLetter")) 37 | vectorDevices.push_back(c); 38 | } 39 | return vectorDevices; 40 | } 41 | 42 | BOOL Config::existDevice(DWORD deviceId) 43 | { 44 | return existValue(deviceId, L"DriveLetter"); 45 | } 46 | 47 | DWORD Config::getDeviceTempFolfer() 48 | { 49 | auto v = getDeviceList(); 50 | for (int i = 0; i < v.size(); i++) 51 | { 52 | if (getTempFolder(v.at(i))) 53 | return v.at(i); 54 | } 55 | return -1; 56 | } 57 | 58 | void Config::saveOriginalTempEnvironment() 59 | { 60 | if (!existValue(L"OriginalTemp") || !existValue(L"OriginalTmp")) { 61 | wchar_t tempEnvironmentVariable[1024] = { 0 }; 62 | wchar_t tmpEnvironmentVariable[1024] = { 0 }; 63 | DWORD dwSize = obKey.GetSizeOfValue(_T("Environment"), L"TEMP", HKEY_CURRENT_USER); 64 | DWORD iTotalLength = dwSize + 1; 65 | memset(tempEnvironmentVariable, 0, iTotalLength); 66 | memset(tmpEnvironmentVariable, 0, iTotalLength); 67 | obKey.GetKeyValue(_T("Environment"), L"TEMP", tempEnvironmentVariable, iTotalLength); 68 | obKey.GetKeyValue(_T("Environment"), L"TMP", tmpEnvironmentVariable, iTotalLength); 69 | 70 | setValue(L"OriginalTemp", tempEnvironmentVariable); 71 | setValue(L"OriginalTmp", tmpEnvironmentVariable); 72 | } 73 | } 74 | 75 | void Config::setMountTempEnvironment(LPCTSTR pszValue) 76 | { 77 | obKey.SetKeyValue(L"Environment", L"TEMP", pszValue, (DWORD)wcslen(pszValue) * 2, true, false, HKEY_CURRENT_USER); 78 | obKey.SetKeyValue(L"Environment", L"TMP", pszValue, (DWORD)wcslen(pszValue) * 2, true, false, HKEY_CURRENT_USER); 79 | } 80 | 81 | void Config::restoreOriginalTempEnvironment() 82 | { 83 | wchar_t zsTemp[1024] = { 0 }; 84 | if (getValue(L"OriginalTemp", zsTemp)) { 85 | obKey.SetKeyValue(L"Environment", L"TEMP", zsTemp, (DWORD)wcslen(zsTemp) * sizeof(wchar_t), true, false, HKEY_CURRENT_USER); 86 | } 87 | 88 | if (getValue(L"OriginalTmp", zsTemp)) { 89 | obKey.SetKeyValue(L"Environment", L"TMP", zsTemp, (DWORD)wcslen(zsTemp) * sizeof(wchar_t), true, false, HKEY_CURRENT_USER); 90 | } 91 | } 92 | 93 | DWORD Config::getCurrentDeviceId() 94 | { 95 | return currentDeviceId; 96 | } 97 | 98 | void Config::setCurrentDeviceId(DWORD pszValue) 99 | { 100 | currentDeviceId = pszValue; 101 | } 102 | 103 | DWORD Config::getGpuId() 104 | { 105 | return getGpuId(currentDeviceId); 106 | } 107 | 108 | DWORD Config::getGpuId(DWORD deviceId) 109 | { 110 | DWORD pszValue = 0; 111 | getValue(deviceId, L"GpuId", pszValue); 112 | return pszValue; 113 | } 114 | 115 | void Config::setGpuId(DWORD pszValue) 116 | { 117 | setValue(currentDeviceId, L"GpuId", pszValue); 118 | } 119 | 120 | DWORD Config::getDriveLetter() 121 | { 122 | return getDriveLetter(currentDeviceId); 123 | } 124 | 125 | DWORD Config::getDriveLetter(DWORD deviceId) 126 | { 127 | DWORD pszValue = deviceId; 128 | getValue(deviceId, L"DriveLetter", pszValue); 129 | return pszValue; 130 | } 131 | 132 | void Config::setDriveLetter(DWORD pszValue) 133 | { 134 | setValue(currentDeviceId, L"DriveLetter", pszValue); 135 | } 136 | 137 | DWORD Config::getDriveType() 138 | { 139 | DWORD pszValue = 0; 140 | getValue(currentDeviceId, L"DriveType", pszValue); 141 | return pszValue; 142 | } 143 | 144 | void Config::setDriveType(DWORD pszValue) 145 | { 146 | setValue(currentDeviceId, L"DriveType", pszValue); 147 | } 148 | 149 | DWORD Config::getDriveRemovable() 150 | { 151 | DWORD pszValue = 0; 152 | getValue(currentDeviceId, L"DriveRemovable", pszValue); 153 | return pszValue; 154 | } 155 | 156 | void Config::setDriveRemovable(DWORD pszValue) 157 | { 158 | setValue(currentDeviceId, L"DriveRemovable", pszValue); 159 | } 160 | 161 | DWORD Config::getDriveFormat() 162 | { 163 | DWORD pszValue = 1; 164 | getValue(currentDeviceId, L"DriveFormat", pszValue); 165 | return pszValue; 166 | } 167 | 168 | void Config::setDriveFormat(DWORD pszValue) 169 | { 170 | setValue(currentDeviceId, L"DriveFormat", pszValue); 171 | } 172 | 173 | DWORD Config::getMemSize() 174 | { 175 | DWORD pszValue = 0; 176 | getValue(currentDeviceId, L"MemSize", pszValue); 177 | return pszValue; 178 | } 179 | 180 | void Config::setMemSize(DWORD pszValue) 181 | { 182 | setValue(currentDeviceId, L"MemSize", pszValue); 183 | } 184 | 185 | void Config::getDriveLabel(LPTSTR pszValue) 186 | { 187 | if (!getValue(currentDeviceId, L"DriveLabel", pszValue)) 188 | { 189 | _tcscpy(pszValue, L"GpuDisk"); 190 | } 191 | } 192 | 193 | void Config::setDriveLabel(LPCTSTR pszValue) 194 | { 195 | setValue(currentDeviceId, L"DriveLabel", pszValue); 196 | } 197 | 198 | void Config::getImageFile(LPTSTR pszValue) 199 | { 200 | if (!getValue(currentDeviceId, L"ImageFile", pszValue)) 201 | { 202 | _tcscpy(pszValue, L""); 203 | } 204 | } 205 | 206 | void Config::setImageFile(LPCTSTR pszValue) 207 | { 208 | setValue(currentDeviceId, L"ImageFile", pszValue); 209 | } 210 | 211 | DWORD Config::getReadOnly() 212 | { 213 | return getReadOnly(currentDeviceId); 214 | } 215 | 216 | DWORD Config::getReadOnly(DWORD deviceId) 217 | { 218 | DWORD pszValue = 0; 219 | getValue(deviceId, L"ReadOnly", pszValue); 220 | return pszValue; 221 | } 222 | 223 | void Config::setReadOnly(DWORD pszValue) 224 | { 225 | setValue(currentDeviceId, L"ReadOnly", pszValue); 226 | } 227 | 228 | DWORD Config::getTempFolder() 229 | { 230 | DWORD pszValue = 0; 231 | getValue(currentDeviceId, L"TempFolder", pszValue); 232 | return pszValue; 233 | } 234 | 235 | DWORD Config::getTempFolder(DWORD deviceId) 236 | { 237 | DWORD pszValue = 0; 238 | getValue(deviceId, L"TempFolder", pszValue); 239 | return pszValue; 240 | } 241 | 242 | void Config::setTempFolder(DWORD pszValue) 243 | { 244 | setValue(currentDeviceId, L"TempFolder", pszValue); 245 | } 246 | 247 | DWORD Config::getStartOnWindows() 248 | { 249 | return getStartOnWindows(currentDeviceId); 250 | } 251 | 252 | DWORD Config::getStartOnWindows(DWORD deviceId) 253 | { 254 | DWORD pszValue = 0; 255 | getValue(deviceId, L"StartOnWindows", pszValue); 256 | return pszValue; 257 | } 258 | 259 | void Config::setStartOnWindows(DWORD pszValue) 260 | { 261 | setValue(currentDeviceId, L"StartOnWindows", pszValue); 262 | } 263 | 264 | bool Config::getValue(LPCTSTR pszValueName, LPTSTR pszValue) 265 | { 266 | DWORD dwSize = obKey.GetSizeOfValue(this->pszKeyName, pszValueName, HKEY_CURRENT_USER); 267 | if (dwSize != 0) { 268 | DWORD iTotalLength = dwSize + 1; 269 | memset(pszValue, 0, iTotalLength); 270 | return obKey.GetKeyValue(this->pszKeyName, pszValueName, pszValue, iTotalLength); 271 | } 272 | 273 | return false; 274 | } 275 | 276 | bool Config::getValue(DWORD gpu, LPCTSTR pszValueName, LPTSTR pszValue) 277 | { 278 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 279 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, gpu); 280 | 281 | DWORD dwSize = obKey.GetSizeOfValue(keyName, pszValueName, HKEY_CURRENT_USER); 282 | if (dwSize != 0) { 283 | DWORD iTotalLength = dwSize + 1; 284 | memset(pszValue, 0, iTotalLength); 285 | return obKey.GetKeyValue(keyName, pszValueName, pszValue, iTotalLength); 286 | } 287 | 288 | return false; 289 | } 290 | 291 | bool Config::getValue(LPCTSTR pszValueName, DWORD& dwValue) 292 | { 293 | DWORD dwSize = obKey.GetSizeOfValue(this->pszKeyName, pszValueName, HKEY_CURRENT_USER); 294 | if (dwSize != 0) { 295 | return obKey.GetKeyValue(this->pszKeyName, pszValueName, dwValue); 296 | } 297 | 298 | return false; 299 | } 300 | 301 | bool Config::getValue(DWORD gpu, LPCTSTR pszValueName, DWORD& dwValue) 302 | { 303 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 304 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, gpu); 305 | 306 | DWORD dwSize = obKey.GetSizeOfValue(keyName, pszValueName, HKEY_CURRENT_USER); 307 | if (dwSize != 0) { 308 | return obKey.GetKeyValue(keyName, pszValueName, dwValue); 309 | } 310 | 311 | return false; 312 | } 313 | 314 | bool Config::setValue(LPCTSTR pszValueName, LPCTSTR pszValue) 315 | { 316 | return obKey.SetKeyValue(this->pszKeyName, pszValueName, pszValue, (DWORD)wcslen(pszValue) * sizeof(LPCTSTR), true, false, HKEY_CURRENT_USER); 317 | } 318 | 319 | bool Config::setValue(DWORD gpu, LPCTSTR pszValueName, LPCTSTR pszValue) 320 | { 321 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 322 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, gpu); 323 | 324 | return obKey.SetKeyValue(keyName, pszValueName, pszValue, (DWORD)wcslen(pszValue) * sizeof(LPCTSTR), true, false, HKEY_CURRENT_USER); 325 | } 326 | 327 | bool Config::setValue(LPCTSTR pszValueName, DWORD pszValue) 328 | { 329 | return obKey.SetKeyValue(this->pszKeyName, pszValueName, pszValue, true, false, HKEY_CURRENT_USER); 330 | } 331 | 332 | bool Config::setValue(DWORD gpu, LPCTSTR pszValueName, DWORD pszValue) 333 | { 334 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 335 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, gpu); 336 | 337 | return obKey.SetKeyValue(keyName, pszValueName, pszValue, true, false, HKEY_CURRENT_USER); 338 | } 339 | 340 | bool Config::existValue(LPCTSTR pszValueName) 341 | { 342 | return obKey.GetSizeOfValue(pszKeyName, pszValueName, HKEY_CURRENT_USER) > 0; 343 | } 344 | 345 | bool Config::existValue(DWORD deviceId, LPCTSTR pszValueName) 346 | { 347 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 348 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, deviceId); 349 | 350 | return obKey.GetSizeOfValue(keyName, pszValueName, HKEY_CURRENT_USER) > 0; 351 | } 352 | 353 | bool Config::deleteDevice(DWORD deviceId) 354 | { 355 | LPTSTR keyName = new TCHAR[_tcslen(this->pszKeyName) + _tcslen(this->pszKeyName) + 3 + 1]; 356 | _stprintf(keyName, _T("%s\\%d"), this->pszKeyName, deviceId); 357 | 358 | return obKey.QuickDeleteKey(keyName, HKEY_CURRENT_USER); 359 | } 360 | 361 | bool Config::deleteValue(LPCTSTR pszValueName) 362 | { 363 | return obKey.DeleteKeyValue(this->pszKeyName, pszValueName, HKEY_CURRENT_USER); 364 | } 365 | 366 | void Config::migrateVersion100() 367 | { 368 | deleteValue(L"DefaultGpu"); 369 | deleteDevice(0); 370 | deleteDevice(1); 371 | deleteDevice(2); 372 | deleteDevice(3); 373 | deleteDevice(4); 374 | deleteDevice(5); 375 | deleteDevice(6); 376 | deleteDevice(7); 377 | deleteDevice(8); 378 | deleteDevice(9); 379 | setValue(L"Version", version); 380 | } 381 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/imdisk/ntkmapi.h: -------------------------------------------------------------------------------- 1 | #ifndef VER_PRODUCTBUILD 2 | #include 3 | #endif 4 | 5 | /// 6 | /// Some additional native kernel-mode API functions we use 7 | /// 8 | 9 | // 10 | // Ensures that we build a pre Win 2000 compatible x86 sys file 11 | // (without ExFreePoolWithTag()). // Olof Lagerkvist 12 | // 13 | #ifndef _WIN64 14 | #ifdef ExFreePool 15 | #undef ExFreePool 16 | #endif 17 | #ifdef ExFreePoolWithTag 18 | #undef ExFreePoolWithTag 19 | #endif 20 | #define ExFreePoolWithTag(b, t) ExFreePool(b) 21 | #endif 22 | 23 | #pragma warning(disable: 4996) 24 | 25 | // 26 | // We include some stuff from newer DDK:s here so that one 27 | // version of the driver for all versions of Windows can 28 | // be compiled with the Windows 2000 DDK. 29 | // 30 | #if (VER_PRODUCTBUILD < 2195) 31 | 32 | #define IOCTL_DISK_GET_PARTITION_INFO_EX CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS) 33 | #define IOCTL_DISK_GET_LENGTH_INFO CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS) 34 | #define IOCTL_DISK_GET_PARTITION_INFO_EX CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS) 35 | #define IOCTL_DISK_SET_PARTITION_INFO_EX CTL_CODE(IOCTL_DISK_BASE, 0x0013, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS) 36 | 37 | typedef enum _PARTITION_STYLE 38 | { 39 | PARTITION_STYLE_MBR, 40 | PARTITION_STYLE_GPT 41 | } PARTITION_STYLE; 42 | 43 | typedef unsigned __int64 ULONG64, *PULONG64; 44 | 45 | typedef struct _PARTITION_INFORMATION_MBR 46 | { 47 | UCHAR PartitionType; 48 | BOOLEAN BootIndicator; 49 | BOOLEAN RecognizedPartition; 50 | ULONG HiddenSectors; 51 | } PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR; 52 | 53 | typedef struct _PARTITION_INFORMATION_GPT 54 | { 55 | GUID PartitionType; 56 | GUID PartitionId; 57 | ULONG64 Attributes; 58 | WCHAR Name[36]; 59 | } PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT; 60 | 61 | typedef struct _PARTITION_INFORMATION_EX 62 | { 63 | PARTITION_STYLE PartitionStyle; 64 | LARGE_INTEGER StartingOffset; 65 | LARGE_INTEGER PartitionLength; 66 | ULONG PartitionNumber; 67 | BOOLEAN RewritePartition; 68 | union 69 | { 70 | PARTITION_INFORMATION_MBR Mbr; 71 | PARTITION_INFORMATION_GPT Gpt; 72 | }; 73 | } PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX; 74 | 75 | typedef struct _GET_LENGTH_INFORMATION 76 | { 77 | LARGE_INTEGER Length; 78 | } GET_LENGTH_INFORMATION, *PGET_LENGTH_INFORMATION; 79 | 80 | typedef SET_PARTITION_INFORMATION SET_PARTITION_INFORMATION_MBR; 81 | typedef PARTITION_INFORMATION_GPT SET_PARTITION_INFORMATION_GPT; 82 | 83 | typedef struct _SET_PARTITION_INFORMATION_EX { 84 | PARTITION_STYLE PartitionStyle; 85 | union { 86 | SET_PARTITION_INFORMATION_MBR Mbr; 87 | SET_PARTITION_INFORMATION_GPT Gpt; 88 | }; 89 | } SET_PARTITION_INFORMATION_EX, *PSET_PARTITION_INFORMATION_EX; 90 | 91 | #endif // (VER_PRODUCTBUILD < 2600) 92 | 93 | #if (VER_PRODUCTBUILD < 3790) 94 | 95 | #define IOCTL_STORAGE_GET_HOTPLUG_INFO CTL_CODE(IOCTL_STORAGE_BASE, 0x0305, METHOD_BUFFERED, FILE_ANY_ACCESS) 96 | 97 | // 98 | // IOCTL_STORAGE_GET_HOTPLUG_INFO 99 | // 100 | 101 | typedef struct _STORAGE_HOTPLUG_INFO { 102 | ULONG Size; 103 | BOOLEAN MediaRemovable; 104 | BOOLEAN MediaHotplug; 105 | BOOLEAN DeviceHotplug; 106 | BOOLEAN WriteCacheEnableOverride; 107 | } STORAGE_HOTPLUG_INFO, *PSTORAGE_HOTPLUG_INFO; 108 | 109 | #endif // (VER_PRODUCTBUILD < 3790) 110 | 111 | NTSYSAPI 112 | NTSTATUS 113 | NTAPI 114 | ZwPulseEvent(IN HANDLE EventHandle, 115 | OUT PLONG PreviousState OPTIONAL); 116 | 117 | // 118 | // We include some stuff from ntifs.h here so that 119 | // the driver can be compiled with only the Win2K DDK. 120 | // 121 | #ifndef _NTIFS_INCLUDED_ 122 | 123 | NTSYSAPI 124 | NTSTATUS 125 | NTAPI 126 | ZwSetEvent(IN HANDLE EventHandle, 127 | OUT PLONG PreviousState OPTIONAL); 128 | 129 | NTSYSAPI 130 | NTSTATUS 131 | NTAPI 132 | ZwWaitForSingleObject(IN HANDLE Handle, 133 | IN BOOLEAN Alertable, 134 | IN PLARGE_INTEGER Timeout OPTIONAL); 135 | 136 | NTSYSAPI 137 | NTSTATUS 138 | NTAPI 139 | ZwAllocateVirtualMemory(IN HANDLE ProcessHandle, 140 | IN OUT PVOID *BaseAddress, 141 | IN ULONG_PTR ZeroBits, 142 | IN OUT PSIZE_T RegionSize, 143 | IN ULONG AllocationType, 144 | IN ULONG Protect); 145 | 146 | NTSYSAPI 147 | NTSTATUS 148 | NTAPI 149 | ZwFreeVirtualMemory(IN HANDLE ProcessHandle, 150 | IN PVOID *BaseAddress, 151 | IN OUT PSIZE_T RegionSize, 152 | IN ULONG FreeType); 153 | 154 | NTSYSAPI 155 | NTSTATUS 156 | NTAPI 157 | ZwFsControlFile( 158 | __in HANDLE FileHandle, 159 | __in_opt HANDLE Event, 160 | __in_opt PIO_APC_ROUTINE ApcRoutine, 161 | __in_opt PVOID ApcContext, 162 | __out PIO_STATUS_BLOCK IoStatusBlock, 163 | __in ULONG FsControlCode, 164 | __in_bcount_opt(InputBufferLength) PVOID InputBuffer, 165 | __in ULONG InputBufferLength, 166 | __out_bcount_opt(OutputBufferLength) PVOID OutputBuffer, 167 | __in ULONG OutputBufferLength 168 | ); 169 | 170 | #define FSCTL_SET_SPARSE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 49, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) 171 | 172 | typedef enum _TOKEN_TYPE { 173 | TokenPrimary = 1, 174 | TokenImpersonation 175 | } TOKEN_TYPE; 176 | typedef TOKEN_TYPE *PTOKEN_TYPE; 177 | 178 | #define TOKEN_SOURCE_LENGTH 8 179 | 180 | typedef struct _TOKEN_SOURCE { 181 | CHAR SourceName[TOKEN_SOURCE_LENGTH]; 182 | LUID SourceIdentifier; 183 | } TOKEN_SOURCE, *PTOKEN_SOURCE; 184 | 185 | typedef struct _TOKEN_CONTROL 186 | { 187 | LUID TokenId; 188 | LUID AuthenticationId; 189 | LUID ModifiedId; 190 | TOKEN_SOURCE TokenSource; 191 | } TOKEN_CONTROL, *PTOKEN_CONTROL; 192 | 193 | typedef struct _SECURITY_CLIENT_CONTEXT 194 | { 195 | SECURITY_QUALITY_OF_SERVICE SecurityQos; 196 | PACCESS_TOKEN ClientToken; 197 | BOOLEAN DirectlyAccessClientToken; 198 | BOOLEAN DirectAccessEffectiveOnly; 199 | BOOLEAN ServerIsRemote; 200 | TOKEN_CONTROL ClientTokenControl; 201 | } SECURITY_CLIENT_CONTEXT, *PSECURITY_CLIENT_CONTEXT; 202 | 203 | NTKERNELAPI 204 | NTSTATUS 205 | SeCreateClientSecurity(IN PETHREAD Thread, 206 | IN PSECURITY_QUALITY_OF_SERVICE QualityOfService, 207 | IN BOOLEAN RemoteClient, 208 | OUT PSECURITY_CLIENT_CONTEXT ClientContext); 209 | 210 | NTKERNELAPI 211 | VOID 212 | SeImpersonateClient(IN PSECURITY_CLIENT_CONTEXT ClientContext, 213 | IN PETHREAD ServerThread OPTIONAL); 214 | 215 | NTKERNELAPI 216 | TOKEN_TYPE 217 | SeTokenType(IN PACCESS_TOKEN Token); 218 | 219 | // PsRevertToSelf() removed for Windows NT 3.51 compatibility, Olof Lagerkvist. 220 | 221 | #define SeDeleteClientSecurity(C) \ 222 | ((SeTokenType((C)->ClientToken) == TokenPrimary) ? \ 223 | (PsDereferencePrimaryToken( (C)->ClientToken )) : \ 224 | (PsDereferenceImpersonationToken( (C)->ClientToken ))) 225 | 226 | #endif // _NTIFS_INCLUDED_ 227 | 228 | #define PsDereferenceImpersonationToken(T) \ 229 | ((ARGUMENT_PRESENT((T))) ? \ 230 | (ObDereferenceObject((T))) : 0) 231 | 232 | #define PsDereferencePrimaryToken(T) (ObDereferenceObject((T))) 233 | 234 | // 235 | // For backward compatibility with <= Windows NT 4.0 by Bruce Engle. 236 | // 237 | #ifndef _WIN64 238 | #ifdef MmGetSystemAddressForMdlSafe 239 | #undef MmGetSystemAddressForMdlSafe 240 | #endif 241 | #define MmGetSystemAddressForMdlSafe(MDL, PRIORITY) \ 242 | MmGetSystemAddressForMdlPrettySafe(MDL) 243 | 244 | __forceinline PVOID 245 | MmGetSystemAddressForMdlPrettySafe(PMDL Mdl) 246 | { 247 | CSHORT MdlMappingCanFail; 248 | PVOID MappedSystemVa; 249 | 250 | if (Mdl == NULL) 251 | return NULL; 252 | 253 | #pragma warning(suppress: 28145) 254 | if (Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL)) 255 | return Mdl->MappedSystemVa; 256 | 257 | #pragma warning(suppress: 28145) 258 | MdlMappingCanFail = Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL; 259 | 260 | #pragma warning(suppress: 28145) 261 | Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL; 262 | 263 | #pragma warning(suppress: 28159) 264 | MappedSystemVa = MmMapLockedPages(Mdl, KernelMode); 265 | 266 | if (MdlMappingCanFail == 0) 267 | { 268 | #pragma warning(suppress: 28145) 269 | Mdl->MdlFlags &= ~MDL_MAPPING_CAN_FAIL; 270 | } 271 | 272 | return MappedSystemVa; 273 | } 274 | #endif 275 | 276 | #ifndef IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES 277 | 278 | #define IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES CTL_CODE(IOCTL_STORAGE_BASE, 0x0501, METHOD_BUFFERED, FILE_WRITE_ACCESS) 279 | 280 | // 281 | // Defines the various actions 282 | // 283 | 284 | typedef ULONG DEVICE_DATA_MANAGEMENT_SET_ACTION; 285 | 286 | #define DeviceDsmAction_None 0 287 | #define DeviceDsmAction_Trim 1 288 | 289 | // 290 | // Structure used to describe the list of ranges to process 291 | // 292 | 293 | typedef struct _DEVICE_DATA_SET_RANGE { 294 | LONGLONG StartingOffset; //in bytes, must allign to sector 295 | ULONGLONG LengthInBytes; // multiple of sector size. 296 | } DEVICE_DATA_SET_RANGE, *PDEVICE_DATA_SET_RANGE; 297 | 298 | // 299 | // input structure for IOCTL_STORAGE_MANAGE_DATA_SET_ATTRIBUTES 300 | // 1. Value ofParameterBlockOffset or ParameterBlockLength is 0 indicates that Parameter Block does not exist. 301 | // 2. Value of DataSetRangesOffset or DataSetRangesLength is 0 indicates that DataSetRanges Block does not exist. 302 | // If DataSetRanges Block exists, it contains contiguous DEVICE_DATA_SET_RANGE structures. 303 | // 3. The total size of buffer should be at least: 304 | // sizeof (DEVICE_MANAGE_DATA_SET_ATTRIBUTES) + ParameterBlockLength + DataSetRangesLength 305 | // 306 | typedef struct _DEVICE_MANAGE_DATA_SET_ATTRIBUTES { 307 | ULONG Size; // Size of structure DEVICE_MANAGE_DATA_SET_ATTRIBUTES 308 | DEVICE_DATA_MANAGEMENT_SET_ACTION Action; 309 | 310 | ULONG Flags; // Global flags across all actions 311 | 312 | ULONG ParameterBlockOffset; // must be alligned to corresponding structure allignment 313 | ULONG ParameterBlockLength; // 0 means Parameter Block does not exist. 314 | 315 | ULONG DataSetRangesOffset; // must be alligned to DEVICE_DATA_SET_RANGE structure allignment. 316 | ULONG DataSetRangesLength; // 0 means DataSetRanges Block does not exist. 317 | 318 | } DEVICE_MANAGE_DATA_SET_ATTRIBUTES, *PDEVICE_MANAGE_DATA_SET_ATTRIBUTES; 319 | 320 | #endif 321 | 322 | #ifndef FSCTL_FILE_LEVEL_TRIM 323 | 324 | #define FSCTL_FILE_LEVEL_TRIM CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 130, METHOD_BUFFERED, FILE_WRITE_DATA) 325 | 326 | // 327 | //======================== FSCTL_FILE_LEVEL_TRIM =========================== 328 | // 329 | // Structure defintions for supporint file level trim 330 | // 331 | 332 | typedef struct _FILE_LEVEL_TRIM_RANGE { 333 | 334 | // 335 | // Bytes offset from the front of the given file to trim at 336 | // 337 | 338 | ULONGLONG Offset; 339 | 340 | // 341 | // Length in bytes to trim from the given offset 342 | // 343 | 344 | ULONGLONG Length; 345 | } FILE_LEVEL_TRIM_RANGE, *PFILE_LEVEL_TRIM_RANGE; 346 | 347 | // 348 | // Input buffer defining what ranges to trim 349 | // 350 | 351 | typedef struct _FILE_LEVEL_TRIM { 352 | 353 | // 354 | // Used when interacting with byte range locks. Set to zero if not SMB or 355 | // similar. 356 | // 357 | 358 | ULONG Key; 359 | 360 | // 361 | // A count of how many Offset:Length pairs are given 362 | // 363 | 364 | ULONG NumRanges; 365 | 366 | // 367 | // All the pairs. 368 | // 369 | 370 | FILE_LEVEL_TRIM_RANGE Ranges[1]; 371 | 372 | } FILE_LEVEL_TRIM, *PFILE_LEVEL_TRIM; 373 | 374 | // 375 | // This is an optional output buffer 376 | // 377 | 378 | typedef struct _FILE_LEVEL_TRIM_OUTPUT { 379 | 380 | // 381 | // Receives the number of input ranges 382 | // that were processed 383 | // 384 | 385 | ULONG NumRangesProcessed; 386 | 387 | } FILE_LEVEL_TRIM_OUTPUT, *PFILE_LEVEL_TRIM_OUTPUT; 388 | 389 | #endif 390 | 391 | #if (VER_PRODUCTBUILD < 7600) 392 | 393 | typedef VOID 394 | KSTART_ROUTINE(IN PVOID StartContext); 395 | 396 | #endif 397 | 398 | #ifndef __drv_maxIRQL 399 | #define __drv_maxIRQL(i) 400 | #endif 401 | #ifndef __drv_when 402 | #define __drv_when(c,a) 403 | #endif 404 | #ifndef __drv_savesIRQLGlobal 405 | #define __drv_savesIRQLGlobal(t,o) 406 | #endif 407 | #ifndef __drv_setsIRQL 408 | #define __drv_setsIRQL(i) 409 | #endif 410 | #ifndef __drv_acquiresExclusiveResource 411 | #define __drv_acquiresExclusiveResource(t) 412 | #endif 413 | #ifndef __drv_releasesExclusiveResource 414 | #define __drv_releasesExclusiveResource(t) 415 | #endif 416 | #ifndef __drv_requiresIRQL 417 | #define __drv_requiresIRQL(i) 418 | #endif 419 | #ifndef __drv_dispatchType 420 | #define __drv_dispatchType(f) 421 | #endif 422 | #ifndef _Dispatch_type_ 423 | #define _Dispatch_type_ __drv_dispatchType 424 | #endif 425 | -------------------------------------------------------------------------------- /GpuRamDrive/3rdparty/inc/CL/cl_ext.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2008-2013 The Khronos Group Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and/or associated documentation files (the 6 | * "Materials"), to deal in the Materials without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sublicense, and/or sell copies of the Materials, and to 9 | * permit persons to whom the Materials are furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included 13 | * in all copies or substantial portions of the Materials. 14 | * 15 | * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 19 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 21 | * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. 22 | ******************************************************************************/ 23 | 24 | /* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ 25 | 26 | /* cl_ext.h contains OpenCL extensions which don't have external */ 27 | /* (OpenGL, D3D) dependencies. */ 28 | 29 | #ifndef __CL_EXT_H 30 | #define __CL_EXT_H 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifdef __APPLE__ 37 | #include 38 | #include 39 | #else 40 | #include 41 | #endif 42 | 43 | /* cl_khr_fp16 extension - no extension #define since it has no functions */ 44 | #define CL_DEVICE_HALF_FP_CONFIG 0x1033 45 | 46 | /* Memory object destruction 47 | * 48 | * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR 49 | * 50 | * Registers a user callback function that will be called when the memory object is deleted and its resources 51 | * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback 52 | * stack associated with memobj. The registered user callback functions are called in the reverse order in 53 | * which they were registered. The user callback functions are called and then the memory object is deleted 54 | * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be 55 | * notified when the memory referenced by host_ptr, specified when the memory object is created and used as 56 | * the storage bits for the memory object, can be reused or freed. 57 | * 58 | * The application may not call CL api's with the cl_mem object passed to the pfn_notify. 59 | * 60 | * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) 61 | * before using. 62 | */ 63 | #define cl_APPLE_SetMemObjectDestructor 1 64 | cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, 65 | void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), 66 | void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 67 | 68 | 69 | /* Context Logging Functions 70 | * 71 | * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). 72 | * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) 73 | * before using. 74 | * 75 | * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger 76 | */ 77 | #define cl_APPLE_ContextLoggingFunctions 1 78 | extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, 79 | const void * /* private_info */, 80 | size_t /* cb */, 81 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 82 | 83 | /* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ 84 | extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, 85 | const void * /* private_info */, 86 | size_t /* cb */, 87 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 88 | 89 | /* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ 90 | extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, 91 | const void * /* private_info */, 92 | size_t /* cb */, 93 | void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; 94 | 95 | 96 | /************************ 97 | * cl_khr_icd extension * 98 | ************************/ 99 | #define cl_khr_icd 1 100 | 101 | /* cl_platform_info */ 102 | #define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 103 | 104 | /* Additional Error Codes */ 105 | #define CL_PLATFORM_NOT_FOUND_KHR -1001 106 | 107 | extern CL_API_ENTRY cl_int CL_API_CALL 108 | clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, 109 | cl_platform_id * /* platforms */, 110 | cl_uint * /* num_platforms */); 111 | 112 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( 113 | cl_uint /* num_entries */, 114 | cl_platform_id * /* platforms */, 115 | cl_uint * /* num_platforms */); 116 | 117 | 118 | /* Extension: cl_khr_image2D_buffer 119 | * 120 | * This extension allows a 2D image to be created from a cl_mem buffer without a copy. 121 | * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. 122 | * Both the sampler and sampler-less read_image built-in functions are supported for 2D images 123 | * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported 124 | * for 2D images created from a buffer. 125 | * 126 | * When the 2D image from buffer is created, the client must specify the width, 127 | * height, image format (i.e. channel order and channel data type) and optionally the row pitch 128 | * 129 | * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. 130 | * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. 131 | */ 132 | 133 | /************************************* 134 | * cl_khr_initalize_memory extension * 135 | *************************************/ 136 | 137 | #define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x200E 138 | 139 | 140 | /************************************** 141 | * cl_khr_terminate_context extension * 142 | **************************************/ 143 | 144 | #define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x200F 145 | #define CL_CONTEXT_TERMINATE_KHR 0x2010 146 | 147 | #define cl_khr_terminate_context 1 148 | extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; 149 | 150 | typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; 151 | 152 | 153 | /* 154 | * Extension: cl_khr_spir 155 | * 156 | * This extension adds support to create an OpenCL program object from a 157 | * Standard Portable Intermediate Representation (SPIR) instance 158 | */ 159 | 160 | #define CL_DEVICE_SPIR_VERSIONS 0x40E0 161 | #define CL_PROGRAM_BINARY_TYPE_INTERMEDIATE 0x40E1 162 | 163 | 164 | /****************************************** 165 | * cl_nv_device_attribute_query extension * 166 | ******************************************/ 167 | /* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ 168 | #define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 169 | #define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 170 | #define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 171 | #define CL_DEVICE_WARP_SIZE_NV 0x4003 172 | #define CL_DEVICE_GPU_OVERLAP_NV 0x4004 173 | #define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 174 | #define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 175 | #define CL_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT_NV 0x4007 176 | #define CL_DEVICE_PCI_BUS_ID_NV 0x4008 177 | #define CL_DEVICE_PCI_SLOT_ID_NV 0x4009 178 | 179 | 180 | /********************************* 181 | * cl_amd_device_attribute_query * 182 | *********************************/ 183 | #define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 184 | 185 | /********************************* 186 | * cl_arm_printf extension 187 | *********************************/ 188 | #define CL_PRINTF_CALLBACK_ARM 0x40B0 189 | #define CL_PRINTF_BUFFERSIZE_ARM 0x40B1 190 | 191 | #ifdef CL_VERSION_1_1 192 | /*********************************** 193 | * cl_ext_device_fission extension * 194 | ***********************************/ 195 | #define cl_ext_device_fission 1 196 | 197 | extern CL_API_ENTRY cl_int CL_API_CALL 198 | clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 199 | 200 | typedef CL_API_ENTRY cl_int 201 | (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 202 | 203 | extern CL_API_ENTRY cl_int CL_API_CALL 204 | clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 205 | 206 | typedef CL_API_ENTRY cl_int 207 | (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; 208 | 209 | typedef cl_ulong cl_device_partition_property_ext; 210 | extern CL_API_ENTRY cl_int CL_API_CALL 211 | clCreateSubDevicesEXT( cl_device_id /*in_device*/, 212 | const cl_device_partition_property_ext * /* properties */, 213 | cl_uint /*num_entries*/, 214 | cl_device_id * /*out_devices*/, 215 | cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; 216 | 217 | typedef CL_API_ENTRY cl_int 218 | ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, 219 | const cl_device_partition_property_ext * /* properties */, 220 | cl_uint /*num_entries*/, 221 | cl_device_id * /*out_devices*/, 222 | cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; 223 | 224 | /* cl_device_partition_property_ext */ 225 | #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 226 | #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 227 | #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 228 | #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 229 | 230 | /* clDeviceGetInfo selectors */ 231 | #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 232 | #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 233 | #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 234 | #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 235 | #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 236 | 237 | /* error codes */ 238 | #define CL_DEVICE_PARTITION_FAILED_EXT -1057 239 | #define CL_INVALID_PARTITION_COUNT_EXT -1058 240 | #define CL_INVALID_PARTITION_NAME_EXT -1059 241 | 242 | /* CL_AFFINITY_DOMAINs */ 243 | #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 244 | #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 245 | #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 246 | #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 247 | #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 248 | #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 249 | 250 | /* cl_device_partition_property_ext list terminators */ 251 | #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) 252 | #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) 253 | #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) 254 | 255 | /********************************* 256 | * cl_qcom_ext_host_ptr extension 257 | *********************************/ 258 | 259 | #define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) 260 | 261 | #define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 262 | #define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 263 | #define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 264 | #define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 265 | #define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 266 | #define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 267 | #define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 268 | #define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 269 | 270 | typedef cl_uint cl_image_pitch_info_qcom; 271 | 272 | extern CL_API_ENTRY cl_int CL_API_CALL 273 | clGetDeviceImageInfoQCOM(cl_device_id device, 274 | size_t image_width, 275 | size_t image_height, 276 | const cl_image_format *image_format, 277 | cl_image_pitch_info_qcom param_name, 278 | size_t param_value_size, 279 | void *param_value, 280 | size_t *param_value_size_ret); 281 | 282 | typedef struct _cl_mem_ext_host_ptr 283 | { 284 | /* Type of external memory allocation. */ 285 | /* Legal values will be defined in layered extensions. */ 286 | cl_uint allocation_type; 287 | 288 | /* Host cache policy for this external memory allocation. */ 289 | cl_uint host_cache_policy; 290 | 291 | } cl_mem_ext_host_ptr; 292 | 293 | /********************************* 294 | * cl_qcom_ion_host_ptr extension 295 | *********************************/ 296 | 297 | #define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 298 | 299 | typedef struct _cl_mem_ion_host_ptr 300 | { 301 | /* Type of external memory allocation. */ 302 | /* Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. */ 303 | cl_mem_ext_host_ptr ext_host_ptr; 304 | 305 | /* ION file descriptor */ 306 | int ion_filedesc; 307 | 308 | /* Host pointer to the ION allocated memory */ 309 | void* ion_hostptr; 310 | 311 | } cl_mem_ion_host_ptr; 312 | 313 | #endif /* CL_VERSION_1_1 */ 314 | 315 | #ifdef __cplusplus 316 | } 317 | #endif 318 | 319 | 320 | #endif /* __CL_EXT_H */ 321 | -------------------------------------------------------------------------------- /GpuRamDrive/DiskUtil.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "stdafx.h" 4 | #include "DiskUtil.h" 5 | 6 | #define dump_buffersize_megs 16 7 | #define dump_buffersize (dump_buffersize_megs * 1024 * 1024) 8 | #define dump_workingsetsize ((dump_buffersize_megs + 1) * 1024 * 1024) 9 | 10 | DiskUtil::DiskUtil() 11 | : buffer(NULL) 12 | ,hinput(NULL) 13 | ,houtput(NULL) 14 | { 15 | } 16 | 17 | DiskUtil::~DiskUtil() 18 | { 19 | } 20 | 21 | BOOL DiskUtil::checkDriveIsMounted(char letter, wchar_t* type) 22 | { 23 | wchar_t szTemp[64]; 24 | _snwprintf_s(szTemp, sizeof(szTemp), L"%c:\\", letter); 25 | UINT res = GetDriveType(szTemp); 26 | if (type != NULL) 27 | { 28 | switch (res) 29 | { 30 | case 0: 31 | _tcsncpy(type, L"Indetermined", sizeof(L"Indetermined")); 32 | break; 33 | case 1: 34 | //_tcsncpy(type, L"Not available", sizeof(L"Not available")); 35 | _tcsncpy(type, L"", sizeof(L"")); 36 | break; 37 | case 2: 38 | _tcsncpy(type, L"Removable", sizeof(L"Removable")); 39 | break; 40 | case 3: 41 | _tcsncpy(type, L"HardDisk", sizeof(L"HardDisk")); 42 | break; 43 | case 4: 44 | _tcsncpy(type, L"Network", sizeof(L"Network")); 45 | break; 46 | case 5: 47 | _tcsncpy(type, L"CD-ROM", sizeof(L"CD-ROM")); 48 | break; 49 | case 6: 50 | _tcsncpy(type, L"RamDisk", sizeof(L"RamDisk")); 51 | break; 52 | default: 53 | _tcsncpy(type, L"Indetermined", sizeof(L"Indetermined")); 54 | } 55 | } 56 | 57 | return res > 1; 58 | } 59 | 60 | BOOL DiskUtil::fileExists(LPCTSTR szPath) 61 | { 62 | DWORD dwAttrib = GetFileAttributes(szPath); 63 | 64 | return (dwAttrib != INVALID_FILE_ATTRIBUTES && 65 | !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); 66 | } 67 | 68 | std::wstring DiskUtil::chooserFile(const wchar_t* title, const wchar_t* filter) 69 | { 70 | wchar_t szFile[MAX_PATH]; 71 | OPENFILENAME ofn; 72 | ZeroMemory(&ofn, sizeof(ofn)); 73 | ofn.lStructSize = sizeof(ofn); 74 | ofn.hwndOwner = NULL; 75 | ofn.lpstrFile = szFile; 76 | ofn.lpstrFile[0] = '\0'; 77 | ofn.nMaxFile = sizeof(szFile); 78 | ofn.lpstrFilter = filter; 79 | ofn.lpstrTitle = title; 80 | ofn.nFilterIndex = 1; 81 | ofn.lpstrFileTitle = NULL; 82 | ofn.nMaxFileTitle = 0; 83 | ofn.lpstrInitialDir = NULL; 84 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY; 85 | if (!GetOpenFileName(&ofn)) { 86 | return L""; 87 | } 88 | 89 | return ofn.lpstrFile; 90 | 91 | /* 92 | WCHAR szPath[MAX_PATH + 1] = { 0 }; 93 | DWORD retval = GetFullPathNameW(ofn.lpstrFile, MAX_PATH, szPath, NULL); 94 | if ((retval == 0) || (retval > MAX_PATH)) 95 | return L""; 96 | 97 | std::wstring wstrPath(szPath, retval); 98 | std::wcout << wstrPath << endl; 99 | return wstrPath; 100 | */ 101 | } 102 | 103 | void DiskUtil::createDriveIcon(char letter) 104 | { 105 | wchar_t keyName[128 + 1] = { 0 }; 106 | _stprintf(keyName, _T("SOFTWARE\\Classes\\Applications\\Explorer.exe\\Drives\\%c\\DefaultIcon"), letter); 107 | LPTSTR path = new TCHAR[MAX_PATH]; 108 | GetModuleFileName(NULL, path, MAX_PATH); 109 | 110 | wchar_t pszValue[MAX_PATH + 10] = { 0 }; 111 | _stprintf(pszValue, _T("%s,0"), path); 112 | 113 | obKey.SetKeyValue(keyName, L"", pszValue, (DWORD)wcslen(pszValue) * sizeof(wchar_t), true, false, HKEY_CURRENT_USER); 114 | } 115 | 116 | void DiskUtil::removeDriveIcon(char letter) 117 | { 118 | LPTSTR keyName = new TCHAR[128 + 1]; 119 | _stprintf(keyName, _T("SOFTWARE\\Classes\\Applications\\Explorer.exe\\Drives\\%c"), letter); 120 | obKey.QuickDeleteKey(keyName, HKEY_CURRENT_USER); 121 | } 122 | 123 | void DiskUtil::throwError(const char* text) 124 | { 125 | DWORD err = GetLastError(); 126 | 127 | freeResources(); 128 | char message[1024] = {}; 129 | sprintf(message, text, err); 130 | throw std::runtime_error(message); 131 | } 132 | 133 | void DiskUtil::freeResources() 134 | { 135 | if (buffer != NULL) 136 | { 137 | VirtualUnlock(buffer, dump_buffersize); 138 | VirtualFree(buffer, 0, MEM_RELEASE); 139 | } 140 | if (hinput != NULL && hinput != INVALID_HANDLE_VALUE) 141 | { 142 | CloseHandle(hinput); 143 | } 144 | if (houtput != NULL && houtput != INVALID_HANDLE_VALUE) 145 | { 146 | CloseHandle(houtput); 147 | } 148 | buffer = NULL; 149 | hinput = NULL; 150 | houtput = NULL; 151 | } 152 | 153 | DWORD DiskUtil::save(const wchar_t* source_device_name, const wchar_t* filename) 154 | { 155 | DWORD err; 156 | DWORD bytes_to_transfer, byte_count; 157 | GET_LENGTH_INFORMATION source_disklength; 158 | DISK_GEOMETRY source_diskgeometry; 159 | LARGE_INTEGER offset; 160 | OVERLAPPED overlapped; 161 | 162 | if (!SetProcessWorkingSetSize(GetCurrentProcess(), dump_workingsetsize, dump_workingsetsize)) 163 | { 164 | throwError("Error %u trying to expand working set"); 165 | } 166 | 167 | buffer = VirtualAlloc(NULL, dump_buffersize, MEM_COMMIT, PAGE_READWRITE); 168 | 169 | if (buffer == NULL) 170 | { 171 | throwError("Error %u trying to allocate buffer"); 172 | } 173 | 174 | if (!VirtualLock(buffer, dump_buffersize)) 175 | { 176 | throwError("Error %u trying to lock buffer"); 177 | } 178 | 179 | hinput = CreateFile(source_device_name, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); 180 | 181 | if (hinput == INVALID_HANDLE_VALUE) { 182 | throwError("Error %u opening input device"); 183 | } 184 | 185 | if (!DeviceIoControl(hinput, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &byte_count, NULL)) 186 | { 187 | throwError("Error %u locking input volume"); 188 | } 189 | 190 | if (!DeviceIoControl(hinput, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &source_diskgeometry, sizeof(source_diskgeometry), &byte_count, NULL)) 191 | { 192 | throwError("Error %u getting device geometry"); 193 | } 194 | 195 | switch (source_diskgeometry.MediaType) 196 | { 197 | case Unknown: 198 | case RemovableMedia: 199 | case FixedMedia: 200 | 201 | if (!DeviceIoControl(hinput, FSCTL_ALLOW_EXTENDED_DASD_IO, NULL, 0, &source_disklength, sizeof(source_disklength), &byte_count, NULL)) 202 | { 203 | throwError("Error %u getting input device dasd"); 204 | } 205 | if (!DeviceIoControl(hinput, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &source_disklength, sizeof(source_disklength), &byte_count, NULL)) 206 | { 207 | throwError("Error %u getting input device length"); 208 | } 209 | 210 | fprintf(stderr, "\nInput disk has %I64i bytes.\n\n", source_disklength.Length.QuadPart); 211 | break; 212 | 213 | default: 214 | 215 | source_disklength.Length.QuadPart = 216 | source_diskgeometry.Cylinders.QuadPart * 217 | source_diskgeometry.TracksPerCylinder * 218 | source_diskgeometry.SectorsPerTrack * 219 | source_diskgeometry.BytesPerSector; 220 | 221 | fprintf(stderr, 222 | "\n" 223 | "Input device appears to be a floppy disk. WARNING: if this is not a\n" 224 | "floppy disk the calculated size will probably be incorrect, resulting\n" 225 | "in an incomplete copy.\n" 226 | "\n" 227 | "Input disk has %I64i bytes.\n" 228 | "\n", 229 | source_disklength.Length.QuadPart); 230 | 231 | break; 232 | } 233 | 234 | houtput = CreateFile(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL); 235 | 236 | if (houtput == INVALID_HANDLE_VALUE) 237 | { 238 | throwError("Error %u creating output file"); 239 | } 240 | 241 | offset.QuadPart = 0; 242 | overlapped.hEvent = 0; 243 | 244 | for (;;) 245 | { 246 | overlapped.Offset = offset.LowPart; 247 | overlapped.OffsetHigh = offset.HighPart; 248 | 249 | if (source_disklength.Length.QuadPart - offset.QuadPart < dump_buffersize) 250 | { 251 | bytes_to_transfer = (DWORD)(source_disklength.Length.QuadPart - offset.QuadPart); 252 | if (bytes_to_transfer == 0) break; 253 | } 254 | else 255 | { 256 | bytes_to_transfer = dump_buffersize; 257 | } 258 | 259 | if (!ReadFile(hinput, buffer, bytes_to_transfer, NULL, &overlapped)) 260 | { 261 | throwError("Error %u initiating read from input disk"); 262 | } 263 | 264 | if (!GetOverlappedResult(hinput, &overlapped, &byte_count, TRUE)) 265 | { 266 | throwError("Error %u reading from input disk"); 267 | } 268 | 269 | if (byte_count != bytes_to_transfer) 270 | { 271 | err = GetLastError(); 272 | printf("Internal error - partial read. Last error code %u.\n", err); 273 | printf("bytes_to_transfer = %u; byte_count = %u.\n", bytes_to_transfer, byte_count); 274 | if (byte_count == 0) 275 | { 276 | freeResources(); 277 | return ERROR_INVALID_FUNCTION; 278 | } 279 | bytes_to_transfer = byte_count; 280 | } 281 | 282 | if (!WriteFile(houtput, buffer, bytes_to_transfer, NULL, &overlapped)) 283 | { 284 | err = GetLastError(); 285 | if (err != ERROR_IO_PENDING) 286 | { 287 | throwError("Error %u initiating write to output file"); 288 | } 289 | } 290 | 291 | if (!GetOverlappedResult(houtput, &overlapped, &byte_count, TRUE)) 292 | { 293 | throwError("Error %u writing to output file"); 294 | } 295 | 296 | if (byte_count != bytes_to_transfer) 297 | { 298 | printf("Internal error - partial write.\n"); 299 | printf("bytes_to_transfer = %u; byte_count = %u.\n", bytes_to_transfer, byte_count); 300 | freeResources(); 301 | return ERROR_INVALID_FUNCTION; 302 | } 303 | 304 | offset.QuadPart += bytes_to_transfer; 305 | } 306 | 307 | overlapped.Offset = offset.LowPart; 308 | overlapped.OffsetHigh = offset.HighPart; 309 | 310 | if (!ReadFile(hinput, buffer, source_diskgeometry.BytesPerSector, NULL, &overlapped)) 311 | { 312 | err = GetLastError(); 313 | if (err == ERROR_HANDLE_EOF) 314 | { 315 | freeResources(); 316 | return 0; 317 | } 318 | throwError("Error %u initiating read from input disk past end of file"); 319 | } 320 | 321 | if (!GetOverlappedResult(hinput, &overlapped, &byte_count, TRUE)) 322 | { 323 | err = GetLastError(); 324 | if (err == ERROR_HANDLE_EOF) 325 | { 326 | freeResources(); 327 | return 0; 328 | } 329 | throwError("Error %u reading from input disk past end of file"); 330 | } 331 | 332 | if (byte_count == 0) 333 | { 334 | freeResources(); 335 | return 0; 336 | } 337 | 338 | printf("WARNING: the expected amount of data was successfully copied,\n" 339 | "but end of file not detected on input disk. The copy might\n" 340 | "not be complete."); 341 | 342 | return ERROR_MORE_DATA; 343 | } 344 | 345 | DWORD DiskUtil::restore(const wchar_t* filename, const wchar_t* target_device_name) { 346 | 347 | DWORD err; 348 | WIN32_FILE_ATTRIBUTE_DATA fad; 349 | DWORD bytes_to_transfer, byte_count; 350 | LARGE_INTEGER filelength; 351 | GET_LENGTH_INFORMATION target_disklength; 352 | DISK_GEOMETRY target_diskgeometry; 353 | LARGE_INTEGER transfer_length; 354 | LARGE_INTEGER offset; 355 | OVERLAPPED overlapped; 356 | 357 | if (!SetProcessWorkingSetSize(GetCurrentProcess(), dump_workingsetsize, dump_workingsetsize)) 358 | { 359 | throwError("Error %u trying to expand working set"); 360 | } 361 | 362 | buffer = VirtualAlloc(NULL, dump_buffersize, MEM_COMMIT, PAGE_READWRITE); 363 | 364 | if (buffer == NULL) 365 | { 366 | throwError("Error %u trying to allocate buffer"); 367 | } 368 | 369 | if (!VirtualLock(buffer, dump_buffersize)) 370 | { 371 | throwError("Error %u trying to lock buffer"); 372 | } 373 | 374 | if (!GetFileAttributesEx(filename, GetFileExInfoStandard, &fad)) 375 | { 376 | throwError("Error %u reading input file attributes"); 377 | } 378 | 379 | filelength.HighPart = fad.nFileSizeHigh; 380 | filelength.LowPart = fad.nFileSizeLow; 381 | 382 | hinput = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL); 383 | 384 | if (hinput == INVALID_HANDLE_VALUE) 385 | { 386 | throwError("Error %u opening input file"); 387 | } 388 | 389 | houtput = CreateFile(target_device_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL); 390 | 391 | if (houtput == INVALID_HANDLE_VALUE) { 392 | throwError("Error %u opening output device"); 393 | } 394 | 395 | if (!DeviceIoControl(houtput, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &byte_count, NULL)) 396 | { 397 | throwError("Error %u locking volume"); 398 | } 399 | 400 | if (!DeviceIoControl(houtput, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &target_diskgeometry, sizeof(target_diskgeometry), &byte_count, NULL)) 401 | { 402 | throwError("Error %u getting output device geometry"); 403 | } 404 | 405 | switch (target_diskgeometry.MediaType) 406 | { 407 | case Unknown: 408 | case RemovableMedia: 409 | case FixedMedia: 410 | 411 | if (!DeviceIoControl(houtput, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &target_disklength, sizeof(target_disklength), &byte_count, NULL)) 412 | { 413 | throwError("Error %u getting output device length"); 414 | } 415 | 416 | break; 417 | 418 | default: 419 | 420 | target_disklength.Length.QuadPart = 421 | target_diskgeometry.Cylinders.QuadPart * 422 | target_diskgeometry.TracksPerCylinder * 423 | target_diskgeometry.SectorsPerTrack * 424 | target_diskgeometry.BytesPerSector; 425 | 426 | fprintf(stderr, 427 | "\n" 428 | "Output device appears to be a floppy disk. WARNING: if this is not a\n" 429 | "floppy disk the calculated output device size is probably incorrect,\n" 430 | "which might result in an incomplete copy.\n" 431 | "\n" 432 | "Output disk has %I64i bytes.\n" 433 | "\n", 434 | target_disklength.Length.QuadPart); 435 | 436 | break; 437 | } 438 | 439 | if (filelength.QuadPart == target_disklength.Length.QuadPart) 440 | { 441 | transfer_length.QuadPart = filelength.QuadPart; 442 | } 443 | else if (filelength.QuadPart < target_disklength.Length.QuadPart) 444 | { 445 | fprintf(stderr, "Image is smaller than target. Part of the target will not be written to.\n\n"); 446 | transfer_length.QuadPart = filelength.QuadPart; 447 | } 448 | else 449 | { 450 | fprintf(stderr, "Image is larger than target. Part of the image will not be copied.\n\n"); 451 | transfer_length.QuadPart = target_disklength.Length.QuadPart; 452 | } 453 | 454 | offset.QuadPart = 0; 455 | overlapped.hEvent = 0; 456 | 457 | for (;;) 458 | { 459 | overlapped.Offset = offset.LowPart; 460 | overlapped.OffsetHigh = offset.HighPart; 461 | 462 | if (transfer_length.QuadPart - offset.QuadPart < dump_buffersize) 463 | { 464 | bytes_to_transfer = (DWORD)(transfer_length.QuadPart - offset.QuadPart); 465 | if (bytes_to_transfer == 0) break; 466 | } 467 | else 468 | { 469 | bytes_to_transfer = dump_buffersize; 470 | } 471 | 472 | if (!ReadFile(hinput, buffer, bytes_to_transfer, NULL, &overlapped)) 473 | { 474 | err = GetLastError(); 475 | if (err != ERROR_IO_PENDING) 476 | { 477 | throwError("Error %u initiating read from input file"); 478 | } 479 | } 480 | 481 | if (!GetOverlappedResult(hinput, &overlapped, &byte_count, TRUE)) 482 | { 483 | throwError("Error %u reading from input file"); 484 | } 485 | 486 | if (byte_count != bytes_to_transfer) 487 | { 488 | err = GetLastError(); 489 | printf("Internal error - partial read. Last error code %u.\n", err); 490 | printf("bytes_to_transfer = %u; byte_count = %u.\n", bytes_to_transfer, byte_count); 491 | if (byte_count == 0) 492 | { 493 | freeResources(); 494 | return ERROR_INVALID_FUNCTION; 495 | } 496 | bytes_to_transfer = byte_count; 497 | } 498 | 499 | if (!WriteFile(houtput, buffer, bytes_to_transfer, NULL, &overlapped)) 500 | { 501 | err = GetLastError(); 502 | if (err != ERROR_IO_PENDING) 503 | { 504 | throwError("Error %u initiating write to output disk"); 505 | } 506 | } 507 | 508 | if (!GetOverlappedResult(houtput, &overlapped, &byte_count, TRUE)) 509 | { 510 | throwError("Error %u writing to output disk"); 511 | } 512 | 513 | if (byte_count != bytes_to_transfer) 514 | { 515 | printf("Internal error - partial write.\n"); 516 | printf("bytes_to_transfer = %u; byte_count = %u.\n", bytes_to_transfer, byte_count); 517 | freeResources(); 518 | return ERROR_INVALID_FUNCTION; 519 | } 520 | 521 | offset.QuadPart += bytes_to_transfer; 522 | } 523 | 524 | freeResources(); 525 | return 0; 526 | } -------------------------------------------------------------------------------- /GpuRamDrive/GpuRamDrive.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | GpuRamDrive proxy for ImDisk Virtual Disk Driver. 3 | 4 | Copyright (C) 2016 Syahmi Azhar. 5 | 6 | Permission is hereby granted, free of charge, to any person 7 | obtaining a copy of this software and associated documentation 8 | files (the "Software"), to deal in the Software without 9 | restriction, including without limitation the rights to use, 10 | copy, modify, merge, publish, distribute, sublicense, and/or 11 | sell copies of the Software, and to permit persons to whom the 12 | Software is furnished to do so, subject to the following 13 | conditions: 14 | 15 | The above copyright notice and this permission notice shall be 16 | included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 22 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 23 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25 | OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include "stdafx.h" 29 | #include 30 | #include 31 | #include "GpuRamDrive.h" 32 | 33 | 34 | #if GPU_API == GPU_API_OPENCL 35 | #pragma comment (lib, "opencl.lib") 36 | #endif 37 | 38 | #if GPU_API == GPU_API_CUDA 39 | #pragma comment(lib, "cuda.lib") 40 | #include "CudaHandler.h" 41 | #endif 42 | 43 | GPURamDrive::GPURamDrive() 44 | : m_DriveType(EGpuRamDriveType::HD) 45 | , m_DriveRemovable(false) 46 | , m_MemSize(0) 47 | , m_Context(nullptr) 48 | , m_Queue(nullptr) 49 | , m_GpuMem(nullptr) 50 | , m_pBuff(nullptr) 51 | , m_ImdDrive(INVALID_HANDLE_VALUE) 52 | , m_ShmHandle(NULL) 53 | , m_ShmMutexSrv(NULL) 54 | , m_ShmReqEvent(NULL) 55 | , m_ShmRespEvent(NULL) 56 | , m_ShmView(nullptr) 57 | , m_clPlatformId() 58 | , m_clDeviceId() 59 | , m_BufSize() 60 | , m_BufStart() 61 | , config(L"GpuRamDrive") 62 | , debugTools(L"GpuRamDrive") 63 | #if GPU_API == GPU_API_CUDA 64 | , m_cuDev(0) 65 | , m_cuCtx(nullptr) 66 | , m_cuDevPtr() 67 | #endif 68 | { 69 | #if GPU_API == GPU_API_CUDA 70 | CudaHandler::GetInstance(); 71 | #endif 72 | } 73 | 74 | GPURamDrive::~GPURamDrive() 75 | { 76 | ImdiskUnmountDevice(); 77 | } 78 | 79 | void GPURamDrive::RefreshGPUInfo() 80 | { 81 | m_Devices.clear(); 82 | 83 | #if GPU_API == GPU_API_HOSTMEM 84 | TGPUDevice GpuDevices; 85 | MEMORYSTATUSEX memStatus = { 0 }; 86 | 87 | memStatus.dwLength = sizeof(memStatus); 88 | GlobalMemoryStatusEx(&memStatus); 89 | GpuDevices.memsize = memStatus.ullTotalPhys; 90 | GpuDevices.platform_id = 0; 91 | GpuDevices.device_id = 0; 92 | GpuDevices.name = "Host Memory"; 93 | m_Devices.push_back(GpuDevices); 94 | #elif GPU_API == GPU_API_CUDA 95 | CUresult res; 96 | int cuDevCount; 97 | 98 | if ((res = cuDeviceGetCount(&cuDevCount)) != CUDA_SUCCESS) { 99 | throw std::runtime_error("Unable to get cuda device count: " + std::to_string(res)); 100 | } 101 | 102 | for (int i = 0; i < cuDevCount; i++) { 103 | TGPUDevice GpuDevices; 104 | CUdevice dev; 105 | 106 | char szPlatformName[64] = { 0 }; 107 | 108 | cuDeviceGet(&dev, 0); 109 | cuDeviceGetName(szPlatformName, sizeof(szPlatformName), dev); 110 | cuDeviceTotalMem((size_t*)&GpuDevices.memsize, dev); 111 | 112 | GpuDevices.platform_id = 0; 113 | GpuDevices.device_id = (cl_device_id)(0ui64 | (unsigned int)dev); 114 | GpuDevices.name = szPlatformName; 115 | m_Devices.push_back(GpuDevices); 116 | } 117 | #else 118 | cl_int clRet; 119 | cl_platform_id platforms[8]; 120 | cl_uint numPlatforms; 121 | 122 | if ((clRet = clGetPlatformIDs(4, platforms, &numPlatforms)) != CL_SUCCESS) { 123 | throw std::runtime_error(std::string("Unable to get platform IDs: ") + std::to_string(clRet)); 124 | } 125 | 126 | for (cl_uint i = 0; i < numPlatforms; i++) { 127 | cl_device_id devices[16]; 128 | cl_uint numDevices; 129 | char szPlatformName[64] = { 0 }; 130 | 131 | if ((clRet = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, sizeof(szPlatformName), szPlatformName, nullptr)) != CL_SUCCESS) { 132 | continue; 133 | } 134 | 135 | if ((clRet = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_ACCELERATOR, 16, devices, &numDevices)) != CL_SUCCESS) { 136 | continue; 137 | } 138 | 139 | for (cl_uint j = 0; j < numDevices; j++) { 140 | TGPUDevice GpuDevices; 141 | char szDevName[64] = { 0 }; 142 | 143 | if ((clRet = clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &GpuDevices.memsize, nullptr)) != CL_SUCCESS) { 144 | continue; 145 | } 146 | 147 | if ((clRet = clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(szDevName), szDevName, nullptr)) != CL_SUCCESS) { 148 | continue; 149 | } 150 | 151 | GpuDevices.platform_id = platforms[i]; 152 | GpuDevices.device_id = devices[j]; 153 | GpuDevices.name = szPlatformName + std::string(" - ") + szDevName; 154 | m_Devices.push_back(GpuDevices); 155 | } 156 | } 157 | #endif 158 | } 159 | 160 | const std::vector& GPURamDrive::GetGpuDevices() 161 | { 162 | if (m_Devices.size() == 0) { 163 | RefreshGPUInfo(); 164 | } 165 | return m_Devices; 166 | } 167 | 168 | void GPURamDrive::SetDriveType(EGpuRamDriveType type) 169 | { 170 | m_DriveType = type; 171 | } 172 | 173 | void GPURamDrive::SetDriveType(const wchar_t* type) 174 | { 175 | if (type == nullptr) return; 176 | 177 | if (_wcsicmp(type, L"HD") == 0) { 178 | m_DriveType = EGpuRamDriveType::HD; 179 | } else if (_wcsicmp(type, L"FD") == 0) { 180 | m_DriveType = EGpuRamDriveType::FD; 181 | } else if (_wcsicmp(type, L"CD") == 0) { 182 | m_DriveType = EGpuRamDriveType::CD; 183 | } else if (_wcsicmp(type, L"RAW") == 0) { 184 | m_DriveType = EGpuRamDriveType::RAW; 185 | } 186 | } 187 | 188 | void GPURamDrive::SetRemovable(bool removable) 189 | { 190 | m_DriveRemovable = removable; 191 | } 192 | 193 | void GPURamDrive::CreateRamDevice(cl_platform_id clPlatformId, cl_device_id clDeviceId, const std::wstring& ServiceName, size_t MemSize, const wchar_t* MountPoint, const std::wstring& FormatParam, const std::wstring& LabelParam, bool TempFolderParam) 194 | { 195 | debugTools.deb(L"Creating the ramdrive '%s'", MountPoint); 196 | m_clPlatformId = clPlatformId; 197 | m_clDeviceId = clDeviceId; 198 | m_MemSize = MemSize; 199 | m_ServiceName = ServiceName; 200 | m_DeviceId = IMDISK_AUTO_DEVICE_NUMBER; 201 | m_TempFolderParam = TempFolderParam; 202 | 203 | std::exception state_ex; 204 | std::atomic state = 0; 205 | 206 | #if GPU_API == GPU_API_CUDA 207 | m_cuCtx = CudaHandler::GetInstance()->getContext(m_clDeviceId); 208 | #endif 209 | 210 | // Avoid creating ram-device when it is still unmounting, usually when user do fast mount/unmount clicking. 211 | if (m_GpuThread.joinable()) { 212 | if (m_StateChangeCallback) m_StateChangeCallback(); 213 | return; 214 | } 215 | 216 | m_GpuThread = std::thread([&]() { 217 | try 218 | { 219 | debugTools.deb(L"Allocating the memory '%llu'", MemSize); 220 | GpuAllocateRam(); 221 | debugTools.deb(L"Setting the Imdisk '%s'", ServiceName.c_str()); 222 | ImdiskSetupComm(ServiceName); 223 | state = 1; 224 | ImdiskHandleComm(); 225 | Close(); 226 | } 227 | catch (const std::exception& ex) 228 | { 229 | Close(); 230 | state_ex = ex; 231 | state = 2; 232 | } 233 | }); 234 | 235 | while (state == 0) { 236 | Sleep(1); 237 | } 238 | 239 | if (state == 2) { 240 | if (m_GpuThread.joinable()) m_GpuThread.join(); 241 | throw state_ex; 242 | } 243 | 244 | debugTools.deb(L"Mounting the drive on '%s'", MountPoint); 245 | ImdiskMountDevice(MountPoint); 246 | 247 | if (FormatParam.length()) { 248 | debugTools.deb(L"Formatting the drive as '%s'", FormatParam.c_str()); 249 | wchar_t formatCommand[128] = { 0 }; 250 | STARTUPINFO StartInfo = { 0 }; 251 | PROCESS_INFORMATION ProcInfo = { 0 }; 252 | 253 | _snwprintf_s(formatCommand, sizeof(formatCommand), L"format.com %s %s", MountPoint, FormatParam.c_str()); 254 | if (wcsstr(formatCommand, L"/y") == nullptr && wcsstr(formatCommand, L"/Y") == nullptr) { 255 | wcscat_s(formatCommand, L" /y"); 256 | } 257 | 258 | CreateProcess(nullptr, 259 | formatCommand, 260 | nullptr, 261 | nullptr, 262 | TRUE, 263 | CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS, 264 | nullptr, 265 | nullptr, 266 | &StartInfo, 267 | &ProcInfo); 268 | 269 | WaitForSingleObject(ProcInfo.hProcess, INFINITE); 270 | CloseHandle(ProcInfo.hProcess); 271 | CloseHandle(ProcInfo.hThread); 272 | 273 | // Set Volumen Label 274 | if (LabelParam.length()) { 275 | debugTools.deb(L"Setting volumen name to '%s'", LabelParam.c_str()); 276 | SetVolumeLabel(MountPoint, LabelParam.c_str()); 277 | } 278 | 279 | // Create Temporal directory 280 | if (TempFolderParam) { 281 | debugTools.deb(L"Setting temporal environment to '%s\\Temp'", MountPoint); 282 | wchar_t temporalFolderName[64] = { 0 }; 283 | _snwprintf_s(temporalFolderName, sizeof(temporalFolderName), L"%s\\Temp", MountPoint); 284 | CreateDirectory(temporalFolderName, NULL); 285 | config.setMountTempEnvironment(temporalFolderName); 286 | } 287 | 288 | // Create Icon Drive 289 | 290 | } 291 | 292 | if (m_StateChangeCallback) m_StateChangeCallback(); 293 | } 294 | 295 | void GPURamDrive::ImdiskMountDevice(const wchar_t* MountPoint) 296 | { 297 | DISK_GEOMETRY dskGeom = { 0 }; 298 | DWORD flags = IMDISK_TYPE_PROXY | IMDISK_PROXY_TYPE_SHM | (DWORD)m_DriveType; 299 | if (m_DriveRemovable) flags |= IMDISK_OPTION_REMOVABLE; 300 | 301 | ImDiskSetAPIFlags(IMDISK_API_FORCE_DISMOUNT); 302 | 303 | m_MountPoint = MountPoint; 304 | debugTools.deb(L"ImDiskCreateDeviceEx start"); 305 | if (!ImDiskCreateDeviceEx(NULL, &m_DeviceId, &dskGeom, nullptr, flags, m_ServiceName.c_str(), FALSE, (LPWSTR)MountPoint)) { 306 | m_GpuThread.detach(); 307 | Close(); 308 | ImdiskUnmountDevice(); 309 | throw std::runtime_error("Unable to create and mount ImDisk drive"); 310 | } 311 | debugTools.deb(L"ImDiskCreateDeviceEx end"); 312 | } 313 | 314 | void GPURamDrive::ImdiskUnmountDevice() 315 | { 316 | if (m_MountPoint.length() == 0) return; 317 | 318 | try 319 | { 320 | if (m_TempFolderParam) 321 | config.restoreOriginalTempEnvironment(); 322 | 323 | debugTools.deb(L"Unmounting the ramdrive '%s'", m_MountPoint.c_str()); 324 | //ImDiskRemoveDevice(NULL, 0, m_MountPoint.c_str()); 325 | ImDiskForceRemoveDevice(NULL, m_DeviceId); 326 | debugTools.deb(L"Unmounted the ramdrive '%s'", m_MountPoint.c_str()); 327 | m_MountPoint.clear(); 328 | 329 | if (m_GpuThread.get_id() != std::this_thread::get_id()) { 330 | if (m_GpuThread.joinable()) m_GpuThread.join(); 331 | } 332 | } 333 | catch (const std::exception& ex) 334 | { 335 | debugTools.deb(L"Error to unmounting the ramdrive '%s'", ex.what()); 336 | } 337 | } 338 | 339 | void GPURamDrive::Close() 340 | { 341 | if (m_ShmView) UnmapViewOfFile(m_ShmView); 342 | if (m_ShmHandle) CloseHandle(m_ShmHandle); 343 | if (m_ShmMutexSrv) CloseHandle(m_ShmMutexSrv); 344 | if (m_ShmReqEvent) CloseHandle(m_ShmReqEvent); 345 | if (m_ShmRespEvent) CloseHandle(m_ShmRespEvent); 346 | 347 | if (m_pBuff) delete[] m_pBuff; 348 | #if GPU_API == GPU_API_OPENCL 349 | if (m_GpuMem) clReleaseMemObject(m_GpuMem); 350 | if (m_Queue) clReleaseCommandQueue(m_Queue); 351 | if (m_Context) clReleaseContext(m_Context); 352 | #endif 353 | 354 | m_ShmView = nullptr; 355 | m_ShmHandle = NULL; 356 | m_ShmMutexSrv = NULL; 357 | m_ShmReqEvent = NULL; 358 | m_ShmRespEvent = NULL; 359 | 360 | m_pBuff = nullptr; 361 | m_GpuMem = nullptr; 362 | m_Queue = nullptr; 363 | m_Context = nullptr; 364 | m_MemSize = 0; 365 | 366 | #if GPU_API == GPU_API_CUDA 367 | cuCtxPushCurrent(m_cuCtx); 368 | if (m_cuDevPtr) cuMemFree(m_cuDevPtr); 369 | CudaHandler::GetInstance()->removeContext(m_clDeviceId); 370 | m_cuDevPtr = 0; 371 | cuCtxPopCurrent(&m_cuCtx); 372 | #endif 373 | 374 | if (m_StateChangeCallback) m_StateChangeCallback(); 375 | } 376 | 377 | bool GPURamDrive::IsMounted() 378 | { 379 | return m_MountPoint.size() != 0 && m_ShmView != nullptr; 380 | } 381 | 382 | void GPURamDrive::SetStateChangeCallback(const std::function callback) 383 | { 384 | m_StateChangeCallback = callback; 385 | } 386 | 387 | void GPURamDrive::GpuAllocateRam() 388 | { 389 | #if GPU_API == GPU_API_HOSTMEM 390 | m_pBuff = new char[m_MemSize]; 391 | #elif GPU_API == GPU_API_CUDA 392 | cuCtxPushCurrent(m_cuCtx); 393 | CUresult res; 394 | if ((res = cuMemAlloc(&m_cuDevPtr, m_MemSize)) != CUDA_SUCCESS) { 395 | if (res == CUDA_ERROR_OUT_OF_MEMORY) { 396 | size_t free_m, total_m, free_b, total_b; 397 | CUresult res2 = cuMemGetInfo(&free_b, &total_b); 398 | free_m = free_b / 1048576; 399 | total_m = total_b / 1048576; 400 | debugTools.deb(L"Available free video memory: '%llu' bytes", free_b); 401 | cuCtxPopCurrent(&m_cuCtx); 402 | throw std::runtime_error("Not enough memory to alloc, free: '" + std::to_string(free_m) + "' Mb"); 403 | } 404 | else { 405 | cuCtxPopCurrent(&m_cuCtx); 406 | throw std::runtime_error("Unable to allocate memory on device, error code: " + std::to_string(res)); 407 | } 408 | } 409 | cuCtxPopCurrent(&m_cuCtx); 410 | #else 411 | 412 | cl_int clRet; 413 | 414 | m_Context = clCreateContext(nullptr, 1, &m_clDeviceId, nullptr, nullptr, &clRet); 415 | if (m_Context == nullptr) { 416 | throw std::runtime_error("Unable to create context: " + std::to_string(clRet)); 417 | } 418 | 419 | m_Queue = clCreateCommandQueue(m_Context, m_clDeviceId, 0, &clRet); 420 | if (m_Queue == nullptr) { 421 | throw std::runtime_error("Unable to create command queue: " + std::to_string(clRet)); 422 | } 423 | 424 | m_GpuMem = clCreateBuffer(m_Context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, m_MemSize, nullptr, &clRet); 425 | if (m_GpuMem == nullptr) { 426 | throw std::runtime_error("Unable to create memory buffer: " + std::to_string(clRet)); 427 | } 428 | #endif 429 | } 430 | 431 | safeio_ssize_t GPURamDrive::GpuWrite(void *buf, safeio_size_t size, off_t_64 offset) 432 | { 433 | #if GPU_API == GPU_API_HOSTMEM 434 | memcpy(m_pBuff + offset, buf, size); 435 | return size; 436 | #elif GPU_API == GPU_API_CUDA 437 | cuCtxPushCurrent(m_cuCtx); 438 | if (cuMemcpyHtoD(m_cuDevPtr + (CUdeviceptr)offset, buf, size) == CUDA_SUCCESS) { 439 | cuCtxPopCurrent(&m_cuCtx); 440 | return size; 441 | } 442 | cuCtxPopCurrent(&m_cuCtx); 443 | return 0; 444 | #else 445 | if (clEnqueueWriteBuffer(m_Queue, m_GpuMem, CL_TRUE, (size_t)offset, (size_t)size, buf, 0, nullptr, nullptr) != CL_SUCCESS) { 446 | return 0; 447 | } 448 | 449 | return size; 450 | #endif 451 | } 452 | 453 | safeio_ssize_t GPURamDrive::GpuRead(void *buf, safeio_size_t size, off_t_64 offset) 454 | { 455 | #if GPU_API == GPU_API_HOSTMEM 456 | memcpy(buf, m_pBuff + offset, size); 457 | return size; 458 | #elif GPU_API == GPU_API_CUDA 459 | cuCtxPushCurrent(m_cuCtx); 460 | if (cuMemcpyDtoH(buf, m_cuDevPtr + (CUdeviceptr)offset, size) == CUDA_SUCCESS) { 461 | cuCtxPopCurrent(&m_cuCtx); 462 | return size; 463 | } 464 | cuCtxPopCurrent(&m_cuCtx); 465 | return 0; 466 | #else 467 | if (clEnqueueReadBuffer(m_Queue, m_GpuMem, CL_TRUE, (size_t)offset, (size_t)size, buf, 0, nullptr, nullptr) != CL_SUCCESS) { 468 | return 0; 469 | } 470 | 471 | return size; 472 | #endif 473 | } 474 | 475 | void GPURamDrive::ImdiskSetupComm(const std::wstring& ServiceName) 476 | { 477 | MEMORY_BASIC_INFORMATION MemInfo; 478 | ULARGE_INTEGER MapSize; 479 | DWORD dwErr; 480 | std::wstring sTemp; 481 | const std::wstring sPrefix = L"Global\\"; 482 | 483 | m_BufSize = (4 << 20); 484 | MapSize.QuadPart = m_BufSize + IMDPROXY_HEADER_SIZE; 485 | 486 | sTemp = sPrefix + ServiceName; 487 | m_ShmHandle = CreateFileMapping(INVALID_HANDLE_VALUE, 488 | NULL, 489 | PAGE_READWRITE | SEC_COMMIT, 490 | MapSize.HighPart, 491 | MapSize.LowPart, 492 | sTemp.c_str()); 493 | dwErr = GetLastError(); 494 | if (m_ShmHandle == NULL) { 495 | throw std::runtime_error("Unable to create file mapping: " + std::to_string(dwErr)); 496 | } 497 | 498 | if (dwErr == ERROR_ALREADY_EXISTS) { 499 | throw std::runtime_error("A service with this name is already running or is still being used by ImDisk"); 500 | } 501 | 502 | m_ShmView = MapViewOfFile(m_ShmHandle, FILE_MAP_WRITE, 0, 0, 0); 503 | if (m_ShmView == nullptr) { 504 | dwErr = GetLastError(); 505 | throw std::runtime_error("Unable to map view of shared memory: " + std::to_string(dwErr)); 506 | } 507 | 508 | if (!VirtualQuery(m_ShmView, &MemInfo, sizeof(MemInfo))) { 509 | dwErr = GetLastError(); 510 | throw std::runtime_error("Unable to query memory info: " + std::to_string(dwErr)); 511 | } 512 | 513 | m_BufStart = (char*)m_ShmView + IMDPROXY_HEADER_SIZE; 514 | 515 | 516 | sTemp = sPrefix + ServiceName + L"_Server"; 517 | m_ShmMutexSrv = CreateMutex(NULL, FALSE, sTemp.c_str()); 518 | if (m_ShmMutexSrv == NULL) { 519 | dwErr = GetLastError(); 520 | throw std::runtime_error("Unable to create mutex object: " + std::to_string(dwErr)); 521 | } 522 | 523 | if (WaitForSingleObject(m_ShmMutexSrv, 0) != WAIT_OBJECT_0) { 524 | throw std::runtime_error("A service with this name is already running"); 525 | } 526 | 527 | sTemp = sPrefix + ServiceName + L"_Request"; 528 | m_ShmReqEvent = CreateEvent(NULL, FALSE, FALSE, sTemp.c_str()); 529 | if (m_ShmReqEvent == NULL) { 530 | dwErr = GetLastError(); 531 | throw std::runtime_error("Unable to create request event object: " + std::to_string(dwErr)); 532 | } 533 | 534 | sTemp = sPrefix + ServiceName + L"_Response"; 535 | m_ShmRespEvent = CreateEvent(NULL, FALSE, FALSE, sTemp.c_str()); 536 | if (m_ShmRespEvent == NULL) { 537 | dwErr = GetLastError(); 538 | throw std::runtime_error("Unable to create response event object: " + std::to_string(dwErr)); 539 | } 540 | } 541 | 542 | void GPURamDrive::ImdiskHandleComm() 543 | { 544 | PIMDPROXY_READ_REQ Req = (PIMDPROXY_READ_REQ)m_ShmView; 545 | PIMDPROXY_READ_RESP Resp = (PIMDPROXY_READ_RESP)m_ShmView; 546 | 547 | for (;;) 548 | { 549 | if (WaitForSingleObject(m_ShmReqEvent, INFINITE) != WAIT_OBJECT_0) { 550 | return; 551 | } 552 | 553 | switch (Req->request_code) 554 | { 555 | case IMDPROXY_REQ_INFO: 556 | { 557 | PIMDPROXY_INFO_RESP resp = (PIMDPROXY_INFO_RESP)m_ShmView; 558 | resp->file_size = m_MemSize; 559 | resp->req_alignment = 1; 560 | resp->flags = 0; 561 | break; 562 | } 563 | 564 | case IMDPROXY_REQ_READ: 565 | { 566 | Resp->errorno = 0; 567 | Resp->length = GpuRead(m_BufStart, (safeio_size_t)(Req->length < m_BufSize ? Req->length : m_BufSize), Req->offset); 568 | 569 | break; 570 | } 571 | 572 | case IMDPROXY_REQ_WRITE: 573 | { 574 | Resp->errorno = 0; 575 | Resp->length = GpuWrite(m_BufStart, (safeio_size_t)(Req->length < m_BufSize ? Req->length : m_BufSize), Req->offset); 576 | 577 | break; 578 | } 579 | 580 | case IMDPROXY_REQ_CLOSE: 581 | return; 582 | 583 | default: 584 | Req->request_code = ENODEV; 585 | } 586 | 587 | if (!SetEvent(m_ShmRespEvent)) { 588 | return; 589 | } 590 | } 591 | } --------------------------------------------------------------------------------