-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kernel bitwise_or #158
Open
Janicewei
wants to merge
2
commits into
master
Choose a base branch
from
cw655_or_1008
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
kernel bitwise_or #158
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <cmath> | ||
#include <ATen/Dispatch.h> | ||
#include <ATen/hammerblade/HammerBladeContext.h> | ||
#include <ATen/native/TensorIterator.h> | ||
#include <ATen/native/ReduceOps.h> | ||
#include <ATen/native/hammerblade/Offload.h> | ||
|
||
namespace at { namespace native { | ||
|
||
Tensor or_kernel_hb(const Tensor& self, const Tensor& other) { | ||
TORCH_CHECK(self.numel() == other.numel(), "The size of two tensors should match."); | ||
// TORCH_CHECK(self.scalar_type() == ScalarType::Int || self.scalar_type() == ScalarType::Bool, "HammerBlade or is implemented for Int and Bool only"); | ||
// TORCH_CHECK(other.scalar_type() == ScalarType::Int || other.scalar_type() == ScalarType::Bool, "HammerBlade or is implemented for Int and Bool only"); | ||
Tensor result = at::empty_like(self, self.options()); | ||
hb_offload_kernel(result, self, other, "tensorlib_or"); | ||
return result; | ||
} | ||
|
||
}} // namespace at::native |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//======================================================================== | ||
// Element-wise or kernel | ||
//======================================================================== | ||
// | ||
// Authors : Janice Wei | ||
// Date : 10/08/2020 | ||
|
||
#include <kernel_common.hpp> | ||
#include <cstdint> | ||
|
||
extern "C" { | ||
|
||
__attribute__ ((noinline)) int tensorlib_or( | ||
hb_tensor_t* t0_p, | ||
hb_tensor_t* t1_p, | ||
hb_tensor_t* t2_p) { | ||
auto res = HBTensor<int>(t0_p); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to |
||
auto input1 = HBTensor<int>(t1_p); | ||
auto input2 = HBTensor<int>(t2_p); | ||
|
||
bsg_cuda_print_stat_kernel_start(); | ||
|
||
hb_tiled_foreach( | ||
[](int a, int b) { | ||
return a | b; | ||
}, | ||
res, input1, input2); | ||
|
||
bsg_cuda_print_stat_kernel_end(); | ||
|
||
g_barrier.sync(); | ||
return 0; | ||
} | ||
|
||
HB_EMUL_REG_KERNEL(tensorlib_or, hb_tensor_t*, hb_tensor_t*, hb_tensor_t*) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
tests of or kernel | ||
Authors : Janice Wei | ||
Date : 10/08/2020 | ||
""" | ||
|
||
import torch | ||
import random | ||
from hypothesis import given, settings | ||
from .hypothesis_test_util import HypothesisUtil as hu | ||
|
||
torch.manual_seed(42) | ||
random.seed(42) | ||
|
||
# ------------------------------------------------------------------------ | ||
# test of x1 | x2 | ||
# ------------------------------------------------------------------------ | ||
|
||
def _test_or(x1, x2): | ||
h1 = x1.hammerblade() | ||
h2 = x2.hammerblade() | ||
assert h1 is not x1 | ||
assert h2 is not x2 | ||
y_c = x1 | x2 | ||
y_h = h1 | h2 | ||
assert y_h.device == torch.device("hammerblade") | ||
assert torch.allclose(y_c, y_h.cpu()) | ||
|
||
# ------------------------------------------------------------------------ | ||
# tests of or kernel with integer elements | ||
# ------------------------------------------------------------------------ | ||
|
||
def test_or_1(): | ||
x = torch.ones(1, 10, dtype=torch.int) | ||
_test_or(x, x) | ||
|
||
def test_or_2(): | ||
x1 = torch.ones(4, 5, dtype=torch.int) | ||
x2 = torch.ones(4, 5, dtype=torch.int) | ||
_test_or(x1, x2) | ||
|
||
def test_or_3(): | ||
x = torch.randint(-2 ** 30, 2 ** 30 - 1, (1, 128)).to(torch.int32) | ||
y = torch.randint(-2 ** 30, 2 ** 30 - 1, (1, 128)).to(torch.int32) | ||
_test_or(x, y) | ||
|
||
def test_or_4(): | ||
x = torch.randint(-2 ** 30, 2 ** 30 - 1, (16, 32)).to(torch.int32) | ||
y = torch.randint(-2 ** 30, 2 ** 30 - 1, (16, 32)).to(torch.int32) | ||
_test_or(x, y) | ||
|
||
@settings(deadline=None) | ||
@given(inputs=hu.tensors(n=2)) | ||
def test_or_hypothesis(inputs): | ||
x1 = torch.tensor(inputs[0]).to(torch.int32) | ||
x2 = torch.tensor(inputs[1]).to(torch.int32) | ||
_test_or(x1, x2) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as
and
, I think if you doself.scalar_type() == kInt
it will workMaybe you need
at::kInt
...