Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributing a SYCL version #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
89 changes: 89 additions & 0 deletions SYCL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Modifications Copyright (C) 2023 Intel Corporation
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
#
# SPDX-License-Identifier: GPL-2.0-only
#

cmake_minimum_required(VERSION 3.10)

project(bitcracker LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

option(ENABLE_KERNEL_PROFILING "Build using kernel profiling" OFF)
option(GPU_AOT "Build AOT for Intel GPU" OFF)
option(USE_NVIDIA_BACKEND "Build for NVIDIA backend" OFF)
option(USE_AMDHIP_BACKEND "Build for AMD HIP backend" OFF)
option(USE_SM "Build for specific SM" OFF)

set(INTEL_GPU_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
set(NVIDIA_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
set(AMD_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")

set(USE_DEFAULT_FLAGS ON)
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
message(STATUS "Using DEFAULT compilation flags")
else()
message(STATUS "Overriding DEFAULT compilation flags")
set(USE_DEFAULT_FLAGS OFF)
endif()

# AOT compilation
if(GPU_AOT)
message(STATUS "Enabling INTEL backend")
if(USE_DEFAULT_FLAGS)
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
endif()
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f -options -ze-opt-large-register-file\" ")
else()
message(STATUS "Using custom AOT compilation flag ${GPU_AOT}")
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ")
endif()
elseif(USE_NVIDIA_BACKEND)
message(STATUS "Enabling NVIDIA backend")
if(USE_DEFAULT_FLAGS)
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
endif()
if(USE_SM)
message("-- Building for SM_${USE_SM} compatibility")
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM}")
else()
message("-- Building for SM_80 compatibility (DEFAULT)")
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80")
endif()
elseif(USE_AMDHIP_BACKEND)
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
if(USE_DEFAULT_FLAGS)
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx908 for MI100)
endif()
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
endif()

set(SOURCES
${CMAKE_SOURCE_DIR}/src/main.cpp
${CMAKE_SOURCE_DIR}/src/utils.cpp
${CMAKE_SOURCE_DIR}/src/w_blocks.cpp
${CMAKE_SOURCE_DIR}/src/attack.cpp
)

include_directories(${CMAKE_SOURCE_DIR}/src)

add_executable(bitcracker ${SOURCES})

target_link_libraries(bitcracker sycl OpenCL stdc++fs)
16 changes: 16 additions & 0 deletions SYCL/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Modifications Copyright (C) 2023 Intel Corporation

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2, as published
by the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.


SPDX-License-Identifier: GPL-2.0-only
80 changes: 80 additions & 0 deletions SYCL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# BitCracker

BitCracker is the first open source password cracking tool for storage devices (original CUDA source code is from [here](https://github.com/e-ago/bitcracker)).

## SYCL version

- The CUDA code was converted to SYCL using Intel's DPC++ Compatiblity Tool (DPCT) available [here](https://www.intel.com/content/www/us/en/developer/tools/oneapi/dpc-compatibility-tool.html#gs.52d73b).
- Timing code was later added for performance measurement purpose.
- The same SYCL code runs on Intel GPUs & CPUs as well as NVIDIA (tested on A100 and H100) and AMD (tested on MI100 and MI250) GPUs.

# Current Version:
- Initial release of the workload

# Build Instructions
Notes
- icpx compiler mentioned below is included in oneAPI Base Toolkit available [here](https://www.intel.com/content/www/us/en/developer/tools/oneapi/base-toolkit-download.html).
- clang++ compiler mentioned below is available [here](https://github.com/intel/llvm/blob/sycl/sycl/doc/GetStartedGuide.md).

## To build for SYCL

For Intel GPU -
First source icpx compiler. Then,

```
cd SYCL
mkdir build
cd build
CXX=icpx cmake -DGPU_AOT=pvc ..
make -sj
```
Note:
- To enable AOT compilation, please use the flag `-DGPU_AOT=pvc` for PVC as shown above.

For AMD GPU -
First source clang++ compiler. Then,
```
cd SYCL
mkdir build
cd build
CXX=clang++ cmake -DUSE_AMDHIP_BACKEND=gfx90a ..
make -sj
```
Note:
- We use the flag `-DUSE_AMDHIP_BACKEND=gfx90a` for MI250. Use the correct value for your GPU.

For NVIDIA GPU -
First source clang++ compiler. Then,
```
cd SYCL
mkdir build
cd build
CXX=clang++ cmake -DUSE_NVIDIA_BACKEND=YES -DUSE_SM=80 ..
make -sj
```
Note:
- We use the flag `-DUSE_SM=80` for A100 or `-DUSE_SM=90` for H100.

# Run instructions

After building, to run the workload, cd into the SYCL/build folder, if not already there. Then

```
# PVC 1 tile:
ONEAPI_DEVICE_SELECTOR=level_zero:0.0 ./bitcracker -f ../hash_pass/img_win8_user_hash.txt -d ../hash_pass/user_passwords_60000.txt -b 60000
```
```
# PVC 2 tiles:
ONEAPI_DEVICE_SELECTOR=level_zero:0 ./bitcracker -f ../hash_pass/img_win8_user_hash.txt -d ../hash_pass/user_passwords_60000.txt -b 60000
```
```
# AMD GPU:
ONEAPI_DEVICE_SELECTOR=hip:0 ./bitcracker -f ../hash_pass/img_win8_user_hash.txt -d ../hash_pass/user_passwords_60000.txt -b 60000
```
```
# NVIDIA GPU:
ONEAPI_DEVICE_SELECTOR=cuda:0 ./bitcracker -f ../hash_pass/img_win8_user_hash.txt -d ../hash_pass/user_passwords_60000.txt -b 60000
```
# Output

Output gives the total time for running the whole workload.
1 change: 1 addition & 0 deletions SYCL/hash_pass/hash_recv_pass.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$bitlocker$2$16$cda1b7e0308cffe3d4e3ec9afc7a3e61$1048576$12$b0599ad6c6a1cf0106000000$60$58516d80cb347b7a992e9eb05f8157d79ac2f66d101c796ce6ec40c91706e4d9289bcd7b2790162795a8fdc60696846d7fca26f0f75288fe07536706
1 change: 1 addition & 0 deletions SYCL/hash_pass/img_win8_user_hash.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$bitlocker$0$16$0a8b9d0655d3900e9f67280adc27b5d7$1048576$12$b0599ad6c6a1cf0103000000$60$c16658f54140b3d90be6de9e03b1fe90033a2c7df7127bcd16cb013cf778c12072142c484c9c291a496fc0ebd8c21c33b595a9c1587acfc6d8bb9663
1 change: 1 addition & 0 deletions SYCL/hash_pass/one_password.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O_FDWTxyQEXSS8WkTe5eOTbDzesLETl9
14 changes: 14 additions & 0 deletions SYCL/hash_pass/password_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random
import secrets
from pathlib import Path

min_password_len = 8
max_password_len = 27
num_passwords = 72 * 1024
output_file = Path('user_passwords_large.txt')

with output_file.open('w') as fout:
for _ in range(num_passwords):
password_len = random.randint(min_password_len, max_password_len)
password = secrets.token_urlsafe(password_len) + '\n'
fout.write(password)