Skip to content

Commit

Permalink
Roughly approximate R packages. Changes from old master branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
kondziu committed Jun 18, 2019
1 parent a0fead6 commit 7859c2d
Show file tree
Hide file tree
Showing 43 changed files with 476 additions and 180 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
!DESCRIPTION
!NAMESPACE
!CMakeLists.txt
!cmake/FindR.cmake
!Makefile
!Makevars
!*/cmake/FindR.cmake
22 changes: 0 additions & 22 deletions CMakeLists.txt

This file was deleted.

10 changes: 0 additions & 10 deletions DESCRIPTION

This file was deleted.

30 changes: 0 additions & 30 deletions R/ufos.R

This file was deleted.

10 changes: 0 additions & 10 deletions src/bin_file_source.h

This file was deleted.

36 changes: 0 additions & 36 deletions src/init.c

This file was deleted.

16 changes: 0 additions & 16 deletions src/userfaultCore_dummy.c

This file was deleted.

53 changes: 53 additions & 0 deletions ufos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cmake_minimum_required(VERSION 3.7)
project(ufos)

SET(EX_PLATFORM 64)
SET(EX_PLATFORM_NAME "x64")

add_definitions(-Wall -O2 -D__UFOs_CoreDev__)
#-Wall -g

set(CMAKE_CXX_STANDARD 11)

#file(GLOB_RECURSE SRC "src/*.c" "src/*.h")

set(CORE_SRC src/mappedMemory/userfaultCore.h
src/mappedMemory/sparseList.h
src/mappedMemory/sparseList.c
src/mappedMemory/userfaultCore.c
src/mappedMemory/userFaultCoreInternal.h
src/mappedMemory/userfaultGettersSetters.c)

set(UNSTDLIB_SRC
src/unstdLib/errors.h
src/unstdLib/math.h
src/unstdLib/vars.h)

set(R_SRC src/ufos.h
src/ufos.c
src/init.c)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

find_package(R REQUIRED)
message("R libraries: ${R_LIBRARIES}")
message("R include dirs: ${R_INCLUDE_DIR}")

find_package (Threads)

add_library(ufos SHARED ${CORE_SRC} ${R_SRC} ${UNSTDLIB_SRC})
include_directories(ufos ${R_INCLUDE_DIR})
target_link_libraries(ufos ${R_LIBRARIES})

add_executable(ufoTest ${CORE_SRC} ${UNSTDLIB_SRC} src/mappedMemory/ufoTest.c)
target_link_libraries(ufoTest ${CMAKE_THREAD_LIBS_INIT})

add_executable(strideTest ${CORE_SRC} src/mappedMemory/stride.c)
target_link_libraries(strideTest ${CMAKE_THREAD_LIBS_INIT})

add_executable(sparseListTest ${CORE_SRC} src/mappedMemory/sparseListTest.c)
target_link_libraries(sparseListTest ${CMAKE_THREAD_LIBS_INIT})

add_executable(userfaultSpeed ${CORE_SRC} src/mappedMemory/userfaultSpeed.c)
target_link_libraries(userfaultSpeed ${CMAKE_THREAD_LIBS_INIT})

20 changes: 20 additions & 0 deletions ufos/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Package: ufos
Type: Package
Title: UserFault Objects: framework for implementing of custom objects
masquerading as plain R objects via user faults
Description: Experiments in making custom objects with complex behavior
appearing as ordinary R data structures (data.frames, matrices,
etc.) to both R functions and C functions. This uses user faults
(memory faults) to capture memory accesses and override them.
Version: 0.1.0
Authors@R: c(person(given = "Colette", family = "Kerr", role = c("aut"),
email = "[email protected]"),
person(given = "Konrad", family = "Siek", role = c("aut", "cre"),
email = "[email protected]"))
Maintainer: Konrad Siek <[email protected]>
License: GPL-2 | GPL-3
Encoding: UTF-8
LazyData: true
NeedsCompilation: yes
Suggests: ufovectors

File renamed without changes.
2 changes: 2 additions & 0 deletions ufos/R/ufos.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Empty.

File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions ufos/src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PKG_CPPFLAGS = -pthread -D__UFOs_CoreDev__
PKG_LIBS = -pthread -D__UFOs_CoreDev__
25 changes: 25 additions & 0 deletions ufos/src/init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "ufos.h"

#include <R_ext/Rdynload.h>
#include <R_ext/Visibility.h>

// List of functions provided by the package.
static const R_CallMethodDef CallEntries[] = {
// Terminates the function list. Necessary.
{NULL, NULL, 0}
};

