Skip to content

Commit 40de518

Browse files
author
pradeep
committed
Add hidden functions to get/set max jit length for tests
These functions are not exposed to users. They are not included when generating installers. These functions are purely for testing certain internal behavior given a certain combination of environment variables. Test for unit max JIT height infinite recursion bug
1 parent 01f34e8 commit 40de518

15 files changed

Lines changed: 179 additions & 21 deletions

src/api/c/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ target_sources(c_api_interface
105105
${CMAKE_CURRENT_SOURCE_DIR}/index.cpp
106106
${CMAKE_CURRENT_SOURCE_DIR}/internal.cpp
107107
${CMAKE_CURRENT_SOURCE_DIR}/inverse.cpp
108+
${CMAKE_CURRENT_SOURCE_DIR}/jit_test_api.h
109+
${CMAKE_CURRENT_SOURCE_DIR}/jit_test_api.cpp
108110
${CMAKE_CURRENT_SOURCE_DIR}/join.cpp
109111
${CMAKE_CURRENT_SOURCE_DIR}/lu.cpp
110112
${CMAKE_CURRENT_SOURCE_DIR}/match_template.cpp

src/api/c/jit_test_api.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************
2+
* Copyright (c) 2021, ArrayFire
3+
* All rights reserved.
4+
*
5+
* This file is distributed under 3-clause BSD license.
6+
* The complete license agreement can be obtained at:
7+
* http://arrayfire.com/licenses/BSD-3-Clause
8+
********************************************************/
9+
10+
#include <jit_test_api.h>
11+
12+
#include <backend.hpp>
13+
#include <common/err_common.hpp>
14+
#include <platform.hpp>
15+
16+
af_err af_get_max_jit_len(int *jitLen) {
17+
*jitLen = detail::getMaxJitSize();
18+
return AF_SUCCESS;
19+
}
20+
21+
af_err af_set_max_jit_len(const int maxJitLen) {
22+
try {
23+
ARG_ASSERT(1, maxJitLen > 0);
24+
detail::getMaxJitSize() = maxJitLen;
25+
}
26+
CATCHALL;
27+
return AF_SUCCESS;
28+
}

src/api/c/jit_test_api.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*******************************************************
2+
* Copyright (c) 2021, ArrayFire
3+
* All rights reserved.
4+
*
5+
* This file is distributed under 3-clause BSD license.
6+
* The complete license agreement can be obtained at:
7+
* http://arrayfire.com/licenses/BSD-3-Clause
8+
********************************************************/
9+
10+
#pragma once
11+
12+
#include <af/defines.h>
13+
14+
#ifdef __cplusplus
15+
namespace af {
16+
/// Get the maximum jit tree length for active backend
17+
///
18+
/// \returns the maximum length of jit tree from root to any leaf
19+
AFAPI int getMaxJitLen(void);
20+
21+
/// Set the maximum jit tree length for active backend
22+
///
23+
/// \param[in] jit_len is the maximum length of jit tree from root to any
24+
/// leaf
25+
AFAPI void setMaxJitLen(const int jitLen);
26+
} // namespace af
27+
#endif //__cplusplus
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/// Get the maximum jit tree length for active backend
34+
///
35+
/// \param[out] jit_len is the maximum length of jit tree from root to any
36+
/// leaf
37+
///
38+
/// \returns Always returns AF_SUCCESS
39+
AFAPI af_err af_get_max_jit_len(int *jit_len);
40+
41+
/// Set the maximum jit tree length for active backend
42+
///
43+
/// \param[in] jit_len is the maximum length of jit tree from root to any
44+
/// leaf
45+
///
46+
/// \returns Always returns AF_SUCCESS
47+
AFAPI af_err af_set_max_jit_len(const int jit_len);
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif

src/api/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ target_sources(cpp_api_interface
4545
${CMAKE_CURRENT_SOURCE_DIR}/imageio.cpp
4646
${CMAKE_CURRENT_SOURCE_DIR}/index.cpp
4747
${CMAKE_CURRENT_SOURCE_DIR}/internal.cpp
48+
${CMAKE_CURRENT_SOURCE_DIR}/jit_test_api.cpp
4849
${CMAKE_CURRENT_SOURCE_DIR}/lapack.cpp
4950
${CMAKE_CURRENT_SOURCE_DIR}/matchTemplate.cpp
5051
${CMAKE_CURRENT_SOURCE_DIR}/mean.cpp

src/api/cpp/jit_test_api.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*******************************************************
2+
* Copyright (c) 2021, ArrayFire
3+
* All rights reserved.
4+
*
5+
* This file is distributed under 3-clause BSD license.
6+
* The complete license agreement can be obtained at:
7+
* http://arrayfire.com/licenses/BSD-3-Clause
8+
********************************************************/
9+
10+
#include <jit_test_api.h>
11+
#include "error.hpp"
12+
13+
namespace af {
14+
int getMaxJitLen(void) {
15+
int retVal = 0;
16+
AF_THROW(af_get_max_jit_len(&retVal));
17+
return retVal;
18+
}
19+
20+
void setMaxJitLen(const int jitLen) { AF_THROW(af_set_max_jit_len(jitLen)); }
21+
} // namespace af

src/api/unified/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ target_sources(af
2222
${CMAKE_CURRENT_SOURCE_DIR}/image.cpp
2323
${CMAKE_CURRENT_SOURCE_DIR}/index.cpp
2424
${CMAKE_CURRENT_SOURCE_DIR}/internal.cpp
25+
${CMAKE_CURRENT_SOURCE_DIR}/jit_test_api.cpp
2526
${CMAKE_CURRENT_SOURCE_DIR}/lapack.cpp
2627
${CMAKE_CURRENT_SOURCE_DIR}/memory.cpp
2728
${CMAKE_CURRENT_SOURCE_DIR}/ml.cpp

src/api/unified/jit_test_api.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*******************************************************
2+
* Copyright (c) 2021, ArrayFire
3+
* All rights reserved.
4+
*
5+
* This file is distributed under 3-clause BSD license.
6+
* The complete license agreement can be obtained at:
7+
* http://arrayfire.com/licenses/BSD-3-Clause
8+
********************************************************/
9+
10+
#include <jit_test_api.h>
11+
12+
#include "symbol_manager.hpp"
13+
14+
af_err af_get_max_jit_len(int *jitLen) { CALL(af_get_max_jit_len, jitLen); }
15+
16+
af_err af_set_max_jit_len(const int jitLen) {
17+
CALL(af_set_max_jit_len, jitLen);
18+
}

src/backend/cpu/platform.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,14 @@ void devprop(char* d_name, char* d_platform, char* d_toolkit, char* d_compute) {
104104
snprintf(d_compute, 10, "%s", "0.0");
105105
}
106106

107-
unsigned getMaxJitSize() {
108-
const int MAX_JIT_LEN = 100;
109-
110-
thread_local int length = 0;
111-
if (length == 0) {
107+
int& getMaxJitSize() {
108+
constexpr int MAX_JIT_LEN = 100;
109+
thread_local int length = 0;
110+
if (length <= 0) {
112111
string env_var = getEnvVar("AF_CPU_MAX_JIT_LEN");
113112
if (!env_var.empty()) {
114-
length = stoi(env_var);
113+
int input_len = std::stoi(env_var);
114+
length = input_len > 0 ? input_len : MAX_JIT_LEN;
115115
} else {
116116
length = MAX_JIT_LEN;
117117
}

src/backend/cpu/platform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ bool isHalfSupported(int device);
3636

3737
void devprop(char* d_name, char* d_platform, char* d_toolkit, char* d_compute);
3838

39-
unsigned getMaxJitSize();
39+
int& getMaxJitSize();
4040

4141
int getDeviceCount();
4242

src/backend/cuda/platform.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,14 @@ string getCUDARuntimeVersion() noexcept {
325325
}
326326
}
327327

328-
unsigned getMaxJitSize() {
329-
const int MAX_JIT_LEN = 100;
330-
331-
thread_local int length = 0;
332-
if (length == 0) {
328+
int &getMaxJitSize() {
329+
constexpr int MAX_JIT_LEN = 100;
330+
thread_local int length = 0;
331+
if (length <= 0) {
333332
std::string env_var = getEnvVar("AF_CUDA_MAX_JIT_LEN");
334333
if (!env_var.empty()) {
335-
length = std::stoi(env_var);
334+
int input_len = std::stoi(env_var);
335+
length = input_len > 0 ? input_len : MAX_JIT_LEN;
336336
} else {
337337
length = MAX_JIT_LEN;
338338
}

0 commit comments

Comments
 (0)