Skip to content

Commit 99a61d2

Browse files
authored
Merge pull request #19 from oneapi-src/bitcracker/code_update/2309
[bitcracker] code update + cmake changes
2 parents 1d7f137 + 47c2b13 commit 99a61d2

File tree

5 files changed

+85
-48
lines changed

5 files changed

+85
-48
lines changed

bitcracker/CUDA/CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,25 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2626

2727
option(USE_SM "Build for specific SM" OFF)
2828

29-
# CMAKE_CXX_FLAGS
30-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
29+
set(DEF_WL_CXX_FLAGS " ")
30+
set(DEF_GENERAL_CXX_FLAGS " -O3 -ffast-math ")
31+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
32+
33+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
34+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
35+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
36+
37+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
38+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
39+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
3140
message(STATUS "Using DEFAULT compilation flags")
32-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -ffast-math ")
33-
else()
34-
message(STATUS "OVERRIDING DEFAULT compilation flags")
41+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
42+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
43+
message(STATUS "OVERRIDING GENERAL compilation flags")
44+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
45+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
46+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
47+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
3548
endif()
3649

3750
# CUDA_NVCC_FLAGS

bitcracker/HIP/CMakeLists.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@
1616
# SPDX-License-Identifier: GPL-2.0-only
1717
#
1818

19-
cmake_minimum_required(VERSION 3.10)
19+
cmake_minimum_required(VERSION 3.10)
2020

2121
project(bitcracker LANGUAGES CXX)
2222

2323
set(CMAKE_CXX_STANDARD 17)
2424
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2525
set(CMAKE_CXX_EXTENSIONS OFF)
2626

27+
set(DEF_WL_CXX_FLAGS " -D__HIP_PLATFORM_AMD__ ")
28+
set(DEF_GENERAL_CXX_FLAGS " -O3 -std=c++17 -ffast-math ")
29+
set(DEF_COMBINED_CXX_FLAGS "${DEF_GENERAL_CXX_FLAGS} ${DEF_WL_CXX_FLAGS}")
30+
2731
if(NOT DEFINED ROCM_PATH)
2832
if(NOT DEFINED ENV{ROCM_PATH})
2933
set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to which HIP has been installed")
@@ -35,12 +39,21 @@ set(CMAKE_MODULE_PATH "${ROCM_PATH}/hip/cmake" ${CMAKE_MODULE_PATH})
3539
set(HIP_INCLUDE_DIRS "${ROCM_PATH}/include" ${HIP_INCLUDE_DIRS})
3640
set(HIP_LIBRARIES "${ROCM_PATH}/lib" ${HIP_LIBRARIES})
3741

38-
# CMAKE_CXX_FLAGS
39-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
40-
message(STATUS "Using DEFAULT compilation flags for the application")
41-
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -O3 -std=c++17 -ffast-math ")
42-
else()
43-
message(STATUS "OVERRIDING compilation flags")
42+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
43+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
44+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
45+
46+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
47+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
48+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
49+
message(STATUS "Using DEFAULT compilation flags")
50+
set(CMAKE_CXX_FLAGS "${DEF_COMBINED_CXX_FLAGS}")
51+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
52+
message(STATUS "OVERRIDING GENERAL compilation flags")
53+
set(CMAKE_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS}")
54+
string(APPEND CMAKE_CXX_FLAGS ${DEF_WL_CXX_FLAGS})
55+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
56+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
4457
endif()
4558

4659
find_package(HIP REQUIRED)
@@ -58,5 +71,3 @@ include_directories(
5871
)
5972

6073
add_executable(bitcracker ${SOURCES})
61-
62-
# target_link_libraries(bitcracker ${HIP_LIBRARIES})

bitcracker/README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,12 @@
22

33
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)).
44

5-
## Cloning
6-
7-
To clone
8-
9-
```
10-
git clone https://github.com/oneapi-src/Velocity-Bench.git
11-
```
12-
135
## Supported versions
146

