Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #313 from david-ragazzi/flexible_var_platforms
Browse files Browse the repository at this point in the history
Windows build: Discard NTA_PLATFORM_* in favor of NTA_OS_* and NTA_ARCH_* macro variables
  • Loading branch information
scottpurdy committed Jan 28, 2015
2 parents 44fa2fa + 3bde6e7 commit 559a69c
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 168 deletions.
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(PLATFORM "linux")
set(STDLIB "")
endif()
string(TOUPPER ${PLATFORM} PLATFORM_UPPERCASE)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(STDLIB "${STDLIB} -static-libgcc -static-libstdc++")
endif()

set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
else()
set(BITNESS 32)
endif()

# Compiler `-D*` definitions
add_definitions(-DNTA_PLATFORM_${PLATFORM}${BITNESS}
add_definitions(-DNTA_OS_${PLATFORM_UPPERCASE}
-DNTA_ARCH_${BITNESS}
-DHAVE_CONFIG_H
-DNTA_INTERNAL
-DBOOST_NO_WREGEX
Expand Down
8 changes: 4 additions & 4 deletions src/nupic/algorithms/Cells4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ void Cells4::compute(Real* input, Real* output, bool doInference, bool doLearnin
// invalidating our indexes.
memset(output, 0, _nCells * sizeof(output[0])); // most output is zero
#if SOME_STATES_NOT_INDEXED
#ifdef NTA_PLATFORM_darwin86
#if defined(NTA_ARCH_32) && defined(NTA_OS_DARWIN)
const UInt multipleOf4 = 4 * (_nCells/4);
UInt i;
for (i = 0; i < multipleOf4; i += 4) {
Expand Down Expand Up @@ -1402,7 +1402,7 @@ void Cells4::compute(Real* input, Real* output, bool doInference, bool doLearnin
output[i] = 1.0;
}
}
#endif // NTA_PLATFORM_darwin86
#endif // defined(NTA_ARCH_32) && defined(NTA_OS_DARWIN)
#else
static std::vector<UInt> cellsOn;
std::vector<UInt>::iterator iterOn;
Expand Down Expand Up @@ -2833,7 +2833,7 @@ void Cells4::computeForwardPropagation(CState& state)
// Compute cell and segment activity by following forward propagation
// links from each source cell. _cellActivity will be set to the total
// activity coming into a cell.
#ifdef NTA_PLATFORM_darwin86
#if defined(NTA_ARCH_32) && defined(NTA_OS_DARWIN)
const UInt multipleOf8 = 8 * (_nCells/8);
UInt i;
for (i = 0; i < multipleOf8; i += 8) {
Expand Down Expand Up @@ -2889,7 +2889,7 @@ void Cells4::computeForwardPropagation(CState& state)
}
}
}
#endif // NTA_PLATFORM_darwin86
#endif // defined(NTA_ARCH_32) && defined(NTA_OS_DARWIN)
}
#endif // SOME_STATES_NOT_INDEXED

Expand Down
2 changes: 1 addition & 1 deletion src/nupic/algorithms/FDRCSpatial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <nupic/math/StlIo.hpp>

#ifdef NTA_PLATFORM_linux64
#if defined(NTA_ARCH_64) && defined(NTA_OS_LINUX)
#define P_INC 4
#else
#define P_INC 2
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/algorithms/ImageSensorLite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

