Skip to content

Commit d96cb13

Browse files
modify test sample
2 parents 798736c + e88035d commit d96cb13

File tree

129 files changed

+3469
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3469
-537
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ repos:
151151
(?x)^(
152152
paddle/fluid/operators/CMakeLists.txt
153153
)$
154-
- repo: https://github.com/cmake-lint/cmake-lint
155-
rev: 1.4.2
154+
- repo: https://github.com/PFCCLab/cmake-lint-paddle
155+
rev: v1.5.1
156156
hooks:
157157
- id: cmakelint
158158
args: [--config=./tools/codestyle/.cmakelintrc]

cmake/external/protobuf.cmake

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ if(NOT "${PROTOBUF_ROOT}" STREQUAL "")
182182
endif()
183183
endif()
184184

185-
function(build_protobuf TARGET_NAME BUILD_FOR_HOST)
185+
function(build_protobuf TARGET_NAME)
186186
string(REPLACE "extern_" "" TARGET_DIR_NAME "${TARGET_NAME}")
187187
set(PROTOBUF_PREFIX_DIR ${THIRD_PARTY_PATH}/${TARGET_DIR_NAME})
188188
set(PROTOBUF_SOURCE_DIR
@@ -210,22 +210,18 @@ function(build_protobuf TARGET_NAME BUILD_FOR_HOST)
210210
PARENT_SCOPE)
211211

212212
set(OPTIONAL_CACHE_ARGS "")
213-
set(OPTIONAL_ARGS "")
214-
if(BUILD_FOR_HOST)
215-
set(OPTIONAL_ARGS "-Dprotobuf_WITH_ZLIB=OFF")
216-
else()
217-
set(OPTIONAL_ARGS
218-
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
219-
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
220-
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}"
221-
"-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}"
222-
"-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}"
223-
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
224-
"-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}"
225-
"-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}"
226-
"-Dprotobuf_WITH_ZLIB=ON"
227-
"-DZLIB_ROOT:FILEPATH=${ZLIB_ROOT}"
228-
${EXTERNAL_OPTIONAL_ARGS})
213+
set(OPTIONAL_ARGS
214+
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
215+
"-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}"
216+
"-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}"
217+
"-DCMAKE_C_FLAGS_DEBUG=${CMAKE_C_FLAGS_DEBUG}"
218+
"-DCMAKE_C_FLAGS_RELEASE=${CMAKE_C_FLAGS_RELEASE}"
219+
"-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
220+
"-DCMAKE_CXX_FLAGS_RELEASE=${CMAKE_CXX_FLAGS_RELEASE}"
221+
"-DCMAKE_CXX_FLAGS_DEBUG=${CMAKE_CXX_FLAGS_DEBUG}"
222+
"-Dprotobuf_WITH_ZLIB=ON"
223+
${EXTERNAL_OPTIONAL_ARGS})
224+
if(NOT APPLE)
229225
set(OPTIONAL_CACHE_ARGS "-DZLIB_ROOT:STRING=${ZLIB_ROOT}")
230226
endif()
231227
if(WIN32)
@@ -339,7 +335,7 @@ else()
339335
endif()
340336

341337
if(NOT PROTOBUF_FOUND)
342-
build_protobuf(extern_protobuf FALSE)
338+
build_protobuf(extern_protobuf)
343339

344340
set(PROTOBUF_INCLUDE_DIR
345341
${extern_protobuf_INCLUDE_DIR}

cmake/inference_lib.cmake

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,11 @@ else()
268268
SRCS ${paddle_phi_lib}
269269
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
270270
endif()
271-
if(WITH_SHARED_IR)
272-
set(paddle_pir_lib ${PADDLE_BINARY_DIR}/paddle/pir/libpir.*)
273-
copy(
274-
inference_lib_dist
275-
SRCS ${paddle_pir_lib}
276-
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
277-
endif()
271+
set(paddle_common_lib ${PADDLE_BINARY_DIR}/paddle/common/libcommon.*)
272+
copy(
273+
inference_lib_dist
274+
SRCS ${paddle_common_lib}
275+
DSTS ${PADDLE_INFERENCE_INSTALL_DIR}/paddle/lib)
278276
endif()
279277

280278
copy(

paddle/cinn/auto_schedule/cost_model/feature_extractor_test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ TEST(FeatureExtractor, SimpleAssign) {
8989
ASSERT_EQ(to_check[29], slog(3));
9090
}
9191

92+
#ifdef CINN_WITH_CUDA
9293
TEST(FeatureExtractor, MatrixMultiply) {
9394
Context::Global().ResetNameId();
9495
#ifdef CINN_WITH_CUDA
@@ -162,6 +163,6 @@ TEST(FeatureExtractor, MatrixMultiply) {
162163
// GpuBind loop
163164
ASSERT_EQ(to_check[37], slog(out_loop));
164165
}
165-
166+
#endif
166167
} // namespace auto_schedule
167168
} // namespace cinn

paddle/cinn/backends/ir_schedule_test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ void test_unroll(void* _args, int32_t num_args)
690690
ASSERT_EQ(utils::Trim(target_code), utils::Trim(source_code));
691691
}
692692

693+
#ifdef CINN_WITH_CUDA
693694
TEST(IrSchedule, bind) {
694695
Context::Global().ResetNameId();
695696
Expr M(32);
@@ -733,6 +734,7 @@ function test_bind (_A, _B)
733734
}
734735
)ROC"));
735736
}
737+
#endif
736738

