mirror of
https://github.com/iperov/DeepFaceLive
synced 2025-08-21 05:53:25 -07:00
update xlib.avecl
This commit is contained in:
parent
dedacc9753
commit
7aef4d2b1e
3 changed files with 42 additions and 2 deletions
37
xlib/avecl/_internal/initializer/InitConst.py
Normal file
37
xlib/avecl/_internal/initializer/InitConst.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from ..backend import Kernel
|
||||
from ..HKernel import HKernel
|
||||
from ..SCacheton import SCacheton
|
||||
from ..Tensor import Tensor
|
||||
from .Initializer import Initializer
|
||||
|
||||
|
||||
class InitConst(Initializer):
|
||||
|
||||
def __init__(self, value=0):
|
||||
"""
|
||||
arguments
|
||||
|
||||
value(0)
|
||||
"""
|
||||
super().__init__()
|
||||
self._value = value
|
||||
|
||||
def initialize_tensor(self, tensor : Tensor):
|
||||
|
||||
key = (InitConst, self._value, tensor.dtype)
|
||||
kernel = SCacheton.get_var(key)
|
||||
if kernel is None:
|
||||
kernel = Kernel(kernel_text=f"""
|
||||
{HKernel.define_tensor('O', (tensor.shape.size,), tensor.dtype )}
|
||||
__kernel void impl(__global O_PTR_TYPE* O_PTR_NAME)
|
||||
{{
|
||||
O_GLOBAL_STORE(get_global_id(0), (O_TYPE){self._value} );
|
||||
}}
|
||||
""")
|
||||
SCacheton.set_var(key, kernel)
|
||||
|
||||
tensor.get_device().run_kernel( kernel, tensor.get_buffer(),
|
||||
global_shape=(tensor.shape.size,) )
|
||||
|
||||
def __str__(self): return f'InitConst low={self._low}, high={self._high}'
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from .InitConst import InitConst
|
||||
from .InitCoords2DArange import InitCoords2DArange
|
||||
from .Initializer import Initializer
|
||||
from .InitRandomUniform import InitRandomUniform
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue