Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake Options (-REQUIRED_AVX, REQUIRED_EXAMPLES, REQUIRED_TESTS) #12

Merged
merged 6 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "external/argtable3"]
path = external/argtable3
[submodule "clients/spatter/external/argtable3"]
path = clients/spatter/external/argtable3
url = https://github.com/argtable/argtable3.git
74 changes: 38 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,55 +1,57 @@
cmake_minimum_required(VERSION 3.10)
project(memory-accelerator C)
cmake_minimum_required(VERSION 3.12)
project(scoria C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_subdirectory(src)

add_compile_options(-Wall -Wextra -pedantic -Wno-unused-function -Wno-strict-prototypes -g)

# JL: Can't use STREQUAL here because the compiler ID could be "IntelLLVM"
if (CMAKE_C_COMPILER_ID MATCHES "Intel")
add_compile_options(-mavx512f -Wno-debug-disables-optimization)
else()
add_compile_options(-g)
endif()

set(CMAKE_C_STANDARD 11)

include_directories(include)
include_directories(include/controller)
include_directories(include/client)
include_directories(include/posix)
include_directories(include/shared)
include_directories(include/uthash)

add_executable(client client.c ${CLIENT_SOURCE_FILES} ${SHARED_SOURCE_FILES})
target_link_libraries(client shm pthread rt)

add_executable(controller controller.c ${CONTROLLER_SOURCE_FILES} ${SHARED_SOURCE_FILES})
target_link_libraries(controller shm pthread rt)


find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
# set supported intrinsics
set(SCORIA_SUPPORTED_INTRINSICS AVX SVE)

foreach(_intrinsic ${SCORIA_SUPPORTED_INTRINSICS})
option(Scoria_REQUIRE_${_intrinsic} "Build Scoria with ${intrinsic} support" OFF)
endforeach()

if(Scoria_REQUIRE_AVX)
message(STATUS "Building with AVX support")
add_compile_options(-mavx512f)
add_compile_definitions(USE_AVX)
else()
message(STATUS "Building without AVX suppoort")
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/external/argtable3/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
if(Scoria_REQUIRE_SVE)
message(FATAL_ERROR "Scoria does not have SVE support at this time")
else()
message(STATUS "Building without SVE support")
endif()

if (CMAKE_C_COMPILER_ID MATCHES "Intel")
add_compile_options(-Rno-debug-disables-optimization)
endif()

add_subdirectory(external/argtable3)
include_directories(external/argtable3/src)

add_subdirectory(tests)
option(Scoria_REQUIRE_CLIENTS "Build Scoria example clients" ON)
if(Scoria_REQUIRE_CLIENTS)
message(STATUS "Building Example Clients")
add_subdirectory(clients)
endif()

option(Scoria_REQUIRE_TESTS "Build Scoria with test client" OFF)
if(Scoria_REQUIRE_TESTS)
message(STATUS "Building with Test Client")
add_subdirectory(tests)
endif()
add_executable(scoria controller.c ${CONTROLLER_SOURCE_FILES} ${SHARED_SOURCE_FILES})

target_link_libraries(scoria shm pthread rt)
26 changes: 0 additions & 26 deletions client.c

This file was deleted.

2 changes: 2 additions & 0 deletions clients/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(simple)
add_subdirectory(spatter)
5 changes: 5 additions & 0 deletions clients/simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.12)
project(scoria C)

add_executable(simple_client simple_client.c ${CLIENT_SOURCE_FILES} ${SHARED_SOURCE_FILES})
target_link_libraries(simple_client shm pthread rt)
74 changes: 74 additions & 0 deletions clients/simple/simple_client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <stdio.h>

#include "client.h"
#include "config.h"

#include "client_cleanup.h"
#include "client_init.h"
#include "client_memory.h"
#include "client_wait_requests.h"

#include "shm_malloc.h"

void place_requests(struct client *client) {
// Allocate Buffer
double *A = shm_malloc(1024 * sizeof(int));

if (client->chatty)
printf("Client(%d): Received Pointer to Allocated Memory: %p\n", client->id,
(void *)A);

// Write to Buffer
printf("Client(%d): Writing Array:\n", client->id);

double *input = shm_malloc(1024 * sizeof(double));
for (size_t i = 0; i < 1024; ++i) {
input[i] = (double)(2 * i);
}

struct request req1;
scoria_write(client, A, 1024, input, NULL, NULL, 0, 0, &req1);
wait_request(client, &req1);
shm_free(input);

// Read from Buffer
printf("Client(%d): Reading Array:\n", client->id);

double *output = shm_malloc(1024 * sizeof(double));

struct request req2;
scoria_read(client, A, 1024, output, NULL, NULL, 0, 0, &req2);
wait_request(client, &req2);

for (size_t i = 0; i < 1024; ++i)
printf("%.2f ", output[i]);
printf("\n");
shm_free(output);

// Free Buffer
shm_free(A);

// Exit Program
// struct request req3;
// scoria_quit(client, &req3);

// wait_request(client, &req3);
}