737739
TEST(IrSchedule, simple_compute_at) {
738740
Context::Global().ResetNameId();

paddle/cinn/common/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ gather_srcs(
1919
arithmatic.cc
2020
cas.cc
2121
union_find.cc
22-
python_interpreter_guard.cc)
22+
python_interpreter_guard.cc
23+
dev_info_manager.cc
24+
nvgpu_dev_info.cc)
2325

2426
message(STATUS "srcs: ${cinnapi_src}")
2527

paddle/cinn/common/dev_info_base.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
namespace cinn {
18+
namespace common {
19+
20+
class DevInfoBase {
21+
public:
22+
virtual ~DevInfoBase() = default;
23+
};
24+
25+
} // namespace common
26+
} // namespace cinn
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <glog/logging.h>
16+
17+
#include "paddle/cinn/common/dev_info_base.h"
18+
#include "paddle/cinn/common/dev_info_manager.h"
19+
20+
namespace cinn {
21+
namespace common {
22+
23+
DevInfoMgr::DevInfoMgr(Target::Arch arch, int device_num)
24+
: arch_(arch), device_num_(device_num) {
25+
switch (arch) {
26+
case Target::Arch::ARM:
27+
case Target::Arch::X86:
28+
case Target::Arch::Unk:
29+
impl_ = std::make_unique<DevInfoBase>();
30+
break;
31+
case Target::Arch::NVGPU:
32+
#ifdef CINN_WITH_CUDA
33+
impl_ = std::make_unique<NVGPUDevInfo>(device_num);
34+
#endif
35+
default:
36+
CHECK(false) << "Current device can't be recognized!\n";
37+
break;
38+
}
39+
}
40+
41+
std::unique_ptr<DevInfoMgr> DevInfoMgr::GetDevInfo(Target::Arch arch,
42+
int device_num) {
43+
std::unique_ptr<DevInfoMgr> ret(new DevInfoMgr(arch, device_num));
44+
return ret;
45+
}
46+
47+
} // namespace common
48+
} // namespace cinn
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <memory>
18+
19+
#include "paddle/cinn/common/macros.h"
20+
#include "paddle/cinn/common/nvgpu_dev_info.h"
21+
#include "paddle/cinn/common/target.h"
22+
23+
namespace cinn {
24+
namespace common {
25+
26+
class DevInfoMgr final {
27+
private:
28+
explicit DevInfoMgr(Target::Arch arch = Target::Arch::Unk,
29+
int device_num = 0);
30+
std::unique_ptr<DevInfoBase> impl_;
31+
Target::Arch arch_;
32+
int device_num_;
33+
34+
public:
35+
static std::unique_ptr<DevInfoMgr> GetDevInfo(
36+
Target::Arch arch = Target::Arch::NVGPU, int device_num = 0);
37+
38+
// Extra device should be added here
39+
#ifdef CINN_WITH_CUDA
40+
using RET_TYPE = NVGPUDevInfo;
41+
const RET_TYPE* operator->() const {
42+
CHECK(!std::is_void<RET_TYPE>()) << "Current device can't be recognized!\n";
43+
return dynamic_cast<const RET_TYPE*>(impl_.get());
44+
}
45+
RET_TYPE* operator->() {
46+
CHECK(!std::is_void<RET_TYPE>()) << "Current device can't be recognized!\n";
47+
return dynamic_cast<RET_TYPE*>(impl_.get());
48+
}
49+
#endif
50+
};
51+
52+
} // namespace common
53+
} // namespace cinn
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) 2023 CINN Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#ifdef CINN_WITH_CUDA
15+
#include "paddle/cinn/common/nvgpu_dev_info.h"
16+
17+
namespace cinn {
18+
namespace common {
19+
20+
std::array<int, 3> NVGPUDevInfo::GetMaxGridDims() const {
21+
std::array<int, 3> ret;
22+
ret[0] = prop_->maxGridSize[0];
23+
ret[1] = prop_->maxGridSize[1];
24+
ret[2] = prop_->maxGridSize[2];
25+
return ret;
26+
}
27+
28+
std::array<int, 3> NVGPUDevInfo::GetMaxBlockDims() const {
29+
std::array<int, 3> ret;
30+
ret[0] = prop_->maxThreadsDim[0];
31+
ret[1] = prop_->maxThreadsDim[1];
32+
ret[2] = prop_->maxThreadsDim[2];
33+
return ret;
34+
}
35+
36+
int NVGPUDevInfo::GetMultiProcessorCount() const {
37+
return prop_->multiProcessorCount;
38+
}
39+
40+
int NVGPUDevInfo::GetMaxThreadsPerMultiProcessor() const {
41+
return prop_->maxThreadsPerMultiProcessor;
42+
}
43+
44+
int NVGPUDevInfo::GetMaxThreadsPerBlock() const {
45+
return prop_->maxThreadsPerBlock;
46+
}
47+
48+
} // namespace common
49+
} // namespace cinn
50+
#endif

0 commit comments

Comments
 (0)