Skip to content

Commit

Permalink
Errata fixes (Apress#105)
Browse files Browse the repository at this point in the history
* Don't use octal initializer

* Use C++-style max limit

* Add comments clarifying what T is within the snip blocks

* Move some comments closer to initial use site
  • Loading branch information
Mike Kinsner authored Jun 5, 2023
1 parent fac585c commit c409529
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace sycl;
extern const int matrixSize = 128;
static const int iterations = 16;

// T is the type of data stored in the matrix
template <typename T>
double run_sycl(const std::vector<T>& vecA,
const std::vector<T>& vecB,
Expand Down Expand Up @@ -56,6 +57,8 @@ double run_sycl(const std::vector<T>& vecA,
// Index in the local index space:
int i = item.get_local_id()[1];

// Template type T is the type of data stored in
// the matrix
T sum = 0;
for (int kk = 0; kk < K; kk += tile_size) {
// Load the matrix tile from matrix A, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace sycl;
extern const int matrixSize = 128;
static const int iterations = 16;

// T is the type of data stored in the matrix
template <typename T>
double run_sycl(const std::vector<T>& vecA,
const std::vector<T>& vecB,
Expand Down Expand Up @@ -55,6 +56,8 @@ double run_sycl(const std::vector<T>& vecA,
// Index in the local index space:
int i = item.get_local_id()[1];

// Template type T is the type of data stored
// in the matrix
T sum = 0;
for (int kk = 0; kk < K; kk += tile_size) {
// Load the matrix tile from matrix A.
Expand Down
2 changes: 2 additions & 0 deletions samples/Ch09_work_item_communication/fig_9_4_naive_matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ double run_sycl(const std::vector<T>& vecA,
int m = id[0];
int n = id[1];

// Template type T is the type of data stored
// in the matrix
T sum = 0;
for (int k = 0; k < K; k++) {
sum += matrixA[m][k] * matrixB[k][n];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ double run_sycl(const std::vector<T>& vecA,

// Local accessor, for one matrix tile:
constexpr int tile_size = 16;

// Template type T is the type of data stored in the matrix
auto tileA = local_accessor<T, 1>(tile_size, h);

h.parallel_for(
Expand Down
4 changes: 2 additions & 2 deletions samples/Ch16_cpus/fig_16_18_vector_swizzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ int main() {

q.single_task([=]() {
sycl::vec<int, 4> old_v =
sycl::vec<int, 4>(000, 100, 200, 300);
sycl::vec<int, 4>(0, 100, 200, 300);
sycl::vec<int, 4> new_v = sycl::vec<int, 4>();

new_v.rgba() = old_v.abgr();
int vals[] = {300, 200, 100, 000};
int vals[] = {300, 200, 100, 0};

if (new_v.r() != vals[0] || new_v.g() != vals[1] ||
new_v.b() != vals[2] || new_v.a() != vals[3]) {
Expand Down
3 changes: 2 additions & 1 deletion samples/Ch16_cpus/fig_16_6_stream_triad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cassert>
#include <cfloat>
#include <iostream>
#include <limits>
#include <string>
#include <sycl/sycl.hpp>
using namespace sycl;
Expand All @@ -20,7 +21,7 @@ double triad(const std::vector<float>& vecA,
assert(vecA.size() == vecB.size() &&
vecB.size() == vecC.size());
const size_t array_size = vecA.size();
double min_time_ns = DBL_MAX;
double min_time_ns = std::numeric_limits<double>::max();

queue q{property::queue::enable_profiling{}};
std::cout << "Running on device: "
Expand Down
2 changes: 1 addition & 1 deletion samples/Ch16_cpus/figure_16_6.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ double triad(const std::vector<double>& vecA,
std::vector<double>& vecC) {
assert(vecA.size() == vecB.size() == vecC.size());
const size_t array_size = vecA.size();
double min_time_ns = DBL_MAX;
double min_time_ns = std::numeric_limits<double>::max();

queue Q{property::queue::enable_profiling{}};
std::cout << "Running on device: "
Expand Down

0 comments on commit c409529

Please sign in to comment.