From 2a1d2c6818ffd4110c5d4e308c6d77f1ca1342e6 Mon Sep 17 00:00:00 2001 From: borg323 Date: Sat, 29 Jun 2024 23:26:42 +0300 Subject: [PATCH 1/6] move rescorer to trainingdata --- meson.build | 2 +- src/rescorer_main.cc | 2 +- src/{rescorer => trainingdata}/rescoreloop.cc | 2 +- src/{rescorer => trainingdata}/rescoreloop.h | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename src/{rescorer => trainingdata}/rescoreloop.cc (99%) rename src/{rescorer => trainingdata}/rescoreloop.h (100%) diff --git a/meson.build b/meson.build index 27d6c6cb63..342825f48e 100644 --- a/meson.build +++ b/meson.build @@ -702,7 +702,7 @@ endif if get_option('rescorer') deps += subproject('gaviotatb').get_variable('gaviotatb_dep') executable('rescorer', 'src/rescorer_main.cc', - [common_files, 'src/rescorer/rescoreloop.cc'], + [common_files, 'src/trainingdata/rescoreloop.cc'], include_directories: includes, dependencies: deps, install: true) endif diff --git a/src/rescorer_main.cc b/src/rescorer_main.cc index f7acee7853..c693ad36d1 100644 --- a/src/rescorer_main.cc +++ b/src/rescorer_main.cc @@ -28,7 +28,7 @@ #include #include "chess/board.h" -#include "rescorer/rescoreloop.h" +#include "trainingdata/rescoreloop.h" #include "utils/commandline.h" #include "utils/esc_codes.h" #include "utils/exception.h" diff --git a/src/rescorer/rescoreloop.cc b/src/trainingdata/rescoreloop.cc similarity index 99% rename from src/rescorer/rescoreloop.cc rename to src/trainingdata/rescoreloop.cc index 2da34c3c22..51e22d4903 100644 --- a/src/rescorer/rescoreloop.cc +++ b/src/trainingdata/rescoreloop.cc @@ -25,7 +25,7 @@ Program grant you additional permission to convey the resulting work. */ -#include "rescorer/rescoreloop.h" +#include "trainingdata/rescoreloop.h" #include #include diff --git a/src/rescorer/rescoreloop.h b/src/trainingdata/rescoreloop.h similarity index 100% rename from src/rescorer/rescoreloop.h rename to src/trainingdata/rescoreloop.h From e8c50aa505830a31aa9a03a3728f4e6196a86cf8 Mon Sep 17 00:00:00 2001 From: borg323 Date: Sat, 29 Jun 2024 23:44:35 +0300 Subject: [PATCH 2/6] merge benchmark and lc0ctl directories into tools --- meson.build | 10 +++++----- src/main.cc | 10 +++++----- src/{benchmark => tools}/backendbench.cc | 2 +- src/{benchmark => tools}/backendbench.h | 0 src/{benchmark => tools}/benchmark.cc | 2 +- src/{benchmark => tools}/benchmark.h | 0 src/{lc0ctl => tools}/describenet.cc | 2 +- src/{lc0ctl => tools}/describenet.h | 0 src/{lc0ctl => tools}/leela2onnx.cc | 2 +- src/{lc0ctl => tools}/leela2onnx.h | 0 src/{lc0ctl => tools}/onnx2leela.cc | 2 +- src/{lc0ctl => tools}/onnx2leela.h | 0 12 files changed, 15 insertions(+), 15 deletions(-) rename src/{benchmark => tools}/backendbench.cc (99%) rename src/{benchmark => tools}/backendbench.h (100%) rename src/{benchmark => tools}/benchmark.cc (99%) rename src/{benchmark => tools}/benchmark.h (100%) rename src/{lc0ctl => tools}/describenet.cc (99%) rename src/{lc0ctl => tools}/describenet.h (100%) rename src/{lc0ctl => tools}/leela2onnx.cc (99%) rename src/{lc0ctl => tools}/leela2onnx.h (100%) rename src/{lc0ctl => tools}/onnx2leela.cc (99%) rename src/{lc0ctl => tools}/onnx2leela.h (100%) diff --git a/meson.build b/meson.build index 342825f48e..371501e18a 100644 --- a/meson.build +++ b/meson.build @@ -181,12 +181,7 @@ common_files += [ ] files += [ - 'src/benchmark/backendbench.cc', - 'src/benchmark/benchmark.cc', 'src/engine.cc', - 'src/lc0ctl/describenet.cc', - 'src/lc0ctl/leela2onnx.cc', - 'src/lc0ctl/onnx2leela.cc', 'src/mcts/params.cc', 'src/mcts/search.cc', 'src/mcts/stoppers/alphazero.cc', @@ -218,6 +213,11 @@ files += [ 'src/selfplay/loop.cc', 'src/selfplay/multigame.cc', 'src/selfplay/tournament.cc', + 'src/tools/backendbench.cc', + 'src/tools/benchmark.cc', + 'src/tools/describenet.cc', + 'src/tools/leela2onnx.cc', + 'src/tools/onnx2leela.cc', 'src/utils/histogram.cc', 'src/utils/numa.cc', 'src/utils/weights_adapter.cc', diff --git a/src/main.cc b/src/main.cc index 4c8880d4e6..f573e4974f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -25,14 +25,14 @@ Program grant you additional permission to convey the resulting work. */ -#include "benchmark/backendbench.h" -#include "benchmark/benchmark.h" #include "chess/board.h" #include "engine.h" -#include "lc0ctl/describenet.h" -#include "lc0ctl/leela2onnx.h" -#include "lc0ctl/onnx2leela.h" #include "selfplay/loop.h" +#include "tools/backendbench.h" +#include "tools/benchmark.h" +#include "tools/describenet.h" +#include "tools/leela2onnx.h" +#include "tools/onnx2leela.h" #include "utils/commandline.h" #include "utils/esc_codes.h" #include "utils/logging.h" diff --git a/src/benchmark/backendbench.cc b/src/tools/backendbench.cc similarity index 99% rename from src/benchmark/backendbench.cc rename to src/tools/backendbench.cc index 6792f9b778..d8edf3ce97 100644 --- a/src/benchmark/backendbench.cc +++ b/src/tools/backendbench.cc @@ -25,7 +25,7 @@ Program grant you additional permission to convey the resulting work. */ -#include "benchmark/backendbench.h" +#include "tools/backendbench.h" #include "chess/board.h" #include "mcts/node.h" diff --git a/src/benchmark/backendbench.h b/src/tools/backendbench.h similarity index 100% rename from src/benchmark/backendbench.h rename to src/tools/backendbench.h diff --git a/src/benchmark/benchmark.cc b/src/tools/benchmark.cc similarity index 99% rename from src/benchmark/benchmark.cc rename to src/tools/benchmark.cc index d24638a002..c9991cdf3c 100644 --- a/src/benchmark/benchmark.cc +++ b/src/tools/benchmark.cc @@ -25,7 +25,7 @@ Program grant you additional permission to convey the resulting work. */ -#include "benchmark/benchmark.h" +#include "tools/benchmark.h" #include diff --git a/src/benchmark/benchmark.h b/src/tools/benchmark.h similarity index 100% rename from src/benchmark/benchmark.h rename to src/tools/benchmark.h diff --git a/src/lc0ctl/describenet.cc b/src/tools/describenet.cc similarity index 99% rename from src/lc0ctl/describenet.cc rename to src/tools/describenet.cc index 634589f66b..80b5f1ad82 100644 --- a/src/lc0ctl/describenet.cc +++ b/src/tools/describenet.cc @@ -25,7 +25,7 @@ Program grant you additional permission to convey the resulting work. */ -#include "lc0ctl/describenet.h" +#include "tools/describenet.h" #include "neural/loader.h" #include "neural/onnx/onnx.pb.h" diff --git a/src/lc0ctl/describenet.h b/src/tools/describenet.h similarity index 100% rename from src/lc0ctl/describenet.h rename to src/tools/describenet.h diff --git a/src/lc0ctl/leela2onnx.cc b/src/tools/leela2onnx.cc similarity index 99% rename from src/lc0ctl/leela2onnx.cc rename to src/tools/leela2onnx.cc index 27c3a6cdff..0b2ff1db8f 100644 --- a/src/lc0ctl/leela2onnx.cc +++ b/src/tools/leela2onnx.cc @@ -28,11 +28,11 @@ #include #include -#include "lc0ctl/describenet.h" #include "neural/loader.h" #include "neural/onnx/converter.h" #include "neural/xla/onnx2hlo.h" #include "neural/xla/print_hlo.h" +#include "tools/describenet.h" #include "utils/files.h" #include "utils/optionsparser.h" diff --git a/src/lc0ctl/leela2onnx.h b/src/tools/leela2onnx.h similarity index 100% rename from src/lc0ctl/leela2onnx.h rename to src/tools/leela2onnx.h diff --git a/src/lc0ctl/onnx2leela.cc b/src/tools/onnx2leela.cc similarity index 99% rename from src/lc0ctl/onnx2leela.cc rename to src/tools/onnx2leela.cc index d036138251..562367f14d 100644 --- a/src/lc0ctl/onnx2leela.cc +++ b/src/tools/onnx2leela.cc @@ -31,9 +31,9 @@ #include #include -#include "lc0ctl/describenet.h" #include "neural/onnx/onnx.pb.h" #include "proto/net.pb.h" +#include "tools/describenet.h" #include "utils/files.h" #include "utils/fp16_utils.h" #include "utils/optionsparser.h" diff --git a/src/lc0ctl/onnx2leela.h b/src/tools/onnx2leela.h similarity index 100% rename from src/lc0ctl/onnx2leela.h rename to src/tools/onnx2leela.h From 3f7aa62a5d57abec4f23b05a93eb97e3aaa3fb4f Mon Sep 17 00:00:00 2001 From: borg323 Date: Sun, 30 Jun 2024 01:44:33 +0300 Subject: [PATCH 3/6] move backends to neural/backends --- meson.build | 84 +++++++++---------- src/neural/{ => backends}/blas/README.md | 0 src/neural/{ => backends}/blas/blas.h | 0 .../{ => backends}/blas/convolution1.cc | 4 +- src/neural/{ => backends}/blas/convolution1.h | 0 src/neural/{ => backends}/blas/encoder.h | 0 .../blas/fully_connected_layer.cc | 4 +- .../blas/fully_connected_layer.h | 0 .../{ => backends}/blas/layer_norm.ispc | 0 .../{ => backends}/blas/network_blas.cc | 12 +-- src/neural/{ => backends}/blas/se_unit.cc | 4 +- src/neural/{ => backends}/blas/se_unit.h | 0 .../blas/winograd_convolution3.cc | 4 +- .../blas/winograd_convolution3.h | 0 .../blas/winograd_transform.ispc | 0 .../{ => backends}/cuda/common_kernels.cu | 0 src/neural/{ => backends}/cuda/cuda_common.h | 0 .../{ => backends}/cuda/fp16_kernels.cu | 0 .../{ => backends}/cuda/inputs_outputs.h | 0 src/neural/{ => backends}/cuda/kernels.h | 0 src/neural/{ => backends}/cuda/layers.cc | 0 src/neural/{ => backends}/cuda/layers.h | 0 .../{ => backends}/cuda/network_cuda.cc | 0 .../{ => backends}/cuda/network_cudnn.cc | 0 src/neural/{ => backends}/cuda/readme.txt | 0 .../{ => backends}/cuda/winograd_helper.inc | 0 src/neural/{ => backends}/dx/MetaCommand.h | 0 src/neural/{ => backends}/dx/dx_common.h | 0 src/neural/{ => backends}/dx/layers_dx.cc | 0 src/neural/{ => backends}/dx/layers_dx.h | 0 src/neural/{ => backends}/dx/network_dx.cc | 0 src/neural/{ => backends}/dx/network_dx.h | 0 .../{ => backends}/dx/shader_wrapper.cc | 0 src/neural/{ => backends}/dx/shader_wrapper.h | 0 .../{ => backends}/dx/shaders/AddVectors.hlsl | 0 .../{ => backends}/dx/shaders/Conv1x1.hlsl | 0 .../dx/shaders/ExpandPlanes.hlsl | 0 .../{ => backends}/dx/shaders/Gemm.hlsl | 0 .../{ => backends}/dx/shaders/PolicyMap.hlsl | 0 src/neural/{ => backends}/dx/shaders/SE.hlsl | 0 .../dx/shaders/WinogradCommon.h | 0 .../dx/shaders/WinogradTransform.hlsl | 0 .../dx/shaders/WinogradTransformSE.hlsl | 0 .../{ => backends}/dx/shaders/dxc_helper.py | 0 .../{ => backends}/dx/shaders/meson.build | 0 .../{ => backends}/dx/shaders/shader_shared.h | 0 .../{ => backends}/dx/shaders/shaders.h | 0 .../{ => backends}/metal/metal_common.h | 0 .../metal/mps/MetalNetworkBuilder.h | 0 .../metal/mps/MetalNetworkBuilder.mm | 0 .../{ => backends}/metal/mps/NetworkGraph.h | 0 .../{ => backends}/metal/mps/NetworkGraph.mm | 0 .../{ => backends}/metal/network_metal.cc | 0 .../{ => backends}/metal/network_metal.h | 0 src/neural/{ => backends}/network_check.cc | 0 src/neural/{ => backends}/network_demux.cc | 0 src/neural/{ => backends}/network_mux.cc | 0 src/neural/{onnx => backends}/network_onnx.cc | 0 src/neural/{ => backends}/network_random.cc | 0 src/neural/{ => backends}/network_record.cc | 0 src/neural/{ => backends}/network_rr.cc | 0 src/neural/{ => backends}/network_tf_cc.cc | 0 src/neural/{ => backends}/network_trivial.cc | 0 src/neural/{ => backends}/onednn/layers.cc | 0 src/neural/{ => backends}/onednn/layers.h | 0 .../{ => backends}/onednn/network_onednn.cc | 0 src/neural/{ => backends}/opencl/OpenCL.cc | 6 +- src/neural/{ => backends}/opencl/OpenCL.h | 4 +- .../{ => backends}/opencl/OpenCLBuffers.cc | 2 +- .../{ => backends}/opencl/OpenCLBuffers.h | 6 +- .../{ => backends}/opencl/OpenCLParams.h | 0 .../{ => backends}/opencl/OpenCLTuner.cc | 6 +- .../{ => backends}/opencl/OpenCLTuner.h | 4 +- src/neural/{ => backends}/opencl/README.md | 0 .../opencl/clblast_level3/common.opencl | 0 .../clblast_level3/xgemm_batched.opencl | 0 .../opencl/clblast_level3/xgemm_part1.opencl | 0 .../opencl/clblast_level3/xgemm_part2.opencl | 0 .../opencl/clblast_level3/xgemm_part3.opencl | 0 .../opencl/clblast_level3/xgemv.opencl | 0 .../opencl/clsource/config.opencl | 0 .../opencl/clsource/convolve1.opencl | 0 .../opencl/clsource/convolve3.opencl | 0 .../opencl/clsource/policymap.opencl | 0 .../{ => backends}/opencl/clsource/se.opencl | 0 .../{ => backends}/opencl/network_opencl.cc | 4 +- src/neural/{ => backends}/xla/network_xla.cc | 2 +- src/neural/{ => backends}/xla/pjrt.cc | 0 src/neural/{ => backends}/xla/pjrt.h | 0 src/neural/{ => backends}/xla/xla_runner.cc | 2 +- src/neural/{ => backends}/xla/xla_runner.h | 4 +- src/neural/xla/onnx2hlo.h | 2 +- 92 files changed, 77 insertions(+), 77 deletions(-) rename src/neural/{ => backends}/blas/README.md (100%) rename src/neural/{ => backends}/blas/blas.h (100%) rename src/neural/{ => backends}/blas/convolution1.cc (97%) rename src/neural/{ => backends}/blas/convolution1.h (100%) rename src/neural/{ => backends}/blas/encoder.h (100%) rename src/neural/{ => backends}/blas/fully_connected_layer.cc (98%) rename src/neural/{ => backends}/blas/fully_connected_layer.h (100%) rename src/neural/{ => backends}/blas/layer_norm.ispc (100%) rename src/neural/{ => backends}/blas/network_blas.cc (99%) rename src/neural/{ => backends}/blas/se_unit.cc (97%) rename src/neural/{ => backends}/blas/se_unit.h (100%) rename src/neural/{ => backends}/blas/winograd_convolution3.cc (99%) rename src/neural/{ => backends}/blas/winograd_convolution3.h (100%) rename src/neural/{ => backends}/blas/winograd_transform.ispc (100%) rename src/neural/{ => backends}/cuda/common_kernels.cu (100%) rename src/neural/{ => backends}/cuda/cuda_common.h (100%) rename src/neural/{ => backends}/cuda/fp16_kernels.cu (100%) rename src/neural/{ => backends}/cuda/inputs_outputs.h (100%) rename src/neural/{ => backends}/cuda/kernels.h (100%) rename src/neural/{ => backends}/cuda/layers.cc (100%) rename src/neural/{ => backends}/cuda/layers.h (100%) rename src/neural/{ => backends}/cuda/network_cuda.cc (100%) rename src/neural/{ => backends}/cuda/network_cudnn.cc (100%) rename src/neural/{ => backends}/cuda/readme.txt (100%) rename src/neural/{ => backends}/cuda/winograd_helper.inc (100%) rename src/neural/{ => backends}/dx/MetaCommand.h (100%) rename src/neural/{ => backends}/dx/dx_common.h (100%) rename src/neural/{ => backends}/dx/layers_dx.cc (100%) rename src/neural/{ => backends}/dx/layers_dx.h (100%) rename src/neural/{ => backends}/dx/network_dx.cc (100%) rename src/neural/{ => backends}/dx/network_dx.h (100%) rename src/neural/{ => backends}/dx/shader_wrapper.cc (100%) rename src/neural/{ => backends}/dx/shader_wrapper.h (100%) rename src/neural/{ => backends}/dx/shaders/AddVectors.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/Conv1x1.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/ExpandPlanes.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/Gemm.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/PolicyMap.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/SE.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/WinogradCommon.h (100%) rename src/neural/{ => backends}/dx/shaders/WinogradTransform.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/WinogradTransformSE.hlsl (100%) rename src/neural/{ => backends}/dx/shaders/dxc_helper.py (100%) rename src/neural/{ => backends}/dx/shaders/meson.build (100%) rename src/neural/{ => backends}/dx/shaders/shader_shared.h (100%) rename src/neural/{ => backends}/dx/shaders/shaders.h (100%) rename src/neural/{ => backends}/metal/metal_common.h (100%) rename src/neural/{ => backends}/metal/mps/MetalNetworkBuilder.h (100%) rename src/neural/{ => backends}/metal/mps/MetalNetworkBuilder.mm (100%) rename src/neural/{ => backends}/metal/mps/NetworkGraph.h (100%) rename src/neural/{ => backends}/metal/mps/NetworkGraph.mm (100%) rename src/neural/{ => backends}/metal/network_metal.cc (100%) rename src/neural/{ => backends}/metal/network_metal.h (100%) rename src/neural/{ => backends}/network_check.cc (100%) rename src/neural/{ => backends}/network_demux.cc (100%) rename src/neural/{ => backends}/network_mux.cc (100%) rename src/neural/{onnx => backends}/network_onnx.cc (100%) rename src/neural/{ => backends}/network_random.cc (100%) rename src/neural/{ => backends}/network_record.cc (100%) rename src/neural/{ => backends}/network_rr.cc (100%) rename src/neural/{ => backends}/network_tf_cc.cc (100%) rename src/neural/{ => backends}/network_trivial.cc (100%) rename src/neural/{ => backends}/onednn/layers.cc (100%) rename src/neural/{ => backends}/onednn/layers.h (100%) rename src/neural/{ => backends}/onednn/network_onednn.cc (100%) rename src/neural/{ => backends}/opencl/OpenCL.cc (98%) rename src/neural/{ => backends}/opencl/OpenCL.h (98%) rename src/neural/{ => backends}/opencl/OpenCLBuffers.cc (99%) rename src/neural/{ => backends}/opencl/OpenCLBuffers.h (96%) rename src/neural/{ => backends}/opencl/OpenCLParams.h (100%) rename src/neural/{ => backends}/opencl/OpenCLTuner.cc (99%) rename src/neural/{ => backends}/opencl/OpenCLTuner.h (96%) rename src/neural/{ => backends}/opencl/README.md (100%) rename src/neural/{ => backends}/opencl/clblast_level3/common.opencl (100%) rename src/neural/{ => backends}/opencl/clblast_level3/xgemm_batched.opencl (100%) rename src/neural/{ => backends}/opencl/clblast_level3/xgemm_part1.opencl (100%) rename src/neural/{ => backends}/opencl/clblast_level3/xgemm_part2.opencl (100%) rename src/neural/{ => backends}/opencl/clblast_level3/xgemm_part3.opencl (100%) rename src/neural/{ => backends}/opencl/clblast_level3/xgemv.opencl (100%) rename src/neural/{ => backends}/opencl/clsource/config.opencl (100%) rename src/neural/{ => backends}/opencl/clsource/convolve1.opencl (100%) rename src/neural/{ => backends}/opencl/clsource/convolve3.opencl (100%) rename src/neural/{ => backends}/opencl/clsource/policymap.opencl (100%) rename src/neural/{ => backends}/opencl/clsource/se.opencl (100%) rename src/neural/{ => backends}/opencl/network_opencl.cc (99%) rename src/neural/{ => backends}/xla/network_xla.cc (99%) rename src/neural/{ => backends}/xla/pjrt.cc (100%) rename src/neural/{ => backends}/xla/pjrt.h (100%) rename src/neural/{ => backends}/xla/xla_runner.cc (99%) rename src/neural/{ => backends}/xla/xla_runner.h (98%) diff --git a/meson.build b/meson.build index 371501e18a..39770ac01b 100644 --- a/meson.build +++ b/meson.build @@ -192,23 +192,24 @@ files += [ 'src/mcts/stoppers/smooth.cc', 'src/mcts/stoppers/stoppers.cc', 'src/mcts/stoppers/timemgr.cc', + 'src/neural/backends/network_check.cc', + 'src/neural/backends/network_demux.cc', + 'src/neural/backends/network_mux.cc', + 'src/neural/backends/network_random.cc', + 'src/neural/backends/network_record.cc', + 'src/neural/backends/network_rr.cc', + 'src/neural/backends/network_trivial.cc', 'src/neural/cache.cc', 'src/neural/factory.cc', 'src/neural/loader.cc', - 'src/neural/network_check.cc', - 'src/neural/network_demux.cc', 'src/neural/network_legacy.cc', - 'src/neural/network_mux.cc', - 'src/neural/network_random.cc', - 'src/neural/network_record.cc', - 'src/neural/network_rr.cc', - 'src/neural/network_trivial.cc', 'src/neural/onnx/adapters.cc', 'src/neural/onnx/builder.cc', 'src/neural/onnx/converter.cc', 'src/neural/xla/hlo_builder.cc', 'src/neural/xla/onnx2hlo.cc', 'src/neural/xla/print_hlo.cc', + 'src/neural/xla/xla_tensor.cc', 'src/selfplay/game.cc', 'src/selfplay/loop.cc', 'src/selfplay/multigame.cc', @@ -248,7 +249,7 @@ if get_option('build_backends') tf_tensorflow_cc_lib = dependency('tensorflow_cc', required: false) if get_option('tensorflow') and tf_dl_lib.found() and tf_tensorflow_cc_lib.found() deps += [tf_dl_lib, tf_tensorflow_cc_lib] - files += 'src/neural/network_tf_cc.cc' + files += 'src/neural/backends/network_tf_cc.cc' has_backends = true endif @@ -373,11 +374,11 @@ if get_option('build_backends') endif blas_files = [ - 'src/neural/blas/convolution1.cc', - 'src/neural/blas/fully_connected_layer.cc', - 'src/neural/blas/se_unit.cc', - 'src/neural/blas/network_blas.cc', - 'src/neural/blas/winograd_convolution3.cc' + 'src/neural/backends/blas/convolution1.cc', + 'src/neural/backends/blas/fully_connected_layer.cc', + 'src/neural/backends/blas/se_unit.cc', + 'src/neural/backends/blas/network_blas.cc', + 'src/neural/backends/blas/winograd_convolution3.cc' ] shared_files = [ @@ -389,8 +390,8 @@ if get_option('build_backends') has_backends = true if get_option('ispc') and ispc.found() - files += iscp_gen.process('src/neural/blas/winograd_transform.ispc') - files += iscp_gen.process('src/neural/blas/layer_norm.ispc') + files += iscp_gen.process('src/neural/backends/blas/winograd_transform.ispc') + files += iscp_gen.process('src/neural/backends/blas/layer_norm.ispc') files += iscp_gen.process('src/neural/shared/activation.ispc') add_project_arguments('-DUSE_ISPC', language : 'cpp') endif @@ -421,10 +422,10 @@ if get_option('build_backends') if get_option('opencl') and has_opencl opencl_files = [ - 'src/neural/opencl/network_opencl.cc', - 'src/neural/opencl/OpenCL.cc', - 'src/neural/opencl/OpenCLTuner.cc', - 'src/neural/opencl/OpenCLBuffers.cc', + 'src/neural/backends/opencl/network_opencl.cc', + 'src/neural/backends/opencl/OpenCL.cc', + 'src/neural/backends/opencl/OpenCLTuner.cc', + 'src/neural/backends/opencl/OpenCLBuffers.cc', ] shared_files = [ @@ -455,21 +456,21 @@ if get_option('build_backends') if (get_option('cudnn') or get_option('plain_cuda')) and cu_blas.found() and cu_dart.found() and nvcc.found() deps += [cu_blas, cu_dart] - cuda_files = ['src/neural/cuda/layers.cc'] + cuda_files = ['src/neural/backends/cuda/layers.cc'] if get_option('cudnn') and cu_dnn.found() deps += cu_dnn - cuda_files += 'src/neural/cuda/network_cudnn.cc' - cuda_files += 'src/neural/cuda/network_cuda.cc' # To support newer nets. + cuda_files += 'src/neural/backends/cuda/network_cudnn.cc' + cuda_files += 'src/neural/backends/cuda/network_cuda.cc' # To support newer nets. add_project_arguments('-DUSE_CUDNN', language : 'cpp') elif get_option('plain_cuda') - cuda_files += 'src/neural/cuda/network_cuda.cc' + cuda_files += 'src/neural/backends/cuda/network_cuda.cc' endif foreach d : get_option('cudnn_include') if run_command('scripts/checkdir.py', d, check : false).returncode() == 0 includes += include_directories(d, is_system: true) endif endforeach - includes += include_directories('src/neural/cuda/') + includes += include_directories('src/neural/backends/cuda/') cuda_arguments = ['-c', '@INPUT@', '-o', '@OUTPUT@', '-I', meson.current_source_dir() + '/src'] @@ -523,16 +524,16 @@ if get_option('build_backends') endif files += cuda_files files += custom_target('cuda fp32 code', - input : 'src/neural/cuda/common_kernels.cu', + input : 'src/neural/backends/cuda/common_kernels.cu', output : outputname, - depend_files: 'src/neural/cuda/winograd_helper.inc', + depend_files: 'src/neural/backends/cuda/winograd_helper.inc', command : [nvcc, nvcc_extra_args, cuda_arguments] ) files += custom_target('cuda fp16 code', - input : 'src/neural/cuda/fp16_kernels.cu', + input : 'src/neural/backends/cuda/fp16_kernels.cu', output : outputname, - depend_files: 'src/neural/cuda/winograd_helper.inc', + depend_files: 'src/neural/backends/cuda/winograd_helper.inc', command : [nvcc, nvcc_extra_args, cuda_arguments] ) has_backends = true @@ -548,14 +549,14 @@ if get_option('build_backends') dx_dxgi = cc.find_library('dxgi') dx_files = [ - 'src/neural/dx/network_dx.cc', - 'src/neural/dx/shader_wrapper.cc', - 'src/neural/dx/layers_dx.cc', + 'src/neural/backends/dx/network_dx.cc', + 'src/neural/backends/dx/shader_wrapper.cc', + 'src/neural/backends/dx/layers_dx.cc', ] files += dx_files deps += [dx_d3d12, dx_dxgi] - subdir('src/neural/dx/shaders') + subdir('src/neural/backends/dx/shaders') has_backends = true endif @@ -564,8 +565,8 @@ if get_option('build_backends') includes += include_directories(get_option('dnnl_dir') + '/include') deps += [ dnnl_lib, dependency('openmp', required:true) ] files += [ - 'src/neural/onednn/network_onednn.cc', - 'src/neural/onednn/layers.cc', + 'src/neural/backends/onednn/network_onednn.cc', + 'src/neural/backends/onednn/layers.cc', ] has_backends = true endif @@ -586,7 +587,7 @@ if get_option('build_backends') includes += include_directories(get_option('onnx_include') + '/../providers/cpu', is_system: true) endif - files += 'src/neural/onnx/network_onnx.cc' + files += 'src/neural/backends/network_onnx.cc' if cc.find_library('onnxruntime_providers_rocm', dirs: get_option('onnx_libdir'), required: false).found() add_project_arguments('-DUSE_ROCM', language : 'cpp') @@ -607,9 +608,9 @@ if get_option('build_backends') deps += metal_frameworks files += [ - 'src/neural/metal/network_metal.cc', - 'src/neural/metal/mps/NetworkGraph.mm', - 'src/neural/metal/mps/MetalNetworkBuilder.mm', + 'src/neural/backends/metal/network_metal.cc', + 'src/neural/backends/metal/mps/NetworkGraph.mm', + 'src/neural/backends/metal/mps/MetalNetworkBuilder.mm', ] has_backends = true @@ -623,10 +624,9 @@ if get_option('build_backends') ## ~~~~~~~~ if get_option('xla') files += [ - 'src/neural/xla/network_xla.cc', - 'src/neural/xla/pjrt.cc', - 'src/neural/xla/xla_runner.cc', - 'src/neural/xla/xla_tensor.cc', + 'src/neural/backends/xla/network_xla.cc', + 'src/neural/backends/xla/pjrt.cc', + 'src/neural/backends/xla/xla_runner.cc', ] deps += cc.find_library('dl', required: false) has_backends = true diff --git a/src/neural/blas/README.md b/src/neural/backends/blas/README.md similarity index 100% rename from src/neural/blas/README.md rename to src/neural/backends/blas/README.md diff --git a/src/neural/blas/blas.h b/src/neural/backends/blas/blas.h similarity index 100% rename from src/neural/blas/blas.h rename to src/neural/backends/blas/blas.h diff --git a/src/neural/blas/convolution1.cc b/src/neural/backends/blas/convolution1.cc similarity index 97% rename from src/neural/blas/convolution1.cc rename to src/neural/backends/blas/convolution1.cc index c78b3976fb..8674b06dcf 100644 --- a/src/neural/blas/convolution1.cc +++ b/src/neural/backends/blas/convolution1.cc @@ -16,8 +16,8 @@ along with Leela Chess. If not, see . */ -#include "neural/blas/convolution1.h" -#include "neural/blas/blas.h" +#include "neural/backends/blas/convolution1.h" +#include "neural/backends/blas/blas.h" #include diff --git a/src/neural/blas/convolution1.h b/src/neural/backends/blas/convolution1.h similarity index 100% rename from src/neural/blas/convolution1.h rename to src/neural/backends/blas/convolution1.h diff --git a/src/neural/blas/encoder.h b/src/neural/backends/blas/encoder.h similarity index 100% rename from src/neural/blas/encoder.h rename to src/neural/backends/blas/encoder.h diff --git a/src/neural/blas/fully_connected_layer.cc b/src/neural/backends/blas/fully_connected_layer.cc similarity index 98% rename from src/neural/blas/fully_connected_layer.cc rename to src/neural/backends/blas/fully_connected_layer.cc index d228d2523f..9d741cab72 100644 --- a/src/neural/blas/fully_connected_layer.cc +++ b/src/neural/backends/blas/fully_connected_layer.cc @@ -16,8 +16,8 @@ along with Leela Chess. If not, see . */ -#include "neural/blas/fully_connected_layer.h" -#include "neural/blas/blas.h" +#include "neural/backends/blas/fully_connected_layer.h" +#include "neural/backends/blas/blas.h" #include "neural/shared/activation.h" #include diff --git a/src/neural/blas/fully_connected_layer.h b/src/neural/backends/blas/fully_connected_layer.h similarity index 100% rename from src/neural/blas/fully_connected_layer.h rename to src/neural/backends/blas/fully_connected_layer.h diff --git a/src/neural/blas/layer_norm.ispc b/src/neural/backends/blas/layer_norm.ispc similarity index 100% rename from src/neural/blas/layer_norm.ispc rename to src/neural/backends/blas/layer_norm.ispc diff --git a/src/neural/blas/network_blas.cc b/src/neural/backends/blas/network_blas.cc similarity index 99% rename from src/neural/blas/network_blas.cc rename to src/neural/backends/blas/network_blas.cc index 607700df7d..b7e654ea94 100644 --- a/src/neural/blas/network_blas.cc +++ b/src/neural/backends/blas/network_blas.cc @@ -22,12 +22,12 @@ #include #include -#include "neural/blas/blas.h" -#include "neural/blas/convolution1.h" -#include "neural/blas/encoder.h" -#include "neural/blas/fully_connected_layer.h" -#include "neural/blas/se_unit.h" -#include "neural/blas/winograd_convolution3.h" +#include "neural/backends/blas/blas.h" +#include "neural/backends/blas/convolution1.h" +#include "neural/backends/blas/encoder.h" +#include "neural/backends/blas/fully_connected_layer.h" +#include "neural/backends/blas/se_unit.h" +#include "neural/backends/blas/winograd_convolution3.h" #include "neural/factory.h" #include "neural/network.h" #include "neural/network_legacy.h" diff --git a/src/neural/blas/se_unit.cc b/src/neural/backends/blas/se_unit.cc similarity index 97% rename from src/neural/blas/se_unit.cc rename to src/neural/backends/blas/se_unit.cc index a4f24f0e0b..68761f75f5 100644 --- a/src/neural/blas/se_unit.cc +++ b/src/neural/backends/blas/se_unit.cc @@ -16,8 +16,8 @@ along with Leela Chess. If not, see . */ -#include "neural/blas/se_unit.h" -#include "neural/blas/fully_connected_layer.h" +#include "neural/backends/blas/se_unit.h" +#include "neural/backends/blas/fully_connected_layer.h" #include diff --git a/src/neural/blas/se_unit.h b/src/neural/backends/blas/se_unit.h similarity index 100% rename from src/neural/blas/se_unit.h rename to src/neural/backends/blas/se_unit.h diff --git a/src/neural/blas/winograd_convolution3.cc b/src/neural/backends/blas/winograd_convolution3.cc similarity index 99% rename from src/neural/blas/winograd_convolution3.cc rename to src/neural/backends/blas/winograd_convolution3.cc index cd77eb1a21..31f00b50df 100644 --- a/src/neural/blas/winograd_convolution3.cc +++ b/src/neural/backends/blas/winograd_convolution3.cc @@ -16,8 +16,8 @@ along with Leela Chess. If not, see . */ -#include "neural/blas/winograd_convolution3.h" -#include "neural/blas/blas.h" +#include "neural/backends/blas/winograd_convolution3.h" +#include "neural/backends/blas/blas.h" #include #include diff --git a/src/neural/blas/winograd_convolution3.h b/src/neural/backends/blas/winograd_convolution3.h similarity index 100% rename from src/neural/blas/winograd_convolution3.h rename to src/neural/backends/blas/winograd_convolution3.h diff --git a/src/neural/blas/winograd_transform.ispc b/src/neural/backends/blas/winograd_transform.ispc similarity index 100% rename from src/neural/blas/winograd_transform.ispc rename to src/neural/backends/blas/winograd_transform.ispc diff --git a/src/neural/cuda/common_kernels.cu b/src/neural/backends/cuda/common_kernels.cu similarity index 100% rename from src/neural/cuda/common_kernels.cu rename to src/neural/backends/cuda/common_kernels.cu diff --git a/src/neural/cuda/cuda_common.h b/src/neural/backends/cuda/cuda_common.h similarity index 100% rename from src/neural/cuda/cuda_common.h rename to src/neural/backends/cuda/cuda_common.h diff --git a/src/neural/cuda/fp16_kernels.cu b/src/neural/backends/cuda/fp16_kernels.cu similarity index 100% rename from src/neural/cuda/fp16_kernels.cu rename to src/neural/backends/cuda/fp16_kernels.cu diff --git a/src/neural/cuda/inputs_outputs.h b/src/neural/backends/cuda/inputs_outputs.h similarity index 100% rename from src/neural/cuda/inputs_outputs.h rename to src/neural/backends/cuda/inputs_outputs.h diff --git a/src/neural/cuda/kernels.h b/src/neural/backends/cuda/kernels.h similarity index 100% rename from src/neural/cuda/kernels.h rename to src/neural/backends/cuda/kernels.h diff --git a/src/neural/cuda/layers.cc b/src/neural/backends/cuda/layers.cc similarity index 100% rename from src/neural/cuda/layers.cc rename to src/neural/backends/cuda/layers.cc diff --git a/src/neural/cuda/layers.h b/src/neural/backends/cuda/layers.h similarity index 100% rename from src/neural/cuda/layers.h rename to src/neural/backends/cuda/layers.h diff --git a/src/neural/cuda/network_cuda.cc b/src/neural/backends/cuda/network_cuda.cc similarity index 100% rename from src/neural/cuda/network_cuda.cc rename to src/neural/backends/cuda/network_cuda.cc diff --git a/src/neural/cuda/network_cudnn.cc b/src/neural/backends/cuda/network_cudnn.cc similarity index 100% rename from src/neural/cuda/network_cudnn.cc rename to src/neural/backends/cuda/network_cudnn.cc diff --git a/src/neural/cuda/readme.txt b/src/neural/backends/cuda/readme.txt similarity index 100% rename from src/neural/cuda/readme.txt rename to src/neural/backends/cuda/readme.txt diff --git a/src/neural/cuda/winograd_helper.inc b/src/neural/backends/cuda/winograd_helper.inc similarity index 100% rename from src/neural/cuda/winograd_helper.inc rename to src/neural/backends/cuda/winograd_helper.inc diff --git a/src/neural/dx/MetaCommand.h b/src/neural/backends/dx/MetaCommand.h similarity index 100% rename from src/neural/dx/MetaCommand.h rename to src/neural/backends/dx/MetaCommand.h diff --git a/src/neural/dx/dx_common.h b/src/neural/backends/dx/dx_common.h similarity index 100% rename from src/neural/dx/dx_common.h rename to src/neural/backends/dx/dx_common.h diff --git a/src/neural/dx/layers_dx.cc b/src/neural/backends/dx/layers_dx.cc similarity index 100% rename from src/neural/dx/layers_dx.cc rename to src/neural/backends/dx/layers_dx.cc diff --git a/src/neural/dx/layers_dx.h b/src/neural/backends/dx/layers_dx.h similarity index 100% rename from src/neural/dx/layers_dx.h rename to src/neural/backends/dx/layers_dx.h diff --git a/src/neural/dx/network_dx.cc b/src/neural/backends/dx/network_dx.cc similarity index 100% rename from src/neural/dx/network_dx.cc rename to src/neural/backends/dx/network_dx.cc diff --git a/src/neural/dx/network_dx.h b/src/neural/backends/dx/network_dx.h similarity index 100% rename from src/neural/dx/network_dx.h rename to src/neural/backends/dx/network_dx.h diff --git a/src/neural/dx/shader_wrapper.cc b/src/neural/backends/dx/shader_wrapper.cc similarity index 100% rename from src/neural/dx/shader_wrapper.cc rename to src/neural/backends/dx/shader_wrapper.cc diff --git a/src/neural/dx/shader_wrapper.h b/src/neural/backends/dx/shader_wrapper.h similarity index 100% rename from src/neural/dx/shader_wrapper.h rename to src/neural/backends/dx/shader_wrapper.h diff --git a/src/neural/dx/shaders/AddVectors.hlsl b/src/neural/backends/dx/shaders/AddVectors.hlsl similarity index 100% rename from src/neural/dx/shaders/AddVectors.hlsl rename to src/neural/backends/dx/shaders/AddVectors.hlsl diff --git a/src/neural/dx/shaders/Conv1x1.hlsl b/src/neural/backends/dx/shaders/Conv1x1.hlsl similarity index 100% rename from src/neural/dx/shaders/Conv1x1.hlsl rename to src/neural/backends/dx/shaders/Conv1x1.hlsl diff --git a/src/neural/dx/shaders/ExpandPlanes.hlsl b/src/neural/backends/dx/shaders/ExpandPlanes.hlsl similarity index 100% rename from src/neural/dx/shaders/ExpandPlanes.hlsl rename to src/neural/backends/dx/shaders/ExpandPlanes.hlsl diff --git a/src/neural/dx/shaders/Gemm.hlsl b/src/neural/backends/dx/shaders/Gemm.hlsl similarity index 100% rename from src/neural/dx/shaders/Gemm.hlsl rename to src/neural/backends/dx/shaders/Gemm.hlsl diff --git a/src/neural/dx/shaders/PolicyMap.hlsl b/src/neural/backends/dx/shaders/PolicyMap.hlsl similarity index 100% rename from src/neural/dx/shaders/PolicyMap.hlsl rename to src/neural/backends/dx/shaders/PolicyMap.hlsl diff --git a/src/neural/dx/shaders/SE.hlsl b/src/neural/backends/dx/shaders/SE.hlsl similarity index 100% rename from src/neural/dx/shaders/SE.hlsl rename to src/neural/backends/dx/shaders/SE.hlsl diff --git a/src/neural/dx/shaders/WinogradCommon.h b/src/neural/backends/dx/shaders/WinogradCommon.h similarity index 100% rename from src/neural/dx/shaders/WinogradCommon.h rename to src/neural/backends/dx/shaders/WinogradCommon.h diff --git a/src/neural/dx/shaders/WinogradTransform.hlsl b/src/neural/backends/dx/shaders/WinogradTransform.hlsl similarity index 100% rename from src/neural/dx/shaders/WinogradTransform.hlsl rename to src/neural/backends/dx/shaders/WinogradTransform.hlsl diff --git a/src/neural/dx/shaders/WinogradTransformSE.hlsl b/src/neural/backends/dx/shaders/WinogradTransformSE.hlsl similarity index 100% rename from src/neural/dx/shaders/WinogradTransformSE.hlsl rename to src/neural/backends/dx/shaders/WinogradTransformSE.hlsl diff --git a/src/neural/dx/shaders/dxc_helper.py b/src/neural/backends/dx/shaders/dxc_helper.py similarity index 100% rename from src/neural/dx/shaders/dxc_helper.py rename to src/neural/backends/dx/shaders/dxc_helper.py diff --git a/src/neural/dx/shaders/meson.build b/src/neural/backends/dx/shaders/meson.build similarity index 100% rename from src/neural/dx/shaders/meson.build rename to src/neural/backends/dx/shaders/meson.build diff --git a/src/neural/dx/shaders/shader_shared.h b/src/neural/backends/dx/shaders/shader_shared.h similarity index 100% rename from src/neural/dx/shaders/shader_shared.h rename to src/neural/backends/dx/shaders/shader_shared.h diff --git a/src/neural/dx/shaders/shaders.h b/src/neural/backends/dx/shaders/shaders.h similarity index 100% rename from src/neural/dx/shaders/shaders.h rename to src/neural/backends/dx/shaders/shaders.h diff --git a/src/neural/metal/metal_common.h b/src/neural/backends/metal/metal_common.h similarity index 100% rename from src/neural/metal/metal_common.h rename to src/neural/backends/metal/metal_common.h diff --git a/src/neural/metal/mps/MetalNetworkBuilder.h b/src/neural/backends/metal/mps/MetalNetworkBuilder.h similarity index 100% rename from src/neural/metal/mps/MetalNetworkBuilder.h rename to src/neural/backends/metal/mps/MetalNetworkBuilder.h diff --git a/src/neural/metal/mps/MetalNetworkBuilder.mm b/src/neural/backends/metal/mps/MetalNetworkBuilder.mm similarity index 100% rename from src/neural/metal/mps/MetalNetworkBuilder.mm rename to src/neural/backends/metal/mps/MetalNetworkBuilder.mm diff --git a/src/neural/metal/mps/NetworkGraph.h b/src/neural/backends/metal/mps/NetworkGraph.h similarity index 100% rename from src/neural/metal/mps/NetworkGraph.h rename to src/neural/backends/metal/mps/NetworkGraph.h diff --git a/src/neural/metal/mps/NetworkGraph.mm b/src/neural/backends/metal/mps/NetworkGraph.mm similarity index 100% rename from src/neural/metal/mps/NetworkGraph.mm rename to src/neural/backends/metal/mps/NetworkGraph.mm diff --git a/src/neural/metal/network_metal.cc b/src/neural/backends/metal/network_metal.cc similarity index 100% rename from src/neural/metal/network_metal.cc rename to src/neural/backends/metal/network_metal.cc diff --git a/src/neural/metal/network_metal.h b/src/neural/backends/metal/network_metal.h similarity index 100% rename from src/neural/metal/network_metal.h rename to src/neural/backends/metal/network_metal.h diff --git a/src/neural/network_check.cc b/src/neural/backends/network_check.cc similarity index 100% rename from src/neural/network_check.cc rename to src/neural/backends/network_check.cc diff --git a/src/neural/network_demux.cc b/src/neural/backends/network_demux.cc similarity index 100% rename from src/neural/network_demux.cc rename to src/neural/backends/network_demux.cc diff --git a/src/neural/network_mux.cc b/src/neural/backends/network_mux.cc similarity index 100% rename from src/neural/network_mux.cc rename to src/neural/backends/network_mux.cc diff --git a/src/neural/onnx/network_onnx.cc b/src/neural/backends/network_onnx.cc similarity index 100% rename from src/neural/onnx/network_onnx.cc rename to src/neural/backends/network_onnx.cc diff --git a/src/neural/network_random.cc b/src/neural/backends/network_random.cc similarity index 100% rename from src/neural/network_random.cc rename to src/neural/backends/network_random.cc diff --git a/src/neural/network_record.cc b/src/neural/backends/network_record.cc similarity index 100% rename from src/neural/network_record.cc rename to src/neural/backends/network_record.cc diff --git a/src/neural/network_rr.cc b/src/neural/backends/network_rr.cc similarity index 100% rename from src/neural/network_rr.cc rename to src/neural/backends/network_rr.cc diff --git a/src/neural/network_tf_cc.cc b/src/neural/backends/network_tf_cc.cc similarity index 100% rename from src/neural/network_tf_cc.cc rename to src/neural/backends/network_tf_cc.cc diff --git a/src/neural/network_trivial.cc b/src/neural/backends/network_trivial.cc similarity index 100% rename from src/neural/network_trivial.cc rename to src/neural/backends/network_trivial.cc diff --git a/src/neural/onednn/layers.cc b/src/neural/backends/onednn/layers.cc similarity index 100% rename from src/neural/onednn/layers.cc rename to src/neural/backends/onednn/layers.cc diff --git a/src/neural/onednn/layers.h b/src/neural/backends/onednn/layers.h similarity index 100% rename from src/neural/onednn/layers.h rename to src/neural/backends/onednn/layers.h diff --git a/src/neural/onednn/network_onednn.cc b/src/neural/backends/onednn/network_onednn.cc similarity index 100% rename from src/neural/onednn/network_onednn.cc rename to src/neural/backends/onednn/network_onednn.cc diff --git a/src/neural/opencl/OpenCL.cc b/src/neural/backends/opencl/OpenCL.cc similarity index 98% rename from src/neural/opencl/OpenCL.cc rename to src/neural/backends/opencl/OpenCL.cc index 746fcff441..563cef317e 100644 --- a/src/neural/opencl/OpenCL.cc +++ b/src/neural/backends/opencl/OpenCL.cc @@ -32,9 +32,9 @@ #include #include -#include "neural/opencl/OpenCL.h" -#include "neural/opencl/OpenCLParams.h" -#include "neural/opencl/OpenCLTuner.h" +#include "neural/backends/opencl/OpenCL.h" +#include "neural/backends/opencl/OpenCLParams.h" +#include "neural/backends/opencl/OpenCLTuner.h" #include "utils/logging.h" static std::string cl_args = diff --git a/src/neural/opencl/OpenCL.h b/src/neural/backends/opencl/OpenCL.h similarity index 98% rename from src/neural/opencl/OpenCL.h rename to src/neural/backends/opencl/OpenCL.h index 559f1ef382..24bb147c98 100644 --- a/src/neural/opencl/OpenCL.h +++ b/src/neural/backends/opencl/OpenCL.h @@ -37,8 +37,8 @@ using net_t = float; #include #include "cl2.hpp" -#include "neural/opencl/OpenCLBuffers.h" -#include "neural/opencl/OpenCLParams.h" +#include "neural/backends/opencl/OpenCLBuffers.h" +#include "neural/backends/opencl/OpenCLParams.h" inline size_t ceilMultiple(size_t a, size_t b) { if (a % b == 0) return a; diff --git a/src/neural/opencl/OpenCLBuffers.cc b/src/neural/backends/opencl/OpenCLBuffers.cc similarity index 99% rename from src/neural/opencl/OpenCLBuffers.cc rename to src/neural/backends/opencl/OpenCLBuffers.cc index a12f4a4d6a..a6276aac8c 100644 --- a/src/neural/opencl/OpenCLBuffers.cc +++ b/src/neural/backends/opencl/OpenCLBuffers.cc @@ -19,7 +19,7 @@ along with Leela Chess. If not, see . */ -#include "neural/opencl/OpenCLBuffers.h" +#include "neural/backends/opencl/OpenCLBuffers.h" OpenCLBuffers::OpenCLBuffers(const OpenCL_Network& opencl_net) : m_opencl_net(opencl_net), m_opencl(opencl_net.getOpenCL()) { diff --git a/src/neural/opencl/OpenCLBuffers.h b/src/neural/backends/opencl/OpenCLBuffers.h similarity index 96% rename from src/neural/opencl/OpenCLBuffers.h rename to src/neural/backends/opencl/OpenCLBuffers.h index 56d53c4703..3742734b83 100644 --- a/src/neural/opencl/OpenCLBuffers.h +++ b/src/neural/backends/opencl/OpenCLBuffers.h @@ -34,9 +34,9 @@ #include #include -#include "neural/opencl/OpenCL.h" -#include "neural/opencl/OpenCLParams.h" -#include "neural/opencl/OpenCLTuner.h" +#include "neural/backends/opencl/OpenCL.h" +#include "neural/backends/opencl/OpenCLParams.h" +#include "neural/backends/opencl/OpenCLTuner.h" #include "utils/logging.h" class OpenCL_Network; diff --git a/src/neural/opencl/OpenCLParams.h b/src/neural/backends/opencl/OpenCLParams.h similarity index 100% rename from src/neural/opencl/OpenCLParams.h rename to src/neural/backends/opencl/OpenCLParams.h diff --git a/src/neural/opencl/OpenCLTuner.cc b/src/neural/backends/opencl/OpenCLTuner.cc similarity index 99% rename from src/neural/opencl/OpenCLTuner.cc rename to src/neural/backends/opencl/OpenCLTuner.cc index 1e8a0c334b..d25dc48f8c 100644 --- a/src/neural/opencl/OpenCLTuner.cc +++ b/src/neural/backends/opencl/OpenCLTuner.cc @@ -19,7 +19,7 @@ along with Leela Chess. If not, see . */ -#include "neural/opencl/OpenCLTuner.h" +#include "neural/backends/opencl/OpenCLTuner.h" #include #include @@ -31,8 +31,8 @@ #include #include -#include "neural/opencl/OpenCL.h" -#include "neural/opencl/OpenCLParams.h" +#include "neural/backends/opencl/OpenCL.h" +#include "neural/backends/opencl/OpenCLParams.h" #include "utils/logging.h" constexpr auto MAX_ERROR = 1e-4f; diff --git a/src/neural/opencl/OpenCLTuner.h b/src/neural/backends/opencl/OpenCLTuner.h similarity index 96% rename from src/neural/opencl/OpenCLTuner.h rename to src/neural/backends/opencl/OpenCLTuner.h index 0c1ed449ed..fec9105030 100644 --- a/src/neural/opencl/OpenCLTuner.h +++ b/src/neural/backends/opencl/OpenCLTuner.h @@ -26,8 +26,8 @@ #include #include "OpenCLParams.h" -#include "neural/opencl/OpenCL.h" -#include "neural/opencl/OpenCLParams.h" +#include "neural/backends/opencl/OpenCL.h" +#include "neural/backends/opencl/OpenCLParams.h" using Configurations = std::pair>; using TuneParameters = std::map; diff --git a/src/neural/opencl/README.md b/src/neural/backends/opencl/README.md similarity index 100% rename from src/neural/opencl/README.md rename to src/neural/backends/opencl/README.md diff --git a/src/neural/opencl/clblast_level3/common.opencl b/src/neural/backends/opencl/clblast_level3/common.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/common.opencl rename to src/neural/backends/opencl/clblast_level3/common.opencl diff --git a/src/neural/opencl/clblast_level3/xgemm_batched.opencl b/src/neural/backends/opencl/clblast_level3/xgemm_batched.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/xgemm_batched.opencl rename to src/neural/backends/opencl/clblast_level3/xgemm_batched.opencl diff --git a/src/neural/opencl/clblast_level3/xgemm_part1.opencl b/src/neural/backends/opencl/clblast_level3/xgemm_part1.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/xgemm_part1.opencl rename to src/neural/backends/opencl/clblast_level3/xgemm_part1.opencl diff --git a/src/neural/opencl/clblast_level3/xgemm_part2.opencl b/src/neural/backends/opencl/clblast_level3/xgemm_part2.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/xgemm_part2.opencl rename to src/neural/backends/opencl/clblast_level3/xgemm_part2.opencl diff --git a/src/neural/opencl/clblast_level3/xgemm_part3.opencl b/src/neural/backends/opencl/clblast_level3/xgemm_part3.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/xgemm_part3.opencl rename to src/neural/backends/opencl/clblast_level3/xgemm_part3.opencl diff --git a/src/neural/opencl/clblast_level3/xgemv.opencl b/src/neural/backends/opencl/clblast_level3/xgemv.opencl similarity index 100% rename from src/neural/opencl/clblast_level3/xgemv.opencl rename to src/neural/backends/opencl/clblast_level3/xgemv.opencl diff --git a/src/neural/opencl/clsource/config.opencl b/src/neural/backends/opencl/clsource/config.opencl similarity index 100% rename from src/neural/opencl/clsource/config.opencl rename to src/neural/backends/opencl/clsource/config.opencl diff --git a/src/neural/opencl/clsource/convolve1.opencl b/src/neural/backends/opencl/clsource/convolve1.opencl similarity index 100% rename from src/neural/opencl/clsource/convolve1.opencl rename to src/neural/backends/opencl/clsource/convolve1.opencl diff --git a/src/neural/opencl/clsource/convolve3.opencl b/src/neural/backends/opencl/clsource/convolve3.opencl similarity index 100% rename from src/neural/opencl/clsource/convolve3.opencl rename to src/neural/backends/opencl/clsource/convolve3.opencl diff --git a/src/neural/opencl/clsource/policymap.opencl b/src/neural/backends/opencl/clsource/policymap.opencl similarity index 100% rename from src/neural/opencl/clsource/policymap.opencl rename to src/neural/backends/opencl/clsource/policymap.opencl diff --git a/src/neural/opencl/clsource/se.opencl b/src/neural/backends/opencl/clsource/se.opencl similarity index 100% rename from src/neural/opencl/clsource/se.opencl rename to src/neural/backends/opencl/clsource/se.opencl diff --git a/src/neural/opencl/network_opencl.cc b/src/neural/backends/opencl/network_opencl.cc similarity index 99% rename from src/neural/opencl/network_opencl.cc rename to src/neural/backends/opencl/network_opencl.cc index 5d71d06291..5e2a88d13f 100644 --- a/src/neural/opencl/network_opencl.cc +++ b/src/neural/backends/opencl/network_opencl.cc @@ -22,11 +22,11 @@ #include #include +#include "neural/backends/opencl/OpenCL.h" +#include "neural/backends/opencl/OpenCLParams.h" #include "neural/factory.h" #include "neural/network.h" #include "neural/network_legacy.h" -#include "neural/opencl/OpenCL.h" -#include "neural/opencl/OpenCLParams.h" #include "neural/shared/activation.h" #include "neural/shared/policy_map.h" #include "neural/shared/winograd_filter.h" diff --git a/src/neural/xla/network_xla.cc b/src/neural/backends/xla/network_xla.cc similarity index 99% rename from src/neural/xla/network_xla.cc rename to src/neural/backends/xla/network_xla.cc index 29b3a39be3..cfa975d1e1 100644 --- a/src/neural/xla/network_xla.cc +++ b/src/neural/backends/xla/network_xla.cc @@ -27,11 +27,11 @@ #include +#include "neural/backends/xla/xla_runner.h" #include "neural/factory.h" #include "neural/network.h" #include "neural/onnx/converter.h" #include "neural/xla/onnx2hlo.h" -#include "neural/xla/xla_runner.h" #include "utils/bititer.h" namespace lczero { diff --git a/src/neural/xla/pjrt.cc b/src/neural/backends/xla/pjrt.cc similarity index 100% rename from src/neural/xla/pjrt.cc rename to src/neural/backends/xla/pjrt.cc diff --git a/src/neural/xla/pjrt.h b/src/neural/backends/xla/pjrt.h similarity index 100% rename from src/neural/xla/pjrt.h rename to src/neural/backends/xla/pjrt.h diff --git a/src/neural/xla/xla_runner.cc b/src/neural/backends/xla/xla_runner.cc similarity index 99% rename from src/neural/xla/xla_runner.cc rename to src/neural/backends/xla/xla_runner.cc index eaef957535..143fad2efb 100644 --- a/src/neural/xla/xla_runner.cc +++ b/src/neural/backends/xla/xla_runner.cc @@ -25,7 +25,7 @@ Program grant you additional permission to convey the resulting work. */ -#include "neural/xla/xla_runner.h" +#include "neural/backends/xla/xla_runner.h" #include #include diff --git a/src/neural/xla/xla_runner.h b/src/neural/backends/xla/xla_runner.h similarity index 98% rename from src/neural/xla/xla_runner.h rename to src/neural/backends/xla/xla_runner.h index 62c4a27f14..931571362e 100644 --- a/src/neural/xla/xla_runner.h +++ b/src/neural/backends/xla/xla_runner.h @@ -33,8 +33,8 @@ #include #include +#include "neural/backends/xla/pjrt.h" #include "neural/xla/hlo.pb.h" -#include "neural/xla/pjrt.h" #include "neural/xla/xla_tensor.h" namespace lczero { @@ -76,4 +76,4 @@ class XlaRunner { int device_; }; -} // namespace lczero \ No newline at end of file +} // namespace lczero diff --git a/src/neural/xla/onnx2hlo.h b/src/neural/xla/onnx2hlo.h index fe2f1876d4..5d4cca15f9 100644 --- a/src/neural/xla/onnx2hlo.h +++ b/src/neural/xla/onnx2hlo.h @@ -32,7 +32,7 @@ #include "neural/onnx/onnx.pb.h" #include "neural/xla/hlo.pb.h" -#include "neural/xla/xla_runner.h" +#include "neural/xla/xla_tensor.h" namespace lczero { From 0eb0c49dce4de56aff4f070bb2d6345c1108dc48 Mon Sep 17 00:00:00 2001 From: borg323 Date: Sun, 30 Jun 2024 02:05:16 +0300 Subject: [PATCH 4/6] fix build --- src/neural/xla/onnx2hlo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/neural/xla/onnx2hlo.h b/src/neural/xla/onnx2hlo.h index 5d4cca15f9..e06436915d 100644 --- a/src/neural/xla/onnx2hlo.h +++ b/src/neural/xla/onnx2hlo.h @@ -27,6 +27,7 @@ #pragma once +#include #include #include From 0879fd6e8725b7aa66e6473bd04673223002c2fc Mon Sep 17 00:00:00 2001 From: borg323 Date: Fri, 27 Sep 2024 02:42:03 +0300 Subject: [PATCH 5/6] handle backend shared files --- meson.build | 10 ++--- src/neural/backends/blas/encoder.h | 2 +- .../backends/blas/fully_connected_layer.cc | 1 - .../backends/blas/fully_connected_layer.h | 2 +- src/neural/backends/blas/network_blas.cc | 8 ++-- src/neural/backends/blas/se_unit.h | 2 +- src/neural/backends/cuda/common_kernels.cu | 4 +- src/neural/backends/cuda/fp16_kernels.cu | 2 +- src/neural/backends/cuda/kernels.h | 2 +- src/neural/backends/cuda/layers.cc | 4 +- src/neural/backends/cuda/layers.h | 2 +- src/neural/backends/cuda/network_cuda.cc | 6 +-- src/neural/backends/cuda/network_cudnn.cc | 6 +-- src/neural/backends/dx/network_dx.cc | 2 +- .../backends/metal/mps/MetalNetworkBuilder.mm | 2 +- src/neural/backends/metal/network_metal.cc | 4 +- src/neural/backends/network_tf_cc.cc | 2 +- src/neural/backends/onednn/layers.h | 2 +- src/neural/backends/onednn/network_onednn.cc | 4 +- src/neural/backends/opencl/network_opencl.cc | 6 +-- .../{ => backends}/shared/activation.cc | 2 +- src/neural/{ => backends}/shared/activation.h | 16 +------- .../{ => backends}/shared/activation.ispc | 0 .../{ => backends}/shared/winograd_filter.cc | 2 +- .../{ => backends}/shared/winograd_filter.h | 0 src/neural/onnx/converter.cc | 6 +-- src/neural/tables/activation_function.h | 37 +++++++++++++++++++ .../{shared => tables}/attention_policy_map.h | 0 src/neural/{shared => tables}/policy_map.h | 0 29 files changed, 80 insertions(+), 56 deletions(-) rename src/neural/{ => backends}/shared/activation.cc (99%) rename src/neural/{ => backends}/shared/activation.h (81%) rename src/neural/{ => backends}/shared/activation.ispc (100%) rename src/neural/{ => backends}/shared/winograd_filter.cc (98%) rename src/neural/{ => backends}/shared/winograd_filter.h (100%) create mode 100644 src/neural/tables/activation_function.h rename src/neural/{shared => tables}/attention_policy_map.h (100%) rename src/neural/{shared => tables}/policy_map.h (100%) diff --git a/meson.build b/meson.build index 39770ac01b..3275d452ae 100644 --- a/meson.build +++ b/meson.build @@ -382,8 +382,8 @@ if get_option('build_backends') ] shared_files = [ - 'src/neural/shared/activation.cc', - 'src/neural/shared/winograd_filter.cc', + 'src/neural/backends/shared/activation.cc', + 'src/neural/backends/shared/winograd_filter.cc', ] files += blas_files @@ -392,7 +392,7 @@ if get_option('build_backends') if get_option('ispc') and ispc.found() files += iscp_gen.process('src/neural/backends/blas/winograd_transform.ispc') files += iscp_gen.process('src/neural/backends/blas/layer_norm.ispc') - files += iscp_gen.process('src/neural/shared/activation.ispc') + files += iscp_gen.process('src/neural/backends/shared/activation.ispc') add_project_arguments('-DUSE_ISPC', language : 'cpp') endif @@ -429,8 +429,8 @@ if get_option('build_backends') ] shared_files = [ - 'src/neural/shared/activation.cc', - 'src/neural/shared/winograd_filter.cc', + 'src/neural/backends/shared/activation.cc', + 'src/neural/backends/shared/winograd_filter.cc', ] if not opencl_framework.found() diff --git a/src/neural/backends/blas/encoder.h b/src/neural/backends/blas/encoder.h index 28cf3b16b1..e950b2181d 100644 --- a/src/neural/backends/blas/encoder.h +++ b/src/neural/backends/blas/encoder.h @@ -20,7 +20,7 @@ #include -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" #ifdef USE_ISPC #include "layer_norm_ispc.h" diff --git a/src/neural/backends/blas/fully_connected_layer.cc b/src/neural/backends/blas/fully_connected_layer.cc index 9d741cab72..84699a3ec2 100644 --- a/src/neural/backends/blas/fully_connected_layer.cc +++ b/src/neural/backends/blas/fully_connected_layer.cc @@ -18,7 +18,6 @@ #include "neural/backends/blas/fully_connected_layer.h" #include "neural/backends/blas/blas.h" -#include "neural/shared/activation.h" #include #include diff --git a/src/neural/backends/blas/fully_connected_layer.h b/src/neural/backends/blas/fully_connected_layer.h index 1917c41378..821947cef4 100644 --- a/src/neural/backends/blas/fully_connected_layer.h +++ b/src/neural/backends/blas/fully_connected_layer.h @@ -18,7 +18,7 @@ #pragma once -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" #include #include diff --git a/src/neural/backends/blas/network_blas.cc b/src/neural/backends/blas/network_blas.cc index b7e654ea94..71c561ca12 100644 --- a/src/neural/backends/blas/network_blas.cc +++ b/src/neural/backends/blas/network_blas.cc @@ -28,13 +28,13 @@ #include "neural/backends/blas/fully_connected_layer.h" #include "neural/backends/blas/se_unit.h" #include "neural/backends/blas/winograd_convolution3.h" +#include "neural/backends/shared/activation.h" +#include "neural/backends/shared/winograd_filter.h" #include "neural/factory.h" #include "neural/network.h" #include "neural/network_legacy.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" -#include "neural/shared/winograd_filter.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/numa.h" #ifdef USE_DNNL diff --git a/src/neural/backends/blas/se_unit.h b/src/neural/backends/blas/se_unit.h index afc7f2dc15..a93bce1750 100644 --- a/src/neural/backends/blas/se_unit.h +++ b/src/neural/backends/blas/se_unit.h @@ -18,7 +18,7 @@ #pragma once -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" #include diff --git a/src/neural/backends/cuda/common_kernels.cu b/src/neural/backends/cuda/common_kernels.cu index 395bab8d84..20c0d28ae7 100644 --- a/src/neural/backends/cuda/common_kernels.cu +++ b/src/neural/backends/cuda/common_kernels.cu @@ -29,8 +29,8 @@ #include #include "cuda_common.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" +#include "neural/backends/shared/activation.h" +#include "neural/tables/attention_policy_map.h" #include "winograd_helper.inc" namespace lczero { diff --git a/src/neural/backends/cuda/fp16_kernels.cu b/src/neural/backends/cuda/fp16_kernels.cu index f30b14f50d..020634f2fd 100644 --- a/src/neural/backends/cuda/fp16_kernels.cu +++ b/src/neural/backends/cuda/fp16_kernels.cu @@ -26,7 +26,7 @@ */ #include "cuda_common.h" -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" // Allow building on an old architecture. #if __CUDA_ARCH__ < 530 diff --git a/src/neural/backends/cuda/kernels.h b/src/neural/backends/cuda/kernels.h index 483af0f4db..c836a9bfca 100644 --- a/src/neural/backends/cuda/kernels.h +++ b/src/neural/backends/cuda/kernels.h @@ -26,7 +26,7 @@ */ #include "cuda_common.h" -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" namespace lczero { namespace cudnn_backend { diff --git a/src/neural/backends/cuda/layers.cc b/src/neural/backends/cuda/layers.cc index 8543443897..22b4b4bd87 100644 --- a/src/neural/backends/cuda/layers.cc +++ b/src/neural/backends/cuda/layers.cc @@ -32,9 +32,9 @@ #include "cuda_common.h" #include "kernels.h" +#include "neural/backends/shared/activation.h" #include "neural/network.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" +#include "neural/tables/attention_policy_map.h" #include "utils/fp16_utils.h" namespace lczero { diff --git a/src/neural/backends/cuda/layers.h b/src/neural/backends/cuda/layers.h index de563f9346..56009d922c 100644 --- a/src/neural/backends/cuda/layers.h +++ b/src/neural/backends/cuda/layers.h @@ -31,8 +31,8 @@ #include #include "cuda_common.h" +#include "neural/backends/shared/activation.h" #include "neural/network_legacy.h" -#include "neural/shared/activation.h" #ifdef USE_CUDNN #include diff --git a/src/neural/backends/cuda/network_cuda.cc b/src/neural/backends/cuda/network_cuda.cc index cf67d1336c..24760d975e 100644 --- a/src/neural/backends/cuda/network_cuda.cc +++ b/src/neural/backends/cuda/network_cuda.cc @@ -35,11 +35,11 @@ #include "inputs_outputs.h" #include "kernels.h" #include "layers.h" +#include "neural/backends/shared/activation.h" #include "neural/factory.h" #include "neural/network_legacy.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/exception.h" diff --git a/src/neural/backends/cuda/network_cudnn.cc b/src/neural/backends/cuda/network_cudnn.cc index d5b54decdc..e6d7d1f17e 100644 --- a/src/neural/backends/cuda/network_cudnn.cc +++ b/src/neural/backends/cuda/network_cudnn.cc @@ -35,11 +35,11 @@ #include "inputs_outputs.h" #include "kernels.h" #include "layers.h" +#include "neural/backends/shared/activation.h" #include "neural/factory.h" #include "neural/network_legacy.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/exception.h" diff --git a/src/neural/backends/dx/network_dx.cc b/src/neural/backends/dx/network_dx.cc index 1c34a6fb2d..1000b88422 100644 --- a/src/neural/backends/dx/network_dx.cc +++ b/src/neural/backends/dx/network_dx.cc @@ -35,7 +35,7 @@ #include #include "layers_dx.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/policy_map.h" #include "shader_wrapper.h" #include "utils/bititer.h" #include "utils/exception.h" diff --git a/src/neural/backends/metal/mps/MetalNetworkBuilder.mm b/src/neural/backends/metal/mps/MetalNetworkBuilder.mm index 4c3d5c9ccc..2be155975a 100644 --- a/src/neural/backends/metal/mps/MetalNetworkBuilder.mm +++ b/src/neural/backends/metal/mps/MetalNetworkBuilder.mm @@ -26,7 +26,7 @@ Toolkit and the NVIDIA CUDA Deep Neural Network library (or a */ #import "neural/network_legacy.h" -#import "neural/shared/attention_policy_map.h" +#import "neural/tables/attention_policy_map.h" #import "MetalNetworkBuilder.h" #import "NetworkGraph.h" diff --git a/src/neural/backends/metal/network_metal.cc b/src/neural/backends/metal/network_metal.cc index f3d8d7eda2..0a45eb74da 100644 --- a/src/neural/backends/metal/network_metal.cc +++ b/src/neural/backends/metal/network_metal.cc @@ -37,8 +37,8 @@ #include "mps/MetalNetworkBuilder.h" #include "neural/factory.h" #include "neural/network_legacy.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/exception.h" diff --git a/src/neural/backends/network_tf_cc.cc b/src/neural/backends/network_tf_cc.cc index f7b5cad65f..68d1c0fb9d 100644 --- a/src/neural/backends/network_tf_cc.cc +++ b/src/neural/backends/network_tf_cc.cc @@ -38,7 +38,7 @@ #include "neural/factory.h" #include "neural/network_legacy.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/optionsdict.h" #include "utils/transpose.h" diff --git a/src/neural/backends/onednn/layers.h b/src/neural/backends/onednn/layers.h index 64b0096fc1..6c162b2e69 100644 --- a/src/neural/backends/onednn/layers.h +++ b/src/neural/backends/onednn/layers.h @@ -26,7 +26,7 @@ */ #pragma once -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" #include "utils/exception.h" #include "dnnl.hpp" diff --git a/src/neural/backends/onednn/network_onednn.cc b/src/neural/backends/onednn/network_onednn.cc index 3f03cbd054..5fb85b77a5 100644 --- a/src/neural/backends/onednn/network_onednn.cc +++ b/src/neural/backends/onednn/network_onednn.cc @@ -35,8 +35,8 @@ #include "layers.h" #include "neural/factory.h" #include "neural/network_legacy.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/exception.h" diff --git a/src/neural/backends/opencl/network_opencl.cc b/src/neural/backends/opencl/network_opencl.cc index 5e2a88d13f..428b06315f 100644 --- a/src/neural/backends/opencl/network_opencl.cc +++ b/src/neural/backends/opencl/network_opencl.cc @@ -24,12 +24,12 @@ #include "neural/backends/opencl/OpenCL.h" #include "neural/backends/opencl/OpenCLParams.h" +#include "neural/backends/shared/activation.h" +#include "neural/backends/shared/winograd_filter.h" #include "neural/factory.h" #include "neural/network.h" #include "neural/network_legacy.h" -#include "neural/shared/activation.h" -#include "neural/shared/policy_map.h" -#include "neural/shared/winograd_filter.h" +#include "neural/tables/policy_map.h" #include "utils/bititer.h" #include "utils/exception.h" #include "utils/filesystem.h" diff --git a/src/neural/shared/activation.cc b/src/neural/backends/shared/activation.cc similarity index 99% rename from src/neural/shared/activation.cc rename to src/neural/backends/shared/activation.cc index 1710d9e802..6f2551a7e6 100644 --- a/src/neural/shared/activation.cc +++ b/src/neural/backends/shared/activation.cc @@ -16,7 +16,7 @@ along with Leela Chess. If not, see . */ -#include "neural/shared/activation.h" +#include "neural/backends/shared/activation.h" #include #include diff --git a/src/neural/shared/activation.h b/src/neural/backends/shared/activation.h similarity index 81% rename from src/neural/shared/activation.h rename to src/neural/backends/shared/activation.h index 6f110886db..d4bb2879c1 100644 --- a/src/neural/shared/activation.h +++ b/src/neural/backends/shared/activation.h @@ -21,21 +21,9 @@ #include #include +#include "neural/tables/activation_function.h" + namespace lczero { -// The following list matches the one in net.proto. Ideally this would be done -// by including proto/net.pb.h, but this is incompatible with nvcc. -enum ActivationFunction { - ACTIVATION_DEFAULT = 0, - ACTIVATION_MISH = 1, - ACTIVATION_RELU = 2, - ACTIVATION_NONE = 3, - ACTIVATION_TANH = 4, - ACTIVATION_SIGMOID = 5, - ACTIVATION_SELU = 6, - ACTIVATION_SWISH = 7, - ACTIVATION_RELU_2 = 8, - ACTIVATION_SOFTMAX = 9, -}; struct Activations { ActivationFunction default_activation = ACTIVATION_RELU; diff --git a/src/neural/shared/activation.ispc b/src/neural/backends/shared/activation.ispc similarity index 100% rename from src/neural/shared/activation.ispc rename to src/neural/backends/shared/activation.ispc diff --git a/src/neural/shared/winograd_filter.cc b/src/neural/backends/shared/winograd_filter.cc similarity index 98% rename from src/neural/shared/winograd_filter.cc rename to src/neural/backends/shared/winograd_filter.cc index 3bedd29596..e985565663 100644 --- a/src/neural/shared/winograd_filter.cc +++ b/src/neural/backends/shared/winograd_filter.cc @@ -16,7 +16,7 @@ along with Leela Chess. If not, see . */ -#include "neural/shared/winograd_filter.h" +#include "neural/backends/shared/winograd_filter.h" #include diff --git a/src/neural/shared/winograd_filter.h b/src/neural/backends/shared/winograd_filter.h similarity index 100% rename from src/neural/shared/winograd_filter.h rename to src/neural/backends/shared/winograd_filter.h diff --git a/src/neural/onnx/converter.cc b/src/neural/onnx/converter.cc index 99ef40744d..8f8ce375d5 100644 --- a/src/neural/onnx/converter.cc +++ b/src/neural/onnx/converter.cc @@ -38,9 +38,9 @@ #include "neural/network_legacy.h" #include "neural/onnx/adapters.h" #include "neural/onnx/builder.h" -#include "neural/shared/activation.h" -#include "neural/shared/attention_policy_map.h" -#include "neural/shared/policy_map.h" +#include "neural/tables/activation_function.h" +#include "neural/tables/attention_policy_map.h" +#include "neural/tables/policy_map.h" #include "proto/net.pb.h" #include "utils/bf16_utils.h" #include "utils/exception.h" diff --git a/src/neural/tables/activation_function.h b/src/neural/tables/activation_function.h new file mode 100644 index 0000000000..689c74446b --- /dev/null +++ b/src/neural/tables/activation_function.h @@ -0,0 +1,37 @@ +/* + This file is part of Leela Chess Zero. + Copyright (C) 2018-2022 The LCZero Authors + + Leela Chess is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Leela Chess 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 Leela Chess. If not, see . + */ + +#pragma once + +namespace lczero { +// The following list matches the one in net.proto. Ideally this would be done +// by including proto/net.pb.h, but this is incompatible with nvcc. +enum ActivationFunction { + ACTIVATION_DEFAULT = 0, + ACTIVATION_MISH = 1, + ACTIVATION_RELU = 2, + ACTIVATION_NONE = 3, + ACTIVATION_TANH = 4, + ACTIVATION_SIGMOID = 5, + ACTIVATION_SELU = 6, + ACTIVATION_SWISH = 7, + ACTIVATION_RELU_2 = 8, + ACTIVATION_SOFTMAX = 9, +}; + +} // namespace lczero diff --git a/src/neural/shared/attention_policy_map.h b/src/neural/tables/attention_policy_map.h similarity index 100% rename from src/neural/shared/attention_policy_map.h rename to src/neural/tables/attention_policy_map.h diff --git a/src/neural/shared/policy_map.h b/src/neural/tables/policy_map.h similarity index 100% rename from src/neural/shared/policy_map.h rename to src/neural/tables/policy_map.h From 283ed55d1286a1f02e65c5778376d598c2d023e4 Mon Sep 17 00:00:00 2001 From: borg323 Date: Fri, 27 Sep 2024 03:23:44 +0300 Subject: [PATCH 6/6] clean up activation sharing --- src/neural/backends/blas/encoder.h | 2 -- src/neural/backends/cuda/common_kernels.cu | 2 +- src/neural/backends/cuda/fp16_kernels.cu | 2 +- src/neural/backends/cuda/kernels.h | 2 +- src/neural/backends/cuda/layers.cc | 1 - src/neural/backends/cuda/layers.h | 2 +- src/neural/backends/cuda/network_cuda.cc | 1 - src/neural/backends/cuda/network_cudnn.cc | 1 - src/neural/backends/onednn/layers.h | 2 +- src/neural/backends/shared/activation.h | 6 ------ src/neural/tables/activation_function.h | 6 ++++++ 11 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/neural/backends/blas/encoder.h b/src/neural/backends/blas/encoder.h index e950b2181d..b4544b16ff 100644 --- a/src/neural/backends/blas/encoder.h +++ b/src/neural/backends/blas/encoder.h @@ -20,8 +20,6 @@ #include -#include "neural/backends/shared/activation.h" - #ifdef USE_ISPC #include "layer_norm_ispc.h" #endif diff --git a/src/neural/backends/cuda/common_kernels.cu b/src/neural/backends/cuda/common_kernels.cu index 20c0d28ae7..ea8801ec2f 100644 --- a/src/neural/backends/cuda/common_kernels.cu +++ b/src/neural/backends/cuda/common_kernels.cu @@ -29,7 +29,7 @@ #include #include "cuda_common.h" -#include "neural/backends/shared/activation.h" +#include "neural/tables/activation_function.h" #include "neural/tables/attention_policy_map.h" #include "winograd_helper.inc" diff --git a/src/neural/backends/cuda/fp16_kernels.cu b/src/neural/backends/cuda/fp16_kernels.cu index 020634f2fd..0d93ca6459 100644 --- a/src/neural/backends/cuda/fp16_kernels.cu +++ b/src/neural/backends/cuda/fp16_kernels.cu @@ -26,7 +26,7 @@ */ #include "cuda_common.h" -#include "neural/backends/shared/activation.h" +#include "neural/tables/activation_function.h" // Allow building on an old architecture. #if __CUDA_ARCH__ < 530 diff --git a/src/neural/backends/cuda/kernels.h b/src/neural/backends/cuda/kernels.h index c836a9bfca..d4d0482a71 100644 --- a/src/neural/backends/cuda/kernels.h +++ b/src/neural/backends/cuda/kernels.h @@ -26,7 +26,7 @@ */ #include "cuda_common.h" -#include "neural/backends/shared/activation.h" +#include "neural/tables/activation_function.h" namespace lczero { namespace cudnn_backend { diff --git a/src/neural/backends/cuda/layers.cc b/src/neural/backends/cuda/layers.cc index 22b4b4bd87..81a0b01b8b 100644 --- a/src/neural/backends/cuda/layers.cc +++ b/src/neural/backends/cuda/layers.cc @@ -32,7 +32,6 @@ #include "cuda_common.h" #include "kernels.h" -#include "neural/backends/shared/activation.h" #include "neural/network.h" #include "neural/tables/attention_policy_map.h" #include "utils/fp16_utils.h" diff --git a/src/neural/backends/cuda/layers.h b/src/neural/backends/cuda/layers.h index 56009d922c..9ba5bd286e 100644 --- a/src/neural/backends/cuda/layers.h +++ b/src/neural/backends/cuda/layers.h @@ -31,8 +31,8 @@ #include #include "cuda_common.h" -#include "neural/backends/shared/activation.h" #include "neural/network_legacy.h" +#include "neural/tables/activation_function.h" #ifdef USE_CUDNN #include diff --git a/src/neural/backends/cuda/network_cuda.cc b/src/neural/backends/cuda/network_cuda.cc index 24760d975e..2382b04c63 100644 --- a/src/neural/backends/cuda/network_cuda.cc +++ b/src/neural/backends/cuda/network_cuda.cc @@ -35,7 +35,6 @@ #include "inputs_outputs.h" #include "kernels.h" #include "layers.h" -#include "neural/backends/shared/activation.h" #include "neural/factory.h" #include "neural/network_legacy.h" #include "neural/tables/attention_policy_map.h" diff --git a/src/neural/backends/cuda/network_cudnn.cc b/src/neural/backends/cuda/network_cudnn.cc index e6d7d1f17e..ea9e341e07 100644 --- a/src/neural/backends/cuda/network_cudnn.cc +++ b/src/neural/backends/cuda/network_cudnn.cc @@ -35,7 +35,6 @@ #include "inputs_outputs.h" #include "kernels.h" #include "layers.h" -#include "neural/backends/shared/activation.h" #include "neural/factory.h" #include "neural/network_legacy.h" #include "neural/tables/attention_policy_map.h" diff --git a/src/neural/backends/onednn/layers.h b/src/neural/backends/onednn/layers.h index 6c162b2e69..0192096a06 100644 --- a/src/neural/backends/onednn/layers.h +++ b/src/neural/backends/onednn/layers.h @@ -26,7 +26,7 @@ */ #pragma once -#include "neural/backends/shared/activation.h" +#include "neural/tables/activation_function.h" #include "utils/exception.h" #include "dnnl.hpp" diff --git a/src/neural/backends/shared/activation.h b/src/neural/backends/shared/activation.h index d4bb2879c1..b786d3435d 100644 --- a/src/neural/backends/shared/activation.h +++ b/src/neural/backends/shared/activation.h @@ -25,12 +25,6 @@ namespace lczero { -struct Activations { - ActivationFunction default_activation = ACTIVATION_RELU; - ActivationFunction smolgen_activation = ACTIVATION_SWISH; - ActivationFunction ffn_activation = ACTIVATION_RELU_2; -}; - // Softmax activation void SoftmaxActivation(const size_t size, const float* input, float* output); diff --git a/src/neural/tables/activation_function.h b/src/neural/tables/activation_function.h index 689c74446b..56a35f5608 100644 --- a/src/neural/tables/activation_function.h +++ b/src/neural/tables/activation_function.h @@ -34,4 +34,10 @@ enum ActivationFunction { ACTIVATION_SOFTMAX = 9, }; +struct Activations { + ActivationFunction default_activation = ACTIVATION_RELU; + ActivationFunction smolgen_activation = ACTIVATION_SWISH; + ActivationFunction ffn_activation = ACTIVATION_RELU_2; +}; + } // namespace lczero