-
Notifications
You must be signed in to change notification settings - Fork 277
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
Support big endian platform by providing new ops implementation #559
Changes from 5 commits
e026c24
1065f7c
5cb9989
1019c17
50f9ee8
769c649
912e512
af5c1f3
6dc3e9e
6abce3e
a3ee25b
83a0273
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,10 @@ def _import_extra_cpu_backends(): | |
from thinc_apple_ops import AppleOps | ||
except ImportError: | ||
pass | ||
try: | ||
from thinc_bigendian_ops import BigEndianOps | ||
except ImportError: | ||
pass | ||
|
||
|
||
def get_ops(name: str, **kwargs) -> Ops: | ||
|
@@ -91,10 +95,15 @@ def get_ops(name: str, **kwargs) -> Ops: | |
cls: Optional[Callable[..., Ops]] = None | ||
if name == "cpu": | ||
_import_extra_cpu_backends() | ||
|
||
cls = ops_by_name.get("apple", ops_by_name.get("numpy")) | ||
|
||
if "bigendian" in ops_by_name: | ||
cls = ops_by_name.get("bigendian", ops_by_name.get("numpy")) | ||
|
||
else: | ||
cls = ops_by_name.get(name) | ||
|
||
if cls is None: | ||
raise ValueError(f"Invalid backend: {name}") | ||
|
||
|
@@ -113,6 +122,9 @@ def get_array_ops(arr): | |
def use_ops(name: str, **kwargs): | ||
"""Change the backend to execute on for the scope of the block.""" | ||
current_ops = get_current_ops() | ||
# avoid fallback to base NumpyOps if on big endian platform | ||
if current_ops.name == "bigendian" and name == "numpy": | ||
name = current_ops.name | ||
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. I think we've removed all the 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. I removed the highlighted code... At best, this was my attempt to keep an explicit use_ops("numpy") specification from reverting back to numpy ops when explicitly requested from outside of thinc. It is best not to ignore an explicit request. |
||
set_current_ops(get_ops(name, **kwargs)) | ||
try: | ||
yield | ||
|
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.
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.
This is where a ranking from the ops classes themselves would be better.
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.
Updated with suggested change and retested.