diff --git a/Intro_Tutorial/lessons/03_umpire_allocator/03_umpire_allocator.cpp b/Intro_Tutorial/lessons/03_umpire_allocator/03_umpire_allocator.cpp index e90f327..eee435b 100644 --- a/Intro_Tutorial/lessons/03_umpire_allocator/03_umpire_allocator.cpp +++ b/Intro_Tutorial/lessons/03_umpire_allocator/03_umpire_allocator.cpp @@ -9,7 +9,12 @@ int main() // TODO: allocate an array of 100 doubles using the HOST allocator - std::cout << "Address of data: " << data << std::endl; + // TODO: use the resource manager to memset your array to 0 + + // TODO: uncomment this print statement + //std::cout << "Allocated " << (100 * sizeof(double)) << " bytes and set to " + // << data[0] << " using the " << allocator.getName() << " allocator." + // << std::endl; // TODO: deallocate the array diff --git a/Intro_Tutorial/lessons/03_umpire_allocator/README.md b/Intro_Tutorial/lessons/03_umpire_allocator/README.md index f51616a..a6c674b 100644 --- a/Intro_Tutorial/lessons/03_umpire_allocator/README.md +++ b/Intro_Tutorial/lessons/03_umpire_allocator/README.md @@ -7,7 +7,7 @@ deallocate memory. The fundamental concept for accessing memory through Umpire is the `umpire::Allocator`. An `umpire::Allocator` is a C++ object that can be used to allocate and deallocate memory, as well as query a pointer to get -information about it. +information about it. (Note: in this lesson, we will see how to query the name of the Allocator!) All `umpire::Allocator` objects are created and managed by Umpire’s `umpire::ResourceManager`. To create an allocator, first obtain a handle to the @@ -30,6 +30,14 @@ the desired size for your allocation: void* memory = allocator.allocate(size in bytes); ``` +Moving and modifying data in a heterogenous memory system can be annoying since you +have to keep track of the source and destination, and often use vendor-specific APIs +to perform the modifications. In Umpire, all data modification and movement, regardless +of memory resource or platform, is done using Operations. + +Next, we will use the `memset` Operator provided by Umpire's Resource Manager to +set the memory we just allocated to zero. + Don't forget to deallocate your memory afterwards! For more details, you can check out the Umpire documentation: @@ -40,5 +48,5 @@ Once you have made your changes, you can compile and run the lesson: ``` $ make 03_umpire_allocator $ ./bin/03_umpire_allocator -Address of data: 0x????? +Allocated 800 bytes and set to 0 using the HOST allocator. ``` diff --git a/Intro_Tutorial/lessons/03_umpire_allocator/solution/03_umpire_allocator_solution.cpp b/Intro_Tutorial/lessons/03_umpire_allocator/solution/03_umpire_allocator_solution.cpp index 24df8d0..30a31d2 100644 --- a/Intro_Tutorial/lessons/03_umpire_allocator/solution/03_umpire_allocator_solution.cpp +++ b/Intro_Tutorial/lessons/03_umpire_allocator/solution/03_umpire_allocator_solution.cpp @@ -12,7 +12,13 @@ int main() auto allocator = rm.getAllocator("HOST"); data = static_cast(allocator.allocate(100*sizeof(double))); - std::cout << "Address of data: " << data << std::endl; + // TODO: use the resource manager to memset your array to 0 + rm.memset(data, 0); + + // TODO: uncomment this print statement + std::cout << "Allocated " << (100 * sizeof(double)) << " bytes and set to " + << data[0] << " using the " << allocator.getName() << " allocator." + << std::endl; // TODO: deallocate the array allocator.deallocate(data);