Skip to content

Commit f74eae0

Browse files
Split _tensor_impl into three extensions
_tensor_impl continues holding constructors, where, clip _tensor_elementwise_impl holds elementwise functions _tensor_reductions_impl holds reduction functions.
1 parent 6a0b09c commit f74eae0

File tree

4 files changed

+120
-27
lines changed

4 files changed

+120
-27
lines changed

dpctl/tensor/CMakeLists.txt

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ set(_reduction_sources
113113
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/reductions/reduce_hypot.cpp
114114
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/reductions/sum.cpp
115115
)
116+
set(_boolean_reduction_sources
117+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/boolean_reductions.cpp
118+
)
116119
set(_tensor_impl_sources
117-
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/tensor_py.cpp
118-
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/accumulators.cpp
120+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/tensor_ctors.cpp
119121
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/simplify_iteration_space.cpp
122+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/accumulators.cpp
120123
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_and_cast_usm_to_usm.cpp
121124
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_numpy_ndarray_into_usm_ndarray.cpp
122125
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/copy_for_reshape.cpp
@@ -128,19 +131,39 @@ set(_tensor_impl_sources
128131
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/full_ctor.cpp
129132
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/triul_ctor.cpp
130133
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/where.cpp
131-
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/boolean_reductions.cpp
132134
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/device_support_queries.cpp
133135
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/repeat.cpp
134136
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/clip.cpp
135137
)
136-
list(APPEND _tensor_impl_sources
137-
${_elementwise_sources}
138-
${_reduction_sources}
138+
set(_tensor_elementwise_impl_sources
139+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/tensor_elementwise.cpp
140+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/simplify_iteration_space.cpp
141+
${_elementwise_sources}
142+
)
143+
set(_tensor_reductions_impl_sources
144+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/tensor_reductions.cpp
145+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/simplify_iteration_space.cpp
146+
${_boolean_reduction_sources}
147+
${_reduction_sources}
139148
)
140149

150+
set(_py_trgts)
151+
141152
set(python_module_name _tensor_impl)
142153
pybind11_add_module(${python_module_name} MODULE ${_tensor_impl_sources})
143154
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_tensor_impl_sources})
155+
list(APPEND _py_trgts ${python_module_name})
156+
157+
set(python_module_name _tensor_elementwise_impl)
158+
pybind11_add_module(${python_module_name} MODULE ${_tensor_elementwise_impl_sources})
159+
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_tensor_elementwise_impl_sources})
160+
list(APPEND _py_trgts ${python_module_name})
161+
162+
set(python_module_name _tensor_reductions_impl)
163+
pybind11_add_module(${python_module_name} MODULE ${_tensor_reductions_impl_sources})
164+
add_sycl_to_target(TARGET ${python_module_name} SOURCES ${_tensor_reductions_impl_sources})
165+
list(APPEND _py_trgts ${python_module_name})
166+
144167
set(_clang_prefix "")
145168
if (WIN32)
146169
set(_clang_prefix "/clang:")
@@ -170,19 +193,22 @@ if (UNIX)
170193
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/elementwise_functions/sqrt.cpp
171194
PROPERTIES COMPILE_DEFINITIONS "USE_STD_ABS_FOR_COMPLEX_TYPES;USE_STD_SQRT_FOR_COMPLEX_TYPES")
172195
endif()
173-
target_compile_options(${python_module_name} PRIVATE -fno-sycl-id-queries-fit-in-int)
174-
target_link_options(${python_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
175-
if(UNIX)
176-
# this option is supported on Linux only
177-
target_link_options(${python_module_name} PRIVATE -fsycl-link-huge-device-code)
178-
endif()
179-
target_include_directories(${python_module_name}
180-
PRIVATE
181-
${CMAKE_CURRENT_SOURCE_DIR}/../include
182-
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
183-
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
184-
)
196+
185197
set(_linker_options "LINKER:${DPCTL_LDFLAGS}")
186-
target_link_options(${python_module_name} PRIVATE ${_linker_options})
187-
add_dependencies(${python_module_name} _dpctl4pybind11_deps)
188-
install(TARGETS ${python_module_name} DESTINATION "dpctl/tensor")
198+
foreach(python_module_name ${_py_trgts})
199+
target_compile_options(${python_module_name} PRIVATE -fno-sycl-id-queries-fit-in-int)
200+
target_link_options(${python_module_name} PRIVATE -fsycl-device-code-split=per_kernel)
201+
if(UNIX)
202+
# this option is supported on Linux only
203+
target_link_options(${python_module_name} PRIVATE -fsycl-link-huge-device-code)
204+
endif()
205+
target_include_directories(${python_module_name}
206+
PRIVATE
207+
${CMAKE_CURRENT_SOURCE_DIR}/../include
208+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/include
209+
${CMAKE_CURRENT_SOURCE_DIR}/libtensor/source/
210+
)
211+
target_link_options(${python_module_name} PRIVATE ${_linker_options})
212+
add_dependencies(${python_module_name} _dpctl4pybind11_deps)
213+
install(TARGETS ${python_module_name} DESTINATION "dpctl/tensor")
214+
endforeach()

dpctl/tensor/libtensor/source/tensor_py.cpp renamed to dpctl/tensor/libtensor/source/tensor_ctors.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//===-- tensor_py.cpp - Implementation of _tensor_impl module --*-C++-*-/===//
1+
//===-- tensor_ctors.cpp - ---*-C++-*-/===//
2+
// Implementation of _tensor_impl module
23
//
34
// Data Parallel Control (dpctl)
45
//
@@ -43,7 +44,6 @@
4344
#include "copy_for_roll.hpp"
4445
#include "copy_numpy_ndarray_into_usm_ndarray.hpp"
4546
#include "device_support_queries.hpp"
46-
#include "elementwise_functions/elementwise_common.hpp"
4747
#include "eye_ctor.hpp"
4848
#include "full_ctor.hpp"
4949
#include "integer_advanced_indexing.hpp"
@@ -454,8 +454,4 @@ PYBIND11_MODULE(_tensor_impl, m)
454454
"Returns a tuple of events: (hev, ev)",
455455
py::arg("src"), py::arg("min"), py::arg("max"), py::arg("dst"),
456456
py::arg("sycl_queue"), py::arg("depends") = py::list());
457-
458-
dpctl::tensor::py_internal::init_elementwise_functions(m);
459-
dpctl::tensor::py_internal::init_boolean_reduction_functions(m);
460-
dpctl::tensor::py_internal::init_reduction_functions(m);
461457
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===-- tensor_elementwise.cpp ---*-C++-*-/===//
2+
// Implementation of _tensor_elementwise_impl module
3+
//
4+
// Data Parallel Control (dpctl)
5+
//
6+
// Copyright 2020-2023 Intel Corporation
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
///
22+
/// \file
23+
/// This file defines functions of dpctl.tensor._tensor_impl extensions
24+
//===----------------------------------------------------------------------===//
25+
26+
#include "elementwise_functions/elementwise_common.hpp"
27+
#include <pybind11/pybind11.h>
28+
29+
namespace py = pybind11;
30+
31+
PYBIND11_MODULE(_tensor_elementwise_impl, m)
32+
{
33+
dpctl::tensor::py_internal::init_elementwise_functions(m);
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===-- tensor_reductions.cpp - --*-C++-*-/===//
2+
// Implementation of _tensor_reductions_impl module
3+
//
4+
// Data Parallel Control (dpctl)
5+
//
6+
// Copyright 2020-2023 Intel Corporation
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
//===----------------------------------------------------------------------===//
21+
///
22+
/// \file
23+
/// This file defines functions of dpctl.tensor._tensor_impl extensions
24+
//===----------------------------------------------------------------------===//
25+
26+
#include <pybind11/pybind11.h>
27+
28+
#include "boolean_reductions.hpp"
29+
#include "reductions/reduction_common.hpp"
30+
31+
namespace py = pybind11;
32+
33+
PYBIND11_MODULE(_tensor_reductions_impl, m)
34+
{
35+
dpctl::tensor::py_internal::init_boolean_reduction_functions(m);
36+
dpctl::tensor::py_internal::init_reduction_functions(m);
37+
}

0 commit comments

Comments
 (0)