Skip to content

Commit 5a11efe

Browse files
GuillaumeSchmidumar456
authored andcommitted
Fixes local issue with to_string. Refactor out hash funcitons
The arguments provided to OpenCL uses the C++ standard library function std::to_string(). This function uses the locale to render it's argument to a string. It is a problem when arrayfire is used in a software initialised with non "C" locale. For instance, on a French computer, to_string(1.0) will output the string "1,0000000". This string is provided to OpenCL kernels, generating a syntax error. The most portable way to fix this problem is to use a local ostringstream imbued withe "C" locale. An Other way would be to use C++17 to_chars function, as it only renders it argument with "C" locale, without impact from the application or system locale. The patch is pretty simple, it changes the toString() function to use the stringstream in src/backend/common/TemplateArg.cpp and changed the to_string calls to this toString function in types.cpp.
1 parent 84046ca commit 5a11efe

33 files changed

+465
-399
lines changed

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ if(CMAKE_CROSSCOMPILING)
317317
"directory and build the bin2cpp target.")
318318
endif()
319319
else()
320-
add_executable(bin2cpp ${ArrayFire_SOURCE_DIR}/CMakeModules/bin2cpp.cpp
321-
${ArrayFire_SOURCE_DIR}/src/backend/common/util.cpp)
320+
add_executable(bin2cpp CMakeModules/bin2cpp.cpp
321+
src/backend/common/deterministicHash.cpp
322+
src/backend/common/deterministicHash.hpp
323+
src/backend/common/Source.hpp)
322324
set_target_properties(bin2cpp
323325
PROPERTIES
324326
CXX_STANDARD 17)
325327
target_link_libraries(bin2cpp PRIVATE nonstd::span-lite)
326328

327-
# NOSPDLOG is used to remove the spdlog dependency from bin2cpp
328-
target_compile_definitions(bin2cpp PRIVATE NOSPDLOG)
329329
if(WIN32)
330330
target_compile_definitions(bin2cpp PRIVATE OS_WIN)
331331
elseif(APPLE)

CMakeModules/bin2cpp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <utility>
2929
#include <vector>
3030

31-
#include <common/util.hpp>
31+
#include <common/deterministicHash.hpp>
3232

3333
using namespace std;
3434
using std::cout;
@@ -275,7 +275,7 @@ int main(int argc, const char *const *const argv) {
275275

276276
cout << "#pragma once\n";
277277
cout << "#include <cstddef>\n"; // defines size_t
278-
cout << "#include <common/util.hpp>\n"; // defines common::Source
278+
cout << "#include <common/Source.hpp>\n"; // defines common::Source
279279

280280
int ns_cnt = 0;
281281
int level = 0;

src/api/c/device.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
#include <string>
2929

3030
using af::dim4;
31+
using common::getCacheDirectory;
32+
using common::getEnvVar;
3133
using common::half;
34+
using common::JIT_KERNEL_CACHE_DIRECTORY_ENV_NAME;
3235
using detail::Array;
3336
using detail::cdouble;
3437
using detail::cfloat;

src/api/c/type_util.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
#pragma once
1111
#include <af/defines.h>
1212

13-
const char *getName(af_dtype type);
14-
1513
// uchar to number converters
1614
template<typename T>
1715
struct ToNum {

src/api/unified/symbol_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <dlfcn.h>
2727
#endif
2828

29+
using common::getEnvVar;
2930
using common::getErrorMessage;
3031
using common::getFunctionPointer;
3132
using common::loadLibrary;

src/backend/common/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ target_sources(afcommon_interface
4040
${CMAKE_CURRENT_SOURCE_DIR}/MemoryManagerBase.hpp
4141
${CMAKE_CURRENT_SOURCE_DIR}/MersenneTwister.hpp
4242
${CMAKE_CURRENT_SOURCE_DIR}/ModuleInterface.hpp
43+
${CMAKE_CURRENT_SOURCE_DIR}/Source.hpp
4344
${CMAKE_CURRENT_SOURCE_DIR}/SparseArray.cpp
4445
${CMAKE_CURRENT_SOURCE_DIR}/SparseArray.hpp
45-
${CMAKE_CURRENT_SOURCE_DIR}/TemplateArg.cpp
4646
${CMAKE_CURRENT_SOURCE_DIR}/TemplateArg.hpp
4747
${CMAKE_CURRENT_SOURCE_DIR}/TemplateTypename.hpp
4848
${CMAKE_CURRENT_SOURCE_DIR}/blas_headers.hpp
@@ -53,6 +53,8 @@ target_sources(afcommon_interface
5353
${CMAKE_CURRENT_SOURCE_DIR}/complex.hpp
5454
${CMAKE_CURRENT_SOURCE_DIR}/constants.cpp
5555
${CMAKE_CURRENT_SOURCE_DIR}/defines.hpp
56+
${CMAKE_CURRENT_SOURCE_DIR}/deterministicHash.cpp
57+
${CMAKE_CURRENT_SOURCE_DIR}/deterministicHash.hpp
5658
${CMAKE_CURRENT_SOURCE_DIR}/dim4.cpp
5759
${CMAKE_CURRENT_SOURCE_DIR}/dispatch.cpp
5860
${CMAKE_CURRENT_SOURCE_DIR}/dispatch.hpp

src/backend/common/Source.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*******************************************************
2+
* Copyright (c) 2022, 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+
#pragma once
10+
11+
namespace common {
12+
struct Source {
13+
const char* ptr; // Pointer to the kernel source
14+
const std::size_t length; // Length of the kernel source
15+
const std::size_t hash; // hash value for the source *ptr;
16+
};
17+
} // namespace common

src/backend/common/TemplateArg.cpp

Lines changed: 0 additions & 295 deletions
This file was deleted.

0 commit comments

Comments
 (0)