Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion include/taco/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ModeFormat {
/// Properties of a mode format
enum Property {
FULL, NOT_FULL, ORDERED, NOT_ORDERED, UNIQUE, NOT_UNIQUE, BRANCHLESS,
NOT_BRANCHLESS, COMPACT, NOT_COMPACT
NOT_BRANCHLESS, COMPACT, NOT_COMPACT, ZEROLESS, NOT_ZEROLESS
};

/// Instantiates an undefined mode format
Expand Down Expand Up @@ -126,6 +126,7 @@ class ModeFormat {
bool isUnique() const;
bool isBranchless() const;
bool isCompact() const;
bool isZeroless() const;

/// Returns true if a mode format has a specific capability, false otherwise
bool hasCoordValIter() const;
Expand Down
1 change: 1 addition & 0 deletions include/taco/lower/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class Iterator : public util::Comparable<Iterator> {
bool isUnique() const;
bool isBranchless() const;
bool isCompact() const;
bool isZeroless() const;

/// Capabilities supported by levels being iterated.
bool hasCoordIter() const;
Expand Down
2 changes: 1 addition & 1 deletion include/taco/lower/mode_format_compressed.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CompressedModeFormat : public ModeFormatImpl {
public:
CompressedModeFormat();
CompressedModeFormat(bool isFull, bool isOrdered,
bool isUnique, long long allocSize = DEFAULT_ALLOC_SIZE);
bool isUnique, bool isZeroless, long long allocSize = DEFAULT_ALLOC_SIZE);

~CompressedModeFormat() override {}

Expand Down
2 changes: 1 addition & 1 deletion include/taco/lower/mode_format_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace taco {
class DenseModeFormat : public ModeFormatImpl {
public:
DenseModeFormat();
DenseModeFormat(const bool isOrdered, const bool isUnique);
DenseModeFormat(const bool isOrdered, const bool isUnique, const bool isZeroless);

~DenseModeFormat() override {}

Expand Down
3 changes: 2 additions & 1 deletion include/taco/lower/mode_format_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ std::ostream& operator<<(std::ostream&, const ModeFunction&);
class ModeFormatImpl {
public:
ModeFormatImpl(std::string name, bool isFull, bool isOrdered, bool isUnique,
bool isBranchless, bool isCompact, bool hasCoordValIter,
bool isBranchless, bool isCompact, bool isZeroless, bool hasCoordValIter,
bool hasCoordPosIter, bool hasLocate, bool hasInsert,
bool hasAppend);

Expand Down Expand Up @@ -162,6 +162,7 @@ class ModeFormatImpl {
const bool isUnique;
const bool isBranchless;
const bool isCompact;
const bool isZeroless;

const bool hasCoordValIter;
const bool hasCoordPosIter;
Expand Down
2 changes: 1 addition & 1 deletion include/taco/lower/mode_format_singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class SingletonModeFormat : public ModeFormatImpl {
public:
SingletonModeFormat();
SingletonModeFormat(bool isFull, bool isOrdered,
bool isUnique, long long allocSize = DEFAULT_ALLOC_SIZE);
bool isUnique, bool isZeroless, long long allocSize = DEFAULT_ALLOC_SIZE);

~SingletonModeFormat() override {}

Expand Down
15 changes: 15 additions & 0 deletions src/format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ bool ModeFormat::hasProperties(const std::vector<Property>& properties) const {
return false;
}
break;
case ZEROLESS:
if (!isZeroless()) {
return false;
}
break;
case NOT_FULL:
if (isFull()) {
return false;
Expand All @@ -207,6 +212,11 @@ bool ModeFormat::hasProperties(const std::vector<Property>& properties) const {
return false;
}
break;
case NOT_ZEROLESS:
if (isZeroless()) {
return false;
}
break;
}
}
return true;
Expand Down Expand Up @@ -237,6 +247,11 @@ bool ModeFormat::isCompact() const {
return impl->isCompact;
}

bool ModeFormat::isZeroless() const {
taco_iassert(defined());
return impl->isZeroless;
}

bool ModeFormat::hasCoordValIter() const {
taco_iassert(defined());
return impl->hasCoordValIter;
Expand Down
6 changes: 6 additions & 0 deletions src/lower/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ bool Iterator::isCompact() const {
return getMode().defined() && getMode().getModeFormat().isCompact();
}

bool Iterator::isZeroless() const {
taco_iassert(defined());
if (isDimensionIterator()) return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should return false for dimension iterators I think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes. it should return false for dimension iterators. Thank you for correcting me.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will modify that line.

return getMode().defined() && getMode().getModeFormat().isZeroless();
}

bool Iterator::hasCoordIter() const {
taco_iassert(defined());
if (isDimensionIterator()) return false;
Expand Down
14 changes: 11 additions & 3 deletions src/lower/lowerer_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,9 +1384,17 @@ Expr LowererImpl::lowerAccess(Access access) {
return getTensorVar(var);
}

return getIterators(access).back().isUnique()
? Load::make(getValuesArray(var), generateValueLocExpr(access))
: getReducedValueVar(access);

if (getIterators(access).back().isUnique()) {
if (var.getType().getDataType() == Datatype::Bool && getIterators(access).back().isZeroless()) {
return true;
} else {
return Load::make(getValuesArray(var), generateValueLocExpr(access));
}
} else {
return getReducedValueVar(access);
}

}


Expand Down
15 changes: 11 additions & 4 deletions src/lower/mode_format_compressed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ using namespace taco::ir;
namespace taco {

CompressedModeFormat::CompressedModeFormat() :
CompressedModeFormat(false, true, true) {
CompressedModeFormat(false, true, true, false) {
}

CompressedModeFormat::CompressedModeFormat(bool isFull, bool isOrdered,
bool isUnique, long long allocSize) :
ModeFormatImpl("compressed", isFull, isOrdered, isUnique, false, true,
bool isUnique, bool isZeroless, long long allocSize) :
ModeFormatImpl("compressed", isFull, isOrdered, isUnique, false, true, isZeroless,
false, true, false, false, true),
allocSize(allocSize) {
}
Expand All @@ -25,6 +25,7 @@ ModeFormat CompressedModeFormat::copy(
bool isFull = this->isFull;
bool isOrdered = this->isOrdered;
bool isUnique = this->isUnique;
bool isZeroless = this->isZeroless;
for (const auto property : properties) {
switch (property) {
case ModeFormat::FULL:
Expand All @@ -45,12 +46,18 @@ ModeFormat CompressedModeFormat::copy(
case ModeFormat::NOT_UNIQUE:
isUnique = false;
break;
case ModeFormat::ZEROLESS:
isZeroless = true;
break;
case ModeFormat::NOT_ZEROLESS:
isZeroless = false;
break;
default:
break;
}
}
const auto compressedVariant =
std::make_shared<CompressedModeFormat>(isFull, isOrdered, isUnique);
std::make_shared<CompressedModeFormat>(isFull, isOrdered, isUnique, isZeroless);
return ModeFormat(compressedVariant);
}

Expand Down
15 changes: 11 additions & 4 deletions src/lower/mode_format_dense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ using namespace taco::ir;

namespace taco {

DenseModeFormat::DenseModeFormat() : DenseModeFormat(true, true) {
DenseModeFormat::DenseModeFormat() : DenseModeFormat(true, true, false) {
}

DenseModeFormat::DenseModeFormat(const bool isOrdered, const bool isUnique) :
ModeFormatImpl("dense", true, isOrdered, isUnique, false, true, false,
DenseModeFormat::DenseModeFormat(const bool isOrdered, const bool isUnique, const bool isZeroless) :
ModeFormatImpl("dense", true, isOrdered, isUnique, false, true, isZeroless, false,
false, true, true, false) {
}

ModeFormat DenseModeFormat::copy(
std::vector<ModeFormat::Property> properties) const {
bool isOrdered = this->isOrdered;
bool isUnique = this->isUnique;
bool isZeroless = this->isZeroless;
for (const auto property : properties) {
switch (property) {
case ModeFormat::ORDERED:
Expand All @@ -31,11 +32,17 @@ ModeFormat DenseModeFormat::copy(
case ModeFormat::NOT_UNIQUE:
isUnique = false;
break;
case ModeFormat::ZEROLESS:
isZeroless = true;
break;
case ModeFormat::NOT_ZEROLESS:
isZeroless = false;
break;
default:
break;
}
}
return ModeFormat(std::make_shared<DenseModeFormat>(isOrdered, isUnique));
return ModeFormat(std::make_shared<DenseModeFormat>(isOrdered, isUnique, isZeroless));
}

ModeFunction DenseModeFormat::locate(ir::Expr parentPos,
Expand Down
4 changes: 2 additions & 2 deletions src/lower/mode_format_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ std::ostream& operator<<(std::ostream& os, const ModeFunction& modeFunction) {
// class ModeTypeImpl
ModeFormatImpl::ModeFormatImpl(const std::string name, bool isFull,
bool isOrdered, bool isUnique, bool isBranchless,
bool isCompact, bool hasCoordValIter,
bool isCompact, bool isZeroless, bool hasCoordValIter,
bool hasCoordPosIter, bool hasLocate,
bool hasInsert, bool hasAppend) :
name(name), isFull(isFull), isOrdered(isOrdered), isUnique(isUnique),
isBranchless(isBranchless), isCompact(isCompact),
isBranchless(isBranchless), isCompact(isCompact), isZeroless(isZeroless),
hasCoordValIter(hasCoordValIter), hasCoordPosIter(hasCoordPosIter),
hasLocate(hasLocate), hasInsert(hasInsert), hasAppend(hasAppend) {
}
Expand Down
15 changes: 11 additions & 4 deletions src/lower/mode_format_singleton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ using namespace taco::ir;
namespace taco {

SingletonModeFormat::SingletonModeFormat() :
SingletonModeFormat(false, true, true) {
SingletonModeFormat(false, true, true, false) {
}

SingletonModeFormat::SingletonModeFormat(bool isFull, bool isOrdered,
bool isUnique, long long allocSize) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this constructor also be modified to take in isZeroless as an argument?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you are right. Thank you. By the way, it is wired because I modified the code as you suggested about a week ago, but the pull request does not seem to reflect it.

ModeFormatImpl("singleton", isFull, isOrdered, isUnique, true, true,
bool isUnique, bool isZeroless, long long allocSize) :
ModeFormatImpl("singleton", isFull, isOrdered, isUnique, true, true, isZeroless,
false, true, false, false, true),
allocSize(allocSize) {
}
Expand All @@ -25,6 +25,7 @@ ModeFormat SingletonModeFormat::copy(
bool isFull = this->isFull;
bool isOrdered = this->isOrdered;
bool isUnique = this->isUnique;
bool isZeroless = this->isZeroless;
for (const auto property : properties) {
switch (property) {
case ModeFormat::FULL:
Expand All @@ -45,12 +46,18 @@ ModeFormat SingletonModeFormat::copy(
case ModeFormat::NOT_UNIQUE:
isUnique = false;
break;
case ModeFormat::ZEROLESS:
isZeroless = true;
break;
case ModeFormat::NOT_ZEROLESS:
isZeroless = false;
break;
default:
break;
}
}
const auto singletonVariant =
std::make_shared<SingletonModeFormat>(isFull, isOrdered, isUnique);
std::make_shared<SingletonModeFormat>(isFull, isOrdered, isUnique, isZeroless);
return ModeFormat(singletonVariant);
}

Expand Down
3 changes: 2 additions & 1 deletion test/tests-merge_lattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ namespace tests {
class HashedModeFormat : public ModeFormatImpl {
public:
HashedModeFormat() : ModeFormatImpl("hashed", false, false, true, false,
false, false, true, true, true, false) {}
false, false, false, true, true, true, false) {}


ModeFormat copy(std::vector<ModeFormat::Property> properties) const {
return ModeFormat(std::make_shared<HashedModeFormat>());
Expand Down
2 changes: 1 addition & 1 deletion test/tests-storage_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ TEST_P(alloc, storage) {
}

IndexVar i("i"), j("j"), m("m"), n("n"), k("k"), l("l");
ModeFormat SparseSmall(std::make_shared<CompressedModeFormat>(false, true, true,
ModeFormat SparseSmall(std::make_shared<CompressedModeFormat>(false, true, true, false,
32));

IndexArray dlab_indices() {
Expand Down