157
- CUDA: The original code was obtained from [here](https://github.com/e-ago/bitcracker)
168
- SYCL: The CUDA code was migrated using Intel DPCT, and then the resulting code was modified to remove the dpct headers.
179
- HIP: Created from CUDA version using hipify-perl script.
1810

19-
# Current Version:
20-
- Initial release of the workload
21-
2211
# Build Instructions
2312

2413
## To build for SYCL

bitcracker/SYCL/CMakeLists.txt

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,71 @@ option(USE_NVIDIA_BACKEND "Build for NVIDIA backend" OFF)
3030
option(USE_AMDHIP_BACKEND "Build for AMD HIP backend" OFF)
3131
option(USE_SM "Build for specific SM" OFF)
3232

33-
set(INTEL_GPU_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
34-
set(NVIDIA_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
35-
set(AMD_GPU_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
33+
set(DEF_INTEL_WL_CXX_FLAGS " ")
34+
set(DEF_NVIDIA_WL_CXX_FLAGS " ")
35+
set(DEF_AMD_WL_CXX_FLAGS " ")
3636

37-
set(USE_DEFAULT_FLAGS ON)
38-
if("${CMAKE_CXX_FLAGS}" STREQUAL "")
37+
set(DEF_INTEL_GENERAL_CXX_FLAGS " -O2 -fsycl -Wall -Wextra -Wno-unused-parameter ")
38+
set(DEF_NVIDIA_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
39+
set(DEF_AMD_GENERAL_CXX_FLAGS " -O3 -fsycl -Wall -Wextra -Wno-unused-parameter ")
40+
41+
# -DCMAKE_CXX_FLAGS=" -blah -blah " overrides the default flags (BOTH general and WL specific)
42+
# -DOVERRIDE_GENERAL_CXX_FLAGS=" -blah -blah " overrides the general flags only (and not the workload specific flags)
43+
# passing in both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS is not allowed, in order to prevent ambiguity
44+
45+
if(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "" AND NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
46+
message(FATAL_ERROR "Both CMAKE_CXX_FLAGS and OVERRIDE_GENERAL_CXX_FLAGS cannot be passed in together")
47+
elseif("${CMAKE_CXX_FLAGS}" STREQUAL "" AND "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
3948
message(STATUS "Using DEFAULT compilation flags")
40-
else()
41-
message(STATUS "Overriding DEFAULT compilation flags")
42-
set(USE_DEFAULT_FLAGS OFF)
49+
set(INTEL_GPU_CXX_FLAGS "${DEF_INTEL_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
50+
set(NVIDIA_GPU_CXX_FLAGS "${DEF_NVIDIA_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
51+
set(AMD_GPU_CXX_FLAGS "${DEF_AMD_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
52+
elseif(NOT "${OVERRIDE_GENERAL_CXX_FLAGS}" STREQUAL "")
53+
message(STATUS "OVERRIDING GENERAL compilation flags")
54+
set(INTEL_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_INTEL_WL_CXX_FLAGS}")
55+
set(NVIDIA_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_NVIDIA_WL_CXX_FLAGS}")
56+
set(AMD_GPU_CXX_FLAGS "${OVERRIDE_GENERAL_CXX_FLAGS} ${DEF_AMD_WL_CXX_FLAGS}")
57+
elseif(NOT "${CMAKE_CXX_FLAGS}" STREQUAL "")
58+
message(STATUS "OVERRIDING GENERAL and WORKLOAD SPECIFIC compilation flags")
59+
set(INTEL_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
60+
set(NVIDIA_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
61+
set(AMD_GPU_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
4362
endif()
4463

45-
# AOT compilation
4664
if(GPU_AOT)
4765
message(STATUS "Enabling INTEL backend")
48-
if(USE_DEFAULT_FLAGS)
49-
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}") # Default flags for Intel backend
50-
endif()
51-
if( (${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC") )
66+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
67+
if((${GPU_AOT} STREQUAL "pvc") OR (${GPU_AOT} STREQUAL "PVC"))
5268
message(STATUS "Enabling Intel GPU AOT compilation for ${GPU_AOT}")
5369
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=spir64_gen -Xs \"-device 0x0bd5 -revision_id 0x2f -options -ze-opt-large-register-file\" ")
5470
else()
5571
message(STATUS "Using custom AOT compilation flag ${GPU_AOT}")
56-
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ")
72+
string(APPEND CMAKE_CXX_FLAGS " ${GPU_AOT} ") # User should be aware of advanced AOT compilation flags
5773
endif()
5874
elseif(USE_NVIDIA_BACKEND)
5975
message(STATUS "Enabling NVIDIA backend")
60-
if(USE_DEFAULT_FLAGS)
61-
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}") # Default flags for NV backend
62-
endif()
76+
set(CMAKE_CXX_FLAGS "${NVIDIA_GPU_CXX_FLAGS}")
6377
if(USE_SM)
6478
message("-- Building for SM_${USE_SM} compatibility")
65-
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM}")
79+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_${USE_SM} ")
6680
else()
6781
message("-- Building for SM_80 compatibility (DEFAULT)")
68-
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80")
82+
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=nvptx64-nvidia-cuda -Xsycl-target-backend --cuda-gpu-arch=sm_80 ")
6983
endif()
84+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_NVIDIA_BACKEND")
7085
elseif(USE_AMDHIP_BACKEND)
7186
message(STATUS "Enabling AMD HIP backend for ${USE_AMDHIP_BACKEND} AMD architecture")
72-
if(USE_DEFAULT_FLAGS)
73-
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}") # Default flags for AMD backend (gfx908 for MI100)
74-
endif()
87+
set(CMAKE_CXX_FLAGS "${AMD_GPU_CXX_FLAGS}")
7588
string(APPEND CMAKE_CXX_FLAGS " -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${USE_AMDHIP_BACKEND} ")
89+
string(APPEND CMAKE_CXX_FLAGS " -DUSE_AMDHIP_BACKEND")
90+
else()
91+
# JIT case
92+
message(STATUS "Enabling INTEL backend")
93+
set(CMAKE_CXX_FLAGS "${INTEL_GPU_CXX_FLAGS}")
7694
endif()
7795

96+
message(STATUS "CXX Compilation flags set to: ${CMAKE_CXX_FLAGS}")
97+
7898
set(SOURCES
7999
${CMAKE_SOURCE_DIR}/src/main.cpp
80100
${CMAKE_SOURCE_DIR}/src/utils.cpp

bitcracker/SYCL/src/attack.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,11 @@ double attack(
11021102
cgh.depends_on(e1);
11031103
cgh.parallel_for(
11041104
sycl::nd_range<1>(in_range, wg_size),
1105-
[=](sycl::nd_item<1> item) [[intel::reqd_sub_group_size(16)]] {
1105+
[=](sycl::nd_item<1> item)
1106+
#if !defined(USE_NVIDIA_BACKEND) && !defined(USE_AMDHIP_BACKEND)
1107+
[[intel::reqd_sub_group_size(16)]]
1108+
#endif
1109+
{
11061110
decrypt_vmk_with_mac(
11071111
num_read_pswd,
11081112
d_found,

0 commit comments

Comments
 (0)