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
1 change: 0 additions & 1 deletion cunumeric_cpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ if(Legion_USE_OpenMP)
src/cunumeric/matrix/transpose_omp.cc
src/cunumeric/matrix/trilu_omp.cc
src/cunumeric/matrix/trsm_omp.cc
src/cunumeric/matrix/util_omp.cc
src/cunumeric/random/rand_omp.cc
src/cunumeric/search/argwhere_omp.cc
src/cunumeric/search/nonzero_omp.cc
Expand Down
18 changes: 12 additions & 6 deletions src/cunumeric/matrix/contract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::FLOAT_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_s(&lhs, lhs_ndim, lhs_shape, lhs_data, lhs_strides);
Expand Down Expand Up @@ -80,7 +81,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::DOUBLE_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_d(&lhs, lhs_ndim, lhs_shape, lhs_data, lhs_strides);
Expand Down Expand Up @@ -111,7 +113,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::HALF_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
// TBLIS doesn't handle half-precision floating point directly, so we have to go through a
// conversion to single-precision.
Expand Down Expand Up @@ -145,7 +148,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::HALF_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_copy_strides.data(),
rhs2_modes);
rhs2_modes,
lhs_overwritable);

float_tensor_to_half(lhs_data, lhs_copy_data, lhs_ndim, lhs_shape, lhs_strides);
}
Expand All @@ -167,7 +171,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::COMPLEX64_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_c(
Expand Down Expand Up @@ -209,7 +214,8 @@ struct ContractImplBody<VariantKind::CPU, LegateTypeCode::COMPLEX128_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_z(
Expand Down
36 changes: 24 additions & 12 deletions src/cunumeric/matrix/contract.cu
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ __host__ void contract(T* lhs_data,
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
// Initialization
auto handle = get_cutensor();
Expand Down Expand Up @@ -135,7 +136,8 @@ __host__ void contract(T* lhs_data,
cutensorContractionPlan_t plan;
CHECK_CUTENSOR(cutensorInitContractionPlan(handle, &plan, &desc, &find, work_size));
const typename contract_helper<T>::scalar_t alpha = 1.0;
const typename contract_helper<T>::scalar_t beta = 0.0;
// lhs_overwritable being true means that the contraciton tasks can overwrite the lhs
const typename contract_helper<T>::scalar_t beta = lhs_overwritable ? 0.0 : 1.0;
CHECK_CUTENSOR(cutensorContraction(handle,
&plan,
&alpha,
Expand Down Expand Up @@ -167,7 +169,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::HALF_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
contract(lhs_data,
lhs_ndim,
Expand All @@ -183,7 +186,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::HALF_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_strides,
rhs2_modes);
rhs2_modes,
lhs_overwritable);
}
};

Expand All @@ -203,7 +207,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::FLOAT_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
contract(lhs_data,
lhs_ndim,
Expand All @@ -219,7 +224,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::FLOAT_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_strides,
rhs2_modes);
rhs2_modes,
lhs_overwritable);
}
};

Expand All @@ -239,7 +245,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::DOUBLE_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
contract(lhs_data,
lhs_ndim,
Expand All @@ -255,7 +262,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::DOUBLE_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_strides,
rhs2_modes);
rhs2_modes,
lhs_overwritable);
}
};

Expand All @@ -275,7 +283,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::COMPLEX64_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
contract(lhs_data,
lhs_ndim,
Expand All @@ -291,7 +300,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::COMPLEX64_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_strides,
rhs2_modes);
rhs2_modes,
lhs_overwritable);
}
};

Expand All @@ -311,7 +321,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::COMPLEX128_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
contract(lhs_data,
lhs_ndim,
Expand All @@ -327,7 +338,8 @@ struct ContractImplBody<VariantKind::GPU, LegateTypeCode::COMPLEX128_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_strides,
rhs2_modes);
rhs2_modes,
lhs_overwritable);
}
};

