If no chunk_size is specified, OMPScheduleType for kmpc_for_static_init
call is Static and the chunk size is set to 1. If chunk_size is specified,
OMPScheduleType for kmpc_for_static_init call is StaticChunked. Also
fix lowering to LLVM IR for schdule clause in worksharing-loop directive.
Details
Diff Detail
Event Timeline
Generally looks good to me. Just one nit-pick and one "I don't really understand how this actually produces the correct result" (may be that I'm just missing something!)
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | ||
---|---|---|
726 | I may be a bit confused here, but isn't this setting chunk to not-null, and then expecting the apply function to see it as null? | |
mlir/test/Target/LLVMIR/openmp-llvm.mlir | ||
457 | I'd like to see this having a separate name - it makes it so much easier to search the source code when the tests have distinct names! :) |
Change the variable name"const_i32" to "static_chunk_size" and remove redundant code.
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | ||
---|---|---|
726 | This code is the "else" branch, which is for non-static schedule. As OpenMP 5.1 [2.11.4] states, the chunk_size defaults to 1 when it is unspecified for dynamic or guided schedule. The chunk size cannot be specified for runtime or auto schedule. But in implementation, llvm openmp runtime uses kmpc_dispatch_init with the argument "chunk_size" of 1 for runtime or auto schedule. To be short, schedule(static) is NOT the same as schedule(static,1). I noticed "if (!chunk) chunk = one;" is also added in applyDynamicWorkshareLoop in OMPIRBuilder, so remove this code here. |
@peixin is correct. However, a "dispatch" loop is needed in addition to a "chunk" loop, please see TODO in the description of applyStaticWorkshareLoop. This patch would only iterate over chunk_size*omp_get_num_threads() iterations and leave any additional loop iterations unprocessed.
Implementation of static schedule without chunk-size: D114413
@Meinersbur Thanks for the clarification. Can you also handle the fix in mlir part in D114413 (initilize chunk to nullptr and add some test cases in oepnmp-llvm.mlir)? I will close this PR since it is not complete fix.
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | ||
---|---|---|
726 | Thanks, I obviously got confused by the "hidden" bit of code, and thought it was just continuation of the static wsloop code. |
I may be a bit confused here, but isn't this setting chunk to not-null, and then expecting the apply function to see it as null?