當前位置: 首頁>>代碼示例>>Python>>正文


Python cpp_extension.load方法代碼示例

本文整理匯總了Python中torch.utils.cpp_extension.load方法的典型用法代碼示例。如果您正苦於以下問題:Python cpp_extension.load方法的具體用法?Python cpp_extension.load怎麽用?Python cpp_extension.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.utils.cpp_extension的用法示例。


在下文中一共展示了cpp_extension.load方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load_C_extensions

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def _load_C_extensions():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    this_dir = os.path.dirname(this_dir)
    this_dir = os.path.join(this_dir, "csrc")

    main_file = glob.glob(os.path.join(this_dir, "*.cpp"))
    source_cpu = glob.glob(os.path.join(this_dir, "cpu", "*.cpp"))
    source_cuda = glob.glob(os.path.join(this_dir, "cuda", "*.cu"))

    source = main_file + source_cpu

    extra_cflags = []
    if torch.cuda.is_available() and CUDA_HOME is not None:
        source.extend(source_cuda)
        extra_cflags = ["-DWITH_CUDA"]
    source = [os.path.join(this_dir, s) for s in source]
    extra_include_paths = [this_dir]
    return load_ext(
        "torchvision",
        source,
        extra_cflags=extra_cflags,
        extra_include_paths=extra_include_paths,
    ) 
開發者ID:Res2Net,項目名稱:Res2Net-maskrcnn,代碼行數:25,代碼來源:_utils.py

示例2: _load_C_extensions

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def _load_C_extensions():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    this_dir = os.path.join(this_dir, "csrc")

    main_file = glob.glob(os.path.join(this_dir, "*.cpp"))
    sources_cpu = glob.glob(os.path.join(this_dir, "cpu", "*.cpp"))
    sources_cuda = glob.glob(os.path.join(this_dir, "cuda", "*.cu"))

    sources = main_file + sources_cpu

    extra_cflags = []
    extra_cuda_cflags = []
    if torch.cuda.is_available() and CUDA_HOME is not None:
        sources.extend(sources_cuda)
        extra_cflags = ["-O3", "-DWITH_CUDA"]
        extra_cuda_cflags = ["--expt-extended-lambda"]
    sources = [os.path.join(this_dir, s) for s in sources]
    extra_include_paths = [this_dir]
    return load(
        name="ext_lib",
        sources=sources,
        extra_cflags=extra_cflags,
        extra_include_paths=extra_include_paths,
        extra_cuda_cflags=extra_cuda_cflags,
    ) 
開發者ID:tamakoji,項目名稱:pytorch-syncbn,代碼行數:27,代碼來源:_csrc.py

示例3: __init__

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def __init__(self, shapes, verbose=True):
        """

        Parameters
        ----------
        shapes : np.ndarray
            eigen shapes (obtained by PCA)

        """
        super().__init__()

        self.register_buffer("_shape_mean",
                             torch.from_numpy(shapes[0]).float().unsqueeze(0))
        components = []
        for i, _shape in enumerate(shapes[1:]):
            components.append(torch.from_numpy(_shape).float().unsqueeze(0))

        component_tensor = torch.cat(components).unsqueeze(0)
        self.register_buffer("_shape_components", component_tensor)
        self._func = load_cpp("shape_function",
                              sources=[os.path.join(os.path.split(__file__)[0],
                                                    "shape_layer.cpp")],
                              verbose=verbose) 
開發者ID:justusschock,項目名稱:shapenet,代碼行數:25,代碼來源:shape_layer.py

示例4: load_cpp_ext

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def load_cpp_ext(ext_name):
    root_dir = os.path.join(os.path.split(__file__)[0])
    src_dir = os.path.join(root_dir, "cpp")
    tar_dir = os.path.join(src_dir, "build", ext_name)
    os.makedirs(tar_dir, exist_ok=True)
    srcs = glob(f"{src_dir}/*.cu") + glob(f"{src_dir}/*.cpp")

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        from torch.utils.cpp_extension import load

        ext = load(
            name=ext_name,
            sources=srcs,
            extra_cflags=["-O3"],
            extra_cuda_cflags=[],
            build_directory=tar_dir,
        )
    return ext


# defer calling load_cpp_ext to make CUDA_VISIBLE_DEVICES happy 
開發者ID:zhou13,項目名稱:neurvps,代碼行數:24,代碼來源:deformable.py

示例5: _lazy_load_cpu_kernel

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def _lazy_load_cpu_kernel():
    global SRU_CPU_kernel
    if SRU_CPU_kernel is not None:
        return SRU_CPU_kernel
    try:
        from torch.utils.cpp_extension import load
        cpu_source = os.path.join(os.path.dirname(__file__), "sru_cpu_impl.cpp")
        SRU_CPU_kernel = load(
            name="sru_cpu_impl",
            sources=[cpu_source],
            extra_cflags=['-O3'],
            verbose=False
        )
    except:
        # use Python version instead
        SRU_CPU_kernel = False
    return SRU_CPU_kernel

# load C++ implementation for GPU computation 
開發者ID:asappresearch,項目名稱:sru,代碼行數:21,代碼來源:sru_functional.py

示例6: __init__

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def __init__(self, n_dims, verbose=True):
        """

        Parameters
        ----------
        n_dims : int
            number of dimensions
        verbose : float
            if True: verbosity during C++ loading

        """
        super().__init__()

        homogen_trafo = torch.zeros(1, n_dims + 1, n_dims + 1)
        homogen_trafo[:, -1, :-1] = 0.
        homogen_trafo[:, -1, -1] = 1.

        self.register_buffer("_trafo_matrix", homogen_trafo)
        self._n_dims = n_dims

        self._func = load_cpp("homogeneous_transform_function",
                              sources=[
                                  os.path.join(
                                      os.path.split(__file__)[0],
                                      "homogeneous_transform_layer.cpp")],
                              verbose=verbose) 
開發者ID:justusschock,項目名稱:shapenet,代碼行數:28,代碼來源:homogeneous_transform_layer.py

示例7: _load_C_extensions

# 需要導入模塊: from torch.utils import cpp_extension [as 別名]
# 或者: from torch.utils.cpp_extension import load [as 別名]
def _load_C_extensions():
    this_dir = os.path.dirname(os.path.abspath(__file__))
    this_dir = os.path.dirname(this_dir)
    this_dir = os.path.join(this_dir, "csrc")

    main_file = glob.glob(os.path.join(this_dir, "*.cpp"))
    source_cpu = glob.glob(os.path.join(this_dir, "cpu", "*.cpp"))
    source_cuda = glob.glob(os.path.join(this_dir, "cuda", "*.cu"))

    source = main_file + source_cpu

    extra_cflags = []
    if torch.cuda.is_available() and CUDA_HOME is not None:
        source.extend(source_cuda)
        extra_cflags = ["-DWITH_CUDA"]
    source = [os.path.join(this_dir, s) for s in source]
    extra_include_paths = [this_dir]
    build_dir = os.path.dirname(os.path.abspath(__file__))
    build_dir = os.path.dirname(build_dir)
    build_dir = os.path.dirname(build_dir)
    build_dir = os.path.join(build_dir, 'jit', 'torchvision')
    if not os.path.exists(build_dir):
        os.makedirs(build_dir)

    return load_ext(
        "torchvision",
        source,
        extra_cflags=extra_cflags,
        extra_include_paths=extra_include_paths,
        build_directory=build_dir,
        verbose=True,
    ) 
開發者ID:Lausannen,項目名稱:NAS-FCOS,代碼行數:34,代碼來源:_utils.py


注:本文中的torch.utils.cpp_extension.load方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。