Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace fk {
using OutputArrayType = std::array<Instantiable<Operation>, IOpType::Operation::BATCH>;
OutputArrayType resultingArray{};
for (int i = 0; i < IOpType::Operation::BATCH; i++) {
if constexpr (IOpType::template is<ReadType>) {
if constexpr (IOpType::template is<ReadType> || IOpType::template is<IncompleteReadBackType>) {
resultingArray[i] = Operation::build(std::forward<InstantiableType>(batchIOp).params.opData[i]);
} else {
static_assert(IOpType::template is<WriteType>, "IOpType must be ReadType or WriteType");
Expand Down Expand Up @@ -162,25 +162,20 @@ namespace fk {
Implements build(const ParamsType& params)
*/
template <size_t BATCH_, typename Op>
requires(isCompleteOperation<Op>)
struct BatchRead<PlanePolicy::PROCESS_ALL, BATCH_, Op> {
static_assert(isCompleteOperation<Op>,
"The IOp passed as template parameter is not a complete operation");
using Operation = Op;
static constexpr size_t BATCH = BATCH_;
static constexpr PlanePolicy PP = PlanePolicy::PROCESS_ALL;
private:
using SelfType = BatchRead<PlanePolicy::PROCESS_ALL, BATCH_, Op>;
using Parent = ReadOperation<typename Op::ReadDataType,
BatchReadParams<BATCH, PP, Operation>, typename Op::OutputType,
static_cast<TF>(Operation::THREAD_FUSION), SelfType,
Operation::IS_FUSED_OP>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
using Operation = Op;
static constexpr size_t BATCH = BATCH_;
static constexpr PlanePolicy PP = PlanePolicy::PROCESS_ALL;

using ParamsType = BatchReadParams<BATCH, PP, Operation>;
using ReadDataType = typename Operation::ReadDataType;
using InstanceType = ReadType;
using OutputType = typename Operation::OutputType;
using OperationDataType = OperationData<SelfType>;
using InstantiableType = Read<SelfType>;
static constexpr bool IS_FUSED_OP = Operation::IS_FUSED_OP;
static constexpr bool THREAD_FUSION = Operation::THREAD_FUSION;
DECLARE_READ_PARENT_BASIC

FK_HOST_DEVICE_FUSE uint num_elems_x(const Point thread, const OperationDataType& opData) {
return Operation::num_elems_x(thread, opData.params.opData[thread.z]);
Expand All @@ -198,10 +193,6 @@ namespace fk {
return opData.params.activeThreads;
}

template <uint ELEMS_PER_THREAD = 1>
FK_HOST_DEVICE_FUSE auto exec(const Point thread, const OperationDataType& opData) {
return exec<ELEMS_PER_THREAD>(thread, opData.params);
}
template <uint ELEMS_PER_THREAD = 1>
FK_HOST_DEVICE_FUSE auto exec(const Point thread, const ParamsType& params) {
if constexpr (THREAD_FUSION) {
Expand All @@ -210,34 +201,23 @@ namespace fk {
return Operation::exec(thread, params.opData[thread.z]);
}
}
FK_HOST_FUSE InstantiableType build(const OperationDataType& opData) {
return InstantiableType{ opData };
}
FK_HOST_FUSE InstantiableType build(const ParamsType& params) {
return InstantiableType{ {params} };
}
};

template <size_t BATCH_, typename Op>
requires(isCompleteOperation<Op>)
struct BatchRead<PlanePolicy::CONDITIONAL_WITH_DEFAULT, BATCH_, Op> {
static_assert(isCompleteOperation<Op>,
"The IOp passed as template parameter is not a complete operation");
private:
using SelfType = BatchRead<PlanePolicy::CONDITIONAL_WITH_DEFAULT, BATCH_, Op>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
using Operation = Op;
static constexpr size_t BATCH = BATCH_;
static constexpr PlanePolicy PP = PlanePolicy::CONDITIONAL_WITH_DEFAULT;

using ParamsType = BatchReadParams<BATCH, PP, Operation, typename Operation::OutputType>;
using ReadDataType = typename Operation::ReadDataType;
using InstanceType = ReadType;
using OutputType = typename Operation::OutputType;
using OperationDataType = OperationData<SelfType>;
using InstantiableType = Read<SelfType>;
static constexpr bool IS_FUSED_OP = Operation::IS_FUSED_OP;
static constexpr bool THREAD_FUSION = false;
private:
using SelfType = BatchRead<PlanePolicy::CONDITIONAL_WITH_DEFAULT, BATCH, Op>;
using Parent = ReadOperation<typename Op::ReadDataType,
BatchReadParams<BATCH, PP, Operation, typename Op::OutputType>,
typename Op::OutputType,
static_cast<TF>(Operation::THREAD_FUSION), SelfType, false>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
DECLARE_READ_PARENT_BASIC

FK_HOST_DEVICE_FUSE uint num_elems_x(const Point thread, const OperationDataType& opData) {
return Operation::num_elems_x(thread, opData.params.opData[thread.z]);
Expand All @@ -254,11 +234,6 @@ namespace fk {
FK_HOST_DEVICE_FUSE ActiveThreads getActiveThreads(const OperationDataType& opData) {
return opData.params.activeThreads;
}

template <uint ELEMS_PER_THREAD = 1>
FK_HOST_DEVICE_FUSE auto exec(const Point thread, const OperationDataType& opData) {
return exec<ELEMS_PER_THREAD>(thread, opData.params);
}
template <uint ELEMS_PER_THREAD = 1>
FK_HOST_DEVICE_FUSE auto exec(const Point thread, const ParamsType& params) {
if (params.usedPlanes <= thread.z) {
Expand All @@ -271,13 +246,6 @@ namespace fk {
}
}
}

FK_HOST_FUSE InstantiableType build(const OperationDataType& opData) {
return InstantiableType{ opData };
}
FK_HOST_FUSE InstantiableType build(const ParamsType& params) {
return InstantiableType{ {params} };
}
};

/*
Expand All @@ -286,23 +254,19 @@ namespace fk {
ParamsType = BatchReadParams<PlanePolicy::PROCESS_ALL, BATCH, Op>
*/
template <size_t BATCH_, typename Op>
requires(isIncompleteReadBackOperation<Op>)
struct BatchRead<PlanePolicy::PROCESS_ALL, BATCH_, TypeList<Op>> {
private:
using SelfType = BatchRead<PlanePolicy::PROCESS_ALL, BATCH_, TypeList<Op>>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
using Operation = Op;
static constexpr size_t BATCH = BATCH_;
static constexpr PlanePolicy PP = PlanePolicy::PROCESS_ALL;

using ParamsType = BatchReadParams<BATCH, PlanePolicy::PROCESS_ALL, Operation>;
using ReadDataType = typename Operation::ReadDataType;
using InstanceType = ReadType;
using OutputType = typename Operation::OutputType;
using OperationDataType = OperationData<SelfType>;
using InstantiableType = Read<SelfType>;
static constexpr bool IS_FUSED_OP = Operation::IS_FUSED_OP;
static constexpr bool THREAD_FUSION = Operation::THREAD_FUSION;
private:
using SelfType = BatchRead<PP, BATCH, TypeList<Op>>;
using Parent = IncompleteReadBackOperation<typename Operation::ReadDataType,
BatchReadParams<BATCH, PP, Operation>, NullType,
typename Operation::OutputType, SelfType>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
DECLARE_INCOMPLETEREADBACK_PARENT_BASIC

FK_HOST_DEVICE_FUSE uint num_elems_x(const Point thread, const OperationDataType& opData) {
return Operation::num_elems_x(thread, opData.params.opData[thread.z]);
Expand All @@ -319,13 +283,6 @@ namespace fk {
FK_HOST_DEVICE_FUSE ActiveThreads getActiveThreads(const OperationDataType& opData) {
return opData.params.activeThreads;
}

FK_HOST_FUSE InstantiableType build(const OperationDataType& opData) {
return InstantiableType{ opData };
}
FK_HOST_FUSE InstantiableType build(const ParamsType& params) {
return InstantiableType{ {params} };
}
};

/*
Expand All @@ -334,23 +291,19 @@ namespace fk {
ParamsType = BatchReadParams<BATCH, PlanePolicy::CONDITIONAL_WITH_DEFAULT, Op, DefType>
*/
template <size_t BATCH_, typename Op, typename DefType>
requires(isIncompleteReadBackOperation<Op>)
struct BatchRead<PlanePolicy::CONDITIONAL_WITH_DEFAULT, BATCH_, TypeList<Op, DefType>> {
private:
using SelfType = BatchRead<PlanePolicy::CONDITIONAL_WITH_DEFAULT, BATCH_, TypeList<Op, DefType>>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
using Operation = Op;
static constexpr size_t BATCH = BATCH_;
static constexpr PlanePolicy PP = PlanePolicy::CONDITIONAL_WITH_DEFAULT;

using ParamsType = BatchReadParams<BATCH, PlanePolicy::CONDITIONAL_WITH_DEFAULT, Operation, DefType>;
using ReadDataType = typename Operation::ReadDataType;
using InstanceType = ReadType;
using OutputType = typename Operation::OutputType;
using OperationDataType = OperationData<SelfType>;
using InstantiableType = Read<SelfType>;
static constexpr bool IS_FUSED_OP = Operation::IS_FUSED_OP;
static constexpr bool THREAD_FUSION = false;
private:
using SelfType = BatchRead<PP, BATCH, TypeList<Op, DefType>>;
using Parent = IncompleteReadBackOperation<typename Operation::ReadDataType,
BatchReadParams<BATCH, PP, Operation, DefType>, NullType,
typename Operation::OutputType, SelfType>;
public:
FK_STATIC_STRUCT(BatchRead, SelfType)
DECLARE_INCOMPLETEREADBACK_PARENT_BASIC

FK_HOST_DEVICE_FUSE uint num_elems_x(const Point thread, const OperationDataType& opData) {
return Operation::num_elems_x(thread, opData.params.opData[thread.z]);
Expand All @@ -367,13 +320,6 @@ namespace fk {
FK_HOST_DEVICE_FUSE ActiveThreads getActiveThreads(const OperationDataType& opData) {
return opData.params.activeThreads;
}

FK_HOST_FUSE InstantiableType build(const OperationDataType& opData) {
return InstantiableType{ opData };
}
FK_HOST_FUSE InstantiableType build(const ParamsType& params) {
return InstantiableType{ {params} };
}
};

/*
Expand Down Expand Up @@ -420,7 +366,11 @@ namespace fk {
paramsStore.opData[i] = iOps[i];
}

return BatchReadType::build(paramsStore);
if constexpr (isCompleteOperation<NewOperation>) {
return BatchReadType::build(paramsStore);
} else {
return BatchReadType::build(paramsStore, typename BatchReadType::BackIOp{});
}
}
};

Expand Down Expand Up @@ -453,7 +403,11 @@ namespace fk {
paramsStore.opData[i] = iOps[i];
}

return BatchReadType::build(paramsStore);
if constexpr (isCompleteOperation<NewOperation>) {
return BatchReadType::build(paramsStore);
} else {
return BatchReadType::build(paramsStore, typename BatchReadType::BackIOp{});
}
}
};
// ##################### END BATCH_READ #####################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,53 @@ namespace fk {
constexpr bool hasParamsArray =
hasParams_v<Operation> && std::is_array_v<typename Operation::ParamsType>;

template <typename Operation>
constexpr bool hasParamsAndBackIOpNoArray =
hasParamsAndBackIOp_v<Operation> && !std::is_array_v<typename Operation::ParamsType> &&
!std::is_array_v<typename Operation::BackIOp>;

template <typename Operation>
constexpr bool hasParamsAndBackIOpArray =
hasParamsAndBackIOp_v<Operation> && std::is_array_v<typename Operation::ParamsType> &&
std::is_array_v<typename Operation::BackIOp>;

// OperationData implementations
template <typename Operation, typename Enabler = void>
template <typename Operation>
struct OperationData;

using ParamsTypes = TypeList<BinaryType, ReadType, WriteType, MidWriteType, OpenType, ClosedType>;
using ParamsAndBackIOpTypes = TypeList<ReadBackType, IncompleteReadBackType, TernaryType>;

template <typename Operation>
struct OperationData<Operation, std::enable_if_t<one_of_v<typename Operation::InstanceType, ParamsTypes>>> {
requires (one_of_v<typename Operation::InstanceType, ParamsTypes>)
struct OperationData<Operation> {
FK_HOST_DEVICE_CNST OperationData() {};
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType &params_) : params(params_) {}
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType &params_)
requires(hasParamsNoArray<Operation>) : params(params_) {}
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType& params_)
requires(hasParamsArray<Operation>) : params{} {
for (size_t i = 0; i < std::extent_v<typename Operation::ParamsType>; ++i) {
params[i] = params_[i];
}
}
typename Operation::ParamsType params{};
};

template <typename Operation>
struct OperationData<Operation, std::enable_if_t<one_of_v<typename Operation::InstanceType, ParamsAndBackIOpTypes>>> {
requires (one_of_v<typename Operation::InstanceType, ParamsAndBackIOpTypes>)
struct OperationData<Operation> {
FK_HOST_DEVICE_CNST OperationData() {};
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType& params_, const typename Operation::BackIOp& backIOp_) : params(params_), backIOp(backIOp_) {}
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType& params_, const typename Operation::BackIOp& backIOp_)
requires (hasParamsAndBackIOpNoArray<Operation>) : params(params_), backIOp(backIOp_) {}
FK_HOST_DEVICE_CNST OperationData(const typename Operation::ParamsType& params_, const typename Operation::BackIOp& backIOp_)
requires (hasParamsAndBackIOpArray<Operation>) : params{}, backIOp{} {
for (size_t i = 0; i < std::extent_v<typename Operation::ParamsType>; ++i) {
params[i] = params_[i];
}
for (size_t i = 0; i < std::extent_v<typename Operation::BackIOp>; ++i) {
backIOp[i] = backIOp_[i];
}
}
typename Operation::ParamsType params{};
typename Operation::BackIOp backIOp{};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ namespace fk {
template <typename T>
constexpr bool isCompleteOperation = IsCompleteOperation<T>::value;

template <typename T>
constexpr bool isIncompleteReadBackOperation = opIs<IncompleteReadBackType, T>;

template <typename Enabler, typename T>
struct is_fused_operation_ : std::false_type {};

Expand Down
Loading