Skip to content

Commit

Permalink
Merge pull request #97 from LLNL/faster-compile
Browse files Browse the repository at this point in the history
faster compile
  • Loading branch information
trws authored Feb 23, 2022
2 parents fef85a6 + 7013270 commit b442bf3
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 53 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ foreach (backend ${camp_backends})
if ("${ENABLE_${suffix}}")
set ("CAMP_ENABLE_${suffix}" On)
endif()
if ("CAMP_ENABLE_${suffix}")
if (${CAMP_ENABLE_${suffix}})
if (backend IN_LIST camp_runtime_backends)
set (backend ${backend}_runtime)
endif()
Expand Down Expand Up @@ -103,9 +103,10 @@ configure_file(${PROJECT_SOURCE_DIR}/include/camp/config.in.hpp
blt_add_library (
NAME camp
HEADERS ${camp_headers}
SOURCES ./src/errors.cpp
DEPENDS_ON ${camp_depends}
)
target_include_directories (camp INTERFACE
target_include_directories (camp PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- task: CMake@1
inputs:
workingDir: 'build'
cmakeArgs: '--build . --config Release --verbose'
cmakeArgs: '--build . --config Release --verbose --parallel $(parallel)'
- task: CmdLine@2
inputs:
script: 'ctest.exe -T test -C Release'
Expand Down
1 change: 0 additions & 1 deletion include/camp/camp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ For details about use and distribution, please read LICENSE and NOTICE from
#ifndef __CAMP_HPP
#define __CAMP_HPP

#include <array>
#include <type_traits>

#include <camp/defines.hpp>
Expand Down
42 changes: 6 additions & 36 deletions include/camp/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ For details about use and distribution, please read LICENSE and NOTICE from

#include <cstddef>
#include <cstdint>
#include <stdexcept>
#include <string>

#include <camp/config.hpp>

Expand Down Expand Up @@ -178,30 +176,17 @@ using nullptr_t = decltype(nullptr);
using type = typename X<Lambda::template expr, Rest...>::type; \
}

/// Throw a runtime_error, avoid including exception everywhere
void throw_re(const char *s);

#ifdef CAMP_ENABLE_CUDA

#define campCudaErrchk(ans) ::camp::cudaAssert((ans), #ans, __FILE__, __LINE__)

inline cudaError_t cudaAssert(cudaError_t code,
cudaError_t cudaAssert(cudaError_t code,
const char *call,
const char *file,
int line)
{
if (code != cudaSuccess && code != cudaErrorNotReady) {
std::string msg;
msg += "campCudaErrchk(";
msg += call;
msg += ") ";
msg += cudaGetErrorString(code);
msg += " ";
msg += file;
msg += ":";
msg += std::to_string(line);
throw std::runtime_error(msg);
}
return code;
}
int line);

#endif //#ifdef CAMP_ENABLE_CUDA

Expand All @@ -210,25 +195,10 @@ inline cudaError_t cudaAssert(cudaError_t code,

#define campHipErrchk(ans) ::camp::hipAssert((ans), #ans, __FILE__, __LINE__)

inline hipError_t hipAssert(hipError_t code,
hipError_t hipAssert(hipError_t code,
const char *call,
const char *file,
int line)
{
if (code != hipSuccess && code != hipErrorNotReady) {
std::string msg;
msg += "campHipErrchk(";
msg += call;
msg += ") ";
msg += hipGetErrorString(code);
msg += " ";
msg += file;
msg += ":";
msg += std::to_string(line);
throw std::runtime_error(msg);
}
return code;
}
int line);

#endif //#ifdef CAMP_ENABLE_HIP

Expand Down
1 change: 0 additions & 1 deletion include/camp/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ For details about use and distribution, please read LICENSE and NOTICE from
#define CAMP_HELPERS_HPP

#include <cstddef>
#include <iterator>
#include <utility>

#include "camp/defines.hpp"
Expand Down
1 change: 0 additions & 1 deletion include/camp/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ For details about use and distribution, please read LICENSE and NOTICE from

#include "camp/defines.hpp"

#include <array>
#include <type_traits>

namespace camp
Expand Down
6 changes: 2 additions & 4 deletions include/camp/resource/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ For details about use and distribution, please read LICENSE and NOTICE from

#include <cuda_runtime.h>

#include <exception>

namespace camp
{
namespace resources
Expand Down Expand Up @@ -125,7 +123,7 @@ namespace resources
return MemoryAccess::Managed;
}
}
throw std::runtime_error("invalid pointer detected");
::camp::throw_re("invalid pointer detected");
}
public:
Cuda(int group = -1, int dev = 0)
Expand Down Expand Up @@ -232,7 +230,7 @@ namespace resources
campCudaErrchk(cudaFree(p));
break;
case MemoryAccess::Unknown:
throw std::runtime_error("Unknown memory access type, cannot free");
::camp::throw_re("Unknown memory access type, cannot free");
}
}
void memcpy(void *dst, const void *src, size_t size)
Expand Down
3 changes: 1 addition & 2 deletions include/camp/resource/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ For details about use and distribution, please read LICENSE and NOTICE from
#define __CAMP_EVENT_HPP

