Port Multiply.cuh to spla

Đang mở
#290 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
backend, databases

Hướng nghiên cứu

Start with GALATIC/source/device/Multiply.cuh and the private OpenCL mxm wrappers named in the plan, then inspect the existing OpenCL test patterns and registry in src/opencl/cl_algo_registry.cpp. The plan divides the work into buffer/config helpers, the orchestration loop, and public algorithm registration, with focused tests at each stage. Done means the public OpenCL mxm matches the CPU semiring result, stores no additive-identity entries, and the specified verification gates pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

task

Detailed plan: port Multiply.cuh to spla (task #290)

Integration branch: mxm-opencl (stacked mode). Feature branch: feature/290-multiply-cuh, created from mxm-opencl.

Task #290 wires the already ported private OpenCL mxm modules into an end-to-end generic sparse matrix product and registers it for public mxm. The GALATIC orchestrator is GALATIC/source/device/Multiply.cuh; the current whitelisted template tuple is THREADS=128, BLOCKS_PER_MP=1, NNZ_PER_THREAD=2, INPUT_ELEMENTS_PER_THREAD=2, RETAIN_ELEMENTS_PER_THREAD=1, MAX_CHUNKS_TO_MERGE=16, MAX_CHUNKS_GENERALIZED_MERGE=256, MERGE_PATH_OPTIONS=8. User guidance is to preserve GALATIC's two independent restart caps of 128; Algorithm Semantics' "3 times" note does not replace that explicit decision.

S1: Add private multiply configuration and buffer-state helpers [pending]

Code: add src/opencl/cl_mxm_pipeline.hpp in namespace spla::cl_mxm with the fixed GALATIC constants, typed semiring configuration builders for ComputeSpgemmPartConfig, merge configs, ChunksToCsrConfig, an owned typed buffer bundle for all intermediate CSR/chunk/merge/restart arrays, and small host helpers to allocate zeroed buffers, read scalar flags/counters, write/compute starting_ids and per-block nnz, and grow pool/pointer storage without losing published chunks. Reuse the existing fixed 32-bit chunk index layout, WorkSplitConfig::nnz_per_block(), csp_cut_off(), compute_spgemm_part_sort_type_mode(), assign_combine_blocks() case thresholds, and cl_csr_resize(); do not introduce a parallel copy of any sizing or status rule. Add the new header to CMakeLists.txt as a source entry only if the project lists private headers there.

Tests: add host-only validation tests in a new tests/test_opencl_mxm_pipeline.cpp with target_include_directories(... PRIVATE src svector robin_hood) for config derivation: GALATIC constants, restart caps, cut-off derivation, case offsets, and zeroed buffer sizes. Mark new gtest cases with the accelerator-independent main pattern used by other private module tests where possible.

Docs: record in the Code section that the helper layer reuses all existing private wrapper configs and only adds ownership/layout glue, so no public Doxygen or pdoc change is required. Mirror the detailed plan to issue #290.

Spec:

  • No new kernel source is added; no generated source changes are required.
  • Chunk index bits stay 32; compute sort_type_mode remains -1 so the existing wrapper derives GALATIC modes 0/1/2.
  • Flags are read as whole uint values; pool bit is 0x1, pointer bit is 0x2.
  • Restart counters are independent and each fails after 128 restarts, matching GALATIC.
  • Focused config tests must pass with zero failures.

Finding: the private wrappers expose all primitives needed, but no shared owner exists for their transient buffers. The orchestrator therefore needs a typed host-side bundle; duplicating kernel logic is not required.

S2: Implement the full private orchestration loop [pending]

Code: in src/opencl/cl_mxm_pipeline.hpp, add cl_mxm::multiply(queue, R, A, B, op_multiply, op_add, init). Execute the GALATIC sequence: estimate chunk pool; allocate pool and pointer table; run determine_block_starts; build compute starting_ids/nnz; reset run/state arrays; loop compute until flags are zero, growing chunk storage on bit 0x1 and pointer storage on bit 0x2 while rewinding chunk_pointer_alloc from chunk_pointer_position; when compute completes, call assign_combine_blocks once; grow and reset merge restart arrays on shared-row high-water growth; dispatch SIMPLE/MAX_CHUNKS/GENERALIZED with GALATIC restart_offset values; loop merges with the same flag handling and preserve already-published rows; compute final row offsets, determine output nnz, resize CLCsr<T> output, and run chunks_to_csr. Handle a_rows==0 or nnz_a==0 as a valid empty result. Return the first non-Ok status from any private wrapper without publishing a partial public result.

Tests: extend tests/test_opencl_mxm_pipeline.cpp with end-to-end private tests for a small dense-ish product, cancellation to additive identity, a long row that reaches the direct-chunk path, and an empty input. Compare against a CPU reference built from the public semiring functions. Use the existing OpenCL test main/finalize pattern and accelerator limit helpers.

Docs: record in the Code section that GALATIC's Either tags are represented by the existing SPLA restart-kind buffers, CUB BlockScan/BlockRadixSort map to the existing portable SPLA device modules, and no naive scan or sort is introduced. No public API change, so no Doxygen/pdoc update.

Spec:

  • Completion rule: a stage attempt is complete only when its run flag is zero.
  • On pointer restart, only chunk_pointer_alloc is rewound; chunk pool cursor, row heads, row counts, completion status and handled flags are preserved.
  • On pool restart, published chunks and pointer state are preserved; a new same-sized pool is allocated.
  • Merge restart arrays are indexed by block + restart_offset.
  • Final result_offsets is the exclusive prefix sum of output_row_count; the last entry is the output nnz.
  • OpenCL tests must pass with zero failures and zero skipped tests on an available device.

Finding: GALATIC uses three streams for the three merge cases; SPLA's private wrappers take one command queue, so all stages are enqueued in order on the selected default queue. This preserves correctness and all restart semantics while using the existing single-queue accelerator API.

S3: Register the algorithm and add public end-to-end coverage [pending]

Code: add src/opencl/cl_mxm.hpp defining Algo_mxm_cl<T> following Algo_mxmT_masked_cl<T>: validate R writable and A/B readable in FormatMatrix::AccCsr, obtain CLCsr<T> storage, build private configs using get_ttype<T>(), op_multiply, op_add, and the additive-identity literal from init, then call cl_mxm::multiply(). Include the header in src/opencl/cl_algo_registry.cpp and register make_key_cl_0("mxm", INT/UINT/FLOAT). Leave the CPU registration and public API unchanged.

Tests: extend tests/test_mxm.cpp with an OpenCL-backed exec_mxm case that verifies matrix dimensions, sparse output entries, and absence of additive-identity entries. Keep the existing CPU tests unchanged and add an accelerator-gated expectation only where the runtime reports a usable GPU.

Docs: record in this plan that the public exec_mxm API is unchanged and the new algorithm is selected by the existing registry suffix, so no Doxygen/pdoc update is required. Mark T21 done in tasks/global_plan.md. Mirror the final plan state to issue #290.

Spec:

  • R = A * B must match the CPU semiring result for supported scalar types.
  • No additive-identity values are stored in the result.
  • Registry must prefer the OpenCL mxm algorithm whenever acceleration is available and not force-disabled.
  • Final subtask commit message includes standalone Closes #290 and Closes #251 lines.

Finding: public exec_mxm already creates ScheduleTask_mxm and dispatches by registry key; only the missing OpenCL algorithm registration prevents the private pipeline from being selected.

Design notes

  • User guidance recorded verbatim: "Module + wiring (Recommended)", "Yes, full workflow", and "Preserve GALATIC 128".
  • GALATIC source: /home/dmitry-sergeev/SPLA/GALATIC/source/device/Multiply.cuh and GALATIC/include/device/MultiplyKernels.h.
  • CUB primitives observed in the GALATIC call graph: BlockScan, BlockRadixSort, DeviceScan, warp reductions/ballot. SPLA already has portable analogs in block_scan.cl, block_radix_sort.cl, cl_prefix_sum.hpp, and the private mxm wrappers; no naive replacement is introduced.
  • Restart semantics preserve the existing direct OOM behavior from task #289: direct pool/pointer failures set only run-flag bits.

Verification

Run focused build and focused tests after S1, S2 and S3; format all touched C/C++ files with clang-format v21 after each subtask. Final Release quality gate from DEVELOPMENT.md: build, python ./run_tests.py --build-dir=build, find include src tests examples \( -name '*.h' -o -name '*.hpp' -o -name '*.cpp' \) -print0 | xargs -0 clang-format --dry-run -Werror, doxygen Doxyfile, and SPLA_DOCS=true pdoc -o pydocs python/pyspla.

Ngôn ngữ chính
C++
Star
37
Fork
21
Merge trung bình
11 giờ 3 phút
Pull request đã merge (30 ngày)
13

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SparseLinearAlgebra/spla

Tất cả issue của SparseLinearAlgebra/spla

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.