MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / elementwise_func

Function elementwise_func

bitsandbytes/functional.py:155–179  ·  view source on GitHub ↗
(func_name, A, B, value, prefetch=True)

Source from the content-addressed store, hash-verified

153
154
155def elementwise_func(func_name, A, B, value, prefetch=True):
156 func = None
157 if A.dtype == torch.float32:
158 func = getattr(lib, f"c{func_name}_fp32", None)
159 cvalue = ct.c_float(value)
160 elif A.dtype == torch.uint8:
161 func = getattr(lib, f"c{func_name}_uint8", None)
162 cvalue = ct.c_uint8(value)
163
164 if func is None:
165 raise NotImplementedError(f"Function not implemented: {func_name}")
166
167 is_managed = getattr(A, "is_managed", False)
168 if is_managed and prefetch:
169 prefetch_tensor(A)
170 if B is not None:
171 prefetch_tensor(B)
172
173 func(get_ptr(A), get_ptr(B), cvalue, ct.c_int64(A.numel()))
174 if A.is_paged or B.is_paged:
175 # paged function are fully asynchronous
176 # if we return from this function, we want to the tensor
177 # to be in the correct state, that is the final state after the
178 # operation occurred. So we synchronize.
179 torch.cuda.synchronize()
180
181
182def fill(A, value, device=None, prefetch=True):

Callers 2

fillFunction · 0.85
_mulFunction · 0.85

Calls 2

prefetch_tensorFunction · 0.85
get_ptrFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…