Expand Down
27 changes: 16 additions & 11 deletions src/cunumeric/matrix/contract_omp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "cunumeric/matrix/contract.h"
#include "cunumeric/matrix/contract_template.inl"
#include "cunumeric/matrix/util.h"
#include "cunumeric/matrix/util_omp.h"

#include <tblis/tblis.h>
#include <omp.h>
Expand All @@ -43,7 +42,8 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::FLOAT_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_s(&lhs, lhs_ndim, lhs_shape, lhs_data, lhs_strides);
Expand Down Expand Up @@ -74,7 +74,8 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::DOUBLE_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_d(&lhs, lhs_ndim, lhs_shape, lhs_data, lhs_strides);
Expand Down Expand Up @@ -105,25 +106,26 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::HALF_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
// TBLIS doesn't handle half-precision floating point directly, so we have to go through a
// conversion to single-precision.

std::vector<int64_t> lhs_copy_strides(lhs_ndim);
int64_t lhs_size = calculate_volume(lhs_ndim, lhs_shape, lhs_copy_strides.data());
float* lhs_copy_data = allocate_buffer(lhs_size);
half_tensor_to_float_omp(lhs_copy_data, lhs_data, lhs_ndim, lhs_shape, lhs_strides);
half_tensor_to_float(lhs_copy_data, lhs_data, lhs_ndim, lhs_shape, lhs_strides);

std::vector<int64_t> rhs1_copy_strides(rhs1_ndim);
int64_t rhs1_size = calculate_volume(rhs1_ndim, rhs1_shape, rhs1_copy_strides.data());
float* rhs1_copy_data = allocate_buffer(rhs1_size);
half_tensor_to_float_omp(rhs1_copy_data, rhs1_data, rhs1_ndim, rhs1_shape, rhs1_strides);
half_tensor_to_float(rhs1_copy_data, rhs1_data, rhs1_ndim, rhs1_shape, rhs1_strides);

std::vector<int64_t> rhs2_copy_strides(rhs2_ndim);
int64_t rhs2_size = calculate_volume(rhs2_ndim, rhs2_shape, rhs2_copy_strides.data());
float* rhs2_copy_data = allocate_buffer(rhs2_size);
half_tensor_to_float_omp(rhs2_copy_data, rhs2_data, rhs2_ndim, rhs2_shape, rhs2_strides);
half_tensor_to_float(rhs2_copy_data, rhs2_data, rhs2_ndim, rhs2_shape, rhs2_strides);

ContractImplBody<VariantKind::OMP, LegateTypeCode::FLOAT_LT>{}(lhs_copy_data,
lhs_ndim,
Expand All @@ -139,9 +141,10 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::HALF_LT> {
rhs2_ndim,
rhs2_shape,
rhs2_copy_strides.data(),
rhs2_modes);
rhs2_modes,
lhs_overwritable);

float_tensor_to_half_omp(lhs_data, lhs_copy_data, lhs_ndim, lhs_shape, lhs_strides);
float_tensor_to_half(lhs_data, lhs_copy_data, lhs_ndim, lhs_shape, lhs_strides);
}
};

Expand All @@ -161,7 +164,8 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::COMPLEX64_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_c(
Expand Down Expand Up @@ -203,7 +207,8 @@ struct ContractImplBody<VariantKind::OMP, LegateTypeCode::COMPLEX128_LT> {
size_t rhs2_ndim,
int64_t* rhs2_shape,
int64_t* rhs2_strides,
int32_t* rhs2_modes)
int32_t* rhs2_modes,
bool lhs_overwritable)
{
tblis_tensor lhs;
tblis_init_tensor_z(
Expand Down
3 changes: 2 additions & 1 deletion src/cunumeric/matrix/contract_template.inl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ struct ContractImpl {
rhs2_shape.size(),
rhs2_shape.data(),
rhs2_strides.data(),
rhs2_modes.data());
rhs2_modes.data(),
args.lhs.is_readable());

#if 0 // debugging output
std::cout << "end contract kernel:" << std::endl;
Expand Down
Loading