// Initializes the package and registers the routines with the Rdynload
// library. Name follows the pattern: R_init_<package_name>
void attribute_visible R_init_ufos(DllInfo *dll) {
//InitUFOAltRepClass(dll);
//R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
//R_useDynamicSymbols(dll, FALSE);
//R_forceSymbols(dll, TRUE);

R_RegisterCCallable("ufos", "ufo_initialize", (DL_FUNC) &ufo_initialize);
R_RegisterCCallable("ufos", "ufo_new", (DL_FUNC) &ufo_new);
R_RegisterCCallable("ufos", "ufo_shutdown", (DL_FUNC) &ufo_shutdown);
}


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ufo_sources.h → ufos/src/ufo_sources.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef enum {
typedef struct {
ufUserData* data;
ufPopulateRange population_function;
ufo_vector_type_t vector_type;
ufo_vector_type_t vector_type;
//ufUpdateRange update_function;
R_xlen_t length;
} ufo_source_t;
Expand Down
38 changes: 19 additions & 19 deletions src/ufos.c → ufos/src/ufos.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include <R_ext/Rallocators.h>

#include "ufos.h"
#include "ufo_sources.h"
#include "mappedMemory/userfaultCore.h"

#include <assert.h>

ufInstance_t ufo_system;

typedef SEXP (*__ufo_specific_vector_constructor)(ufo_source_t*);
Expand All @@ -33,9 +34,21 @@ void __validate_status_or_die (int status) {
void* __ufo_alloc(R_allocator_t *allocator, size_t size) {
ufo_source_t* source = (ufo_source_t*) allocator->data;

ufObject_t object;
ufObjectConfig_t cfg = makeObjectConfig(int, size, 1); // FIXME
size_t sexp_header_size = sizeof(struct sxpinfo_struct)
+ 2 * sizeof(struct SEXPREC*);

size_t sexp_metadata_size = sizeof(R_allocator_t);

assert((size - sexp_header_size - sexp_metadata_size)
== (source->length * sizeof(int)));

//makeObjectConfig(headerBytes, type, ct, minLoadCt)
ufObjectConfig_t cfg = makeObjectConfig(int,
sexp_header_size + sexp_metadata_size,
source->length,
16); // FIXME

ufObject_t object;
int status = ufCreateObject(ufo_system, cfg, &object);
__validate_status_or_die(status);

Expand Down Expand Up @@ -105,22 +118,9 @@ __ufo_specific_vector_constructor __select_constructor(ufo_vector_type_t type) {
}
}

void __validate_source_or_die(SEXP/*EXTPTRSXP*/ source) {
if (TYPEOF(source) != EXTPTRSXP) {
Rf_error("Invalid source type: expecting EXTPTRSXP");
}
//ufo_source_t* source_details = CAR(source);
}

SEXP __ufo_new(SEXP/*EXTPTRSXP*/ source) {
ufo_source_t* source_details = (ufo_source_t*) CAR(source);
SEXP ufo_new(ufo_source_t* source) {
__ufo_specific_vector_constructor constructor =
__select_constructor(source_details->vector_type);
return constructor(source_details);
}

SEXP ufo_new(SEXP/*EXTPTRSXP*/ source) {
__validate_source_or_die(source);
return __ufo_new(source);
__select_constructor(source->vector_type);
return constructor(source);
}

9 changes: 7 additions & 2 deletions src/ufos.h → ufos/src/ufos.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ typedef struct {
ufPopulateRange population_function;
ufo_vector_type_t vector_type;
//ufUpdateRange update_function;
R_xlen_t length;
uint64_t length;
} ufo_source_t;

// Initialization and shutdown
void ufo_initialize();
void ufo_shutdown();

// Constructor
SEXP ufo_new(ufo_source_t*);
SEXP ufo_new(ufo_source_t*);

// Function types for R dynloader.
typedef void (*ufo_initialize_t)(void);
typedef void (*ufo_shutdown_t)(void);
typedef SEXP (*ufo_new_t)(ufo_source_t*);
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions ufovectors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
project(ufovectors)
cmake_minimum_required(VERSION 2.8.7)

SET(EX_PLATFORM 64)
SET(EX_PLATFORM_NAME "x64")

add_definitions(-Wall -O2)
# -Wall -g

file(GLOB_RECURSE SRC "src/*.c" "src/*.h")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")

find_package(R REQUIRED)
message("R libraries: ${R_LIBRARIES}")
message("R include dirs: ${R_INCLUDE_DIR}")

add_library(ufovectors SHARED ${SRC})
include_directories(ufovectors ${R_INCLUDE_DIR})
target_link_libraries(ufovectors ${R_LIBRARIES})
17 changes: 17 additions & 0 deletions ufovectors/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Package: ufovectors
Type: Package
Title: Implementation of R vectors using UserFault Objects
Description: Example implementation of R vectors using UserFault Objects to
materialize data on demand from file sources.
Version: 0.1.0
Authors@R: c(person(given = "Colette", family = "Kerr", role = c("aut"),
email = "[email protected]"),
person(given = "Konrad", family = "Siek", role = c("aut", "cre"),
email = "[email protected]"))
Maintainer: Konrad Siek <[email protected]>
License: GPL-2 | GPL-3
Encoding: UTF-8
LazyData: true
Depends: ufos
LinkingTo: ufos
NeedsCompilation: yes
10 changes: 10 additions & 0 deletions ufovectors/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
useDynLib(ufovectors, .registration = TRUE, .fixes = "")

export(ufo_integer_bin)
#export(ufo_numeric_bin)
#export(ufo_character_bin)
#export(ufo_complex_bin)
#export(ufo_logical_bin)

export(ufo_init)
export(ufo_shutdown)
Loading

0 comments on commit 7859c2d

Please sign in to comment.