#include<type_traits>
#include<exception>
#include<memory>

namespace camp
Expand Down Expand Up @@ -60,7 +59,7 @@ namespace resources
{
auto result = dynamic_cast<EventModel<T> *>(m_value.get());
if (result == nullptr) {
throw std::runtime_error("Incompatible Event type get cast.");
::camp::throw_re("Incompatible Event type get cast.");
}
return *result->get();
}
Expand Down
8 changes: 4 additions & 4 deletions include/camp/resource/hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ For details about use and distribution, please read LICENSE and NOTICE from
#ifdef CAMP_ENABLE_HIP
#include <hip/hip_runtime.h>

#include <exception>

namespace camp
{
namespace resources
Expand Down Expand Up @@ -122,7 +120,9 @@ namespace resources
return MemoryAccess::Unknown;
}
}
throw std::runtime_error("invalid pointer detected");
::camp::throw_re("invalid pointer detected");
// unreachable
return MemoryAccess::Unknown;
}

public:
Expand Down Expand Up @@ -229,7 +229,7 @@ namespace resources
campHipErrchk(hipFree(p));
break;
case MemoryAccess::Unknown:
throw std::runtime_error("Unknown memory access type, cannot free");
::camp::throw_re("Unknown memory access type, cannot free");
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions include/camp/resource/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ For details about use and distribution, please read LICENSE and NOTICE from
#ifdef CAMP_ENABLE_SYCL
#include <CL/sycl.hpp>
#include <map>
#include <array>
using namespace cl;

namespace camp
Expand Down
2 changes: 1 addition & 1 deletion include/camp/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For details about use and distribution, please read LICENSE and NOTICE from
* \brief Exceptionally basic tuple for host-device support
*/

#include <iostream>
#include <sstream>
#include <type_traits>

#include "camp/concepts.hpp"
Expand Down
71 changes: 71 additions & 0 deletions src/errors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
Copyright (c) 2016-18, Lawrence Livermore National Security, LLC.
Produced at the Lawrence Livermore National Laboratory
Maintained by Tom Scogland <[email protected]>
CODE-756261, All rights reserved.
This file is part of camp.
For details about use and distribution, please read LICENSE and NOTICE from
http://github.com/llnl/camp
*/

#include <camp/camp.hpp>
#include <stdexcept>
#include <string>
#include <exception>


namespace camp
{

void throw_re(const char *s) { throw std::runtime_error(s); }

#ifdef CAMP_ENABLE_CUDA


cudaError_t cudaAssert(cudaError_t code,
const char *call,
const char *file,
int line)
{
if (code != cudaSuccess && code != cudaErrorNotReady) {
std::string msg;
msg += "campCudaErrchk(";
msg += call;
msg += ") ";
msg += cudaGetErrorString(code);
msg += " ";
msg += file;
msg += ":";
msg += std::to_string(line);
throw std::runtime_error(msg);
}
return code;
}

#endif //#ifdef CAMP_ENABLE_CUDA

#ifdef CAMP_ENABLE_HIP

hipError_t hipAssert(hipError_t code,
const char *call,
const char *file,
int line)
{
if (code != hipSuccess && code != hipErrorNotReady) {
std::string msg;
msg += "campHipErrchk(";
msg += call;
msg += ") ";
msg += hipGetErrorString(code);
msg += " ";
msg += file;
msg += ":";
msg += std::to_string(line);
throw std::runtime_error(msg);
}
return code;
}

#endif //#ifdef CAMP_ENABLE_HIP

} // namespace camp

0 comments on commit b442bf3

Please sign in to comment.