// Visual C++ (Windows) does not come with roundf() in
// the standard library
#ifdef NTA_PLATFORM_win32
#if defined(NTA_OS_WINDOWS)
#define ROUND(x) ((x-floor(x))>0.5 ? ceil(x) : floor(x))
#else
#define ROUND(x) (roundf(x))
Expand Down
8 changes: 4 additions & 4 deletions src/nupic/algorithms/Svm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace nupic {

for (int i = 0; i < size(); ++i) {

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
x_[i] = (float*) _aligned_malloc(4*n_dims(), 16);
#else
x_[i] = new feature_type[n_dims()];
Expand Down Expand Up @@ -235,15 +235,15 @@ namespace nupic {
if (sv_mem == nullptr) {
for (size_t i = 0; i != sv.size(); ++i)

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
_aligned_free(sv[i]);
#else
delete [] sv[i];
#endif

} else {

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
_aligned_free(sv_mem);
#else
delete [] sv_mem;
Expand Down Expand Up @@ -398,7 +398,7 @@ namespace nupic {
sv_mem = nullptr;
}

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
sv_mem = (float*) _aligned_malloc(4 * l * n_dims(), 16);
#else
sv_mem = new float [l * n_dims()];
Expand Down
8 changes: 4 additions & 4 deletions src/nupic/algorithms/Svm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <algorithm>

#ifdef NTA_PLATFORM_win32 // to align support vectors for SSE
#ifdef NTA_OS_WINDOWS // to align support vectors for SSE
#include <malloc.h>
#endif

Expand Down Expand Up @@ -142,7 +142,7 @@ namespace nupic {
{
if (recover_)
for (int i = 0; i != size(); ++i)
#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
_aligned_free(x_[i]);
#else
delete [] x_[i];
Expand All @@ -168,7 +168,7 @@ namespace nupic {
NTA_ASSERT(-HUGE_VAL < x[i] && x [i] < HUGE_VAL);
#endif

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
feature_type *new_x = (feature_type*) _aligned_malloc(4*n_dims(), 16);
#else
auto new_x = new feature_type [n_dims()];
Expand Down Expand Up @@ -950,7 +950,7 @@ namespace nupic {
delete model_;
model_ = nullptr;

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
_aligned_free(x_tmp_);
#else
delete [] x_tmp_;
Expand Down
16 changes: 8 additions & 8 deletions src/nupic/algorithms/SvmT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ inline float svm<traits>::rbf_function(float* x, float* x_end, float* y) const
{
float sum = 0;

#if defined(NTA_ASM) && defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_ASM) && defined(NTA_ARCH_32) && defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)

if (with_sse) {

Expand Down Expand Up @@ -774,7 +774,7 @@ inline float svm<traits>::rbf_function(float* x, float* x_end, float* y) const
}
}

#elif defined(NTA_ASM) && defined(NTA_PLATFORM_darwin86)
#elif defined(NTA_ASM) && defined(NTA_ARCH_32) && defined(NTA_OS_DARWIN)

if (with_sse) {

Expand Down Expand Up @@ -817,7 +817,7 @@ inline float svm<traits>::rbf_function(float* x, float* x_end, float* y) const
}
}

#else // not NTA_PLATFORM_darwin86, not NTA_PLATFORM_win32 and VC; or not NTA_ASM
#else // not darwin86, not win32 and VC; or not NTA_ASM

while (x != x_end) {
float d = *x - *y;
Expand Down Expand Up @@ -971,7 +971,7 @@ svm<traits>::binary_probability(const problem_type& prob, float& probA, float& p

svm_model *sub_model = train(sub_prob, sub_param);

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
float* x_tmp = (float*) _aligned_malloc(4*prob.n_dims(), 16);
#else
auto x_tmp = new float[prob.n_dims()];
Expand All @@ -985,7 +985,7 @@ svm<traits>::binary_probability(const problem_type& prob, float& probA, float& p
dec_values[perm[j]] = val * sub_model->label[0];
}

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
_aligned_free(x_tmp);
#else
delete [] x_tmp;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ svm_model* svm<traits>::train(const problem_type& prob, const svm_parameter& par
for (int i = 0; i != l; ++i)
if (nonzero[i]) {

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
float* new_sv = (float*) _aligned_malloc(4*n_dims, 16);
#else
auto new_sv = new float[n_dims];
Expand Down Expand Up @@ -1293,7 +1293,7 @@ float svm<traits>::predict(const svm_model& model, InIter x)

dec_values_ = new float [n_class*(n_class-1)/2];

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
x_tmp_ = (float*) _aligned_malloc(4*n_dims, 16);
#else
x_tmp_ = new float [n_dims];
Expand Down Expand Up @@ -1336,7 +1336,7 @@ float svm<traits>::predict_probability(const svm_model& model, InIter x, OutIter
if (dec_values_ == nullptr) {
dec_values_ = new float [n_class*(n_class-1)/2];

#if defined(NTA_PLATFORM_win32) && defined(NTA_COMPILER_MSVC)
#if defined(NTA_OS_WINDOWS) && defined(NTA_COMPILER_MSVC)
x_tmp_ = (float*) _aligned_malloc(4*n_dims, 16);
#else
x_tmp_ = new float [n_dims];
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/engine/RegionImplFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace nupic
NTA_THROW << "Unable to find NuPIC library in '" << rootDir_ << "'";


#if defined(NTA_PLATFORM_win32)
#if defined(NTA_OS_WINDOWS)
const char * filename = "cpp_region.dll";
#else
const char * filename = "libcpp_region.so";
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/engine/TestNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* ---------------------------------------------------------------------
*/

#ifdef NTA_PLATFORM_sparc64
#if defined(NTA_ARCH_64) && defined(NTA_OS_SPARC)
#include <string>
#else
#include <string.h>
Expand Down
Loading

0 comments on commit 559a69c

Please sign in to comment.