Skip to content

Commit

Permalink
Activate the NumPy fallback for cunumeric.random in CPU build (nv-leg…
Browse files Browse the repository at this point in the history
…ate#485)

* Activate the NumPy fallback for cunumeric.random in CPU build

* Fix for mypy errors
  • Loading branch information
magnatelee authored and sbak5 committed Aug 17, 2022
1 parent 9375084 commit de2dd64
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
3 changes: 3 additions & 0 deletions cunumeric/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ class _CunumericSharedLib:
CUNUMERIC_WRITE: int
CUNUMERIC_ZIP: int

def cunumeric_has_curand(self) -> int:
...


# Load the cuNumeric library first so we have a shard object that
# we can use to initialize all these configuration enumerations
Expand Down
9 changes: 6 additions & 3 deletions cunumeric/random/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
from __future__ import annotations

import numpy.random as _nprandom
from cunumeric.random.random import *
from cunumeric.coverage import clone_module
from cunumeric.random.bitgenerator import *
from cunumeric.random.generator import *
from cunumeric.runtime import runtime

if runtime.has_curand:
from cunumeric.random.random import *
from cunumeric.random.bitgenerator import *
from cunumeric.random.generator import *

clone_module(_nprandom, globals())

Expand Down
2 changes: 2 additions & 0 deletions cunumeric/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def __init__(self, legate_context: LegateContext) -> None:
# Make sure that our CuNumericLib object knows about us so it can
# destroy us
cunumeric_lib.set_runtime(self)
assert cunumeric_lib.shared_object is not None
self.has_curand = cunumeric_lib.shared_object.cunumeric_has_curand()
self._register_dtypes()

self.args = parse_command_args("cunumeric", ARGS)
Expand Down
9 changes: 9 additions & 0 deletions src/cunumeric/cunumeric.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ void cunumeric_perform_registration(void)
ctx, CUNUMERIC_TUNABLE_HAS_NUMAMEM, cunumeric::CuNumeric::mapper_id);
if (fut.get_result<int32_t>() != 0) cunumeric::CuNumeric::has_numamem = true;
}

bool cunumeric_has_curand()
{
#ifdef LEGATE_USE_CUDA
return true;
#else
return false;
#endif
}
}
1 change: 1 addition & 0 deletions src/cunumeric/cunumeric_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ extern "C" {
#endif

void cunumeric_perform_registration();
bool cunumeric_has_curand();

#ifdef __cplusplus
}
Expand Down
6 changes: 5 additions & 1 deletion src/cunumeric/unary/isnan.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ __CUDA_HD__ bool is_nan(const complex<T>& x)
return std::isnan(x.imag()) || std::isnan(x.real());
}

__CUDA_HD__ inline bool is_nan(const __half& x) { return isnan(x); }
__CUDA_HD__ inline bool is_nan(const __half& x)
{
using std::isnan;
return isnan(x);
}

} // namespace cunumeric

0 comments on commit de2dd64

Please sign in to comment.