Skip to content

Commit

Permalink
Fix macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarkovtsev committed Feb 21, 2017
1 parent f160e26 commit 02e824a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/kmcuda.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ KMCUDAResult knn_cuda(
#endif

#ifdef __cplusplus
#include <string>
#include <unordered_map>

namespace {
Expand Down
14 changes: 14 additions & 0 deletions src/r.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,17 @@ static SEXP r_kmeans_cuda(SEXP args) {
SEXP assignments2 = PROTECT(allocVector(INTSXP, samples_size));
uint32_t *assignments_ptr = assignments.get();
int *assignments2_ptr = INTEGER(assignments2);
#ifndef __APPLE__
#pragma omp parallel for simd
for (uint32_t i = 0; i < samples_size; i++) {
assignments2_ptr[i] = assignments_ptr[i] + 1;
}
#else
#pragma omp simd
for (uint32_t i = 0; i < samples_size; i++) {
assignments2_ptr[i] = assignments_ptr[i] + 1;
}
#endif
SEXP tuple = PROTECT(allocVector(VECSXP, 2 + (average_distance_ptr != nullptr)));
SET_VECTOR_ELT(tuple, 0, centroids2);
SET_VECTOR_ELT(tuple, 1, assignments2);
Expand Down Expand Up @@ -373,10 +380,17 @@ static SEXP r_knn_cuda(SEXP args) {
std::unique_ptr<uint32_t[]> assignments(new uint32_t[samples_size]);
int *assignments_obj_ptr = INTEGER(assignments_iter->second);
uint32_t *assignments_ptr = assignments.get();
#ifndef __APPLE__
#pragma omp parallel for simd
for (uint32_t i = 0; i < samples_size; i++) {
assignments_ptr[i] = assignments_obj_ptr[i] - 1;
}
#else
#pragma omp simd
for (uint32_t i = 0; i < samples_size; i++) {
assignments_ptr[i] = assignments_obj_ptr[i] - 1;
}
#endif
KMCUDADistanceMetric metric = parse_metric(kwargs);
int device = parse_device(kwargs);
int verbosity = parse_int(kwargs, "verbosity", 0);
Expand Down

0 comments on commit 02e824a

Please sign in to comment.