Skip to content

Commit

Permalink
[FEA] Atomics codegen refactor (#1993)
Browse files Browse the repository at this point in the history
* Initial draft of new atomics backend

* Change atomic fetch ops back to tag dispatch

* Save wip

* Add load/store and support for MMIO

* Begin working on exch

* Enable formatting exchange

* Several signed-ness fixes

* Make atomics ptx tests build. Lit tests are a WIP.

* Fix load/store, some volatileness, and min/max

* Formatting and enabled codegen in all builds

* Make integral.pass.cpp pass

* Make the rest of the atomics tests pass

* Use 128b ld/st instead of vector load as it is not atomic across the whole atom

* Fix copy-paste mistake in load/store

* Whitespace fixup

* Fix 128b .exch using .cas operands

* Make codegen link fmt as PRIVATE

Co-authored-by: Allison Piper <[email protected]>

* Simplify MMIO down to a static array.

Co-authored-by: Bernhard Manfred Gruber <[email protected]>

* Static -> Inline for codegen functions. Replace endl with '\n'.

* Supply the output stream directly to `fmt::format`

* Update fmtlib.

* Revert `fmt::format(out...)` changes. They don't work on MSVC.

* Fixup libcudacxx codegen CMake stuff

* Remove sneaky cstdef include that was auto-added

* [pre-commit.ci] auto code formatting

---------

Co-authored-by: Allison Piper <[email protected]>
Co-authored-by: Bernhard Manfred Gruber <[email protected]>
Co-authored-by: Michael Schellenberger Costa <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
5 people committed Aug 7, 2024
1 parent b0e09d0 commit 62336ad
Show file tree
Hide file tree
Showing 21 changed files with 5,876 additions and 7,487 deletions.
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
],
"filter": {
"exclude": {
"name": "^libcudacxx\\.test\\.lit$"
"name": "^libcudacxx\\.test\\.(lit|atomics\\.codegen\\.diff)$"
}
}
},
Expand All @@ -487,7 +487,7 @@
"configurePreset": "libcudacxx-codegen",
"filter": {
"include": {
"name": "^libcudacxx\\.atomics\\.codegen.*$"
"name": "^libcudacxx\\.test\\.atomics\\.codegen.*$"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ include(CTest)
enable_testing()

# Add codegen module
option(libcudacxx_ENABLE_CODEGEN "Enable ctest-based testing." OFF)
option(libcudacxx_ENABLE_CODEGEN "Enable libcudacxx's atomics backend codegen and tests." OFF)
if (libcudacxx_ENABLE_CODEGEN)
add_subdirectory(codegen)
endif()
Expand Down
28 changes: 14 additions & 14 deletions libcudacxx/codegen/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
## Codegen adds the following build targets
# libcudacxx.atomics.codegen
# libcudacxx.atomics.codegen.execute
# libcudacxx.atomics.codegen.install
## Test targets:
# libcudacxx.atomics.codegen.diff
# libcudacxx.test.atomics.codegen.diff

add_custom_target(libcudacxx.atomics.codegen)
include(${CMAKE_SOURCE_DIR}/cub/cmake/CPM.cmake)
CPMAddPackage("gh:fmtlib/fmt#11.0.1")

add_executable(
codegen
EXCLUDE_FROM_ALL
codegen.cpp
)

target_compile_features(
codegen PRIVATE cxx_std_14
)
target_link_libraries(codegen PRIVATE fmt)

add_dependencies(libcudacxx.atomics.codegen codegen)
set_property(TARGET codegen PROPERTY CXX_STANDARD 17)

set(atomic_generated_output "${libcudacxx_BINARY_DIR}/codegen/cuda_ptx_generated.h")
set(atomic_install_location "${libcudacxx_SOURCE_DIR}/include/cuda/std/__atomic/functions")

add_custom_target(
libcudacxx.atomics.codegen.execute
COMMAND codegen
libcudacxx.atomics.codegen
COMMAND codegen "${atomic_generated_output}"
BYPRODUCTS "${atomic_generated_output}"
)

add_dependencies(libcudacxx.atomics.codegen libcudacxx.atomics.codegen.execute)

add_custom_target(
libcudacxx.atomics.codegen.install
COMMAND ${CMAKE_COMMAND} -E copy "${atomic_generated_output}" "${atomic_install_location}/cuda_ptx_generated.h"
DEPENDS libcudacxx.atomics.codegen
BYPRODUCTS "${atomic_install_location}/cuda_ptx_generated.h"
)

add_dependencies(libcudacxx.atomics.codegen.install libcudacxx.atomics.codegen.execute)

add_test(
NAME libcudacxx.atomics.codegen.diff
NAME libcudacxx.test.atomics.codegen.diff
COMMAND ${CMAKE_COMMAND} -E compare_files "${atomic_install_location}/cuda_ptx_generated.h" "${atomic_generated_output}"
)

set_tests_properties(
libcudacxx.test.atomics.codegen.diff
PROPERTIES REQUIRED_FILES "${atomic_generated_output}"
)
Loading

0 comments on commit 62336ad

Please sign in to comment.