diff --git a/README.md b/README.md index 2730473..9d914d4 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,34 @@ The tool supports the following options: - `--asm` treat the input as SPIR-V assembly in text form. +# Group and sub-group operations + +Use `--cl-std=CL2.0` or `--cl-std=CL3.0` when translating group operations. +The generated source calls OpenCL collective builtins, following the mappings +in Khronos' SPIRV-LLVM-Translator. The target device must support the extensions +used by the module; spirv2clc emits their enabling pragmas. + +Supported operations include: + +* Work-group and sub-group votes, broadcasts, and add/min/max reductions and + inclusive/exclusive scans (`Groups`). Sub-group broadcasts and integer + collectives also support the narrow types from `cl_khr_subgroup_extended_types`. +* Non-uniform votes and election (`cl_khr_subgroup_non_uniform_vote`). +* Ballots, inverse ballots, bit extraction/counting/scanning, first/last set-bit + queries, non-uniform broadcasts, and the five sub-group ballot masks + (`cl_khr_subgroup_ballot`). +* Non-uniform and clustered arithmetic, bitwise, and logical collectives + (`cl_khr_subgroup_non_uniform_arithmetic`, `cl_khr_subgroup_clustered_reduce`). +* Shuffles, relative shuffles, and rotations, including clustered rotations + (`cl_khr_subgroup_shuffle`, `cl_khr_subgroup_shuffle_relative`, + `cl_khr_subgroup_rotate`). +* Sub-group size, ID, count, and enqueued-count queries, and barriers. + +Uniform operations accept work-group or sub-group execution scope. Non-uniform +operations accept sub-group scope. Arithmetic collectives use scalar OpenCL +builtin overloads; vector arithmetic is rejected. Shader quad operations and +vendor-specific sub-group instructions remain unsupported. + # Embedding as a library spirv2clc can be embedded as a library and used as follows: diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b8549d0..45366c7 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -22,6 +22,7 @@ set(SPIRV2CLC_UNITY_SOURCES utils.cpp types.cpp instns.cpp + groups.cpp instns_ext.cpp) add_library(libspirv2clc diff --git a/lib/groups.cpp b/lib/groups.cpp new file mode 100644 index 0000000..90e7a08 --- /dev/null +++ b/lib/groups.cpp @@ -0,0 +1,238 @@ +// Copyright 2020-2022 The spirv2clc authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// OpenCL builtin mappings follow Khronos SPIRV-LLVM-Translator's +// SPIRVToOCL.cpp (groupOCToOCLBuiltinName / visitCallSPIRVGroupBuiltin). +std::optional +translator_impl::translate_group_instruction(const Instruction &inst, + c::expr_ref &result) { + struct builtin { + const char *name; + bool arithmetic; + bool signed_operand; + bool predicate; + bool boolean_result; + }; + static const std::unordered_map builtins = { + {spv::Op::OpGroupAll, {"all", false, false, true, true}}, + {spv::Op::OpGroupAny, {"any", false, false, true, true}}, + {spv::Op::OpGroupBroadcast, {"broadcast", false, false, false, false}}, + {spv::Op::OpGroupNonUniformRotateKHR, + {"rotate", false, false, false, false}}, + {spv::Op::OpGroupNonUniformElect, {"elect", false, false, false, true}}, + {spv::Op::OpGroupNonUniformAll, + {"non_uniform_all", false, false, true, true}}, + {spv::Op::OpGroupNonUniformAny, + {"non_uniform_any", false, false, true, true}}, + {spv::Op::OpGroupNonUniformAllEqual, + {"non_uniform_all_equal", false, false, false, true}}, + {spv::Op::OpGroupNonUniformBroadcast, + {"non_uniform_broadcast", false, false, false, false}}, + {spv::Op::OpGroupNonUniformBroadcastFirst, + {"broadcast_first", false, false, false, false}}, + {spv::Op::OpGroupNonUniformBallot, {"ballot", false, false, true, false}}, + {spv::Op::OpGroupNonUniformInverseBallot, + {"inverse_ballot", false, false, false, true}}, + {spv::Op::OpGroupNonUniformBallotBitExtract, + {"ballot_bit_extract", false, false, false, true}}, + {spv::Op::OpGroupNonUniformBallotFindLSB, + {"ballot_find_lsb", false, false, false, false}}, + {spv::Op::OpGroupNonUniformBallotFindMSB, + {"ballot_find_msb", false, false, false, false}}, + {spv::Op::OpGroupNonUniformShuffle, + {"shuffle", false, false, false, false}}, + {spv::Op::OpGroupNonUniformShuffleXor, + {"shuffle_xor", false, false, false, false}}, + {spv::Op::OpGroupNonUniformShuffleUp, + {"shuffle_up", false, false, false, false}}, + {spv::Op::OpGroupNonUniformShuffleDown, + {"shuffle_down", false, false, false, false}}, + {spv::Op::OpGroupIAdd, {"add", true, false, false, false}}, + {spv::Op::OpGroupFAdd, {"add", true, false, false, false}}, + {spv::Op::OpGroupFMin, {"min", true, false, false, false}}, + {spv::Op::OpGroupUMin, {"min", true, false, false, false}}, + {spv::Op::OpGroupSMin, {"min", true, true, false, false}}, + {spv::Op::OpGroupFMax, {"max", true, false, false, false}}, + {spv::Op::OpGroupUMax, {"max", true, false, false, false}}, + {spv::Op::OpGroupSMax, {"max", true, true, false, false}}, + {spv::Op::OpGroupNonUniformIAdd, {"add", true, false, false, false}}, + {spv::Op::OpGroupNonUniformFAdd, {"add", true, false, false, false}}, + {spv::Op::OpGroupNonUniformIMul, {"mul", true, false, false, false}}, + {spv::Op::OpGroupNonUniformFMul, {"mul", true, false, false, false}}, + {spv::Op::OpGroupNonUniformSMin, {"min", true, true, false, false}}, + {spv::Op::OpGroupNonUniformUMin, {"min", true, false, false, false}}, + {spv::Op::OpGroupNonUniformFMin, {"min", true, false, false, false}}, + {spv::Op::OpGroupNonUniformSMax, {"max", true, true, false, false}}, + {spv::Op::OpGroupNonUniformUMax, {"max", true, false, false, false}}, + {spv::Op::OpGroupNonUniformFMax, {"max", true, false, false, false}}, + {spv::Op::OpGroupNonUniformBitwiseAnd, + {"and", true, false, false, false}}, + {spv::Op::OpGroupNonUniformBitwiseOr, {"or", true, false, false, false}}, + {spv::Op::OpGroupNonUniformBitwiseXor, + {"xor", true, false, false, false}}, + {spv::Op::OpGroupNonUniformLogicalAnd, + {"logical_and", true, false, true, true}}, + {spv::Op::OpGroupNonUniformLogicalOr, + {"logical_or", true, false, true, true}}, + {spv::Op::OpGroupNonUniformLogicalXor, + {"logical_xor", true, false, true, true}}, + {spv::Op::OpGroupNonUniformBallotBitCount, + {"ballot", true, false, false, false}}, + }; + auto it = builtins.find(inst.opcode()); + if (it == builtins.end()) { + return std::nullopt; + } + const auto &fn = it->second; + auto scope = + constant_operand(inst.GetSingleWordOperand(2), "group execution scope"); + if (!scope) { + return false; + } + const bool uniform = inst.opcode() >= spv::Op::OpGroupAll && + inst.opcode() <= spv::Op::OpGroupSMax; + if (*scope != SpvScopeSubgroup && !(uniform && *scope == SpvScopeWorkgroup)) { + std::cerr << "UNIMPLEMENTED group execution scope " << *scope << std::endl; + return false; + } + if (m_opencl_c_version < 200) { + std::cerr << "UNIMPLEMENTED: group operations require OpenCL C 2.0\n"; + return false; + } + if (*scope == SpvScopeSubgroup) { + enable_extension("cl_khr_subgroups"); + } + // Elect only requires GroupNonUniform in SPIR-V, but its OpenCL builtin + // belongs to the non-uniform vote extension. + if (inst.opcode() == spv::Op::OpGroupNonUniformElect) { + enable_extension("cl_khr_subgroup_non_uniform_vote"); + } + std::string name = *scope == SpvScopeSubgroup ? "sub_group_" : "work_group_"; + unsigned first_arg = 3; + if (fn.arithmetic) { + auto operation = inst.GetSingleWordOperand(3); + const bool ballot = + inst.opcode() == spv::Op::OpGroupNonUniformBallotBitCount; + if (!uniform && !ballot) { + enable_extension(operation == SpvGroupOperationClusteredReduce + ? "cl_khr_subgroup_clustered_reduce" + : "cl_khr_subgroup_non_uniform_arithmetic"); + } + if (ballot) { + name += "ballot_"; + } else if (!uniform && operation != SpvGroupOperationClusteredReduce) { + name += "non_uniform_"; + } + switch (operation) { + case SpvGroupOperationReduce: + name += ballot ? "bit_count" : "reduce"; + break; + case SpvGroupOperationInclusiveScan: + name += ballot ? "inclusive_scan" : "scan_inclusive"; + break; + case SpvGroupOperationExclusiveScan: + name += ballot ? "exclusive_scan" : "scan_exclusive"; + break; + case SpvGroupOperationClusteredReduce: + if (uniform || ballot) { + std::cerr << "UNIMPLEMENTED clustered uniform or ballot operation\n"; + return false; + } + name += "clustered_reduce"; + break; + default: + std::cerr << "UNIMPLEMENTED group operation " << operation << std::endl; + return false; + } + if (!ballot) { + name += std::string("_") + fn.name; + } + first_arg = 4; + if (!ballot) { + auto ty = type_for_val(inst.GetSingleWordOperand(first_arg)); + // OpenCL arithmetic collectives have scalar overloads. Uniform integer + // work-group collectives additionally require at least 32 bits. + if (ty->AsVector() || + (uniform && *scope == SpvScopeWorkgroup && ty->AsInteger() && + ty->AsInteger()->width() < 32)) { + std::cerr << "UNIMPLEMENTED group arithmetic operand type\n"; + return false; + } + if (uniform && *scope == SpvScopeSubgroup && ty->AsInteger() && + ty->AsInteger()->width() < 32) { + enable_extension("cl_khr_subgroup_extended_types"); + } + } + } else { + if (inst.opcode() == spv::Op::OpGroupNonUniformRotateKHR && + inst.NumOperands() == 6) { + name += "clustered_"; + } + name += fn.name; + if (inst.opcode() == spv::Op::OpGroupBroadcast) { + auto ty = type_for_val(inst.GetSingleWordOperand(3)); + if (*scope == SpvScopeSubgroup && + (ty->AsVector() || + (ty->AsInteger() && ty->AsInteger()->width() < 32))) { + enable_extension("cl_khr_subgroup_extended_types"); + } else if (*scope == SpvScopeWorkgroup && + (ty->AsVector() || + (ty->AsInteger() && ty->AsInteger()->width() < 32))) { + std::cerr << "UNIMPLEMENTED work-group broadcast operand type\n"; + return false; + } + } + } + const bool ballot = inst.opcode() >= spv::Op::OpGroupNonUniformBallot && + inst.opcode() <= spv::Op::OpGroupNonUniformBallotFindMSB; + const bool has_value = inst.opcode() != spv::Op::OpGroupNonUniformElect; + if (has_value && !ballot && !fn.arithmetic) { + auto ty = type_for_val(inst.GetSingleWordOperand(first_arg)); + if (ty->AsVector() && inst.opcode() != spv::Op::OpGroupBroadcast && + inst.opcode() != spv::Op::OpGroupNonUniformBroadcast) { + std::cerr << "UNIMPLEMENTED subgroup operand type\n"; + return false; + } + } + std::vector args; + for (unsigned i = first_arg; i < inst.NumOperands(); ++i) { + auto id = inst.GetSingleWordOperand(i); + const bool boolean = type_for_val(id)->kind() == Type::Kind::kBool; + if (i == first_arg && fn.signed_operand) { + args.push_back(as_signed(id)); + } else if (inst.opcode() == spv::Op::OpGroupNonUniformRotateKHR && i == 4) { + args.push_back(as_signed(id)); + } else if (i == first_arg && (fn.predicate || boolean)) { + args.push_back(c::cast("int", value(id))); + } else if (inst.opcode() == spv::Op::OpGroupBroadcast && i == 4 && + type_for_val(id)->AsVector()) { + // OpenCL takes a separate coordinate for each work-group dimension. + auto vec = type_for_val(id)->AsVector(); + for (unsigned j = 0; j < vec->element_count(); ++j) { + args.push_back(vector_component(id, j)); + } + } else { + args.push_back(value(id)); + } + } + result = c::call(name, std::move(args)); + if (fn.boolean_result || + type_for(inst.type_id())->kind() == Type::Kind::kBool) { + // OpenCL returns any nonzero int, whereas SPIR-V returns a boolean. + result = c::binary("!=", result, c::literal("0")); + } else if (fn.signed_operand) { + result = cast_to(inst.type_id(), result); + } + return true; +} diff --git a/lib/instns.cpp b/lib/instns.cpp index 3076c66..2901719 100644 --- a/lib/instns.cpp +++ b/lib/instns.cpp @@ -1281,6 +1281,11 @@ bool translator_impl::translate_instruction(const Instruction &inst, if (*exec_scope == SpvScopeWorkgroup) { work_group = true; } else if (*exec_scope == SpvScopeSubgroup) { + if (m_opencl_c_version < 200) { + std::cerr << "UNIMPLEMENTED: subgroup barriers require OpenCL C 2.0\n"; + return false; + } + enable_extension("cl_khr_subgroups"); work_group = false; } else { std::cerr << "UNIMPLEMENTED OpControlBarrier execution scope " @@ -1377,17 +1382,6 @@ bool translator_impl::translate_instruction(const Instruction &inst, } break; } - case spv::Op::OpGroupNonUniformShuffle: - case spv::Op::OpGroupNonUniformShuffleXor: { - // Sub-group shuffle: operands are . The scope is - // Subgroup; map to the cl_khr_subgroups shuffle builtins. - const char *fn = opcode == spv::Op::OpGroupNonUniformShuffle - ? "sub_group_shuffle" - : "sub_group_shuffle_xor"; - val = call_values( - fn, {inst.GetSingleWordOperand(3), inst.GetSingleWordOperand(4)}); - break; - } case spv::Op::OpGroupAsyncCopy: { auto execution_scope = inst.GetSingleWordOperand(2); auto dst_ptr = inst.GetSingleWordOperand(3); @@ -1459,6 +1453,12 @@ bool translator_impl::translate_instruction(const Instruction &inst, break; } default: + if (auto group = translate_group_instruction(inst, val)) { + if (!*group) { + return false; + } + break; + } std::cerr << "UNIMPLEMENTED instruction " << opcode << std::endl; return false; } @@ -1548,10 +1548,22 @@ c::expr_ref translator_impl::builtin_scalar(SpvBuiltIn builtin) const { switch (builtin) { case SpvBuiltInWorkDim: return c::call("get_work_dim", {}); + case SpvBuiltInSubgroupEqMask: + return c::call("get_sub_group_eq_mask", {}); + case SpvBuiltInSubgroupGeMask: + return c::call("get_sub_group_ge_mask", {}); + case SpvBuiltInSubgroupGtMask: + return c::call("get_sub_group_gt_mask", {}); + case SpvBuiltInSubgroupLeMask: + return c::call("get_sub_group_le_mask", {}); + case SpvBuiltInSubgroupLtMask: + return c::call("get_sub_group_lt_mask", {}); case SpvBuiltInSubgroupSize: return c::call("get_sub_group_size", {}); case SpvBuiltInSubgroupMaxSize: return c::call("get_max_sub_group_size", {}); + case SpvBuiltInNumEnqueuedSubgroups: + return c::call("get_enqueued_num_sub_groups", {}); case SpvBuiltInNumSubgroups: return c::call("get_num_sub_groups", {}); case SpvBuiltInSubgroupId: @@ -1566,6 +1578,10 @@ c::expr_ref translator_impl::builtin_scalar(SpvBuiltIn builtin) const { c::expr_ref translator_impl::builtin_vector_extract(SpvBuiltIn builtin, c::expr_ref idx) const { + if (builtin >= SpvBuiltInSubgroupEqMask && + builtin <= SpvBuiltInSubgroupLtMask) { + return c::index(builtin_scalar(builtin), std::move(idx)); + } const char *query; switch (builtin) { case SpvBuiltInGlobalInvocationId: @@ -1597,6 +1613,10 @@ c::expr_ref translator_impl::builtin_vector_extract(SpvBuiltIn builtin, c::expr_ref translator_impl::builtin_value(SpvBuiltIn builtin, uint32_t tyid) const { + if (builtin >= SpvBuiltInSubgroupEqMask && + builtin <= SpvBuiltInSubgroupLtMask) { + return builtin_scalar(builtin); + } auto vec = type_for(tyid)->AsVector(); if (!vec) { return builtin_scalar(builtin); diff --git a/lib/translator.cpp b/lib/translator.cpp index 8b10dab..ed2f3e0 100644 --- a/lib/translator.cpp +++ b/lib/translator.cpp @@ -118,21 +118,23 @@ std::string translator_impl::note_unsupported(const std::string &what) const { return "UNIMPLEMENTED"; } +// Unity sources retain their dependency order. +// clang-format off #include "utils.cpp" #include "types.cpp" +#include "groups.cpp" #include "instns.cpp" #include "instns_ext.cpp" +// clang-format on + +void translator_impl::enable_extension(const char *extension) { + if (m_enabled_extensions.insert(extension).second) { + m_out.extensions << "#pragma OPENCL EXTENSION " << extension + << " : enable\n"; + } +} bool translator_impl::translate_capabilities() { - // Emit each enabling pragma at most once, even when several capabilities map - // to the same extension (e.g. the various subgroup capabilities). - std::unordered_set enabled_extensions; - auto enable_extension = [&](const char *ext) { - if (enabled_extensions.insert(ext).second) { - m_out.extensions << "#pragma OPENCL EXTENSION " << ext << " : enable" - << std::endl; - } - }; // cl_khr_subgroups is an OpenCL C 2.0 extension (promoted to the // __opencl_c_subgroups optional feature in 3.0). The subgroup capabilities // require it; refuse below 2.0 rather than emit an invalid pragma. @@ -208,14 +210,54 @@ bool translator_impl::translate_capabilities() { } break; case SpvCapabilityGroups: + // Groups also covers work-group collectives, which do not need subgroups. + if (m_opencl_c_version < 200) { + std::cerr << "UNIMPLEMENTED: group operations require OpenCL C 2.0\n"; + return false; + } + break; case SpvCapabilityGroupNonUniform: + if (!require_subgroups("group operations")) { + return false; + } + break; + case SpvCapabilityGroupNonUniformVote: + case SpvCapabilityGroupNonUniformArithmetic: + case SpvCapabilityGroupNonUniformBallot: case SpvCapabilityGroupNonUniformShuffle: - // Work-group / sub-group collective builtins (shuffle, ...), all available - // under cl_khr_subgroups. - if (!require_subgroups("subgroups")) { + case SpvCapabilityGroupNonUniformShuffleRelative: + case SpvCapabilityGroupNonUniformClustered: + case SpvCapabilityGroupNonUniformRotateKHR: { + if (!require_subgroups("subgroup operations")) { return false; } + const char *ext = nullptr; + switch (cap) { + case SpvCapabilityGroupNonUniformVote: + ext = "cl_khr_subgroup_non_uniform_vote"; + break; + case SpvCapabilityGroupNonUniformArithmetic: + ext = "cl_khr_subgroup_non_uniform_arithmetic"; + break; + case SpvCapabilityGroupNonUniformBallot: + ext = "cl_khr_subgroup_ballot"; + break; + case SpvCapabilityGroupNonUniformShuffle: + ext = "cl_khr_subgroup_shuffle"; + break; + case SpvCapabilityGroupNonUniformShuffleRelative: + ext = "cl_khr_subgroup_shuffle_relative"; + break; + case SpvCapabilityGroupNonUniformRotateKHR: + ext = "cl_khr_subgroup_rotate"; + break; + case SpvCapabilityGroupNonUniformClustered: + ext = "cl_khr_subgroup_clustered_reduce"; + break; + } + enable_extension(ext); break; + } case SpvCapabilityAtomicFloat32AddEXT: case SpvCapabilityAtomicFloat64AddEXT: case SpvCapabilityAtomicFloat32MinMaxEXT: @@ -237,6 +279,7 @@ bool translator_impl::translate_extensions() const { // capabilities/instructions they enable are handled elsewhere). static const std::unordered_set handled = { "SPV_KHR_no_integer_wrap_decoration", + "SPV_KHR_subgroup_rotate", "SPV_EXT_shader_atomic_float_add", "SPV_EXT_shader_atomic_float_min_max", }; @@ -422,19 +465,27 @@ bool translator_impl::translate_annotations() { case SpvBuiltInWorkDim: m_builtin_variables[target] = static_cast(builtin); break; + case SpvBuiltInSubgroupEqMask: + case SpvBuiltInSubgroupGeMask: + case SpvBuiltInSubgroupGtMask: + case SpvBuiltInSubgroupLeMask: + case SpvBuiltInSubgroupLtMask: case SpvBuiltInSubgroupSize: case SpvBuiltInSubgroupMaxSize: case SpvBuiltInNumSubgroups: + case SpvBuiltInNumEnqueuedSubgroups: case SpvBuiltInSubgroupId: case SpvBuiltInSubgroupLocalInvocationId: - // Mapped to the get_sub_group_*() builtins, which need cl_khr_subgroups - // (OpenCL C 2.0+; the pragma is emitted from the subgroup capability). + // Mapped to the get_sub_group_*() builtins, which need + // cl_khr_subgroups (OpenCL C 2.0+), including when no dispatch + // capability is declared. if (m_opencl_c_version < 200) { std::cerr << "UNIMPLEMENTED: subgroup builtins require OpenCL C 2.0 " "(targeting " << opencl_c_version_str(m_opencl_c_version) << ").\n"; return false; } + enable_extension("cl_khr_subgroups"); m_builtin_variables[target] = static_cast(builtin); break; default: diff --git a/lib/translator.h b/lib/translator.h index 5c494be..a4d578a 100644 --- a/lib/translator.h +++ b/lib/translator.h @@ -293,6 +293,14 @@ struct translator_impl { // reporting) for one OpenCL C has no counterpart for. c::expr_ref memory_scope(uint32_t scope) const; + // Translate OpenCL group builtins, preserving scope, operation and + // signedness. + // No value means this is not a group instruction. + std::optional + translate_group_instruction(const spvtools::opt::Instruction &inst, + c::expr_ref &result); + void enable_extension(const char *extension); + // The CLK_*_MEM_FENCE flags for a SPIR-V memory-semantics mask (0 if no // memory class is set). Shared by the barrier and fence instructions. c::expr_ref fence_flags(uint32_t mem_sem) const; @@ -427,6 +435,7 @@ struct translator_impl { m_translation_failed = false; m_read_write_images = false; m_out = output(); + m_enabled_extensions.clear(); m_name_allocator = name_allocator(); m_debug_names.clear(); m_names.clear(); @@ -465,6 +474,7 @@ struct translator_impl { std::unique_ptr m_ir; output m_out; + std::unordered_set m_enabled_extensions; name_allocator m_name_allocator; // OpName strings, as given. std::unordered_map m_debug_names; diff --git a/tests/cases/group_collectives.spt b/tests/cases/group_collectives.spt new file mode 100644 index 0000000..a530d60 --- /dev/null +++ b/tests/cases/group_collectives.spt @@ -0,0 +1,203 @@ +; Uniform votes, broadcasts, and all add/min/max reduction and scan mappings. +; Signed min/max must use signed overloads even though SPIR-V integers are +; stored unsigned. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability Groups + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %sg_all "sg_all" + OpName %sg_any "sg_any" + OpName %sg_broadcast1 "sg_broadcast1" + OpName %sg_IAdd_Reduce "sg_IAdd_Reduce" + OpName %sg_IAdd_InclusiveScan "sg_IAdd_InclusiveScan" + OpName %sg_IAdd_ExclusiveScan "sg_IAdd_ExclusiveScan" + OpName %sg_FAdd_Reduce "sg_FAdd_Reduce" + OpName %sg_FAdd_InclusiveScan "sg_FAdd_InclusiveScan" + OpName %sg_FAdd_ExclusiveScan "sg_FAdd_ExclusiveScan" + OpName %sg_FMin_Reduce "sg_FMin_Reduce" + OpName %sg_FMin_InclusiveScan "sg_FMin_InclusiveScan" + OpName %sg_FMin_ExclusiveScan "sg_FMin_ExclusiveScan" + OpName %sg_UMin_Reduce "sg_UMin_Reduce" + OpName %sg_UMin_InclusiveScan "sg_UMin_InclusiveScan" + OpName %sg_UMin_ExclusiveScan "sg_UMin_ExclusiveScan" + OpName %sg_SMin_Reduce "sg_SMin_Reduce" + OpName %sg_SMin_InclusiveScan "sg_SMin_InclusiveScan" + OpName %sg_SMin_ExclusiveScan "sg_SMin_ExclusiveScan" + OpName %sg_FMax_Reduce "sg_FMax_Reduce" + OpName %sg_FMax_InclusiveScan "sg_FMax_InclusiveScan" + OpName %sg_FMax_ExclusiveScan "sg_FMax_ExclusiveScan" + OpName %sg_UMax_Reduce "sg_UMax_Reduce" + OpName %sg_UMax_InclusiveScan "sg_UMax_InclusiveScan" + OpName %sg_UMax_ExclusiveScan "sg_UMax_ExclusiveScan" + OpName %sg_SMax_Reduce "sg_SMax_Reduce" + OpName %sg_SMax_InclusiveScan "sg_SMax_InclusiveScan" + OpName %sg_SMax_ExclusiveScan "sg_SMax_ExclusiveScan" + OpName %wg_all "wg_all" + OpName %wg_any "wg_any" + OpName %wg_broadcast1 "wg_broadcast1" + OpName %wg_broadcast2 "wg_broadcast2" + OpName %wg_broadcast3 "wg_broadcast3" + OpName %wg_IAdd_Reduce "wg_IAdd_Reduce" + OpName %wg_IAdd_InclusiveScan "wg_IAdd_InclusiveScan" + OpName %wg_IAdd_ExclusiveScan "wg_IAdd_ExclusiveScan" + OpName %wg_FAdd_Reduce "wg_FAdd_Reduce" + OpName %wg_FAdd_InclusiveScan "wg_FAdd_InclusiveScan" + OpName %wg_FAdd_ExclusiveScan "wg_FAdd_ExclusiveScan" + OpName %wg_FMin_Reduce "wg_FMin_Reduce" + OpName %wg_FMin_InclusiveScan "wg_FMin_InclusiveScan" + OpName %wg_FMin_ExclusiveScan "wg_FMin_ExclusiveScan" + OpName %wg_UMin_Reduce "wg_UMin_Reduce" + OpName %wg_UMin_InclusiveScan "wg_UMin_InclusiveScan" + OpName %wg_UMin_ExclusiveScan "wg_UMin_ExclusiveScan" + OpName %wg_SMin_Reduce "wg_SMin_Reduce" + OpName %wg_SMin_InclusiveScan "wg_SMin_InclusiveScan" + OpName %wg_SMin_ExclusiveScan "wg_SMin_ExclusiveScan" + OpName %wg_FMax_Reduce "wg_FMax_Reduce" + OpName %wg_FMax_InclusiveScan "wg_FMax_InclusiveScan" + OpName %wg_FMax_ExclusiveScan "wg_FMax_ExclusiveScan" + OpName %wg_UMax_Reduce "wg_UMax_Reduce" + OpName %wg_UMax_InclusiveScan "wg_UMax_InclusiveScan" + OpName %wg_UMax_ExclusiveScan "wg_UMax_ExclusiveScan" + OpName %wg_SMax_Reduce "wg_SMax_Reduce" + OpName %wg_SMax_InclusiveScan "wg_SMax_InclusiveScan" + OpName %wg_SMax_ExclusiveScan "wg_SMax_ExclusiveScan" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %sg_all = OpGroupAll %bool %sg %true + %sg_any = OpGroupAny %bool %sg %true + %sg_broadcast1 = OpGroupBroadcast %uint %sg %val %id + %sg_IAdd_Reduce = OpGroupIAdd %uint %sg Reduce %val + %sg_IAdd_InclusiveScan = OpGroupIAdd %uint %sg InclusiveScan %val + %sg_IAdd_ExclusiveScan = OpGroupIAdd %uint %sg ExclusiveScan %val + %sg_FAdd_Reduce = OpGroupFAdd %f32 %sg Reduce %fval + %sg_FAdd_InclusiveScan = OpGroupFAdd %f32 %sg InclusiveScan %fval + %sg_FAdd_ExclusiveScan = OpGroupFAdd %f32 %sg ExclusiveScan %fval + %sg_FMin_Reduce = OpGroupFMin %f32 %sg Reduce %fval + %sg_FMin_InclusiveScan = OpGroupFMin %f32 %sg InclusiveScan %fval + %sg_FMin_ExclusiveScan = OpGroupFMin %f32 %sg ExclusiveScan %fval + %sg_UMin_Reduce = OpGroupUMin %uint %sg Reduce %val + %sg_UMin_InclusiveScan = OpGroupUMin %uint %sg InclusiveScan %val + %sg_UMin_ExclusiveScan = OpGroupUMin %uint %sg ExclusiveScan %val + %sg_SMin_Reduce = OpGroupSMin %uint %sg Reduce %val + %sg_SMin_InclusiveScan = OpGroupSMin %uint %sg InclusiveScan %val + %sg_SMin_ExclusiveScan = OpGroupSMin %uint %sg ExclusiveScan %val + %sg_FMax_Reduce = OpGroupFMax %f32 %sg Reduce %fval + %sg_FMax_InclusiveScan = OpGroupFMax %f32 %sg InclusiveScan %fval + %sg_FMax_ExclusiveScan = OpGroupFMax %f32 %sg ExclusiveScan %fval + %sg_UMax_Reduce = OpGroupUMax %uint %sg Reduce %val + %sg_UMax_InclusiveScan = OpGroupUMax %uint %sg InclusiveScan %val + %sg_UMax_ExclusiveScan = OpGroupUMax %uint %sg ExclusiveScan %val + %sg_SMax_Reduce = OpGroupSMax %uint %sg Reduce %val + %sg_SMax_InclusiveScan = OpGroupSMax %uint %sg InclusiveScan %val + %sg_SMax_ExclusiveScan = OpGroupSMax %uint %sg ExclusiveScan %val + %wg_all = OpGroupAll %bool %wg %true + %wg_any = OpGroupAny %bool %wg %true + %wg_broadcast1 = OpGroupBroadcast %uint %wg %val %id + %wg_broadcast2 = OpGroupBroadcast %uint %wg %val %coord2 + %wg_broadcast3 = OpGroupBroadcast %uint %wg %val %coord3 + %wg_IAdd_Reduce = OpGroupIAdd %uint %wg Reduce %val + %wg_IAdd_InclusiveScan = OpGroupIAdd %uint %wg InclusiveScan %val + %wg_IAdd_ExclusiveScan = OpGroupIAdd %uint %wg ExclusiveScan %val + %wg_FAdd_Reduce = OpGroupFAdd %f32 %wg Reduce %fval + %wg_FAdd_InclusiveScan = OpGroupFAdd %f32 %wg InclusiveScan %fval + %wg_FAdd_ExclusiveScan = OpGroupFAdd %f32 %wg ExclusiveScan %fval + %wg_FMin_Reduce = OpGroupFMin %f32 %wg Reduce %fval + %wg_FMin_InclusiveScan = OpGroupFMin %f32 %wg InclusiveScan %fval + %wg_FMin_ExclusiveScan = OpGroupFMin %f32 %wg ExclusiveScan %fval + %wg_UMin_Reduce = OpGroupUMin %uint %wg Reduce %val + %wg_UMin_InclusiveScan = OpGroupUMin %uint %wg InclusiveScan %val + %wg_UMin_ExclusiveScan = OpGroupUMin %uint %wg ExclusiveScan %val + %wg_SMin_Reduce = OpGroupSMin %uint %wg Reduce %val + %wg_SMin_InclusiveScan = OpGroupSMin %uint %wg InclusiveScan %val + %wg_SMin_ExclusiveScan = OpGroupSMin %uint %wg ExclusiveScan %val + %wg_FMax_Reduce = OpGroupFMax %f32 %wg Reduce %fval + %wg_FMax_InclusiveScan = OpGroupFMax %f32 %wg InclusiveScan %fval + %wg_FMax_ExclusiveScan = OpGroupFMax %f32 %wg ExclusiveScan %fval + %wg_UMax_Reduce = OpGroupUMax %uint %wg Reduce %val + %wg_UMax_InclusiveScan = OpGroupUMax %uint %wg InclusiveScan %val + %wg_UMax_ExclusiveScan = OpGroupUMax %uint %wg ExclusiveScan %val + %wg_SMax_Reduce = OpGroupSMax %uint %wg Reduce %val + %wg_SMax_InclusiveScan = OpGroupSMax %uint %wg InclusiveScan %val + %wg_SMax_ExclusiveScan = OpGroupSMax %uint %wg ExclusiveScan %val + OpReturn + OpFunctionEnd + +; CHECK-DAG: sg_all = sub_group_all((int)true) != 0 +; CHECK-DAG: sg_any = sub_group_any((int)true) != 0 +; CHECK-DAG: sg_broadcast1 = sub_group_broadcast( +; CHECK-DAG: sg_IAdd_Reduce = sub_group_reduce_add( +; CHECK-DAG: sg_IAdd_InclusiveScan = sub_group_scan_inclusive_add( +; CHECK-DAG: sg_IAdd_ExclusiveScan = sub_group_scan_exclusive_add( +; CHECK-DAG: sg_FAdd_Reduce = sub_group_reduce_add( +; CHECK-DAG: sg_FAdd_InclusiveScan = sub_group_scan_inclusive_add( +; CHECK-DAG: sg_FAdd_ExclusiveScan = sub_group_scan_exclusive_add( +; CHECK-DAG: sg_FMin_Reduce = sub_group_reduce_min( +; CHECK-DAG: sg_FMin_InclusiveScan = sub_group_scan_inclusive_min( +; CHECK-DAG: sg_FMin_ExclusiveScan = sub_group_scan_exclusive_min( +; CHECK-DAG: sg_UMin_Reduce = sub_group_reduce_min( +; CHECK-DAG: sg_UMin_InclusiveScan = sub_group_scan_inclusive_min( +; CHECK-DAG: sg_UMin_ExclusiveScan = sub_group_scan_exclusive_min( +; CHECK-DAG: sg_SMin_Reduce = (uint)sub_group_reduce_min(as_int( +; CHECK-DAG: sg_SMin_InclusiveScan = (uint)sub_group_scan_inclusive_min(as_int( +; CHECK-DAG: sg_SMin_ExclusiveScan = (uint)sub_group_scan_exclusive_min(as_int( +; CHECK-DAG: sg_FMax_Reduce = sub_group_reduce_max( +; CHECK-DAG: sg_FMax_InclusiveScan = sub_group_scan_inclusive_max( +; CHECK-DAG: sg_FMax_ExclusiveScan = sub_group_scan_exclusive_max( +; CHECK-DAG: sg_UMax_Reduce = sub_group_reduce_max( +; CHECK-DAG: sg_UMax_InclusiveScan = sub_group_scan_inclusive_max( +; CHECK-DAG: sg_UMax_ExclusiveScan = sub_group_scan_exclusive_max( +; CHECK-DAG: sg_SMax_Reduce = (uint)sub_group_reduce_max(as_int( +; CHECK-DAG: sg_SMax_InclusiveScan = (uint)sub_group_scan_inclusive_max(as_int( +; CHECK-DAG: sg_SMax_ExclusiveScan = (uint)sub_group_scan_exclusive_max(as_int( +; CHECK-DAG: wg_all = work_group_all((int)true) != 0 +; CHECK-DAG: wg_any = work_group_any((int)true) != 0 +; CHECK-DAG: wg_broadcast1 = work_group_broadcast( +; CHECK-DAG: wg_broadcast2 = work_group_broadcast( +; CHECK-DAG: wg_broadcast3 = work_group_broadcast( +; CHECK-DAG: wg_IAdd_Reduce = work_group_reduce_add( +; CHECK-DAG: wg_IAdd_InclusiveScan = work_group_scan_inclusive_add( +; CHECK-DAG: wg_IAdd_ExclusiveScan = work_group_scan_exclusive_add( +; CHECK-DAG: wg_FAdd_Reduce = work_group_reduce_add( +; CHECK-DAG: wg_FAdd_InclusiveScan = work_group_scan_inclusive_add( +; CHECK-DAG: wg_FAdd_ExclusiveScan = work_group_scan_exclusive_add( +; CHECK-DAG: wg_FMin_Reduce = work_group_reduce_min( +; CHECK-DAG: wg_FMin_InclusiveScan = work_group_scan_inclusive_min( +; CHECK-DAG: wg_FMin_ExclusiveScan = work_group_scan_exclusive_min( +; CHECK-DAG: wg_UMin_Reduce = work_group_reduce_min( +; CHECK-DAG: wg_UMin_InclusiveScan = work_group_scan_inclusive_min( +; CHECK-DAG: wg_UMin_ExclusiveScan = work_group_scan_exclusive_min( +; CHECK-DAG: wg_SMin_Reduce = (uint)work_group_reduce_min(as_int( +; CHECK-DAG: wg_SMin_InclusiveScan = (uint)work_group_scan_inclusive_min(as_int( +; CHECK-DAG: wg_SMin_ExclusiveScan = (uint)work_group_scan_exclusive_min(as_int( +; CHECK-DAG: wg_FMax_Reduce = work_group_reduce_max( +; CHECK-DAG: wg_FMax_InclusiveScan = work_group_scan_inclusive_max( +; CHECK-DAG: wg_FMax_ExclusiveScan = work_group_scan_exclusive_max( +; CHECK-DAG: wg_UMax_Reduce = work_group_reduce_max( +; CHECK-DAG: wg_UMax_InclusiveScan = work_group_scan_inclusive_max( +; CHECK-DAG: wg_UMax_ExclusiveScan = work_group_scan_exclusive_max( +; CHECK-DAG: wg_SMax_Reduce = (uint)work_group_reduce_max(as_int( +; CHECK-DAG: wg_SMax_InclusiveScan = (uint)work_group_scan_inclusive_max(as_int( +; CHECK-DAG: wg_SMax_ExclusiveScan = (uint)work_group_scan_exclusive_max(as_int( diff --git a/tests/cases/subgroup_arithmetic.spt b/tests/cases/subgroup_arithmetic.spt new file mode 100644 index 0000000..35bbe92 --- /dev/null +++ b/tests/cases/subgroup_arithmetic.spt @@ -0,0 +1,227 @@ +; Non-uniform and clustered arithmetic, bitwise, and logical operations. Check +; all three reduction/scan modes and clustered argument order. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformArithmetic + OpCapability GroupNonUniformClustered + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %IAdd_Reduce "IAdd_Reduce" + OpName %IAdd_InclusiveScan "IAdd_InclusiveScan" + OpName %IAdd_ExclusiveScan "IAdd_ExclusiveScan" + OpName %IAdd_ClusteredReduce "IAdd_ClusteredReduce" + OpName %FAdd_Reduce "FAdd_Reduce" + OpName %FAdd_InclusiveScan "FAdd_InclusiveScan" + OpName %FAdd_ExclusiveScan "FAdd_ExclusiveScan" + OpName %FAdd_ClusteredReduce "FAdd_ClusteredReduce" + OpName %IMul_Reduce "IMul_Reduce" + OpName %IMul_InclusiveScan "IMul_InclusiveScan" + OpName %IMul_ExclusiveScan "IMul_ExclusiveScan" + OpName %IMul_ClusteredReduce "IMul_ClusteredReduce" + OpName %FMul_Reduce "FMul_Reduce" + OpName %FMul_InclusiveScan "FMul_InclusiveScan" + OpName %FMul_ExclusiveScan "FMul_ExclusiveScan" + OpName %FMul_ClusteredReduce "FMul_ClusteredReduce" + OpName %SMin_Reduce "SMin_Reduce" + OpName %SMin_InclusiveScan "SMin_InclusiveScan" + OpName %SMin_ExclusiveScan "SMin_ExclusiveScan" + OpName %SMin_ClusteredReduce "SMin_ClusteredReduce" + OpName %UMin_Reduce "UMin_Reduce" + OpName %UMin_InclusiveScan "UMin_InclusiveScan" + OpName %UMin_ExclusiveScan "UMin_ExclusiveScan" + OpName %UMin_ClusteredReduce "UMin_ClusteredReduce" + OpName %FMin_Reduce "FMin_Reduce" + OpName %FMin_InclusiveScan "FMin_InclusiveScan" + OpName %FMin_ExclusiveScan "FMin_ExclusiveScan" + OpName %FMin_ClusteredReduce "FMin_ClusteredReduce" + OpName %SMax_Reduce "SMax_Reduce" + OpName %SMax_InclusiveScan "SMax_InclusiveScan" + OpName %SMax_ExclusiveScan "SMax_ExclusiveScan" + OpName %SMax_ClusteredReduce "SMax_ClusteredReduce" + OpName %UMax_Reduce "UMax_Reduce" + OpName %UMax_InclusiveScan "UMax_InclusiveScan" + OpName %UMax_ExclusiveScan "UMax_ExclusiveScan" + OpName %UMax_ClusteredReduce "UMax_ClusteredReduce" + OpName %FMax_Reduce "FMax_Reduce" + OpName %FMax_InclusiveScan "FMax_InclusiveScan" + OpName %FMax_ExclusiveScan "FMax_ExclusiveScan" + OpName %FMax_ClusteredReduce "FMax_ClusteredReduce" + OpName %BitwiseAnd_Reduce "BitwiseAnd_Reduce" + OpName %BitwiseAnd_InclusiveScan "BitwiseAnd_InclusiveScan" + OpName %BitwiseAnd_ExclusiveScan "BitwiseAnd_ExclusiveScan" + OpName %BitwiseAnd_ClusteredReduce "BitwiseAnd_ClusteredReduce" + OpName %BitwiseOr_Reduce "BitwiseOr_Reduce" + OpName %BitwiseOr_InclusiveScan "BitwiseOr_InclusiveScan" + OpName %BitwiseOr_ExclusiveScan "BitwiseOr_ExclusiveScan" + OpName %BitwiseOr_ClusteredReduce "BitwiseOr_ClusteredReduce" + OpName %BitwiseXor_Reduce "BitwiseXor_Reduce" + OpName %BitwiseXor_InclusiveScan "BitwiseXor_InclusiveScan" + OpName %BitwiseXor_ExclusiveScan "BitwiseXor_ExclusiveScan" + OpName %BitwiseXor_ClusteredReduce "BitwiseXor_ClusteredReduce" + OpName %LogicalAnd_Reduce "LogicalAnd_Reduce" + OpName %LogicalAnd_InclusiveScan "LogicalAnd_InclusiveScan" + OpName %LogicalAnd_ExclusiveScan "LogicalAnd_ExclusiveScan" + OpName %LogicalAnd_ClusteredReduce "LogicalAnd_ClusteredReduce" + OpName %LogicalOr_Reduce "LogicalOr_Reduce" + OpName %LogicalOr_InclusiveScan "LogicalOr_InclusiveScan" + OpName %LogicalOr_ExclusiveScan "LogicalOr_ExclusiveScan" + OpName %LogicalOr_ClusteredReduce "LogicalOr_ClusteredReduce" + OpName %LogicalXor_Reduce "LogicalXor_Reduce" + OpName %LogicalXor_InclusiveScan "LogicalXor_InclusiveScan" + OpName %LogicalXor_ExclusiveScan "LogicalXor_ExclusiveScan" + OpName %LogicalXor_ClusteredReduce "LogicalXor_ClusteredReduce" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %IAdd_Reduce = OpGroupNonUniformIAdd %uint %sg Reduce %val + %IAdd_InclusiveScan = OpGroupNonUniformIAdd %uint %sg InclusiveScan %val + %IAdd_ExclusiveScan = OpGroupNonUniformIAdd %uint %sg ExclusiveScan %val + %IAdd_ClusteredReduce = OpGroupNonUniformIAdd %uint %sg ClusteredReduce %val %cluster + %FAdd_Reduce = OpGroupNonUniformFAdd %f32 %sg Reduce %fval + %FAdd_InclusiveScan = OpGroupNonUniformFAdd %f32 %sg InclusiveScan %fval + %FAdd_ExclusiveScan = OpGroupNonUniformFAdd %f32 %sg ExclusiveScan %fval + %FAdd_ClusteredReduce = OpGroupNonUniformFAdd %f32 %sg ClusteredReduce %fval %cluster + %IMul_Reduce = OpGroupNonUniformIMul %uint %sg Reduce %val + %IMul_InclusiveScan = OpGroupNonUniformIMul %uint %sg InclusiveScan %val + %IMul_ExclusiveScan = OpGroupNonUniformIMul %uint %sg ExclusiveScan %val + %IMul_ClusteredReduce = OpGroupNonUniformIMul %uint %sg ClusteredReduce %val %cluster + %FMul_Reduce = OpGroupNonUniformFMul %f32 %sg Reduce %fval + %FMul_InclusiveScan = OpGroupNonUniformFMul %f32 %sg InclusiveScan %fval + %FMul_ExclusiveScan = OpGroupNonUniformFMul %f32 %sg ExclusiveScan %fval + %FMul_ClusteredReduce = OpGroupNonUniformFMul %f32 %sg ClusteredReduce %fval %cluster + %SMin_Reduce = OpGroupNonUniformSMin %uint %sg Reduce %val + %SMin_InclusiveScan = OpGroupNonUniformSMin %uint %sg InclusiveScan %val + %SMin_ExclusiveScan = OpGroupNonUniformSMin %uint %sg ExclusiveScan %val + %SMin_ClusteredReduce = OpGroupNonUniformSMin %uint %sg ClusteredReduce %val %cluster + %UMin_Reduce = OpGroupNonUniformUMin %uint %sg Reduce %val + %UMin_InclusiveScan = OpGroupNonUniformUMin %uint %sg InclusiveScan %val + %UMin_ExclusiveScan = OpGroupNonUniformUMin %uint %sg ExclusiveScan %val + %UMin_ClusteredReduce = OpGroupNonUniformUMin %uint %sg ClusteredReduce %val %cluster + %FMin_Reduce = OpGroupNonUniformFMin %f32 %sg Reduce %fval + %FMin_InclusiveScan = OpGroupNonUniformFMin %f32 %sg InclusiveScan %fval + %FMin_ExclusiveScan = OpGroupNonUniformFMin %f32 %sg ExclusiveScan %fval + %FMin_ClusteredReduce = OpGroupNonUniformFMin %f32 %sg ClusteredReduce %fval %cluster + %SMax_Reduce = OpGroupNonUniformSMax %uint %sg Reduce %val + %SMax_InclusiveScan = OpGroupNonUniformSMax %uint %sg InclusiveScan %val + %SMax_ExclusiveScan = OpGroupNonUniformSMax %uint %sg ExclusiveScan %val + %SMax_ClusteredReduce = OpGroupNonUniformSMax %uint %sg ClusteredReduce %val %cluster + %UMax_Reduce = OpGroupNonUniformUMax %uint %sg Reduce %val + %UMax_InclusiveScan = OpGroupNonUniformUMax %uint %sg InclusiveScan %val + %UMax_ExclusiveScan = OpGroupNonUniformUMax %uint %sg ExclusiveScan %val + %UMax_ClusteredReduce = OpGroupNonUniformUMax %uint %sg ClusteredReduce %val %cluster + %FMax_Reduce = OpGroupNonUniformFMax %f32 %sg Reduce %fval + %FMax_InclusiveScan = OpGroupNonUniformFMax %f32 %sg InclusiveScan %fval + %FMax_ExclusiveScan = OpGroupNonUniformFMax %f32 %sg ExclusiveScan %fval + %FMax_ClusteredReduce = OpGroupNonUniformFMax %f32 %sg ClusteredReduce %fval %cluster + %BitwiseAnd_Reduce = OpGroupNonUniformBitwiseAnd %uint %sg Reduce %val + %BitwiseAnd_InclusiveScan = OpGroupNonUniformBitwiseAnd %uint %sg InclusiveScan %val + %BitwiseAnd_ExclusiveScan = OpGroupNonUniformBitwiseAnd %uint %sg ExclusiveScan %val + %BitwiseAnd_ClusteredReduce = OpGroupNonUniformBitwiseAnd %uint %sg ClusteredReduce %val %cluster + %BitwiseOr_Reduce = OpGroupNonUniformBitwiseOr %uint %sg Reduce %val + %BitwiseOr_InclusiveScan = OpGroupNonUniformBitwiseOr %uint %sg InclusiveScan %val + %BitwiseOr_ExclusiveScan = OpGroupNonUniformBitwiseOr %uint %sg ExclusiveScan %val + %BitwiseOr_ClusteredReduce = OpGroupNonUniformBitwiseOr %uint %sg ClusteredReduce %val %cluster + %BitwiseXor_Reduce = OpGroupNonUniformBitwiseXor %uint %sg Reduce %val + %BitwiseXor_InclusiveScan = OpGroupNonUniformBitwiseXor %uint %sg InclusiveScan %val + %BitwiseXor_ExclusiveScan = OpGroupNonUniformBitwiseXor %uint %sg ExclusiveScan %val + %BitwiseXor_ClusteredReduce = OpGroupNonUniformBitwiseXor %uint %sg ClusteredReduce %val %cluster + %LogicalAnd_Reduce = OpGroupNonUniformLogicalAnd %bool %sg Reduce %true + %LogicalAnd_InclusiveScan = OpGroupNonUniformLogicalAnd %bool %sg InclusiveScan %true + %LogicalAnd_ExclusiveScan = OpGroupNonUniformLogicalAnd %bool %sg ExclusiveScan %true + %LogicalAnd_ClusteredReduce = OpGroupNonUniformLogicalAnd %bool %sg ClusteredReduce %true %cluster + %LogicalOr_Reduce = OpGroupNonUniformLogicalOr %bool %sg Reduce %true + %LogicalOr_InclusiveScan = OpGroupNonUniformLogicalOr %bool %sg InclusiveScan %true + %LogicalOr_ExclusiveScan = OpGroupNonUniformLogicalOr %bool %sg ExclusiveScan %true + %LogicalOr_ClusteredReduce = OpGroupNonUniformLogicalOr %bool %sg ClusteredReduce %true %cluster + %LogicalXor_Reduce = OpGroupNonUniformLogicalXor %bool %sg Reduce %true + %LogicalXor_InclusiveScan = OpGroupNonUniformLogicalXor %bool %sg InclusiveScan %true + %LogicalXor_ExclusiveScan = OpGroupNonUniformLogicalXor %bool %sg ExclusiveScan %true + %LogicalXor_ClusteredReduce = OpGroupNonUniformLogicalXor %bool %sg ClusteredReduce %true %cluster + OpReturn + OpFunctionEnd + +; CHECK-DAG: IAdd_Reduce = sub_group_non_uniform_reduce_add( +; CHECK-DAG: IAdd_InclusiveScan = sub_group_non_uniform_scan_inclusive_add( +; CHECK-DAG: IAdd_ExclusiveScan = sub_group_non_uniform_scan_exclusive_add( +; CHECK-DAG: IAdd_ClusteredReduce = sub_group_clustered_reduce_add( +; CHECK-DAG: FAdd_Reduce = sub_group_non_uniform_reduce_add( +; CHECK-DAG: FAdd_InclusiveScan = sub_group_non_uniform_scan_inclusive_add( +; CHECK-DAG: FAdd_ExclusiveScan = sub_group_non_uniform_scan_exclusive_add( +; CHECK-DAG: FAdd_ClusteredReduce = sub_group_clustered_reduce_add( +; CHECK-DAG: IMul_Reduce = sub_group_non_uniform_reduce_mul( +; CHECK-DAG: IMul_InclusiveScan = sub_group_non_uniform_scan_inclusive_mul( +; CHECK-DAG: IMul_ExclusiveScan = sub_group_non_uniform_scan_exclusive_mul( +; CHECK-DAG: IMul_ClusteredReduce = sub_group_clustered_reduce_mul( +; CHECK-DAG: FMul_Reduce = sub_group_non_uniform_reduce_mul( +; CHECK-DAG: FMul_InclusiveScan = sub_group_non_uniform_scan_inclusive_mul( +; CHECK-DAG: FMul_ExclusiveScan = sub_group_non_uniform_scan_exclusive_mul( +; CHECK-DAG: FMul_ClusteredReduce = sub_group_clustered_reduce_mul( +; CHECK-DAG: SMin_Reduce = (uint)sub_group_non_uniform_reduce_min(as_int( +; CHECK-DAG: SMin_InclusiveScan = (uint)sub_group_non_uniform_scan_inclusive_min(as_int( +; CHECK-DAG: SMin_ExclusiveScan = (uint)sub_group_non_uniform_scan_exclusive_min(as_int( +; CHECK-DAG: SMin_ClusteredReduce = (uint)sub_group_clustered_reduce_min(as_int( +; CHECK-DAG: UMin_Reduce = sub_group_non_uniform_reduce_min( +; CHECK-DAG: UMin_InclusiveScan = sub_group_non_uniform_scan_inclusive_min( +; CHECK-DAG: UMin_ExclusiveScan = sub_group_non_uniform_scan_exclusive_min( +; CHECK-DAG: UMin_ClusteredReduce = sub_group_clustered_reduce_min( +; CHECK-DAG: FMin_Reduce = sub_group_non_uniform_reduce_min( +; CHECK-DAG: FMin_InclusiveScan = sub_group_non_uniform_scan_inclusive_min( +; CHECK-DAG: FMin_ExclusiveScan = sub_group_non_uniform_scan_exclusive_min( +; CHECK-DAG: FMin_ClusteredReduce = sub_group_clustered_reduce_min( +; CHECK-DAG: SMax_Reduce = (uint)sub_group_non_uniform_reduce_max(as_int( +; CHECK-DAG: SMax_InclusiveScan = (uint)sub_group_non_uniform_scan_inclusive_max(as_int( +; CHECK-DAG: SMax_ExclusiveScan = (uint)sub_group_non_uniform_scan_exclusive_max(as_int( +; CHECK-DAG: SMax_ClusteredReduce = (uint)sub_group_clustered_reduce_max(as_int( +; CHECK-DAG: UMax_Reduce = sub_group_non_uniform_reduce_max( +; CHECK-DAG: UMax_InclusiveScan = sub_group_non_uniform_scan_inclusive_max( +; CHECK-DAG: UMax_ExclusiveScan = sub_group_non_uniform_scan_exclusive_max( +; CHECK-DAG: UMax_ClusteredReduce = sub_group_clustered_reduce_max( +; CHECK-DAG: FMax_Reduce = sub_group_non_uniform_reduce_max( +; CHECK-DAG: FMax_InclusiveScan = sub_group_non_uniform_scan_inclusive_max( +; CHECK-DAG: FMax_ExclusiveScan = sub_group_non_uniform_scan_exclusive_max( +; CHECK-DAG: FMax_ClusteredReduce = sub_group_clustered_reduce_max( +; CHECK-DAG: BitwiseAnd_Reduce = sub_group_non_uniform_reduce_and( +; CHECK-DAG: BitwiseAnd_InclusiveScan = sub_group_non_uniform_scan_inclusive_and( +; CHECK-DAG: BitwiseAnd_ExclusiveScan = sub_group_non_uniform_scan_exclusive_and( +; CHECK-DAG: BitwiseAnd_ClusteredReduce = sub_group_clustered_reduce_and( +; CHECK-DAG: BitwiseOr_Reduce = sub_group_non_uniform_reduce_or( +; CHECK-DAG: BitwiseOr_InclusiveScan = sub_group_non_uniform_scan_inclusive_or( +; CHECK-DAG: BitwiseOr_ExclusiveScan = sub_group_non_uniform_scan_exclusive_or( +; CHECK-DAG: BitwiseOr_ClusteredReduce = sub_group_clustered_reduce_or( +; CHECK-DAG: BitwiseXor_Reduce = sub_group_non_uniform_reduce_xor( +; CHECK-DAG: BitwiseXor_InclusiveScan = sub_group_non_uniform_scan_inclusive_xor( +; CHECK-DAG: BitwiseXor_ExclusiveScan = sub_group_non_uniform_scan_exclusive_xor( +; CHECK-DAG: BitwiseXor_ClusteredReduce = sub_group_clustered_reduce_xor( +; CHECK-DAG: LogicalAnd_Reduce = sub_group_non_uniform_reduce_logical_and({{.*}} != 0 +; CHECK-DAG: LogicalAnd_InclusiveScan = sub_group_non_uniform_scan_inclusive_logical_and({{.*}} != 0 +; CHECK-DAG: LogicalAnd_ExclusiveScan = sub_group_non_uniform_scan_exclusive_logical_and({{.*}} != 0 +; CHECK-DAG: LogicalAnd_ClusteredReduce = sub_group_clustered_reduce_logical_and({{.*}} != 0 +; CHECK-DAG: LogicalOr_Reduce = sub_group_non_uniform_reduce_logical_or({{.*}} != 0 +; CHECK-DAG: LogicalOr_InclusiveScan = sub_group_non_uniform_scan_inclusive_logical_or({{.*}} != 0 +; CHECK-DAG: LogicalOr_ExclusiveScan = sub_group_non_uniform_scan_exclusive_logical_or({{.*}} != 0 +; CHECK-DAG: LogicalOr_ClusteredReduce = sub_group_clustered_reduce_logical_or({{.*}} != 0 +; CHECK-DAG: LogicalXor_Reduce = sub_group_non_uniform_reduce_logical_xor({{.*}} != 0 +; CHECK-DAG: LogicalXor_InclusiveScan = sub_group_non_uniform_scan_inclusive_logical_xor({{.*}} != 0 +; CHECK-DAG: LogicalXor_ExclusiveScan = sub_group_non_uniform_scan_exclusive_logical_xor({{.*}} != 0 +; CHECK-DAG: LogicalXor_ClusteredReduce = sub_group_clustered_reduce_logical_xor({{.*}} != 0 diff --git a/tests/cases/subgroup_ballot.spt b/tests/cases/subgroup_ballot.spt new file mode 100644 index 0000000..3f81a57 --- /dev/null +++ b/tests/cases/subgroup_ballot.spt @@ -0,0 +1,65 @@ +; All ballot operations map to cl_khr_subgroup_ballot, including the distinct +; names used for ballot scans. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformBallot + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %Broadcast "Broadcast" + OpName %BroadcastFirst "BroadcastFirst" + OpName %Ballot "Ballot" + OpName %InverseBallot "InverseBallot" + OpName %BallotBitExtract "BallotBitExtract" + OpName %BallotFindLSB "BallotFindLSB" + OpName %BallotFindMSB "BallotFindMSB" + OpName %Reduce "Reduce" + OpName %InclusiveScan "InclusiveScan" + OpName %ExclusiveScan "ExclusiveScan" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %Broadcast = OpGroupNonUniformBroadcast %uint %sg %val %id + %BroadcastFirst = OpGroupNonUniformBroadcastFirst %uint %sg %val + %Ballot = OpGroupNonUniformBallot %v4 %sg %true + %InverseBallot = OpGroupNonUniformInverseBallot %bool %sg %mask + %BallotBitExtract = OpGroupNonUniformBallotBitExtract %bool %sg %mask %id + %BallotFindLSB = OpGroupNonUniformBallotFindLSB %uint %sg %mask + %BallotFindMSB = OpGroupNonUniformBallotFindMSB %uint %sg %mask + %Reduce = OpGroupNonUniformBallotBitCount %uint %sg Reduce %mask + %InclusiveScan = OpGroupNonUniformBallotBitCount %uint %sg InclusiveScan %mask + %ExclusiveScan = OpGroupNonUniformBallotBitCount %uint %sg ExclusiveScan %mask + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_ballot : enable +; CHECK-DAG: Broadcast = sub_group_non_uniform_broadcast( +; CHECK-DAG: BroadcastFirst = sub_group_broadcast_first( +; CHECK-DAG: Ballot = sub_group_ballot( +; CHECK-DAG: InverseBallot = sub_group_inverse_ballot( +; CHECK-DAG: BallotBitExtract = sub_group_ballot_bit_extract( +; CHECK-DAG: BallotFindLSB = sub_group_ballot_find_lsb( +; CHECK-DAG: BallotFindMSB = sub_group_ballot_find_msb( +; CHECK-DAG: Reduce = sub_group_ballot_bit_count( +; CHECK-DAG: InclusiveScan = sub_group_ballot_inclusive_scan( +; CHECK-DAG: ExclusiveScan = sub_group_ballot_exclusive_scan( diff --git a/tests/cases/subgroup_barrier_only.spt b/tests/cases/subgroup_barrier_only.spt new file mode 100644 index 0000000..17fc64c --- /dev/null +++ b/tests/cases/subgroup_barrier_only.spt @@ -0,0 +1,34 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s 2>&1 | %FileCheck %s --check-prefix=ERROR +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + OpControlBarrier %sg %sg %id + OpReturn + OpFunctionEnd + + ; ERROR: subgroup barriers require OpenCL C 2.0 +; CHECK: #pragma OPENCL EXTENSION cl_khr_subgroups : enable +; CHECK: sub_group_barrier( diff --git a/tests/cases/subgroup_boolean.spt b/tests/cases/subgroup_boolean.spt new file mode 100644 index 0000000..bbd9b7e --- /dev/null +++ b/tests/cases/subgroup_boolean.spt @@ -0,0 +1,44 @@ +; Boolean data movement and AllEqual use int overloads and normalize the +; results back to booleans. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformBallot + OpCapability GroupNonUniformVote + OpCapability GroupNonUniformShuffle + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %bool_bcast = OpGroupNonUniformBroadcast %bool %sg %true %id + %bool_first = OpGroupNonUniformBroadcastFirst %bool %sg %true + %bool_shuffle = OpGroupNonUniformShuffle %bool %sg %true %id + %bool_equal = OpGroupNonUniformAllEqual %bool %sg %true + OpReturn + OpFunctionEnd + +; CHECK: sub_group_non_uniform_broadcast((int)true, {{.*}}) != 0 +; CHECK: sub_group_broadcast_first((int)true) != 0 +; CHECK: sub_group_shuffle((int)true, {{.*}}) != 0 +; CHECK: sub_group_non_uniform_all_equal((int)true) != 0 diff --git a/tests/cases/subgroup_builtins.spt b/tests/cases/subgroup_builtins.spt index ce5f9e5..19978cc 100644 --- a/tests/cases/subgroup_builtins.spt +++ b/tests/cases/subgroup_builtins.spt @@ -8,24 +8,29 @@ OpCapability Addresses OpCapability SubgroupDispatch OpMemoryModel Physical64 OpenCL - OpEntryPoint Kernel %k "test" %sgid %nsg + OpEntryPoint Kernel %k "test" %sgid %nsg %enqueued OpDecorate %sgid BuiltIn SubgroupId OpDecorate %nsg BuiltIn NumSubgroups + OpDecorate %enqueued BuiltIn NumEnqueuedSubgroups %void = OpTypeVoid %uint = OpTypeInt 32 0 %p_in_uint = OpTypePointer Input %uint %p_g_uint = OpTypePointer CrossWorkgroup %uint %sgid = OpVariable %p_in_uint Input - %nsg = OpVariable %p_in_uint Input + %enqueued = OpVariable %p_in_uint Input + %nsg = OpVariable %p_in_uint Input %fnty = OpTypeFunction %void %p_g_uint %k = OpFunction %void None %fnty %out = OpFunctionParameter %p_g_uint %lbl = OpLabel %a = OpLoad %uint %sgid %b = OpLoad %uint %nsg + %e = OpLoad %uint %enqueued %s = OpIAdd %uint %a %b - OpStore %out %s + %s2 = OpIAdd %uint %s %e + OpStore %out %s2 OpReturn OpFunctionEnd ; CHECK-DAG: get_sub_group_id() ; CHECK-DAG: get_num_sub_groups() +; CHECK-DAG: get_enqueued_num_sub_groups() diff --git a/tests/cases/subgroup_elect.spt b/tests/cases/subgroup_elect.spt new file mode 100644 index 0000000..77b27ec --- /dev/null +++ b/tests/cases/subgroup_elect.spt @@ -0,0 +1,38 @@ +; Elect declares only GroupNonUniform, but requires the OpenCL non-uniform +; vote extension. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniform + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %elect = OpGroupNonUniformElect %bool %sg + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_non_uniform_vote : enable +; CHECK-DAG: elect = sub_group_elect() != 0 diff --git a/tests/cases/subgroup_masks.spt b/tests/cases/subgroup_masks.spt new file mode 100644 index 0000000..d496267 --- /dev/null +++ b/tests/cases/subgroup_masks.spt @@ -0,0 +1,84 @@ +; Ballot masks are complete uint4 queries. Exercise named loads, whole-value +; stores, constant extraction, and dynamic extraction. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformBallot + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" %eq %ge %gt %le %lt + OpDecorate %eq BuiltIn SubgroupEqMask + OpName %eq_whole "eq_whole" + OpName %eq_constant "eq_constant" + OpName %eq_dynamic "eq_dynamic" + OpDecorate %ge BuiltIn SubgroupGeMask + OpName %ge_whole "ge_whole" + OpName %ge_constant "ge_constant" + OpName %ge_dynamic "ge_dynamic" + OpDecorate %gt BuiltIn SubgroupGtMask + OpName %gt_whole "gt_whole" + OpName %gt_constant "gt_constant" + OpName %gt_dynamic "gt_dynamic" + OpDecorate %le BuiltIn SubgroupLeMask + OpName %le_whole "le_whole" + OpName %le_constant "le_constant" + OpName %le_dynamic "le_dynamic" + OpDecorate %lt BuiltIn SubgroupLtMask + OpName %lt_whole "lt_whole" + OpName %lt_constant "lt_constant" + OpName %lt_dynamic "lt_dynamic" + %void = OpTypeVoid + %uint = OpTypeInt 32 0 + %v4 = OpTypeVector %uint 4 + %in = OpTypePointer Input %v4 + %out = OpTypePointer CrossWorkgroup %v4 + %eq = OpVariable %in Input + %ge = OpVariable %in Input + %gt = OpVariable %in Input + %le = OpVariable %in Input + %lt = OpVariable %in Input + %fnty = OpTypeFunction %void %out %uint + %k = OpFunction %void None %fnty + %ptr = OpFunctionParameter %out + %idx = OpFunctionParameter %uint + %lbl = OpLabel + %eq_whole = OpLoad %v4 %eq +%eq_constant = OpCompositeExtract %uint %eq_whole 1 + %eq_dynamic = OpVectorExtractDynamic %uint %eq_whole %idx + OpStore %ptr %eq_whole + %ge_whole = OpLoad %v4 %ge +%ge_constant = OpCompositeExtract %uint %ge_whole 1 + %ge_dynamic = OpVectorExtractDynamic %uint %ge_whole %idx + OpStore %ptr %ge_whole + %gt_whole = OpLoad %v4 %gt +%gt_constant = OpCompositeExtract %uint %gt_whole 1 + %gt_dynamic = OpVectorExtractDynamic %uint %gt_whole %idx + OpStore %ptr %gt_whole + %le_whole = OpLoad %v4 %le +%le_constant = OpCompositeExtract %uint %le_whole 1 + %le_dynamic = OpVectorExtractDynamic %uint %le_whole %idx + OpStore %ptr %le_whole + %lt_whole = OpLoad %v4 %lt +%lt_constant = OpCompositeExtract %uint %lt_whole 1 + %lt_dynamic = OpVectorExtractDynamic %uint %lt_whole %idx + OpStore %ptr %lt_whole + OpReturn + OpFunctionEnd +; CHECK: #pragma OPENCL EXTENSION cl_khr_subgroup_ballot : enable +; CHECK-DAG: = get_sub_group_eq_mask()[1] +; CHECK-DAG: = get_sub_group_eq_mask()[ +; CHECK-DAG: *{{.*}} = get_sub_group_eq_mask() +; CHECK-DAG: = get_sub_group_ge_mask()[1] +; CHECK-DAG: = get_sub_group_ge_mask()[ +; CHECK-DAG: *{{.*}} = get_sub_group_ge_mask() +; CHECK-DAG: = get_sub_group_gt_mask()[1] +; CHECK-DAG: = get_sub_group_gt_mask()[ +; CHECK-DAG: *{{.*}} = get_sub_group_gt_mask() +; CHECK-DAG: = get_sub_group_le_mask()[1] +; CHECK-DAG: = get_sub_group_le_mask()[ +; CHECK-DAG: *{{.*}} = get_sub_group_le_mask() +; CHECK-DAG: = get_sub_group_lt_mask()[1] +; CHECK-DAG: = get_sub_group_lt_mask()[ +; CHECK-DAG: *{{.*}} = get_sub_group_lt_mask() diff --git a/tests/cases/subgroup_rotate.spt b/tests/cases/subgroup_rotate.spt new file mode 100644 index 0000000..1748c41 --- /dev/null +++ b/tests/cases/subgroup_rotate.spt @@ -0,0 +1,40 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformRotateKHR + OpExtension "SPV_KHR_subgroup_rotate" + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %rotate "rotate" + OpName %clustered "clustered" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %rotate = OpGroupNonUniformRotateKHR %uint %sg %val %val + %clustered = OpGroupNonUniformRotateKHR %uint %sg %val %val %cluster + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_rotate : enable +; CHECK-DAG: rotate = sub_group_rotate({{.*}}, as_int((uint)4294967290)) +; CHECK-DAG: clustered = sub_group_clustered_rotate( diff --git a/tests/cases/subgroup_shuffle_barrier.spt b/tests/cases/subgroup_shuffle_barrier.spt index 7ee0156..9dbd42c 100644 --- a/tests/cases/subgroup_shuffle_barrier.spt +++ b/tests/cases/subgroup_shuffle_barrier.spt @@ -1,7 +1,7 @@ ; Sub-group shuffle ops (OpGroupNonUniformShuffle/ShuffleXor) map to the ; sub_group_shuffle/sub_group_shuffle_xor builtins, and an OpControlBarrier with -; a Subgroup execution scope maps to sub_group_barrier -- all cl_khr_subgroups -; (OpenCL C 2.0+), so fail loudly below 2.0. +; a Subgroup execution scope maps to sub_group_barrier. Shuffles require +; cl_khr_subgroup_shuffle; barriers require cl_khr_subgroups (OpenCL C 2.0+). ; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s ; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %FileCheck %s ; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null @@ -34,3 +34,4 @@ ; CHECK-DAG: sub_group_shuffle( ; CHECK-DAG: sub_group_shuffle_xor( ; CHECK-DAG: sub_group_barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE) +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_shuffle : enable diff --git a/tests/cases/subgroup_shuffle_relative.spt b/tests/cases/subgroup_shuffle_relative.spt new file mode 100644 index 0000000..1750a49 --- /dev/null +++ b/tests/cases/subgroup_shuffle_relative.spt @@ -0,0 +1,39 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformShuffleRelative + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %Up "Up" + OpName %Down "Down" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %Up = OpGroupNonUniformShuffleUp %uint %sg %val %id + %Down = OpGroupNonUniformShuffleDown %uint %sg %val %id + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_shuffle_relative : enable +; CHECK-DAG: Up = sub_group_shuffle_up( +; CHECK-DAG: Down = sub_group_shuffle_down( diff --git a/tests/cases/subgroup_types.spt b/tests/cases/subgroup_types.spt new file mode 100644 index 0000000..6967f10 --- /dev/null +++ b/tests/cases/subgroup_types.spt @@ -0,0 +1,70 @@ +; Sub-group collectives accept narrow integers with extended_types, 64-bit +; integers, half/double values, and vector broadcasts. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability Groups + OpCapability Int8 + OpCapability Int16 + OpCapability Int64 + OpCapability Float16 + OpCapability Float64 + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + %void = OpTypeVoid + %u8 = OpTypeInt 8 0 + %u16 = OpTypeInt 16 0 + %u64 = OpTypeInt 64 0 + %f16 = OpTypeFloat 16 + %f64 = OpTypeFloat 64 + %c8 = OpConstant %u8 250 + %c16 = OpConstant %u16 65530 + %c64 = OpConstant %u64 18446744073709551610 + %chalf = OpConstant %f16 2.0 + %cdouble = OpConstant %f64 2.0 + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %u8_broadcast = OpGroupBroadcast %u8 %sg %c8 %id + %u8_reduce = OpGroupIAdd %u8 %sg Reduce %c8 + %u8_min = OpGroupSMin %u8 %sg ExclusiveScan %c8 + %u16_broadcast = OpGroupBroadcast %u16 %sg %c16 %id + %u16_reduce = OpGroupIAdd %u16 %sg Reduce %c16 + %u16_min = OpGroupSMin %u16 %sg ExclusiveScan %c16 + %u64_broadcast = OpGroupBroadcast %u64 %sg %c64 %id + %u64_reduce = OpGroupIAdd %u64 %sg Reduce %c64 + %u64_min = OpGroupSMin %u64 %sg ExclusiveScan %c64 + %f16_broadcast = OpGroupBroadcast %f16 %sg %chalf %id + %f16_reduce = OpGroupFAdd %f16 %sg Reduce %chalf + %f16_min = OpGroupFMin %f16 %sg ExclusiveScan %chalf + %f64_broadcast = OpGroupBroadcast %f64 %sg %cdouble %id + %f64_reduce = OpGroupFAdd %f64 %sg Reduce %cdouble + %f64_min = OpGroupFMin %f64 %sg ExclusiveScan %cdouble + %vector = OpGroupBroadcast %v4 %sg %mask %id + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_extended_types : enable +; CHECK-DAG: sub_group_scan_exclusive_min(as_char( +; CHECK-DAG: sub_group_scan_exclusive_min(as_short( +; CHECK-DAG: sub_group_scan_exclusive_min(as_long( +; CHECK-DAG: sub_group_broadcast((uint4) diff --git a/tests/cases/subgroup_unsupported_nonuniform_dynamic_scope.spt b/tests/cases/subgroup_unsupported_nonuniform_dynamic_scope.spt new file mode 100644 index 0000000..53d7357 --- /dev/null +++ b/tests/cases/subgroup_unsupported_nonuniform_dynamic_scope.spt @@ -0,0 +1,33 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s 2>&1 | %FileCheck %s + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniform + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void %uint + %k = OpFunction %void None %fnty + %dynamic = OpFunctionParameter %uint + %lbl = OpLabel + %elect = OpGroupNonUniformElect %bool %dynamic + OpReturn + OpFunctionEnd + +; CHECK: UNIMPLEMENTED non-constant group execution scope diff --git a/tests/cases/subgroup_unsupported_nonuniform_workgroup.spt b/tests/cases/subgroup_unsupported_nonuniform_workgroup.spt new file mode 100644 index 0000000..6933916 --- /dev/null +++ b/tests/cases/subgroup_unsupported_nonuniform_workgroup.spt @@ -0,0 +1,32 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s 2>&1 | %FileCheck %s + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniform + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 2 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %elect = OpGroupNonUniformElect %bool %sg + OpReturn + OpFunctionEnd + +; CHECK: UNIMPLEMENTED group execution scope 2 diff --git a/tests/cases/subgroup_unsupported_vector_arithmetic.spt b/tests/cases/subgroup_unsupported_vector_arithmetic.spt new file mode 100644 index 0000000..8bddbac --- /dev/null +++ b/tests/cases/subgroup_unsupported_vector_arithmetic.spt @@ -0,0 +1,32 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s 2>&1 | %FileCheck %s + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformArithmetic + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %elect = OpGroupNonUniformIAdd %v4 %sg Reduce %mask + OpReturn + OpFunctionEnd + +; CHECK: UNIMPLEMENTED group arithmetic operand type diff --git a/tests/cases/subgroup_unsupported_vector_shuffle.spt b/tests/cases/subgroup_unsupported_vector_shuffle.spt new file mode 100644 index 0000000..ba3dcd7 --- /dev/null +++ b/tests/cases/subgroup_unsupported_vector_shuffle.spt @@ -0,0 +1,32 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s 2>&1 | %FileCheck %s + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformShuffle + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %elect = OpGroupNonUniformShuffle %v4 %sg %mask %id + OpReturn + OpFunctionEnd + +; CHECK: UNIMPLEMENTED subgroup operand type diff --git a/tests/cases/subgroup_votes.spt b/tests/cases/subgroup_votes.spt new file mode 100644 index 0000000..a45f891 --- /dev/null +++ b/tests/cases/subgroup_votes.spt @@ -0,0 +1,45 @@ +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability GroupNonUniformVote + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %all "all" + OpName %any "any" + OpName %equal "equal" + OpName %elect "elect" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %all = OpGroupNonUniformAll %bool %sg %true + %any = OpGroupNonUniformAny %bool %sg %true + %equal = OpGroupNonUniformAllEqual %bool %sg %val + %elect = OpGroupNonUniformElect %bool %sg + OpReturn + OpFunctionEnd + +; CHECK-DAG: #pragma OPENCL EXTENSION cl_khr_subgroup_non_uniform_vote : enable +; CHECK-DAG: all = sub_group_non_uniform_all((int)true) != 0 +; CHECK-DAG: any = sub_group_non_uniform_any((int)true) != 0 +; CHECK-DAG: equal = sub_group_non_uniform_all_equal((uint)4294967290) != 0 +; CHECK-DAG: elect = sub_group_elect() != 0 diff --git a/tests/cases/subgroups.spt b/tests/cases/subgroups.spt index deb0185..2e32bc4 100644 --- a/tests/cases/subgroups.spt +++ b/tests/cases/subgroups.spt @@ -1,7 +1,4 @@ -; The Groups capability (sub-group / work-group collectives) maps to the -; cl_khr_subgroups extension, which is available from OpenCL C 2.0 on: -; translation must fail below that, and otherwise enable it via pragma like the -; fp16/fp64 extensions. +; A subgroup Groups instruction enables cl_khr_subgroups on OpenCL C 2.0+. ; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s ; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %FileCheck %s OpCapability Kernel @@ -10,9 +7,14 @@ OpMemoryModel Physical64 OpenCL OpEntryPoint Kernel %main "test" %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %scope = OpConstant %uint 3 + %true = OpConstantTrue %bool %mainty = OpTypeFunction %void %main = OpFunction %void None %mainty %mbb = OpLabel + %any = OpGroupAny %bool %scope %true OpReturn OpFunctionEnd ; CHECK: #pragma OPENCL EXTENSION cl_khr_subgroups : enable diff --git a/tests/cases/workgroup_collectives.spt b/tests/cases/workgroup_collectives.spt new file mode 100644 index 0000000..949f4b8 --- /dev/null +++ b/tests/cases/workgroup_collectives.spt @@ -0,0 +1,122 @@ +; Work-group-only collectives must not enable cl_khr_subgroups. +; RUN: not %spirv2clc --asm --spirv-version=1.4 --cl-std=CL1.2 %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %FileCheck %s +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL2.0 %s | %clang -c -cl-std=CL2.0 -x cl - -o /dev/null +; RUN: %spirv2clc --asm --spirv-version=1.4 --cl-std=CL3.0 %s | %clang -c -cl-std=CL3.0 -x cl - -o /dev/null + OpCapability Kernel + OpCapability Addresses + OpCapability Groups + OpMemoryModel Physical64 OpenCL + OpEntryPoint Kernel %k "test" + OpName %wg_all "wg_all" + OpName %wg_any "wg_any" + OpName %wg_broadcast1 "wg_broadcast1" + OpName %wg_broadcast2 "wg_broadcast2" + OpName %wg_broadcast3 "wg_broadcast3" + OpName %wg_IAdd_Reduce "wg_IAdd_Reduce" + OpName %wg_IAdd_InclusiveScan "wg_IAdd_InclusiveScan" + OpName %wg_IAdd_ExclusiveScan "wg_IAdd_ExclusiveScan" + OpName %wg_FAdd_Reduce "wg_FAdd_Reduce" + OpName %wg_FAdd_InclusiveScan "wg_FAdd_InclusiveScan" + OpName %wg_FAdd_ExclusiveScan "wg_FAdd_ExclusiveScan" + OpName %wg_FMin_Reduce "wg_FMin_Reduce" + OpName %wg_FMin_InclusiveScan "wg_FMin_InclusiveScan" + OpName %wg_FMin_ExclusiveScan "wg_FMin_ExclusiveScan" + OpName %wg_UMin_Reduce "wg_UMin_Reduce" + OpName %wg_UMin_InclusiveScan "wg_UMin_InclusiveScan" + OpName %wg_UMin_ExclusiveScan "wg_UMin_ExclusiveScan" + OpName %wg_SMin_Reduce "wg_SMin_Reduce" + OpName %wg_SMin_InclusiveScan "wg_SMin_InclusiveScan" + OpName %wg_SMin_ExclusiveScan "wg_SMin_ExclusiveScan" + OpName %wg_FMax_Reduce "wg_FMax_Reduce" + OpName %wg_FMax_InclusiveScan "wg_FMax_InclusiveScan" + OpName %wg_FMax_ExclusiveScan "wg_FMax_ExclusiveScan" + OpName %wg_UMax_Reduce "wg_UMax_Reduce" + OpName %wg_UMax_InclusiveScan "wg_UMax_InclusiveScan" + OpName %wg_UMax_ExclusiveScan "wg_UMax_ExclusiveScan" + OpName %wg_SMax_Reduce "wg_SMax_Reduce" + OpName %wg_SMax_InclusiveScan "wg_SMax_InclusiveScan" + OpName %wg_SMax_ExclusiveScan "wg_SMax_ExclusiveScan" + %void = OpTypeVoid + %bool = OpTypeBool + %uint = OpTypeInt 32 0 + %f32 = OpTypeFloat 32 + %v2 = OpTypeVector %uint 2 + %v3 = OpTypeVector %uint 3 + %v4 = OpTypeVector %uint 4 + %sg = OpConstant %uint 3 + %wg = OpConstant %uint 2 + %val = OpConstant %uint 4294967290 + %id = OpConstant %uint 0 + %cluster = OpConstant %uint 4 + %fval = OpConstant %f32 2.0 + %true = OpConstantTrue %bool + %coord2 = OpConstantComposite %v2 %id %id + %coord3 = OpConstantComposite %v3 %id %id %id + %mask = OpConstantComposite %v4 %id %id %id %id + %fnty = OpTypeFunction %void + %k = OpFunction %void None %fnty + %lbl = OpLabel + %wg_all = OpGroupAll %bool %wg %true + %wg_any = OpGroupAny %bool %wg %true + %wg_broadcast1 = OpGroupBroadcast %uint %wg %val %id + %wg_broadcast2 = OpGroupBroadcast %uint %wg %val %coord2 + %wg_broadcast3 = OpGroupBroadcast %uint %wg %val %coord3 + %wg_IAdd_Reduce = OpGroupIAdd %uint %wg Reduce %val + %wg_IAdd_InclusiveScan = OpGroupIAdd %uint %wg InclusiveScan %val + %wg_IAdd_ExclusiveScan = OpGroupIAdd %uint %wg ExclusiveScan %val + %wg_FAdd_Reduce = OpGroupFAdd %f32 %wg Reduce %fval + %wg_FAdd_InclusiveScan = OpGroupFAdd %f32 %wg InclusiveScan %fval + %wg_FAdd_ExclusiveScan = OpGroupFAdd %f32 %wg ExclusiveScan %fval + %wg_FMin_Reduce = OpGroupFMin %f32 %wg Reduce %fval + %wg_FMin_InclusiveScan = OpGroupFMin %f32 %wg InclusiveScan %fval + %wg_FMin_ExclusiveScan = OpGroupFMin %f32 %wg ExclusiveScan %fval + %wg_UMin_Reduce = OpGroupUMin %uint %wg Reduce %val + %wg_UMin_InclusiveScan = OpGroupUMin %uint %wg InclusiveScan %val + %wg_UMin_ExclusiveScan = OpGroupUMin %uint %wg ExclusiveScan %val + %wg_SMin_Reduce = OpGroupSMin %uint %wg Reduce %val + %wg_SMin_InclusiveScan = OpGroupSMin %uint %wg InclusiveScan %val + %wg_SMin_ExclusiveScan = OpGroupSMin %uint %wg ExclusiveScan %val + %wg_FMax_Reduce = OpGroupFMax %f32 %wg Reduce %fval + %wg_FMax_InclusiveScan = OpGroupFMax %f32 %wg InclusiveScan %fval + %wg_FMax_ExclusiveScan = OpGroupFMax %f32 %wg ExclusiveScan %fval + %wg_UMax_Reduce = OpGroupUMax %uint %wg Reduce %val + %wg_UMax_InclusiveScan = OpGroupUMax %uint %wg InclusiveScan %val + %wg_UMax_ExclusiveScan = OpGroupUMax %uint %wg ExclusiveScan %val + %wg_SMax_Reduce = OpGroupSMax %uint %wg Reduce %val + %wg_SMax_InclusiveScan = OpGroupSMax %uint %wg InclusiveScan %val + %wg_SMax_ExclusiveScan = OpGroupSMax %uint %wg ExclusiveScan %val + OpReturn + OpFunctionEnd + +; CHECK-NOT: cl_khr_subgroups +; CHECK-DAG: wg_all = work_group_all((int)true) != 0 +; CHECK-DAG: wg_any = work_group_any((int)true) != 0 +; CHECK-DAG: wg_broadcast1 = work_group_broadcast( +; CHECK-DAG: wg_broadcast2 = work_group_broadcast( +; CHECK-DAG: wg_broadcast3 = work_group_broadcast( +; CHECK-DAG: wg_IAdd_Reduce = work_group_reduce_add( +; CHECK-DAG: wg_IAdd_InclusiveScan = work_group_scan_inclusive_add( +; CHECK-DAG: wg_IAdd_ExclusiveScan = work_group_scan_exclusive_add( +; CHECK-DAG: wg_FAdd_Reduce = work_group_reduce_add( +; CHECK-DAG: wg_FAdd_InclusiveScan = work_group_scan_inclusive_add( +; CHECK-DAG: wg_FAdd_ExclusiveScan = work_group_scan_exclusive_add( +; CHECK-DAG: wg_FMin_Reduce = work_group_reduce_min( +; CHECK-DAG: wg_FMin_InclusiveScan = work_group_scan_inclusive_min( +; CHECK-DAG: wg_FMin_ExclusiveScan = work_group_scan_exclusive_min( +; CHECK-DAG: wg_UMin_Reduce = work_group_reduce_min( +; CHECK-DAG: wg_UMin_InclusiveScan = work_group_scan_inclusive_min( +; CHECK-DAG: wg_UMin_ExclusiveScan = work_group_scan_exclusive_min( +; CHECK-DAG: wg_SMin_Reduce = (uint)work_group_reduce_min(as_int( +; CHECK-DAG: wg_SMin_InclusiveScan = (uint)work_group_scan_inclusive_min(as_int( +; CHECK-DAG: wg_SMin_ExclusiveScan = (uint)work_group_scan_exclusive_min(as_int( +; CHECK-DAG: wg_FMax_Reduce = work_group_reduce_max( +; CHECK-DAG: wg_FMax_InclusiveScan = work_group_scan_inclusive_max( +; CHECK-DAG: wg_FMax_ExclusiveScan = work_group_scan_exclusive_max( +; CHECK-DAG: wg_UMax_Reduce = work_group_reduce_max( +; CHECK-DAG: wg_UMax_InclusiveScan = work_group_scan_inclusive_max( +; CHECK-DAG: wg_UMax_ExclusiveScan = work_group_scan_exclusive_max( +; CHECK-DAG: wg_SMax_Reduce = (uint)work_group_reduce_max(as_int( +; CHECK-DAG: wg_SMax_InclusiveScan = (uint)work_group_scan_inclusive_max(as_int( +; CHECK-DAG: wg_SMax_ExclusiveScan = (uint)work_group_scan_exclusive_max(as_int( +; CHECK-NOT: cl_khr_subgroups