int main(int argc, char **argv) {
// Suppress Compiler Warnings
(void)argc;
(void)argv;

struct client client;
client.chatty = 0;

init(&client);
place_requests(&client);

cleanup(&client);

printf("Exiting...\n");

return 0;
}
26 changes: 26 additions & 0 deletions clients/spatter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()

if(NOT EXISTS "${PROJECT_SOURCE_DIR}/clients/spatter/external/argtable3/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()

add_subdirectory(external/argtable3)
include_directories(external/argtable3/src)

add_executable(spatter_client spatter_client.c parse-args.c json.c sp_alloc.c pcg_basic.c backend-support-tests.c ${CLIENT_SOURCE_FILES} ${SHARED_SOURCE_FILES})
target_compile_definitions(spatter_client PUBLIC USE_SERIAL)
target_link_libraries(spatter_client shm pthread rt m argtable3)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LANL and GT), this list of conditions and the following disclaimer.
#define STRING_SIZE 1000000
#define MAX_PATTERN_LEN 1048576

#include <sgtype.h>
#include "sgtype.h"
#include <stdint.h>
#include <sys/types.h>

Expand Down
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 tests/test_spatter.c → clients/spatter/spatter_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "client_cleanup.h"
#include "client_init.h"
#include "client_memory.h"
#include "client_place_requests.h"
#include "client_wait_requests.h"
#include "config.h"
#include "parse-args.h"
#include "shm_malloc.h"
Expand Down
4 changes: 2 additions & 2 deletions include/client/client_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
void scoria_put_request(struct client *client, struct request *req);

void scoria_quit(struct client *client, struct request *req);
void scoria_read(struct client *client, void *buffer, const size_t N,
void scoria_read(struct client *client, const void *buffer, const size_t N,
void *output, const size_t *ind1, const size_t *ind2,
size_t num_threads, bool use_avx, struct request *req);
void scoria_write(struct client *client, void *buffer, const size_t N,
void *input, const size_t *ind1, const size_t *ind2,
const void *input, const size_t *ind1, const size_t *ind2,
size_t num_threads, bool use_avx, struct request *req);

#endif /* CLIENT_MEMORY_H */
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef CLIENT_PLACE_REQUESTS
#define CLIENT_PLACE_REQUESTS
#ifndef CLIENT_WAIT_REQUESTS
#define CLIENT_WAIT_REQUESTS

#include "client.h"
#include "request.h"

void wait_request(struct client *client, struct request *req);
void wait_requests(struct client *client, struct request *reqs,
size_t num_reqs);
void place_requests(struct client *client);

#endif /* CLIENT_PLACE_REQUESTS */
#endif /* CLIENT_WAIT_REQUESTS */
12 changes: 12 additions & 0 deletions include/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@
#include "config.h"
#include "request.h"

#define NUMERRORS 7

typedef enum _controller_status {
SCORIA_SUCCESS = 0,
SCORIA_SCALAR_READ_FAIL = -1,
SCORIA_SCALAR_WRITE_FAIL = -2,
SCORIA_AVX_READ_FAIL = -3,
SCORIA_AVX_WRITE_FAIL = -4,
SCORIA_SVE_READ_FAIL = -5,
SCORIA_SVE_WRITE_FAIL = -6
} c_status;

struct controller {
int fd_location;
int fd_requests;
Expand Down
10 changes: 6 additions & 4 deletions include/controller/controller_handle_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ struct thread_args {
struct controller *controller;
};

void handle_read(struct controller *controller, struct request_queue *queue,
struct request *req);
void handle_write(struct controller *controller, struct request_queue *queue,
struct request *req);
void controller_status(c_status stat, struct request *req);

c_status handle_read(struct controller *controller, struct request_queue *queue,
struct request *req);
c_status handle_write(struct controller *controller,
struct request_queue *queue, struct request *req);

void *handler(void *args);
void handle_requests(struct controller *controller);
Expand Down
Loading